ATLAS Offline Software
MergeMcEventCollTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MCTRUTHSIMALGS_MERGEMCEVENTCOLLTOOL_H
6 #define MCTRUTHSIMALGS_MERGEMCEVENTCOLLTOOL_H
7 
9 
10 #include "Gaudi/Property.h"
11 #include "GaudiKernel/ServiceHandle.h"
12 #include "GaudiKernel/PhysicalConstants.h"
13 
14 #include <utility> /* pair */
15 
16 class McEventCollection;
17 
20 #include "AtlasHepMC/HeavyIon.h"
29 public:
30  MergeMcEventCollTool(const std::string& type,
31  const std::string& name,
32  const IInterface* parent);
33  virtual StatusCode initialize() override final;
36  virtual StatusCode prepareEvent(const EventContext& ctx, unsigned int nInputEvents) override final;
39  virtual StatusCode mergeEvent(const EventContext& ctx) override final;
42  virtual StatusCode processBunchXing(int bunchXing,
43  SubEventIterator bSubEvents,
44  SubEventIterator eSubEvents) override final;
45 
48  // virtual bool toProcess(int bunchXing) const;
49 
50  virtual StatusCode processAllSubEvents(const EventContext& ctx) override final;
51 
52 private:
53  //** The types used to classify the events. NOPUTYPE is used both as the number of types, and to flag a reject (no type)
55 
56  //** Add the required information from the current GenEvent to the output McEventCollection
57  StatusCode processEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType);
58  //** Special case of processEvent for the first (signal) GenEvent
60  //** Add the required sub-set of the information from the current GenEvent to the output McEventCollection
61  StatusCode processUnfilteredEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType);
62  //** This is for events which have already been truth-filtered. Add the whole GenEvent to the output McEventCollection
63  StatusCode processTruthFilteredEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType);
64  //** Remove any empty background GenEvents from the output McEventCollection
66  //** Print out detailed debug info if required.
68  //** Ensure that any GenEvent::HeavyIon info is stored in the signal GenEvent.
70  //** Classify the current GenParticle according to the MC Truth Taskforce requirements
71  MergeMcEventCollTool::puType classifyVertex(const HepMC::ConstGenParticlePtr& pCurrentVertexParticle, const HepMC::ConstGenVertexPtr& pCurrentParticleProductionVertex, double currentEventTime);
72  //** Check if the current GenVertex contains beam particles
73  bool isInitialCollisionVertex(const HepMC::ConstGenVertexPtr& pCurrentVertex) const;
74  //** Check whether the current McEventCollection has already been truth-filtered
75  bool isTruthFiltertedMcEventCollection(const McEventCollection *pMcEvtColl) const;
76  //** Map from GenEvent to puType FIXME: Simpler to key the map on GenEvent* ?
77  typedef std::map<std::pair<int,int>, int> PileUpBackgroundMap;
79  //** Update the map of GenEvent->puType
80  void updateClassificationMap(int signal_process_id, int event_number, int hack, int classification, bool firstUpdateForThisEvent);
81 
82  ServiceHandle<PileUpMergeSvc> m_pMergeSvc{this, "PileUpMergeSvc", "PileUpMergeSvc", "Handle for the PileUpMergeSvc (provides input McEventCollections)"};
83  //** New McEventCollection to be written out to file
85  StringProperty m_truthCollInputKey{this, "TruthCollInputKey", "TruthEvent", "Name of input McEventCollection"};
86  StringProperty m_truthCollOutputKey{this, "TruthCollOutputKey", "TruthEvent", "Name of output McEventCollection"};
87  BooleanProperty m_keepUnstable{this, "KeepUnstable", false, "Do not cut unstable particles"};
88  DoubleProperty m_absEtaMax{this, "AbsEtaMax", 5.0, "Eta cut-off for INTIME GenParticles"};
89  DoubleProperty m_absEtaMax_outOfTime{this,"OutOfTimeAbsEtaMax", 3.0, "Eta cut-off for OUTOFTIME GenParticles"};
90  DoubleProperty m_lowTimeToKeep{this, "LowTimeToKeep", -51.0, "leading edge in ns of the time window to keep if SaveOutOfTimePileUp is true"};
91  DoubleProperty m_highTimeToKeep{this, "HighTimeToKeep", 51.0, "trailing edge in ns of the time window to keep if SaveOutOfTimePileUp is true"};
92  //** Radius acceptance cut on production vertex of all stable particles (in mm)
93  DoubleProperty m_rRange{this, "rRange", 20.0*Gaudi::Units::mm, "rRange of production vertex in mm"};
94  //** Radius acceptance squared to speed up cut
95  double m_r2Range{400.0};
96  //** Cut on Z coordinate of production vertex in mm, to distinguish between minbias and cavern background categories
97  DoubleProperty m_zRange{this, "zRange", 200.0*Gaudi::Units::mm, "z range of production vertex in mm"};
98  DoubleProperty m_ptMin{this, "ptMin", 0.4*Gaudi::Units::GeV, "Minimum threshold for pT for selected pileup particles in MeV"};
99  DoubleProperty m_minKinE{this, "EKinMin", 1.0*Gaudi::Units::MeV, "Minimum threshold for Kinetic Energy of selected cavern events in MeV"};
100  //** save minimum bias events in the t0 bunch xing
101  BooleanProperty m_saveInTimePileup{this, "SaveInTimeMinBias", true, "save min bias particles in the t0 xing"};
102  //** save minbias events which are "close" by (within [ m_lowTimeToKeep, m_highTimeToKeep ])
103  BooleanProperty m_saveOutOfTimePileup{this, "SaveOutOfTimeMinBias", true, "save out of time min bias particles in the [LowTimeToKeep:HighTimeToKeep] range"};
104  //** save as well the rest of minbias
105  BooleanProperty m_saveRestOfPileup{this, "SaveRestOfMinBias", false, "save the rest of out of time min bias particles as well"};
106  //** save as well the cavern background
107  BooleanProperty m_saveCavernBackground{this, "SaveCavernBackground", true, "save the cavern background as well"};
108  //** do the slimming - flag to do slimming or not
109  BooleanProperty m_doSlimming{this, "DoSlimming", true, "flag to do the slimming or save everything"};
110  //** Should any details of GenEvents corresponding to each puType be saved?
112  //** The index (before sorting) within the McEventCollection where the background events start
114  //** Bool to indicate that the next GenEvent is a new signal event
115  bool m_newevent{true};
116  //** The total number of GenEvents that will be passed for the current signal event
117  unsigned int m_nInputMcEventColls{0};
118  //** How many background events have been read so far for this signal event
119  unsigned int m_nBkgEventsReadSoFar{0};
120  //** Ensure that the collision GenVertex objects of minbias background events are saved.
121  BooleanProperty m_addBackgroundCollisionVertices{this, "AddBackgroundCollisionVertices", true, "ensure that the collision GenVertex objects of minbias background events are saved."};
122  //** Should empty GenEvents be removed from the output McEventCollection?
123  BooleanProperty m_compressOutputCollection{this, "CompressOutputCollection", false, "Remove all empty GenEvents from the output McEventCollection"};
124  //** Just save the Signal GenEvent
125  BooleanProperty m_onlySaveSignalTruth{this, "OnlySaveSignalTruth", false, "Just save the Signal GenEvent"};
126  //** Temporary store for the true signal event number
128 
129 };
130 #endif //MCTRUTHSIMALGS_MERGEMCEVENTCOLLTOOL_H
MergeMcEventCollTool::m_rRange
DoubleProperty m_rRange
Definition: MergeMcEventCollTool.h:93
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
MergeMcEventCollTool::m_saveOutOfTimePileup
BooleanProperty m_saveOutOfTimePileup
Definition: MergeMcEventCollTool.h:103
MergeMcEventCollTool::m_truthCollOutputKey
StringProperty m_truthCollOutputKey
Definition: MergeMcEventCollTool.h:86
MergeMcEventCollTool::INTIME
@ INTIME
Definition: MergeMcEventCollTool.h:54
MergeMcEventCollTool::prepareEvent
virtual StatusCode prepareEvent(const EventContext &ctx, unsigned int nInputEvents) override final
called before the subevts loop.
Definition: MergeMcEventCollTool.cxx:98
MergeMcEventCollTool::m_saveInTimePileup
BooleanProperty m_saveInTimePileup
Definition: MergeMcEventCollTool.h:101
MergeMcEventCollTool::initialize
virtual StatusCode initialize() override final
Definition: MergeMcEventCollTool.cxx:77
MergeMcEventCollTool::printDetailsOfMergedMcEventCollection
void printDetailsOfMergedMcEventCollection() const
Definition: MergeMcEventCollTool.cxx:238
MergeMcEventCollTool::CAVERN
@ CAVERN
Definition: MergeMcEventCollTool.h:54
MergeMcEventCollTool::m_signal_event_number
int m_signal_event_number
Definition: MergeMcEventCollTool.h:127
HepMC::signal_process_id
int signal_process_id(const GenEvent &e)
Definition: GenEvent.h:635
HeavyIon.h
MergeMcEventCollTool::classifyVertex
MergeMcEventCollTool::puType classifyVertex(const HepMC::ConstGenParticlePtr &pCurrentVertexParticle, const HepMC::ConstGenVertexPtr &pCurrentParticleProductionVertex, double currentEventTime)
Definition: MergeMcEventCollTool.cxx:513
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
MergeMcEventCollTool::processUnfilteredEvent
StatusCode processUnfilteredEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType)
Definition: MergeMcEventCollTool.cxx:395
MergeMcEventCollTool::m_lowTimeToKeep
DoubleProperty m_lowTimeToKeep
Definition: MergeMcEventCollTool.h:90
MergeMcEventCollTool::m_saveType
bool m_saveType[NOPUTYPE]
Definition: MergeMcEventCollTool.h:111
MergeMcEventCollTool::processFirstSubEvent
StatusCode processFirstSubEvent(const McEventCollection *pMcEvtColl)
Definition: MergeMcEventCollTool.cxx:257
GenParticle_fwd.h
MergeMcEventCollTool::processEvent
StatusCode processEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType)
Definition: MergeMcEventCollTool.cxx:320
MergeMcEventCollTool::m_newevent
bool m_newevent
Definition: MergeMcEventCollTool.h:115
MergeMcEventCollTool::m_truthCollInputKey
StringProperty m_truthCollInputKey
Definition: MergeMcEventCollTool.h:85
MergeMcEventCollTool::puType
puType
Definition: MergeMcEventCollTool.h:54
MergeMcEventCollTool::m_startingIndexForBackground
unsigned int m_startingIndexForBackground
Definition: MergeMcEventCollTool.h:113
MergeMcEventCollTool::m_absEtaMax
DoubleProperty m_absEtaMax
Definition: MergeMcEventCollTool.h:88
MergeMcEventCollTool::m_pOvrlMcEvColl
McEventCollection * m_pOvrlMcEvColl
Definition: MergeMcEventCollTool.h:84
MergeMcEventCollTool::m_doSlimming
BooleanProperty m_doSlimming
Definition: MergeMcEventCollTool.h:109
MergeMcEventCollTool::processAllSubEvents
virtual StatusCode processAllSubEvents(const EventContext &ctx) override final
return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase...
Definition: MergeMcEventCollTool.cxx:117
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
GenVertex_fwd.h
MergeMcEventCollTool::m_nInputMcEventColls
unsigned int m_nInputMcEventColls
Definition: MergeMcEventCollTool.h:117
MergeMcEventCollTool::m_nBkgEventsReadSoFar
unsigned int m_nBkgEventsReadSoFar
Definition: MergeMcEventCollTool.h:119
MergeMcEventCollTool::MergeMcEventCollTool
MergeMcEventCollTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MergeMcEventCollTool.cxx:70
MergeMcEventCollTool::saveHeavyIonInfo
StatusCode saveHeavyIonInfo(const McEventCollection *pMcEvtColl)
Definition: MergeMcEventCollTool.cxx:355
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MergeMcEventCollTool::OUTOFTIME
@ OUTOFTIME
Definition: MergeMcEventCollTool.h:54
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
MergeMcEventCollTool::updateClassificationMap
void updateClassificationMap(int signal_process_id, int event_number, int hack, int classification, bool firstUpdateForThisEvent)
Definition: MergeMcEventCollTool.cxx:585
PileUpToolBase
Definition: PileUpToolBase.h:18
MergeMcEventCollTool::m_highTimeToKeep
DoubleProperty m_highTimeToKeep
Definition: MergeMcEventCollTool.h:91
MergeMcEventCollTool::PileUpBackgroundMap
std::map< std::pair< int, int >, int > PileUpBackgroundMap
Definition: MergeMcEventCollTool.h:77
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
MergeMcEventCollTool::m_backgroundClassificationMap
PileUpBackgroundMap m_backgroundClassificationMap
Definition: MergeMcEventCollTool.h:78
MergeMcEventCollTool::mergeEvent
virtual StatusCode mergeEvent(const EventContext &ctx) override final
called at the end of the subevts loop.
Definition: MergeMcEventCollTool.cxx:209
MergeMcEventCollTool::m_addBackgroundCollisionVertices
BooleanProperty m_addBackgroundCollisionVertices
Definition: MergeMcEventCollTool.h:121
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MergeMcEventCollTool
a PileUpTool to merge MC truth collection in the overlay store
Definition: MergeMcEventCollTool.h:28
MergeMcEventCollTool::NOPUTYPE
@ NOPUTYPE
Definition: MergeMcEventCollTool.h:54
MergeMcEventCollTool::m_minKinE
DoubleProperty m_minKinE
Definition: MergeMcEventCollTool.h:99
MergeMcEventCollTool::isInitialCollisionVertex
bool isInitialCollisionVertex(const HepMC::ConstGenVertexPtr &pCurrentVertex) const
Definition: MergeMcEventCollTool.cxx:498
MergeMcEventCollTool::m_saveCavernBackground
BooleanProperty m_saveCavernBackground
Definition: MergeMcEventCollTool.h:107
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
MergeMcEventCollTool::processBunchXing
virtual StatusCode processBunchXing(int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents) override final
called for each active bunch-crossing to process current SubEvents bunchXing is in ns
Definition: MergeMcEventCollTool.cxx:185
MergeMcEventCollTool::isTruthFiltertedMcEventCollection
bool isTruthFiltertedMcEventCollection(const McEventCollection *pMcEvtColl) const
Definition: MergeMcEventCollTool.cxx:308
MergeMcEventCollTool::m_saveRestOfPileup
BooleanProperty m_saveRestOfPileup
Definition: MergeMcEventCollTool.h:105
MergeMcEventCollTool::m_compressOutputCollection
BooleanProperty m_compressOutputCollection
Definition: MergeMcEventCollTool.h:123
MergeMcEventCollTool::m_keepUnstable
BooleanProperty m_keepUnstable
Definition: MergeMcEventCollTool.h:87
MergeMcEventCollTool::RESTOFMB
@ RESTOFMB
Definition: MergeMcEventCollTool.h:54
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MergeMcEventCollTool::m_onlySaveSignalTruth
BooleanProperty m_onlySaveSignalTruth
Definition: MergeMcEventCollTool.h:125
MergeMcEventCollTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: MergeMcEventCollTool.h:82
MergeMcEventCollTool::m_ptMin
DoubleProperty m_ptMin
Definition: MergeMcEventCollTool.h:98
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
MergeMcEventCollTool::m_zRange
DoubleProperty m_zRange
Definition: MergeMcEventCollTool.h:97
MergeMcEventCollTool::compressOutputMcEventCollection
StatusCode compressOutputMcEventCollection()
Definition: MergeMcEventCollTool.cxx:561
PileUpToolBase.h
helper base class IPileUpTool::toProcess().
MergeMcEventCollTool::processTruthFilteredEvent
StatusCode processTruthFilteredEvent(const McEventCollection *pMcEvtColl, const double currentEventTime, const int currentBkgEventIndex, int pileupType)
Definition: MergeMcEventCollTool.cxx:371
MergeMcEventCollTool::m_r2Range
double m_r2Range
Definition: MergeMcEventCollTool.h:95
ServiceHandle< PileUpMergeSvc >
MergeMcEventCollTool::m_absEtaMax_outOfTime
DoubleProperty m_absEtaMax_outOfTime
Definition: MergeMcEventCollTool.h:89