ATLAS Offline Software
HGTD_RDOAnalysis.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "HGTD_RDOAnalysis.h"
6 #include "StoreGate/ReadHandle.h"
9 
10 #include "TruthUtils/AtlasPID.h"
12 
13 #include "TTree.h"
14 #include "TString.h"
15 
16 #include <algorithm>
17 #include <math.h>
18 #include <functional>
19 #include <iostream>
20 
21 
22 HGTD_RDOAnalysis::HGTD_RDOAnalysis(const std::string& name, ISvcLocator *pSvcLocator)
23  : AthAlgorithm(name, pSvcLocator) { }
24 
26  ATH_MSG_DEBUG( "Initializing HGTD_RDOAnalysis" );
27 
28  // This will check that the properties were initialized
29  // properly by job configuration.
33 
34  // Grab HGTDID helper
37 
38  // Grab Ntuple and histogramming service for tree
39  ATH_CHECK(m_thistSvc.retrieve());
40 
41  m_tree = new TTree(m_ntupleName.value().c_str(), "HGTD_RDOAnalysis");
42  ATH_CHECK(m_thistSvc->regTree(m_ntuplePath.value() + m_ntupleName.value(), m_tree));
43  if (m_tree) {
44  m_tree->Branch("m_rdo_module_layer", &m_rdo_module_layer);
45  m_tree->Branch("m_rdo_module_x", &m_rdo_module_x);
46  m_tree->Branch("m_rdo_module_y", &m_rdo_module_y);
47  m_tree->Branch("m_rdo_module_z", &m_rdo_module_z);
48  m_tree->Branch("m_rdo_module_ID", &m_rdo_module_ID);
49  m_tree->Branch("m_rdo_hit_x", &m_rdo_hit_x);
50  m_tree->Branch("m_rdo_hit_y", &m_rdo_hit_y);
51  m_tree->Branch("m_rdo_hit_z", &m_rdo_hit_z);
52  m_tree->Branch("m_rdo_hit_toa", &m_rdo_hit_toa);
53  m_tree->Branch("m_rdo_hit_sdo_toa", &m_rdo_hit_sdo_toa);
54  m_tree->Branch("m_rdo_hit_sdo_truth_category", &m_rdo_hit_sdo_truth_category);
55  } else {
56  ATH_MSG_ERROR("No tree found!");
57  }
58  /*
59  // HISTOGRAMS
60 
62  m_h_rdoID = new TH1F("h_rdoID", "rdoID", 100, 0, 10e17);
63  m_h_rdoID->StatOverflows();
64  ATH_CHECK(m_thistSvc->regHist(m_histPath + m_h_rdoID->GetName(), m_h_rdoID));
65  */
66 
67  return StatusCode::SUCCESS;
68 }
69 
71  ATH_MSG_DEBUG(" In HGTD_RDOAnalysis::execute()" );
72  m_rdo_module_layer.clear();
73  m_rdo_module_x.clear();
74  m_rdo_module_y.clear();
75  m_rdo_module_z.clear();
76  m_rdo_module_ID.clear();
77  m_rdo_hit_x.clear();
78  m_rdo_hit_y.clear();
79  m_rdo_hit_z.clear();
80  m_rdo_hit_toa.clear();
81  m_rdo_hit_sdo_toa.clear();
83 
84  // Raw HGTD Data
86  //Adding SimMap and McEvent here for added truthMatching checks
88 
90  bool doTruthMatching = true;
91  const HepMC::GenEvent* hardScatterEvent(nullptr);
92 
93  if (mcEventCollection->size()==0){
94  ATH_MSG_WARNING("Failed to retrieve a nonzero sized truth event collection, disabling truthMatching");
95  doTruthMatching = false;
96  }
97  if(doTruthMatching) hardScatterEvent = mcEventCollection->at(0);
98 
99  if(p_RDO_cont.isValid()) {
100  // loop over RDO container
101  for ( HGTD_RDO_Container::const_iterator rdoCont_itr = p_RDO_cont->begin(); rdoCont_itr != p_RDO_cont->end(); ++rdoCont_itr ) {
102 
103  const HGTD_RDO_Collection* p_RDO_coll(*rdoCont_itr);
104  const Identifier rdoIDColl((*rdoCont_itr)->identify());
105 
106  const InDetDD::HGTD_DetectorElement *elementColl = m_HGTD_Manager->getDetectorElement(rdoIDColl);
107  InDetDD::SiLocalPosition localPosColl = elementColl->rawLocalPositionOfCell(rdoIDColl);
108  Amg::Vector3D globalPosColl = elementColl->globalPosition(localPosColl);
109 
110 
111  for ( HGTD_RDO_Collection::const_iterator rdo_itr= p_RDO_coll->begin(); rdo_itr != p_RDO_coll->end(); ++rdo_itr ) {
112 
113  const Identifier rdoID((*rdo_itr)->identify());
114 
116  InDetDD::SiLocalPosition localPos_hit = rdo_element->rawLocalPositionOfCell(rdoID);
117  Amg::Vector3D globalPos_hit = rdo_element->globalPosition(localPos_hit);
118 
119  m_rdo_hit_x.push_back(globalPos_hit[Amg::x]);
120  m_rdo_hit_y.push_back(globalPos_hit[Amg::y]);
121  m_rdo_hit_z.push_back(globalPos_hit[Amg::z]);
122 
123  // Move global position storage for RDO module from outer to inner loop
124  m_rdo_module_x.push_back(globalPosColl[Amg::x]);
125  m_rdo_module_y.push_back(globalPosColl[Amg::y]);
126  m_rdo_module_z.push_back(globalPosColl[Amg::z]);
127 
128  m_rdo_module_layer.push_back(m_HGTD_ID->layer(rdoIDColl));
129  m_rdo_module_ID.push_back(rdoIDColl.get_compact());
130 
131  // Get the Time of Arrival which include the tof and the digitisation smearing of 25 ps
132  float rdo_toa = (*rdo_itr)->getTOA();
133  m_rdo_hit_toa.push_back(rdo_toa);
134 
135  // For truth matching studies we need to get the truth nature of each deposit.
136  // For each hit, there can be up to 7 deposit from different nature accessed through the SDO map.
137  if(doTruthMatching){
138  if(simDataMap.isValid()){
139  InDetSimDataCollection::const_iterator iter = (*simDataMap).find((*rdo_itr)->identify());
140  std::vector<SdoInfo> sdo_info;
141  if ( iter != (*simDataMap).end() ) {
142  const InDetSimData& sdo = iter->second;
143  const std::vector< InDetSimData::Deposit >& deposits = sdo.getdeposits();
144  for( std::vector< InDetSimData::Deposit >::const_iterator nextdeposit = deposits.begin() ; nextdeposit!=deposits.end(); ++nextdeposit) {
145  SdoInfo sdoi;
146  // The times of the deposit also include the smearing of digi of 25 ps
147  sdoi.time = nextdeposit->second;
148  const HepMcParticleLink& particleLink = nextdeposit->first;
149  if(particleLink.isValid()){
150  HepMC::ConstGenParticlePtr genPart(particleLink.cptr());
151  if(isHSGoodParticle(genPart,hardScatterEvent)) sdoi.truth = 1; // signal
152  else sdoi.truth = 2; // pile-up
153  }
154  sdo_info.push_back(sdoi);
155  }
156  } else {
157  // Secondaries are not saved in the SDO map, hence saving the TOA for them
158  SdoInfo sdoi;
159  sdoi.time = rdo_toa;
160  sdoi.truth = 3; // secondary
161  sdo_info.push_back(sdoi);
162  }
163 
164  // Only the particle that creates the first deposit is considered to be the correct particle
165  std::sort(sdo_info.begin(), sdo_info.end());
166  if (sdo_info.size() > 0) {
167  m_rdo_hit_sdo_toa.push_back(sdo_info.at(0).time);
168  m_rdo_hit_sdo_truth_category.push_back(sdo_info.at(0).truth);
169  }
170  }
171  else {
172  ATH_MSG_ERROR("No HGTD SDO map found!");
173  }
174  }
175  }
176  }
177  }
178  else {
179  ATH_MSG_ERROR("No HGTD RDO container found!");
180  }
181 
182  if (m_tree) m_tree->Fill();
183 
184  return StatusCode::SUCCESS;
185 }
186 
187 bool HGTD_RDOAnalysis::isHSGoodParticle(HepMC::ConstGenParticlePtr particlePtr,const HepMC::GenEvent* hardScatterGenEvent, float min_pt_cut) {
188  bool decision = false;
189  if( MC::isGenStable(particlePtr) and
190  isCharged(particlePtr) and
191  particlePtr->momentum().perp() >= min_pt_cut and
192  particlePtr->momentum().eta() < 4. and
193  particlePtr->parent_event() == hardScatterGenEvent)
194  decision = true;
195 
196  return decision;
197 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
HGTD_RDOAnalysis::SdoInfo::truth
int truth
Definition: HGTD_RDOAnalysis.h:35
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
HGTD_RDOAnalysis::execute
virtual StatusCode execute() override final
Definition: HGTD_RDOAnalysis.cxx:70
HGTD_RDOAnalysis::m_rdo_hit_x
std::vector< float > m_rdo_hit_x
Definition: HGTD_RDOAnalysis.h:72
HGTD_RDOAnalysis::m_rdo_hit_y
std::vector< float > m_rdo_hit_y
Definition: HGTD_RDOAnalysis.h:73
InDetSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition: InDetSimData.h:74
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
HGTD_RDOAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: HGTD_RDOAnalysis.h:64
Amg::y
@ y
Definition: GeoPrimitives.h:35
InDetDD::HGTD_DetectorElement
Definition: HGTD_DetectorElement.h:40
HGTD_RDOAnalysis::m_ntuplePath
Gaudi::Property< std::string > m_ntuplePath
Definition: HGTD_RDOAnalysis.h:60
Identifier::get_compact
value_type get_compact() const
Get the compact id.
HGTD_RDOAnalysis::m_inputTruthKey
SG::ReadHandleKey< InDetSimDataCollection > m_inputTruthKey
Definition: HGTD_RDOAnalysis.h:50
HGTD_RDOAnalysis::m_ntupleName
Gaudi::Property< std::string > m_ntupleName
Definition: HGTD_RDOAnalysis.h:61
HGTD_ID::layer
int layer(const Identifier &id) const
Definition: HGTD_ID.h:475
HGTD_RDO_Collection
Definition: HGTD_RDO_Collection.h:19
MC::isGenStable
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
Definition: HepMCHelpers.h:54
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
InDetDD::SiLocalPosition
Definition: SiLocalPosition.h:31
HGTD_RDOAnalysis::m_HGTD_Manager
const HGTD_DetectorManager * m_HGTD_Manager
Definition: HGTD_RDOAnalysis.h:53
HGTD_RDOAnalysis::m_tree
TTree * m_tree
Definition: HGTD_RDOAnalysis.h:66
HGTD_RDOAnalysis::m_rdo_hit_toa
std::vector< float > m_rdo_hit_toa
Definition: HGTD_RDOAnalysis.h:75
HGTD_RDOAnalysis::m_rdo_module_z
std::vector< float > m_rdo_module_z
Definition: HGTD_RDOAnalysis.h:70
Amg::z
@ z
Definition: GeoPrimitives.h:36
HGTD_RDOAnalysis::SdoInfo
Definition: HGTD_RDOAnalysis.h:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HGTD_DetectorManager::getDetectorElement
const InDetDD::HGTD_DetectorElement * getDetectorElement(const Identifier &id) const
access to individual elements : via Identifier
Definition: HGTD_DetectorManager.cxx:50
HGTD_RDOAnalysis::m_HGTD_Name
Gaudi::Property< std::string > m_HGTD_Name
Definition: HGTD_RDOAnalysis.h:54
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::x
@ x
Definition: GeoPrimitives.h:34
HGTD_RDOAnalysis::m_rdo_hit_sdo_toa
std::vector< float > m_rdo_hit_sdo_toa
Definition: HGTD_RDOAnalysis.h:76
InDetSimData
Definition: InDetSimData.h:42
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:79
HGTD_RDOAnalysis::m_rdo_module_x
std::vector< float > m_rdo_module_x
Definition: HGTD_RDOAnalysis.h:68
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
HGTD_RDOAnalysis::isHSGoodParticle
bool isHSGoodParticle(HepMC::ConstGenParticlePtr particlePtr, const HepMC::GenEvent *hardScatterEvent, float min_pt_cut=1000.)
Definition: HGTD_RDOAnalysis.cxx:187
HGTD_RDOAnalysis::m_rdo_module_layer
std::vector< int > m_rdo_module_layer
Definition: HGTD_RDOAnalysis.h:67
SiLocalPosition.h
HGTD_RDOAnalysis::SdoInfo::time
float time
Definition: HGTD_RDOAnalysis.h:34
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HGTD_RDOAnalysis::m_inputMcEventCollectionKey
SG::ReadHandleKey< McEventCollection > m_inputMcEventCollectionKey
Definition: HGTD_RDOAnalysis.h:51
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
HGTD_RDOAnalysis::m_rdo_hit_z
std::vector< float > m_rdo_hit_z
Definition: HGTD_RDOAnalysis.h:74
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
SiDetectorElement.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
InDetDD::SolidStateDetectorElementBase::rawLocalPositionOfCell
Amg::Vector2D rawLocalPositionOfCell(const SiCellId &cellId) const
Returns position (center) of cell.
Definition: SolidStateDetectorElementBase.cxx:230
isCharged
bool isCharged(const T &p)
Definition: AtlasPID.h:993
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDetDD::SolidStateDetectorElementBase::globalPosition
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
HGTD_RDOAnalysis::m_rdo_module_ID
std::vector< unsigned long long > m_rdo_module_ID
Definition: HGTD_RDOAnalysis.h:71
HGTD_RDOAnalysis::initialize
virtual StatusCode initialize() override final
Definition: HGTD_RDOAnalysis.cxx:25
HGTD_RDOAnalysis::m_HGTDID_Name
Gaudi::Property< std::string > m_HGTDID_Name
Definition: HGTD_RDOAnalysis.h:56
HGTD_RDOAnalysis::m_rdo_module_y
std::vector< float > m_rdo_module_y
Definition: HGTD_RDOAnalysis.h:69
HGTD_RDOAnalysis.h
HGTD_RDOAnalysis::HGTD_RDOAnalysis
HGTD_RDOAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HGTD_RDOAnalysis.cxx:22
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ReadHandle.h
Handle class for reading from StoreGate.
HGTD_RDOAnalysis::m_HGTD_ID
const HGTD_ID * m_HGTD_ID
Definition: HGTD_RDOAnalysis.h:55
HGTD_RDOAnalysis::m_inputKey
SG::ReadHandleKey< HGTD_RDO_Container > m_inputKey
Definition: HGTD_RDOAnalysis.h:49
HGTD_RDOAnalysis::m_rdo_hit_sdo_truth_category
std::vector< int > m_rdo_hit_sdo_truth_category
Definition: HGTD_RDOAnalysis.h:77
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
AtlasPID.h
Identifier
Definition: IdentifierFieldParser.cxx:14