ATLAS Offline Software
CaloBaselineMonAlg.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 
6 #include "CaloBaselineMonAlg.h"
7 
10 
11 #include "CaloGeoHelpers/CaloSampling.h"
12 #include "AthenaKernel/Units.h"
13 
14 
15 using xAOD::CaloCluster;
16 using Athena::Units::GeV;
17 
18 CaloBaselineMonAlg::CaloBaselineMonAlg(const std::string& name, ISvcLocator* pSvcLocator) :
19  CaloMonAlgBase(name, pSvcLocator),
20  m_bool_pedestalMon(false),
21  m_bool_bcidtoolMon(false)
22 {
23 
24 }
25 
26 
28 
29 
31 
33 
35  /*
36  if (sc.isFailure()) {
37  ATH_MSG_WARNING( "Unable to retrieve BunchCrossingData. Switch off CaloBaselineMon" );
38  m_pedestalMon_BCIDmin = -1;
39  m_bcidtoolMon_BCIDmax = -1;
40  }
41  */
42 
44 
46 
47  m_etaBinWidth.resize(m_partNames.size());
48  m_inv_etaBinWidth.resize(m_partNames.size());
49 
50  m_partMap.resize(3);
51  m_partMap = {-1,-1,-1};
52  // 0:EM / 1:HEC / FCal:2
53  for (uint iPart = 0;iPart < m_partNames.size();iPart++){
54  if (m_partNames[iPart] == "EM") m_partMap[0] = iPart;
55  if (m_partNames[iPart] == "HEC") m_partMap[1] = iPart;
56  if (m_partNames[iPart] == "FCal") m_partMap[2] = iPart;
57  if (m_partNames[iPart] == "HEC+FCal"){
58  m_partMap[1] = iPart;
59  m_partMap[2] = iPart;
60  }
61  m_etaBinWidth[iPart] = (m_etaMax[iPart]-m_etaMin[iPart])/((float) m_nbOfEtaBins[iPart]);
62  m_inv_etaBinWidth[iPart] = ((float) m_nbOfEtaBins[iPart])/(m_etaMax[iPart]-m_etaMin[iPart]);
63  }
64 
65  m_histoGroups.reserve(m_partNames.size());
66  for (unsigned i=0; i<m_partNames.size(); ++i) {
67  m_histoGroups.push_back( Monitored::buildToolMap<int>(m_tools,m_partNames[i], m_nbOfEtaBins[i]));
68  }
69 
71 }
72 
74 StatusCode CaloBaselineMonAlg::fillHistograms(const EventContext& ctx) const {
75 
76  StatusCode sc = StatusCode::SUCCESS;
77 
78  bool ifPass = 1;
79  bool passBeamBackgroundRemoval = 0;
80  sc = checkFilters(ifPass, passBeamBackgroundRemoval,m_MonGroupName, ctx);
81  if(sc.isFailure() || !ifPass) return StatusCode::SUCCESS;
82 
83  ATH_MSG_DEBUG("checkFilters() passed");
84 
85  int lumiBlock = ctx.eventID().lumi_block();
86  int bcid = ctx.eventID().bunch_crossing_id();
87 
88  bool thisEvent_bool_pedestalMon = false;
89  bool thisEvent_bool_bcidtoolMon = false;
90 
92  const BunchCrossingCondData* bunchCrossing=*bccd;
93  if (!bunchCrossing) {
94  ATH_MSG_WARNING("Failed to retrieve Bunch Crossing data, no monitoring in this event");
95  return StatusCode::SUCCESS;
96  }
97  // Fill pedestalMon only when the bunch is empty and far away enough from the last train.
98  if (m_bool_pedestalMon){
99  // FIXME: gapAfterBunch and gapBeforeBunch are not yet implemented in BunchCrossingCondData
100  //if ((not bunchCrossing->isFilled(bcid)) and (bunchCrossing->gapAfterBunch(bcid) >= m_pedestalMon_BCIDmin*25.) and (bunchCrossing->gapBeforeBunch(bcid) >= m_pedestalMon_BCIDmin*25.)) thisEvent_bool_pedestalMon = true;
101  if(!bunchCrossing->isInTrain(bcid)) thisEvent_bool_pedestalMon = true;
102  }
103  ATH_MSG_DEBUG("m_bool_pedestalMon passed");
104  // Fill bcidtoolMon only when the bunch is in a bunch train and within accepted BCID range.
105  if (m_bool_bcidtoolMon){
106  if (bunchCrossing->isInTrain(bcid) and bunchCrossing->distanceFromFront(bcid,BunchCrossingCondData::BunchCrossings) <= m_bcidtoolMon_BCIDmax) thisEvent_bool_bcidtoolMon = true;
107  }
108  ATH_MSG_DEBUG("m_bool_bcidtoolMon passed");
109 
110  ATH_MSG_DEBUG(thisEvent_bool_pedestalMon<<" "<<thisEvent_bool_bcidtoolMon);
111 
112  if (not (thisEvent_bool_pedestalMon or thisEvent_bool_bcidtoolMon)) return sc;
113 
115 
116  if(!cellCont.isValid() ) {
117  ATH_MSG_WARNING("No CaloCell container found in TDS");
118  return sc;
119  }
120 
121  // Initialize the sum per eta band for each partition
122  std::vector<std::vector<float>> sum_partition_eta;
123  sum_partition_eta.resize(m_partNames.size());
124  for (uint iPart = 0;iPart < m_partNames.size();iPart++){
125  sum_partition_eta[iPart].resize(m_nbOfEtaBins[iPart]);
126  }
127 
128  for (uint iPart = 0;iPart < m_partNames.size();iPart++){
129  for (uint iEta = 0; iEta < m_nbOfEtaBins[iPart]; iEta ++){
130  sum_partition_eta[iPart][iEta] = 0.;
131  }
132  }
133 
134  CaloCellContainer::const_iterator it = cellCont->begin();
135  CaloCellContainer::const_iterator it_e = cellCont->end();
136 
137  for ( ; it!=it_e;++it) {
138 
139  // cell info
140  const CaloCell* cell = *it;
141  Identifier id = cell->ID();
142  float energy = cell->energy();
143  double eta = cell->caloDDE()->eta_raw();
144 
145  int partThisAlgo = 0;
146  if (m_calo_id->is_em(id)) partThisAlgo = m_partMap[0];
147  if (m_calo_id->is_hec(id)) partThisAlgo = m_partMap[1];
148  if (m_calo_id->is_fcal(id)) partThisAlgo = m_partMap[2];
149 
150 
151  if ((eta<m_etaMin[partThisAlgo]) or (eta>m_etaMax[partThisAlgo])) continue;
152  int etaBin = std::floor((eta-m_etaMin[partThisAlgo])*m_inv_etaBinWidth[partThisAlgo]);
153 
154  sum_partition_eta[partThisAlgo][etaBin] += energy;
155  } // cell iter loop
156 
157 
158  // Loop on cells is over. Now fill histograms with sum per eta.
159  auto bcidfill = Monitored::Scalar<int>("BCID",bcid);
160  fill(m_MonGroupName,bcidfill);
161  if (thisEvent_bool_pedestalMon ) {
162  for (uint iPart = 0;iPart < m_partNames.size();iPart++){
163  auto sum = Monitored::Scalar<float>("sumPedEta_"+m_partNames[iPart],-1);
164  auto etaToBeFilled = Monitored::Scalar<float>("pedEta_"+m_partNames[iPart],-1);
165  auto lb = Monitored::Scalar<int>("LB_"+m_partNames[iPart],lumiBlock);
166  auto bcideta = Monitored::Scalar<int>("etaBCID_"+m_partNames[iPart],bcid);
167  for (uint iEta = 0; iEta < m_nbOfEtaBins[iPart]; iEta ++){
168  // Normalize the sum by the \delta\eta.\delta\phi.\mu
169  sum = sum_partition_eta[iPart][iEta]*(m_inv_etaBinWidth[iPart])/(2*M_PI)/lbAverageInteractionsPerCrossing(ctx);
170  etaToBeFilled = ((float) iEta)*m_etaBinWidth[iPart] + m_etaMin[iPart];
171  fill(m_MonGroupName,lb,etaToBeFilled,sum);
172  fill(m_tools[m_histoGroups.at(iPart).at(iEta)],bcideta,sum);
173  }
174  }
175  }
176 
177  if (thisEvent_bool_bcidtoolMon ) {
178  for (uint iPart = 0;iPart < m_partNames.size();iPart++){
179  auto sum = Monitored::Scalar<float>("sumBCIDEta_"+m_partNames[iPart],-1);
180  auto etaToBeFilled = Monitored::Scalar<float>("bcidEta_"+m_partNames[iPart],-1);
181  auto lb = Monitored::Scalar<int>("LB_"+m_partNames[iPart],lumiBlock);
182  auto bcideta = Monitored::Scalar<int>("etaBCID_"+m_partNames[iPart],bcid);
183  for (uint iEta = 0; iEta < m_nbOfEtaBins[iPart]; iEta ++){
184  // Normalize the sum by the \delta\eta.\delta\phi.\mu
185  sum = sum_partition_eta[iPart][iEta]*(m_inv_etaBinWidth[iPart])/(2*M_PI)/lbAverageInteractionsPerCrossing(ctx);
186  etaToBeFilled = ((float) iEta)*m_etaBinWidth[iPart] + m_etaMin[iPart];
187  fill(m_MonGroupName,lb,etaToBeFilled,sum);
188  fill(m_tools[m_histoGroups.at(iPart).at(iEta)],bcideta,sum);
189  }
190  }
191  }
192 
193  return sc;
194 }
195 
196 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloMonAlgBase::checkFilters
StatusCode checkFilters(bool &ifPass, bool &passBeamBackgroundRemoval, const std::string &MonGroupName, const EventContext &ctx) const
Definition: CaloMonAlgBase.cxx:61
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
BunchCrossingCondData
Definition: BunchCrossingCondData.h:23
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CaloBaselineMonAlg::m_histoGroups
std::vector< std::vector< int > > m_histoGroups
Definition: CaloBaselineMonAlg.h:69
CaloBaselineMonAlg::m_bcDataKey
SG::ReadCondHandleKey< BunchCrossingCondData > m_bcDataKey
Definition: CaloBaselineMonAlg.h:40
CaloBaselineMonAlg::m_etaMax
Gaudi::Property< std::vector< float > > m_etaMax
Definition: CaloBaselineMonAlg.h:54
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
skel.it
it
Definition: skel.GENtoEVGEN.py:396
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CaloMonAlgBase::initialize
virtual StatusCode initialize()
initialize
Definition: CaloMonAlgBase.cxx:25
CaloCell_Base_ID::is_hec
bool is_hec(const Identifier id) const
test if the id belongs to the HEC
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
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloBaselineMonAlg::m_inv_etaBinWidth
std::vector< float > m_inv_etaBinWidth
Definition: CaloBaselineMonAlg.h:62
CaloBaselineMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override final
adds event to the monitoring histograms
Definition: CaloBaselineMonAlg.cxx:74
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
CaloCell_Base_ID::is_em
bool is_em(const Identifier id) const
test if the id belongs to LArEM
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:148
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloBaselineMonAlg::m_nbOfEtaBins
Gaudi::Property< std::vector< uint > > m_nbOfEtaBins
Definition: CaloBaselineMonAlg.h:56
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloBaselineMonAlg::m_bcidtoolMon_BCIDmax
Gaudi::Property< int > m_bcidtoolMon_BCIDmax
Definition: CaloBaselineMonAlg.h:52
CaloCell_Base_ID::is_fcal
bool is_fcal(const Identifier id) const
test if the id belongs to the FCAL - true also for MiniFCAL
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
DQAtlasReadyFilterTool.h
BunchCrossingCondData::BunchCrossings
@ BunchCrossings
Distance in units of 25 nanoseconds.
Definition: BunchCrossingCondData.h:132
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloBaselineMonAlg::m_partNames
Gaudi::Property< std::vector< std::string > > m_partNames
Definition: CaloBaselineMonAlg.h:59
CaloMonAlgBase::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloMonAlgBase.h:43
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
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
BunchCrossingCondData::distanceFromFront
int distanceFromFront(const bcid_type bcid, const BunchDistanceType type=NanoSec) const
The distance of the specific bunch crossing from the front of the train.
Definition: BunchCrossingCondData.cxx:35
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloBaselineMonAlg::m_etaBinWidth
std::vector< float > m_etaBinWidth
Definition: CaloBaselineMonAlg.h:61
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
Units.h
Wrapper to avoid constant divisions when using units.
AthMonitorAlgorithm::lbAverageInteractionsPerCrossing
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) const
Calculate the average mu, i.e.
Definition: AthMonitorAlgorithm.cxx:222
CaloBaselineMonAlg::m_bool_pedestalMon
bool m_bool_pedestalMon
Definition: CaloBaselineMonAlg.h:65
CaloBaselineMonAlg::initialize
virtual StatusCode initialize() override final
initialize
Definition: CaloBaselineMonAlg.cxx:27
BunchCrossingCondData::isInTrain
bool isInTrain(const bcid_type bcid) const
Function deciding if a given bunch crossing is in a filled train.
Definition: BunchCrossingCondData.h:376
CaloBaselineMonAlg::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: CaloBaselineMonAlg.h:38
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloBaselineMonAlg::m_MonGroupName
Gaudi::Property< std::string > m_MonGroupName
Definition: CaloBaselineMonAlg.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloBaselineMonAlg::m_partMap
std::vector< int > m_partMap
Definition: CaloBaselineMonAlg.h:90
CaloBaselineMonAlg::CaloBaselineMonAlg
CaloBaselineMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloBaselineMonAlg.cxx:18
CaloBaselineMonAlg::m_pedestalMon_BCIDmin
Gaudi::Property< int > m_pedestalMon_BCIDmin
Definition: CaloBaselineMonAlg.h:49
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
CaloMonAlgBase
Definition: CaloMonAlgBase.py:1
CaloBaselineMonAlg::m_etaMin
Gaudi::Property< std::vector< float > > m_etaMin
Definition: CaloBaselineMonAlg.h:55
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
DQBadLBFilterTool.h
CaloBaselineMonAlg::m_bool_bcidtoolMon
bool m_bool_bcidtoolMon
Definition: CaloBaselineMonAlg.h:66
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:74
CaloBaselineMonAlg.h
readCCLHist.float
float
Definition: readCCLHist.py:83
Identifier
Definition: IdentifierFieldParser.cxx:14