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