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