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_hit_x", &m_rdo_hit_x);
49  m_tree->Branch("m_rdo_hit_y", &m_rdo_hit_y);
50  m_tree->Branch("m_rdo_hit_z", &m_rdo_hit_z);
51  m_tree->Branch("m_rdo_hit_toa", &m_rdo_hit_toa);
52  m_tree->Branch("m_rdo_hit_sdo_toa", &m_rdo_hit_sdo_toa);
53  m_tree->Branch("m_rdo_hit_sdo_truth_category", &m_rdo_hit_sdo_truth_category);
54  } else {
55  ATH_MSG_ERROR("No tree found!");
56  }
57  /*
58  // HISTOGRAMS
59 
61  m_h_rdoID = new TH1F("h_rdoID", "rdoID", 100, 0, 10e17);
62  m_h_rdoID->StatOverflows();
63  ATH_CHECK(m_thistSvc->regHist(m_histPath + m_h_rdoID->GetName(), m_h_rdoID));
64  */
65 
66  return StatusCode::SUCCESS;
67 }
68 
70  ATH_MSG_DEBUG(" In HGTD_RDOAnalysis::execute()" );
71  m_rdo_module_layer.clear();
72  m_rdo_module_x.clear();
73  m_rdo_module_y.clear();
74  m_rdo_module_z.clear();
75  m_rdo_hit_x.clear();
76  m_rdo_hit_y.clear();
77  m_rdo_hit_z.clear();
78  m_rdo_hit_toa.clear();
79  m_rdo_hit_sdo_toa.clear();
81 
82  // Raw HGTD Data
84  //Adding SimMap and McEvent here for added truthMatching checks
86 
88  bool doTruthMatching = true;
89  const HepMC::GenEvent* hardScatterEvent(nullptr);
90 
91  if (mcEventCollection->size()==0){
92  ATH_MSG_WARNING("Failed to retrieve a nonzero sized truth event collection, disabling truthMatching");
93  doTruthMatching = false;
94  }
95  if(doTruthMatching) hardScatterEvent = mcEventCollection->at(0);
96 
97  if(p_RDO_cont.isValid()) {
98  // loop over RDO container
99  for ( HGTD_RDO_Container::const_iterator rdoCont_itr = p_RDO_cont->begin(); rdoCont_itr != p_RDO_cont->end(); ++rdoCont_itr ) {
100 
101  const HGTD_RDO_Collection* p_RDO_coll(*rdoCont_itr);
102  const Identifier rdoIDColl((*rdoCont_itr)->identify());
103 
104  const InDetDD::HGTD_DetectorElement *elementColl = m_HGTD_Manager->getDetectorElement(rdoIDColl);
105  InDetDD::SiLocalPosition localPosColl = elementColl->rawLocalPositionOfCell(rdoIDColl);
106  Amg::Vector3D globalPosColl = elementColl->globalPosition(localPosColl);
107 
108  m_rdo_module_x.push_back(globalPosColl[Amg::x]);
109  m_rdo_module_y.push_back(globalPosColl[Amg::y]);
110  m_rdo_module_z.push_back(globalPosColl[Amg::z]);
111 
112  m_rdo_module_layer.push_back(m_HGTD_ID->layer(rdoIDColl));
113 
114  for ( HGTD_RDO_Collection::const_iterator rdo_itr= p_RDO_coll->begin(); rdo_itr != p_RDO_coll->end(); ++rdo_itr ) {
115 
116  const Identifier rdoID((*rdo_itr)->identify());
117 
119  InDetDD::SiLocalPosition localPos_hit = rdo_element->rawLocalPositionOfCell(rdoID);
120  Amg::Vector3D globalPos_hit = rdo_element->globalPosition(localPos_hit);
121 
122  m_rdo_hit_x.push_back(globalPos_hit[Amg::x]);
123  m_rdo_hit_y.push_back(globalPos_hit[Amg::y]);
124  m_rdo_hit_z.push_back(globalPos_hit[Amg::z]);
125 
126  // Get the Time of Arrival which include the tof and the digitisation smearing of 25 ps
127  float rdo_toa = (*rdo_itr)->getTOA();
128  m_rdo_hit_toa.push_back(rdo_toa);
129 
130  // For truth matching studies we need to get the truth nature of each deposit.
131  // For each hit, there can be up to 7 deposit from different nature accessed through the SDO map.
132  if(doTruthMatching){
133  if(simDataMap.isValid()){
134  InDetSimDataCollection::const_iterator iter = (*simDataMap).find((*rdo_itr)->identify());
135  std::vector<SdoInfo> sdo_info;
136  if ( iter != (*simDataMap).end() ) {
137  const InDetSimData& sdo = iter->second;
138  const std::vector< InDetSimData::Deposit >& deposits = sdo.getdeposits();
139  for( std::vector< InDetSimData::Deposit >::const_iterator nextdeposit = deposits.begin() ; nextdeposit!=deposits.end(); ++nextdeposit) {
140  SdoInfo sdoi;
141  // The times of the deposit also include the smearing of digi of 25 ps
142  sdoi.time = nextdeposit->second;
143  const HepMcParticleLink& particleLink = nextdeposit->first;
144  if(particleLink.isValid()){
145  HepMC::ConstGenParticlePtr genPart(particleLink.cptr());
146  if(isHSGoodParticle(genPart,hardScatterEvent)) sdoi.truth = 1; // signal
147  else sdoi.truth = 2; // pile-up
148  }
149  sdo_info.push_back(sdoi);
150  }
151  } else {
152  // Secondaries are not saved in the SDO map, hence saving the TOA for them
153  SdoInfo sdoi;
154  sdoi.time = rdo_toa;
155  sdoi.truth = 3; // secondary
156  sdo_info.push_back(sdoi);
157  }
158 
159  // Only the particle that creates the first deposit is considered to be the correct particle
160  std::sort(sdo_info.begin(), sdo_info.end());
161  if (sdo_info.size() > 0) {
162  m_rdo_hit_sdo_toa.push_back(sdo_info.at(0).time);
163  m_rdo_hit_sdo_truth_category.push_back(sdo_info.at(0).truth);
164  }
165  }
166  else {
167  ATH_MSG_ERROR("No HGTD SDO map found!");
168  }
169  }
170  }
171  }
172  }
173  else {
174  ATH_MSG_ERROR("No HGTD RDO container found!");
175  }
176 
177  if (m_tree) m_tree->Fill();
178 
179  return StatusCode::SUCCESS;
180 }
181 
182 bool HGTD_RDOAnalysis::isHSGoodParticle(HepMC::ConstGenParticlePtr particlePtr,const HepMC::GenEvent* hardScatterGenEvent, float min_pt_cut) {
183  bool decision = false;
184  if( MC::isGenStable(particlePtr) and
185  isCharged(particlePtr) and
186  particlePtr->momentum().perp() >= min_pt_cut and
187  particlePtr->momentum().eta() < 4. and
188  particlePtr->parent_event() == hardScatterGenEvent)
189  decision = true;
190 
191  return decision;
192 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
HGTD_RDOAnalysis::SdoInfo::truth
int truth
Definition: HGTD_RDOAnalysis.h:35
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:69
HGTD_RDOAnalysis::m_rdo_hit_x
std::vector< float > m_rdo_hit_x
Definition: HGTD_RDOAnalysis.h:71
HGTD_RDOAnalysis::m_rdo_hit_y
std::vector< float > m_rdo_hit_y
Definition: HGTD_RDOAnalysis.h:72
InDetSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition: InDetSimData.h:74
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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
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:36
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:74
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_RDOAnalysis::m_HGTD_Name
Gaudi::Property< std::string > m_HGTD_Name
Definition: HGTD_RDOAnalysis.h:54
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:75
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:242
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
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:236
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:182
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:73
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
SiDetectorElement.h
HGTD_DetectorManager::getDetectorElement
InDetDD::HGTD_DetectorElement * getDetectorElement(const Identifier &id) const
access to individual elements : via Identifier
Definition: HGTD_DetectorManager.cxx:57
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:496
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::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:76
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