File indexing completed on 2024-06-29 07:05:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <string>
0011 #include <iostream>
0012
0013 #include <TString.h>
0014 #include <TSystem.h>
0015 #include <TBranch.h>
0016 #include <TLeaf.h>
0017 #include <TDatabasePDG.h>
0018
0019 #include "eicsmear/erhic/Forester.h"
0020 #include "eicsmear/erhic/File.h"
0021
0022 #include "HepMC3/GenEvent.h"
0023 #include "HepMC3/GenVertex.h"
0024 #include "HepMC3/GenParticle.h"
0025 #include "HepMC3/GenCrossSection.h"
0026 #include "HepMC3/Attribute.h"
0027 #include "HepMC3/Version.h"
0028 #include "HepMC3/WriterAscii.h"
0029 #include "HepMC3/WriterAsciiHepMC2.h"
0030 #include "HepMC3/WriterRoot.h"
0031 #include "HepMC3/WriterRootTree.h"
0032
0033 #include <map>
0034
0035 using std::cout;
0036 using std::cerr;
0037 using std::endl;
0038
0039 using HepMC3::FourVector;
0040 using HepMC3::GenRunInfo;
0041 using HepMC3::GenEvent;
0042 using HepMC3::GenParticle;
0043 using HepMC3::GenParticlePtr;
0044 using HepMC3::GenVertex;
0045 using HepMC3::GenVertexPtr;
0046 using HepMC3::GenCrossSection;
0047 using HepMC3::GenCrossSectionPtr;
0048
0049
0050
0051
0052
0053
0054
0055
0056 Long64_t TreeToHepMC(const std::string& inputFileName,
0057 const std::string& outputDirName,
0058 Long64_t maxEvent,
0059 const erhic::HepMC_outtype outtype) {
0060
0061
0062 if ( !TString(inputFileName).EndsWith(".root", TString::kIgnoreCase) ){
0063 cerr << "Warning: " << inputFileName << " does not end with .root" << endl;
0064 }
0065
0066
0067
0068 TFile inFile(inputFileName.c_str(), "READ");
0069 if (!inFile.IsOpen()) {
0070 std::cerr << "Unable to open " << inputFileName << std::endl;
0071 }
0072 TTree* mcTree(NULL);
0073
0074 inFile.GetObject("EICTree", mcTree);
0075 if (!mcTree) {
0076 std::cerr << "Unable to find EICTree in " << inputFileName << std::endl;
0077 return 1;
0078 }
0079 erhic::EventMC* inEvent(NULL);
0080 mcTree->SetBranchAddress("event",&inEvent);
0081
0082
0083 TClass* branchClass = TClass::GetClass(mcTree->GetBranch("event")->GetClassName());
0084 TString generatorname = branchClass->GetName();
0085 if (branchClass->InheritsFrom("erhic::EventDis")) {
0086 generatorname.ReplaceAll("erhic::Event","");
0087 } else {
0088 cerr << branchClass->GetName() << " is not supported." << endl;
0089 return -1;
0090 }
0091
0092
0093 bool beaglemode=false;
0094 if (branchClass->InheritsFrom("erhic::EventBeagle")) {
0095 cout << "Warning: BeAGLE support is rudimentary. Can't fix mother-daughter structure." << endl;
0096 cout << endl;
0097 beaglemode=true;
0098 }
0099
0100
0101 bool legacymilou=false;
0102 bool milouwarn=false;
0103 if (branchClass->InheritsFrom("erhic::EventMilou")) {
0104 legacymilou=true;
0105 }
0106
0107
0108 std::shared_ptr<GenRunInfo> run = std::make_shared<GenRunInfo>();
0109 struct GenRunInfo::ToolInfo generator={
0110 std::string(generatorname),
0111 std::string("unknown version"),
0112 std::string("Used generator")
0113 };
0114 run->tools().push_back(generator);
0115
0116
0117
0118
0119
0120
0121 std::vector<std::string> wnames;
0122 if (!wnames.size()) wnames.push_back("default");
0123 run->set_weight_names(wnames);
0124
0125
0126
0127
0128
0129
0130 double crossSection = 1.0;
0131 double crossSectionError = 0.0;
0132
0133
0134
0135 std::vector <string> RunAttributes = {"crossSection", "crossSectionError", "nEvents", "nTrials" };
0136 for ( auto att : RunAttributes ){
0137 TObjString* ObjString(nullptr);
0138 inFile.GetObject(att.c_str(), ObjString);
0139 if (ObjString) {
0140 double value = std::atof(ObjString->String());
0141 if ( att == "crossSection" ) {
0142
0143 value *=1e6;
0144 crossSection = value;
0145 }
0146 if ( att == "crossSectionError" ){
0147
0148 value *=1e6;
0149 crossSectionError = value;
0150 }
0151 cout << " Adding to the header: " << att << " " << value << endl;
0152 run->add_attribute( att, std::make_shared<HepMC3::DoubleAttribute>( value )) ;
0153 }
0154 }
0155
0156
0157
0158
0159 TString outName = gSystem->BaseName(inputFileName.c_str());
0160
0161 outName.Replace(outName.Last('.'), outName.Length(), "");
0162 outName.Append(".hepmc");
0163
0164 TString outDir(outputDirName);
0165 if (!outDir.EndsWith("/")) outDir.Append('/');
0166 outName.Prepend(outDir);
0167
0168
0169
0170 std::shared_ptr<HepMC3::Writer> file;
0171 switch ( outtype ) {
0172 case erhic::HepMC_outtype::HepMC2 :
0173 file = std::make_shared<HepMC3::WriterAsciiHepMC2>(outName.Data(),run);
0174 break;
0175 case erhic::HepMC_outtype::HepMC3 :
0176 file = std::make_shared<HepMC3::WriterAscii>(outName.Data(),run);
0177 break;
0178 case erhic::HepMC_outtype::RootTree :
0179
0180 outName.Append(".root");
0181 file = std::make_shared<HepMC3::WriterRootTree>(outName.Data(),run);
0182
0183 break;
0184 case erhic::HepMC_outtype::Root :
0185
0186 outName.Append(".root");
0187 file = std::make_shared<HepMC3::WriterRoot>(outName.Data(),run);
0188 break;
0189 default :
0190 cerr << "Unknown HepMC_outtype" << endl;
0191 return -1;
0192 break;
0193 }
0194
0195
0196 if (mcTree->GetEntries() < maxEvent || maxEvent < 1) {
0197 maxEvent = mcTree->GetEntries();
0198 }
0199 std::cout <<
0200 "/-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-/"
0201 << std::endl;
0202 std::cout <<
0203 "/ Commencing conversion of " << maxEvent << " events."
0204 << std::endl;
0205 std::cout <<
0206 "/-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-/"
0207 << std::endl;
0208
0209 for (Long64_t i(0); i < maxEvent; i++) {
0210 if (i % 10000 == 0 && i != 0) {
0211 std::cout << "Processing event " << i << std::endl;
0212 }
0213 mcTree->GetEntry(i);
0214
0215
0216
0217 GenEvent hepmc3evt( HepMC3::Units::GEV, HepMC3::Units::CM );
0218 hepmc3evt.set_event_number(i);
0219 hepmc3evt.weights().clear();
0220 hepmc3evt.weights().push_back(1.0);
0221
0222
0223 GenCrossSectionPtr xsec = std::make_shared<GenCrossSection>();
0224 xsec->set_cross_section( crossSection, crossSectionError);
0225 hepmc3evt.set_cross_section(xsec);
0226
0227
0228
0229 auto leaves = mcTree->GetListOfLeaves();
0230 for ( int l = 0 ; l < leaves->GetEntries(); ++l ){
0231 TLeaf* leaf = (TLeaf*) leaves->At(l);
0232 TString lname = leaf->GetName();
0233 TString c = leaf->GetTypeName();
0234 if ( lname.BeginsWith("particles") ) continue;
0235
0236
0237
0238 if ( lname == "weight"){
0239 hepmc3evt.weights().clear();
0240 hepmc3evt.weights().push_back( leaf->GetValue() );
0241 continue;
0242 }
0243
0244 if ( lname.Contains( "char", TString::kIgnoreCase) ) {
0245
0246
0247 continue;
0248 }
0249 if ( lname.Contains( "long", TString::kIgnoreCase) ) {
0250 hepmc3evt.add_attribute(lname.Data(),std::make_shared<HepMC3::LongAttribute>( leaf->GetValue() )) ;
0251 continue;
0252 }
0253 if ( lname.Contains( "int", TString::kIgnoreCase)
0254 || lname.Contains( "short", TString::kIgnoreCase) ) {
0255 hepmc3evt.add_attribute(lname.Data(),std::make_shared<HepMC3::IntAttribute>( leaf->GetValue() )) ;
0256 continue;
0257 }
0258 if ( lname.Contains( "float", TString::kIgnoreCase)
0259 || lname.Contains( "double", TString::kIgnoreCase) ) {
0260 hepmc3evt.add_attribute(lname.Data(),std::make_shared<HepMC3::DoubleAttribute>( leaf->GetValue() )) ;
0261 continue;
0262 }
0263
0264 }
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287 auto beagle_final_index = std::numeric_limits< decltype(inEvent->GetTrack(0)->GetParentIndex())>::max();
0288
0289 if ( beaglemode ){
0290 auto bosonindex=inEvent->ExchangeBoson()->GetIndex();
0291
0292
0293 auto scatteredindex = inEvent->ScatteredLepton()->GetIndex();
0294
0295 for( unsigned int t=0; t<inEvent->GetNTracks(); ++t) {
0296 Particle* inParticle = inEvent->GetTrack(t);
0297 auto myindex = inParticle->GetIndex();
0298
0299
0300
0301 if ( myindex==inEvent->BeamLepton()->GetIndex()
0302 || myindex==inEvent->BeamHadron()->GetIndex()
0303 ) continue;
0304
0305
0306
0307 if ( myindex==scatteredindex ){
0308 inParticle->SetParentIndex( inEvent->BeamLepton()->GetIndex() );
0309 inParticle->SetParentIndex1( 0 );
0310 inParticle->SetChild1Index( 0 );
0311 inParticle->SetChildNIndex( 0 );
0312 continue;
0313 }
0314
0315
0316 if ( myindex==bosonindex ){
0317 inParticle->SetChild1Index( 5 );
0318 inParticle->SetChildNIndex( inEvent->GetNTracks() );
0319 continue;
0320 }
0321
0322 auto pdg = TDatabasePDG::Instance()->GetParticle( inParticle->Id() );
0323
0324 switch (inParticle->GetStatus() ){
0325 case 2 :
0326
0327 if ( !pdg ){
0328 inParticle->SetStatus(12);
0329 } else if ( !TString(pdg->ParticleClass()).Contains("Lepton")
0330 && !TString(pdg->ParticleClass()).Contains("Baryon")
0331 && !TString(pdg->ParticleClass()).Contains("Meson")
0332 ){
0333 inParticle->SetStatus(12);
0334 inParticle->SetParentIndex( bosonindex );
0335 inParticle->SetParentIndex1( 0 );
0336
0337 inParticle->SetChild1Index( beagle_final_index );
0338 inParticle->SetChildNIndex( 0 );
0339 } else{
0340
0341 if ( inParticle->GetChild1Index() == 0 ){
0342 std::cout << "Processing event " << i << std::endl;
0343 std::cout << "Processing track " << t << " with index " << inParticle->GetIndex() << std::endl;
0344 std::cout << "I am a hadron or lepton with status 2, but I do not have children. " << std::endl;
0345 return -1;
0346 }
0347
0348
0349 if ( inParticle->GetParentIndex1()!=0 ){
0350 std::cout << "Processing event " << i << std::endl;
0351 std::cout << "Processing track " << t << " with index " << inParticle->GetIndex() << std::endl;
0352 std::cout << "Warning: I am a hadron or lepton with status 2, but I have too many parents. " << std::endl;
0353 std::cout << "Discarding the older one" << std::endl;
0354
0355 inParticle->SetParentIndex( std::max ( inParticle->GetParentIndex(), inParticle->GetParentIndex1() ) );
0356 inParticle->SetParentIndex1( 0 );
0357 }
0358 auto mom = inParticle->GetParent();
0359 if ( !mom ){
0360 std::cout << "Processing event " << i << std::endl;
0361 std::cout << "Processing track " << t << " with index " << inParticle->GetIndex() << std::endl;
0362 std::cout << "I am a hadron or lepton with status 2, but I have no parents. " << std::endl;
0363 return -1;
0364 }
0365
0366 if ( mom->GetStatus() == 1 ){
0367 std::cout << "Processing event " << i << std::endl;
0368 std::cout << "Processing track " << t << " with index " << inParticle->GetIndex() << std::endl;
0369 std::cout << "I am a hadron or lepton with status 2, but my mother is final. " << std::endl;
0370 return -1;
0371 }
0372 if ( mom->GetStatus() != 2 ){
0373
0374 inParticle->SetParentIndex( beagle_final_index );
0375 inParticle->SetParentIndex1( 0 );
0376 }
0377 }
0378 break;
0379 case 1:
0380 {
0381
0382 auto mom = inParticle->GetParent();
0383 if ( mom ){
0384
0385 if ( mom->GetStatus() == 2 ){
0386
0387 inParticle->SetChild1Index( 0 );
0388 inParticle->SetChildNIndex( 0 );
0389 break;
0390 }
0391 }
0392
0393 inParticle->SetParentIndex( beagle_final_index );
0394 inParticle->SetParentIndex1( 0 );
0395
0396 inParticle->SetChild1Index( 0 );
0397 inParticle->SetChildNIndex( 0 );
0398 break;
0399 }
0400 default :
0401
0402 inParticle->SetParentIndex( bosonindex );
0403 inParticle->SetParentIndex1( 0 );
0404
0405 inParticle->SetChild1Index( beagle_final_index );
0406 inParticle->SetChildNIndex( 0 );
0407 break;
0408 }
0409 }
0410 }
0411
0412 if ( legacymilou && inEvent->BeamLepton()->GetChild1Index()==0 ){
0413 if ( !milouwarn ){
0414 cout << "Warning: Trying to repair legay Milou's parentage issues." << endl;
0415 cout << endl;
0416 milouwarn=true;
0417 }
0418
0419
0420 inEvent->GetTrack(1-1)->SetChild1Index(3);
0421 inEvent->GetTrack(1-1)->SetChildNIndex(4);
0422
0423
0424 inEvent->GetTrack(2-1)->SetChild1Index(6);
0425 inEvent->GetTrack(2-1)->SetChildNIndex(0);
0426
0427
0428 inEvent->GetTrack(3-1)->SetParentIndex(1);
0429 inEvent->GetTrack(3-1)->SetChild1Index(0);
0430 inEvent->GetTrack(3-1)->SetChildNIndex(0);
0431
0432
0433 inEvent->GetTrack(4-1)->SetParentIndex(1);
0434 inEvent->GetTrack(4-1)->SetChild1Index(5);
0435 inEvent->GetTrack(4-1)->SetChildNIndex(0);
0436
0437
0438 inEvent->GetTrack(5-1)->SetParentIndex(4);
0439 inEvent->GetTrack(5-1)->SetChild1Index(0);
0440 inEvent->GetTrack(5-1)->SetChildNIndex(0);
0441
0442
0443 inEvent->GetTrack(6-1)->SetParentIndex(2);
0444 inEvent->GetTrack(6-1)->SetChild1Index(0);
0445 inEvent->GetTrack(6-1)->SetChildNIndex(0);
0446
0447
0448 if (inEvent->GetTrack(7-1) ){
0449 inEvent->GetTrack(7-1)->SetParentIndex(0);
0450 inEvent->GetTrack(7-1)->SetChild1Index(0);
0451 inEvent->GetTrack(7-1)->SetChildNIndex(0);
0452 }
0453 }
0454
0455
0456
0457 if ( !beaglemode ){
0458 for( unsigned int t=0; t<inEvent->GetNTracks(); ++t) {
0459 const Particle* inParticle = inEvent->GetTrack(t);
0460
0461
0462 auto myindex = inParticle->GetIndex();
0463
0464 auto c1 = inParticle->GetChild1Index();
0465 auto cN = inParticle->GetChildNIndex();
0466 if ( cN==0 ) cN =c1;
0467 if ( c1>cN ) std::swap(c1,cN);
0468 if ( c1>0 ) {
0469
0470
0471
0472 bool djangohproblem = false;
0473
0474 for ( UShort_t c = c1; c<=cN; ++c ){
0475 Particle* child = inEvent->GetTrack(c-1);
0476 if ( !child ) {
0477 cerr << "Trying to access a non-existant child" << endl;
0478 cerr << "Event is " << i << " Problem index is " << c << endl;
0479 cerr << "If this is not a djangoh file, please contact the eic-smear developers"<<endl;
0480 djangohproblem = true;
0481 break;
0482 }
0483
0484
0485 auto p1 = child->GetParentIndex();
0486 auto pN = child->GetParentIndex1();
0487 if ( p1>pN ) std::swap(p1,pN);
0488 if ( p1==0 && pN==0 ){
0489 child->SetParentIndex( myindex );
0490 } else if ( p1==0 ) {
0491 if ( pN != myindex ){
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501 }
0502 } else {
0503
0504 cout << "Found more than one parent in a non-BeAGLE file. Please contact the authors." << endl;
0505 return -1;
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530 }
0531 }
0532 if(djangohproblem) continue;
0533 }
0534
0535 auto p1 = inParticle->GetParentIndex();
0536 auto pN = inParticle->GetParentIndex1();
0537 if ( p1>pN ) std::swap(p1,pN);
0538 if ( p1==0 ) p1 =pN;
0539
0540 if (pN > 0){
0541 for ( unsigned int p = p1; p<=pN ; ++p ){
0542 Particle* parent = inEvent->GetTrack(p-1);
0543 auto pc1 = parent->GetChild1Index();
0544 auto pcN = parent->GetChildNIndex();
0545 if ( pc1>pcN ) std::swap(pc1,pcN);
0546 if ( pc1 > myindex ){
0547
0548 parent->SetChild1Index( myindex );
0549 }
0550 if ( pcN < myindex ){
0551
0552 parent->SetChildNIndex( myindex );
0553 }
0554 }
0555 }
0556 }
0557 }
0558
0559
0560 std::vector<GenParticlePtr> hepevt_particles;
0561 hepevt_particles.reserve( inEvent->GetNTracks() );
0562 for( unsigned int t=0; t<inEvent->GetNTracks(); ++t) {
0563 const Particle* inParticle = inEvent->GetTrack(t);
0564
0565 auto status = inParticle->GetStatus();
0566 if ( status==1 ){
0567 if (inParticle->GetNChildren() != 0 ){
0568 cout << "Status is 1 but we have children?" << endl;
0569 inParticle->Print();
0570 }
0571 }
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588 FourVector pv = FourVector( inParticle->GetPx(), inParticle->GetPy(), inParticle->GetPz(),inParticle->GetE() );
0589 int statusHepMC = inParticle->GetStatus();
0590
0591
0592
0593
0594
0595
0596
0597 if ( ! beaglemode && t>3 ){
0598 if (inParticle->GetNChildren() != 0 ){
0599 auto pdg = TDatabasePDG::Instance()->GetParticle( inParticle->Id() );
0600 if ( pdg ){
0601 if ( TString(pdg->ParticleClass()).Contains("Lepton")
0602 || TString(pdg->ParticleClass()).Contains("Baryon")
0603 || TString(pdg->ParticleClass()).Contains("Meson")
0604 ){
0605
0606
0607
0608 statusHepMC = 2;
0609 }
0610 }
0611 }
0612 }
0613
0614
0615
0616
0617
0618
0619
0620
0621 if ( statusHepMC != 1 && statusHepMC != 2 && statusHepMC != 4 ){
0622 while ( statusHepMC <=10 ) statusHepMC+=10;
0623 while ( statusHepMC >200 ) statusHepMC-=10;
0624 }
0625
0626
0627
0628
0629
0630 if( statusHepMC == 4) statusHepMC = 1;
0631
0632
0633 hepevt_particles.push_back( std::make_shared<GenParticle>( pv, inParticle->Id(), statusHepMC ));
0634 hepevt_particles.back()->set_generated_mass( inParticle->GetM() );
0635
0636 }
0637
0638
0639
0640
0641
0642
0643
0644
0645 auto lepton=inEvent->BeamLepton();
0646 int index_lepton = lepton->GetIndex();
0647 if ( index_lepton !=1 ) std::cout << "Warning: Found BeamLepton at " << index_lepton << endl;
0648 auto hep_lepton = hepevt_particles.at( index_lepton-1);
0649 hep_lepton->set_status(4);
0650
0651 auto boson=inEvent->ExchangeBoson();
0652 int index_boson = boson->GetIndex();
0653
0654
0655
0656
0657
0658
0659 auto hep_boson = hepevt_particles.at( index_boson-1);
0660
0661
0662 GenVertexPtr v_lepton = std::make_shared<GenVertex>();
0663 v_lepton->add_particle_in (hep_lepton);
0664 v_lepton->add_particle_out (hep_boson);
0665 hepmc3evt.add_vertex(v_lepton);
0666
0667 auto hadron=inEvent->BeamHadron();
0668 int index_hadron = hadron->GetIndex();
0669 if ( index_hadron !=2 ) std::cout << "Warning: Found BeamHadron at " << index_hadron << endl;
0670 auto hep_hadron = hepevt_particles.at( index_hadron-1);
0671 hep_hadron->set_status(4);
0672 GenVertexPtr v_hadron = std::make_shared<GenVertex>();
0673
0674 v_hadron->add_particle_in (hep_hadron);
0675 hepmc3evt.add_vertex(v_hadron);
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700 GenVertexPtr v_beagle_final = std::make_shared<GenVertex>();
0701 if ( beaglemode ){
0702 v_hadron->add_particle_in(hep_boson);
0703 hepmc3evt.add_vertex( v_beagle_final );
0704
0705
0706
0707 }
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721 for( unsigned int t=0; t<inEvent->GetNTracks(); ++t) {
0722 const Particle* inParticle = inEvent->GetTrack(t);
0723
0724
0725 int index = inParticle->GetIndex();
0726 if ( index==index_lepton || index==index_boson || index==index_hadron) continue;
0727 auto hep_in = hepevt_particles.at( index-1);
0728
0729 auto hep_mom = hep_hadron;
0730 int momindex = inParticle->GetParentIndex();
0731 auto statusHepMC = inParticle->GetStatus();
0732
0733
0734
0735 if (branchClass->InheritsFrom("erhic::EventDjangoh")){
0736 if( statusHepMC==1 && momindex==1 &&
0737 (abs(inParticle->Id())==1 || abs(inParticle->Id())==2 || abs(inParticle->Id())==3 ||
0738 abs(inParticle->Id())==90 || inParticle->Id()==91 || inParticle->Id()==92) ){
0739 momindex+=1;
0740 }
0741 }
0742
0743
0744
0745 if ( beaglemode && statusHepMC==3 ) continue;
0746 if ( beaglemode && statusHepMC==14 ) continue;
0747 if ( beaglemode && statusHepMC==18 ) continue;
0748 if ( beaglemode && statusHepMC==12 ) continue;
0749
0750
0751
0752
0753
0754
0755 if ( momindex == beagle_final_index ){
0756 v_beagle_final->add_particle_out(hep_in);
0757 continue;
0758 }
0759
0760
0761
0762 if ( beaglemode && statusHepMC!=1 && statusHepMC!=2 ){
0763 v_beagle_final->add_particle_in(hep_in);
0764 }
0765
0766
0767 if ( momindex > 0 ){
0768 hep_mom = hepevt_particles.at( momindex-1);
0769 }
0770
0771
0772 auto momend = hep_mom->end_vertex();
0773 if (!momend) {
0774 momend = std::make_shared<GenVertex>();
0775 momend->add_particle_in(hep_mom);
0776 hepmc3evt.add_vertex(momend);
0777 }
0778
0779 momend->add_particle_out(hep_in);
0780
0781
0782 if ( momindex > 1){
0783 auto vnew = inParticle->GetVertex();
0784 momend->set_position( FourVector( vnew.x(), vnew.y(), vnew.z(), 0));
0785 }
0786
0787 }
0788
0789
0790 file->write_event(hepmc3evt);
0791
0792
0793
0794
0795 }
0796
0797 file->close();
0798
0799 Long64_t result = 0;
0800
0801 return result;
0802 }
0803
0804
0805
0806
0807
0808 Long64_t TreeToHepMC(const std::string& inputFileName,
0809 const std::string& outputDirName,
0810 Long64_t maxEvent,
0811 const bool createHepMC2){
0812 if ( createHepMC2 ) {
0813 cout << "Warning, this interface is deprecated, please use:" << endl;
0814 cout << "TreeToHepMC(\""<< inputFileName<< "\",\""<< outputDirName
0815 << "\","<< maxEvent << ","
0816 << "erhic::HepMC_outtype::HepMC2)"
0817 << endl;
0818 return TreeToHepMC(inputFileName,outputDirName,maxEvent,erhic::HepMC_outtype::HepMC2);
0819 } else {
0820 cout << "Warning, this interface is deprecated, please use:" << endl;
0821 cout << "TreeToHepMC(\""<< inputFileName<< "\",\""<< outputDirName
0822 << "\","<< maxEvent << ","
0823 << "erhic::HepMC_outtype::HepMC3)"
0824 << endl;
0825 return TreeToHepMC(inputFileName,outputDirName,maxEvent,erhic::HepMC_outtype::HepMC3);
0826 }
0827
0828
0829
0830
0831
0832
0833
0834
0835 return -1;
0836 }
0837
0838