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