ATLAS Offline Software
TileTOFTool.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 "StoreGate/ReadHandle.h"
8 
9 #include "TileTOFTool.h"
11 #include "TileEvent/TileCell.h"
12 #include "CaloIdentifier/TileID.h"
13 
14 #include <cmath>
15 #include "TFile.h"
16 #include "TTree.h"
17 #include "TF1.h"
18 
20 
21 TileTOFTool::TileTOFTool(const std::string& type, const std::string& name, const IInterface* pParent )
22  : AthAlgTool( type, name, pParent ),
23  m_tileID(nullptr),
24  m_LBA_LBC(),
25  m_LBA_EBA(),
26  m_LBC_EBC(),
27  m_Nlbc(),
28  m_Neba(),
29  m_Nebc(),
30  m_LA_EA(0),
31  m_LA_LC(0),
32  m_LA_EC(0)
33 {
34  declareInterface<ITileCalibTool>( this );
35 
36  m_timeCor = new float[4][64]();
37  m_tcor = new float[4][32][32]();
38  m_nPair = new int[4][32][32]();
39 }
40 
42 
43  delete[] m_timeCor;
44  delete[] m_tcor;
45  delete[] m_nPair;
46 
47 }
48 
50 
52 {
53  ATH_MSG_INFO ( "initialize()" );
54 
56 
57  return StatusCode::SUCCESS;
58 }
59 
61 {
62  ATH_MSG_INFO ( "initializeNtuple(" << runNumber << "," << runType << "," << rootFile << ")" );
63  return StatusCode::SUCCESS;
64 }
65 
67 {
68  ATH_MSG_INFO ( "execute()" );
69 
71  ATH_CHECK( cellCONT.isValid() );
72  ATH_MSG_DEBUG ( "Cell container found" );
73 
74  CaloCellContainer::const_iterator iCell = cellCONT->begin();
75  CaloCellContainer::const_iterator lastCell = cellCONT->end();
76 
78 
79  int n = 0;
80  double x[20] = {0};
81  double y[20] = {0};
82  double z[20] = {0};
83  double t[20] = {0};
84  int part[20] = {0};
85  int mod[20] = {0};
86 
87  int section;
88  int side;
89 
90  for( ; iCell != lastCell; ++iCell) // loop over Calo cells
91  {
92  const CaloCell* cell_ptr = *iCell; // pointer to cell object
93 
94  if ( m_tileID->is_tile(cell_ptr->ID()) )
95  {
96  const TileCell* tile_cell = dynamic_cast<const TileCell*> (cell_ptr);
97 
98  if ((tile_cell!=nullptr)&&((tile_cell->ene1())>150.)&&((tile_cell->ene2())>150.)&&((tile_cell->energy())<5000.)&&(fabs(tile_cell->timeDiff())<3.5)&&(fabs(tile_cell->time())>0.00000001)) // cut to select TileCal cells crossed by muons
99  {
100  Identifier id = tile_cell->ID();
101 
102  x[n] = tile_cell->x();
103  y[n] = tile_cell->y();
104  z[n] = tile_cell->z();
105  t[n] = tile_cell->time();
106  mod[n] = m_tileID->module(id);
107 
108  section = m_tileID->section(id);
109  side = m_tileID->side(id);
110 
111  if((section == 2 || section ==3) && side == 1){part[n] = 0;} //EBA
112  else if(section == 1 && side == 1){part[n] = 1;} //LBA
113  else if(section == 1 && side == -1){part[n] = 2;} //LBC
114  else if((section == 2 || section ==3) && side == -1){part[n] = 3;} //EBC
115  n++;
116  if(n==9){break;} // events with air showers not considered
117  }
118  }
119  }
120 
121 // calculate a matrix for each partition with the time offset of each module at the bottom side of TileCal wrt each module at the bottom
122 
123 //function to calculate difference between measured time and expected TOF of the muon
124 #define TIMECOR(MOD_REF1, MOD_REF2, PART_REF1, PART_REF2, COUNT, TCOR) \
125  do { \
126  if (mod[i]==MOD_REF1 && mod[j]==MOD_REF2 && \
127  part[i]==PART_REF1 && part[j]==PART_REF2) { \
128  float TOF = sqrt(((x[j]-x[i])*(x[j]-x[i]))+((y[j]-y[i])*(y[j]-y[i]))+((z[j]-z[i])*(z[j]-z[i])))/299.792; \
129  float tc = t[j]-t[i]-TOF; \
130  ++COUNT; \
131  TCOR += tc; \
132  } \
133  } while(0)
134 
135 
136  if(n<9){
137  for(int i=0; i<n; i++) {
138  for(int j=0; j<n; j++) {
139  for(int s=0; s<4; s++) {
140  for(int k=0; k<32; k++) {
141  for(int l=0; l<32; l++) {
142  TIMECOR(k,l+32,s,s, m_nPair[s][k][l], m_tcor[s][k][l]);
143  }
144  }
145  }
146 
147  for(int s=0; s<4; s++){
148  TIMECOR(15,s+46,1,0, m_Neba[s], m_LBA_EBA[s]);
149  TIMECOR(15,s+46,1,2, m_Nlbc[s], m_LBA_LBC[s]);
150  TIMECOR(15,s+46,2,3, m_Nebc[s], m_LBC_EBC[s]);
151  }
152  }
153  }
154  }
155 
156  return StatusCode::SUCCESS;
157 }
158 
160 {
161  ATH_MSG_INFO ( "finalizeCalculations()" );
162 
163 // finalize calculation of the matrix
164 
165  for(int s=0; s<4; s++) {
166  for(int k=0; k<32; k++) {
167  for(int l=0; l<32; l++) {
168  if(m_nPair[s][k][l]!=0) {
169  m_tcor[s][k][l] = m_tcor[s][k][l]/m_nPair[s][k][l];
170  }
171  }
172  }}
173 
174 
175 // Offsets between different partitions
176 
177  int p0 = 0, p2 = 0, p3 = 0;
178  m_LA_EA = 0.;
179  m_LA_LC = 0.;
180  m_LA_EC = 0.;
181 
182  for(int s=0; s<4; s++){
183  if(m_Neba[s]!=0) {
184  m_LBA_EBA[s] = m_LBA_EBA[s]/m_Neba[s];
185  if(m_nPair[0][15][s+14]>5) {
186  m_LA_EA = m_LA_EA + m_tcor[0][15][s+14] - m_LBA_EBA[s];
187  p0++;
188  }
189  }
190 
191  if(m_Nlbc[s]!=0) {
192  m_LBA_LBC[s] = m_LBA_LBC[s]/m_Nlbc[s];
193  if(m_nPair[2][15][s+14]>5) {
194  m_LA_LC = m_LA_LC + m_tcor[2][15][s+14] - m_LBA_LBC[s];
195  p2++;
196  }
197  }
198 
199  if(m_Nebc[s]!=0) {
200  m_LBC_EBC[s] = m_LBC_EBC[s]/m_Nlbc[s];
201  if(m_nPair[2][15][s+14]>5) {
202  m_LA_EC = m_LA_EC + m_LA_LC + m_tcor[3][15][s+14] - m_LBC_EBC[s];
203  p3++;
204  }
205  }
206  }
207 
208  if(p0 != 0){m_LA_EA = m_LA_EA/p0; }
209  if(p2 != 0){m_LA_LC = m_LA_LC/p2; }
210  if(p3 != 0){m_LA_EC = m_LA_EC/p3; }
211 
212 // Calculation of time offsets wrt module 16 of each partition
213 
214  int n2[4][64] = {{0}};
215  memset( m_timeCor, 0, 2 * sizeof(*m_timeCor) );
216 
217  for(int s=0; s<4; s++){
218 
219  m_timeCor[s][15] = 0.; n2[s][15] = 1;
220 
221  for(int k=12; k<20; k++) {
222  if(m_nPair[s][15][k]>5) {
223  m_timeCor[s][k+32] = -m_tcor[s][15][k];
224  n2[s][k+32]=1;
225  }
226  }
227 
228 // Path to calculate all time offsets for modules in region x > 0
229 
230  for(int k=12; k<15; k++) {
231  for(int l=16; l<20; l++) {
232  if(m_nPair[s][k][l]>5) {
233  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
234  n2[s][k]++;
235  }
236  }
237  if(n2[s][k]>0)
238  m_timeCor[s][k] /= n2[s][k];
239  }
240 
241  for(int k=12; k<16; k++) {
242  for(int l=20; l<24; l++) {
243  if(m_nPair[s][k][l]>5) {
244  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
245  n2[s][l+32]++;
246  }
247  }
248  }
249  for(int k=52; k<56; k++) {
250  if(n2[s][k]>0) {
251  m_timeCor[s][k] /= n2[s][k];
252  }
253  }
254 
255  for(int k=8; k<12; k++) {
256  for(int l=20; l<24; l++) {
257  if(m_nPair[s][k][l]>5) {
258  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
259  n2[s][k]++;
260  }
261  }
262  if(n2[s][k]>0)
263  m_timeCor[s][k] /= n2[s][k];
264  }
265 
266  for(int k=8; k<12; k++) {
267  for(int l=24; l<28; l++) {
268  if(m_nPair[s][k][l]>5) {
269  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
270  n2[s][l+32]++;
271  }
272  }
273  }
274  for(int k=56; k<60; k++) {
275  if(n2[s][k]>0) {
276  m_timeCor[s][k] /=n2[s][k];
277  }
278  }
279 
280  for(int k=0; k<8; k++) {
281  for(int l=24; l<28; l++) {
282  if(m_nPair[s][k][l]>5) {
283  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
284  n2[s][k]++;
285  }
286  }
287  if (n2[s][k]>0)
288  m_timeCor[s][k] /= n2[s][k];
289  }
290 
291  for(int k=4; k<8; k++) {
292  for(int l=28; l<32; l++) {
293  if(m_nPair[s][k][l]>5) {
294  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
295  n2[s][l+32]++;
296  }
297  }
298  }
299  for(int k=60; k<64; k++) {
300  if(n2[s][k]>0)
301  m_timeCor[s][k] /= n2[s][k];
302  }
303 
304 // Path to calculate all time offsets for modules in region x < 0
305 
306  for(int k=16; k<20; k++) {
307  for(int l=12; l<16; l++) {
308  if(m_nPair[s][k][l]>5) {
309  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
310  n2[s][k]++;
311  }
312  }
313  if(n2[s][k]>0)
314  m_timeCor[s][k] /= n2[s][k];
315  }
316 
317  for(int k=16; k<20; k++) {
318  for(int l=8; l<12; l++) {
319  if(m_nPair[s][k][l]>5) {
320  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
321  n2[s][l+32]++;
322  }
323  }
324  }
325  for(int k=40; k<44; k++) {
326  if(n2[s][k]>0)
327  m_timeCor[s][k] /= n2[s][k];
328  }
329 
330  for(int k=20; k<24; k++){
331  for(int l=8; l<12; l++) {
332  if(m_nPair[s][k][l]>5) {
333  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
334  n2[s][k]++;
335  }
336  }
337  if(n2[s][k]>0)
338  m_timeCor[s][k] /= n2[s][k];
339  }
340 
341  for(int k=20; k<24; k++) {
342  for(int l=4; l<8; l++) {
343  if(m_nPair[s][k][l]>5) {
344  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
345  n2[s][l+32]++;
346  }
347  }
348  }
349  for(int k=36; k<40; k++) {
350  if(n2[s][k]>0) {
351  m_timeCor[s][k] /= n2[s][k];
352  }
353  }
354 
355  for(int k=24; k<32; k++) {
356  for(int l=4; l<8; l++) {
357  if(m_nPair[s][k][l]>5) {
358  m_timeCor[s][k] += m_timeCor[s][l+32] + m_tcor[s][k][l];
359  n2[s][k]++;
360  }
361  }
362  if(n2[s][k]>0)
363  m_timeCor[s][k] /= n2[s][k];
364  }
365 
366  for(int k=24; k<28; k++) {
367  for(int l=0; l<4; l++) {
368  if(m_nPair[s][k][l]>5) {
369  m_timeCor[s][l+32] += m_timeCor[s][k] - m_tcor[s][k][l];
370  n2[s][l+32]++;
371  }
372  }
373  }
374  for(int k=32; k<36; k++) {
375  if(n2[s][k]>0)
376  m_timeCor[s][k] /= n2[s][k];
377  }
378 
379  for(int l=0; l<64; l++) {
380  ATH_MSG_INFO ( "Partition: " << s << " Module: " << l+1 << " TimeCor: " << m_timeCor[s][l] << " n: " << n2[s][l] );
381  }
382  } //end of loop over different partitions
383 
384  return StatusCode::SUCCESS;
385 }
386 
388 {
389  ATH_MSG_INFO ( "writeNtuple(" << runNumber << "," << runType << "," << rootFile << ")" );
390 
391  TTree *t = new TTree("TOF", "TOF");
392  t->Branch("Time_Offset", m_timeCor, "Time_Offset[4][64]/F");
393  t->Branch("eba16_lba16", &m_LA_EA, "eba16_lba16/F");
394  t->Branch("lbc16_lba16", &m_LA_LC, "lbc16_lba16/F");
395  t->Branch("ebc16_lba16", &m_LA_EC, "ebc16_lba16/F");
396  t->Fill();
397  t->Write();
398 
399  return StatusCode::SUCCESS;
400 }
401 
403 {
404  ATH_MSG_INFO ( "finalize()" );
405  return StatusCode::SUCCESS;
406 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileTOFTool::m_LA_EA
float m_LA_EA
Definition: TileTOFTool.h:54
TileCell
Definition: TileCell.h:57
TileTOFTool::execute
virtual StatusCode execute()
Definition: TileTOFTool.cxx:66
TileTOFTool.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TileTOFTool::m_timeCor
float(* m_timeCor)[64]
Definition: TileTOFTool.h:45
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TileTOFTool::m_LBA_EBA
float m_LBA_EBA[4]
Definition: TileTOFTool.h:48
TileTOFTool::finalize
virtual StatusCode finalize()
Definition: TileTOFTool.cxx:402
TileTOFTool::m_tcor
float(* m_tcor)[32][32]
Definition: TileTOFTool.h:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCell::y
float y() const
get y (through CaloDetDescrElement)
Definition: CaloCell.h:420
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileTOFTool::m_Neba
int m_Neba[4]
Definition: TileTOFTool.h:51
TileCell::ene1
float ene1(void) const
get energy of first PMT
Definition: TileCell.h:193
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
TileTOFTool::initialize
virtual StatusCode initialize()
Definition: TileTOFTool.cxx:51
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
CaloCell::time
float time() const
get time (data member)
Definition: CaloCell.h:352
x
#define x
TileTOFTool::finalizeCalculations
virtual StatusCode finalizeCalculations()
Definition: TileTOFTool.cxx:159
TileID.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
ParticleJetTools::p3
Amg::Vector3D p3(const xAOD::TruthVertex *p)
Definition: ParticleJetLabelCommon.cxx:55
TileTOFTool::m_Nlbc
int m_Nlbc[4]
Definition: TileTOFTool.h:50
TRT::Hit::side
@ side
Definition: HitInfo.h:83
TileTOFTool::~TileTOFTool
virtual ~TileTOFTool()
Definition: TileTOFTool.cxx:41
TileTOFTool::m_LA_LC
float m_LA_LC
Definition: TileTOFTool.h:55
TileCell::timeDiff
float timeDiff(void) const
get time diff for two PMTs (data member)
Definition: TileCell.h:190
TileTOFTool::initNtuple
virtual StatusCode initNtuple(int runNumber, int runType, TFile *rootfile)
Definition: TileTOFTool.cxx:60
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
Tile_Base_ID::module
int module(const Identifier &id) const
Definition: Tile_Base_ID.cxx:159
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
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
TileTOFTool::writeNtuple
virtual StatusCode writeNtuple(int runNumber, int runType, TFile *rootfile)
Definition: TileTOFTool.cxx:387
TileCell.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
makeComparison.rootFile
rootFile
Definition: makeComparison.py:27
AtlasDetectorID::is_tile
bool is_tile(Identifier id) const
Definition: AtlasDetectorID.h:695
TIMECOR
#define TIMECOR(MOD_REF1, MOD_REF2, PART_REF1, PART_REF2, COUNT, TCOR)
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
TileTOFTool::m_tileID
const TileID * m_tileID
Definition: TileTOFTool.h:36
TileTOFTool::m_LBC_EBC
float m_LBC_EBC[4]
Definition: TileTOFTool.h:49
python.OnlineISConfiguration.runType
def runType
Definition: OnlineISConfiguration.py:112
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TileTOFTool::TileTOFTool
TileTOFTool(const std::string &type, const std::string &name, const IInterface *pParent)
Definition: TileTOFTool.cxx:21
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
CaloCellContainer.h
TileTOFTool::m_LA_EC
float m_LA_EC
Definition: TileTOFTool.h:56
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
TileCell::ene2
float ene2(void) const
get energy of second PMT
Definition: TileCell.h:195
y
#define y
TileTOFTool::m_nPair
int(* m_nPair)[32][32]
Definition: TileTOFTool.h:59
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloCell::z
float z() const
get z (through CaloDetDescrElement)
Definition: CaloCell.h:427
CaloCell::x
float x() const
get x (through CaloDetDescrElement)
Definition: CaloCell.h:413
Tile_Base_ID::section
int section(const Identifier &id) const
Definition: Tile_Base_ID.cxx:147
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
TileTOFTool::m_Nebc
int m_Nebc[4]
Definition: TileTOFTool.h:52
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
TileTOFTool::m_caloCellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellContainerKey
Definition: TileTOFTool.h:40
TileTOFTool::m_LBA_LBC
float m_LBA_LBC[4]
Definition: TileTOFTool.h:47
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528