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