ATLAS Offline Software
Loading...
Searching...
No Matches
EvtInclusiveDecay.cxx
Go to the documentation of this file.
1//*****************************************************************************
2//
3// Generators/EvtGen_i/EvtInclusiveDecay.h
4//
5// EvtInclusiveDecay is a TopAlg that takes HepMC events from StoreGate and
6// generates particle decays using EvtGen. Depending on job options either all or
7// only a subset of the particles which have decays defined in the EvtGen
8// decay files will be handed to EvtGen. Both undecayed particles and particles
9// with an existing decay tree can be handled (in the latter case,
10// EvtInclusiveDecay will remove the existing decay tree).
11//
12// Written in February 2006 by Juerg Beringer, based in part on the existing
13// EvtDecay module.
14//
15//*****************************************************************************
16
18
19#include "EvtGenBase/EvtAbsRadCorr.hh"
20#include "EvtGenBase/EvtDecayBase.hh"
21#include "EvtGen_i/EvtGenExternal/EvtExternalGenList.hh"
22
23#include "EvtGenBase/EvtVector4R.hh"
24#include "EvtGenBase/EvtParticle.hh"
25#include "EvtGenBase/EvtParticleFactory.hh"
26#include "EvtGen/EvtGen.hh"
27#include "EvtGenBase/EvtRandomEngine.hh"
28#include "EvtGenBase/EvtDecayTable.hh"
29
31
32#include "AtlasHepMC/GenEvent.h"
37
38#include "GaudiKernel/MsgStream.h"
39#include "GaudiKernel/ISvcLocator.h"
40#include "GaudiKernel/DataSvc.h"
43
45#include "CLHEP/Random/RandFlat.h"
46#include "CLHEP/Vector/LorentzVector.h"
48
49#include <stdlib.h>
50#include <sstream>
51#include <map>
52
53
54EvtInclusiveDecay::EvtInclusiveDecay(const std::string& name, ISvcLocator* pSvcLocator):
55 GenBase( name, pSvcLocator ),
57
58 // Basic EvtGen configuration: decay and particle definition files, random number stream
59 declareProperty("pdtFile", m_pdtFile = "inclusive.pdt");
60 declareProperty("decayFile", m_decayFile = "2014inclusive.dec");
61 declareProperty("userDecayFile", m_userDecayFile = "");
62 declareProperty("randomStreamName", m_randomStreamName = "EVTGEN");
63 declareProperty("inputKeyName", m_inputKeyName = "GEN_EVENT");
64 declareProperty("outputKeyName",m_outputKeyName = "GEN_EVENT_EVTGEN");
65 declareProperty("readExisting",m_readExisting=false);
66
67 // Selection of particles to be decayed
68 declareProperty("prohibitFinalStateDecay", m_prohibitFinalStateDecay=false);
69 declareProperty("prohibitReDecay", m_prohibitReDecay=false);
70 declareProperty("prohibitUnDecay", m_prohibitUnDecay=true);
71 declareProperty("prohibitRemoveSelfDecay", m_prohibitRemoveSelfDecay=false);
72 declareProperty("blackList",m_blackList);
73 declareProperty("allowAllKnownDecays", m_allowAllKnownDecays=true);
74 declareProperty("allowDefaultBDecays", m_allowDefaultBDecays=true);
75 declareProperty("whiteList",m_whiteList);
76
77 // Level of output
78 declareProperty("printHepMCBeforeEvtGen", m_printHepMCBeforeEvtGen=false);
79 declareProperty("printHepMCAfterEvtGen", m_printHepMCAfterEvtGen=false);
80 declareProperty("printHepMCHighlighted", m_printHepMCHighlighted=true);
81 declareProperty("printHepMCHighLightTopLevelDecays", m_printHepMCHighLightTopLevelDecays=true);
82
83 // Optional checks
84 declareProperty("checkDecayTree", m_checkDecayTree=false);
85 declareProperty("checkDecayChannels", m_checkDecayChannels=false);
86
87 // Repeated decays
88 declareProperty("maxNRepeatedDecays", m_maxNRepeatedDecays=1);
89
90 // User selection
91 declareProperty("applyUserSelection", m_applyUserSelection=false);
92 declareProperty("userSelRequireOppositeSignedMu", m_userSelRequireOppositeSignedMu=true);
93 declareProperty("userSelMu1MinPt", m_userSelMu1MinPt=0.);
94 declareProperty("userSelMu2MinPt", m_userSelMu2MinPt=0.);
95 declareProperty("userSelMu1MaxEta", m_userSelMu1MaxEta=102.5);
96 declareProperty("userSelMu2MaxEta", m_userSelMu2MaxEta=102.5);
97 declareProperty("userSelMinDimuMass", m_userSelMinDimuMass=0.);
98 declareProperty("userSelMaxDimuMass", m_userSelMaxDimuMass=-1.); // set to negative to not apply cut
99 declareProperty("isfHerwig", m_isfHerwig=false);
100 declareProperty("setVMtransversePol", m_setVMtransversePol=false);
101
102 // We have decided to blacklist Tau decays because we are not sure whether the polarization
103 // would be properly passed to EvtGen
104 m_blackList.push_back(15);
105}
106
107
108
113
114
115
117
119 // Get the random number service
120 CHECK(m_rndmSvc.retrieve());
121
122 msg(MSG::INFO) << "EvtInclusiveDecay initialize" << endmsg;
123 msg(MSG::INFO) << "Particle properties definition file = " << m_pdtFile << endmsg;
124 msg(MSG::INFO) << "Main decay file = " << m_decayFile << endmsg;
125 msg(MSG::INFO) << "User decay file = " << m_userDecayFile << endmsg;
126 msg(MSG::INFO) << "Max number of repeated decays = " << m_maxNRepeatedDecays << endmsg;
127 msg(MSG::INFO) << "EvtInclusiveDecay selection parameters:" << endmsg;
128 msg(MSG::INFO) << "* prohibitFinalStateDecay = " << m_prohibitFinalStateDecay << endmsg;
129 msg(MSG::INFO) << "* prohibitReDecay = " << m_prohibitReDecay << endmsg;
130 msg(MSG::INFO) << "* prohibitUnDecay = " << m_prohibitUnDecay << endmsg;
131 msg(MSG::INFO) << "* prohibitRemoveSelfDecay = " << m_prohibitRemoveSelfDecay << endmsg;
132 msg(MSG::INFO) << "* allowAllKnownDecays = " << m_allowAllKnownDecays << endmsg;
133 msg(MSG::INFO) << "* allowDefaultBDecays = " << m_allowDefaultBDecays << endmsg;
134 msg(MSG::INFO) << "User selection parameters:" << endmsg;
135 msg(MSG::INFO) << "* applyUserSelection = " << m_applyUserSelection << endmsg;
136 msg(MSG::INFO) << "* userSelRequireOppositeSignedMu = " << m_userSelRequireOppositeSignedMu << endmsg;
137 msg(MSG::INFO) << "* userSelMu1MinPt = " << m_userSelMu1MinPt << endmsg;
138 msg(MSG::INFO) << "* userSelMu2MinPt = " << m_userSelMu2MinPt << endmsg;
139 msg(MSG::INFO) << "* userSelMu1MaxEta = " << m_userSelMu1MaxEta << endmsg;
140 msg(MSG::INFO) << "* userSelMu2MaxEta = " << m_userSelMu2MaxEta << endmsg;
141 msg(MSG::INFO) << "* userSelMinDimuMass = " << m_userSelMinDimuMass << endmsg;
142 msg(MSG::INFO) << "* userSelMaxDimuMass = " << m_userSelMaxDimuMass << endmsg;
143
144 // Initialize and print blackList
145 m_blackListSet.insert(m_blackList.begin(),m_blackList.end());
146 msg(MSG::INFO) << "* blackList; = ";
147 for (std::set<int>::iterator i = m_blackListSet.begin(); i!=m_blackListSet.end(); ++i)
148 msg(MSG::INFO) << (*i) << " ";
149 msg(MSG::INFO)<< endmsg;
150
151 // Initialize and print whiteList
152 m_whiteListSet.insert(m_whiteList.begin(),m_whiteList.end());
153 msg(MSG::INFO) << "* whiteList = ";
154 for (std::set<int>::iterator i = m_whiteListSet.begin(); i!=m_whiteListSet.end(); ++i)
155 msg(MSG::INFO) << (*i) << " ";
156 msg(MSG::INFO) << endmsg;
157
158 CLHEP::HepRandomEngine* rndmEngine = getRandomEngineDuringInitialize(m_randomStreamName, m_randomSeed, m_dsid);
159 // Obtain random number generator for EvtGen
160 m_evtAtRndmGen = new EvtInclusiveAtRndmGen(rndmEngine);
161
162 // Create an instance of EvtGen and read particle properties and decay files
163 EvtExternalGenList genList(true,xmlpath(),"gamma");
164 EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
165 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
166
167 // Create the EvtGen generator object
168 // EvtGen myGenerator("decayFile.dec", "evt.pdl", randomEnginePointer,
169 // radCorrEngine, &extraModels);
170
171
172 m_myEvtGen = new EvtGen( m_decayFile.c_str(), m_pdtFile.c_str(), m_evtAtRndmGen, radCorrEngine, &extraModels);
173 if(!m_userDecayFile.empty())
174 m_myEvtGen->readUDecay(m_userDecayFile.c_str());
175
176 return StatusCode::SUCCESS;
177}
178
179
180void EvtInclusiveDecay::reseedRandomEngine(const std::string& streamName,
181 const EventContext& ctx)
182{
183 long seeds[7];
184 ATHRNG::calculateSeedsMC21(seeds, streamName, ctx.eventID().event_number(), m_dsid, m_randomSeed);
185 m_evtAtRndmGen->getEngine()->setSeeds(seeds, 0); // NOT THREAD-SAFE
186}
187
188
189CLHEP::HepRandomEngine* EvtInclusiveDecay::getRandomEngine(const std::string& streamName, unsigned long int randomSeedOffset,
190 const EventContext& ctx) const
191{
192 ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
193 rngWrapper->setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
194 return rngWrapper->getEngine(ctx);
195}
196
197
198CLHEP::HepRandomEngine* EvtInclusiveDecay::getRandomEngineDuringInitialize(const std::string& streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun, unsigned int lbn) const
199{
200 const size_t slot=0;
201 EventContext ctx;
202 ctx.setSlot( slot );
203 ctx.setEventID (EventIDBase (conditionsRun,
204 EventIDBase::UNDEFEVT, // event
205 EventIDBase::UNDEFNUM, // timestamp
206 EventIDBase::UNDEFNUM, // timestamp ns
207 lbn));
209 Atlas::ExtendedEventContext( evtStore()->hiveProxyDict(),
210 conditionsRun) );
211 return getRandomEngine(streamName, randomSeedOffset, ctx);
212}
213
214
215StatusCode EvtInclusiveDecay::execute(const EventContext& ctx) {
216 ATH_MSG_DEBUG("EvtInclusiveDecay executing");
217
219
220 std::string key = m_inputKeyName;
221 // retrieve event from Transient Store (Storegate)
222
223 // Load HepMC info
224 // FIXME should be using Read/WriteHandles here
225 const McEventCollection* oldmcEvtColl{};
226 if(m_readExisting) {
227 CHECK(evtStore()->retrieve(oldmcEvtColl, key));
228 // Fill the new McEventCollection with a copy of the initial HepMC::GenEvent
229 m_mcEvtColl = new McEventCollection(*oldmcEvtColl);
230 }
231 else {CHECK(evtStore()->retrieve(m_mcEvtColl, key));}
232
233 if(m_readExisting) {
234 if(m_outputKeyName!=key) {
236 }
237 }
238
240 for( mcItr = m_mcEvtColl->begin(); mcItr != m_mcEvtColl->end(); ++mcItr ) {
241 HepMC::GenEvent* hepMC = *mcItr;
242
243 // Search HepMC record for particles to be decayed by EvtGen
244 // NOTE: In order to ensure repeatability, we use customized a std::set to obtain
245 // an ordered list of particles to be decayed by EvtGen.
246 std::set<HepMC::GenVertexPtr> visited;
247 std::set<HepMC::GenParticlePtr,ParticleIdCompare> toBeDecayed;
248 for (auto p: *hepMC) {
249 if ( (!p->production_vertex()) ||
250 (p->production_vertex()->particles_in_size() == 0) ) {
251 StatusCode sc = traverseDecayTree(std::move(p),false,visited,toBeDecayed);
252 if (sc.isFailure())
253 return StatusCode::FAILURE;
254 }
255 }
256 // Print HepMC in tree format if desired (before doing anything)
258 msg(MSG::INFO) << "Printing HepMC record at " << hepMC << " BEFORE running EvtGen:" << endmsg;
260 printHepMC(hepMC,&toBeDecayed);
261 else
262 printHepMC(hepMC);
263 }
264
265
266 // Decay selected particles
267 bool eventPassesCuts(false);
268 int loopCounter(0);
269 while( !eventPassesCuts && loopCounter < m_maxNRepeatedDecays ) {
270
271 for (auto p: toBeDecayed) {
272 if (p == 0) {
273 msg(MSG::ERROR ) << "Overlapping decay tree for particle" << p <<endmsg;
274 return StatusCode::FAILURE;
275 }
276 decayParticle(hepMC,std::move(p));
278 }
279
281 eventPassesCuts = passesUserSelection(hepMC);
282 else
283 eventPassesCuts = true;
284
286 loopCounter++;
287 }
288
289 // Store the number of decay attempts in event weights std::map, only if repeated decays enabled
290
291 if(m_maxNRepeatedDecays > 1) {
292 hepMC->weight("nEvtGenDecayAttempts") = loopCounter;
293 }
294 // Print HepMC in tree format if desired (after finishing all EvtGen decays)
296 msg(MSG::INFO) << "Printing HepMC record at " << hepMC << " AFTER running EvtGen:" << endmsg;
298 printHepMC(hepMC,&toBeDecayed);
299 else
300 printHepMC(hepMC);
301 }
302 }
303
304 if(m_readExisting && m_outputKeyName==key) {
306 }
307
308 return StatusCode::SUCCESS;
309}
310
311
313
315 ATH_MSG_INFO("The following particles were checked and didn't have any decay channels:");
316 if (msgLvl(MSG::INFO)) {
317 std::cout << std::endl;
318 std::cout << " Particle code # Occurences" << std::endl;
319 std::cout << "----------------------------------" << std::endl;
320 for (std::map<int,long>::iterator p = m_noDecayChannels.begin(); p!=m_noDecayChannels.end(); ++p) {
321 int id = p->first;
322 int count = p->second;
323 std::cout << std::setw(14) << id
324 << std::setw(20) << count
325 << std::endl;
326 }
327 std::cout << std::endl;
328 }
329 }
330 ATH_MSG_INFO("Total number of repeated decays: " << m_nRepeatedDecays);
331 ATH_MSG_INFO("EvtInclusiveDecay finalized");
332 return StatusCode::SUCCESS;
333}
334
335
336
337//
338// Recursively traverse the decay tree of a particle p, looking for particles to be
339// decayed by EvtGen. Care is taken to traverse each particle only once.
340// Note that since in each decay tree only the top-most particle will be decayed
341// by EvtGen (with its decay tree being deleted beforehand), we cannot use HepMC's
342// "descendant" iterator.
343//
345 bool isToBeRemoved,
346 std::set<HepMC::GenVertexPtr>& visited,
347 std::set<HepMC::GenParticlePtr,ParticleIdCompare>& toBeDecayed) {
348 ATH_MSG_VERBOSE("Inspecting: " << pdgName(p) << " " << p);
349 if (!isToBeRemoved) {
350 if (isToBeDecayed(p,true)) {
351 toBeDecayed.insert(p);
352 isToBeRemoved = true;
353 ATH_MSG_VERBOSE("Selected particle for decay: " << pdgName(p) << " " << p );
354
355 // In principle we could stop the recursion here. However, to prevent
356 // pathological cases in certain decay trees (in particular from Herwig),
357 // we continue in order to mark all descendants of this particle
358 // as visited. Thus none of these descendants can be flagged for further
359 // decay, even if it has several mothers.
360 }
361 }
362 auto v = p->end_vertex();
363 if (v) {
364 if (visited.insert(v).second) {
365 if ( isToBeRemoved && (v->particles_in_size()>1) && m_checkDecayTree ) {
366 ATH_MSG_WARNING("Found particle to be decayed with vertex with >1 incoming mother particles in decay tree");
367 ATH_MSG_WARNING( ([&p, &v](){ std::stringstream ss; HepMC::Print::line(ss,p); HepMC::Print::line(ss,v); return ss.str();})());
368 }
369 for (auto itp: *v) {
370 ATH_CHECK(traverseDecayTree(std::move(itp),isToBeRemoved,visited,toBeDecayed) );
371 }
372
373 }
374 }
375 return StatusCode::SUCCESS;
376}
377
378
379
380//
381// Remove an existing decay tree
382//
384 auto v = p->end_vertex();
385 if (v) {
386 //This is recursive in HepMC3. But explicit deletion is allowed as well.
387 hepMC->remove_vertex(std::move(v));
388 p->set_status(1); // For now, flag particle as undecayed (stable)
389 ATH_MSG_DEBUG("Removed existing " << pdgName(p) << " " << p );
390 }
391}
392
393
394
395//
396// Decay a particle with EvtGen. Any existing decay tree will be removed.
397//
398// The following status codes are used:
399//
400// status == 1 - undecayed particle (also for particles that are not supposed to decay)
401// status == 2 - particle decayed by EvtGen
402// status == 0 - error, particle was supposed to be decayed by EvtGen, but found no decay channel
403//
404// Note that if a particle with an existing decay tree but no defined decay channels
405// in EvtGen is passed to this routine, the net effect will be to "undecay" this
406// particle. The particle will be flagged by status code 899, but MAY BE LOST further
407// downstream in the simulation chain. The default job parameters are for routine
408// isToBeDecayed() to never enable decays of such particles by EvtGen.
409//
411 ATH_MSG_DEBUG("Decaying particle " << pdgName(part) << " " << part);
412 if (msgLvl(MSG::VERBOSE)) HepMC::Print::line(std::cout,part);
413
414 // Remove existing decay tree, if any, and flag particle as being decayed by EvtGen
415 removeDecayTree(hepMC,part);
416 part->set_status(0);
417
418 // Create EvtGen version of part and have EvtGen decay it.
419 // Since EvtGen uses GeV, convert particles momentum from MeV to GeV.
420 int id = part->pdg_id();
421 EvtId evtId=EvtPDL::evtIdFromStdHep(id);
422 double en =(part->momentum()).e()/1000.;
423 double px=(part->momentum()).px()/1000.;
424 double py=(part->momentum()).py()/1000.;
425 double pz=(part->momentum()).pz()/1000.;
426 EvtVector4R evtP(en,px,py,pz);
427 EvtParticle* evtPart = EvtParticleFactory::particleFactory(evtId,evtP);
428
429 // set transverse polarization to vector mesons (relevant for coherent production of J/Psi etc in UPC)
430 if(m_setVMtransversePol && (id==113 || id== 443 || id==100443 || id==553 || id==100553 || id==200553) )evtPart->setVectorSpinDensity();
431
432 m_myEvtGen->generateDecay(evtPart);
433 if (msgLvl(MSG::VERBOSE)) evtPart->printTree();
434 double ct_s = part->production_vertex()->position().t();
435 double x_s = part->production_vertex()->position().x();
436 double y_s = part->production_vertex()->position().y();
437 double z_s = part->production_vertex()->position().z();
438
439 EvtVector4R treeStart(ct_s,x_s,y_s,z_s);
440 // Add new decay tree to hepMC, converting back from GeV to MeV.
441 addEvtGenDecayTree(hepMC, part, evtPart, treeStart, 1000.);
442 if(evtPart->getNDaug() !=0) part->set_status(2);
443 evtPart->deleteTree();
444}
445
446
447
449 EvtParticle* evtPart, EvtVector4R treeStart, double momentumScaleFactor) {
450 if(evtPart->getNDaug()!=0) {
451 // Add decay vertex, starting from production vertex of particle
452 double ct=(evtPart->getDaug(0)->get4Pos()).get(0)+treeStart.get(0);
453 double x=(evtPart->getDaug(0)->get4Pos()).get(1)+treeStart.get(1);
454 double y=(evtPart->getDaug(0)->get4Pos()).get(2)+treeStart.get(2);
455 double z=(evtPart->getDaug(0)->get4Pos()).get(3)+treeStart.get(3);
456
458
459 hepMC->add_vertex(end_vtx);
460 end_vtx->add_particle_in(std::move(part));
461
462 // Add decay daughter with their own decay trees
463 for(uint it=0; it<evtPart->getNDaug(); it++) {
464 double e=(evtPart->getDaug(it)->getP4Lab()).get(0) * momentumScaleFactor;
465 double px=(evtPart->getDaug(it)->getP4Lab()).get(1) * momentumScaleFactor;
466 double py=(evtPart->getDaug(it)->getP4Lab()).get(2) * momentumScaleFactor;
467 double pz=(evtPart->getDaug(it)->getP4Lab()).get(3) * momentumScaleFactor;
468 int id=EvtPDL::getStdHep(evtPart->getDaug(it)->getId());
469 int status=1;
470 if(evtPart->getDaug(it)->getNDaug() != 0) status=2;
471 HepMC::GenParticlePtr daughter = HepMC::newGenParticlePtr(HepMC::FourVector(px,py,pz,e),id,status);
472 end_vtx->add_particle_out(daughter);
473 addEvtGenDecayTree(hepMC, std::move(daughter), evtPart->getDaug(it), treeStart, momentumScaleFactor);
474 }
475 }
476}
477
478
479
480//
481// isToBeDecayed returns true if we want the particle p to be decayed by
482// EvtGen based on the job options selected by the user.
483// The parameter doCrossChecks is used to prevent double-counting for cross-checks
484// if isToBeDecayed is called more than once for the same particle.
485//
487 int id = p->pdg_id();
488 int nDaughters = 0;
489 auto v = p->end_vertex();
490 if (v) nDaughters = v->particles_out_size();
491
492 // Ignore documentation lines
493 if (p->status() == 3) return false;
494 // And any particles that aren't stable or decayed
495 if(!m_isfHerwig && !MC::isPhysical(p)) return false;
496
497 // Particularly for Herwig, try to ignore particles that really should
498 // be flagged as documentation lines
499 double m2 = p->momentum().m2();
500 if (m2 < -1.0E-3) {
501 ATH_MSG_DEBUG("Ignoring particle " << pdgName(std::move(p)) << " with m^2 = " << m2);
502 return false;
503 }
504
505 // Check whether EvtGen has any decay channels defined for this particle
506 EvtId evtId = EvtPDL::evtIdFromStdHep(id);
507 // std::cout << "EVTID: " << evtId.getId() << " alias " << evtId.getAlias() << std::endl;
508 int nModes = 0;
509 if (evtId.getId()>=0)
510 // nModes = EvtDecayTable::getNMode(evtId.getAlias());
511 nModes = EvtDecayTable::getInstance()->getNMode(evtId.getAlias());
512 if (doCrossChecks) {
513 ATH_MSG_VERBOSE("Checking particle " << pdgName(p)
514 << " (status = " << p->status()
515 <<") -- " << nModes << " decay modes found");
516 if (m_checkDecayChannels && nModes==0) {
517 std::map<int,long>::iterator pos = m_noDecayChannels.find(id);
518 if (pos != m_noDecayChannels.end())
519 (pos->second)++;
520 else
521 m_noDecayChannels[id] = 1;
522 }
523 }
524
525 // Check prohibit* settings
526 if (m_prohibitFinalStateDecay && MC::isStable(p)) return false;
527 if (m_prohibitReDecay && nDaughters>0) return false;
528 if (m_prohibitUnDecay && nModes==0) return false;
529 if (m_prohibitRemoveSelfDecay && nDaughters>0) {
530 // For now, check only children - this should be sufficient and checking all
531 // descendants would be very expensive.
532 for (auto itd: *v) {
533 if (std::abs(itd->pdg_id()) == std::abs(id)) return false;
534 }
535 }
536
537 // Check blackList
538 if (m_blackListSet.count(std::abs(id))>0) return false;
539
540 // Check allow* settings
541 if (m_allowAllKnownDecays && nModes>0) return true;
542 if (m_allowDefaultBDecays && isDefaultB(id)) return true;
543
544 // Check whiteList
545 if (m_whiteListSet.count(std::abs(id))>0) return true;
546
547 return false; // Default is NOT to decay through EvtGen
548}
549
550
551
552//
553// The following mimicks the particle selection implemented in EvtDecay.
554//
555bool EvtInclusiveDecay::isDefaultB(const int pId) const {
556 int id = std::abs(pId);
557 if ( id == 511 ||
558 id == 521 ||
559 id == 531 ||
560 id == 541 ||
561 id == 5122 ||
562 id == 5132 ||
563 id == 5232 ||
564 id == 5112 ||
565 id == 5212 ||
566 id == 5222 )
567 return true;
568 else
569 return false;
570}
571
572//
573// Function to apply the user selection after repeated decay
574// Now the selection is based on di-muon kinematics only
575// TODO: to be replaced by something more configurable
576//
578 bool passed(false);
579 std::vector<HepMC::GenParticlePtr> *muons = new std::vector<HepMC::GenParticlePtr>;
580
581 for ( const auto& p: *hepMC) {
582 if( std::abs(p->pdg_id()) == 13 )
583 muons->push_back(p);
584 }
585
586 for (auto muItr1 = muons->begin(); muItr1 != muons->end(); ++muItr1) {
587 for (auto muItr2 = muItr1+1; muItr2 != muons->end(); ++muItr2) {
588 if( m_userSelRequireOppositeSignedMu && (*muItr1)->pdg_id() * (*muItr2)->pdg_id() > 0)
589 continue;
590 if( !( (*muItr1)->momentum().perp() > m_userSelMu1MinPt && std::abs((*muItr1)->momentum().pseudoRapidity()) < m_userSelMu1MaxEta &&
591 (*muItr2)->momentum().perp() > m_userSelMu2MinPt && std::abs((*muItr2)->momentum().pseudoRapidity()) < m_userSelMu2MaxEta ) &&
592 !( (*muItr2)->momentum().perp() > m_userSelMu1MinPt && std::abs((*muItr2)->momentum().pseudoRapidity()) < m_userSelMu1MaxEta &&
593 (*muItr1)->momentum().perp() > m_userSelMu2MinPt && std::abs((*muItr1)->momentum().pseudoRapidity()) < m_userSelMu2MaxEta ) )
594 continue;
595 double dimuMass = invMass((*muItr1),(*muItr2));
596 if( !( dimuMass > m_userSelMinDimuMass && (dimuMass < m_userSelMaxDimuMass || m_userSelMaxDimuMass < 0.) ) )
597 continue;
598 passed = true;
599 }
600 }
601
602 delete muons;
603
604 return passed;
605}
606
608 double p1Px = p1->momentum().px();
609 double p1Py = p1->momentum().py();
610 double p1Pz = p1->momentum().pz();
611 double p1E = p1->momentum().e();
612 double p2Px = p2->momentum().px();
613 double p2Py = p2->momentum().py();
614 double p2Pz = p2->momentum().pz();
615 double p2E = p2->momentum().e();
616 double dimuE = p2E + p1E;
617 double dimuPx = p2Px + p1Px;
618 double dimuPy = p2Py + p1Py;
619 double dimuPz = p2Pz + p1Pz;
620 double invMass = std::sqrt(dimuE*dimuE - dimuPx*dimuPx - dimuPy*dimuPy - dimuPz*dimuPz);
621
622 return invMass;
623}
624
625//
626// Utility functions to print a HepMC event record in a tree-like format, using
627// colors to denote the status of particles and to indicate which particles
628// are selected by the job options to be decayed by EvtGen.
629//
630
631void EvtInclusiveDecay::printHepMC(HepMC::GenEvent* hepMC, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
632 std::set<HepMC::GenVertexPtr> visited;
633 unsigned int nParticlesFound = 0;
634 unsigned int nTreesFound = 0;
635 for (auto p: *hepMC) {
636 if ( (!p->production_vertex()) ||
637 (p->production_vertex()->particles_in_size() == 0) ) {
638 nTreesFound++;
639 std::cout << "\n Found new partial decay tree:\n" << std::endl;
640 unsigned int nParticlesVisited = printTree(std::move(p),visited,1,particleSet);
641 std::cout << "\n " << nParticlesVisited << " particles in this subtree" << std::endl;
642 nParticlesFound += nParticlesVisited;
643 }
644 }
645 std::cout << "\n Total of " << nParticlesFound << " particles found in "
646 << nTreesFound << " decay subtrees in HepMC event record\n" << std::endl;
647}
648
649unsigned int EvtInclusiveDecay::printTree(HepMC::GenParticlePtr p, std::set<HepMC::GenVertexPtr>& visited, int level, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
650
651 unsigned int nParticlesVisited = 1;
652 for (int i=0; i<level; i++) std::cout << " ";
653 std::cout << pdgName(p,m_printHepMCHighlighted,particleSet);
654 auto v = p->end_vertex();
655 if (v) {
656 if (v->particles_in_size() > 1)
657 std::cout << " [interaction: " << v->particles_in_size() << " particles, vertex " << v << "] --> ";
658 else
659 std::cout << " --> ";
660 if (visited.insert(v).second) {
661 for (auto itp: *v) {
662 std::cout << pdgName(itp,m_printHepMCHighlighted,particleSet) << " ";
663 }
664 std::cout << std::endl;
665 for (auto itp: *v) {
666 if (itp->end_vertex())
667 nParticlesVisited += printTree(std::move(itp), visited, level+1, particleSet);
668 else
669 nParticlesVisited++;
670 }
671 } else
672 std::cout << "see above" << std::endl;
673 } else
674 std::cout << " no decay vertex\n" << std::endl;
675 return nParticlesVisited;
676}
677
678std::string EvtInclusiveDecay::pdgName(HepMC::ConstGenParticlePtr p, bool statusHighlighting, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
679 std::ostringstream buf;
680 bool inlist = false;
681 if (particleSet) for (const auto& pinl: *particleSet) if (pinl&&p) if (pinl.get() == p.get()) inlist=true;
682 if (statusHighlighting) {
683 if ( ((particleSet!=0) && (inlist)) ||
684 ((particleSet==0) && isToBeDecayed(p,false)) )
685 buf << "\033[7m"; // reverse
686 if (p and !MC::isStable(p)) {
687 if (MC::isDecayed(p))
688 buf << "\033[33m"; // yellow
689 else
690 buf << "\033[31m"; // red
691 }
692 }
693 if (p){
694 buf << p->pdg_id();
695 if (statusHighlighting) {
696 buf << "\033[0m"; // revert color attributes
697 }
698 }
699 return buf.str();
700}
701
702
703//
704// Interface between Athena random number service and EvtGen's EvtRandomEngine class
705//
706EvtInclusiveAtRndmGen::EvtInclusiveAtRndmGen(CLHEP::HepRandomEngine* engine)
707 : m_engine(engine)
708{}
709
711 return CLHEP::RandFlat::shoot(m_engine);
712}
713
715
717 return PathResolverFindCalibDirectory( "Pythia8/xmldoc" );
718}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
unsigned int uint
static Double_t ss
static Double_t sc
std::string PathResolverFindCalibDirectory(const std::string &logical_file_name)
#define y
#define x
#define z
Define macros for attributes used to control the static checker.
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:154
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:108
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
EvtInclusiveAtRndmGen(CLHEP::HepRandomEngine *engine)
CLHEP::HepRandomEngine * m_engine
void printHepMC(HepMC::GenEvent *hepMC, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
ServiceHandle< IAthRNGSvc > m_rndmSvc
void removeDecayTree(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr p)
void reseedRandomEngine(const std::string &streamName, const EventContext &ctx)
bool isDefaultB(const int pId) const
std::set< int > m_blackListSet
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
void addEvtGenDecayTree(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr part, EvtParticle *evtPart, EvtVector4R treeStart, double momentumScaleFactor=1.0)
std::string m_randomStreamName
IntegerProperty m_dsid
StatusCode traverseDecayTree(HepMC::GenParticlePtr p, bool isToBeRemoved, std::set< HepMC::GenVertexPtr > &visited, std::set< HepMC::GenParticlePtr, ParticleIdCompare > &toBeDecayed)
bool passesUserSelection(HepMC::GenEvent *hepMC)
double invMass(HepMC::ConstGenParticlePtr p1, HepMC::ConstGenParticlePtr p2)
McEventCollection * m_mcEvtColl
std::string m_userDecayFile
std::string xmlpath(void)
std::set< int > m_whiteListSet
IntegerProperty m_randomSeed
Seed for random number engine.
std::vector< int > m_blackList
unsigned int printTree(HepMC::GenParticlePtr p, std::set< HepMC::GenVertexPtr > &visited, int level, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
std::string m_outputKeyName
bool isToBeDecayed(HepMC::ConstGenParticlePtr p, bool doCrossChecks)
std::string pdgName(HepMC::ConstGenParticlePtr p, bool statusHighlighting=false, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
std::map< int, long > m_noDecayChannels
void decayParticle(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr p)
StatusCode execute(const EventContext &ctx)
Execute method.
EvtInclusiveAtRndmGen * m_evtAtRndmGen
EvtInclusiveDecay(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< int > m_whiteList
virtual StatusCode initialize() override
Definition GenBase.cxx:17
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenBase.cxx:11
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
HepMC3::FourVector FourVector
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
void fillBarcodesAttribute(GenEvent *e)
Definition GenEvent.h:393
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isDecayed(const T &p)
Identify if the particle decayed.
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.