[1140] | 1 | #include <stdexcept>
|
---|
| 2 | #include <iostream>
|
---|
| 3 | #include <sstream>
|
---|
| 4 | #include <memory>
|
---|
| 5 |
|
---|
| 6 | #include <map>
|
---|
| 7 |
|
---|
| 8 | #include <stdlib.h>
|
---|
| 9 | #include <signal.h>
|
---|
| 10 | #include <stdio.h>
|
---|
| 11 |
|
---|
| 12 | #include "TROOT.h"
|
---|
| 13 | #include "TApplication.h"
|
---|
| 14 |
|
---|
| 15 | #include "TFile.h"
|
---|
| 16 | #include "TObjArray.h"
|
---|
| 17 | #include "TStopwatch.h"
|
---|
| 18 | #include "TDatabasePDG.h"
|
---|
| 19 | #include "TParticlePDG.h"
|
---|
| 20 | #include "TLorentzVector.h"
|
---|
| 21 |
|
---|
| 22 | #include "modules/Delphes.h"
|
---|
| 23 | #include "classes/DelphesStream.h"
|
---|
| 24 | #include "classes/DelphesClasses.h"
|
---|
| 25 | #include "classes/DelphesFactory.h"
|
---|
| 26 |
|
---|
| 27 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
| 28 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
| 29 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
| 30 |
|
---|
[1155] | 31 | #include "ProMC/ProMC.pb.h"
|
---|
| 32 | #include "ProMC/ProMCBook.h"
|
---|
| 33 | #include "ProMC/ProMCHeader.pb.h"
|
---|
[1140] | 34 |
|
---|
| 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | //---------------------------------------------------------------------------
|
---|
| 38 |
|
---|
[1182] | 39 | void ConvertInput(ProMCEvent &event, ExRootTreeBranch *branch, DelphesFactory *factory,
|
---|
| 40 | TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray, TObjArray *partonOutputArray,
|
---|
| 41 | TStopwatch *readStopWatch, TStopwatch *procStopWatch)
|
---|
[1140] | 42 | {
|
---|
| 43 | Int_t i;
|
---|
| 44 |
|
---|
| 45 | ProMCEvent_Event *mutableEvent;
|
---|
| 46 | ProMCEvent_Particles *mutableParticles;
|
---|
| 47 |
|
---|
| 48 | HepMCEvent *element;
|
---|
| 49 | Candidate *candidate;
|
---|
| 50 | TDatabasePDG *pdg;
|
---|
| 51 | TParticlePDG *pdgParticle;
|
---|
| 52 | Int_t pdgCode;
|
---|
| 53 |
|
---|
| 54 | Int_t pid, status;
|
---|
| 55 | Double_t px, py, pz, e, mass;
|
---|
| 56 | Double_t x, y, z;
|
---|
| 57 |
|
---|
| 58 | pdg = TDatabasePDG::Instance();
|
---|
| 59 |
|
---|
| 60 | // event information
|
---|
| 61 | mutableEvent = event.mutable_event();
|
---|
| 62 |
|
---|
| 63 | element = static_cast<HepMCEvent *>(branch->NewEntry());
|
---|
| 64 |
|
---|
| 65 | element->Number = mutableEvent->number();
|
---|
| 66 |
|
---|
| 67 | element->ProcessID = mutableEvent->process_id();
|
---|
[1146] | 68 | element->MPI = mutableEvent->mpi();
|
---|
| 69 | element->Weight = mutableEvent->weight();
|
---|
[1140] | 70 | element->Scale = mutableEvent->scale();
|
---|
| 71 | element->AlphaQED = mutableEvent->alpha_qed();
|
---|
| 72 | element->AlphaQCD = mutableEvent->alpha_qcd();
|
---|
| 73 |
|
---|
| 74 | element->ID1 = mutableEvent->id1();
|
---|
| 75 | element->ID2 = mutableEvent->id2();
|
---|
| 76 | element->X1 = mutableEvent->x1();
|
---|
| 77 | element->X2 = mutableEvent->x2();
|
---|
| 78 | element->ScalePDF = mutableEvent->scale_pdf();
|
---|
| 79 | element->PDF1 = mutableEvent->pdf1();
|
---|
| 80 | element->PDF2 = mutableEvent->pdf2();
|
---|
| 81 |
|
---|
[1182] | 82 | element->ReadTime = readStopWatch->RealTime();
|
---|
| 83 | element->ProcTime = procStopWatch->RealTime();
|
---|
[1140] | 84 |
|
---|
| 85 | mutableParticles = event.mutable_particles();
|
---|
| 86 |
|
---|
[1150] | 87 | for(i = 0; i < mutableParticles->pdg_id_size(); ++i)
|
---|
[1140] | 88 | {
|
---|
| 89 | pid = mutableParticles->pdg_id(i);
|
---|
| 90 | status = mutableParticles->status(i);
|
---|
| 91 | px = mutableParticles->px(i); py = mutableParticles->py(i); pz = mutableParticles->pz(i); mass = mutableParticles->mass(i);
|
---|
| 92 | x = mutableParticles->x(i); y = mutableParticles->y(i); z = mutableParticles->z(i);
|
---|
| 93 | e = TMath::Sqrt(px*px + py*py + pz*pz + mass*mass);
|
---|
| 94 |
|
---|
| 95 | candidate = factory->NewCandidate();
|
---|
| 96 |
|
---|
| 97 | candidate->PID = pid;
|
---|
| 98 | pdgCode = TMath::Abs(candidate->PID);
|
---|
| 99 |
|
---|
| 100 | candidate->Status = status;
|
---|
| 101 |
|
---|
| 102 | candidate->M1 = mutableParticles->mother1(i);
|
---|
| 103 | candidate->M2 = mutableParticles->mother2(i);
|
---|
| 104 |
|
---|
| 105 | candidate->D1 = mutableParticles->daughter1(i);
|
---|
| 106 | candidate->D2 = mutableParticles->daughter2(i);
|
---|
| 107 |
|
---|
| 108 | pdgParticle = pdg->GetParticle(pid);
|
---|
| 109 | candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
|
---|
| 110 | candidate->Mass = pdgParticle ? pdgParticle->Mass() : -999.9;
|
---|
| 111 |
|
---|
| 112 | candidate->Momentum.SetPxPyPzE(px, py, pz, e);
|
---|
| 113 |
|
---|
| 114 | candidate->Position.SetXYZT(x, y, z, 0.0);
|
---|
| 115 |
|
---|
| 116 | allParticleOutputArray->Add(candidate);
|
---|
| 117 |
|
---|
[1147] | 118 | if(!pdgParticle) continue;
|
---|
[1140] | 119 |
|
---|
| 120 | if(status == 1)
|
---|
| 121 | {
|
---|
| 122 | stableParticleOutputArray->Add(candidate);
|
---|
| 123 | }
|
---|
| 124 | else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
|
---|
| 125 | {
|
---|
| 126 | partonOutputArray->Add(candidate);
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | //---------------------------------------------------------------------------
|
---|
| 132 |
|
---|
| 133 | static bool interrupted = false;
|
---|
| 134 |
|
---|
| 135 | void SignalHandler(int sig)
|
---|
| 136 | {
|
---|
| 137 | interrupted = true;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | //---------------------------------------------------------------------------
|
---|
| 141 |
|
---|
| 142 | int main(int argc, char *argv[])
|
---|
| 143 | {
|
---|
| 144 | char appName[] = "DelphesCMSFWLite";
|
---|
| 145 | stringstream message;
|
---|
| 146 | ProMCBook *inputFile = 0;
|
---|
| 147 | TFile *outputFile = 0;
|
---|
[1182] | 148 | TStopwatch readStopWatch, procStopWatch;
|
---|
[1140] | 149 | ExRootTreeWriter *treeWriter = 0;
|
---|
| 150 | ExRootTreeBranch *branchEvent = 0;
|
---|
| 151 | ExRootConfReader *confReader = 0;
|
---|
| 152 | Delphes *modularDelphes = 0;
|
---|
| 153 | DelphesFactory *factory = 0;
|
---|
| 154 | TObjArray *allParticleOutputArray = 0, *stableParticleOutputArray = 0, *partonOutputArray = 0;
|
---|
| 155 | Int_t i;
|
---|
[1185] | 156 | Long64_t eventCounter, numberOfEvents;
|
---|
[1140] | 157 |
|
---|
| 158 | if(argc < 4)
|
---|
| 159 | {
|
---|
| 160 | cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl;
|
---|
| 161 | cout << " config_file - configuration file in Tcl format," << endl;
|
---|
| 162 | cout << " output_file - output file in ROOT format," << endl;
|
---|
| 163 | cout << " input_file(s) - input file(s) in ProMC format." << endl;
|
---|
| 164 | return 1;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | signal(SIGINT, SignalHandler);
|
---|
| 168 |
|
---|
| 169 | gROOT->SetBatch();
|
---|
| 170 |
|
---|
| 171 | int appargc = 1;
|
---|
| 172 | char *appargv[] = {appName};
|
---|
| 173 | TApplication app(appName, &appargc, appargv);
|
---|
| 174 |
|
---|
| 175 | try
|
---|
| 176 | {
|
---|
| 177 | outputFile = TFile::Open(argv[2], "CREATE");
|
---|
| 178 |
|
---|
| 179 | if(outputFile == NULL)
|
---|
| 180 | {
|
---|
| 181 | message << "can't open " << argv[2] << endl;
|
---|
| 182 | throw runtime_error(message.str());
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | treeWriter = new ExRootTreeWriter(outputFile, "Delphes");
|
---|
| 186 |
|
---|
[1146] | 187 | branchEvent = treeWriter->NewBranch("Event", HepMCEvent::Class());
|
---|
[1140] | 188 |
|
---|
| 189 | confReader = new ExRootConfReader;
|
---|
| 190 | confReader->ReadFile(argv[1]);
|
---|
| 191 |
|
---|
| 192 | modularDelphes = new Delphes("Delphes");
|
---|
| 193 | modularDelphes->SetConfReader(confReader);
|
---|
| 194 | modularDelphes->SetTreeWriter(treeWriter);
|
---|
| 195 |
|
---|
| 196 | factory = modularDelphes->GetFactory();
|
---|
| 197 | allParticleOutputArray = modularDelphes->ExportArray("allParticles");
|
---|
| 198 | stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
|
---|
| 199 | partonOutputArray = modularDelphes->ExportArray("partons");
|
---|
| 200 |
|
---|
| 201 | modularDelphes->InitTask();
|
---|
| 202 |
|
---|
| 203 | for(i = 3; i < argc && !interrupted; ++i)
|
---|
| 204 | {
|
---|
| 205 | cout << "** Reading " << argv[i] << endl;
|
---|
| 206 |
|
---|
| 207 | inputFile = new ProMCBook(argv[i], "r");
|
---|
| 208 |
|
---|
| 209 | if(inputFile == NULL)
|
---|
| 210 | {
|
---|
| 211 | message << "can't open " << argv[i] << endl;
|
---|
| 212 | throw runtime_error(message.str());
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[1185] | 215 | numberOfEvents = inputFile->getEvents();;
|
---|
[1140] | 216 |
|
---|
[1185] | 217 | if(numberOfEvents <= 0) continue;
|
---|
[1140] | 218 |
|
---|
[1185] | 219 | ExRootProgressBar progressBar(numberOfEvents - 1);
|
---|
[1140] | 220 |
|
---|
| 221 | // Loop over all objects
|
---|
| 222 | modularDelphes->Clear();
|
---|
| 223 | treeWriter->Clear();
|
---|
[1182] | 224 | readStopWatch.Start();
|
---|
[1185] | 225 | for(eventCounter = 0; eventCounter < numberOfEvents && !interrupted; ++eventCounter)
|
---|
[1140] | 226 | {
|
---|
| 227 | if(inputFile->next() != 0) continue;
|
---|
| 228 | ProMCEvent event = inputFile->get();
|
---|
| 229 |
|
---|
[1182] | 230 | readStopWatch.Stop();
|
---|
| 231 |
|
---|
| 232 | procStopWatch.Start();
|
---|
| 233 | ConvertInput(event, branchEvent, factory,
|
---|
| 234 | allParticleOutputArray, stableParticleOutputArray, partonOutputArray,
|
---|
| 235 | &readStopWatch, &procStopWatch);
|
---|
[1140] | 236 | modularDelphes->ProcessTask();
|
---|
[1182] | 237 | procStopWatch.Stop();
|
---|
[1140] | 238 |
|
---|
| 239 | treeWriter->Fill();
|
---|
| 240 |
|
---|
| 241 | modularDelphes->Clear();
|
---|
| 242 | treeWriter->Clear();
|
---|
| 243 |
|
---|
[1182] | 244 | readStopWatch.Start();
|
---|
[1185] | 245 | progressBar.Update(eventCounter);
|
---|
[1140] | 246 | }
|
---|
[1185] | 247 |
|
---|
| 248 | progressBar.Update(eventCounter, eventCounter, kTRUE);
|
---|
[1140] | 249 | progressBar.Finish();
|
---|
| 250 |
|
---|
| 251 | inputFile->close();
|
---|
[1146] | 252 | delete inputFile;
|
---|
[1140] | 253 | }
|
---|
| 254 |
|
---|
| 255 | modularDelphes->FinishTask();
|
---|
| 256 | treeWriter->Write();
|
---|
| 257 |
|
---|
| 258 | cout << "** Exiting..." << endl;
|
---|
| 259 |
|
---|
| 260 | delete modularDelphes;
|
---|
| 261 | delete confReader;
|
---|
| 262 | delete treeWriter;
|
---|
| 263 | delete outputFile;
|
---|
| 264 |
|
---|
| 265 | return 0;
|
---|
| 266 | }
|
---|
| 267 | catch(runtime_error &e)
|
---|
| 268 | {
|
---|
| 269 | if(treeWriter) delete treeWriter;
|
---|
| 270 | if(outputFile) delete outputFile;
|
---|
| 271 | cerr << "** ERROR: " << e.what() << endl;
|
---|
| 272 | return 1;
|
---|
| 273 | }
|
---|
| 274 | }
|
---|