ATLAS Offline Software
TauolaPP.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "Tauolapp_i/TauolaPP.h"
7 
8 // Tauola header files
9 #include "Tauola/Log.h"
10 #include "Tauola/Tauola.h"
11 #ifdef HEPMC3
12 #include "Tauola/TauolaHepMC3Event.h"
13 namespace Tauolapp
14 {
15 using TauolaHepMCEvent=TauolaHepMC3Event;
16 using TauolaHepMCParticle=TauolaHepMC3Particle;
17 }
18 #else
19 #include "Tauola/TauolaHepMCEvent.h"
20 #endif
21 
22 #include "Tauola/f_Variables.h"
23 
24 // for proper seeding
25 #include "CLHEP/Random/RandFlat.h"
27 
28 // Pointer to random engine
29 CLHEP::HepRandomEngine* TauolaPP::p_rndmEngine = nullptr;
30 
31 double AthenaRandomGenerator ATLAS_NOT_THREAD_SAFE ()
32 {
33  return CLHEP::RandFlat::shoot(TauolaPP::p_rndmEngine);
34 }
35 
36 
37 // Constructor
38 TauolaPP::TauolaPP(const std::string& name, ISvcLocator* pSvcLocator)
39  : AthAlgorithm(name, pSvcLocator)
40 {
41 }
42 
43 
45 
46  ATH_CHECK(m_rndmSvc.retrieve());
48  const long* sip = p_rndmEngine->getSeeds();
49 
50  // Setup and intialise Tauola Interface
51  using Tauolapp::Tauola;
52  Tauola::setSameParticleDecayMode(m_decay_mode_same);
53  Tauola::setOppositeParticleDecayMode(m_decay_mode_opp);
54  // etc.... see Tauola.h for the full list of configurables
55  // Note: some need to be set before (or after) calling Tauola::initialize();
56 
57  // Tauola::setHiggsScalarPseudoscalarMixingAngle(atof(argv[5]));
58  // Tauola::setHiggsScalarPseudoscalarPDG(25);
59 
61 
62  Tauola::setEtaK0sPi(1,0,1); // switches to decay eta K0_S and pi0 1/0 on/off.
66 
67  //call RanLux generator for ++ part of Tauola
68  Tauola::setRandomGenerator(AthenaRandomGenerator);
69 
70  //seeding tauola-fortran generator
71  // See tauola.f: the first parameter should be positive int <900000000
72  Tauola::setSeed(int(std::abs(sip[0])%(900000000)),0,0);
73 
74  //setting tau mass
75  Tauolapp::parmas_.amtau=m_tau_mass;
76 
77  return StatusCode::SUCCESS;
78 }
79 
80 
81 void TauolaPP::reseedRandomEngine(const std::string& streamName, const EventContext& ctx)
82 {
83  long seeds[7];
84  ATHRNG::calculateSeedsMC21(seeds, streamName, ctx.eventID().event_number(), m_dsid, m_randomSeed);
85  p_rndmEngine->setSeeds(seeds, 0); // NOT THREAD-SAFE
86 }
87 
88 
89 CLHEP::HepRandomEngine* TauolaPP::getRandomEngine(const std::string& streamName, unsigned long int randomSeedOffset,
90  const EventContext& ctx) const
91 {
92  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
93  rngWrapper->setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
94  return rngWrapper->getEngine(ctx);
95 }
96 
97 
98 CLHEP::HepRandomEngine* TauolaPP::getRandomEngineDuringInitialize(const std::string& streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun, unsigned int lbn) const
99 {
100  const size_t slot=0;
101  EventContext ctx;
102  ctx.setSlot( slot );
103  ctx.setEventID (EventIDBase (conditionsRun,
104  EventIDBase::UNDEFEVT, // event
105  EventIDBase::UNDEFNUM, // timestamp
106  EventIDBase::UNDEFNUM, // timestamp ns
107  lbn));
109  Atlas::ExtendedEventContext( evtStore()->hiveProxyDict(),
110  conditionsRun) );
111  return getRandomEngine(streamName, randomSeedOffset, ctx);
112 }
113 
114 
116 
117  //Re-seed the random number stream
118  const EventContext& ctx = Gaudi::Hive::currentContext();
119  reseedRandomEngine("TAUOLAPP", ctx);
120 
121  // Load HepMC info
122  // FIXME should be using Read/WriteHandles here
123  const McEventCollection* mcCollptr_const;
124  ATH_CHECK( evtStore()->retrieve(mcCollptr_const, m_key) );
125  // Const_cast to make an event possible to update
126  McEventCollection* mcCollptr = const_cast<McEventCollection*>(mcCollptr_const);
127 
128  // Loop over all events in McEventCollection
129  for (HepMC::GenEvent* evt : *mcCollptr) {
130  // Convert event record to format readable by tauola interface
131  auto t_event = new Tauolapp::TauolaHepMCEvent(evt);
132 
133  // remove tau decays first
134  t_event->undecayTaus();
135  // decay taus
136  t_event->decayTaus();
137  // t_event->getEvent()->print();
138  }
139 
140  return StatusCode::SUCCESS;
141 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
TauolaPP::reseedRandomEngine
void reseedRandomEngine(const std::string &streamName, const EventContext &ctx)
Definition: TauolaPP.cxx:81
TauolaPP::m_key
StringProperty m_key
Event record container key - FIXME should be using Read/WriteHandles here.
Definition: TauolaPP.h:47
TauolaPP::p_rndmEngine
static CLHEP::HepRandomEngine * p_rndmEngine
Definition: TauolaPP.h:35
TauolaPP.h
TauolaPP::m_setRadiation
BooleanProperty m_setRadiation
TAUOLA switch for radiative corrections for leptonic tau decays.
Definition: TauolaPP.h:77
TauolaPP::getRandomEngineDuringInitialize
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
Definition: TauolaPP.cxx:98
TauolaPP::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: TauolaPP.h:50
initialize
void initialize()
Definition: run_EoverP.cxx:894
TauolaPP::m_decay_mode_opp
IntegerProperty m_decay_mode_opp
TAUOLA decay mode of particles with opposite charge as "decay_particle".
Definition: TauolaPP.h:68
TauolaPP::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
Definition: TauolaPP.cxx:89
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ATLAS_NOT_THREAD_SAFE
double AthenaRandomGenerator ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: TauolaPP.cxx:31
TauolaPP::execute
virtual StatusCode execute() override
Pass each event in the McEventCollection to Tauola to (re)decay the taus.
Definition: TauolaPP.cxx:115
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
McEventCollection.h
Atlas::ExtendedEventContext
Definition: ExtendedEventContext.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TauolaPP_Fragment.setRadiationCutOff
setRadiationCutOff
Definition: TauolaPP_Fragment.py:11
TauolaPP_Fragment.spin_correlation
spin_correlation
Definition: TauolaPP_Fragment.py:9
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
TauolaPP::m_setRadiationCutOff
DoubleProperty m_setRadiationCutOff
TAUOLA cut-off for radiative corrections.
Definition: TauolaPP.h:80
AthAlgorithm
Definition: AthAlgorithm.h:47
TauolaPP_Fragment.setRadiation
setRadiation
Definition: TauolaPP_Fragment.py:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
TauolaPP::TauolaPP
TauolaPP(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: TauolaPP.cxx:38
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
ATHRNG::calculateSeedsMC21
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.
Definition: RNGWrapper.cxx:37
TauolaPP::initialize
virtual StatusCode initialize() override
Initialization of Tauola++ and setting of JO configurables.
Definition: TauolaPP.cxx:44
TauolaPP::m_randomSeed
IntegerProperty m_randomSeed
Seed for random number engine.
Definition: TauolaPP.h:56
TauolaPP::m_tau_mass
DoubleProperty m_tau_mass
tau mass to be taken by TAUOLA
Definition: TauolaPP.h:71
Atlas::setExtendedEventContext
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
Definition: ExtendedEventContext.cxx:50
TauolaPP::m_dsid
IntegerProperty m_dsid
Definition: TauolaPP.h:53
TauolaPP::m_spin_correlation
BooleanProperty m_spin_correlation
TAUOLA switch for spin effects.
Definition: TauolaPP.h:74
LB_AnalMapSplitter.lbn
lbn
Definition: LB_AnalMapSplitter.py:28
TauolaPP::m_decay_mode_same
IntegerProperty m_decay_mode_same
TAUOLA decay mode of particles with same charge as "decay_particle".
Definition: TauolaPP.h:65