[2eb25b1] | 1 | /*
|
---|
| 2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
| 3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
| 4 | *
|
---|
| 5 | * This program is free software: you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include <stdexcept>
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <sstream>
|
---|
| 22 |
|
---|
| 23 | #include <vector>
|
---|
| 24 |
|
---|
| 25 | #include <signal.h>
|
---|
| 26 |
|
---|
| 27 | #include "TROOT.h"
|
---|
| 28 | #include "TApplication.h"
|
---|
| 29 |
|
---|
| 30 | #include "TFile.h"
|
---|
| 31 | #include "TObjArray.h"
|
---|
| 32 | #include "TDatabasePDG.h"
|
---|
| 33 | #include "TParticlePDG.h"
|
---|
| 34 | #include "TLorentzVector.h"
|
---|
| 35 |
|
---|
| 36 | #include "modules/Delphes.h"
|
---|
| 37 | #include "classes/DelphesClasses.h"
|
---|
| 38 | #include "classes/DelphesFactory.h"
|
---|
| 39 | #include "classes/DelphesHepMCReader.h"
|
---|
| 40 |
|
---|
| 41 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
| 42 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
| 43 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
| 44 |
|
---|
| 45 | #include "fastjet/PseudoJet.hh"
|
---|
| 46 | #include "fastjet/JetDefinition.hh"
|
---|
| 47 | #include "fastjet/ClusterSequence.hh"
|
---|
| 48 |
|
---|
[8e602e5] | 49 | // #include "fastjet/contrib/Nsubjettiness.hh"
|
---|
| 50 | // #include "fastjet/contrib/Njettiness.hh"
|
---|
| 51 | // #include "fastjet/contrib/NjettinessPlugin.hh"
|
---|
| 52 | // #include "fastjet/contrib/WinnerTakeAllRecombiner.hh"
|
---|
[2eb25b1] | 53 |
|
---|
| 54 | using namespace std;
|
---|
| 55 | using namespace fastjet;
|
---|
[8e602e5] | 56 | // using namespace fastjet::contrib;
|
---|
[2eb25b1] | 57 |
|
---|
| 58 | //---------------------------------------------------------------------------
|
---|
| 59 |
|
---|
| 60 | static bool interrupted = false;
|
---|
| 61 |
|
---|
| 62 | void SignalHandler(int sig)
|
---|
| 63 | {
|
---|
| 64 | interrupted = true;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | //---------------------------------------------------------------------------
|
---|
| 68 |
|
---|
| 69 | int main(int argc, char *argv[])
|
---|
| 70 | {
|
---|
[8e602e5] | 71 | char appName[] = "ExternalFastJetHepMC";
|
---|
[2eb25b1] | 72 | stringstream message;
|
---|
| 73 | FILE *inputFile = 0;
|
---|
| 74 | ExRootConfReader *confReader = 0;
|
---|
| 75 | Delphes *modularDelphes = 0;
|
---|
| 76 | DelphesFactory *factory = 0;
|
---|
| 77 | TObjArray *stableParticleOutputArray = 0, *allParticleOutputArray = 0, *partonOutputArray = 0;
|
---|
| 78 | DelphesHepMCReader *reader = 0;
|
---|
| 79 | Int_t i, maxEvents, skipEvents;
|
---|
| 80 | Long64_t length, eventCounter;
|
---|
| 81 |
|
---|
| 82 | TObjArray *inputArray = 0;
|
---|
| 83 | TIterator *inputIterator = 0;
|
---|
| 84 | Candidate *candidate = 0;
|
---|
| 85 | TLorentzVector momentum;
|
---|
| 86 |
|
---|
| 87 | JetDefinition *definition = 0;
|
---|
[8e602e5] | 88 | // JetDefinition::Recombiner *recomb = 0;
|
---|
[2eb25b1] | 89 | vector<PseudoJet> inputList, outputList;
|
---|
| 90 | PseudoJet jet;
|
---|
| 91 |
|
---|
| 92 | if(argc < 2)
|
---|
| 93 | {
|
---|
| 94 | cout << " Usage: " << appName << " config_file" << " [input_file(s)]" << endl;
|
---|
| 95 | cout << " config_file - configuration file in Tcl format," << endl;
|
---|
| 96 | cout << " input_file(s) - input file(s) in HepMC format," << endl;
|
---|
| 97 | cout << " with no input_file, or when input_file is -, read standard input." << endl;
|
---|
| 98 | return 1;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | signal(SIGINT, SignalHandler);
|
---|
| 102 |
|
---|
| 103 | gROOT->SetBatch();
|
---|
| 104 |
|
---|
| 105 | int appargc = 1;
|
---|
| 106 | char *appargv[] = {appName};
|
---|
| 107 | TApplication app(appName, &appargc, appargv);
|
---|
| 108 |
|
---|
| 109 | try
|
---|
| 110 | {
|
---|
| 111 | confReader = new ExRootConfReader;
|
---|
| 112 | confReader->ReadFile(argv[1]);
|
---|
| 113 |
|
---|
| 114 | maxEvents = confReader->GetInt("::MaxEvents", 0);
|
---|
| 115 | skipEvents = confReader->GetInt("::SkipEvents", 0);
|
---|
| 116 |
|
---|
| 117 | if(maxEvents < 0)
|
---|
| 118 | {
|
---|
| 119 | throw runtime_error("MaxEvents must be zero or positive");
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if(skipEvents < 0)
|
---|
| 123 | {
|
---|
| 124 | throw runtime_error("SkipEvents must be zero or positive");
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | modularDelphes = new Delphes("Delphes");
|
---|
| 128 | modularDelphes->SetConfReader(confReader);
|
---|
| 129 |
|
---|
| 130 | factory = modularDelphes->GetFactory();
|
---|
| 131 | allParticleOutputArray = modularDelphes->ExportArray("allParticles");
|
---|
| 132 | stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
|
---|
| 133 | partonOutputArray = modularDelphes->ExportArray("partons");
|
---|
| 134 |
|
---|
| 135 | reader = new DelphesHepMCReader;
|
---|
| 136 |
|
---|
| 137 | modularDelphes->InitTask();
|
---|
| 138 |
|
---|
| 139 | ClusterSequence::print_banner();
|
---|
[8e602e5] | 140 | // recomb = new WinnerTakeAllRecombiner();
|
---|
| 141 | // definition = new JetDefinition(antikt_algorithm, 0.5, recomb, Best);
|
---|
| 142 | definition = new JetDefinition(antikt_algorithm, 0.5);
|
---|
[2eb25b1] | 143 |
|
---|
| 144 | inputArray = modularDelphes->ImportArray("Calorimeter/towers");
|
---|
| 145 | inputIterator = inputArray->MakeIterator();
|
---|
| 146 |
|
---|
| 147 | i = 2;
|
---|
| 148 | do
|
---|
| 149 | {
|
---|
| 150 | if(interrupted) break;
|
---|
| 151 |
|
---|
| 152 | if(i == argc || strncmp(argv[i], "-", 2) == 0)
|
---|
| 153 | {
|
---|
| 154 | cout << "** Reading standard input" << endl;
|
---|
| 155 | inputFile = stdin;
|
---|
| 156 | length = -1;
|
---|
| 157 | }
|
---|
| 158 | else
|
---|
| 159 | {
|
---|
| 160 | cout << "** Reading " << argv[i] << endl;
|
---|
| 161 | inputFile = fopen(argv[i], "r");
|
---|
| 162 |
|
---|
| 163 | if(inputFile == NULL)
|
---|
| 164 | {
|
---|
| 165 | message << "can't open " << argv[i];
|
---|
| 166 | throw runtime_error(message.str());
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | fseek(inputFile, 0L, SEEK_END);
|
---|
| 170 | length = ftello(inputFile);
|
---|
| 171 | fseek(inputFile, 0L, SEEK_SET);
|
---|
| 172 |
|
---|
| 173 | if(length <= 0)
|
---|
| 174 | {
|
---|
| 175 | fclose(inputFile);
|
---|
| 176 | ++i;
|
---|
| 177 | continue;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | reader->SetInputFile(inputFile);
|
---|
| 182 |
|
---|
| 183 | // Loop over all objects
|
---|
| 184 | eventCounter = 0;
|
---|
| 185 | modularDelphes->Clear();
|
---|
| 186 | reader->Clear();
|
---|
| 187 | while((maxEvents <= 0 || eventCounter - skipEvents < maxEvents) &&
|
---|
| 188 | reader->ReadBlock(factory, allParticleOutputArray,
|
---|
| 189 | stableParticleOutputArray, partonOutputArray) && !interrupted)
|
---|
| 190 | {
|
---|
| 191 | if(reader->EventReady())
|
---|
| 192 | {
|
---|
| 193 | ++eventCounter;
|
---|
| 194 |
|
---|
| 195 | if(eventCounter > skipEvents)
|
---|
| 196 | {
|
---|
| 197 | modularDelphes->ProcessTask();
|
---|
| 198 |
|
---|
| 199 | inputList.clear();
|
---|
| 200 | inputIterator->Reset();
|
---|
| 201 | while((candidate = static_cast<Candidate*>(inputIterator->Next())))
|
---|
| 202 | {
|
---|
| 203 | momentum = candidate->Momentum;
|
---|
| 204 | jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
|
---|
| 205 | inputList.push_back(jet);
|
---|
| 206 | }
|
---|
| 207 | ClusterSequence sequence(inputList, *definition);
|
---|
| 208 | outputList.clear();
|
---|
[8e602e5] | 209 | outputList = sorted_by_pt(sequence.inclusive_jets(0.0));
|
---|
| 210 |
|
---|
| 211 | // tell the user what was done
|
---|
| 212 | // - the description of the algorithm used
|
---|
| 213 | // - show the inclusive jets as
|
---|
| 214 | // {index, rapidity, phi, pt}
|
---|
| 215 | //----------------------------------------------------------
|
---|
| 216 | if(eventCounter == skipEvents + 1)
|
---|
| 217 | {
|
---|
| 218 | cout << "Ran " << definition->description() << endl;
|
---|
| 219 |
|
---|
| 220 | // label the columns
|
---|
| 221 | printf("%5s %15s %15s %15s\n","jet #", "rapidity", "phi", "pt");
|
---|
| 222 |
|
---|
| 223 | // print out the details for each jet
|
---|
| 224 | for (unsigned int i = 0; i < outputList.size(); i++) {
|
---|
| 225 | printf("%5u %15.8f %15.8f %15.8f\n",
|
---|
| 226 | i, outputList[i].rap(), outputList[i].phi(),
|
---|
| 227 | outputList[i].perp());
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
[2eb25b1] | 230 | }
|
---|
| 231 |
|
---|
| 232 | modularDelphes->Clear();
|
---|
| 233 | reader->Clear();
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | if(inputFile != stdin) fclose(inputFile);
|
---|
| 238 |
|
---|
| 239 | ++i;
|
---|
| 240 | }
|
---|
| 241 | while(i < argc);
|
---|
| 242 |
|
---|
| 243 | modularDelphes->FinishTask();
|
---|
| 244 |
|
---|
| 245 | cout << "** Exiting..." << endl;
|
---|
| 246 |
|
---|
[8e602e5] | 247 | delete definition;
|
---|
| 248 | // delete recomb;
|
---|
| 249 |
|
---|
[2eb25b1] | 250 | delete reader;
|
---|
| 251 | delete modularDelphes;
|
---|
| 252 | delete confReader;
|
---|
| 253 |
|
---|
| 254 | return 0;
|
---|
| 255 | }
|
---|
| 256 | catch(runtime_error &e)
|
---|
| 257 | {
|
---|
| 258 | cerr << "** ERROR: " << e.what() << endl;
|
---|
| 259 | return 1;
|
---|
| 260 | }
|
---|
| 261 | }
|
---|