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
227 std::unique_ptr<McEventCollection> mcEvtCollPtr;
228
230 McEventCollection* mcEvtColl = nullptr;
231
232 if(m_readExisting) {
233 const McEventCollection* oldmcEvtColl = nullptr;
234 CHECK(evtStore()->retrieve(oldmcEvtColl, key));
235 // Fill the new McEventCollection with a copy of the initial HepMC::GenEvent
236 mcEvtCollPtr = std::make_unique<McEventCollection>(*oldmcEvtColl);
237 mcEvtColl = mcEvtCollPtr.get();
238 }
239 else {CHECK(evtStore()->retrieve(mcEvtColl, key));}
240
242 for( mcItr = mcEvtColl->begin(); mcItr != mcEvtColl->end(); ++mcItr ) {
243 HepMC::GenEvent* hepMC = *mcItr;
244
245 // Search HepMC record for particles to be decayed by EvtGen
246 // NOTE: In order to ensure repeatability, we use customized a std::set to obtain
247 // an ordered list of particles to be decayed by EvtGen.
248 std::set<HepMC::GenVertexPtr> visited;
249 std::set<HepMC::GenParticlePtr,ParticleIdCompare> toBeDecayed;
250 for (auto p: *hepMC) {
251 if ( (!p->production_vertex()) ||
252 (p->production_vertex()->particles_in_size() == 0) ) {
253 StatusCode sc = traverseDecayTree(std::move(p),false,visited,toBeDecayed);
254 if (sc.isFailure())
255 return StatusCode::FAILURE;
256 }
257 }
258 // Print HepMC in tree format if desired (before doing anything)
260 msg(MSG::INFO) << "Printing HepMC record at " << hepMC << " BEFORE running EvtGen:" << endmsg;
262 printHepMC(hepMC,&toBeDecayed);
263 else
264 printHepMC(hepMC);
265 }
266
267
268 // Decay selected particles
269 bool eventPassesCuts(false);
270 int loopCounter(0);
271 while( !eventPassesCuts && loopCounter < m_maxNRepeatedDecays ) {
272
273 for (auto p: toBeDecayed) {
274 if (p == 0) {
275 msg(MSG::ERROR ) << "Overlapping decay tree for particle" << p <<endmsg;
276 return StatusCode::FAILURE;
277 }
278 decayParticle(hepMC,std::move(p));
280 }
281
283 eventPassesCuts = passesUserSelection(hepMC);
284 else
285 eventPassesCuts = true;
286
288 loopCounter++;
289 }
290
291 // Store the number of decay attempts in event weights std::map, only if repeated decays enabled
292
293 if(m_maxNRepeatedDecays > 1) {
294 hepMC->weight("nEvtGenDecayAttempts") = loopCounter;
295 }
296 // Print HepMC in tree format if desired (after finishing all EvtGen decays)
298 msg(MSG::INFO) << "Printing HepMC record at " << hepMC << " AFTER running EvtGen:" << endmsg;
300 printHepMC(hepMC,&toBeDecayed);
301 else
302 printHepMC(hepMC);
303 }
304 }
305
306 if (mcEvtCollPtr) {
307 if(m_outputKeyName!=key) {
308 ATH_CHECK(evtStore()->record(std::move(mcEvtCollPtr),m_outputKeyName));
309 }
310 else {
311 ATH_CHECK(evtStore()->overwrite(std::move(mcEvtCollPtr), m_outputKeyName, true));
312 }
313 }
314
315 return StatusCode::SUCCESS;
316}
317
318
320
322 ATH_MSG_INFO("The following particles were checked and didn't have any decay channels:");
323 if (msgLvl(MSG::INFO)) {
324 std::cout << std::endl;
325 std::cout << " Particle code # Occurences" << std::endl;
326 std::cout << "----------------------------------" << std::endl;
327 for (std::map<int,long>::iterator p = m_noDecayChannels.begin(); p!=m_noDecayChannels.end(); ++p) {
328 int id = p->first;
329 int count = p->second;
330 std::cout << std::setw(14) << id
331 << std::setw(20) << count
332 << std::endl;
333 }
334 std::cout << std::endl;
335 }
336 }
337 ATH_MSG_INFO("Total number of repeated decays: " << m_nRepeatedDecays);
338 ATH_MSG_INFO("EvtInclusiveDecay finalized");
339 return StatusCode::SUCCESS;
340}
341
342
343
344//
345// Recursively traverse the decay tree of a particle p, looking for particles to be
346// decayed by EvtGen. Care is taken to traverse each particle only once.
347// Note that since in each decay tree only the top-most particle will be decayed
348// by EvtGen (with its decay tree being deleted beforehand), we cannot use HepMC's
349// "descendant" iterator.
350//
352 bool isToBeRemoved,
353 std::set<HepMC::GenVertexPtr>& visited,
354 std::set<HepMC::GenParticlePtr,ParticleIdCompare>& toBeDecayed) {
355 ATH_MSG_VERBOSE("Inspecting: " << pdgName(p) << " " << p);
356 if (!isToBeRemoved) {
357 if (isToBeDecayed(p,true)) {
358 toBeDecayed.insert(p);
359 isToBeRemoved = true;
360 ATH_MSG_VERBOSE("Selected particle for decay: " << pdgName(p) << " " << p );
361
362 // In principle we could stop the recursion here. However, to prevent
363 // pathological cases in certain decay trees (in particular from Herwig),
364 // we continue in order to mark all descendants of this particle
365 // as visited. Thus none of these descendants can be flagged for further
366 // decay, even if it has several mothers.
367 }
368 }
369 auto v = p->end_vertex();
370 if (v) {
371 if (visited.insert(v).second) {
372 if ( isToBeRemoved && (v->particles_in_size()>1) && m_checkDecayTree ) {
373 ATH_MSG_WARNING("Found particle to be decayed with vertex with >1 incoming mother particles in decay tree");
374 ATH_MSG_WARNING( ([&p, &v](){ std::stringstream ss; HepMC::Print::line(ss,p); HepMC::Print::line(ss,v); return ss.str();})());
375 }
376 for (auto itp: *v) {
377 ATH_CHECK(traverseDecayTree(std::move(itp),isToBeRemoved,visited,toBeDecayed) );
378 }
379
380 }
381 }
382 return StatusCode::SUCCESS;
383}
384
385
386
387//
388// Remove an existing decay tree
389//
391 auto v = p->end_vertex();
392 if (v) {
393 //This is recursive in HepMC3. But explicit deletion is allowed as well.
394 hepMC->remove_vertex(std::move(v));
395 p->set_status(1); // For now, flag particle as undecayed (stable)
396 ATH_MSG_DEBUG("Removed existing " << pdgName(p) << " " << p );
397 }
398}
399
400
401
402//
403// Decay a particle with EvtGen. Any existing decay tree will be removed.
404//
405// The following status codes are used:
406//
407// status == 1 - undecayed particle (also for particles that are not supposed to decay)
408// status == 2 - particle decayed by EvtGen
409// status == 0 - error, particle was supposed to be decayed by EvtGen, but found no decay channel
410//
411// Note that if a particle with an existing decay tree but no defined decay channels
412// in EvtGen is passed to this routine, the net effect will be to "undecay" this
413// particle. The particle will be flagged by status code 899, but MAY BE LOST further
414// downstream in the simulation chain. The default job parameters are for routine
415// isToBeDecayed() to never enable decays of such particles by EvtGen.
416//
418 ATH_MSG_DEBUG("Decaying particle " << pdgName(part) << " " << part);
419 if (msgLvl(MSG::VERBOSE)) HepMC::Print::line(std::cout,part);
420
421 // Remove existing decay tree, if any, and flag particle as being decayed by EvtGen
422 removeDecayTree(hepMC,part);
423 part->set_status(0);
424
425 // Create EvtGen version of part and have EvtGen decay it.
426 // Since EvtGen uses GeV, convert particles momentum from MeV to GeV.
427 int id = part->pdg_id();
428 EvtId evtId=EvtPDL::evtIdFromStdHep(id);
429 double en =(part->momentum()).e()/1000.;
430 double px=(part->momentum()).px()/1000.;
431 double py=(part->momentum()).py()/1000.;
432 double pz=(part->momentum()).pz()/1000.;
433 EvtVector4R evtP(en,px,py,pz);
434 EvtParticle* evtPart = EvtParticleFactory::particleFactory(evtId,evtP);
435
436 // set transverse polarization to vector mesons (relevant for coherent production of J/Psi etc in UPC)
437 if(m_setVMtransversePol && (id==113 || id== 443 || id==100443 || id==553 || id==100553 || id==200553) )evtPart->setVectorSpinDensity();
438
439 m_myEvtGen->generateDecay(evtPart);
440 if (msgLvl(MSG::VERBOSE)) evtPart->printTree();
441 double ct_s = part->production_vertex()->position().t();
442 double x_s = part->production_vertex()->position().x();
443 double y_s = part->production_vertex()->position().y();
444 double z_s = part->production_vertex()->position().z();
445
446 EvtVector4R treeStart(ct_s,x_s,y_s,z_s);
447 // Add new decay tree to hepMC, converting back from GeV to MeV.
448 addEvtGenDecayTree(hepMC, part, evtPart, treeStart, 1000.);
449 if(evtPart->getNDaug() !=0) part->set_status(2);
450 evtPart->deleteTree();
451}
452
453
454
456 EvtParticle* evtPart, EvtVector4R treeStart, double momentumScaleFactor) {
457 if(evtPart->getNDaug()!=0) {
458 // Add decay vertex, starting from production vertex of particle
459 double ct=(evtPart->getDaug(0)->get4Pos()).get(0)+treeStart.get(0);
460 double x=(evtPart->getDaug(0)->get4Pos()).get(1)+treeStart.get(1);
461 double y=(evtPart->getDaug(0)->get4Pos()).get(2)+treeStart.get(2);
462 double z=(evtPart->getDaug(0)->get4Pos()).get(3)+treeStart.get(3);
463
465
466 hepMC->add_vertex(end_vtx);
467 end_vtx->add_particle_in(std::move(part));
468
469 // Add decay daughter with their own decay trees
470 for(uint it=0; it<evtPart->getNDaug(); it++) {
471 double e=(evtPart->getDaug(it)->getP4Lab()).get(0) * momentumScaleFactor;
472 double px=(evtPart->getDaug(it)->getP4Lab()).get(1) * momentumScaleFactor;
473 double py=(evtPart->getDaug(it)->getP4Lab()).get(2) * momentumScaleFactor;
474 double pz=(evtPart->getDaug(it)->getP4Lab()).get(3) * momentumScaleFactor;
475 int id=EvtPDL::getStdHep(evtPart->getDaug(it)->getId());
476 int status=1;
477 if(evtPart->getDaug(it)->getNDaug() != 0) status=2;
478 HepMC::GenParticlePtr daughter = HepMC::newGenParticlePtr(HepMC::FourVector(px,py,pz,e),id,status);
479 end_vtx->add_particle_out(daughter);
480 addEvtGenDecayTree(hepMC, std::move(daughter), evtPart->getDaug(it), treeStart, momentumScaleFactor);
481 }
482 }
483}
484
485
486
487//
488// isToBeDecayed returns true if we want the particle p to be decayed by
489// EvtGen based on the job options selected by the user.
490// The parameter doCrossChecks is used to prevent double-counting for cross-checks
491// if isToBeDecayed is called more than once for the same particle.
492//
494 int id = p->pdg_id();
495 int nDaughters = 0;
496 auto v = p->end_vertex();
497 if (v) nDaughters = v->particles_out_size();
498
499 // Ignore documentation lines
500 if (p->status() == 3) return false;
501 // And any particles that aren't stable or decayed
502 if(!m_isfHerwig && !MC::isPhysical(p)) return false;
503
504 // Particularly for Herwig, try to ignore particles that really should
505 // be flagged as documentation lines
506 double m2 = p->momentum().m2();
507 if (m2 < -1.0E-3) {
508 ATH_MSG_DEBUG("Ignoring particle " << pdgName(std::move(p)) << " with m^2 = " << m2);
509 return false;
510 }
511
512 // Check whether EvtGen has any decay channels defined for this particle
513 EvtId evtId = EvtPDL::evtIdFromStdHep(id);
514 // std::cout << "EVTID: " << evtId.getId() << " alias " << evtId.getAlias() << std::endl;
515 int nModes = 0;
516 if (evtId.getId()>=0)
517 // nModes = EvtDecayTable::getNMode(evtId.getAlias());
518 nModes = EvtDecayTable::getInstance()->getNMode(evtId.getAlias());
519 if (doCrossChecks) {
520 ATH_MSG_VERBOSE("Checking particle " << pdgName(p)
521 << " (status = " << p->status()
522 <<") -- " << nModes << " decay modes found");
523 if (m_checkDecayChannels && nModes==0) {
524 std::map<int,long>::iterator pos = m_noDecayChannels.find(id);
525 if (pos != m_noDecayChannels.end())
526 (pos->second)++;
527 else
528 m_noDecayChannels[id] = 1;
529 }
530 }
531
532 // Check prohibit* settings
533 if (m_prohibitFinalStateDecay && MC::isStable(p)) return false;
534 if (m_prohibitReDecay && nDaughters>0) return false;
535 if (m_prohibitUnDecay && nModes==0) return false;
536 if (m_prohibitRemoveSelfDecay && nDaughters>0) {
537 // For now, check only children - this should be sufficient and checking all
538 // descendants would be very expensive.
539 for (auto itd: *v) {
540 if (std::abs(itd->pdg_id()) == std::abs(id)) return false;
541 }
542 }
543
544 // Check blackList
545 if (m_blackListSet.count(std::abs(id))>0) return false;
546
547 // Check allow* settings
548 if (m_allowAllKnownDecays && nModes>0) return true;
549 if (m_allowDefaultBDecays && isDefaultB(id)) return true;
550
551 // Check whiteList
552 if (m_whiteListSet.count(std::abs(id))>0) return true;
553
554 return false; // Default is NOT to decay through EvtGen
555}
556
557
558
559//
560// The following mimicks the particle selection implemented in EvtDecay.
561//
562bool EvtInclusiveDecay::isDefaultB(const int pId) const {
563 int id = std::abs(pId);
564 if ( id == 511 ||
565 id == 521 ||
566 id == 531 ||
567 id == 541 ||
568 id == 5122 ||
569 id == 5132 ||
570 id == 5232 ||
571 id == 5112 ||
572 id == 5212 ||
573 id == 5222 )
574 return true;
575 else
576 return false;
577}
578
579//
580// Function to apply the user selection after repeated decay
581// Now the selection is based on di-muon kinematics only
582// TODO: to be replaced by something more configurable
583//
585 bool passed(false);
586 std::vector<HepMC::GenParticlePtr> *muons = new std::vector<HepMC::GenParticlePtr>;
587
588 for ( const auto& p: *hepMC) {
589 if( std::abs(p->pdg_id()) == 13 )
590 muons->push_back(p);
591 }
592
593 for (auto muItr1 = muons->begin(); muItr1 != muons->end(); ++muItr1) {
594 for (auto muItr2 = muItr1+1; muItr2 != muons->end(); ++muItr2) {
595 if( m_userSelRequireOppositeSignedMu && (*muItr1)->pdg_id() * (*muItr2)->pdg_id() > 0)
596 continue;
597 if( !( (*muItr1)->momentum().perp() > m_userSelMu1MinPt && std::abs((*muItr1)->momentum().pseudoRapidity()) < m_userSelMu1MaxEta &&
598 (*muItr2)->momentum().perp() > m_userSelMu2MinPt && std::abs((*muItr2)->momentum().pseudoRapidity()) < m_userSelMu2MaxEta ) &&
599 !( (*muItr2)->momentum().perp() > m_userSelMu1MinPt && std::abs((*muItr2)->momentum().pseudoRapidity()) < m_userSelMu1MaxEta &&
600 (*muItr1)->momentum().perp() > m_userSelMu2MinPt && std::abs((*muItr1)->momentum().pseudoRapidity()) < m_userSelMu2MaxEta ) )
601 continue;
602 double dimuMass = invMass((*muItr1),(*muItr2));
603 if( !( dimuMass > m_userSelMinDimuMass && (dimuMass < m_userSelMaxDimuMass || m_userSelMaxDimuMass < 0.) ) )
604 continue;
605 passed = true;
606 }
607 }
608
609 delete muons;
610
611 return passed;
612}
613
615 double p1Px = p1->momentum().px();
616 double p1Py = p1->momentum().py();
617 double p1Pz = p1->momentum().pz();
618 double p1E = p1->momentum().e();
619 double p2Px = p2->momentum().px();
620 double p2Py = p2->momentum().py();
621 double p2Pz = p2->momentum().pz();
622 double p2E = p2->momentum().e();
623 double dimuE = p2E + p1E;
624 double dimuPx = p2Px + p1Px;
625 double dimuPy = p2Py + p1Py;
626 double dimuPz = p2Pz + p1Pz;
627 double invMass = std::sqrt(dimuE*dimuE - dimuPx*dimuPx - dimuPy*dimuPy - dimuPz*dimuPz);
628
629 return invMass;
630}
631
632//
633// Utility functions to print a HepMC event record in a tree-like format, using
634// colors to denote the status of particles and to indicate which particles
635// are selected by the job options to be decayed by EvtGen.
636//
637
638void EvtInclusiveDecay::printHepMC(HepMC::GenEvent* hepMC, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
639 std::set<HepMC::GenVertexPtr> visited;
640 unsigned int nParticlesFound = 0;
641 unsigned int nTreesFound = 0;
642 for (auto p: *hepMC) {
643 if ( (!p->production_vertex()) ||
644 (p->production_vertex()->particles_in_size() == 0) ) {
645 nTreesFound++;
646 std::cout << "\n Found new partial decay tree:\n" << std::endl;
647 unsigned int nParticlesVisited = printTree(std::move(p),visited,1,particleSet);
648 std::cout << "\n " << nParticlesVisited << " particles in this subtree" << std::endl;
649 nParticlesFound += nParticlesVisited;
650 }
651 }
652 std::cout << "\n Total of " << nParticlesFound << " particles found in "
653 << nTreesFound << " decay subtrees in HepMC event record\n" << std::endl;
654}
655
656unsigned int EvtInclusiveDecay::printTree(HepMC::GenParticlePtr p, std::set<HepMC::GenVertexPtr>& visited, int level, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
657
658 unsigned int nParticlesVisited = 1;
659 for (int i=0; i<level; i++) std::cout << " ";
660 std::cout << pdgName(p,m_printHepMCHighlighted,particleSet);
661 auto v = p->end_vertex();
662 if (v) {
663 if (v->particles_in_size() > 1)
664 std::cout << " [interaction: " << v->particles_in_size() << " particles, vertex " << v << "] --> ";
665 else
666 std::cout << " --> ";
667 if (visited.insert(v).second) {
668 for (auto itp: *v) {
669 std::cout << pdgName(itp,m_printHepMCHighlighted,particleSet) << " ";
670 }
671 std::cout << std::endl;
672 for (auto itp: *v) {
673 if (itp->end_vertex())
674 nParticlesVisited += printTree(std::move(itp), visited, level+1, particleSet);
675 else
676 nParticlesVisited++;
677 }
678 } else
679 std::cout << "see above" << std::endl;
680 } else
681 std::cout << " no decay vertex\n" << std::endl;
682 return nParticlesVisited;
683}
684
685std::string EvtInclusiveDecay::pdgName(HepMC::ConstGenParticlePtr p, bool statusHighlighting, std::set<HepMC::GenParticlePtr,ParticleIdCompare>* particleSet) {
686 std::ostringstream buf;
687 bool inlist = false;
688 if (particleSet) for (const auto& pinl: *particleSet) if (pinl&&p) if (pinl.get() == p.get()) inlist=true;
689 if (statusHighlighting) {
690 if ( ((particleSet!=0) && (inlist)) ||
691 ((particleSet==0) && isToBeDecayed(p,false)) )
692 buf << "\033[7m"; // reverse
693 if (p and !MC::isStable(p)) {
694 if (MC::isDecayed(p))
695 buf << "\033[33m"; // yellow
696 else
697 buf << "\033[31m"; // red
698 }
699 }
700 if (p){
701 buf << p->pdg_id();
702 if (statusHighlighting) {
703 buf << "\033[0m"; // revert color attributes
704 }
705 }
706 return buf.str();
707}
708
709
710//
711// Interface between Athena random number service and EvtGen's EvtRandomEngine class
712//
713EvtInclusiveAtRndmGen::EvtInclusiveAtRndmGen(CLHEP::HepRandomEngine* engine)
714 : m_engine(engine)
715{}
716
718 return CLHEP::RandFlat::shoot(m_engine);
719}
720
722
724 return PathResolverFindCalibDirectory( "Pythia8/xmldoc" );
725}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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:841
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
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)
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.