Changeset 341014c in git for readers/DelphesProIO.cpp
- Timestamp:
- Feb 12, 2019, 9:29:17 PM (6 years ago)
- Branches:
- ImprovedOutputFile, Timing, llp, master
- Children:
- 6455202
- Parents:
- 45e58be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
readers/DelphesProIO.cpp
r45e58be r341014c 18 18 */ 19 19 20 #include <iostream> 21 #include <memory> 22 #include <sstream> 20 23 #include <stdexcept> 21 #include <iostream>22 #include <sstream>23 #include <memory>24 24 25 25 #include <map> 26 26 27 #include <stdlib.h>28 27 #include <signal.h> 29 28 #include <stdio.h> 30 29 #include <stdlib.h> 30 31 #include "TApplication.h" 31 32 #include "TROOT.h" 32 #include "TApplication.h" 33 33 34 #include "TDatabasePDG.h" 34 35 #include "TFile.h" 36 #include "TLorentzVector.h" 35 37 #include "TObjArray.h" 38 #include "TParticlePDG.h" 36 39 #include "TStopwatch.h" 37 #include "TDatabasePDG.h" 38 #include "TParticlePDG.h" 39 #include "TLorentzVector.h" 40 41 #include "modules/Delphes.h" 42 #include "classes/DelphesStream.h" 40 43 41 #include "classes/DelphesClasses.h" 44 42 #include "classes/DelphesFactory.h" 45 43 #include "classes/DelphesStream.h" 44 #include "modules/Delphes.h" 45 46 #include "ExRootAnalysis/ExRootProgressBar.h" 47 #include "ExRootAnalysis/ExRootTreeBranch.h" 46 48 #include "ExRootAnalysis/ExRootTreeWriter.h" 47 #include "ExRootAnalysis/ExRootTreeBranch.h" 48 #include "ExRootAnalysis/ExRootProgressBar.h" 49 50 #include <proio/reader.h> 49 51 50 #include <proio/event.h> 52 51 #include <proio/model/mc.pb.h> 53 namespace model=proio::model::mc; 54 52 #include <proio/reader.h> 53 namespace model = proio::model::mc; 55 54 56 55 using namespace std; … … 59 58 // This method dynamically checks the message type (varint or not) depending on 60 59 // non-zero value of units momentumUnit and positionUnit. 61 void ConvertInput(proio::Event *event, double momentumUnit, double positionUnit, 60 void ConvertInput(proio::Event *event, double momentumUnit, double positionUnit, 62 61 ExRootTreeBranch *branch, DelphesFactory *factory, 63 62 TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray, … … 80 79 element = static_cast<HepMCEvent *>(branch->NewEntry()); 81 80 82 int nID=0; 83 double weight=0; 84 int process_id=0; 85 auto mcentries = event->TaggedEntries("MCParameters"); 86 for (uint64_t mcentryID : mcentries) { 87 auto mcpar = dynamic_cast<proio::model::mc::MCParameters *>(event->GetEntry(mcentryID)); 88 nID=mcpar->number(); 89 weight=mcpar->weight(); 90 process_id=mcpar->processid(); 91 break; // consider only most generic from 1st entry 92 }; 81 int nID = 0; 82 double weight = 0; 83 int process_id = 0; 84 auto mcentries = event->TaggedEntries("MCParameters"); 85 for(uint64_t mcentryID : mcentries) 86 { 87 auto mcpar = dynamic_cast<proio::model::mc::MCParameters *>(event->GetEntry(mcentryID)); 88 nID = mcpar->number(); 89 weight = mcpar->weight(); 90 process_id = mcpar->processid(); 91 break; // consider only most generic from 1st entry 92 }; 93 93 94 94 element->Number = nID; 95 element->ProcessID = process_id;95 element->ProcessID = process_id; 96 96 element->Weight = weight; 97 97 98 /*98 /* 99 99 // Pythia8 specific 100 100 element->MPI = mutableEvent->mpi(); … … 114 114 element->ProcTime = procStopWatch->RealTime(); 115 115 116 117 118 if ( momentumUnit >0 && positionUnit>0) { 119 120 121 auto entries = event->TaggedEntries("VarintPackedParticles"); 122 123 for (uint64_t entryID : entries) { 124 125 auto mutableParticles = dynamic_cast<model::VarintPackedParticles *>(event->GetEntry(entryID)); 126 127 for(int i = 0; i < mutableParticles->pdg_size(); ++i) 128 { 129 pid = mutableParticles->pdg(i); 130 status = mutableParticles->status(i); 131 px = mutableParticles->px(i)/momentumUnit; 132 py = mutableParticles->py(i)/momentumUnit; 133 pz = mutableParticles->pz(i)/momentumUnit; 134 mass = mutableParticles->mass(i)/momentumUnit; 135 x = mutableParticles->x(i)/positionUnit; 136 y = mutableParticles->y(i)/positionUnit; 137 z = mutableParticles->z(i)/positionUnit; 138 t = mutableParticles->t(i)/positionUnit; 139 140 candidate = factory->NewCandidate(); 141 candidate->PID = pid; 142 pdgCode = TMath::Abs(candidate->PID); 143 candidate->Status = status; 144 candidate->M1 = mutableParticles->parent1(i); 145 candidate->M2 = mutableParticles->parent2(i); 146 candidate->D1 = mutableParticles->child1(i); 147 candidate->D2 = mutableParticles->child2(i); 148 pdgParticle = pdg->GetParticle(pid); 149 candidate->Charge = mutableParticles->charge(i)/3.0; 150 //candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999; 151 candidate->Mass = mass; 152 candidate->Momentum.SetXYZM(px, py, pz, mass); 153 candidate->Position.SetXYZT(x, y, z, t); 154 allParticleOutputArray->Add(candidate); 155 if(!pdgParticle) continue; 156 157 if(status == 1) 116 if(momentumUnit > 0 && positionUnit > 0) 117 { 118 119 auto entries = event->TaggedEntries("VarintPackedParticles"); 120 121 for(uint64_t entryID : entries) 158 122 { 159 stableParticleOutputArray->Add(candidate); 160 } 161 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15) 162 { 163 partonOutputArray->Add(candidate); 123 124 auto mutableParticles = dynamic_cast<model::VarintPackedParticles *>(event->GetEntry(entryID)); 125 126 for(int i = 0; i < mutableParticles->pdg_size(); ++i) 127 { 128 pid = mutableParticles->pdg(i); 129 status = mutableParticles->status(i); 130 px = mutableParticles->px(i) / momentumUnit; 131 py = mutableParticles->py(i) / momentumUnit; 132 pz = mutableParticles->pz(i) / momentumUnit; 133 mass = mutableParticles->mass(i) / momentumUnit; 134 x = mutableParticles->x(i) / positionUnit; 135 y = mutableParticles->y(i) / positionUnit; 136 z = mutableParticles->z(i) / positionUnit; 137 t = mutableParticles->t(i) / positionUnit; 138 139 candidate = factory->NewCandidate(); 140 candidate->PID = pid; 141 pdgCode = TMath::Abs(candidate->PID); 142 candidate->Status = status; 143 candidate->M1 = mutableParticles->parent1(i); 144 candidate->M2 = mutableParticles->parent2(i); 145 candidate->D1 = mutableParticles->child1(i); 146 candidate->D2 = mutableParticles->child2(i); 147 pdgParticle = pdg->GetParticle(pid); 148 candidate->Charge = mutableParticles->charge(i) / 3.0; 149 //candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999; 150 candidate->Mass = mass; 151 candidate->Momentum.SetXYZM(px, py, pz, mass); 152 candidate->Position.SetXYZT(x, y, z, t); 153 allParticleOutputArray->Add(candidate); 154 if(!pdgParticle) continue; 155 156 if(status == 1) 157 { 158 stableParticleOutputArray->Add(candidate); 159 } 160 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15) 161 { 162 partonOutputArray->Add(candidate); 163 } 164 } 164 165 } 165 166 } 166 167 } 168 169 } else { 170 171 172 auto entries = event->TaggedEntries("Particle"); 173 174 for (uint64_t entryID : entries) { 175 auto part = dynamic_cast<model::Particle *>(event->GetEntry(entryID)); 176 pid = part->pdg(); 177 status = part->status(); 178 model::XYZF pvector=part->p(); 179 px=pvector.x(); 180 py=pvector.y(); 181 pz=pvector.z(); 182 mass = part->mass(); 183 auto v =part->vertex(); 184 x=v.x(); 185 y=v.y(); 186 z=v.z(); 187 t=v.t(); 188 189 candidate = factory->NewCandidate(); 190 candidate->PID = pid; 191 pdgCode = TMath::Abs(candidate->PID); 192 candidate->Status = status; 193 194 int M1=0; 195 int M2=0; 196 for (int k1=0; k1<part->parent_size(); k1++){ 197 if (k1==0) { 198 auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(0))); 199 M1=mother->barcode(); 200 } 201 if (k1==1) { 202 auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(1))); 203 M2=mother->barcode(); 204 } 167 else 168 { 169 170 auto entries = event->TaggedEntries("Particle"); 171 172 for(uint64_t entryID : entries) 173 { 174 auto part = dynamic_cast<model::Particle *>(event->GetEntry(entryID)); 175 pid = part->pdg(); 176 status = part->status(); 177 model::XYZF pvector = part->p(); 178 px = pvector.x(); 179 py = pvector.y(); 180 pz = pvector.z(); 181 mass = part->mass(); 182 auto v = part->vertex(); 183 x = v.x(); 184 y = v.y(); 185 z = v.z(); 186 t = v.t(); 187 188 candidate = factory->NewCandidate(); 189 candidate->PID = pid; 190 pdgCode = TMath::Abs(candidate->PID); 191 candidate->Status = status; 192 193 int M1 = 0; 194 int M2 = 0; 195 for(int k1 = 0; k1 < part->parent_size(); k1++) 196 { 197 if(k1 == 0) 198 { 199 auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(0))); 200 M1 = mother->barcode(); 201 } 202 if(k1 == 1) 203 { 204 auto mother = dynamic_cast<model::Particle *>(event->GetEntry(part->parent(1))); 205 M2 = mother->barcode(); 206 } 207 } 208 209 int D1 = 0; 210 int D2 = 0; 211 for(int k1 = 0; k1 < part->child_size(); k1++) 212 { 213 if(k1 == 0) 214 { 215 auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(0))); 216 D1 = child->barcode(); 217 } 218 219 if(k1 == 1) 220 { 221 auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(1))); 222 D2 = child->barcode(); 223 }; 224 } 225 226 candidate->M1 = M1; 227 candidate->M2 = M2; 228 candidate->D1 = D1; 229 candidate->D2 = D2; 230 231 pdgParticle = pdg->GetParticle(pid); 232 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge() / 3.0) : -999; 233 candidate->Mass = mass; 234 235 candidate->Momentum.SetXYZM(px, py, pz, mass); 236 237 candidate->Position.SetXYZT(x, y, z, t); 238 239 allParticleOutputArray->Add(candidate); 240 241 if(!pdgParticle) continue; 242 243 if(status == 1) 244 { 245 stableParticleOutputArray->Add(candidate); 246 } 247 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15) 248 { 249 partonOutputArray->Add(candidate); 250 } 205 251 } 206 252 207 208 int D1=0; 209 int D2=0; 210 for (int k1=0; k1<part->child_size(); k1++){ 211 if (k1==0) { 212 auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(0))); 213 D1=child->barcode(); 214 } 215 216 if (k1==1) { 217 auto child = dynamic_cast<model::Particle *>(event->GetEntry(part->child(1))); 218 D2=child->barcode(); 219 }; 220 } 221 222 223 candidate->M1 = M1; 224 candidate->M2 = M2; 225 candidate->D1 = D1; 226 candidate->D2 = D2; 227 228 pdgParticle = pdg->GetParticle(pid); 229 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999; 230 candidate->Mass = mass; 231 232 candidate->Momentum.SetXYZM(px, py, pz, mass); 233 234 candidate->Position.SetXYZT(x, y, z, t); 235 236 allParticleOutputArray->Add(candidate); 237 238 if(!pdgParticle) continue; 239 240 if(status == 1) 241 { 242 stableParticleOutputArray->Add(candidate); 243 } 244 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15) 245 { 246 partonOutputArray->Add(candidate); 247 } 248 249 } 250 251 252 } // end particle type 253 253 } // end particle type 254 254 } 255 255 … … 283 283 if(argc < 4) 284 284 { 285 cout << " Usage: " << appName << " config_file" << " output_file" << " input_file(s)" << endl; 285 cout << " Usage: " << appName << " config_file" 286 << " output_file" 287 << " input_file(s)" << endl; 286 288 cout << " config_file - configuration file in Tcl format," << endl; 287 289 cout << " output_file - output file in ROOT format," << endl; … … 330 332 cout << "** INFO: Reading " << argv[i] << endl; 331 333 332 inputFile =new proio::Reader( argv[i]);334 inputFile = new proio::Reader(argv[i]); 333 335 334 336 if(inputFile == NULL) … … 338 340 } 339 341 340 341 /* 342 /* 342 343 // this is slow method, but general 343 344 inputFile->SeekToStart(); … … 350 351 */ 351 352 352 353 auto event = new proio::Event(); 354 355 356 double varint_energy=0; 357 double varint_length=0; 358 359 360 auto max_n_events = std::numeric_limits<uint64_t>::max(); 361 auto nn = inputFile->Skip(max_n_events); 362 cout << "** INFO: " << nn-1 << " events found in ProIO file" << endl; 363 inputFile->SeekToStart(); 364 numberOfEvents = nn-1; // last event has only metadata (no particle record) 365 366 if(numberOfEvents <= 0) continue; 367 368 ExRootProgressBar progressBar(numberOfEvents - 1); 369 353 auto event = new proio::Event(); 354 355 double varint_energy = 0; 356 double varint_length = 0; 357 358 auto max_n_events = std::numeric_limits<uint64_t>::max(); 359 auto nn = inputFile->Skip(max_n_events); 360 cout << "** INFO: " << nn - 1 << " events found in ProIO file" << endl; 361 inputFile->SeekToStart(); 362 numberOfEvents = nn - 1; // last event has only metadata (no particle record) 363 364 if(numberOfEvents <= 0) continue; 365 366 ExRootProgressBar progressBar(numberOfEvents - 1); 370 367 371 368 // Loop over all objects … … 376 373 for(eventCounter = 0; eventCounter < numberOfEvents && !interrupted; ++eventCounter) 377 374 { 378 inputFile->Next(event); 375 inputFile->Next(event); 379 376 if(event == 0) continue; 380 377 381 // get metadata 382 if (eventCounter == 0) { 383 auto metadata = event->Metadata(); 384 std::cout << "** INFO: ProIO file metadata:" << std::endl; 385 for (auto element : metadata) { 386 string key=(string)element.first; 387 string value=(string)(*element.second); 388 std::cout << "** INFO: " << key << " = " << value << std::endl; 389 if (key=="info:varint_energy") varint_energy=std::stod(value); 390 if (key=="info:varint_length") varint_length=std::stod(value); 391 } 392 } 393 378 // get metadata 379 if(eventCounter == 0) 380 { 381 auto metadata = event->Metadata(); 382 std::cout << "** INFO: ProIO file metadata:" << std::endl; 383 for(auto element : metadata) 384 { 385 string key = (string)element.first; 386 string value = (string)(*element.second); 387 std::cout << "** INFO: " << key << " = " << value << std::endl; 388 if(key == "info:varint_energy") varint_energy = std::stod(value); 389 if(key == "info:varint_length") varint_length = std::stod(value); 390 } 391 } 394 392 395 393 readStopWatch.Stop(); … … 397 395 procStopWatch.Start(); 398 396 399 ConvertInput(event, varint_energy, varint_length, 397 ConvertInput(event, varint_energy, varint_length, 400 398 branchEvent, factory, 401 399 allParticleOutputArray, stableParticleOutputArray, 402 400 partonOutputArray, &readStopWatch, &procStopWatch); 403 401 404 402 modularDelphes->ProcessTask(); 405 403 procStopWatch.Stop(); … … 414 412 } 415 413 416 417 414 progressBar.Update(eventCounter, eventCounter, kTRUE); 418 415 progressBar.Finish(); … … 420 417 delete inputFile; 421 418 } 422 423 419 424 420 modularDelphes->FinishTask();
Note:
See TracChangeset
for help on using the changeset viewer.