ATLAS Offline Software
LArTTL1Calib.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // +======================================================================+
6 // + +
7 // + Author ........: F. Ledroit +
8 // + Institut ......: ISN Grenoble +
9 // + Creation date .: 09/01/2003 +
10 // + +
11 // +======================================================================+
12 //
13 // ........ includes
14 //
15 #include "LArL1Sim/LArTTL1Calib.h"
16 // .......... utilities
17 //
18 
20 #include "LArRawEvent/LArTTL1.h"
22 //
23 // ........ Gaudi needed includes
24 //
25 #include "Gaudi/Property.h"
26 #include "GaudiKernel/ISvcLocator.h"
27 //
28 #include "GaudiKernel/INTupleSvc.h"
29 // #include "GaudiKernel/NTupleDirectory.h"
30 #include "GaudiKernel/SmartDataPtr.h"
31 #include "StoreGate/StoreGateSvc.h"
32 
33 //
34 
35 LArTTL1Calib::LArTTL1Calib(const std::string& name, ISvcLocator* pSvcLocator)
36  : AthAlgorithm(name, pSvcLocator)
37 // + -------------------------------------------------------------------- +
38 // + Author ........: F. Ledroit +
39 // + Creation date .: 20/04/2004 +
40 // + Subject: TTL1 Calib constructor +
41 // + -------------------------------------------------------------------- +
42 {
43  //
44  // ........ default values of private data
45  //
46  // m_thresholdGeVTTs = 0.1; // pb here: threshold depends on whether
47  // calib already applied or not... m_thresholdGeVTTs = 0.001; // and
48  // whether want to study calib or noise
49  m_thresholdGeVTTs = 0.;
50  m_maxNtt = 8000;
51  // m_maxNtt = 500;
52 
53  m_pnt = nullptr;
54 
55  m_lvl1Helper = nullptr;
56 
57  //
58  return;
59 }
60 
64  return;
65 }
66 
68  // +======================================================================+
69  // + +
70  // + Author ........: F. Ledroit +
71  // + Creation date .: 09/01/2003 +
72  // + +
73  // +======================================================================+
74  //
75  // ......... declaration
76  //
77  ATH_MSG_DEBUG("in initialize()");
78 
79  NTuple::Directory* dir = nullptr;
80  NTupleFilePtr file1(ntupleSvc(), "/NTUPLES/FILE1");
81 
82  if (file1 != 0) {
83  if (!(dir = ntupleSvc()->createDirectory("/NTUPLES/FILE1/DIR"))) {
84  ATH_MSG_ERROR("Cannot create directory /NTUPLES/FILE1/DIR");
85  }
86  } else {
87  ATH_MSG_ERROR("Cannot access file /NTUPLES/FILE1");
88  return StatusCode::FAILURE;
89  }
90 
91  ATH_MSG_DEBUG("created directory /NTUPLES/FILE1/DIR");
92 
93  NTuplePtr pnt(ntupleSvc(), "/NTUPLES/FILE1/DIR/10");
94  if (!pnt) {
95  pnt = ntupleSvc()->book(dir, 10, CLID_ColumnWiseTuple, "LArLvl1TT");
96 
97  if (pnt) {
98  ATH_MSG_DEBUG("booked ntuple LArLvl1TT");
99  m_pnt = pnt;
100 
101  ATH_CHECK(pnt->addItem("nTotEm", m_ntotem));
102  ATH_CHECK(pnt->addItem("EtTotEm", m_etotem));
103  ATH_CHECK(pnt->addItem("n3x3Em", m_n3x3em));
104  ATH_CHECK(pnt->addItem("E3x3Em", m_e3x3em));
105  ATH_CHECK(pnt->addItem("EmostEm", m_emostem));
106  ATH_CHECK(pnt->addItem("BarrelECEm", m_bec_mostEem));
107  ATH_CHECK(pnt->addItem("EmFcalEm", m_emfcal_mostEem));
108  ATH_CHECK(pnt->addItem("IetaEm", m_Ieta_mostEem));
109  ATH_CHECK(pnt->addItem("LphiEm", m_Lphi_mostEem));
110  ATH_CHECK(pnt->addItem("nTTaboveThrEm", m_nttem, 0, m_maxNtt));
111  ATH_CHECK(pnt->addItem("EtTTEm", m_nttem, m_ettem));
112  ATH_CHECK(pnt->addItem("BECTTEm", m_nttem, m_becttem));
113  ATH_CHECK(pnt->addItem("EmFcalTTEm", m_nttem, m_emfcalttem));
114  ATH_CHECK(pnt->addItem("IetaTTEm", m_nttem, m_Ietattem));
115  ATH_CHECK(pnt->addItem("LphiTTEm", m_nttem, m_Lphittem));
116 
117  ATH_CHECK(pnt->addItem("nTotHad", m_ntothad));
118  ATH_CHECK(pnt->addItem("EtTotHad", m_etothad));
119  ATH_CHECK(pnt->addItem("n3x3Had", m_n3x3had));
120  ATH_CHECK(pnt->addItem("E3x3Had", m_e3x3had));
121  ATH_CHECK(pnt->addItem("EmostHad", m_emosthad));
122  ATH_CHECK(pnt->addItem("HecFcalHad", m_hecfcal_mostEhad));
123  ATH_CHECK(pnt->addItem("IetaHad", m_Ieta_mostEhad));
124  ATH_CHECK(pnt->addItem("LphiHad", m_Lphi_mostEhad));
125  ATH_CHECK(pnt->addItem("nTTaboveThrHad", m_ntthad, 0, m_maxNtt));
126  ATH_CHECK(pnt->addItem("EtTTHad", m_ntthad, m_etthad));
127  ATH_CHECK(pnt->addItem("HecFcalTTHad", m_ntthad, m_hecfcaltthad));
128  ATH_CHECK(pnt->addItem("IetaTTHad", m_ntthad, m_Ietatthad));
129  ATH_CHECK(pnt->addItem("LphiTTHad", m_ntthad, m_Lphitthad));
130 
131  } else {
132  ATH_MSG_ERROR("could not book Ntuple");
133  }
134  } else {
135  ATH_MSG_ERROR("Ntuple is already booked");
136  }
137  //
138 
140 
141  ATH_MSG_DEBUG("Initialization completed successfully");
142  return StatusCode::SUCCESS;
143 }
144 
146  // +======================================================================+
147  // + +
148  // + Author: F. Ledroit +
149  // + Creation date: 2003/01/13 +
150  // + +
151  // +======================================================================+
152  //
153  // ......... declarations
154  //
155  ATH_MSG_DEBUG("Begining of execution");
156 
158  Identifier ttOffId;
159 
160  std::vector<std::string> containerVec; // FIX ME USING PROPERTIES !!!
161  containerVec.push_back("LArTTL1EM");
162  containerVec.push_back("LArTTL1HAD");
163 
164  //
165  // ............ loop over the wanted ttl1 containers (1 em, 1 had)
166  //
167 
168  for (unsigned int iTTL1Container = 0; iTTL1Container < containerVec.size();
169  iTTL1Container++) {
170  //
171  // ..... Get the pointer to the TTL1 Container from StoreGate
172  //
173  ATH_MSG_DEBUG(" asking for: " << containerVec[iTTL1Container]);
174 
175  const LArTTL1Container* ttl1_container;
176  ATH_CHECK(
177  evtStore()->retrieve(ttl1_container, containerVec[iTTL1Container]));
178 
179  //
180  ATH_MSG_DEBUG("number of ttl1s: " << ttl1_container->size());
181 
182  int samp = iTTL1Container;
183  int indexem = 0;
184  int indexhad = 0;
185 
186  float e_mostE = 0.;
187  int bec_mostE = 99;
188  int hecfcal_mostE = 99;
189  int Ieta_mostE = 99;
190  int Lphi_mostE = 99;
191  int phiMax_mostE = -99;
192 
193  //
194  // ....... loop over ttl1s and get informations
195  //
196 
197  for (const LArTTL1* ttl1 : *ttl1_container) {
198  ttOffId = ttl1->ttOfflineID();
199  std::vector<float> sampleV = ttl1->samples();
200  float e = sampleV[3] * 1e-3; // go to GeV
201  int reg = m_lvl1Helper->region(ttOffId);
202  int eta = m_lvl1Helper->eta(ttOffId);
203  int bec = 99;
204  int hecfcal = 99;
205  int Ieta = 99;
206  decodeInverseTTChannel(reg, samp, eta, bec, hecfcal, Ieta);
207  int Lphi = m_lvl1Helper->phi(ttOffId) + 1;
208  int phiMax = m_lvl1Helper->phi_max(ttOffId);
209  if (e > e_mostE) {
210  e_mostE = e;
211  bec_mostE = bec;
212  hecfcal_mostE = hecfcal;
213  Ieta_mostE = Ieta;
214  Lphi_mostE = Lphi;
215  phiMax_mostE = phiMax;
216  }
217 
218  if (samp == 0) {
219  // EM towers
220  m_etotem += e;
221  if (indexem < m_maxNtt) {
222  if (e > m_thresholdGeVTTs) {
223  m_ettem[indexem] = e;
224  m_becttem[indexem] = bec;
225  m_emfcalttem[indexem] = hecfcal;
226  m_Ietattem[indexem] = Ieta;
227  m_Lphittem[indexem] = Lphi;
228  indexem++;
229  }
230  } else {
231  if (m_maxNtt == indexem) {
232  ATH_MSG_WARNING("Too many em TT. Save only " << m_maxNtt);
233  break;
234  }
235  }
236  } else {
237  // HAD towers
238  m_etothad += e;
239  if (indexhad < m_maxNtt) {
240  if (e > m_thresholdGeVTTs) {
241  m_etthad[indexhad] = e;
242  m_hecfcaltthad[indexhad] = hecfcal;
243  m_Ietatthad[indexhad] = Ieta;
244  m_Lphitthad[indexhad] = Lphi;
245  indexhad++;
246  }
247  } else {
248  if (m_maxNtt == indexhad) {
249  ATH_MSG_WARNING("Too many had TT. Save only " << m_maxNtt);
250  break;
251  }
252  }
253  }
254 
255  } // .... end of loop over ittl1s
256  ATH_MSG_DEBUG("number of em/had ttl1s: " << indexem << " / " << indexhad);
257 
258  int etaLim = 13; // barrel-ec transition
259  if (hecfcal_mostE > 0) {
260  etaLim = 14;
261  }
262  if (samp == 0) {
263  // em:
264  m_ntotem = ttl1_container->size();
265  m_nttem = indexem;
266  for (int i = 0; i < indexem; ++i) {
267  int deltaEta = std::abs(Ieta_mostE - m_Ietattem[i]);
268  int deltaPhi = std::abs(Lphi_mostE - m_Lphittem[i]); // not quite 3x3
269  if ((deltaEta <= 1 ||
270  deltaEta >= etaLim) // because phi granularity changes
271  && (deltaPhi <= 1 ||
272  deltaPhi == phiMax_mostE)) { // at eta=2.5 and 3.2
273  m_n3x3em += 1;
274  m_e3x3em += m_ettem[i];
275  }
276  }
277  m_emostem = e_mostE;
278  m_bec_mostEem = bec_mostE;
279  m_emfcal_mostEem = hecfcal_mostE;
280  m_Ieta_mostEem = Ieta_mostE;
281  m_Lphi_mostEem = Lphi_mostE;
282  } else {
283  // had:
284  m_ntothad = ttl1_container->size();
285  m_ntthad = indexhad;
286  for (int i = 0; i < indexhad; ++i) {
287  int deltaEta = std::abs(Ieta_mostE - m_Ietatthad[i]);
288  int deltaPhi = std::abs(Lphi_mostE - m_Lphitthad[i]);
289  if ((deltaEta <= 1 || deltaEta >= etaLim) &&
290  (deltaPhi <= 1 || deltaPhi == phiMax_mostE)) {
291  m_n3x3had += 1;
292  m_e3x3had += m_etthad[i];
293  }
294  }
295  m_emosthad = e_mostE;
296  m_hecfcal_mostEhad = hecfcal_mostE;
297  m_Ieta_mostEhad = Ieta_mostE;
298  m_Lphi_mostEhad = Lphi_mostE;
299  }
300 
301  } // .... end of loop over containers
302  ATH_MSG_DEBUG("end of loop over containers, write record");
303 
304  ATH_CHECK(ntupleSvc()->writeRecord(m_pnt));
305  return StatusCode::SUCCESS;
306 }
307 
309  // +======================================================================+
310  // + +
311  // + Author: F. Ledroit +
312  // + Creation date: 2003/01/13 +
313  // + +
314  // +======================================================================+
315  //
316  ATH_MSG_DEBUG(" LArTTL1Calib finalize completed successfully");
317  return StatusCode::SUCCESS;
318 }
319 
321  int& bec, int& emhf,
322  int& Ieta) const {
323  // fix me !!! this method is duplicated from LArCablingService
324  if (region == 0) {
325  if (eta <= 14) {
326  bec = 0; // EM barrel
327  emhf = 0;
328  Ieta = eta + 1;
329  } else {
330  bec = 1; // EMEC or HEC
331  emhf = layer;
332  Ieta = eta - 13;
333  }
334  } else if (region == 1 || region == 2) {
335  bec = 1;
336  emhf = layer;
337  if (region == 1) {
338  Ieta = eta + 12;
339  } else {
340  Ieta = 15;
341  }
342  } else if (region == 3) { // FCAL only
343  bec = 1;
344  emhf = 2 + layer;
345  Ieta = eta + 1;
346  }
347 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArTTL1Calib::m_hecfcaltthad
NTuple::Array< long > m_hecfcaltthad
Definition: LArTTL1Calib.h:92
LArTTL1Calib::m_Lphi_mostEem
NTuple::Item< long > m_Lphi_mostEem
Definition: LArTTL1Calib.h:74
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
LArTTL1Calib::m_Lphittem
NTuple::Array< long > m_Lphittem
Definition: LArTTL1Calib.h:80
LArTTL1Calib::m_etothad
NTuple::Item< float > m_etothad
Definition: LArTTL1Calib.h:83
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LArTTL1Calib::m_maxNtt
int m_maxNtt
Definition: LArTTL1Calib.h:59
LArTTL1Calib::m_hecfcal_mostEhad
NTuple::Item< long > m_hecfcal_mostEhad
Definition: LArTTL1Calib.h:87
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
LArTTL1Calib::m_nttem
NTuple::Item< long > m_nttem
Definition: LArTTL1Calib.h:75
CaloLVL1_ID::phi_max
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
Definition: CaloLVL1_ID.cxx:495
LArTTL1Calib::m_lvl1Helper
const CaloLVL1_ID * m_lvl1Helper
Definition: LArTTL1Calib.h:96
LArTTL1Calib::execute
virtual StatusCode execute()
Definition: LArTTL1Calib.cxx:145
LArTTL1Calib::~LArTTL1Calib
~LArTTL1Calib()
destructor
Definition: LArTTL1Calib.cxx:61
CaloLVL1_ID::region
int region(const Identifier id) const
return region according to :
Definition: CaloLVL1_ID.h:647
LArTTL1Calib::m_emfcalttem
NTuple::Array< long > m_emfcalttem
Definition: LArTTL1Calib.h:78
LArTTL1Container.h
LArTTL1Calib::m_n3x3em
NTuple::Item< long > m_n3x3em
Definition: LArTTL1Calib.h:68
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
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LArTTL1Calib::m_ettem
NTuple::Array< float > m_ettem
Definition: LArTTL1Calib.h:76
LArTTL1Calib::decodeInverseTTChannel
void decodeInverseTTChannel(int region, int layer, int eta, int &bec, int &emhf, int &Ieta) const
Definition: LArTTL1Calib.cxx:320
LArTTL1Calib::m_ntthad
NTuple::Item< long > m_ntthad
Definition: LArTTL1Calib.h:90
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:66
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArTTL1Calib::m_Ietattem
NTuple::Array< long > m_Ietattem
Definition: LArTTL1Calib.h:79
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
LArTTL1Calib::m_thresholdGeVTTs
float m_thresholdGeVTTs
Definition: LArTTL1Calib.h:58
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LArTTL1Calib::m_emosthad
NTuple::Item< float > m_emosthad
Definition: LArTTL1Calib.h:86
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArTTL1Calib::m_ntothad
NTuple::Item< long > m_ntothad
Definition: LArTTL1Calib.h:82
LArTTL1Container
Container class for LArTTL1.
Definition: LArTTL1Container.h:24
AthAlgorithm
Definition: AthAlgorithm.h:47
LArTTL1Calib::initialize
virtual StatusCode initialize()
Definition: LArTTL1Calib.cxx:67
beamspotman.dir
string dir
Definition: beamspotman.py:623
LArTTL1Calib::m_bec_mostEem
NTuple::Item< long > m_bec_mostEem
Definition: LArTTL1Calib.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArTTL1Calib::m_etotem
NTuple::Item< float > m_etotem
Definition: LArTTL1Calib.h:67
CaloLVL1_ID::eta
int eta(const Identifier id) const
return eta according to :
Definition: CaloLVL1_ID.h:653
LArTTL1Calib::LArTTL1Calib
LArTTL1Calib(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: LArTTL1Calib.cxx:35
LArTTL1.h
LArTTL1Calib::m_n3x3had
NTuple::Item< long > m_n3x3had
Definition: LArTTL1Calib.h:84
LArTTL1Calib::m_pnt
NTuple::Tuple * m_pnt
Definition: LArTTL1Calib.h:62
LArTTL1Calib::m_emostem
NTuple::Item< float > m_emostem
Definition: LArTTL1Calib.h:70
LArTTL1Calib::m_e3x3had
NTuple::Item< float > m_e3x3had
Definition: LArTTL1Calib.h:85
CaloLVL1_ID.h
LArTTL1Calib::m_Ietatthad
NTuple::Array< long > m_Ietatthad
Definition: LArTTL1Calib.h:93
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArTTL1Calib::m_ntotem
NTuple::Item< long > m_ntotem
Definition: LArTTL1Calib.h:66
LArTTL1Calib::m_emfcal_mostEem
NTuple::Item< long > m_emfcal_mostEem
Definition: LArTTL1Calib.h:72
LArTTL1Calib::m_Ieta_mostEhad
NTuple::Item< long > m_Ieta_mostEhad
Definition: LArTTL1Calib.h:88
LArTTL1Calib::m_etthad
NTuple::Array< float > m_etthad
Definition: LArTTL1Calib.h:91
LArTTL1Calib::m_becttem
NTuple::Array< long > m_becttem
Definition: LArTTL1Calib.h:77
LArTTL1Calib::m_Lphi_mostEhad
NTuple::Item< long > m_Lphi_mostEhad
Definition: LArTTL1Calib.h:89
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LArTTL1Calib::m_Lphitthad
NTuple::Array< long > m_Lphitthad
Definition: LArTTL1Calib.h:94
LArTTL1
Liquid Argon TT L1 sum class.
Definition: LArTTL1.h:29
LArTTL1Calib::finalize
virtual StatusCode finalize()
Definition: LArTTL1Calib.cxx:308
LArTTL1Calib::m_Ieta_mostEem
NTuple::Item< long > m_Ieta_mostEem
Definition: LArTTL1Calib.h:73
LArTTL1Calib::m_e3x3em
NTuple::Item< float > m_e3x3em
Definition: LArTTL1Calib.h:69
LArTTL1Calib.h
Identifier
Definition: IdentifierFieldParser.cxx:14