ATLAS Offline Software
TRTCalibrator.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 /********************************************************************
7 
8  NAME: TRTCalibrator.cxx
9 PACKAGE: TRTCalibTools
10 
11 AUTHORS: Johan Lundquist
12 CREATED: 27-03-2009
13 
14 PURPOSE: Tool for calibrating the TRT
15 
16 ********************************************************************/
17 
18 #include "TRTCalibrator.h"
19 #include "Calibrator.h"
21 #include "TrkTrack/Track.h"
25 
31 #include "InDetIdentifier/TRT_ID.h"
38 
39 #include <TNtuple.h>
40 #include <TFile.h>
41 #include <fstream>
42 
43 
44 TRTCalibrator::TRTCalibrator(const std::string& type, const std::string& name, const IInterface* parent) :
46  m_DetID(nullptr),
47  m_TRTID(nullptr),
48  m_trtmanager(nullptr),
49  m_trtcaldbTool("ITRT_CalDbTool", this),
50  m_neighbourSvc("ITRT_StrawNeighbourSvc", name),
51  m_TRTStrawSummaryTool("InDetTRTStrawStatusSummaryTool",this),
52  m_maxDistance(2.8),
53  m_maxTimeResidual(150),
54  m_minTimebinsOverThreshold(2),
55  m_maxTrackChisquarePerDof(10),
56  m_numOfHitsTotal(0),
57  m_numOfHitsAccepted(0),
58  m_numOfProcessedTracks(0),
59  m_comTimeName("ComTime"),
60  m_minrt(10000),
61  m_mint0(200),
62  m_nevents(-1),
63  m_t0offset(-0.3),
64  m_calsub("user"),
65  m_rtbinning("t"),
66  m_selstring("_*_-_-_-_-_-_-"),
67  m_options(""),
68  m_hittuple("basic.root"),
69  m_rtrel("basic"),
70  m_ntrtmanager("TRT"),
71  m_SplitBarrel(true),
72  m_useP0(true),
73  m_floatP3(true),
74  m_DoShortStrawCorrection(true),
75  m_DoArXenonSep(false)
76 {
77  declareInterface<ITRTCalibrator>(this);
78  declareProperty("TRTCalDbTool",m_trtcaldbTool);
79  declareProperty("NeighbourSvc",m_neighbourSvc);
80  declareProperty("maxDistance",m_maxDistance) ;
81  declareProperty("maxTimeResidual",m_maxTimeResidual) ;
82  declareProperty("minTimebinsOverThreshold",m_minTimebinsOverThreshold) ;
83  declareProperty("maxTrackChisquarePerDof",m_maxTrackChisquarePerDof) ;
84  declareProperty("MinRt",m_minrt);
85  declareProperty("MinT0",m_mint0);
86  declareProperty("Nevents",m_nevents);
87  declareProperty("Selstring",m_selstring);
88  declareProperty("SubPart",m_calsub);
89  declareProperty("Options",m_options);
90  declareProperty("Hittuple",m_hittuple);
91  declareProperty("RtRel",m_rtrel);
92  declareProperty("TrtManagerLocation",m_ntrtmanager);
93  declareProperty("CalibrateRt",m_doRt);
94  declareProperty("CalibrateT0",m_doT0);
95  declareProperty("RtBinning",m_rtbinning);
96  declareProperty("FitResidual",m_doRes);
97  declareProperty("NoHistograms",m_beQuiet);
98  declareProperty("UseBoardRef",m_useBoardRef);
99  declareProperty("SplitBarrel",m_SplitBarrel);
100  declareProperty("UseP0",m_useP0);
101  declareProperty("FloatP3",m_floatP3);
102  declareProperty("PrintLog",m_doLogPrint);
103  declareProperty("PrintT0Out",m_doOutPrint);
104  declareProperty("PrintRtOut",m_doRtPrint);
105  declareProperty("T0Offset",m_t0offset);
106  declareProperty("DoShortStrawCorrection",m_DoShortStrawCorrection);
107  declareProperty("DoArXenonSep",m_DoArXenonSep);
108  declareProperty("TRTStrawSummaryTool", m_TRTStrawSummaryTool);
109 }
110 
111 
113 {
114  ATH_MSG_INFO( "initialize()" );
115 
116  m_trtmanager=nullptr;
117 
118  if ((detStore()->retrieve(m_DetID,"AtlasID")).isFailure()) {
119  ATH_MSG_FATAL( "Problem retrieving ATLASDetectorID helper" );
120  return StatusCode::FAILURE;
121  }
122  if ((detStore()->retrieve(m_trtmanager,m_ntrtmanager)).isFailure()) {
123  ATH_MSG_FATAL ( "Could not get TRT_DetectorManager" );
124  return StatusCode::FAILURE;
125  }
126  if ((detStore()->retrieve(m_TRTID)).isFailure()) {
127  ATH_MSG_FATAL( "Problem retrieving TRTID helper" );
128  return StatusCode::FAILURE;
129  }
130  if(m_trtcaldbTool.retrieve().isFailure()) {
131  ATH_MSG_FATAL( "Could not get TRTCalDbTool !" );
132  return StatusCode::FAILURE;
133  }
134  if(StatusCode::SUCCESS!=m_neighbourSvc.retrieve() ) {
135  ATH_MSG_FATAL("Could not get TRTStrawNeighbourTool !");
136  return StatusCode::FAILURE;
137  }
138 
139 
140  // The tool to get the argon status:
141 
142  if (m_TRTStrawSummaryTool.retrieve().isFailure() ) {
143  ATH_MSG_ERROR ("Failed to retrieve StrawStatus Summary " << m_TRTStrawSummaryTool);
144  return StatusCode::FAILURE;
145  } else {
146  ATH_MSG_INFO( "Retrieved tool " << m_TRTStrawSummaryTool );
147  }
148 
149 
150 
151  /*
152  Pre-define standard calibration configuration
153 
154  The string-vectors "CalibrateRt" ("CalibrateT0") contains the names of the levels for
155  which R-t (T0) calibration should be performed
156 
157  The string-vector "PrintLog" contains the names of the levels for which a status line
158  should be printed to the output log
159 
160  The string-vectors "PrintT0Out" and "PrintRtOut" contains the names of the levels for
161  text files containing the calibration constants should be generated
162 
163  This standard configuration divides the Barrel in 9 parts:
164 
165  "all": a single calibration for all hits in the whole TRT
166  "-1" & "1": calibration of the barrel C- & A-side
167  "X_Y": calibration of layer Y in barrel X-side
168  */
169 
170  //the whole TRT
171  m_config["all"].selections["Detector"].insert(CALIB_NONE); // don't go deeper than TRT level
172  m_config["all"].selections["Layer"].insert(CALIB_NONE);
173  m_config["all"].selections["Module"].insert(CALIB_NONE);
174  m_config["all"].selections["Board"].insert(CALIB_NONE);
175  m_config["all"].selections["Chip"].insert(CALIB_NONE);
176  m_config["all"].selections["Straw"].insert(CALIB_NONE);
177  m_config["all"].CalibrateRt.emplace_back("TRT") ; //only calibrate R-t and T0 on TRT level
178  m_config["all"].CalibrateT0.emplace_back("TRT") ;
179  m_config["all"].PrintLog.emplace_back("TRT") ;
180  m_config["all"].PrintT0Out.emplace_back("TRT") ;
181  m_config["all"].PrintRtOut.emplace_back("TRT") ;
182 
183  //common for all barrel/ec
184  m_config["subdet"].CalibrateRt.emplace_back("TRT") ; //calibrate R-t and T0 on TRT and barrel/ec level
185  m_config["subdet"].CalibrateRt.emplace_back("Detector") ;
186  m_config["subdet"].CalibrateT0=m_config["subdet"].CalibrateRt;
187  m_config["subdet"].NoHistograms.emplace_back("TRT") ; //don't write root histogram on TRT level
188  m_config["subdet"].PrintLog=m_config["subdet"].CalibrateRt;
189  m_config["subdet"].PrintT0Out.emplace_back("Detector") ;
190  m_config["subdet"].PrintRtOut.emplace_back("Detector") ;
191 
192  //individual barrel/ec
193  m_config["1"]=m_config["subdet"];
194  m_config["1"].selections["Detector"].insert(1);
195  m_config["1"].selections["Layer"].insert(CALIB_NONE); // don't go deeper than barrel/ec level
196  m_config["1"].selections["Module"].insert(CALIB_NONE);
197  m_config["1"].selections["Board"].insert(CALIB_NONE);
198  m_config["1"].selections["Chip"].insert(CALIB_NONE);
199  m_config["1"].selections["Straw"].insert(CALIB_NONE);
200  m_config["-1"]=m_config["subdet"];
201  m_config["-1"].selections["Detector"].insert(-1);
202  m_config["-1"].selections["Layer"].insert(CALIB_NONE);
203  m_config["-1"].selections["Module"].insert(CALIB_NONE);
204  m_config["-1"].selections["Board"].insert(CALIB_NONE);
205  m_config["-1"].selections["Chip"].insert(CALIB_NONE);
206  m_config["-1"].selections["Straw"].insert(CALIB_NONE);
207 
208  //common for all layers
209  m_config["layer"].CalibrateRt.emplace_back("TRT") ; //calibrate R-t and T0 on all levels (except Straw level)
210  m_config["layer"].CalibrateRt.emplace_back("Detector") ;
211  m_config["layer"].CalibrateRt.emplace_back("Layer") ;
212  m_config["layer"].CalibrateRt.emplace_back("Module") ;
213  m_config["layer"].CalibrateRt.emplace_back("Board") ;
214  m_config["layer"].CalibrateRt.emplace_back("Chip") ;
215  m_config["layer"].CalibrateT0=m_config["layer"].CalibrateRt;
216  m_config["layer"].NoHistograms.emplace_back("TRT") ; //don't write root histogram on TRT, barrel/ec, straw level
217  m_config["layer"].NoHistograms.emplace_back("Detector") ;
218  m_config["layer"].NoHistograms.emplace_back("Straw") ;
219  m_config["layer"].PrintLog=m_config["layer"].CalibrateRt;
220  m_config["layer"].PrintT0Out.emplace_back("Layer") ;
221  m_config["layer"].PrintT0Out.emplace_back("Module") ;
222  m_config["layer"].PrintT0Out.emplace_back("Board") ;
223  m_config["layer"].PrintT0Out.emplace_back("Chip") ;
224  m_config["layer"].PrintT0Out.emplace_back("Straw") ; //print txt output for each straw
225  m_config["layer"].PrintRtOut.emplace_back("Layer") ;
226  m_config["layer"].PrintRtOut.emplace_back("Module") ;
227  m_config["layer"].PrintRtOut.emplace_back("Board") ;
228  m_config["layer"].PrintRtOut.emplace_back("Chip") ;
229  m_config["layer"].PrintRtOut.emplace_back("Straw") ; //print txt output for each straw
230 
231  //individual layers
232  m_config["1_0"]=m_config["layer"];
233  m_config["1_0"].selections["Detector"].insert(1);
234  m_config["1_0"].selections["Layer"].insert(0);
235  m_config["1_1"]=m_config["layer"];
236  m_config["1_1"].selections["Detector"].insert(1);
237  m_config["1_1"].selections["Layer"].insert(1);
238  m_config["1_2"]=m_config["layer"];
239  m_config["1_2"].selections["Detector"].insert(1);
240  m_config["1_2"].selections["Layer"].insert(2);
241  m_config["-1_0"]=m_config["layer"];
242  m_config["-1_0"].selections["Detector"].insert(-1);
243  m_config["-1_0"].selections["Layer"].insert(0);
244  m_config["-1_1"]=m_config["layer"];
245  m_config["-1_1"].selections["Detector"].insert(-1);
246  m_config["-1_1"].selections["Layer"].insert(1);
247  m_config["-1_2"]=m_config["layer"];
248  m_config["-1_2"].selections["Detector"].insert(-1);
249  m_config["-1_2"].selections["Layer"].insert(2);
250 
251  return StatusCode::SUCCESS;
252 }
253 
254 
256 {
257  return StatusCode::SUCCESS;
258 }
259 
260 
261 std::string TRTCalibrator::SubLev(std::string pat, int lev){
262 
263  std::string sublev;
264 
265  for (int i=0;i<lev;i++){
266  pat.replace(pat.find('_'),1,"");
267  sublev = pat.substr(0,pat.find('_'));
268  pat.replace(0,pat.find('_'),"");
269  }
270  return sublev;
271 }
272 
274 
275  std::map<std::string,int> strawmap;
276  Identifier ident=(Identifier)(isid);
277 
278 
279 
280  std::string strawkey=std::string(Form("%i %i %i %i %i",
281  (int)m_TRTID->barrel_ec(ident),
282  (int)m_TRTID->layer_or_wheel(ident) ,
283  (int)m_TRTID->phi_module(ident) ,
284  (int)m_TRTID->straw_layer(ident) ,
285  (int)m_TRTID->straw(ident)));
286  strawmap[strawkey]=isid;
287 }
288 
289 
290 bool TRTCalibrator::IsSubLev(const std::string& key, int lev, const std::string& sublev){
291 
292  std::string sl=sublev;
293 
294  if (sl.compare(SubLev(key,lev))==0) return true;
295 
296  while(sl.compare(sl.substr(sl.find(',')+1))!=0){
297  if (SubLev(key,lev).compare(sl.substr(0,sl.find(',')))==0) return true;
298  sl=sl.substr(sl.find(',')+1);
299  if (SubLev(key,lev).compare(sl.substr(0,sl.find(',')))==0) return true;
300  }
301  return false;
302 
303 }
304 
305 int TRTCalibrator::GetSubLevels(const std::string& key, int lev, std::set<int>* levels){
306 
307  std::string sl=SubLev(key,lev);
308 
309  if (sl.compare("-")==0) {
310  levels->insert(-4);
311  return 999;
312  }
313  if (sl.compare("*")==0) {
314  levels->insert(-3);
315  return 999;
316  }
317 
318  if(sl.find(',')!=std::string::npos){
319  int value;
320  while(sl.find(',')!=std::string::npos){
321  sscanf(sl.substr(0,sl.find(',')).data(),"%i",&value);
322  levels->insert(value);
323  sl=sl.substr(sl.find(',')+1);
324  }
325  sscanf(sl.data(),"%i",&value);
326  levels->insert(value);
327  return levels->size();
328  }
329 
330  if(sl.find('t')!=std::string::npos){
331  int min,max;
332  sscanf(sl.substr(0,sl.find('t')).data(),"%i",&min);
333  ATH_MSG_INFO( "min=" << min );
334  sl=sl.substr(sl.find('t')+1);
335  sscanf(sl.data(),"%i",&max);
336  ATH_MSG_INFO("max=" << max);
337  for (int imod=min; imod<=max; imod++){
338  levels->insert(imod);
339  }
340  return levels->size();
341  }
342 
343  int value;
344  sscanf(sl.data(),"%i",&value);
345  levels->insert(value);
346  return levels->size();
347 
348 }
349 
350 void TRTCalibrator::MakeBDKeys(int bec, int low, int mod, int brd, int chp, int strawid){
351  //make map keys for the board-chip view
352 
353  char ckey[100];
354  sprintf(ckey,"_%i_%i_%i_%i_%i_%i",bec,low,mod,brd,chp,strawid); m_Skey=std::string(ckey);
355  sprintf(ckey,"_%i_%i_%i_%i_%i",bec,low,mod,brd,chp); m_Ckey=std::string(ckey);
356  sprintf(ckey,"_%i_%i_%i_%i",bec,low,mod,brd); m_Bkey=std::string(ckey);
357  sprintf(ckey,"_%i_%i_%i",bec,low,mod); m_Mkey=std::string(ckey);
358  sprintf(ckey,"_%i_%i",bec,low); m_Lkey=std::string(ckey);
359  sprintf(ckey,"_%i",bec); m_Dkey=std::string(ckey);
360  sprintf(ckey,"_all"); m_Tkey=std::string(ckey);
361 
362  sprintf(ckey,"_%i_%i",abs(bec),low); m_Lkey_acc=std::string(ckey);
363  sprintf(ckey,"_%i",abs(bec)); m_Dkey_acc=std::string(ckey);
364 
365 }
366 
367 bool TRTCalibrator::calibrate ATLAS_NOT_THREAD_SAFE () {
368 
369  float sid;
371  const InDetDD::TRT_BaseElement* strawelement;
372  const InDetDD::TRT_BarrelElement* barrelelement;
373  const InDetDD::TRT_EndcapElement* endcapelement;
374  int nTRThist=0, ndethist=0, nlayhist=0, nmodhist=0, nbrdhist=0, nchphist=0, nstwhist=0;
375  int nTRThistAr=0, ndethistAr=0, nlayhistAr=0, nmodhistAr=0, nbrdhistAr=0, nchphistAr=0, nstwhistAr=0;
376  databundle hitdata;
377 
378  std::string infile=m_hittuple;
379  std::string outfile="calibout";
380 
381  std::string detname="Detector";
382  std::string layname="Layer";
383  if (!m_SplitBarrel) {
384  detname="WholeBarrel";
385  layname="WholeBarrelLayer";
386  }
387 
388  //create Calibrator objects for each sub-level
389  Calibrator TRT(0,"TRT",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
390  Calibrator Detector(1,detname.data(),m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
391  Calibrator Layer(2,layname.data(),m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
392  Calibrator Module(3,"Module",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
393  Calibrator Board(4,"Board",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
394  Calibrator Chip(5,"Chip",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
395  Calibrator Straw(6,"Straw",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
396 
397 
398  // make a map of calibrators (so that they can be looped over)
399  std::map<std::string,Calibrator*> calibrators;
400  calibrators["TRT"]=&TRT;
401  calibrators["Detector"]=&Detector;
402  calibrators["Layer"]=&Layer;
403  calibrators["Module"]=&Module;
404  calibrators["Board"]=&Board;
405  calibrators["Chip"]=&Chip;
406  calibrators["Straw"]=&Straw;
407 
408  //use default configurations unless "user" option is used
409  if(m_calsub!="user"){
410  m_doRt=m_config[m_calsub].CalibrateRt;
411  m_doT0=m_config[m_calsub].CalibrateT0;
412  m_doRes=m_config[m_calsub].FitResidual;
413  m_beQuiet=m_config[m_calsub].NoHistograms;
414  m_doOutPrint=m_config[m_calsub].PrintT0Out;
415  m_doRtPrint=m_config[m_calsub].PrintRtOut;
416  m_doLogPrint=m_config[m_calsub].PrintLog;
417  }
418 
419  //configure the calibrators
420  for (const std::string& s : m_doRt) calibrators[s]->dort=true;
421  for (const std::string& s : m_doT0) calibrators[s]->dot0=true;
422  for (const std::string& s : m_doRes) calibrators[s]->dores=true;
423  for (const std::string& s : m_beQuiet) calibrators[s]->bequiet=true;
424  for (const std::string& s : m_doOutPrint) calibrators[s]->printt0=true;
425  for (const std::string& s : m_doRtPrint) calibrators[s]->printrt=true;
426  for (const std::string& s : m_doLogPrint) calibrators[s]->printlog=true;
427  for (const std::string& s : m_useBoardRef) calibrators[s]->usebref=true;
428  for (std::pair<const std::string, Calibrator*>& p : calibrators) {
429  Calibrator* calib = p.second;
430  calib->usep0=m_useP0;
431  calib->floatp3=m_floatP3;
432  calib->useshortstraws=m_DoShortStrawCorrection;
433 
434  if (m_doRt.size()==0) calib->nort=true;
435  if (m_doT0.size()==0) calib->not0=true;
436 
437  std::set<int> selset;
438  GetSubLevels(m_selstring,calib->level+1,&selset); //get the set of selections for level "level+1" from the m_selstring ...
439  for (std::set<int>::iterator imod=selset.begin(); imod!=selset.end(); ++imod){
440  calib->selection = selset;//... and configure the calibrator with them
441  }
442  }
443 
444  // FOR ARGON:
445  Calibrator TRT_Ar (0,"TRT_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
446  Calibrator Detector_Ar(1,"Detector_Ar",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
447  Calibrator Layer_Ar (2,"Layer_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
448  Calibrator Module_Ar (3,"Module_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
449  Calibrator Board_Ar (4,"Board_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
450  Calibrator Chip_Ar (5,"Chip_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
451  Calibrator Straw_Ar (6,"Straw_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
452 
453  // make a map of calibrators (so that they can be looped over)
454  std::map<std::string,Calibrator*> calibratorsAr;
455  calibratorsAr["TRT"] =&TRT_Ar;
456  calibratorsAr["Detector"] =&Detector_Ar;
457  calibratorsAr["Layer"] =&Layer_Ar;
458  calibratorsAr["Module"] =&Module_Ar;
459  calibratorsAr["Board"] =&Board_Ar;
460  calibratorsAr["Chip"] =&Chip_Ar;
461  calibratorsAr["Straw"] =&Straw_Ar;
462 
463  //configure the calibrators
464  for (const std::string& s : m_doRt) calibratorsAr[s]->dort=true;
465  for (const std::string& s : m_doT0) calibratorsAr[s]->dot0=true;
466  for (const std::string& s : m_doRes) calibratorsAr[s]->dores=true;
467  for (const std::string& s : m_beQuiet) calibratorsAr[s]->bequiet=true;
468  for (const std::string& s : m_doOutPrint) calibratorsAr[s]->printt0=true;
469  for (const std::string& s : m_doRtPrint) calibratorsAr[s]->printrt=true;
470  for (const std::string& s : m_doLogPrint) calibratorsAr[s]->printlog=true;
471  for (const std::string& s : m_useBoardRef) calibratorsAr[s]->usebref=true;
472  for (std::pair<const std::string, Calibrator*>& p : calibratorsAr) {
473  Calibrator* calib = p.second;
474  calib->usep0=m_useP0;
475  calib->floatp3=m_floatP3;
476  calib->useshortstraws=m_DoShortStrawCorrection;
477 
478  if (m_doRt.size()==0) calib->nort=true;
479  if (m_doT0.size()==0) calib->not0=true;
480 
481  std::set<int> selset;
482  GetSubLevels(m_selstring,calib->level+1,&selset); //get the set of selections for level "level+1" from the m_selstring ...
483  for (std::set<int>::iterator imod=selset.begin(); imod!=selset.end(); ++imod){
484  calib->selection = selset;//... and configure the calibrator with them
485  }
486  }
487 
488 
489 
490  m_options = '_' + TRT.GetOptString() + '_' + Detector.GetOptString() + '_' + Layer.GetOptString() + '_' + Module.GetOptString() + '_' + Board.GetOptString() + '_' + Chip.GetOptString() + '_' + Straw.GetOptString();
491  if(m_calsub!="user") m_selstring = '_' + TRT.GetSelString() + '_' + Detector.GetSelString() + '_' + Layer.GetSelString() + '_' + Module.GetSelString() + '_' + Board.GetSelString() + '_' + Chip.GetSelString() + '_' + Straw.GetSelString();
492 
493  //print some info
494  ATH_MSG_INFO(" ");
495  ATH_MSG_INFO( "INPUT FILE : " << infile );
496  ATH_MSG_INFO( "OUTPUT FILE : " << outfile );
497  ATH_MSG_INFO( "SELECTION STRING : " << m_selstring );
498  ATH_MSG_INFO( "OPTION STRING : " << m_options );
499  ATH_MSG_INFO( "RT RELATION : " << m_rtrel );
500  ATH_MSG_INFO( "MIN STATISTICS : RT=" << m_minrt << ", T0=" << m_mint0 );
501  ATH_MSG_INFO( "T0 OFFSET : " << m_t0offset );
502  ATH_MSG_INFO(" ");
503  ATH_MSG_INFO( TRT.PrintInfo() );
504  ATH_MSG_INFO( Detector.PrintInfo() );
505  ATH_MSG_INFO( Layer.PrintInfo() );
506  ATH_MSG_INFO( Module.PrintInfo() );
507  ATH_MSG_INFO( Board.PrintInfo() );
508  ATH_MSG_INFO( Chip.PrintInfo() );
509  ATH_MSG_INFO( Straw.PrintInfo() );
510  ATH_MSG_INFO(" ");
511 
512  if (m_DoArXenonSep){
513  //print some info
514  ATH_MSG_INFO(" ");
515  ATH_MSG_INFO( "Setup for the ARGON Straws: " );
516  ATH_MSG_INFO( "INPUT FILE : " << infile );
517  ATH_MSG_INFO( "OUTPUT FILE : " << outfile );
518  ATH_MSG_INFO( "SELECTION STRING : " << m_selstring );
519  ATH_MSG_INFO( "OPTION STRING : " << m_options );
520  ATH_MSG_INFO( "RT RELATION : " << m_rtrel );
521  ATH_MSG_INFO( "MIN STATISTICS : RT=" << m_minrt << ", T0=" << m_mint0 );
522  ATH_MSG_INFO( "T0 OFFSET : " << m_t0offset );
523  ATH_MSG_INFO( " ");
524  ATH_MSG_INFO( TRT_Ar.PrintInfo() );
525  ATH_MSG_INFO( Detector_Ar.PrintInfo() );
526  ATH_MSG_INFO( Layer_Ar.PrintInfo() );
527  ATH_MSG_INFO( Module_Ar.PrintInfo() );
528  ATH_MSG_INFO( Board_Ar.PrintInfo() );
529  ATH_MSG_INFO( Chip_Ar.PrintInfo() );
530  ATH_MSG_INFO( Straw_Ar.PrintInfo() );
531  ATH_MSG_INFO(" ");
532  }
533  //read the chip reference t0 values from finedelays.txt
534  int rbrd, rchp, rdet, dum;
535  float rt0;
536  std::map<std::string,float> reft0map;
537  std::ifstream t0ref("finedelays.txt",std::ios::in);
538  if(t0ref.is_open()) ATH_MSG_INFO(" Opened finedelays.txt ");
539  for(int iref=0;iref<208;iref++){
540  t0ref >> rbrd >> rchp >> rdet >> dum >> rt0;
541  reft0map[std::string(Form("_%i_%i_%i",rdet,rbrd,rchp))]=rt0;
542  }
543 
544  t0ref.close();
545 
546 
547  //set type of rt-relation
548  bool isdines = m_rtrel.find("dines")!=std::string::npos;
549  bool isbinned = m_rtrel.find("binned")!=std::string::npos;
550  int rtint;
551  if (isdines) rtint=2;
552  else if (isbinned) rtint=1;
553  else rtint=0;
554  ATH_MSG_INFO(" Rt relation is: " << rtint);
555 
556  int npop,isid;
557  std::map<std::string,epdata> ephasemap;
558 
559  // open the output histogram file
560  std::unique_ptr<TFile> histfile(TFile::Open("calibout.root","RECREATE"));
561 
562  if(!histfile || histfile->IsZombie()) {
563  ATH_MSG_ERROR ("Failed to open calibout.root ");
564  return false;
565  } else {
566  ATH_MSG_INFO ("Opened calibout.root ");
567  }
568 
569  std::ifstream myFile (infile.data(), std::ios::in | std::ios::binary);
570  ATH_MSG_INFO( " Opened " << infile << " as binary histogram file " );
571  int ihist=0;
572  int ihistAr=0;
573 
574  while(true){
575 
576  //read a binary histogram
577  myFile.read ((char*)&npop,sizeof(int)); //number of populated bins
578  if (myFile.eof()) break;
579  int* chist=new int[2*npop+2]; //the histogram
580  if (npop>0) myFile.read ((char*)(chist+2), sizeof(int)*2*npop);
581  myFile.read ((char*)&isid,sizeof(int)); //the straw id
582  sid = (float)isid;
583  if(sid<0) continue;
584 
585  chist[0]=npop;
586  chist[1]=isid;
587  //get the straw address (barrel/ec, layer, module, ...) based on the straw identifier
588  ident=(Identifier)(isid);
589  int chip=0,board=-1;
590  m_neighbourSvc->getChip(ident,chip);
591  if(abs(m_TRTID->barrel_ec(ident))<2){
592  board=m_neighbourSvc->chipToBoardBarrel(chip,m_TRTID->layer_or_wheel(ident));
593  }
594  else if (chip<12) {
595  board=0;
596  }
597  else {
598  chip=chip-20;
599  board=1;
600  }
601  if (m_SplitBarrel) hitdata.det=(int)m_TRTID->barrel_ec(ident);
602  else hitdata.det=abs((int)m_TRTID->barrel_ec(ident));
603  if(hitdata.det!=1 && hitdata.det!=-1 && hitdata.det!=2 && hitdata.det!=-2) {
604  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " detector decoded to be : " << hitdata.det);
605  continue;
606  }
607  hitdata.lay=(int)m_TRTID->layer_or_wheel(ident);
608  if( (hitdata.det==1 || hitdata.det==-1) && (hitdata.lay<0 || hitdata.lay>2) ) {
609  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " barrel layer decoded to be : " << hitdata.lay);
610  continue;
611  } else if( (hitdata.det==2 || hitdata.det==-2) && (hitdata.lay<0 || hitdata.lay>13) ) {
612  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " endcap layer decoded to be : " << hitdata.lay);
613  continue;
614  }
615  hitdata.mod=(int)m_TRTID->phi_module(ident);
616  if( hitdata.mod < 0 || hitdata.mod > 31 ) {
617  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " phi-module decoded to be : " << hitdata.lay);
618  continue;
619  }
620 
621  hitdata.brd=board;
622  hitdata.chp=chip;
623  hitdata.stl=(int)m_TRTID->straw_layer(ident);
624  if( hitdata.stl < 0 || hitdata.stl > m_TRTID->straw_layer_max(ident) ) {
625  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " straw-layer decoded to be : " << hitdata.stl);
626  continue;
627  }
628 
629  hitdata.stw=(int)m_TRTID->straw(ident);
630  if( hitdata.stw < 0 || hitdata.stw > m_TRTID->straw_max(ident) ) {
631  ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " straw decoded to be : " << hitdata.stw);
632  continue;
633  }
634 
635  hitdata.sid=isid;
636 
637  //get the old rt parameters based on straw identifier
638  const float* pcal ;
639  std::vector<float> rvalues ;
640  const float defaultpcal[] = {0,0,0,0} ;
641  if (isdines){
642  const TRTCond::DinesRtRelation* rtr = dynamic_cast<const TRTCond::DinesRtRelation*>(m_trtcaldbTool->getRtRelation(ident)) ;
643  pcal = rtr ? rtr->cal() : defaultpcal ;
644  }
645 
646  else {
647  const TRTCond::BasicRtRelation* rtr = dynamic_cast<const TRTCond::BasicRtRelation*>(m_trtcaldbTool->getRtRelation(ident)) ;
648  pcal = rtr ? rtr->cal() : defaultpcal ;
649  }
650  hitdata.rtpar[0]=pcal[0];
651  hitdata.rtpar[1]=pcal[1];
652  hitdata.rtpar[2]=pcal[2];
653  hitdata.rtpar[3]=pcal[3];
654 
655 
656  //build map keys
657  MakeBDKeys(hitdata.det, hitdata.lay, hitdata.mod, hitdata.brd, hitdata.chp, hitdata.sid);
658 
659  //make the level hierachy dictionaries
660  m_trt.t[m_Tkey].d[m_Dkey].l[m_Lkey].m[m_Mkey].b[m_Bkey].c[m_Ckey].s[m_Skey].z=0;
661  m_trt_acc.t[m_Tkey].d[m_Dkey_acc].l[m_Lkey_acc].m[m_Mkey].b[m_Bkey].c[m_Ckey].s[m_Skey].z=0;
662 
663  //populate the hit data structure to be added
664 
665 
666  hitdata.ievt=0;
667  hitdata.tres=0;
668  hitdata.weight=1.0;
669  hitdata.res=0;
670  hitdata.t=0;
671  hitdata.r=0;
672  hitdata.t0=m_trtcaldbTool->getT0(ident);
673 
674  strawelement = m_trtmanager->getElement(ident);
675  if(hitdata.det==1 || hitdata.det==-1) {
676  barrelelement=(InDetDD::TRT_BarrelElement*)strawelement;
677  hitdata.x=(barrelelement->center(ident)).x();
678  hitdata.y=(barrelelement->center(ident)).y();
679  hitdata.z=(barrelelement->center(ident)).z();
680  }else{
681  endcapelement=(InDetDD::TRT_EndcapElement*)strawelement;
682  hitdata.x=(endcapelement->center(ident)).x();
683  hitdata.y=(endcapelement->center(ident)).y();
684  hitdata.z=(endcapelement->center(ident)).z();
685  }
686 
687  //in the short straws corrections, autodetect if it was applied on the previous step
688  if ( m_DoShortStrawCorrection && hitdata.lay==0 && hitdata.stl<9){
689  //If correction was done in ctes in db (readed), undo the correction: This fixes problem on t0 averaging....
690  double t0test1=m_trtcaldbTool->getT0((Identifier)301998432);
691  double t0test2=m_trtcaldbTool->getT0((Identifier)302001504);
692  if (t0test1 != t0test2) hitdata.t0+=0.75; //short straw compensation
693  }
694 
695  //the reference t0 from finedelays
696  hitdata.rt0=reft0map[std::string(Form("_%i_%i_%i",hitdata.det,hitdata.brd,hitdata.chp))];
697 
698  // Prepare for Xe-Ar mixed conditions:
699  int isArgonStraw = 0;
700  if (m_TRTStrawSummaryTool->getStatusHT(ident) != TRTCond::StrawStatus::Good) {
701  isArgonStraw = 1;
702  }
703 
704 
705  //add histogram to the Calibrators (A and C side separated)
706  if(!m_DoArXenonSep){
707 
708  nTRThist += TRT.AddHit(m_Tkey,hitdata,chist,true);
709  if (Detector.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
710  if (m_SplitBarrel) ndethist += Detector.AddHit(m_Dkey,hitdata,chist,true);
711  else ndethist += Detector.AddHit(m_Dkey_acc,hitdata,chist,true);
712  if (Layer.CheckSelection(hitdata.lay)) {
713  if (m_SplitBarrel) nlayhist += Layer.AddHit(m_Lkey,hitdata,chist,true);
714  else { nlayhist += Layer.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
715  if (Module.CheckSelection(hitdata.mod)) {
716  nmodhist += Module.AddHit(m_Mkey,hitdata,chist,true);
717  if (Board.CheckSelection(hitdata.brd)) {
718  nbrdhist += Board.AddHit(m_Bkey,hitdata,chist,true);
719  if (Chip.CheckSelection(hitdata.chp)) {
720  nchphist += Chip.AddHit(m_Ckey,hitdata,chist,true);
721  if (Straw.CheckSelection(hitdata.stw))
722  nstwhist += Straw.AddHit(m_Skey,hitdata,chist,true);
723  }
724  }
725  }
726  }
727  } // Here it closes
728  ihist++;
729  } else
730  if(isArgonStraw==0){ // Separate Ar and Xe in endcaps. Here Xe
731  nTRThist += TRT.AddHit(m_Tkey,hitdata,chist,true);
732  if (Detector.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
733  if (m_SplitBarrel) ndethist += Detector.AddHit(m_Dkey,hitdata,chist,true);
734  else ndethist += Detector.AddHit(m_Dkey_acc,hitdata,chist,true);
735  if (Layer.CheckSelection(hitdata.lay)) {
736  if (m_SplitBarrel) nlayhist += Layer.AddHit(m_Lkey,hitdata,chist,true);
737  else { nlayhist += Layer.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
738  if (Module.CheckSelection(hitdata.mod)) {
739  nmodhist += Module.AddHit(m_Mkey,hitdata,chist,true);
740  if (Board.CheckSelection(hitdata.brd)) {
741  nbrdhist += Board.AddHit(m_Bkey,hitdata,chist,true);
742  if (Chip.CheckSelection(hitdata.chp)) {
743  nchphist += Chip.AddHit(m_Ckey,hitdata,chist,true);
744  if (Straw.CheckSelection(hitdata.stw)) {
745  nstwhist += Straw.AddHit(m_Skey,hitdata,chist,true);
746  }
747  }
748  }
749  }
750  }
751  } // Here it closes
752  ihist++;
753  } else { // ARGON HITS
754  nTRThistAr += TRT_Ar.AddHit(m_Tkey,hitdata,chist,true);
755  if (Detector_Ar.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
756  if (m_SplitBarrel) ndethistAr += Detector_Ar.AddHit(m_Dkey,hitdata,chist,true);
757  else ndethistAr += Detector_Ar.AddHit(m_Dkey_acc,hitdata,chist,true);
758  if (Layer_Ar.CheckSelection(hitdata.lay)) {
759  if (m_SplitBarrel) nlayhistAr += Layer_Ar.AddHit(m_Lkey,hitdata,chist,true);
760  else { nlayhistAr += Layer_Ar.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
761  if (Module_Ar.CheckSelection(hitdata.mod)) {
762  nmodhistAr += Module_Ar.AddHit(m_Mkey,hitdata,chist,true);
763  if (Board_Ar.CheckSelection(hitdata.brd)) {
764  nbrdhistAr += Board_Ar.AddHit(m_Bkey,hitdata,chist,true);
765  if (Chip_Ar.CheckSelection(hitdata.chp)) {
766  nchphistAr += Chip_Ar.AddHit(m_Ckey,hitdata,chist,true);
767  if (Straw_Ar.CheckSelection(hitdata.stw)) {
768  nstwhistAr += Straw_Ar.AddHit(m_Skey,hitdata,chist,true);
769  }
770  }
771  }
772  }
773  }
774  } // Here it closes
775  ihistAr++;
776  } // END ARGON HITS
777 
778 
779  if ((ihist%10000==9999) | (ihist==m_nevents-1)){
780  ATH_MSG_INFO( Form("%7i HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihist+1,nTRThist, ndethist, nlayhist, nmodhist, nbrdhist, nchphist, nstwhist) );
781  if(m_DoArXenonSep) ATH_MSG_INFO( Form("%7i Ar HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihistAr+1,nTRThistAr, ndethistAr, nlayhistAr, nmodhistAr, nbrdhistAr, nchphistAr, nstwhistAr) );
782  }
783 
784  ihist++;
785  delete [] chist;
786  } // Finish Straw Loop
787 
788  ATH_MSG_INFO( Form("%7i HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihist+1,nTRThist, ndethist, nlayhist, nmodhist, nbrdhist, nchphist, nstwhist) );
789  if(m_DoArXenonSep) ATH_MSG_INFO( Form("%7i Ar HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihistAr+1,nTRThistAr, ndethistAr, nlayhistAr, nmodhistAr, nbrdhistAr, nchphistAr, nstwhistAr) );
790 
791  TRT.UpdateOldConstants();
792  Detector.UpdateOldConstants();
793  Layer.UpdateOldConstants();
794  Module.UpdateOldConstants();
795  Board.UpdateOldConstants();
796  Chip.UpdateOldConstants();
797 
798  if (ihistAr>0 ){
799  TRT_Ar.UpdateOldConstants();
800  Detector_Ar.UpdateOldConstants();
801  Layer_Ar.UpdateOldConstants();
802  Module_Ar.UpdateOldConstants();
803  Board_Ar.UpdateOldConstants();
804  Chip_Ar.UpdateOldConstants();
805  }
806 
807  myFile.close();
808 
809 
810  ATH_MSG_INFO(" ");
811  ATH_MSG_INFO( TRT.PrintStat() );
812  ATH_MSG_INFO( Detector.PrintStat() );
813  ATH_MSG_INFO( Layer.PrintStat() );
814  ATH_MSG_INFO( Module.PrintStat() );
815  ATH_MSG_INFO( Board.PrintStat() );
816  ATH_MSG_INFO( Chip.PrintStat() );
817  ATH_MSG_INFO( Straw.PrintStat() );
818  ATH_MSG_INFO(" ");
819 
820 
821  if(m_DoArXenonSep){
822  ATH_MSG_INFO(" ");
823  ATH_MSG_INFO( TRT_Ar.PrintStat() );
824  ATH_MSG_INFO( Detector_Ar.PrintStat() );
825  ATH_MSG_INFO( Layer_Ar.PrintStat() );
826  ATH_MSG_INFO( Module_Ar.PrintStat() );
827  ATH_MSG_INFO( Board_Ar.PrintStat() );
828  ATH_MSG_INFO( Chip_Ar.PrintStat() );
829  ATH_MSG_INFO( Straw_Ar.PrintStat() );
830  ATH_MSG_INFO(" ");
831  }
832 
833 
834 
835  //caldata startdata(true,tbins,rbins);
836  caldata startdata(true,55,100);
837  //caldata startdata(true,64,64);
838  startdata.t0=5.0;
839  std::map<std::string,TDirectory*> dirmap;
840  TDirectory* trtdir=gDirectory;
841  TDirectory* detdir=gDirectory;
842  TDirectory* laydir=gDirectory;
843  TDirectory* moddir=gDirectory;
844  TDirectory* brddir=gDirectory;
845  TDirectory* chpdir=gDirectory;
846 
847  std::ofstream rtcalfile(Form("%s_rt.txt",outfile.data()),std::ios::out);
848  std::ofstream binrtcalfile(Form("%s_binrt.txt",outfile.data()),std::ios::out);
849  std::ofstream t0calfile(Form("%s_t0.txt",outfile.data()),std::ios::out);
850 
851 
852  //if (m_SplitBarrel){
853 
854  for (std::pair<const std::string, BDdetector>& pt : m_trt.t) {
855 
856  if (TRT.Skip()) break;
857  if (TRT.HasKey(pt.first)) {
858  trtdir = TRT.Calibrate(histfile.get(),pt.first,SubLev(m_options,1),&startdata);
859  if (TRT.printt0) t0calfile << Form("-3 -1 -1 -1 -1 : %e %e",TRT.data[pt.first].t0,TRT.data[pt.first].t0err) << std::endl;
860  if (TRT.printrt) rtcalfile << Form("-3 -1 -1 -1 -1 : %i %e %e %e %e",rtint,TRT.data[pt.first].rtpar[0],TRT.data[pt.first].rtpar[1],TRT.data[pt.first].rtpar[2],TRT.data[pt.first].rtpar[3]) << std::endl;
861  }
862  for (std::pair<const std::string, BDlayer>& pd : pt.second.d) {
863 
864  if(Detector.Skip()) break;
865  if(Detector.HasKey(pd.first)){
866  detdir = Detector.Calibrate(trtdir,pd.first,SubLev(m_options,2),&TRT.data[pt.first]);
867  }
868  for (std::pair<const std::string, BDmodule>& pl : pd.second.l) {
869 
870  if(Layer.Skip()) break;
871  if(Layer.HasKey(pl.first)){
872  laydir = Layer.Calibrate(detdir,pl.first,SubLev(m_options,3),&Detector.data[pd.first]);
873  if (Layer.printt0) t0calfile << Form("%i %i -1 -1 -1 : %e %e",Layer.data[pl.first].det,Layer.data[pl.first].lay,Layer.data[pl.first].t0,Layer.data[pl.first].t0err) << std::endl;
874  if (Layer.printrt) rtcalfile << Form("%i %i -1 -1 -1 : %i %e %e %e %e",Layer.data[pl.first].det,Layer.data[pl.first].lay,rtint,Layer.data[pl.first].rtpar[0],Layer.data[pl.first].rtpar[1],Layer.data[pl.first].rtpar[2],Layer.data[pl.first].rtpar[3]) << std::endl;
875  if (!m_SplitBarrel) {
876  if (Layer.printt0) t0calfile << Form("%i %i -1 -1 -1 : %e %e",-Layer.data[pl.first].det,Layer.data[pl.first].lay,Layer.data[pl.first].t0,Layer.data[pl.first].t0err) << std::endl;
877  if (Layer.printrt) rtcalfile << Form("%i %i -1 -1 -1 : %i %e %e %e %e",-Layer.data[pl.first].det,Layer.data[pl.first].lay,rtint,Layer.data[pl.first].rtpar[0],Layer.data[pl.first].rtpar[1],Layer.data[pl.first].rtpar[2],Layer.data[pl.first].rtpar[3]) << std::endl;
878  }
879  }
880  for (std::pair<const std::string, BDboard>& pm : pl.second.m) {
881 
882  if(Module.Skip()) break;
883  if(Module.HasKey(pm.first)){
884  moddir = Module.Calibrate(laydir,pm.first,SubLev(m_options,4),&Layer.data[pl.first]);
885  if (Module.printt0) t0calfile << Form("%i %i %i -1 -1 : %e %e",Module.data[pm.first].det,Module.data[pm.first].lay,Module.data[pm.first].mod,Module.data[pm.first].t0,Module.data[pm.first].t0err) << std::endl;
886  if (Module.printrt) rtcalfile << Form("%i %i %i -1 -1 : %i %e %e %e %e",Module.data[pm.first].det,Module.data[pm.first].lay,Module.data[pm.first].mod,rtint,Module.data[pm.first].rtpar[0],Module.data[pm.first].rtpar[1],Module.data[pm.first].rtpar[2],Module.data[pm.first].rtpar[3]) << std::endl;
887  }
888  for (std::pair<const std::string, BDchip>& pb : pm.second.b) {
889 
890  if(Board.Skip()) break;
891  if(Board.HasKey(pb.first)){
892  brddir = Board.Calibrate(moddir,pb.first,SubLev(m_options,5),&Module.data[pm.first]);
893  }
894  for (std::pair<const std::string, BDstraw>& pc : pb.second.c) {
895 
896  if(Chip.Skip()) break;
897  if(Chip.HasKey(pc.first)){
898  chpdir = Chip.Calibrate(brddir,pc.first,SubLev(m_options,6),&Board.data[pb.first]);
899  }
900  for (std::pair<const std::string, BDzero>& ps : pc.second.s) {
901 
902  if(Straw.Skip()) break;
903  if(Straw.HasKey(ps.first)){
904  Straw.Calibrate(chpdir,ps.first,SubLev(m_options,7),&Chip.data[pc.first]);
905  if (Straw.printt0) t0calfile << Form("%i %i %i %i %i : %e %e",Straw.data[ps.first].det,Straw.data[ps.first].lay,Straw.data[ps.first].mod,Straw.data[ps.first].stl,Straw.data[ps.first].stw,Straw.data[ps.first].t0,Straw.data[ps.first].t0err) << std::endl;
906  if (Straw.printrt) rtcalfile << Form("%i %i %i %i %i : %i %e %e %e %e",Straw.data[ps.first].det,Straw.data[ps.first].lay,Straw.data[ps.first].mod,Straw.data[ps.first].stl,Straw.data[ps.first].stw,rtint,Straw.data[ps.first].rtpar[0],Straw.data[ps.first].rtpar[1],Straw.data[ps.first].rtpar[2],Straw.data[ps.first].rtpar[3]) << std::endl;
907 
908 
909  }
910  }
911  }
912  }
913  }
914  }
915  }
916  }
917 
918  std::map<std::string,TDirectory*> dirArmap;
919  TDirectory* trtdirAr=gDirectory;
920  TDirectory* detdirAr=gDirectory;
921  TDirectory* laydirAr=gDirectory;
922  TDirectory* moddirAr=gDirectory;
923  TDirectory* brddirAr=gDirectory;
924  TDirectory* chpdirAr=gDirectory;
925 
926  if (m_DoArXenonSep){
927 
928  for (std::pair<const std::string, BDdetector>& pt : m_trt.t) {
929 
930  if (TRT_Ar.Skip()) break;
931  if (TRT_Ar.HasKey(pt.first)) {
932  trtdirAr = TRT_Ar.Calibrate(histfile.get(),pt.first,SubLev(m_options,1),&startdata);
933  }
934  for (std::pair<const std::string, BDlayer>& pd : pt.second.d) {
935 
936  if(Detector_Ar.Skip()) break;
937  if(Detector_Ar.HasKey(pd.first)){
938  detdirAr = Detector_Ar.Calibrate(trtdirAr,pd.first,SubLev(m_options,2),&TRT_Ar.data[pt.first]);
939  }
940  for (std::pair<const std::string, BDmodule>& pl : pd.second.l) {
941 
942  if(Layer_Ar.Skip()) break;
943  if(Layer_Ar.HasKey(pl.first)){
944  laydirAr = Layer_Ar.Calibrate(detdirAr,pl.first,SubLev(m_options,3),&Detector_Ar.data[pd.first]);
945 
946  }
947  for (std::pair<const std::string, BDboard>& pm : pl.second.m) {
948 
949  if(Module_Ar.Skip()) break;
950  if(Module_Ar.HasKey(pm.first)){
951  moddirAr = Module_Ar.Calibrate(laydirAr,pm.first,SubLev(m_options,4),&Layer_Ar.data[pl.first]);
952  if (Module_Ar.printt0) t0calfile << Form("%i %i %i -1 -1 : %e %e",Module_Ar.data[pm.first].det,Module_Ar.data[pm.first].lay,Module_Ar.data[pm.first].mod,Module_Ar.data[pm.first].t0,Module_Ar.data[pm.first].t0err) << std::endl;
953  if (Layer_Ar.printrt) rtcalfile << Form("%i %i %i -1 -1 : %i %e %e %e %e",Module_Ar.data[pm.first].det,Module_Ar.data[pm.first].lay,Module_Ar.data[pm.first].mod,rtint,Module_Ar.data[pm.first].rtpar[0],Module_Ar.data[pm.first].rtpar[1],Module_Ar.data[pm.first].rtpar[2],Module_Ar.data[pm.first].rtpar[3]) << std::endl;
954  }
955  for (std::pair<const std::string, BDchip>& pb : pm.second.b) {
956  if(Board_Ar.Skip()) break;
957  if(Board_Ar.HasKey(pb.first)){
958  brddirAr = Board_Ar.Calibrate(moddirAr,pb.first,SubLev(m_options,5),&Module_Ar.data[pm.first]);
959  }
960  for (std::pair<const std::string, BDstraw>& pc : pb.second.c) {
961 
962  if(Chip_Ar.Skip()) break;
963  if(Chip_Ar.HasKey(pc.first)){
964  chpdirAr = Chip_Ar.Calibrate(brddirAr,pc.first,SubLev(m_options,6),&Board_Ar.data[pb.first]);
965  }
966  for (std::pair<const std::string, BDzero>& ps : pc.second.s) {
967 
968  if(Straw_Ar.Skip()) break;
969  if(Straw_Ar.HasKey(ps.first)){
970  Straw_Ar.Calibrate(chpdirAr,ps.first,SubLev(m_options,7),&Chip_Ar.data[pc.first]);
971  if (Straw_Ar.printt0) t0calfile << Form("%i %i %i %i %i : %e %e",Straw_Ar.data[ps.first].det,Straw_Ar.data[ps.first].lay,Straw_Ar.data[ps.first].mod,Straw_Ar.data[ps.first].stl,Straw_Ar.data[ps.first].stw,Straw_Ar.data[ps.first].t0,Straw_Ar.data[ps.first].t0err) << std::endl;
972  if (Straw_Ar.printrt) rtcalfile << Form("%i %i %i %i %i : %i %e %e %e %e",Straw_Ar.data[ps.first].det,Straw_Ar.data[ps.first].lay,Straw_Ar.data[ps.first].mod,Straw_Ar.data[ps.first].stl,Straw_Ar.data[ps.first].stw,rtint,Straw_Ar.data[ps.first].rtpar[0],Straw_Ar.data[ps.first].rtpar[1],Straw_Ar.data[ps.first].rtpar[2],Straw_Ar.data[ps.first].rtpar[3]) << std::endl;
973  }
974  }
975  }
976  }
977  }
978  }
979  }
980  }
981 
982 }// Close for ARGON
983 
984 
985 
986 
987  //make ntuples for each calibrator
988  if (!TRT.bequiet) TRT.WriteStat(histfile.get());
989  if (!Detector.bequiet) Detector.WriteStat(histfile.get());
990  if (!Layer.bequiet) Layer.WriteStat(histfile.get());
991  if (!Module.bequiet) Module.WriteStat(histfile.get());
992  if (!Board.bequiet) Board.WriteStat(histfile.get());
993  Chip.WriteStat(histfile.get());
994  Straw.WriteStat(histfile.get());
995 
996  TRT.DumpConstants();
997  Detector.DumpConstants();
998  Layer.DumpConstants();
999  Module.DumpConstants();
1000  Board.DumpConstants();
1001  Chip.DumpConstants();
1002  Straw.DumpConstants();
1003 
1004  rtcalfile.close();
1005  binrtcalfile.close();
1006  t0calfile.close();
1007 
1008  //AR
1009  //make ntuples for each calibrator
1010  if(m_DoArXenonSep){
1011  if (!TRT_Ar.bequiet) TRT_Ar.WriteStat(histfile.get());
1012  if (!Detector_Ar.bequiet) Detector_Ar.WriteStat(histfile.get());
1013  if (!Layer_Ar.bequiet) Layer_Ar.WriteStat(histfile.get());
1014  if (!Module_Ar.bequiet) Module_Ar.WriteStat(histfile.get());
1015  if (!Board_Ar.bequiet) Board_Ar.WriteStat(histfile.get());
1016  Chip_Ar.WriteStat(histfile.get());
1017  Straw_Ar.WriteStat(histfile.get());
1018 
1019  TRT_Ar.DumpConstants();
1020  Detector_Ar.DumpConstants();
1021  Layer_Ar.DumpConstants();
1022  Module_Ar.DumpConstants();
1023  Board_Ar.DumpConstants();
1024  Chip_Ar.DumpConstants();
1025  Straw_Ar.DumpConstants();
1026  }
1027 
1028  histfile->ls();
1029  ATH_MSG_INFO( "writing out calibout.root");
1030  histfile->Write();
1031 
1032  return true;
1033 
1034 }
1035 
1037  if (aTrack==nullptr) {};
1038  if (output==nullptr) {};
1039  return true;
1040 }
1041 
1042 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TRTCond::DinesRtRelation
Definition: DinesRtRelation.h:26
TRTCalibrator::m_maxTimeResidual
float m_maxTimeResidual
Definition: TRTCalibrator.h:120
Calibrator::printt0
bool printt0
if true a t0 entry in the calibration output file is prined for each sub-module in this sub-level
Definition: Calibrator.h:349
TRTCalibrator.h
databundle::det
int det
detector (barrel -1 or 1, or end-cap -2 or 2)
Definition: Calibrator.h:79
TRT
@ TRT
Definition: RegSelEnums.h:26
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTCalibrator::m_calsub
std::string m_calsub
Definition: TRTCalibrator.h:135
DinesRtRelation.h
InDetDD::TRT_BarrelElement
Definition: TRT_BarrelElement.h:44
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
TrackParameters.h
run.infile
string infile
Definition: run.py:13
ComTime.h
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRT_DetectorManager.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
TRTCalibrator::m_beQuiet
std::vector< std::string > m_beQuiet
Definition: TRTCalibrator.h:145
TRTCalibrator::finalize
virtual StatusCode finalize() override
Definition: TRTCalibrator.cxx:255
TRTCalibrator::m_floatP3
bool m_floatP3
Definition: TRTCalibrator.h:149
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
RtRelation.h
abstract base class for rt-relations
Calibrator::UpdateOldConstants
int UpdateOldConstants()
...
Definition: Calibrator.cxx:529
Calibrator
A structure to contain data associated with the calibration of a certain sub-module.
Definition: Calibrator.h:178
Calibrator::HasKey
bool HasKey(const std::string &) const
...
Definition: Calibrator.cxx:452
TRTCalibrator::m_TRTID
const TRT_ID * m_TRTID
Definition: TRTCalibrator.h:114
TRTCalibrator::m_Dkey
std::string m_Dkey
Definition: TRTCalibrator.h:156
TRTCalibrator::m_Dkey_acc
std::string m_Dkey_acc
Definition: TRTCalibrator.h:156
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TRTCalibrator::m_minTimebinsOverThreshold
int m_minTimebinsOverThreshold
Definition: TRTCalibrator.h:121
caldata
A structure to contain data associated with the calibration of a certain sub-module.
Definition: Calibrator.h:104
databundle::lay
int lay
layer
Definition: Calibrator.h:80
InDetDD::TRT_EndcapElement
Definition: TRT_EndcapElement.h:44
Calibrator::CheckSelection
bool CheckSelection(int)
Checks if a given sub-module is selected for calibration.
Definition: Calibrator.cxx:457
TRTCalibrator::m_t0offset
float m_t0offset
The t0 offset.
Definition: TRTCalibrator.h:133
Calibrator::printrt
bool printrt
if true an rt entry in the calibration output file is prined for each sub-module in this sub-level
Definition: Calibrator.h:350
TRTCalibrator::m_maxTrackChisquarePerDof
float m_maxTrackChisquarePerDof
Definition: TRTCalibrator.h:122
athena.value
value
Definition: athena.py:122
TRTCalibrator::m_doOutPrint
std::vector< std::string > m_doOutPrint
Definition: TRTCalibrator.h:153
TRTCalibrator::m_DetID
const AtlasDetectorID * m_DetID
Definition: TRTCalibrator.h:113
BasicRtRelation.h
databundle::brd
int brd
board
Definition: Calibrator.h:82
TRTCalibrator::m_config
std::map< std::string, conf > m_config
Definition: TRTCalibrator.h:181
x
#define x
TRT::TrackInfo
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:83
PrepRawData.h
python.RingerConstants.Layer
Layer
Definition: RingerConstants.py:42
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
Track.h
Calibrator::Skip
bool Skip()
...
Definition: Calibrator.cxx:462
TRTCalibrator::m_DoArXenonSep
bool m_DoArXenonSep
Definition: TRTCalibrator.h:151
databundle::stw
int stw
straw number (within the strawlayer)
Definition: Calibrator.h:85
Calibrator::PrintInfo
std::string PrintInfo()
Definition: Calibrator.cxx:467
TRTCalibrator::m_rtrel
std::string m_rtrel
the rt relation to use
Definition: TRTCalibrator.h:140
TRTCalibrator::m_useP0
bool m_useP0
Definition: TRTCalibrator.h:148
databundle::mod
int mod
phi module
Definition: Calibrator.h:81
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
TRTCalibrator::m_rtbinning
std::string m_rtbinning
Definition: TRTCalibrator.h:136
TRTCond::DinesRtRelation::cal
const float * cal() const
return to calibration constants
Definition: DinesRtRelation.h:76
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:902
TrackInfo.h
TRTCalibrator::m_nevents
int m_nevents
The number of hits or histograms read from the input file.
Definition: TRTCalibrator.h:132
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTCalibrator::m_minrt
int m_minrt
minimum number of hits required to do R-t calibration
Definition: TRTCalibrator.h:130
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
TRT
Definition: HitInfo.h:33
ATLAS_NOT_THREAD_SAFE
bool TRTCalibrator::calibrate ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: TRTCalibrator.cxx:367
TRTCalibrator::m_mint0
int m_mint0
minimum number of hits required to do T0 calibration
Definition: TRTCalibrator.h:131
Calibrator::GetOptString
std::string GetOptString() const
Creates a string summarizing what is being done at this sub-level.
Definition: Calibrator.cxx:485
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
TRTCond::BasicRtRelation
Definition: BasicRtRelation.h:26
databundle::x
float x
straw x position
Definition: Calibrator.h:96
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
caldata::t0
float t0
the new t0
Definition: Calibrator.h:126
TRTCalibrator::MakeBDKeys
void MakeBDKeys(int, int, int, int, int, int)
makes the key strings for a sub-module
Definition: TRTCalibrator.cxx:350
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BinnedRtRelation.h
databundle::res
float res
space residual
Definition: Calibrator.h:90
Calibrator::DumpConstants
void DumpConstants()
Definition: Calibrator.cxx:1225
TRTCalibrator::m_TRTStrawSummaryTool
ToolHandle< ITRT_StrawStatusSummaryTool > m_TRTStrawSummaryTool
The ConditionsSummaryTool.
Definition: TRTCalibrator.h:118
TRTCalibrator::m_Skey
std::string m_Skey
Definition: TRTCalibrator.h:156
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TRTCalibrator::m_doT0
std::vector< std::string > m_doT0
Definition: TRTCalibrator.h:143
TRTCalibrator::m_doRtPrint
std::vector< std::string > m_doRtPrint
Definition: TRTCalibrator.h:154
jet::CompCategory::Detector
@ Detector
Definition: UncertaintyEnum.h:19
databundle::ievt
int ievt
event number
Definition: Calibrator.h:87
TRTCalibrator::m_SplitBarrel
bool m_SplitBarrel
Definition: TRTCalibrator.h:147
TRTCalibrator::m_doLogPrint
std::vector< std::string > m_doLogPrint
Definition: TRTCalibrator.h:152
TRTCalibrator::m_selstring
std::string m_selstring
Definition: TRTCalibrator.h:137
TRTCalibrator::SubLev
std::string SubLev(std::string, int)
return sub-level i from a selection string with the form _X_X_X_X_X_X_X
Definition: TRTCalibrator.cxx:261
TRT_DriftCircleOnTrack.h
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
TRT_DriftCircle.h
databundle::weight
float weight
histogram weight (currently set to 1)
Definition: Calibrator.h:89
TRTCond::StrawStatus::Good
@ Good
Definition: StrawStatus.h:18
min
#define min(a, b)
Definition: cfImp.cxx:40
merge.output
output
Definition: merge.py:17
dso-stats.pat
pat
Definition: dso-stats.py:39
Calibrator::WriteStat
void WriteStat(TDirectory *)
Creates an ntuple with entries containing data associated with the sub-modules in a sub level.
Definition: Calibrator.cxx:1180
EventPrimitives.h
xAOD::Straw
@ Straw
Definition: TrackingPrimitives.h:557
databundle::rtpar
std::array< float, 4 > rtpar
rt-parameters used in the reconstruction
Definition: Calibrator.h:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
RIO_OnTrack.h
TRTCalibrator::m_doRes
std::vector< std::string > m_doRes
Definition: TRTCalibrator.h:144
TRTCalibrator::m_maxDistance
float m_maxDistance
Definition: TRTCalibrator.h:119
LArConditions2Ntuple.ckey
string ckey
Definition: LArConditions2Ntuple.py:159
Calibrator::PrintStat
std::string PrintStat()
Prints some sub-level statistics.
Definition: Calibrator.cxx:478
databundle
A structure to contain hit data.
Definition: Calibrator.h:77
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
LocalParameters.h
TRTCalibrator::m_trtmanager
const InDetDD::TRT_DetectorManager * m_trtmanager
Definition: TRTCalibrator.h:115
databundle::chp
int chp
chip
Definition: Calibrator.h:83
TRTCalibrator::m_ntrtmanager
std::string m_ntrtmanager
Definition: TRTCalibrator.h:141
PlotSFuncertainty.calib
calib
Definition: PlotSFuncertainty.py:110
TRTCalibrator::m_neighbourSvc
ServiceHandle< ITRT_StrawNeighbourSvc > m_neighbourSvc
Definition: TRTCalibrator.h:117
databundle::z
float z
straw z position
Definition: Calibrator.h:98
Calibrator::AddHit
int AddHit(const std::string &, const databundle &, int *, bool)
Adds hits to a sub-module either in the form of a single straw hit or a histogram containing all the ...
Definition: Calibrator.cxx:962
Calibrator.h
TRTCalibrator::m_doRt
std::vector< std::string > m_doRt
Definition: TRTCalibrator.h:142
Calibrator::GetSelString
std::string GetSelString()
Creates a string summarizing which modules are being calibrated at this sub-level.
Definition: Calibrator.cxx:506
databundle::rt0
float rt0
reference t0 (offset from board mean)
Definition: Calibrator.h:94
y
#define y
TRTCalibrator::m_Mkey
std::string m_Mkey
Definition: TRTCalibrator.h:156
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TRTCalibrator::CALIB_NONE
@ CALIB_NONE
Definition: TRTCalibrator.h:183
TRTCalibrator::m_Bkey
std::string m_Bkey
Definition: TRTCalibrator.h:156
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TRTCalibrator::m_Tkey
std::string m_Tkey
Definition: TRTCalibrator.h:156
TRTCalibrator::m_Ckey
std::string m_Ckey
Definition: TRTCalibrator.h:156
TRTCalibrator::m_DoShortStrawCorrection
bool m_DoShortStrawCorrection
Definition: TRTCalibrator.h:150
InDetDD::TRT_BaseElement::center
virtual const Amg::Vector3D & center() const override final
Element Surface: center of a straw layer.
TRTCalibrator::m_options
std::string m_options
Definition: TRTCalibrator.h:138
databundle::stl
int stl
straw-layer
Definition: Calibrator.h:84
databundle::r
float r
drift radius from r(t) relation
Definition: Calibrator.h:92
databundle::sid
int sid
straw ID
Definition: Calibrator.h:86
TRTCalibrator::initialize
virtual StatusCode initialize() override
Pre-define standard calibration configuration.
Definition: TRTCalibrator.cxx:112
TRTCalibrator::m_hittuple
std::string m_hittuple
Definition: TRTCalibrator.h:139
TRTCalibrator::m_useBoardRef
std::vector< std::string > m_useBoardRef
Definition: TRTCalibrator.h:146
TRTCalibrator::DumpStrawData
void DumpStrawData(int)
returns true if the ...
Definition: TRTCalibrator.cxx:273
TRTCalibrator::TRTCalibrator
TRTCalibrator(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: TRTCalibrator.cxx:44
TRTCond::BasicRtRelation::cal
const float * cal() const
return to calibration constants
Definition: BasicRtRelation.h:76
TRTCalibrator::fill
virtual bool fill(const Trk::Track *aTrack, TRT::TrackInfo *output) override
Definition: TRTCalibrator.cxx:1036
TRTCalibrator::GetSubLevels
int GetSubLevels(const std::string &, int, std::set< int > *)
fills a set of integers with the indexes af the sub-modules that are conatined in a selection
Definition: TRTCalibrator.cxx:305
TRTCalibrator::m_trtcaldbTool
ToolHandle< ITRT_CalDbTool > m_trtcaldbTool
Definition: TRTCalibrator.h:116
AthAlgTool
Definition: AthAlgTool.h:26
Calibrator::bequiet
bool bequiet
if true no histograms are written to the root file
Definition: Calibrator.h:347
databundle::tres
float tres
time residual
Definition: Calibrator.h:88
TRTCalibrator::m_Lkey
std::string m_Lkey
Definition: TRTCalibrator.h:156
databundle::t0
float t0
t0 value used in reconstruction
Definition: Calibrator.h:93
TRTCalibrator::IsSubLev
bool IsSubLev(const std::string &, int, const std::string &)
returns true if the ...
Definition: TRTCalibrator.cxx:290
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
module_driven_slicing.histfile
histfile
Definition: module_driven_slicing.py:571
readCCLHist.float
float
Definition: readCCLHist.py:83
databundle::y
float y
straw y position
Definition: Calibrator.h:97
python.SystemOfUnits.pc
float pc
Definition: SystemOfUnits.py:99
TRTCalibrator::m_Lkey_acc
std::string m_Lkey_acc
Definition: TRTCalibrator.h:156
Calibrator::data
std::map< std::string, caldata > data
A map between the sub-module identifier string and the calibration data structure (caldata)
Definition: Calibrator.h:339
extractSporadic.myFile
myFile
Definition: extractSporadic.py:87
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
databundle::t
float t
raw time
Definition: Calibrator.h:91
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37