[b443089] | 1 | /*
|
---|
| 2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
| 3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
[1fa50c2] | 4 | *
|
---|
[b443089] | 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.
|
---|
[1fa50c2] | 9 | *
|
---|
[b443089] | 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.
|
---|
[1fa50c2] | 14 | *
|
---|
[b443089] | 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 |
|
---|
[d7d2da3] | 19 | #include <stdexcept>
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <sstream>
|
---|
| 22 |
|
---|
| 23 | #include <signal.h>
|
---|
| 24 |
|
---|
| 25 | #include "TROOT.h"
|
---|
| 26 | #include "TApplication.h"
|
---|
| 27 |
|
---|
| 28 | #include "TFile.h"
|
---|
| 29 | #include "TObjArray.h"
|
---|
| 30 | #include "TStopwatch.h"
|
---|
| 31 | #include "TDatabasePDG.h"
|
---|
| 32 | #include "TParticlePDG.h"
|
---|
| 33 | #include "TLorentzVector.h"
|
---|
| 34 |
|
---|
| 35 | #include "classes/DelphesClasses.h"
|
---|
| 36 | #include "classes/DelphesFactory.h"
|
---|
| 37 | #include "classes/DelphesSTDHEPReader.h"
|
---|
| 38 | #include "classes/DelphesPileUpWriter.h"
|
---|
| 39 |
|
---|
| 40 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
| 41 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
| 42 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
| 43 |
|
---|
| 44 | using namespace std;
|
---|
| 45 |
|
---|
| 46 | //---------------------------------------------------------------------------
|
---|
| 47 |
|
---|
| 48 | static bool interrupted = false;
|
---|
| 49 |
|
---|
| 50 | void SignalHandler(int sig)
|
---|
| 51 | {
|
---|
| 52 | interrupted = true;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | //---------------------------------------------------------------------------
|
---|
| 56 |
|
---|
| 57 | int main(int argc, char *argv[])
|
---|
| 58 | {
|
---|
| 59 | char appName[] = "stdhep2pileup";
|
---|
| 60 | stringstream message;
|
---|
| 61 | FILE *inputFile = 0;
|
---|
| 62 | DelphesFactory *factory = 0;
|
---|
| 63 | TObjArray *stableParticleOutputArray = 0, *allParticleOutputArray = 0, *partonOutputArray = 0;
|
---|
| 64 | TIterator *itParticle = 0;
|
---|
| 65 | Candidate *candidate = 0;
|
---|
| 66 | DelphesPileUpWriter *writer = 0;
|
---|
| 67 | DelphesSTDHEPReader *reader = 0;
|
---|
| 68 | Int_t i;
|
---|
| 69 | Long64_t length, eventCounter;
|
---|
| 70 |
|
---|
| 71 | if(argc < 2)
|
---|
| 72 | {
|
---|
| 73 | cout << " Usage: " << appName << " output_file" << " [input_file(s)]" << endl;
|
---|
| 74 | cout << " output_file - output binary pile-up file," << endl;
|
---|
| 75 | cout << " input_file(s) - input file(s) in STDHEP format," << endl;
|
---|
| 76 | cout << " with no input_file, or when input_file is -, read standard input." << endl;
|
---|
| 77 | return 1;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | signal(SIGINT, SignalHandler);
|
---|
| 81 |
|
---|
| 82 | gROOT->SetBatch();
|
---|
| 83 |
|
---|
| 84 | int appargc = 1;
|
---|
| 85 | char *appargv[] = {appName};
|
---|
| 86 | TApplication app(appName, &appargc, appargv);
|
---|
| 87 |
|
---|
| 88 | try
|
---|
| 89 | {
|
---|
| 90 | writer = new DelphesPileUpWriter(argv[1]);
|
---|
| 91 |
|
---|
| 92 | factory = new DelphesFactory("ObjectFactory");
|
---|
| 93 | allParticleOutputArray = factory->NewPermanentArray();
|
---|
| 94 | stableParticleOutputArray = factory->NewPermanentArray();
|
---|
| 95 | partonOutputArray = factory->NewPermanentArray();
|
---|
| 96 |
|
---|
| 97 | itParticle = stableParticleOutputArray->MakeIterator();
|
---|
| 98 |
|
---|
| 99 | reader = new DelphesSTDHEPReader;
|
---|
| 100 |
|
---|
| 101 | i = 2;
|
---|
| 102 | do
|
---|
| 103 | {
|
---|
| 104 | if(interrupted) break;
|
---|
| 105 |
|
---|
| 106 | if(i == argc || strncmp(argv[i], "-", 2) == 0)
|
---|
| 107 | {
|
---|
| 108 | cout << "** Reading standard input" << endl;
|
---|
| 109 | inputFile = stdin;
|
---|
| 110 | length = -1;
|
---|
| 111 | }
|
---|
| 112 | else
|
---|
| 113 | {
|
---|
| 114 | cout << "** Reading " << argv[i] << endl;
|
---|
[b8b29f1] | 115 | inputFile = fopen(argv[i], "rb");
|
---|
[d7d2da3] | 116 |
|
---|
| 117 | if(inputFile == NULL)
|
---|
| 118 | {
|
---|
| 119 | message << "can't open " << argv[i];
|
---|
| 120 | throw runtime_error(message.str());
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | fseek(inputFile, 0L, SEEK_END);
|
---|
| 124 | length = ftello(inputFile);
|
---|
| 125 | fseek(inputFile, 0L, SEEK_SET);
|
---|
| 126 |
|
---|
| 127 | if(length <= 0)
|
---|
| 128 | {
|
---|
| 129 | fclose(inputFile);
|
---|
| 130 | ++i;
|
---|
| 131 | continue;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | reader->SetInputFile(inputFile);
|
---|
| 136 |
|
---|
| 137 | ExRootProgressBar progressBar(length);
|
---|
| 138 |
|
---|
| 139 | // Loop over all objects
|
---|
| 140 | eventCounter = 0;
|
---|
| 141 | factory->Clear();
|
---|
| 142 | reader->Clear();
|
---|
| 143 | while(reader->ReadBlock(factory, allParticleOutputArray,
|
---|
| 144 | stableParticleOutputArray, partonOutputArray) && !interrupted)
|
---|
| 145 | {
|
---|
| 146 | if(reader->EventReady())
|
---|
| 147 | {
|
---|
| 148 | ++eventCounter;
|
---|
| 149 |
|
---|
| 150 | itParticle->Reset();
|
---|
| 151 | while((candidate = static_cast<Candidate*>(itParticle->Next())))
|
---|
| 152 | {
|
---|
| 153 | const TLorentzVector &position = candidate->Position;
|
---|
| 154 | const TLorentzVector &momentum = candidate->Momentum;
|
---|
| 155 | writer->WriteParticle(candidate->PID,
|
---|
| 156 | position.X(), position.Y(), position.Z(), position.T(),
|
---|
| 157 | momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | writer->WriteEntry();
|
---|
| 161 |
|
---|
| 162 | factory->Clear();
|
---|
| 163 | reader->Clear();
|
---|
| 164 | }
|
---|
| 165 | progressBar.Update(ftello(inputFile), eventCounter);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | fseek(inputFile, 0L, SEEK_END);
|
---|
| 169 | progressBar.Update(ftello(inputFile), eventCounter, kTRUE);
|
---|
| 170 | progressBar.Finish();
|
---|
| 171 |
|
---|
| 172 | if(inputFile != stdin) fclose(inputFile);
|
---|
| 173 |
|
---|
| 174 | ++i;
|
---|
| 175 | }
|
---|
| 176 | while(i < argc);
|
---|
| 177 |
|
---|
| 178 | writer->WriteIndex();
|
---|
| 179 |
|
---|
| 180 | cout << "** Exiting..." << endl;
|
---|
| 181 |
|
---|
| 182 | delete reader;
|
---|
| 183 | delete factory;
|
---|
| 184 | delete writer;
|
---|
| 185 |
|
---|
| 186 | return 0;
|
---|
| 187 | }
|
---|
| 188 | catch(runtime_error &e)
|
---|
| 189 | {
|
---|
| 190 | if(writer) delete writer;
|
---|
| 191 | cerr << "** ERROR: " << e.what() << endl;
|
---|
| 192 | return 1;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|