ATLAS Offline Software
LArSCHitFillerTool.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 
7 #include <sstream>
8 
10 #include "CaloEvent/CaloCell.h"
12 #include "CaloDetDescr/CaloDetDescrElement.h"
14 
17 
18 #include <vector>
19 #include <list>
20 #include <map>
21 #include <iostream>
22 #include <cmath>
23 
24 #include "LArSCHitFillerTool.h"
25 
26 namespace D3PD {
27 
28 
36  (const std::string& type,
37  const std::string& name,
38  const IInterface* parent)
40  m_dd_fSampl (nullptr),
41  m_caloEtaSelection( false ),
42  m_caloPhiSelection( false ),
43  m_caloLayerSelection( false ),
44  m_caloSelection( false ),
45  m_scidtool ("CaloSuperCellIDTool")
46  {
47 
48  declareProperty( "CaloEtaCut", m_etaCut );
49  declareProperty( "CaloPhiCut", m_phiCut );
50  declareProperty( "CaloLayers", m_caloLayers );
51  declareProperty( "CaloDetectors", m_caloNums );
52  // 1=EMB; 2=EMEC Outer Wheel; 3=EMEC Inner Wheel; 4=HEC; 5=FCAL
53 
54  declareProperty ("SCIDTool", m_scidtool,
55  "Offline / supercell mapping tool.");
56 
57  LArSCHitFillerTool::book().ignore(); // Avoid coverity warnings.
58 }
59 
60 
62 {
63  ServiceHandle<StoreGateSvc> detStore("DetectorStore", name());
64  CHECK( detStore.retrieve() ) ;
65  CHECK( m_scidtool.retrieve() );
67  CHECK( detStore->retrieve (m_sc_idHelper) );
68 
69  CHECK ( detStore->retrieve(m_emid) );
70  CHECK ( detStore->retrieve(m_fcalid) );
71  CHECK ( detStore->retrieve(m_hecid) );
72  CHECK ( detStore->retrieve(m_tileid) );
73  CHECK ( detStore->retrieve(m_onlineHelper));
74 
75  CHECK ( detStore->retrieve(m_dd_fSampl));
76 
77  const unsigned int nSubCalo = static_cast< int >( CaloCell_ID::NSUBCALO );
78 
79  //check calo number specified
80  m_caloSelection = false;
81  if( m_caloNums.size() == 0 ) {
82  ATH_MSG_INFO( " *** LArSCHitFillerTool: No calorimeter selection" );
83  // return StatusCode::SUCCESS;
84  } else if( m_caloNums.size() > nSubCalo ) {
86  << " More than " << nSubCalo << " calo specified. "
87  << "Must be wrong. Stop.";
88  return StatusCode::FAILURE;
89  } else {
90  m_caloSelection = true;
91  for( unsigned int index = 0; index < m_caloNums.size(); ++index ) {
92  if( m_caloNums[ index ]>= nSubCalo ) {
94  << "Invalid calo specification:"
95  << m_caloNums[index] << "Stop.";
96  return StatusCode::FAILURE;
97  } else {
98  ATH_MSG_INFO( "*** LArSCHitFillerTool: Select calorimeter " << m_caloNums[ index ] );
99  }
100  }
101  }
102 
103  m_caloEtaSelection = false;
104  if ( m_etaCut.size() >0 ) {
105  if ( m_etaCut.size()== 2 && m_etaCut[0]<m_etaCut[1] ) {
106  REPORT_MESSAGE( MSG::INFO ) << "*** LArSCHitFillerTool: Eta Selection specified: " << m_etaCut[0] << ", " << m_etaCut[1];
107  m_caloEtaSelection=true;
108  } else {
109  REPORT_MESSAGE( MSG::FATAL ) << " *** LArSCHitFillerTool: Invalid Eta Cut Range specified: Abort!";
110  return StatusCode::FAILURE;
111  }
112  }
113 
114  m_caloPhiSelection = false;
115  if ( m_phiCut.size() >0 ) {
116  if ( m_phiCut.size() == 2 && m_phiCut[0]<m_phiCut[1] ) {
117  REPORT_MESSAGE( MSG::INFO ) << "*** LArSCHitFillerTool: Phi Selection specified: " << m_phiCut[0] << ", " << m_phiCut[1];
118  m_caloPhiSelection = true;
119  } else {
120  REPORT_MESSAGE( MSG::FATAL ) << " *** LArSCHitFillerTool: Invalid Phi Cut Range specified: Abort!";
121  return StatusCode::FAILURE;
122  }
123  }
124 
125  m_caloLayerSelection = false;
126  if ( m_caloLayers.size()>0 ) {
127  if ( m_caloLayers.size()>28 ) {
128  REPORT_MESSAGE( MSG::FATAL ) << " *** LArSCHitFillerTool: Invalid No. of Calo Layer selection: " << m_caloLayers.size() << " Abort!";
129  return StatusCode::FAILURE;
130  }
131  for( unsigned int j=0; j<m_caloLayers.size(); j++) {
132  if (m_caloLayers[j]>27 ) {
133  REPORT_MESSAGE( MSG::FATAL ) << " *** LArSCHitFillerTool: Invalid Calo Layer selection: " << m_caloLayers[j] << " Abort!";
134  return StatusCode::FAILURE;
135  }
136  }
137  m_caloLayerSelection = true;
138  }
139 
140 
141  ATH_MSG_INFO( " *** LArSCHitFillerTool: caloEtaSelection " << m_caloEtaSelection );
142  ATH_MSG_INFO( " *** LArSCHitFillerTool: caloPhiSelection " << m_caloPhiSelection );
143  ATH_MSG_INFO( " *** LArSCHitFillerTool: caloLayerSelection " << m_caloLayerSelection );
144 
145  ATH_MSG_INFO( " *** LArSCHitFillerTool: completed" );
146  return StatusCode::SUCCESS;
147 }
148 
153 {
154  CHECK( addVariable ("nSC", m_nSC ));
155  CHECK( addVariable ("E", m_E));
156  CHECK( addVariable ("eta", m_eta));
157  CHECK( addVariable ("phi", m_phi));
158  CHECK( addVariable ("Eoff", m_Eoff));
159  CHECK( addVariable ("Et", m_Et));
160  CHECK( addVariable ("fsampl", m_fsampl));
161  CHECK( addVariable ("calo", m_calo));
162  CHECK( addVariable ("region", m_region));
163  CHECK( addVariable ("sampling", m_sampling));
164  CHECK( addVariable ("ieta", m_ieta));
165  CHECK( addVariable ("jphi", m_jphi));
166  //CHECK( addVariable ("hid", m_hashid));
167  CHECK( addVariable ("IdCells", m_offlId));
168 
169  return StatusCode::SUCCESS;
170 }
171 
172 
182 
183  std::map<int, double> sc_E;
184 
185  typedef LArHitContainer CONTAINER;
186  CONTAINER::const_iterator f_hit = p.begin();
187  CONTAINER::const_iterator l_hit = p.end();
188  for( ; f_hit != l_hit; ++f_hit ) {
189  const LArHit* hit = ( *f_hit );
190  const Identifier cell_id = hit->cellID();
191  Identifier sc_offl_id = m_scidtool->offlineToSuperCellID (cell_id);
192  int hashId = m_sc_idHelper->calo_cell_hash( sc_offl_id) ;
193  if (hashId < 999999)
194  sc_E[hashId] += hit->energy();
195  }
196 
197 
198  int nSC = 0;
199 
200  std::map<int, double>::const_iterator it = sc_E.begin();
201  std::map<int, double>::const_iterator it_e = sc_E.end();
202 
203  SG::ReadCondHandle<CaloSuperCellDetDescrManager> caloSuperCellMgrHandle{m_caloSuperCellMgrKey,Gaudi::Hive::currentContext()};
204  const CaloSuperCellDetDescrManager* sc_dd_mgr = *caloSuperCellMgrHandle;
205 
206  for ( ; it!=it_e ; ++it ) {
207  int hashId = (*it).first;
208  Identifier offlId = m_sc_idHelper->cell_id(hashId) ;
209  float fsampl = m_dd_fSampl->FSAMPL(offlId);
210  double E = (*it).second;
211 
212  // int pn = m_sc_idHelper->pos_neg(offlId);
213  int calo = m_sc_idHelper->sub_calo(hashId);
214  int region = m_sc_idHelper->region(offlId);
215  unsigned int lay = m_sc_idHelper->sampling(offlId);
216  int ieta = m_sc_idHelper->eta(offlId);
217  int jphi = m_sc_idHelper->phi(offlId);
218  float feta = sc_dd_mgr->get_element(offlId)->eta();
219  float fphi = sc_dd_mgr->get_element(offlId)->phi();
220  int lardet = calo;
221 
222  if (m_caloSelection) {
223  std::vector< unsigned int >::const_iterator theFound =
224  std::find( m_caloNums.begin(), m_caloNums.end(), lardet );
225  if( theFound == m_caloNums.end() ) continue;
226  }
227  if ( m_caloEtaSelection ) {
228  if (feta<m_etaCut[0] || feta>m_etaCut[1]) continue;
229  }
230  if ( m_caloPhiSelection ) {
231  if (fphi<m_phiCut[0] || fphi>m_phiCut[1]) continue;
232  }
233  if ( m_caloLayerSelection ) {
234  bool tmp=false;
235  for( unsigned int j=0; j<m_caloLayers.size(); j++) {
236  if (m_caloLayers[j]==lay) tmp=true;
237  }
238  if (!tmp) continue;
239  }
240  nSC++;
241  m_E->push_back( E );
242  m_calo->push_back( calo );
243  m_region->push_back( region );
244  m_sampling->push_back( lay );
245  m_ieta->push_back( ieta );
246  m_jphi->push_back( jphi );
247  m_offlId->push_back( offlId.get_identifier32().get_compact() );
248  m_eta->push_back( feta );
249  m_phi->push_back( fphi );
250  double offEnergy = E;
251  if ( fsampl>0. ) {
252  offEnergy /= fsampl;
253  } else {
254  offEnergy = 0;
255  }
256  m_Eoff->push_back( offEnergy );
257  m_Et->push_back( offEnergy/cosh( feta ) );
258  m_fsampl->push_back( fsampl );
259  }
260  *m_nSC = nSC;
261 
262  return StatusCode::SUCCESS;
263 
264 }
265 
266 
267 } // namespace D3PD
268 
D3PD::LArSCHitFillerTool::book
virtual StatusCode book()
Book variables for this block.
Definition: LArSCHitFillerTool.cxx:152
D3PD::LArSCHitFillerTool::fill
virtual StatusCode fill(const LArHitContainer &p)
Fill one block — type-safe version.
Definition: LArSCHitFillerTool.cxx:181
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
CaloCell_Base_ID::region
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
D3PD::LArSCHitFillerTool::m_jphi
std::vector< int > * m_jphi
Definition: LArSCHitFillerTool.h:91
index
Definition: index.py:1
D3PD::LArSCHitFillerTool::m_scidtool
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Property: Offline / supercell mapping tool.
Definition: LArSCHitFillerTool.h:106
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
skel.it
it
Definition: skel.GENtoEVGEN.py:423
D3PD::LArSCHitFillerTool::m_eta
std::vector< double > * m_eta
Definition: LArSCHitFillerTool.h:81
D3PD::LArSCHitFillerTool::m_E
std::vector< double > * m_E
Definition: LArSCHitFillerTool.h:80
D3PD::LArSCHitFillerTool::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArSCHitFillerTool.h:75
CaloCell.h
LArHit::energy
double energy() const
Definition: LArHit.h:113
LArHitContainer
Hit collection.
Definition: LArHitContainer.h:26
D3PD::AddVariable::addVariable
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
Definition: AddVariable.cxx:85
D3PD::LArSCHitFillerTool::m_dd_fSampl
const ILArfSampl * m_dd_fSampl
Definition: LArSCHitFillerTool.h:76
D3PD::LArSCHitFillerTool::m_region
std::vector< int > * m_region
Definition: LArSCHitFillerTool.h:88
LArSCHitFillerTool.h
D3PD::LArSCHitFillerTool::initialize
virtual StatusCode initialize()
Book variables for this block.
Definition: LArSCHitFillerTool.cxx:61
D3PD::LArSCHitFillerTool::m_nSC
int * m_nSC
parameters
Definition: LArSCHitFillerTool.h:79
D3PD::LArSCHitFillerTool::m_fsampl
std::vector< double > * m_fsampl
Definition: LArSCHitFillerTool.h:85
ICaloSuperCellIDTool.h
D3PD::LArSCHitFillerTool::m_caloSelection
bool m_caloSelection
Definition: LArSCHitFillerTool.h:102
CaloSuperCellDetDescrManager
Definition: CaloDetDescrManager.h:490
D3PD::LArSCHitFillerTool::m_emid
const LArEM_ID * m_emid
Definition: LArSCHitFillerTool.h:71
D3PD::LArSCHitFillerTool::m_phiCut
std::vector< float > m_phiCut
Definition: LArSCHitFillerTool.h:95
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
D3PD::LArSCHitFillerTool::m_Et
std::vector< double > * m_Et
Definition: LArSCHitFillerTool.h:84
D3PD::LArSCHitFillerTool::m_calo
std::vector< int > * m_calo
Definition: LArSCHitFillerTool.h:87
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ILArfSampl::FSAMPL
virtual const float & FSAMPL(const HWIdentifier &id) const =0
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
CaloCell_Base_ID::eta
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
D3PD::LArSCHitFillerTool::m_ieta
std::vector< int > * m_ieta
Definition: LArSCHitFillerTool.h:90
D3PD::BlockFillerTool
Type-safe wrapper for block filler tools.
Definition: BlockFillerTool.h:68
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::LArSCHitFillerTool::m_caloLayers
std::vector< unsigned int > m_caloLayers
Definition: LArSCHitFillerTool.h:97
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
D3PD::LArSCHitFillerTool::m_caloPhiSelection
bool m_caloPhiSelection
Definition: LArSCHitFillerTool.h:100
D3PD::LArSCHitFillerTool::m_caloNums
std::vector< unsigned int > m_caloNums
Definition: LArSCHitFillerTool.h:96
LArHit::cellID
Identifier cellID() const
Definition: LArHit.h:108
D3PD::LArSCHitFillerTool::LArSCHitFillerTool
LArSCHitFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: LArSCHitFillerTool.cxx:36
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
D3PD::LArSCHitFillerTool::m_sc_idHelper
const CaloCell_SuperCell_ID * m_sc_idHelper
idHlper
Definition: LArSCHitFillerTool.h:112
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
D3PD::LArSCHitFillerTool::m_caloEtaSelection
bool m_caloEtaSelection
Definition: LArSCHitFillerTool.h:99
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
CaloCell_Base_ID::phi
int phi(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloCellContainer.h
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
D3PD::LArSCHitFillerTool::m_fcalid
const LArFCAL_ID * m_fcalid
Definition: LArSCHitFillerTool.h:72
D3PD::LArSCHitFillerTool::m_caloSuperCellMgrKey
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
Definition: LArSCHitFillerTool.h:108
D3PD::LArSCHitFillerTool::m_etaCut
std::vector< float > m_etaCut
Definition: LArSCHitFillerTool.h:94
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
DeMoScan.index
string index
Definition: DeMoScan.py:362
D3PD::LArSCHitFillerTool::m_phi
std::vector< double > * m_phi
Definition: LArSCHitFillerTool.h:82
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
CaloDetDescrElement::eta
float eta() const
cell eta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:344
CaloCell_Base_ID::NSUBCALO
@ NSUBCALO
Definition: CaloCell_Base_ID.h:46
CaloDetDescrElement::phi
float phi() const
cell phi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:346
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
D3PD::LArSCHitFillerTool::m_Eoff
std::vector< double > * m_Eoff
Definition: LArSCHitFillerTool.h:83
D3PD::LArSCHitFillerTool::m_hecid
const LArHEC_ID * m_hecid
Definition: LArSCHitFillerTool.h:73
ILArfSampl.h
D3PD::LArSCHitFillerTool::m_tileid
const TileID * m_tileid
Definition: LArSCHitFillerTool.h:74
D3PD::LArSCHitFillerTool::m_caloLayerSelection
bool m_caloLayerSelection
Definition: LArSCHitFillerTool.h:101
D3PD::LArSCHitFillerTool::m_sampling
std::vector< int > * m_sampling
Definition: LArSCHitFillerTool.h:89
LArOnlineID.h
D3PD::LArSCHitFillerTool::m_offlId
std::vector< unsigned int > * m_offlId
Definition: LArSCHitFillerTool.h:92
ServiceHandle< StoreGateSvc >