ATLAS Offline Software
METCaloRegionsTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // METCaloRegionsTool.cxx
8 // Implementation file for class METCaloRegionsTool
9 //
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 //
12 // Author: P Loch, S Resconi, TJ Khoo, AS Mete
14 
15 // METReconstruction includes
17 
18 // MET EDM
19 #if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
20 #else
23 #endif
24 
25 namespace met {
26 
27  using std::vector;
28  //
29  using xAOD::IParticle;
30  //
31  using xAOD::CaloCluster;
33  //
34  using xAOD::MissingET;
36 
37  // Initialize s_CaloRegionNames
39  {
40  "EMB",
41  "EME",
42  "FCAL",
43  "HEC",
44  "PEMB",
45  "PEME",
46  "TILE"
47  };
48 
50  // Public methods:
52 
53  // Constructors
56  AsgTool(name)
57  {
58  }
59 
60  // Athena algtool's Hooks
63  {
64  ATH_MSG_DEBUG("Initializing " << name() << "...");
65 
66  #if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS)
68  #endif
69  // Either Cells or Clusters
72 
73  return StatusCode::SUCCESS;
74  }
75 
77  // Protected methods:
79 
81  {
82 
83  ATH_MSG_DEBUG ("In execute: " << name() << "...");
84 
85  // Create the container and push back the new MET terms
87  MissingETContainer* metCont = static_cast<MissingETContainer*>( metTerm_EMB->container() );
88 
89  // Push region terms to the container
90  for( int i=0; i < REGIONS_TOTAL; ++i) {
91  // Create the new terms
92  if( i > 0 ) {
93  metCont->push_back( new MissingET(0.,0.,0.) );
94  }
95  // Set Name and Source
96  metCont->at(i)->setName( s_CaloRegionNames[i] );
97  metCont->at(i)->setSource( source );
98  }
99  // The last term is Trigger MET if asked for by the user
101  std::string termName = "";
102  for( int i=0; i<3; ++i) {
103  switch(i) {
104  case 0: termName = "AllCells"; break;
105  case 1: termName = "Cells_Abs2S"; break;
106  case 2: termName = "Cells_Abs2S_m5S"; break;
107  }
108  metCont->push_back( new MissingET(0.,0.,0.) );
109  metCont->at(REGIONS_TOTAL+i)->setName( termName );
111  }
112  }
113 
114  StatusCode sc = StatusCode::SUCCESS;
115 
116  // Either Cells or Clusters
117  if(m_calo_useCells) {
118  // Retrieve the cell container
120 
121  #if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
122  #else
123  if (!caloCellCont.isValid()) {
124  ATH_MSG_WARNING("Couldn't set up ReadHandle for Calo Cell Container "<<m_caloCellKey.key());
125  ATH_MSG_WARNING("Unable to retrieve input cell cluster container");
126  return StatusCode::SUCCESS;
127 
128  }
129  #endif
130  // Fill MET
131  sc = fillCellMet(metCont,caloCellCont.cptr());
132  } else {
133  // Retrieve the calo container
135  if (!caloClusCont.isValid()) {
136  ATH_MSG_WARNING("Unable to retrieve input calo cluster container"<<m_caloClusterKey.key());
137  return StatusCode::SUCCESS;
138 
139  }
140  // Fill MET
141  sc=fillClusterMet(metCont,caloClusCont.cptr());
142  } // end if use clusters if/else
143 
144  // Debug information
145  for( int i=0; i < REGIONS_TOTAL; ++i) {
146  MissingET* currentTerm = (MissingET*) metCont->at(i);
147  if(!currentTerm) continue;
148  ATH_MSG_DEBUG ( "MET Calo term name " << currentTerm->name() <<
149  ", source " << currentTerm->source() <<
150  ", mpx " << currentTerm->mpx() <<
151  ", mpy " << currentTerm->mpy() <<
152  ", met " << currentTerm->met() <<
153  ", sumet " << currentTerm->sumet()
154  );
155  } // end debug information
156 
157  if(sc.isFailure()) {
158  ATH_MSG_WARNING("Unable to fill cell/cluster MET");
159  }
160 
161  return StatusCode::SUCCESS;
162  }
163 
164  // Find MetTerm name for a given sampling
166  {
167  switch(sample) {
168  case CaloSampling::EMB1:
169  case CaloSampling::EMB2:
170  case CaloSampling::EMB3:
171  return metContainer->at(EMB);
172  //
173  case CaloSampling::EME1:
174  case CaloSampling::EME2:
175  case CaloSampling::EME3:
176  return metContainer->at(EME);
177  //
178  case CaloSampling::FCAL0:
179  case CaloSampling::FCAL1:
180  case CaloSampling::FCAL2:
181  return metContainer->at(FCAL);
182  //
183  case CaloSampling::HEC0:
184  case CaloSampling::HEC1:
185  case CaloSampling::HEC2:
186  case CaloSampling::HEC3:
187  return metContainer->at(HEC);
188  //
190  return metContainer->at(PEMB);
191  //
193  return metContainer->at(PEME);
194  //
204  return metContainer->at(TILE);
205  //
206  default: return nullptr;
207  }
208  }
209 
210  // Fill Cell MET
212  const CaloCellContainer* caloCellContainer) const
213  {
214  #if defined (XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
215  ATH_MSG_WARNING("Cell information is only available in athena framework");
216  #else
218  const CaloNoise* noiseCDO=*noiseHdl;
219  // Loop over all cells
220  for (const CaloCell* cell : *caloCellContainer) {
221 
222  // Retrieve the sampling
223  CaloSampling::CaloSample sample = (CaloSampling::CaloSample) cell->caloDDE()->getSampling();
224 
225  // Calculate Et/phi
226  double e_cell = cell->energy();
227  double et_cell = e_cell/cosh(cell->eta());
228  double phi_cell = cell->phi();
229 
230  // Find the associated MET
231  MissingET* metTerm = findMetTerm(metContainer, sample);
232  if(!metTerm) {
233  ATH_MSG_WARNING("Invalid calo sample MET pointer");
234  continue;
235  }
236 
237  // Add to MET for the Calo regions
238  metTerm->add(et_cell*cos(phi_cell),
239  et_cell*sin(phi_cell),
240  et_cell);
241 
242  // Trigger MET
243  if(m_calo_doTriggerMet) {
244  #if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
245  double noise_cell = 0;
246  #else
247  double noise_cell = noiseCDO->getNoise(cell->ID(),cell->gain());
248  #endif
249  // All cells
250  metContainer->at(REGIONS_TOTAL)->add(et_cell*cos(phi_cell),
251  et_cell*sin(phi_cell),
252  et_cell);
253  // |E| > 2*sigma
254  if( fabs(e_cell) < 2.0*noise_cell ) continue;
255  metContainer->at(REGIONS_TOTAL+1)->add(et_cell*cos(phi_cell),
256  et_cell*sin(phi_cell),
257  et_cell);
258  // E > -5*sigma
259  if( e_cell < -5.0*noise_cell ) continue;
260  metContainer->at(REGIONS_TOTAL+2)->add(et_cell*cos(phi_cell),
261  et_cell*sin(phi_cell),
262  et_cell);
263  }
264  } // end of loop overall cells
265  #endif
266  return StatusCode::SUCCESS;
267  } // end of fillCellMet
268 
269  // Fill Cluster MET
271  const CaloClusterContainer* caloClusContainer) const
272  {
273 
274  // Loop over all clusters
275  for(const auto *iClus : *caloClusContainer) {
276  // Loop over all samplings
277  for(int iSample=CaloSampling::PreSamplerB;
278  iSample<=CaloSampling::FCAL2; ++iSample) {
279 
281 
282  // Eta is only defined if Energy != 0
283  if(fabs(iClus->eSample(sample))>0) {
284 
285  // Calculate Et/phi
286  double et_sample = iClus->eSample(sample)/cosh(iClus->etaSample(sample));
287  double phi_sample = iClus->phiSample(sample);
288 
289  // Find the associated MET
290  MissingET* metTerm = findMetTerm(metContainer, sample);
291  if(!metTerm) {
292  ATH_MSG_WARNING("Invalid calo sample MET pointer");
293  continue;
294  }
295 
296  // Add to MET
297  metTerm->add(et_sample*cos(phi_sample),
298  et_sample*sin(phi_sample),
299  et_sample);
300  } // end of energy>0 if
301  } // end of loop over samplings
302  } // end of loop over clusters
303  return StatusCode::SUCCESS;
304  } // end of fillClusterMet
305 
306 }
xAOD::MissingETComponentMap_v1
Definition: MissingETComponentMap_v1.h:25
met::METCaloRegionsTool::findMetTerm
static xAOD::MissingET * findMetTerm(xAOD::MissingETContainer *metContainer, CaloSampling::CaloSample sample)
Definition: METCaloRegionsTool.cxx:165
CaloCell_ID_FCS::TileExt2
@ TileExt2
Definition: FastCaloSim_CaloCell_ID.h:39
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
met::METCaloRegionsTool::REGIONS_TOTAL
@ REGIONS_TOTAL
Definition: METCaloRegionsTool.h:108
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
xAOD::MissingET_v1::sumet
float sumet() const
Returns.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
met::METCaloRegionsTool::EME
@ EME
Definition: METCaloRegionsTool.h:102
CaloCell_ID_FCS::TileExt0
@ TileExt0
Definition: FastCaloSim_CaloCell_ID.h:37
CaloCell_ID_FCS::TileBar1
@ TileBar1
Definition: FastCaloSim_CaloCell_ID.h:32
met::METCaloRegionsTool::m_calo_doTriggerMet
Gaudi::Property< bool > m_calo_doTriggerMet
Definition: METCaloRegionsTool.h:82
met::METCaloRegionsTool::PEME
@ PEME
Definition: METCaloRegionsTool.h:106
met::METCaloRegionsTool::HEC
@ HEC
Definition: METCaloRegionsTool.h:104
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
xAOD::MissingETContainer
MissingETContainer_v1 MissingETContainer
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingETContainer.h:16
CaloCell_ID_FCS::HEC2
@ HEC2
Definition: FastCaloSim_CaloCell_ID.h:29
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
met::METCaloRegionsTool::execute
virtual StatusCode execute(xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap) const override
Definition: METCaloRegionsTool.cxx:80
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
CaloCell_ID_FCS::TileGap3
@ TileGap3
Definition: FastCaloSim_CaloCell_ID.h:36
met::METCaloRegionsTool::s_CaloRegionNames
static const std::string s_CaloRegionNames[]
Definition: METCaloRegionsTool.h:111
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
met::METCaloRegionsTool::EMB
@ EMB
Definition: METCaloRegionsTool.h:101
xAOD::CaloClusterContainer
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloClusterContainer.h:17
met
Definition: IMETSignificance.h:24
CaloCell_ID_FCS::HEC1
@ HEC1
Definition: FastCaloSim_CaloCell_ID.h:28
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
lumiFormat.i
int i
Definition: lumiFormat.py:92
met::METCaloRegionsTool::m_caloClusterKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusterKey
Definition: METCaloRegionsTool.h:121
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCell_ID_FCS::TileBar0
@ TileBar0
Definition: FastCaloSim_CaloCell_ID.h:31
met::METCaloRegionsTool::m_calo_useCells
Gaudi::Property< bool > m_calo_useCells
Definition: METCaloRegionsTool.h:81
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
CaloCell_ID_FCS::TileGap2
@ TileGap2
Definition: FastCaloSim_CaloCell_ID.h:35
MissingETBase::Source::Category::Calo
@ Calo
Indicator for MET terms reconstructed from calorimeter signals alone.
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
xAOD::MissingET_v1::mpx
float mpx() const
Returns .
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
xAOD::MissingET_v1::name
const std::string & name() const
Identifier getters.
MissingET
Athena::TPCnvVers::Old Athena::TPCnvVers::Old MissingET
Definition: RecTPCnv.cxx:64
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CaloCell_ID_FCS::TileGap1
@ TileGap1
Definition: FastCaloSim_CaloCell_ID.h:34
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloNoise
Definition: CaloNoise.h:16
xAOD::MissingET_v1::add
void add(const IParticle *particle)
Add particle kinematics to MET.
Definition: MissingET_v1.cxx:77
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CaloCell_ID_FCS::TileExt1
@ TileExt1
Definition: FastCaloSim_CaloCell_ID.h:38
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
CaloNoise.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::MissingET_v1::source
MissingETBase::Types::bitmask_t source() const
MET object source tag.
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCell_ID_FCS::HEC0
@ HEC0
Definition: FastCaloSim_CaloCell_ID.h:27
met::METCaloRegionsTool::fillCellMet
StatusCode fillCellMet(xAOD::MissingETContainer *metContainer, const CaloCellContainer *caloCellContainer) const
Definition: METCaloRegionsTool.cxx:211
met::METCaloRegionsTool::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Definition: METCaloRegionsTool.h:119
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
MissingETBase::Source::clusterEM
static Types::bitmask_t clusterEM(Region reg=Region::FullAcceptance)
Bit mask for MET term from EMTopo signal objects.
Definition: MissingETBase.h:305
met::METCaloRegionsTool::METCaloRegionsTool
METCaloRegionsTool()
METCaloRegionsTool.h
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
xAOD::MissingET_v1::mpy
float mpy() const
Returns .
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
met::METCaloRegionsTool::m_caloCellKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellKey
Definition: METCaloRegionsTool.h:122
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
CaloCell_ID_FCS::TileBar2
@ TileBar2
Definition: FastCaloSim_CaloCell_ID.h:33
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
xAOD::MissingET_v1::met
float met() const
Returns .
met::METCaloRegionsTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METCaloRegionsTool.cxx:62
met::METCaloRegionsTool::TILE
@ TILE
Definition: METCaloRegionsTool.h:107
met::METCaloRegionsTool::PEMB
@ PEMB
Definition: METCaloRegionsTool.h:105
met::METCaloRegionsTool::fillClusterMet
StatusCode fillClusterMet(xAOD::MissingETContainer *metContainer, const xAOD::CaloClusterContainer *caloClusContainer) const
Definition: METCaloRegionsTool.cxx:270
met::METCaloRegionsTool::FCAL
@ FCAL
Definition: METCaloRegionsTool.h:103