ATLAS Offline Software
Classes | Functions
TRTCalib_bhadd.cxx File Reference
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <TMath.h>
#include <iostream>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include <map>
#include <vector>
#include <TFile.h>
#include <TNtuple.h>
#include <TH2F.h>
#include <TH1D.h>
#include <TVectorD.h>

Go to the source code of this file.

Classes

class  CalHist
 
class  CompBHist
 
class  trackdata
 
struct  calibpars
 

Functions

int Simple1dHist (float min, float max, int nbins, float value)
 
int Simple2dHist (float minx, float maxx, int nbinsx, float miny, float maxy, int nbinsy, float valuex, float valuey)
 
void process_mem_usage (double &vm_usage, double &resident_set)
 
map< string, calibparsreadoldpars ()
 
int dump_tracktuple (map< string, trackdata > *trackmap)
 
int dump_hists (map< int, CalHist * > *histmap, int ntbins, int nrbins, int, char *fname, int fileno)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ dump_hists()

int dump_hists ( map< int, CalHist * > *  histmap,
int  ntbins,
int  nrbins,
int  ,
char *  fname,
int  fileno 
)

Definition at line 292 of file TRTCalib_bhadd.cxx.

293 {
294 
295  std::vector<int> temparray(ntbins * nrbins + 200, 0);
296  int maxnpop = 0;
297  int totnpop = 0;
298  ofstream ofile(Form("%s.part%i", fname, fileno), ios::out | ios::binary | ios::app);
299  for (map<int, CalHist *>::iterator it = histmap->begin(); it != histmap->end(); ++it)
300  {
301  it->second->GetArray(temparray, ntbins * nrbins + 200);
302  CompBHist *cbhist = new CompBHist(it->first, temparray, ntbins, nrbins);
303  cbhist->Write(&ofile);
304  if (cbhist->npop > maxnpop)
305  maxnpop = cbhist->npop;
306  totnpop += cbhist->npop;
307  delete cbhist;
308  }
309 
310  cout << "DUMPING " << histmap->size() << " HISTOGRAMS, MAX NONZERO BINS: " << maxnpop << ", AVERAGE NONZERO BINS: " << (float)totnpop / histmap->size() << endl;
311 
312  ofile.close();
313 
314  return 0;
315 }

◆ dump_tracktuple()

int dump_tracktuple ( map< string, trackdata > *  trackmap)

Definition at line 277 of file TRTCalib_bhadd.cxx.

278 {
279 
280  TFile *ttfile = new TFile("tracktuple.root", "UPDATE");
281  TNtuple *tracktup = new TNtuple("tracktuple", "track data", "run:evt:track:epnew:epold:nhits:t0:t:ttrack:theta:phi:d0:pt:trackres:trackresMean");
282  for (std::map<std::string, trackdata>::iterator iep = trackmap->begin(); iep != trackmap->end(); ++iep)
283  {
284  tracktup->Fill(iep->second.run, iep->second.event, iep->second.track, iep->second.epnew / iep->second.nhits, iep->second.epold, iep->second.nhits, iep->second.t0 / iep->second.nhits, iep->second.t / iep->second.nhits, iep->second.ttrack / iep->second.nhits, iep->second.theta, iep->second.phi, iep->second.d0, iep->second.pt, (iep->second.trackres / iep->second.nhits), (iep->second.trackresMean / iep->second.nhits));
285  }
286  ttfile->Write();
287  ttfile->Close();
288  // tracktup->Delete();
289  return 0;
290 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 319 of file TRTCalib_bhadd.cxx.

320 {
321 
322  bool existAr = false;
323 
324  float ptcutforerrors = 2;
325  // int who = RUSAGE_SELF;
326  // struct rusage usage;
327  // struct sysinfo sinfo;
328  // int ret;
329  double vm, rss;
330 
331  float run, evt, trk, det, lay, mod, stl, stw, brd, chp, fsid, r, dr, t, rtrack, ttrack, drtrack, t0, ephase, theta, phi, pt, d0, ToT, HT, qoverp, isArgonStraw;
332  int sid;
333  pt = 0;
334  d0 = 0;
335  phi = 0;
336  theta = 0;
337  map<int, CalHist *> histmap;
338  map<string, trackdata> trackmap;
339 
340  int ntbins = 55, nrbins = 100, ntresbins = 100, nresbins = 100, nhistbins, maxvalue = 0;
341  // int ntbins=64,nrbins=64,ntresbins=100,nresbins=100,nhistbins,maxvalue=0;
342  double minr = 0, maxr = 2, mint = -5, maxt = 50, mintres = -10, maxtres = 10, minres = -0.6, maxres = 0.6;
343  // double minr=0,maxr=2,mint=-10,maxt=80,mintres=-25,maxtres=25,minres=-1.0,maxres=1.0;
344 
345  // int ntbins=64,nrbins=64,ntresbins=100,nresbins=100,nhistbins,maxvalue=0;
346  // double minr=0,maxr=2,mint=-10,maxt=80,mintres=-25,maxtres=25,minres=-1.0,maxres=1.0;
347 
348  // sscanf (argv[1],"%i",&ntbins);
349  // sscanf (argv[2],"%i",&nrbins);
350  nhistbins = ntbins * nrbins + 200;
351 
352  int npop;
353  // char header[50];
354  std::vector<int> histdata(nhistbins, 0);
355 
356  int nhits = 0, nhists = 0;
357  int ntres = 0, nres = 0, nrt = 0;
358  int nhistsadd = 0, nbinsadd = 0, nhiststmp = 0;
359 
360  int nfiles = argc - 2;
361  cout << "PROCESSING " << nfiles << " FILE(S)" << endl
362  << endl;
363 
364  ofstream ofilestat((string(argv[1]) + ".stat").data(), ios::out);
365 
366  TH1F *residual_ref = new TH1F("residual_-2_0_0_1", "residual_-2_0_0_1", nresbins, minres, maxres);
367  TH1F *timeresidual_ref = new TH1F("timeresidual_1_0_0_0_1", "timeresidual_1_0_0_0_1", ntresbins, mintres, maxtres);
368  TH2F *rt_ref = new TH2F("rt_-1_2", "rt_-1_2", ntbins, mint, maxt, nrbins, minr, maxr);
369  TH2F *rt_ref2 = new TH2F("rt_-1", "rt_-1", ntbins, mint, maxt, nrbins, minr, maxr);
370 
371  TH2F *reshist_trt = new TH2F("residual_trt", "residual_trt", ntbins, mint, maxt, 100, -0.4, 0.4);
372  TH2F *reshist_bar = new TH2F("residual_bar", "residual_bar", ntbins, mint, maxt, 100, -0.4, 0.4);
373  TH2F *reshist1 = new TH2F("residual_1", "residual_1", ntbins, mint, maxt, 100, -0.4, 0.4);
374  TH2F *reshist2 = new TH2F("residual_-1", "residual_-1", ntbins, mint, maxt, 100, -0.4, 0.4);
375  TH2F *reshist3 = new TH2F("residual_2", "residual_2", ntbins, mint, maxt, 100, -0.4, 0.4);
376  TH2F *reshist4 = new TH2F("residual_-2", "residual_-2", ntbins, mint, maxt, 100, -0.4, 0.4);
377 
378  TH2F *treshist_trt = new TH2F("timeresidual_trt", "timeresidual_trt", 50, mintres, maxtres, nrbins, minr, maxr);
379  TH2F *treshist_bar = new TH2F("timeresidual_bar", "timeresidual_bar", 50, mintres, maxtres, nrbins, minr, maxr);
380  TH2F *treshist1 = new TH2F("timeresidual_1", "timeresidual_1", 50, mintres, maxtres, nrbins, minr, maxr);
381  TH2F *treshist2 = new TH2F("timeresidual_-1", "timeresidual_-1", 50, mintres, maxtres, nrbins, minr, maxr);
382  TH2F *treshist3 = new TH2F("timeresidual_2", "timeresidual_2", 50, mintres, maxtres, nrbins, minr, maxr);
383  TH2F *treshist4 = new TH2F("timeresidual_-2", "timeresidual_-2", 50, mintres, maxtres, nrbins, minr, maxr);
384 
385  map<string, calibpars> pt0map = readoldpars();
386 
387  // Histograms to do error study: Barrel/Ecs:
388 
389  // Pt dependent:
390 
391  // Pull All hits:
392  TH2F *pull_trt = new TH2F("pull_trt", "pull_TRT_allhits", 16, 0, 16, 200, -4, 4);
393  TH2F *pull_ba = new TH2F("pull_ba", "pull_BarrelA_allhits", 16, 0, 16, 200, -4, 4);
394  TH2F *pull_bc = new TH2F("pull_bc", "pull_BarrelC_allhits", 16, 0, 16, 200, -4, 4);
395  TH2F *pull_ea = new TH2F("pull_ea", "pull_EndcapA_allhits", 16, 0, 16, 200, -4, 4);
396  TH2F *pull_ec = new TH2F("pull_ec", "pull_EndcapC_allhits", 16, 0, 16, 200, -4, 4);
397 
398  // Residual All hits:
399  TH2F *residual_trt = new TH2F("residual_allhits", "residual_TRT_allhits", 16, 0, 16, 200, -2, 2);
400  TH2F *residual_ba = new TH2F("residual_ba", "residual_BarrelA_allhits", 16, 0, 16, 200, -2, 2);
401  TH2F *residual_bc = new TH2F("residual_bc", "residual_BarrelC_allhits", 16, 0, 16, 200, -2, 2);
402  TH2F *residual_ea = new TH2F("residual_ea", "residual_EndcapA_allhits", 16, 0, 16, 200, -2, 2);
403  TH2F *residual_ec = new TH2F("residual_ec", "residual_EndcapC_allhits", 16, 0, 16, 200, -2, 2);
404 
405  // Time Residual All hits:
406  TH2F *tresidual_trt = new TH2F("tresidual_trt", "tresidual_TRT_allhits", 16, 0, 16, 200, -20, 20);
407  TH2F *tresidual_ba = new TH2F("tresidual_ba", "tresidual_BarrelA_allhits", 16, 0, 16, 200, -20, 20);
408  TH2F *tresidual_bc = new TH2F("tresidual_bc", "tresidual_BarrelC_allhits", 16, 0, 16, 200, -20, 20);
409  TH2F *tresidual_ea = new TH2F("tresidual_ea", "tresidual_EndcapA_allhits", 16, 0, 16, 200, -20, 20);
410  TH2F *tresidual_ec = new TH2F("tresidual_ec", "tresidual_EndcapC_allhits", 16, 0, 16, 200, -20, 20);
411 
412  // Pull Precision hits:
413  TH2F *pull_trtP = new TH2F("pull_trtP", "pull_TRT_Phits", 16, 0, 16, 200, -4, 4);
414  TH2F *pull_baP = new TH2F("pull_baP", "pull_BarrelA_Phits", 16, 0, 16, 200, -4, 4);
415  TH2F *pull_bcP = new TH2F("pull_bcP", "pull_BarrelC_Phits", 16, 0, 16, 200, -4, 4);
416  TH2F *pull_eaP = new TH2F("pull_eaP", "pull_EndcapA_Phits", 16, 0, 16, 200, -4, 4);
417  TH2F *pull_ecP = new TH2F("pull_ecP", "pull_EndcapC_Phits", 16, 0, 16, 200, -4, 4);
418  // Residaul Precision hits:
419  TH2F *residual_trtP = new TH2F("residual_trtP", "residual_TRT_Phits", 16, 0, 16, 200, -2, 2);
420  TH2F *residual_baP = new TH2F("residual_baP", "residual_BarrelA_Phits", 16, 0, 16, 200, -2, 2);
421  TH2F *residual_bcP = new TH2F("residual_bcP", "residual_BarrelC_Phits", 16, 0, 16, 200, -2, 2);
422  TH2F *residual_eaP = new TH2F("residual_eaP", "residual_EndcapA_Phits", 16, 0, 16, 200, -2, 2);
423  TH2F *residual_ecP = new TH2F("residual_ecP", "residual_EndcapC_Phits", 16, 0, 16, 200, -2, 2);
424  // Residaul Precision hits:
425  TH2F *tresidual_trtP = new TH2F("tresidual_trtP", "residual_TRT_Phits", 16, 0, 16, 200, -20, 20);
426  TH2F *tresidual_baP = new TH2F("tresidual_baP", "residual_BarrelA_Phits", 16, 0, 16, 200, -20, 20);
427  TH2F *tresidual_bcP = new TH2F("tresidual_bcP", "residual_BarrelC_Phits", 16, 0, 16, 200, -20, 20);
428  TH2F *tresidual_eaP = new TH2F("tresidual_eaP", "residual_EndcapA_Phits", 16, 0, 16, 200, -20, 20);
429  TH2F *tresidual_ecP = new TH2F("tresidual_ecP", "residual_EndcapC_Phits", 16, 0, 16, 200, -20, 20);
430  // Track Errors :
431  TH2F *trackerrors_trtP = new TH2F("trackerrors_trt", "trackerrors_vs_pt_trt", 16, 0, 16, 200, 0, 0.2);
432  TH2F *trackerrors_baP = new TH2F("trackerrors_ba", "trackerrors_vs_pt_BarrelA", 16, 0, 16, 200, 0, .2);
433  TH2F *trackerrors_bcP = new TH2F("trackerrors_bc", "trackerrors_vs_pt_BarrelC", 16, 0, 16, 200, 0, .2);
434  TH2F *trackerrors_eaP = new TH2F("trackerrors_ea", "trackerrors_vs_pt_EndcapA", 16, 0, 16, 200, 0, .2);
435  TH2F *trackerrors_ecP = new TH2F("trackerrors_ec", "trackerrors_vs_pt_EndcapC", 16, 0, 16, 200, 0, .2);
436 
437  // for (map<string,calibpars>::iterator iot=pt0map.begin(); iot!=pt0map.end(); iot++) {
438 
439  // Time Bin Dependent:
440 
441  int ntbins2 = 30;
442  float tmin = -10;
443  float tmax = 75;
444 
445  // TH2 to Store the Pull vs width:
446  TH2F *pull_vs_tb_trt = new TH2F("pull_vs_tb_trt", "pull_vs_timebin_trt", ntbins2, tmin, tmax, 200, -4, 4);
447  TH2F *pull_vs_tb_ba = new TH2F("pull_vs_tb_ba", "pull_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, -4, 4);
448  TH2F *pull_vs_tb_bc = new TH2F("pull_vs_tb_bc", "pull_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, -4, 4);
449  TH2F *pull_vs_tb_ea = new TH2F("pull_vs_tb_ea", "pull_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, -4, 4);
450  TH2F *pull_vs_tb_ec = new TH2F("pull_vs_tb_ec", "pull_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, -4, 4);
451 
452  // TH2 to Store the ErrorsUsed vs width:
453  TH2F *errors_vs_tb_trt = new TH2F("errors_vs_tb_trt", "errors_vs_timebin_trt", ntbins2, tmin, tmax, 200, 0, 0.4);
454  TH2F *errors_vs_tb_ba = new TH2F("errors_vs_tb_ba", "errors_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, 0, 0.4);
455  TH2F *errors_vs_tb_bc = new TH2F("errors_vs_tb_bc", "errors_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, 0, 0.4);
456  TH2F *errors_vs_tb_ea = new TH2F("errors_vs_tb_ea", "errors_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, 0, 0.4);
457  TH2F *errors_vs_tb_ec = new TH2F("errors_vs_tb_ec", "errors_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, 0, 0.4);
458 
459  // TH2 to Store the ErrorsUsed vs width:
460  TH2F *residual_vs_tb_trt = new TH2F("residual_vs_tb_trt", "residual_vs_timebin_trt", ntbins2, tmin, tmax, 200, -2, .2);
461  TH2F *residual_vs_tb_ba = new TH2F("residual_vs_tb_ba", "residual_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, -2, .2);
462  TH2F *residual_vs_tb_bc = new TH2F("residual_vs_tb_bc", "residual_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, -2, .2);
463  TH2F *residual_vs_tb_ea = new TH2F("residual_vs_tb_ea", "residual_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, -2, .2);
464  TH2F *residual_vs_tb_ec = new TH2F("residual_vs_tb_ec", "residual_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, -2, .2);
465 
466  // TH2 to Store the Track Errors vs width:
467  TH2F *trackerrors_vs_tb_trt = new TH2F("trackerrors_vs_tb_trt", "trackerrors_vs_timebin_trt", ntbins2, tmin, tmax, 200, 0, 0.2);
468  TH2F *trackerrors_vs_tb_ba = new TH2F("trackerrors_vs_tb_ba", "trackerrors_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, 0, .2);
469  TH2F *trackerrors_vs_tb_bc = new TH2F("trackerrors_vs_tb_bc", "trackerrors_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, 0, .2);
470  TH2F *trackerrors_vs_tb_ea = new TH2F("trackerrors_vs_tb_ea", "trackerrors_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, 0, .2);
471  TH2F *trackerrors_vs_tb_ec = new TH2F("trackerrors_vs_tb_ec", "trackerrors_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, 0, .2);
472 
473  // Histograms to store the ToT Corrections, TIME RESIDUAL:
474  TH2F *tres_vs_ToT_trt = new TH2F("tres_vs_ToT_trt", "tres_vs_ToT_trt", 24, -0.5, 23.5, 200, -20, 20);
475  TH2F *tres_vs_ToT_ba = new TH2F("tres_vs_ToT_ba", "tres_vs_ToT_ba", 24, -0.5, 23.5, 200, -20, 20);
476  TH2F *tres_vs_ToT_bc = new TH2F("tres_vs_ToT_bc", "tres_vs_ToT_bc", 24, -0.5, 23.5, 200, -20, 20);
477  TH2F *tres_vs_ToT_ea = new TH2F("tres_vs_ToT_ea", "tres_vs_ToT_ea", 24, -0.5, 23.5, 200, -20, 20);
478  TH2F *tres_vs_ToT_ec = new TH2F("tres_vs_ToT_ec", "tres_vs_ToT_ec", 24, -0.5, 23.5, 200, -20, 20);
479 
480  // Residual:
481  TH2F *res_vs_ToT_trt = new TH2F("res_vs_ToT_trt", "res_vs_ToT_trt", 24, -0.5, 23.5, 200, -2, 2);
482  TH2F *res_vs_ToT_ba = new TH2F("res_vs_ToT_ba", "res_vs_ToT_ba", 24, -0.5, 23.5, 200, -2, 2);
483  TH2F *res_vs_ToT_bc = new TH2F("res_vs_ToT_bc", "res_vs_ToT_bc", 24, -0.5, 23.5, 200, -2, 2);
484  TH2F *res_vs_ToT_ea = new TH2F("res_vs_ToT_ea", "res_vs_ToT_ea", 24, -0.5, 23.5, 200, -2, 2);
485  TH2F *res_vs_ToT_ec = new TH2F("res_vs_ToT_ec", "res_vs_ToT_ec", 24, -0.5, 23.5, 200, -2, 2);
486 
487  // Histograms to store the HT Corrections, TIME RESIDUAL:
488  TH2F *tres_vs_HT_trt = new TH2F("tres_vs_HT_trt", "tres_vs_HT_trt", 2, -0.5, 1.5, 200, -20, 20);
489  TH2F *tres_vs_HT_ba = new TH2F("tres_vs_HT_ba", "tres_vs_HT_ba", 2, -0.5, 1.5, 200, -20, 20);
490  TH2F *tres_vs_HT_bc = new TH2F("tres_vs_HT_bc", "tres_vs_HT_bc", 2, -0.5, 1.5, 200, -20, 20);
491  TH2F *tres_vs_HT_ea = new TH2F("tres_vs_HT_ea", "tres_vs_HT_ea", 2, -0.5, 1.5, 200, -20, 20);
492  TH2F *tres_vs_HT_ec = new TH2F("tres_vs_HT_ec", "tres_vs_HT_ec", 2, -0.5, 1.5, 200, -20, 20);
493 
494  // Residual:
495  TH2F *res_vs_HT_trt = new TH2F("res_vs_HT_trt", "res_vs_HT_trt", 2, -0.5, 1.5, 200, -2, 2);
496  TH2F *res_vs_HT_ba = new TH2F("res_vs_HT_ba", "res_vs_HT_ba", 2, -0.5, 1.5, 200, -2, 2);
497  TH2F *res_vs_HT_bc = new TH2F("res_vs_HT_bc", "res_vs_HT_bc", 2, -0.5, 1.5, 200, -2, 2);
498  TH2F *res_vs_HT_ea = new TH2F("res_vs_HT_ea", "res_vs_HT_ea", 2, -0.5, 1.5, 200, -2, 2);
499  TH2F *res_vs_HT_ec = new TH2F("res_vs_HT_ec", "res_vs_HT_ec", 2, -0.5, 1.5, 200, -2, 2);
500 
501  // Histograms to store the sin(theta)/p Corrections, TIME RESIDUAL:
502  TH2F *tres_vs_SinOverP_trt = new TH2F("tres_vs_SinOverP_trt", "tres_vs_SinOverP_trt", 24, 0., 1., 200, -20., 20.);
503  TH2F *tres_vs_SinOverP_ba = new TH2F("tres_vs_SinOverP_ba", "tres_vs_SinOverP_ba", 24, 0., 1., 200, -20., 20.);
504  TH2F *tres_vs_SinOverP_bc = new TH2F("tres_vs_SinOverP_bc", "tres_vs_SinOverP_bc", 24, 0., 1., 200, -20., 20.);
505  TH2F *tres_vs_SinOverP_ea = new TH2F("tres_vs_SinOverP_ea", "tres_vs_SinOverP_ea", 24, 0., 1., 200, -20., 20.);
506  TH2F *tres_vs_SinOverP_ec = new TH2F("tres_vs_SinOverP_ec", "tres_vs_SinOverP_ec", 24, 0., 1., 200, -20., 20.);
507 
508  // Residual:
509  TH2F *res_vs_SinOverP_trt = new TH2F("res_vs_SinOverP_trt", "res_vs_SinOverP_trt", 24, 0., 1., 200, -2., 2.);
510  TH2F *res_vs_SinOverP_ba = new TH2F("res_vs_SinOverP_ba", "res_vs_SinOverP_ba", 24, 0., 1., 200, -2., 2.);
511  TH2F *res_vs_SinOverP_bc = new TH2F("res_vs_SinOverP_bc", "res_vs_SinOverP_bc", 24, 0., 1., 200, -2., 2.);
512  TH2F *res_vs_SinOverP_ea = new TH2F("res_vs_SinOverP_ea", "res_vs_SinOverP_ea", 24, 0., 1., 200, -2., 2.);
513  TH2F *res_vs_SinOverP_ec = new TH2F("res_vs_SinOverP_ec", "res_vs_SinOverP_ec", 24, 0., 1., 200, -2., 2.);
514 
515  // Histograms to store the sin(theta)/p Corrections, TIME RESIDUAL:
516  TH2F *tres_vs_CosOverP_trt = new TH2F("tres_vs_CosOverP_trt", "tres_vs_CosOverP_trt", 24, 0., 1., 200, -20., 20.);
517  TH2F *tres_vs_CosOverP_ba = new TH2F("tres_vs_CosOverP_ba", "tres_vs_CosOverP_ba", 24, 0., 1., 200, -20., 20.);
518  TH2F *tres_vs_CosOverP_bc = new TH2F("tres_vs_CosOverP_bc", "tres_vs_CosOverP_bc", 24, 0., 1., 200, -20., 20.);
519  TH2F *tres_vs_CosOverP_ea = new TH2F("tres_vs_CosOverP_ea", "tres_vs_CosOverP_ea", 24, 0., 1., 200, -20., 20.);
520  TH2F *tres_vs_CosOverP_ec = new TH2F("tres_vs_CosOverP_ec", "tres_vs_CosOverP_ec", 24, 0., 1., 200, -20., 20.);
521 
522  // Residual:
523  TH2F *res_vs_CosOverP_trt = new TH2F("res_vs_CosOverP_trt", "res_vs_CosOverP_trt", 24, 0., 1., 200, -2., 2.);
524  TH2F *res_vs_CosOverP_ba = new TH2F("res_vs_CosOverP_ba", "res_vs_CosOverP_ba", 24, 0., 1., 200, -2., 2.);
525  TH2F *res_vs_CosOverP_bc = new TH2F("res_vs_CosOverP_bc", "res_vs_CosOverP_bc", 24, 0., 1., 200, -2., 2.);
526  TH2F *res_vs_CosOverP_ea = new TH2F("res_vs_CosOverP_ea", "res_vs_CosOverP_ea", 24, 0., 1., 200, -2., 2.);
527  TH2F *res_vs_CosOverP_ec = new TH2F("res_vs_CosOverP_ec", "res_vs_CosOverP_ec", 24, 0., 1., 200, -2., 2.);
528 
529  // HISTOGRAMS FOR ARGON STRAWS!!!!
530  TH2F *resArhist_trt = new TH2F("residualAr_trt", "residualAr_trt", ntbins, mint, maxt, 100, -0.4, 0.4);
531  TH2F *resArhist_bar = new TH2F("residualAr_bar", "residualAr_bar", ntbins, mint, maxt, 100, -0.4, 0.4);
532  TH2F *resArhist1 = new TH2F("residualAr_1", "residualAr_1", ntbins, mint, maxt, 100, -0.4, 0.4);
533  TH2F *resArhist2 = new TH2F("residualAr_-1", "residualAr_-1", ntbins, mint, maxt, 100, -0.4, 0.4);
534  TH2F *resArhist3 = new TH2F("residualAr_2", "residualAr_2", ntbins, mint, maxt, 100, -0.4, 0.4);
535  TH2F *resArhist4 = new TH2F("residualAr_-2", "residualAr_-2", ntbins, mint, maxt, 100, -0.4, 0.4);
536 
537  TH2F *tresArhist_trt = new TH2F("timeresidualAr_trt", "timeresidualAr_trt", 50, mintres, maxtres, nrbins, minr, maxr);
538  TH2F *tresArhist_bar = new TH2F("timeresidualAr_bar", "timeresidualAr_bar", 50, mintres, maxtres, nrbins, minr, maxr);
539  TH2F *tresArhist1 = new TH2F("timeresidualAr_1", "timeresidualAr_1", 50, mintres, maxtres, nrbins, minr, maxr);
540  TH2F *tresArhist2 = new TH2F("timeresidualAr_-1", "timeresidualAr_-1", 50, mintres, maxtres, nrbins, minr, maxr);
541  TH2F *tresArhist3 = new TH2F("timeresidualAr_2", "timeresidualAr_2", 50, mintres, maxtres, nrbins, minr, maxr);
542  TH2F *tresArhist4 = new TH2F("timeresidualAr_-2", "timeresidualAr_-2", 50, mintres, maxtres, nrbins, minr, maxr);
543  // Histograms to do error study: Barrel/Ecs:
544 
545  // Pt dependent:
546  // Pull All hits:
547  TH2F *pullAr_trt = new TH2F("pullAr_trt", "pullAr_TRT_allhits", 16, 0, 16, 200, -4, 4);
548  TH2F *pullAr_ba = new TH2F("pullAr_ba", "pullAr_BarrelA_allhits", 16, 0, 16, 200, -4, 4);
549  TH2F *pullAr_bc = new TH2F("pullAr_bc", "pullAr_BarrelC_allhits", 16, 0, 16, 200, -4, 4);
550  TH2F *pullAr_ea = new TH2F("pullAr_ea", "pullAr_EndcapA_allhits", 16, 0, 16, 200, -4, 4);
551  TH2F *pullAr_ec = new TH2F("pullAr_ec", "pullAr_EndcapC_allhits", 16, 0, 16, 200, -4, 4);
552 
553  // Residual All hits:
554  TH2F *residualAr_trt = new TH2F("residualAr_allhits", "residualAr_TRT_allhits", 16, 0, 16, 200, -2, 2);
555  TH2F *residualAr_ba = new TH2F("residualAr_ba", "residualAr_BarrelA_allhits", 16, 0, 16, 200, -2, 2);
556  TH2F *residualAr_bc = new TH2F("residualAr_bc", "residualAr_BarrelC_allhits", 16, 0, 16, 200, -2, 2);
557  TH2F *residualAr_ea = new TH2F("residualAr_ea", "residualAr_EndcapA_allhits", 16, 0, 16, 200, -2, 2);
558  TH2F *residualAr_ec = new TH2F("residualAr_ec", "residualAr_EndcapC_allhits", 16, 0, 16, 200, -2, 2);
559 
560  // Time Residual All hits:
561  TH2F *tresidualAr_trt = new TH2F("tresidualAr_trt", "tresidualAr_TRT_allhits", 16, 0, 16, 200, -20, 20);
562  TH2F *tresidualAr_ba = new TH2F("tresidualAr_ba", "tresidualAr_BarrelA_allhits", 16, 0, 16, 200, -20, 20);
563  TH2F *tresidualAr_bc = new TH2F("tresidualAr_bc", "tresidualAr_BarrelC_allhits", 16, 0, 16, 200, -20, 20);
564  TH2F *tresidualAr_ea = new TH2F("tresidualAr_ea", "tresidualAr_EndcapA_allhits", 16, 0, 16, 200, -20, 20);
565  TH2F *tresidualAr_ec = new TH2F("tresidualAr_ec", "tresidualAr_EndcapC_allhits", 16, 0, 16, 200, -20, 20);
566 
567  // Pull Precision hits:
568  TH2F *pullAr_trtP = new TH2F("pullAr_trtP", "pullAr_TRT_Phits", 16, 0, 16, 200, -4, 4);
569  TH2F *pullAr_baP = new TH2F("pullAr_baP", "pullAr_BarrelA_Phits", 16, 0, 16, 200, -4, 4);
570  TH2F *pullAr_bcP = new TH2F("pullAr_bcP", "pullAr_BarrelC_Phits", 16, 0, 16, 200, -4, 4);
571  TH2F *pullAr_eaP = new TH2F("pullAr_eaP", "pullAr_EndcapA_Phits", 16, 0, 16, 200, -4, 4);
572  TH2F *pullAr_ecP = new TH2F("pullAr_ecP", "pullAr_EndcapC_Phits", 16, 0, 16, 200, -4, 4);
573  // Residaul Precision hits:
574  TH2F *residualAr_trtP = new TH2F("residualAr_trtP", "residualAr_TRT_Phits", 16, 0, 16, 200, -2, 2);
575  TH2F *residualAr_baP = new TH2F("residualAr_baP", "residualAr_BarrelA_Phits", 16, 0, 16, 200, -2, 2);
576  TH2F *residualAr_bcP = new TH2F("residualAr_bcP", "residualAr_BarrelC_Phits", 16, 0, 16, 200, -2, 2);
577  TH2F *residualAr_eaP = new TH2F("residualAr_eaP", "residualAr_EndcapA_Phits", 16, 0, 16, 200, -2, 2);
578  TH2F *residualAr_ecP = new TH2F("residualAr_ecP", "residualAr_EndcapC_Phits", 16, 0, 16, 200, -2, 2);
579  // Residaul Precision hits:
580  TH2F *tresidualAr_trtP = new TH2F("tresidualAr_trtP", "residualAr_TRT_Phits", 16, 0, 16, 200, -20, 20);
581  TH2F *tresidualAr_baP = new TH2F("tresidualAr_baP", "residualAr_BarrelA_Phits", 16, 0, 16, 200, -20, 20);
582  TH2F *tresidualAr_bcP = new TH2F("tresidualAr_bcP", "residualAr_BarrelC_Phits", 16, 0, 16, 200, -20, 20);
583  TH2F *tresidualAr_eaP = new TH2F("tresidualAr_eaP", "residualAr_EndcapA_Phits", 16, 0, 16, 200, -20, 20);
584  TH2F *tresidualAr_ecP = new TH2F("tresidualAr_ecP", "residualAr_EndcapC_Phits", 16, 0, 16, 200, -20, 20);
585  // Track Errors :
586  TH2F *trackerrorsAr_trtP = new TH2F("trackerrorsAr_trt", "trackerrorsAr_vs_pt_trt", 16, 0, 16, 200, 0, 0.2);
587  TH2F *trackerrorsAr_baP = new TH2F("trackerrorsAr_ba", "trackerrorsAr_vs_pt_BarrelA", 16, 0, 16, 200, 0, .2);
588  TH2F *trackerrorsAr_bcP = new TH2F("trackerrorsAr_bc", "trackerrorsAr_vs_pt_BarrelC", 16, 0, 16, 200, 0, .2);
589  TH2F *trackerrorsAr_eaP = new TH2F("trackerrorsAr_ea", "trackerrorsAr_vs_pt_EndcapA", 16, 0, 16, 200, 0, .2);
590  TH2F *trackerrorsAr_ecP = new TH2F("trackerrorsAr_ec", "trackerrorsAr_vs_pt_EndcapC", 16, 0, 16, 200, 0, .2);
591 
592  // Time Bin Dependent:
593 
594  // TH2 to Store the Pull vs width:
595  TH2F *pullAr_vs_tb_trt = new TH2F("pullAr_vs_tb_trt", "pullAr_vs_timebin_trt", ntbins2, tmin, tmax, 200, -4, 4);
596  TH2F *pullAr_vs_tb_ba = new TH2F("pullAr_vs_tb_ba", "pullAr_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, -4, 4);
597  TH2F *pullAr_vs_tb_bc = new TH2F("pullAr_vs_tb_bc", "pullAr_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, -4, 4);
598  TH2F *pullAr_vs_tb_ea = new TH2F("pullAr_vs_tb_ea", "pullAr_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, -4, 4);
599  TH2F *pullAr_vs_tb_ec = new TH2F("pullAr_vs_tb_ec", "pullAr_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, -4, 4);
600 
601  // TH2 to Store the ErrorsUsed vs width:
602  TH2F *errorsAr_vs_tb_trt = new TH2F("errorsAr_vs_tb_trt", "errorsAr_vs_timebin_trt", ntbins2, tmin, tmax, 200, 0, 0.4);
603  TH2F *errorsAr_vs_tb_ba = new TH2F("errorsAr_vs_tb_ba", "errorsAr_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, 0, 0.4);
604  TH2F *errorsAr_vs_tb_bc = new TH2F("errorsAr_vs_tb_bc", "errorsAr_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, 0, 0.4);
605  TH2F *errorsAr_vs_tb_ea = new TH2F("errorsAr_vs_tb_ea", "errorsAr_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, 0, 0.4);
606  TH2F *errorsAr_vs_tb_ec = new TH2F("errorsAr_vs_tb_ec", "errorsAr_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, 0, 0.4);
607 
608  // TH2 to Store the ErrorsUsed vs width:
609  TH2F *residualAr_vs_tb_trt = new TH2F("residualAr_vs_tb_trt", "residualAr_vs_timebin_trt", ntbins2, tmin, tmax, 200, -2, .2);
610  TH2F *residualAr_vs_tb_ba = new TH2F("residualAr_vs_tb_ba", "residualAr_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, -2, .2);
611  TH2F *residualAr_vs_tb_bc = new TH2F("residualAr_vs_tb_bc", "residualAr_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, -2, .2);
612  TH2F *residualAr_vs_tb_ea = new TH2F("residualAr_vs_tb_ea", "residualAr_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, -2, .2);
613  TH2F *residualAr_vs_tb_ec = new TH2F("residualAr_vs_tb_ec", "residualAr_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, -2, .2);
614 
615  // TH2 to Store the Track Errors vs width:
616  TH2F *trackerrorsAr_vs_tb_trt = new TH2F("trackerrorsAr_vs_tb_trt", "trackerrorsAr_vs_timebin_trt", ntbins2, tmin, tmax, 200, 0, 0.2);
617  TH2F *trackerrorsAr_vs_tb_ba = new TH2F("trackerrorsAr_vs_tb_ba", "trackerrorsAr_vs_timebin_BarrelA", ntbins2, tmin, tmax, 200, 0, .2);
618  TH2F *trackerrorsAr_vs_tb_bc = new TH2F("trackerrorsAr_vs_tb_bc", "trackerrorsAr_vs_timebin_BarrelC", ntbins2, tmin, tmax, 200, 0, .2);
619  TH2F *trackerrorsAr_vs_tb_ea = new TH2F("trackerrorsAr_vs_tb_ea", "trackerrorsAr_vs_timebin_EndcapA", ntbins2, tmin, tmax, 200, 0, .2);
620  TH2F *trackerrorsAr_vs_tb_ec = new TH2F("trackerrorsAr_vs_tb_ec", "trackerrorsAr_vs_timebin_EndcapC", ntbins2, tmin, tmax, 200, 0, .2);
621 
622  // Histograms to store the ToT Corrections, TIME RESIDUAL:
623  TH2F *tresAr_vs_ToT_trt = new TH2F("tresAr_vs_ToT_trt", "tresAr_vs_ToT_trt", 24, -0.5, 23.5, 200, -20, 20);
624  TH2F *tresAr_vs_ToT_ba = new TH2F("tresAr_vs_ToT_ba", "tresAr_vs_ToT_ba", 24, -0.5, 23.5, 200, -20, 20);
625  TH2F *tresAr_vs_ToT_bc = new TH2F("tresAr_vs_ToT_bc", "tresAr_vs_ToT_bc", 24, -0.5, 23.5, 200, -20, 20);
626  TH2F *tresAr_vs_ToT_ea = new TH2F("tresAr_vs_ToT_ea", "tresAr_vs_ToT_ea", 24, -0.5, 23.5, 200, -20, 20);
627  TH2F *tresAr_vs_ToT_ec = new TH2F("tresAr_vs_ToT_ec", "tresAr_vs_ToT_ec", 24, -0.5, 23.5, 200, -20, 20);
628 
629  // Residual:
630  TH2F *resAr_vs_ToT_trt = new TH2F("resAr_vs_ToT_trt", "resAr_vs_ToT_trt", 24, -0.5, 23.5, 200, -2, 2);
631  TH2F *resAr_vs_ToT_ba = new TH2F("resAr_vs_ToT_ba", "resAr_vs_ToT_ba", 24, -0.5, 23.5, 200, -2, 2);
632  TH2F *resAr_vs_ToT_bc = new TH2F("resAr_vs_ToT_bc", "resAr_vs_ToT_bc", 24, -0.5, 23.5, 200, -2, 2);
633  TH2F *resAr_vs_ToT_ea = new TH2F("resAr_vs_ToT_ea", "resAr_vs_ToT_ea", 24, -0.5, 23.5, 200, -2, 2);
634  TH2F *resAr_vs_ToT_ec = new TH2F("resAr_vs_ToT_ec", "resAr_vs_ToT_ec", 24, -0.5, 23.5, 200, -2, 2);
635 
636  // Histograms to store the HT Corrections, TIME RESIDUAL:
637  TH2F *tresAr_vs_HT_trt = new TH2F("tresAr_vs_HT_trt", "tresAr_vs_HT_trt", 2, -0.5, 1.5, 200, -20, 20);
638  TH2F *tresAr_vs_HT_ba = new TH2F("tresAr_vs_HT_ba", "tresAr_vs_HT_ba", 2, -0.5, 1.5, 200, -20, 20);
639  TH2F *tresAr_vs_HT_bc = new TH2F("tresAr_vs_HT_bc", "tresAr_vs_HT_bc", 2, -0.5, 1.5, 200, -20, 20);
640  TH2F *tresAr_vs_HT_ea = new TH2F("tresAr_vs_HT_ea", "tresAr_vs_HT_ea", 2, -0.5, 1.5, 200, -20, 20);
641  TH2F *tresAr_vs_HT_ec = new TH2F("tresAr_vs_HT_ec", "tresAr_vs_HT_ec", 2, -0.5, 1.5, 200, -20, 20);
642 
643  // Residual:
644  TH2F *resAr_vs_HT_trt = new TH2F("resAr_vs_HT_trt", "resAr_vs_HT_trt", 2, -0.5, 1.5, 200, -2, 2);
645  TH2F *resAr_vs_HT_ba = new TH2F("resAr_vs_HT_ba", "resAr_vs_HT_ba", 2, -0.5, 1.5, 200, -2, 2);
646  TH2F *resAr_vs_HT_bc = new TH2F("resAr_vs_HT_bc", "resAr_vs_HT_bc", 2, -0.5, 1.5, 200, -2, 2);
647  TH2F *resAr_vs_HT_ea = new TH2F("resAr_vs_HT_ea", "resAr_vs_HT_ea", 2, -0.5, 1.5, 200, -2, 2);
648  TH2F *resAr_vs_HT_ec = new TH2F("resAr_vs_HT_ec", "resAr_vs_HT_ec", 2, -0.5, 1.5, 200, -2, 2);
649 
650  // Histograms to store the sin(theta)/p Corrections, TIME RESIDUAL:
651  TH2F *tresAr_vs_SinOverP_trt = new TH2F("tresAr_vs_SinOverP_trt", "tresAr_vs_SinOverP_trt", 24, 0., 1., 200, -20., 20.);
652  TH2F *tresAr_vs_SinOverP_ba = new TH2F("tresAr_vs_SinOverP_ba", "tresAr_vs_SinOverP_ba", 24, 0., 1., 200, -20., 20.);
653  TH2F *tresAr_vs_SinOverP_bc = new TH2F("tresAr_vs_SinOverP_bc", "tresAr_vs_SinOverP_bc", 24, 0., 1., 200, -20., 20.);
654  TH2F *tresAr_vs_SinOverP_ea = new TH2F("tresAr_vs_SinOverP_ea", "tresAr_vs_SinOverP_ea", 24, 0., 1., 200, -20., 20.);
655  TH2F *tresAr_vs_SinOverP_ec = new TH2F("tresAr_vs_SinOverP_ec", "tresAr_vs_SinOverP_ec", 24, 0., 1., 200, -20., 20.);
656 
657  // Residual:
658  TH2F *resAr_vs_SinOverP_trt = new TH2F("resAr_vs_SinOverP_trt", "resAr_vs_SinOverP_trt", 24, 0., 1., 200, -2., 2.);
659  TH2F *resAr_vs_SinOverP_ba = new TH2F("resAr_vs_SinOverP_ba", "resAr_vs_SinOverP_ba", 24, 0., 1., 200, -2., 2.);
660  TH2F *resAr_vs_SinOverP_bc = new TH2F("resAr_vs_SinOverP_bc", "resAr_vs_SinOverP_bc", 24, 0., 1., 200, -2., 2.);
661  TH2F *resAr_vs_SinOverP_ea = new TH2F("resAr_vs_SinOverP_ea", "resAr_vs_SinOverP_ea", 24, 0., 1., 200, -2., 2.);
662  TH2F *resAr_vs_SinOverP_ec = new TH2F("resAr_vs_SinOverP_ec", "resAr_vs_SinOverP_ec", 24, 0., 1., 200, -2., 2.);
663 
664  // Histograms to store the sin(theta)/p Corrections, TIME RESIDUAL:
665  TH2F *tresAr_vs_CosOverP_trt = new TH2F("tresAr_vs_CosOverP_trt", "tresAr_vs_CosOverP_trt", 24, 0., 1., 200, -20., 20.);
666  TH2F *tresAr_vs_CosOverP_ba = new TH2F("tresAr_vs_CosOverP_ba", "tresAr_vs_CosOverP_ba", 24, 0., 1., 200, -20., 20.);
667  TH2F *tresAr_vs_CosOverP_bc = new TH2F("tresAr_vs_CosOverP_bc", "tresAr_vs_CosOverP_bc", 24, 0., 1., 200, -20., 20.);
668  TH2F *tresAr_vs_CosOverP_ea = new TH2F("tresAr_vs_CosOverP_ea", "tresAr_vs_CosOverP_ea", 24, 0., 1., 200, -20., 20.);
669  TH2F *tresAr_vs_CosOverP_ec = new TH2F("tresAr_vs_CosOverP_ec", "tresAr_vs_CosOverP_ec", 24, 0., 1., 200, -20., 20.);
670 
671  // Residual:
672  TH2F *resAr_vs_CosOverP_trt = new TH2F("resAr_vs_CosOverP_trt", "resAr_vs_CosOverP_trt", 24, 0., 1., 200, -2., 2.);
673  TH2F *resAr_vs_CosOverP_ba = new TH2F("resAr_vs_CosOverP_ba", "resAr_vs_CosOverP_ba", 24, 0., 1., 200, -2., 2.);
674  TH2F *resAr_vs_CosOverP_bc = new TH2F("resAr_vs_CosOverP_bc", "resAr_vs_CosOverP_bc", 24, 0., 1., 200, -2., 2.);
675  TH2F *resAr_vs_CosOverP_ea = new TH2F("resAr_vs_CosOverP_ea", "resAr_vs_CosOverP_ea", 24, 0., 1., 200, -2., 2.);
676  TH2F *resAr_vs_CosOverP_ec = new TH2F("resAr_vs_CosOverP_ec", "resAr_vs_CosOverP_ec", 24, 0., 1., 200, -2., 2.);
677 
678  // for (map<string,calibpars>::iterator iot=pt0map.begin(); iot!=pt0map.end(); iot++) {
679  // cout << iot->second.t0 << " " << iot->second.dt0 << endl;
680  // }
681 
682  //*********************************************************************
683  // FILE LOOP
684  for (int ifiles = 0; ifiles < nfiles; ifiles++)
685  {
686  //*********************************************************************
687 
688  bool isntuple = false;
689  char filetype[5];
690  ifstream myFile(argv[ifiles + 2], ios::in | ios::binary);
691  if (myFile.is_open())
692  {
693  myFile.read((char *)filetype, 4);
694  filetype[4] = 0;
695  if (strcmp(filetype, "root") == 0)
696  isntuple = true;
697  // if (strcmp(filetype,"bina")==0) return 3;
698  myFile.close();
699  }
700  else
701  {
702  std::cerr << "WRONG INPUT FILE!\n";
703  return -1;
704  }
705 
706  //*********************************************************************
707  // SCANNING ROOT FILE
708  if (isntuple)
709  {
710  //*********************************************************************
711 
712  nhistsadd = 0;
713 
714  TFile *ntfile = new TFile(argv[ifiles + 2]);
715  TNtuple *hittuple = (TNtuple *)ntfile->Get("ntuple");
716 
717  hittuple->SetBranchAddress("run", &run);
718  hittuple->SetBranchAddress("evt", &evt);
719  hittuple->SetBranchAddress("trk", &trk);
720  hittuple->SetBranchAddress("det", &det);
721  hittuple->SetBranchAddress("lay", &lay);
722  hittuple->SetBranchAddress("mod", &mod);
723  hittuple->SetBranchAddress("brd", &brd);
724  hittuple->SetBranchAddress("chp", &chp);
725  hittuple->SetBranchAddress("sid", &fsid);
726  hittuple->SetBranchAddress("stl", &stl);
727  hittuple->SetBranchAddress("stw", &stw);
728  hittuple->SetBranchAddress("r", &r);
729  hittuple->SetBranchAddress("dr", &dr);
730  hittuple->SetBranchAddress("dr", &dr);
731  hittuple->SetBranchAddress("t", &t);
732  hittuple->SetBranchAddress("t0", &t0);
733  // hittuple->SetBranchAddress("rtrack",&rtrack);
734  // hittuple->SetBranchAddress("ttrack",&ttrack);
735  hittuple->SetBranchAddress("rtrackunbias", &rtrack);
736  hittuple->SetBranchAddress("drrtrackunbias", &drtrack);
737  hittuple->SetBranchAddress("ttrackunbias", &ttrack);
738  hittuple->SetBranchAddress("ephase", &ephase);
739 
740  if (hittuple->GetListOfBranches()->FindObject("theta"))
741  {
742  hittuple->SetBranchAddress("theta", &theta);
743  }
744  if (hittuple->GetListOfBranches()->FindObject("phi"))
745  {
746  hittuple->SetBranchAddress("phi", &phi);
747  }
748  if (hittuple->GetListOfBranches()->FindObject("d0"))
749  {
750  hittuple->SetBranchAddress("d0", &d0);
751  }
752  if (hittuple->GetListOfBranches()->FindObject("pt"))
753  {
754  hittuple->SetBranchAddress("pt", &pt);
755  }
756  if (hittuple->GetListOfBranches()->FindObject("ToT"))
757  {
758  hittuple->SetBranchAddress("ToT", &ToT);
759  }
760  else
761  ToT = 0;
762  if (hittuple->GetListOfBranches()->FindObject("HT"))
763  {
764  hittuple->SetBranchAddress("HT", &HT);
765  }
766  else
767  HT = 0;
768  if (hittuple->GetListOfBranches()->FindObject("qoverp"))
769  {
770  hittuple->SetBranchAddress("qoverp", &qoverp);
771  }
772  else
773  qoverp = 0;
774 
775  if (hittuple->GetListOfBranches()->FindObject("isArgonStraw"))
776  {
777  hittuple->SetBranchAddress("isArgonStraw", &isArgonStraw);
778  }
779  else
780  isArgonStraw = 0;
781 
782  int nevents;
783  int npt0 = 0;
784  float diffpt0 = 0;
785  nevents = hittuple->GetEntries();
786 
787  cout << "SCANNING ROOT FILE " << argv[ifiles + 2] << " (" << nevents << " HITS)" << endl;
788 
789  //*********************************************************************
790  // EVENT LOOP
791  for (int ievt = 0; ievt < nevents; ievt++)
792  {
793  // for (int ievt=25000000;ievt<nevents;ievt++){
794  // for (int ievt=0;ievt<2000100;ievt++){
795  // for (int ievt=0;ievt<1000;ievt++){
796  //*********************************************************************
797 
798  hittuple->GetEntry(ievt);
799 
800  if (dr < 1.0)
801  { // event selection
802  // if (true){ //event selection
803 
804  nhits++;
805 
806  string trkkey = string(Form("_%i_%i_%i", (int)run, (int)evt, (int)trk));
807 
808  string pt0key = string(Form("_%i_%i_%i_%i_%i", (int)det, (int)lay, (int)mod, (int)stl, (int)stw));
809  if (pt0map.find(pt0key) != pt0map.end())
810  {
811  diffpt0 += fabs(t0 - pt0map[string(Form("_%i_%i_%i_%i_%i", (int)det, (int)lay, (int)mod, (int)stl, (int)stw))].t0);
812  t0 = pt0map[string(Form("_%i_%i_%i_%i_%i", (int)det, (int)lay, (int)mod, (int)stl, (int)stw))].t0;
813  npt0++;
814  // cout << string(Form("_%i_%i_%i_%i_%i",(int)det,(int)lay,(int)mod,(int)stl,(int)stw)) << " " << t0 << " -> " << pt0map[string(Form("_%i_%i_%i_%i_%i",(int)det,(int)lay,(int)mod,(int)stl,(int)stw))].t0 << endl;
815  }
816 
817  if (trackmap.find(trkkey) == trackmap.end())
818  {
819  trackmap[trkkey].run = run;
820  trackmap[trkkey].event = evt;
821  trackmap[trkkey].track = trk;
822  trackmap[trkkey].epnew = (t + ephase) - t0 - ttrack;
823  trackmap[trkkey].epold = ephase;
824  trackmap[trkkey].nhits = 1.0;
825  trackmap[trkkey].t = t;
826  trackmap[trkkey].ttrack = ttrack;
827  trackmap[trkkey].t0 = t0;
828  trackmap[trkkey].theta = theta;
829  trackmap[trkkey].phi = phi;
830  trackmap[trkkey].d0 = d0;
831  trackmap[trkkey].pt = pt;
832  trackmap[trkkey].trackres = (r - rtrack) * (r - rtrack);
833  trackmap[trkkey].trackresMean = (r - rtrack);
834  }
835  else
836  {
837  trackmap[trkkey].epnew += (t + ephase) - t0 - ttrack;
838  trackmap[trkkey].t += t;
839  trackmap[trkkey].ttrack += ttrack;
840  trackmap[trkkey].t0 += t0;
841  trackmap[trkkey].nhits++;
842  trackmap[trkkey].trackres += (r - rtrack) * (r - rtrack);
843  trackmap[trkkey].trackresMean += (r - rtrack);
844  }
845  sid = (int)fsid;
846 
847  short tresbin = Simple1dHist(mintres, maxtres, ntresbins, t - ttrack - t0 + ephase);
848  short rresbin = Simple1dHist(minres, maxres, nresbins, r - rtrack);
849  short trbin = Simple2dHist(mint, maxt, ntbins, minr, maxr, nrbins, t - t0 + ephase, fabs(rtrack));
850 
851  if ((int)det == -2 && (int)lay == 0 && (int)mod == 0 && (int)brd == 1)
852  residual_ref->Fill(r - rtrack);
853  if ((int)det == 1 && (int)lay == 0 && (int)mod == 0 && (int)brd == 0 && (int)chp == 1)
854  timeresidual_ref->Fill(t - ttrack - t0 + ephase);
855  if ((int)det == -1 && (int)lay == 2)
856  rt_ref->Fill(t - t0 + ephase, fabs(rtrack));
857  if ((int)det == -1)
858  rt_ref2->Fill(t - t0 + ephase, fabs(rtrack));
859 
860  if (histmap.find(sid) == histmap.end())
861  {
862  nhistsadd++;
863  nhists++;
864  histmap[sid] = new CalHist();
865  }
866  if (tresbin >= 0)
867  {
868  nbinsadd += histmap[sid]->IncreaseBin(tresbin, 1);
869  ntres++;
870  }
871  if (rresbin >= 0)
872  {
873  nbinsadd += histmap[sid]->IncreaseBin(rresbin + 100, 1);
874  nres++;
875  }
876  if (trbin >= 0)
877  {
878  nbinsadd += histmap[sid]->IncreaseBin(trbin + 200, 1);
879  nrt++;
880  }
881 
882  if (histmap[sid]->maxvalue > maxvalue)
883  maxvalue = histmap[sid]->maxvalue;
884 
885  if ((nhits % 1000000 == 0) | (ievt == nevents - 1))
886  {
887  process_mem_usage(vm, rss);
888  // cppcheck-suppress invalidPrintfArgType_uint
889  printf("%8i HITS READ, %8i HISTOGRAMS (%8lu ADDED), %8i BINS ADDED, MAXVALUE: %3i, VM: %8.0f, RSS: %8.0f\n", nhits, nhists, histmap.size() - nhiststmp, nbinsadd, maxvalue, vm, rss);
890  nhiststmp = histmap.size();
891  // nhistsadd=0;
892  nbinsadd = 0;
893  }
894 
895  if (nhits % 20000000 == 0)
896  {
897  dump_hists(&histmap, ntbins, nrbins, ntres, argv[1], 0);
898  for (map<int, CalHist *>::iterator it = histmap.begin(); it != histmap.end(); ++it)
899  {
900  delete it->second;
901  }
902  histmap.clear();
903  dump_tracktuple(&trackmap);
904  trackmap.clear();
905  nhiststmp = 0;
906  maxvalue = 0;
907  }
908 
909  if (isArgonStraw == 0)
910  { // ONLY STORE THE XENON CIRCLES:
911  reshist_trt->Fill(t - t0, fabs(r) - fabs(rtrack));
912  if ((int)det == -2)
913  reshist1->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
914  if ((int)det == -1)
915  reshist2->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
916  if ((int)det == 1)
917  reshist3->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
918  if ((int)det == 2)
919  reshist4->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
920  if (abs((int)det) == 1)
921  reshist_bar->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
922 
923  treshist_trt->Fill(t - t0 - ttrack, fabs(rtrack));
924  if ((int)det == -2)
925  treshist1->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
926  if ((int)det == -1)
927  treshist2->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
928  if ((int)det == 1)
929  treshist3->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
930  if ((int)det == 2)
931  treshist4->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
932  if (abs((int)det) == 1)
933  treshist_bar->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
934 
935  float residual = r - rtrack;
936  // float timebin = int((t-t0 + ephase)/3.125 );
937  float time = t - t0 + ephase;
938  float pull = (r - rtrack) / TMath::Sqrt(dr * dr + drtrack * drtrack);
939  float tresidual = t - t0 - ttrack + ephase;
940 
941  ToT = ToT / 3.125;
942 
943  float sinoverp = 0.0;
944  float cosoverp = 0.0;
945  if (pt != 0.0)
946  {
947  sinoverp = 1000. * sin(theta) * sin(theta) / pt;
948  cosoverp = 1000. * cos(theta) * cos(theta) / pt;
949  }
950 
951  float ppt = pt / 1000.;
952  if (ppt > 16)
953  ppt = 15.5;
954 
955  tres_vs_ToT_trt->Fill(ToT, tresidual);
956  res_vs_ToT_trt->Fill(ToT, residual);
957  tres_vs_HT_trt->Fill(HT, tresidual);
958  res_vs_HT_trt->Fill(HT, residual);
959  tres_vs_SinOverP_trt->Fill(sinoverp, tresidual);
960  res_vs_SinOverP_trt->Fill(sinoverp, residual);
961  tres_vs_CosOverP_trt->Fill(cosoverp, tresidual);
962  res_vs_CosOverP_trt->Fill(cosoverp, residual);
963 
964  pull_trtP->Fill(ppt, pull);
965  residual_trtP->Fill(ppt, residual);
966  tresidual_trtP->Fill(ppt, tresidual);
967  trackerrors_trtP->Fill(ppt, drtrack);
968  if (ppt > ptcutforerrors)
969  pull_vs_tb_trt->Fill(time, pull);
970  if (ppt > ptcutforerrors)
971  errors_vs_tb_trt->Fill(time, dr);
972  if (ppt > ptcutforerrors)
973  trackerrors_vs_tb_trt->Fill(time, drtrack);
974  if (ppt > ptcutforerrors)
975  residual_vs_tb_trt->Fill(time, residual);
976 
977  if ((int)det == -2)
978  {
979  tres_vs_ToT_ea->Fill(ToT, tresidual);
980  res_vs_ToT_ea->Fill(ToT, residual);
981  tres_vs_HT_ea->Fill(HT, tresidual);
982  res_vs_HT_ea->Fill(HT, residual);
983  tres_vs_SinOverP_ea->Fill(sinoverp, tresidual);
984  res_vs_SinOverP_ea->Fill(sinoverp, residual);
985  tres_vs_CosOverP_ea->Fill(cosoverp, tresidual);
986  res_vs_CosOverP_ea->Fill(cosoverp, residual);
987 
988  pull_eaP->Fill(ppt, pull);
989  residual_eaP->Fill(ppt, residual);
990  tresidual_eaP->Fill(ppt, tresidual);
991  trackerrors_eaP->Fill(ppt, drtrack);
992  if (ppt > ptcutforerrors)
993  pull_vs_tb_ea->Fill(time, pull);
994  if (ppt > ptcutforerrors)
995  errors_vs_tb_ea->Fill(time, dr);
996  if (ppt > ptcutforerrors)
997  trackerrors_vs_tb_ea->Fill(time, drtrack);
998  if (ppt > ptcutforerrors)
999  residual_vs_tb_ea->Fill(time, residual);
1000  }
1001  if ((int)det == 2)
1002  {
1003  tres_vs_ToT_ec->Fill(ToT, tresidual);
1004  res_vs_ToT_ec->Fill(ToT, residual);
1005  tres_vs_HT_ec->Fill(HT, tresidual);
1006  res_vs_HT_ec->Fill(HT, residual);
1007  tres_vs_SinOverP_ec->Fill(sinoverp, tresidual);
1008  res_vs_SinOverP_ec->Fill(sinoverp, residual);
1009  tres_vs_CosOverP_ec->Fill(cosoverp, tresidual);
1010  res_vs_CosOverP_ec->Fill(cosoverp, residual);
1011 
1012  pull_ecP->Fill(ppt, pull);
1013  residual_ecP->Fill(ppt, residual);
1014  tresidual_ecP->Fill(ppt, tresidual);
1015  trackerrors_ecP->Fill(ppt, drtrack);
1016  if (ppt > ptcutforerrors)
1017  pull_vs_tb_ec->Fill(time, pull);
1018  if (ppt > ptcutforerrors)
1019  errors_vs_tb_ec->Fill(time, dr);
1020  if (ppt > ptcutforerrors)
1021  trackerrors_vs_tb_ec->Fill(time, drtrack);
1022  if (ppt > ptcutforerrors)
1023  residual_vs_tb_ec->Fill(time, residual);
1024  }
1025  if ((int)det == -1)
1026  {
1027  tres_vs_ToT_ba->Fill(ToT, tresidual);
1028  res_vs_ToT_ba->Fill(ToT, residual);
1029  tres_vs_HT_ba->Fill(HT, tresidual);
1030  res_vs_HT_ba->Fill(HT, residual);
1031  tres_vs_SinOverP_ba->Fill(sinoverp, tresidual);
1032  res_vs_SinOverP_ba->Fill(sinoverp, residual);
1033  tres_vs_CosOverP_ba->Fill(cosoverp, tresidual);
1034  res_vs_CosOverP_ba->Fill(cosoverp, residual);
1035 
1036  pull_baP->Fill(ppt, pull);
1037  residual_baP->Fill(ppt, residual);
1038  tresidual_baP->Fill(ppt, tresidual);
1039  trackerrors_baP->Fill(ppt, drtrack);
1040  if (ppt > ptcutforerrors)
1041  pull_vs_tb_ba->Fill(time, pull);
1042  if (ppt > ptcutforerrors)
1043  errors_vs_tb_ba->Fill(time, dr);
1044  if (ppt > ptcutforerrors)
1045  trackerrors_vs_tb_ba->Fill(time, drtrack);
1046  if (ppt > ptcutforerrors)
1047  residual_vs_tb_ba->Fill(time, residual);
1048  }
1049  if ((int)det == 1)
1050  {
1051  tres_vs_ToT_bc->Fill(ToT, tresidual);
1052  res_vs_ToT_bc->Fill(ToT, residual);
1053  tres_vs_HT_bc->Fill(HT, tresidual);
1054  res_vs_HT_bc->Fill(HT, residual);
1055  tres_vs_SinOverP_bc->Fill(sinoverp, tresidual);
1056  res_vs_SinOverP_bc->Fill(sinoverp, residual);
1057  tres_vs_CosOverP_bc->Fill(cosoverp, tresidual);
1058  res_vs_CosOverP_bc->Fill(cosoverp, residual);
1059 
1060  pull_bcP->Fill(ppt, pull);
1061  residual_bcP->Fill(ppt, residual);
1062  tresidual_bcP->Fill(ppt, tresidual);
1063  trackerrors_bcP->Fill(ppt, drtrack);
1064  if (ppt > ptcutforerrors)
1065  pull_vs_tb_bc->Fill(time, pull);
1066  if (ppt > ptcutforerrors)
1067  errors_vs_tb_bc->Fill(time, dr);
1068  if (ppt > ptcutforerrors)
1069  trackerrors_vs_tb_bc->Fill(time, drtrack);
1070  if (ppt > ptcutforerrors)
1071  residual_vs_tb_bc->Fill(time, residual);
1072  }
1073  }
1074  else
1075  { // DUMP THE ARGON PART:
1076 
1077  existAr = true;
1078 
1079  resArhist_trt->Fill(t - t0, fabs(r) - fabs(rtrack));
1080  if ((int)det == -2)
1081  resArhist1->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
1082  if ((int)det == -1)
1083  resArhist2->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
1084  if ((int)det == 1)
1085  resArhist3->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
1086  if ((int)det == 2)
1087  resArhist4->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
1088  if (abs((int)det) == 1)
1089  resArhist_bar->Fill(t - t0 + ephase, fabs(r) - fabs(rtrack));
1090 
1091  tresArhist_trt->Fill(t - t0 - ttrack, fabs(rtrack));
1092  if ((int)det == -2)
1093  tresArhist1->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
1094  if ((int)det == -1)
1095  tresArhist2->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
1096  if ((int)det == 1)
1097  tresArhist3->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
1098  if ((int)det == 2)
1099  tresArhist4->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
1100  if (abs((int)det) == 1)
1101  tresArhist_bar->Fill(t - t0 - ttrack + ephase, fabs(rtrack));
1102 
1103  float residual = r - rtrack;
1104  // float timebin = int((t-t0 + ephase)/3.125 );
1105  float time = t - t0 + ephase;
1106  float pull = (r - rtrack) / TMath::Sqrt(dr * dr + drtrack * drtrack);
1107  float tresidual = t - t0 - ttrack + ephase;
1108 
1109  ToT = ToT / 3.125;
1110  float sinoverp = 0.0;
1111  float cosoverp = 0.0;
1112  if (pt != 0.0)
1113  {
1114  sinoverp = 1000. * sin(theta) * sin(theta) / pt;
1115  cosoverp = 1000. * cos(theta) * cos(theta) / pt;
1116  }
1117  float ppt = pt / 1000.;
1118  if (ppt > 16)
1119  ppt = 15.5;
1120 
1121  tresAr_vs_ToT_trt->Fill(ToT, tresidual);
1122  resAr_vs_ToT_trt->Fill(ToT, residual);
1123  tresAr_vs_HT_trt->Fill(HT, tresidual);
1124  resAr_vs_HT_trt->Fill(HT, residual);
1125  tresAr_vs_SinOverP_trt->Fill(sinoverp, tresidual);
1126  resAr_vs_SinOverP_trt->Fill(sinoverp, residual);
1127  tresAr_vs_CosOverP_trt->Fill(cosoverp, tresidual);
1128  resAr_vs_CosOverP_trt->Fill(cosoverp, residual);
1129 
1130  pullAr_trtP->Fill(ppt, pull);
1131  residualAr_trtP->Fill(ppt, residual);
1132  tresidualAr_trtP->Fill(ppt, tresidual);
1133  trackerrorsAr_trtP->Fill(ppt, drtrack);
1134  if (ppt > ptcutforerrors)
1135  pullAr_vs_tb_trt->Fill(time, pull);
1136  if (ppt > ptcutforerrors)
1137  errors_vs_tb_trt->Fill(time, dr);
1138  if (ppt > ptcutforerrors)
1139  trackerrors_vs_tb_trt->Fill(time, drtrack);
1140  if (ppt > ptcutforerrors)
1141  residualAr_vs_tb_trt->Fill(time, residual);
1142 
1143  if ((int)det == 2)
1144  {
1145  tresAr_vs_ToT_ea->Fill(ToT, tresidual);
1146  resAr_vs_ToT_ea->Fill(ToT, residual);
1147  tresAr_vs_HT_ea->Fill(HT, tresidual);
1148  resAr_vs_HT_ea->Fill(HT, residual);
1149  tresAr_vs_SinOverP_ea->Fill(sinoverp, tresidual);
1150  resAr_vs_SinOverP_ea->Fill(sinoverp, residual);
1151  tresAr_vs_CosOverP_ea->Fill(cosoverp, tresidual);
1152  resAr_vs_CosOverP_ea->Fill(cosoverp, residual);
1153 
1154  pullAr_eaP->Fill(ppt, pull);
1155  residualAr_eaP->Fill(ppt, residual);
1156  tresidualAr_eaP->Fill(ppt, tresidual);
1157  trackerrorsAr_eaP->Fill(ppt, drtrack);
1158  if (ppt > ptcutforerrors)
1159  pullAr_vs_tb_ea->Fill(time, pull);
1160  if (ppt > ptcutforerrors)
1161  errorsAr_vs_tb_ea->Fill(time, dr);
1162  if (ppt > ptcutforerrors)
1163  trackerrorsAr_vs_tb_ea->Fill(time, drtrack);
1164  if (ppt > ptcutforerrors)
1165  residualAr_vs_tb_ea->Fill(time, residual);
1166  }
1167  else if ((int)det == -2)
1168  {
1169  tresAr_vs_ToT_ec->Fill(ToT, tresidual);
1170  resAr_vs_ToT_ec->Fill(ToT, residual);
1171  tresAr_vs_HT_ec->Fill(HT, tresidual);
1172  resAr_vs_HT_ec->Fill(HT, residual);
1173  tresAr_vs_SinOverP_ec->Fill(sinoverp, tresidual);
1174  resAr_vs_SinOverP_ec->Fill(sinoverp, residual);
1175  tresAr_vs_CosOverP_ec->Fill(cosoverp, tresidual);
1176  resAr_vs_CosOverP_ec->Fill(cosoverp, residual);
1177 
1178  pullAr_ecP->Fill(ppt, pull);
1179  residualAr_ecP->Fill(ppt, residual);
1180  tresidualAr_ecP->Fill(ppt, tresidual);
1181  trackerrorsAr_ecP->Fill(ppt, drtrack);
1182  if (ppt > ptcutforerrors)
1183  pullAr_vs_tb_ec->Fill(time, pull);
1184  if (ppt > ptcutforerrors)
1185  errorsAr_vs_tb_ec->Fill(time, dr);
1186  if (ppt > ptcutforerrors)
1187  trackerrorsAr_vs_tb_ec->Fill(time, drtrack);
1188  if (ppt > ptcutforerrors)
1189  residualAr_vs_tb_ec->Fill(time, residual);
1190  }
1191  else if ((int)det == 1)
1192  {
1193  tresAr_vs_ToT_ba->Fill(ToT, tresidual);
1194  resAr_vs_ToT_ba->Fill(ToT, residual);
1195  tresAr_vs_HT_ba->Fill(HT, tresidual);
1196  resAr_vs_HT_ba->Fill(HT, residual);
1197  tresAr_vs_SinOverP_ba->Fill(sinoverp, tresidual);
1198  resAr_vs_SinOverP_ba->Fill(sinoverp, residual);
1199  tresAr_vs_CosOverP_ba->Fill(cosoverp, tresidual);
1200  resAr_vs_CosOverP_ba->Fill(cosoverp, residual);
1201 
1202  pullAr_baP->Fill(ppt, pull);
1203  residualAr_baP->Fill(ppt, residual);
1204  tresidualAr_baP->Fill(ppt, tresidual);
1205  trackerrorsAr_baP->Fill(ppt, drtrack);
1206  if (ppt > ptcutforerrors)
1207  pullAr_vs_tb_ba->Fill(time, pull);
1208  if (ppt > ptcutforerrors)
1209  errorsAr_vs_tb_ba->Fill(time, dr);
1210  if (ppt > ptcutforerrors)
1211  trackerrorsAr_vs_tb_ba->Fill(time, drtrack);
1212  if (ppt > ptcutforerrors)
1213  residualAr_vs_tb_ba->Fill(time, residual);
1214  }
1215  else if ((int)det == -1)
1216  {
1217  tresAr_vs_ToT_bc->Fill(ToT, tresidual);
1218  resAr_vs_ToT_bc->Fill(ToT, residual);
1219  tresAr_vs_HT_bc->Fill(HT, tresidual);
1220  resAr_vs_HT_bc->Fill(HT, residual);
1221  tresAr_vs_SinOverP_bc->Fill(sinoverp, tresidual);
1222  resAr_vs_SinOverP_bc->Fill(sinoverp, residual);
1223  tresAr_vs_CosOverP_bc->Fill(cosoverp, tresidual);
1224  resAr_vs_CosOverP_bc->Fill(cosoverp, residual);
1225 
1226  pullAr_bcP->Fill(ppt, pull);
1227  residualAr_bcP->Fill(ppt, residual);
1228  tresidualAr_bcP->Fill(ppt, tresidual);
1229  trackerrorsAr_bcP->Fill(ppt, drtrack);
1230  if (ppt > ptcutforerrors)
1231  pullAr_vs_tb_bc->Fill(time, pull);
1232  if (ppt > ptcutforerrors)
1233  errorsAr_vs_tb_bc->Fill(time, dr);
1234  if (ppt > ptcutforerrors)
1235  trackerrorsAr_vs_tb_bc->Fill(time, drtrack);
1236  if (ppt > ptcutforerrors)
1237  residualAr_vs_tb_bc->Fill(time, residual);
1238  }
1239  } // Close the argon part
1240 
1241  } // ... if event selection (dr<1) -> Precision hits:
1242 
1243  float ppt = pt / 1000.;
1244  if (ppt > 16)
1245  ppt = 15.5;
1246  float residual = r - rtrack;
1247  float tresidual = t - t0 - ttrack + ephase;
1248  float pull = (r - rtrack) / TMath::Sqrt(dr * dr + drtrack * drtrack);
1249 
1250  if (isArgonStraw == 0)
1251  { // ONLY STORE THE XENON CIRCLES:
1252  pull_trt->Fill(ppt, pull);
1253  residual_trt->Fill(ppt, residual);
1254  tresidual_trt->Fill(ppt, residual);
1255  if ((int)det == -2)
1256  {
1257  pull_ea->Fill(ppt, pull);
1258  tresidual_ea->Fill(ppt, tresidual);
1259  }
1260  if ((int)det == 2)
1261  {
1262  pull_ec->Fill(ppt, pull);
1263  residual_ec->Fill(ppt, residual);
1264  tresidual_ec->Fill(ppt, tresidual);
1265  }
1266  if ((int)det == -1)
1267  {
1268  pull_ba->Fill(ppt, pull);
1269  residual_ba->Fill(ppt, residual);
1270  tresidual_ba->Fill(ppt, tresidual);
1271  }
1272  if ((int)det == 1)
1273  {
1274  pull_bc->Fill(ppt, pull);
1275  residual_bc->Fill(ppt, residual);
1276  tresidual_bc->Fill(ppt, tresidual);
1277  }
1278  }
1279  else
1280  {
1281  pullAr_trt->Fill(ppt, pull);
1282  residualAr_trt->Fill(ppt, residual);
1283  tresidualAr_trt->Fill(ppt, residual);
1284  if ((int)det == 2)
1285  {
1286  pullAr_ea->Fill(ppt, pull);
1287  tresidualAr_ea->Fill(ppt, tresidual);
1288  }
1289  if ((int)det == -2)
1290  {
1291  pullAr_ec->Fill(ppt, pull);
1292  residualAr_ec->Fill(ppt, residual);
1293  tresidualAr_ec->Fill(ppt, tresidual);
1294  }
1295  if ((int)det == 1)
1296  {
1297  pullAr_ba->Fill(ppt, pull);
1298  residualAr_ba->Fill(ppt, residual);
1299  tresidualAr_ba->Fill(ppt, tresidual);
1300  }
1301  if ((int)det == -1)
1302  {
1303  pullAr_bc->Fill(ppt, pull);
1304  residualAr_bc->Fill(ppt, residual);
1305  tresidualAr_bc->Fill(ppt, tresidual);
1306  }
1307  } // save all AR hits
1308 
1309  } // END OF EVENT LOOP
1310  if (npt0 !=0){
1311  printf("REPLACED %d T0S WITH PRECISION VALUES (MEAN DIFF=%f)\n", npt0, diffpt0 / float(npt0));
1312  } else {
1313  printf("ERROR!! npt0 is zero!");
1314  }
1315 
1316  if (ifiles == nfiles - 1)
1317  {
1318  // Since we access here in the last loop iteration, better to use RECREATE than UPDATE
1319  TFile *ttfile = new TFile("tracktuple.root", "RECREATE");
1320 
1321  TDirectory *trtdir = ttfile->mkdir("TRT_all");
1322  TDirectory *binhist = trtdir->mkdir("reshists");
1323  TDirectory *detdir1 = trtdir->mkdir("Detector_-2");
1324  TDirectory *binhist1 = detdir1->mkdir("reshists1"); // NB! changed reshist to reshist1 for safety
1325  TDirectory *detdir2 = trtdir->mkdir("Detector_-1");
1326  TDirectory *binhist2 = detdir2->mkdir("reshists2");
1327  TDirectory *detdir3 = trtdir->mkdir("Detector_1");
1328  TDirectory *binhist3 = detdir3->mkdir("reshists3");
1329  TDirectory *detdir4 = trtdir->mkdir("Detector_2");
1330  TDirectory *binhist4 = detdir4->mkdir("reshists4");
1331  TDirectory *detdir5 = trtdir->mkdir("WholeBarrel_1");
1332  TDirectory *binhist5 = detdir5->mkdir("reshists5");
1333 
1334  TDirectory *errordir = ttfile->mkdir("Errors");
1335  TDirectory *corrdir = ttfile->mkdir("Correction");
1336 
1337  int npointsX = reshist1->GetNbinsX();
1338  int npointsY = treshist1->GetNbinsY();
1339  TH1D **hslizesX = new TH1D *[npointsX];
1340  TH1D **hslizesY = new TH1D *[npointsY];
1341 
1342  TVectorD tbins(npointsX);
1343  TVectorD rbins(npointsY);
1344 
1345  string chname;
1346  for (int i = 0; i < npointsX; i++)
1347  {
1348 
1349  tbins(i) = reshist1->GetXaxis()->GetBinCenter(i + 1);
1350 
1351  binhist->cd();
1352  chname = string(Form("res_tbin%i_trt", i));
1353  hslizesX[i] = reshist_trt->ProjectionY(chname.data(), i + 1, i + 1);
1354  binhist1->cd();
1355  chname = string(Form("res_tbin%i_-2", i));
1356  hslizesX[i] = reshist1->ProjectionY(chname.data(), i + 1, i + 1);
1357  binhist2->cd();
1358  chname = string(Form("res_tbin%i_-1", i));
1359  hslizesX[i] = reshist2->ProjectionY(chname.data(), i + 1, i + 1);
1360  binhist3->cd();
1361  chname = string(Form("res_tbin%i_1", i));
1362  hslizesX[i] = reshist3->ProjectionY(chname.data(), i + 1, i + 1);
1363  binhist4->cd();
1364  chname = string(Form("res_tbin%i_2", i));
1365  hslizesX[i] = reshist4->ProjectionY(chname.data(), i + 1, i + 1);
1366  binhist5->cd();
1367  chname = string(Form("res_tbin%i_bar", i));
1368  hslizesX[i] = reshist_bar->ProjectionY(chname.data(), i + 1, i + 1);
1369  }
1370 
1371  for (int i = 0; i < npointsY; i++)
1372  {
1373 
1374  rbins(i) = treshist1->GetYaxis()->GetBinCenter(i + 1);
1375 
1376  binhist->cd();
1377  chname = string(Form("tres_rbin%i_trt", i));
1378  hslizesY[i] = treshist_trt->ProjectionX(chname.data(), i + 1, i + 1);
1379  binhist1->cd();
1380  chname = string(Form("tres_rbin%i_-2", i));
1381  hslizesY[i] = treshist1->ProjectionX(chname.data(), i + 1, i + 1);
1382  binhist2->cd();
1383  chname = string(Form("tres_rbin%i_-1", i));
1384  hslizesY[i] = treshist1->ProjectionX(chname.data(), i + 1, i + 1);
1385  binhist3->cd();
1386  chname = string(Form("tres_rbin%i_1", i));
1387  hslizesY[i] = treshist3->ProjectionX(chname.data(), i + 1, i + 1);
1388  binhist4->cd();
1389  chname = string(Form("tres_rbin%i_2", i));
1390  hslizesY[i] = treshist4->ProjectionX(chname.data(), i + 1, i + 1);
1391  binhist5->cd();
1392  chname = string(Form("tres_rbin%i_bar", i));
1393  hslizesY[i] = treshist_bar->ProjectionX(chname.data(), i + 1, i + 1);
1394  }
1395 
1396  ttfile->cd();
1397  tbins.Write("tbins");
1398  rbins.Write("rbins");
1399 
1400  trtdir->cd();
1401  residual_ref->Write();
1402  timeresidual_ref->Write();
1403  rt_ref->Write();
1404  rt_ref2->Write();
1405 
1406  binhist->cd();
1407  reshist_trt->Write();
1408  binhist5->cd();
1409  reshist_bar->Write();
1410  binhist1->cd();
1411  reshist1->Write();
1412  binhist2->cd();
1413  reshist2->Write();
1414  binhist3->cd();
1415  reshist3->Write();
1416  binhist4->cd();
1417  reshist4->Write();
1418  binhist->cd();
1419  treshist_trt->Write();
1420  binhist5->cd();
1421  treshist_bar->Write();
1422  binhist1->cd();
1423  treshist1->Write();
1424  binhist2->cd();
1425  treshist2->Write();
1426  binhist3->cd();
1427  treshist3->Write();
1428  binhist4->cd();
1429  treshist4->Write();
1430 
1431  // Save stuff for errors:
1432  errordir->cd();
1433 
1434  pull_trt->Write();
1435  pull_ba->Write();
1436  pull_bc->Write();
1437  pull_ea->Write();
1438  pull_ec->Write();
1439 
1440  residual_trt->Write();
1441  residual_ba->Write();
1442  residual_bc->Write();
1443  residual_ea->Write();
1444  residual_ec->Write();
1445 
1446  tresidual_trt->Write();
1447  tresidual_ba->Write();
1448  tresidual_bc->Write();
1449  tresidual_ea->Write();
1450  tresidual_ec->Write();
1451 
1452  pull_trtP->Write();
1453  pull_baP->Write();
1454  pull_bcP->Write();
1455  pull_eaP->Write();
1456  pull_ecP->Write();
1457 
1458  residual_trtP->Write();
1459  residual_baP->Write();
1460  residual_bcP->Write();
1461  residual_eaP->Write();
1462  residual_ecP->Write();
1463 
1464  tresidual_trtP->Write();
1465  tresidual_baP->Write();
1466  tresidual_bcP->Write();
1467  tresidual_eaP->Write();
1468  tresidual_ecP->Write();
1469 
1470  pull_vs_tb_trt->Write();
1471  pull_vs_tb_trt->Write();
1472  pull_vs_tb_ba->Write();
1473  pull_vs_tb_bc->Write();
1474  pull_vs_tb_ea->Write();
1475  pull_vs_tb_ec->Write();
1476 
1477  errors_vs_tb_trt->Write();
1478  errors_vs_tb_ba->Write();
1479  errors_vs_tb_bc->Write();
1480  errors_vs_tb_ea->Write();
1481  errors_vs_tb_ec->Write();
1482 
1483  residual_vs_tb_trt->Write();
1484  residual_vs_tb_ba->Write();
1485  residual_vs_tb_bc->Write();
1486  residual_vs_tb_ea->Write();
1487  residual_vs_tb_ec->Write();
1488 
1489  trackerrors_trtP->Write();
1490  trackerrors_baP->Write();
1491  trackerrors_bcP->Write();
1492  trackerrors_eaP->Write();
1493  trackerrors_ecP->Write();
1494 
1495  trackerrors_vs_tb_trt->Write();
1496  trackerrors_vs_tb_ba->Write();
1497  trackerrors_vs_tb_bc->Write();
1498  trackerrors_vs_tb_ea->Write();
1499  trackerrors_vs_tb_ec->Write();
1500 
1501  // Save HT correction and ToT
1502  corrdir->cd();
1503 
1504  tres_vs_ToT_trt->Write();
1505  tres_vs_ToT_ba->Write();
1506  tres_vs_ToT_bc->Write();
1507  tres_vs_ToT_ea->Write();
1508  tres_vs_ToT_ec->Write();
1509 
1510  res_vs_ToT_trt->Write();
1511  res_vs_ToT_ba->Write();
1512  res_vs_ToT_bc->Write();
1513  res_vs_ToT_ea->Write();
1514  res_vs_ToT_ec->Write();
1515 
1516  tres_vs_HT_trt->Write();
1517  tres_vs_HT_ba->Write();
1518  tres_vs_HT_bc->Write();
1519  tres_vs_HT_ea->Write();
1520  tres_vs_HT_ec->Write();
1521 
1522  res_vs_HT_trt->Write();
1523  res_vs_HT_ba->Write();
1524  res_vs_HT_bc->Write();
1525  res_vs_HT_ea->Write();
1526  res_vs_HT_ec->Write();
1527 
1528  tres_vs_SinOverP_trt->Write();
1529  tres_vs_SinOverP_ba->Write();
1530  tres_vs_SinOverP_bc->Write();
1531  tres_vs_SinOverP_ea->Write();
1532  tres_vs_SinOverP_ec->Write();
1533 
1534  res_vs_SinOverP_trt->Write();
1535  res_vs_SinOverP_ba->Write();
1536  res_vs_SinOverP_bc->Write();
1537  res_vs_SinOverP_ea->Write();
1538  res_vs_SinOverP_ec->Write();
1539 
1540  tres_vs_CosOverP_trt->Write();
1541  tres_vs_CosOverP_ba->Write();
1542  tres_vs_CosOverP_bc->Write();
1543  tres_vs_CosOverP_ea->Write();
1544  tres_vs_CosOverP_ec->Write();
1545 
1546  res_vs_CosOverP_trt->Write();
1547  res_vs_CosOverP_ba->Write();
1548  res_vs_CosOverP_bc->Write();
1549  res_vs_CosOverP_ea->Write();
1550  res_vs_CosOverP_ec->Write();
1551 
1552  // Save the ARGON Part:
1553 
1554  if (existAr)
1555  {
1556  TDirectory *trtArdir = ttfile->mkdir("TRT_Ar_all");
1557  TDirectory *binArhist = trtArdir->mkdir("reshists_Ar"); // NB! changed directory names from reshists
1558  TDirectory *detArdir1 = trtArdir->mkdir("Detector_Ar_-2");
1559  TDirectory *binArhist1 = detArdir1->mkdir("reshists_Ar1");
1560  TDirectory *detArdir2 = trtArdir->mkdir("Detector_Ar_-1");
1561  TDirectory *binArhist2 = detArdir2->mkdir("reshists_Ar2");
1562  TDirectory *detArdir3 = trtArdir->mkdir("Detector_Ar_1");
1563  TDirectory *binArhist3 = detArdir3->mkdir("reshists_Ar3");
1564  TDirectory *detArdir4 = trtArdir->mkdir("Detector_Ar_2");
1565  TDirectory *binArhist4 = detArdir4->mkdir("reshists_Ar4");
1566  TDirectory *detArdir5 = trtArdir->mkdir("WholeBarrel_Ar_1");
1567  TDirectory *binArhist5 = detArdir5->mkdir("reshists_Ar5");
1568 
1569  TDirectory *errordirAr = ttfile->mkdir("ErrorsAr");
1570  TDirectory *corrdirAr = ttfile->mkdir("CorrectionAr");
1571  trtArdir->cd();
1572 
1573  binArhist->cd();
1574  resArhist_trt->Write();
1575  binArhist5->cd();
1576  resArhist_bar->Write();
1577  binArhist1->cd();
1578  resArhist1->Write();
1579  binArhist2->cd();
1580  resArhist2->Write();
1581  binArhist3->cd();
1582  resArhist3->Write();
1583  binArhist4->cd();
1584  resArhist4->Write();
1585  binArhist->cd();
1586  tresArhist_trt->Write();
1587  binArhist5->cd();
1588  tresArhist_bar->Write();
1589  binArhist1->cd();
1590  tresArhist1->Write();
1591  binArhist2->cd();
1592  tresArhist2->Write();
1593  binArhist3->cd();
1594  tresArhist3->Write();
1595  binArhist4->cd();
1596  tresArhist4->Write();
1597 
1598  TH1D **hslizesArX = new TH1D *[npointsX];
1599  TH1D **hslizesArY = new TH1D *[npointsY];
1600  TVectorD tbinsAr(npointsX);
1601  TVectorD rbinsAr(npointsY);
1602  for (int i = 0; i < npointsX; i++)
1603  {
1604  tbinsAr(i) = resArhist1->GetXaxis()->GetBinCenter(i + 1);
1605  binArhist->cd();
1606  chname = string(Form("res_tbin%i_trt", i));
1607  hslizesArX[i] = resArhist_trt->ProjectionY(chname.data(), i + 1, i + 1);
1608  binArhist1->cd();
1609  chname = string(Form("res_tbin%i_-2", i));
1610  hslizesArX[i] = resArhist1->ProjectionY(chname.data(), i + 1, i + 1);
1611  binArhist2->cd();
1612  chname = string(Form("res_tbin%i_-1", i));
1613  hslizesArX[i] = resArhist2->ProjectionY(chname.data(), i + 1, i + 1);
1614  binArhist3->cd();
1615  chname = string(Form("res_tbin%i_1", i));
1616  hslizesArX[i] = resArhist3->ProjectionY(chname.data(), i + 1, i + 1);
1617  binArhist4->cd();
1618  chname = string(Form("res_tbin%i_2", i));
1619  hslizesArX[i] = resArhist4->ProjectionY(chname.data(), i + 1, i + 1);
1620  binArhist5->cd();
1621  chname = string(Form("res_tbin%i_bar", i));
1622  hslizesArX[i] = resArhist_bar->ProjectionY(chname.data(), i + 1, i + 1);
1623  }
1624 
1625  for (int i = 0; i < npointsY; i++)
1626  {
1627  rbinsAr(i) = tresArhist1->GetYaxis()->GetBinCenter(i + 1);
1628  binArhist->cd();
1629  chname = string(Form("tres_rbin%i_trt", i));
1630  hslizesArY[i] = tresArhist_trt->ProjectionX(chname.data(), i + 1, i + 1);
1631  binArhist1->cd();
1632  chname = string(Form("tres_rbin%i_-2", i));
1633  hslizesArY[i] = tresArhist1->ProjectionX(chname.data(), i + 1, i + 1);
1634  binArhist2->cd();
1635  chname = string(Form("tres_rbin%i_-1", i));
1636  hslizesArY[i] = tresArhist1->ProjectionX(chname.data(), i + 1, i + 1);
1637  binArhist3->cd();
1638  chname = string(Form("tres_rbin%i_1", i));
1639  hslizesArY[i] = tresArhist3->ProjectionX(chname.data(), i + 1, i + 1);
1640  binArhist4->cd();
1641  chname = string(Form("tres_rbin%i_2", i));
1642  hslizesArY[i] = tresArhist4->ProjectionX(chname.data(), i + 1, i + 1);
1643  binArhist5->cd();
1644  chname = string(Form("tres_rbin%i_bar", i));
1645  hslizesArY[i] = tresArhist_bar->ProjectionX(chname.data(), i + 1, i + 1);
1646  }
1647 
1648  // Save stuff for errors:
1649  errordirAr->cd();
1650 
1651  pullAr_trt->Write();
1652  pullAr_ba->Write();
1653  pullAr_bc->Write();
1654  pullAr_ea->Write();
1655  pullAr_ec->Write();
1656 
1657  residualAr_trt->Write();
1658  residualAr_ba->Write();
1659  residualAr_bc->Write();
1660  residualAr_ea->Write();
1661  residualAr_ec->Write();
1662 
1663  tresidualAr_trt->Write();
1664  tresidualAr_ba->Write();
1665  tresidualAr_bc->Write();
1666  tresidualAr_ea->Write();
1667  tresidualAr_ec->Write();
1668 
1669  pullAr_trtP->Write();
1670  pullAr_baP->Write();
1671  pullAr_bcP->Write();
1672  pullAr_eaP->Write();
1673  pullAr_ecP->Write();
1674 
1675  residualAr_trtP->Write();
1676  residualAr_baP->Write();
1677  residualAr_bcP->Write();
1678  residualAr_eaP->Write();
1679  residualAr_ecP->Write();
1680 
1681  tresidualAr_trtP->Write();
1682  tresidualAr_baP->Write();
1683  tresidualAr_bcP->Write();
1684  tresidualAr_eaP->Write();
1685  tresidualAr_ecP->Write();
1686 
1687  pullAr_vs_tb_trt->Write();
1688  pullAr_vs_tb_trt->Write();
1689  pullAr_vs_tb_ba->Write();
1690  pullAr_vs_tb_bc->Write();
1691  pullAr_vs_tb_ea->Write();
1692  pullAr_vs_tb_ec->Write();
1693 
1694  errorsAr_vs_tb_trt->Write();
1695  errorsAr_vs_tb_ba->Write();
1696  errorsAr_vs_tb_bc->Write();
1697  errorsAr_vs_tb_ea->Write();
1698  errorsAr_vs_tb_ec->Write();
1699 
1700  residualAr_vs_tb_trt->Write();
1701  residualAr_vs_tb_ba->Write();
1702  residualAr_vs_tb_bc->Write();
1703  residualAr_vs_tb_ea->Write();
1704  residualAr_vs_tb_ec->Write();
1705 
1706  trackerrorsAr_trtP->Write();
1707  trackerrorsAr_baP->Write();
1708  trackerrorsAr_bcP->Write();
1709  trackerrorsAr_eaP->Write();
1710  trackerrorsAr_ecP->Write();
1711 
1712  trackerrorsAr_vs_tb_trt->Write();
1713  trackerrorsAr_vs_tb_ba->Write();
1714  trackerrorsAr_vs_tb_bc->Write();
1715  trackerrorsAr_vs_tb_ea->Write();
1716  trackerrorsAr_vs_tb_ec->Write();
1717 
1718  // Save HT correction and ToT
1719  corrdirAr->cd();
1720 
1721  tresAr_vs_ToT_trt->Write();
1722  tresAr_vs_ToT_ba->Write();
1723  tresAr_vs_ToT_bc->Write();
1724  tresAr_vs_ToT_ea->Write();
1725  tresAr_vs_ToT_ec->Write();
1726 
1727  resAr_vs_ToT_trt->Write();
1728  resAr_vs_ToT_ba->Write();
1729  resAr_vs_ToT_bc->Write();
1730  resAr_vs_ToT_ea->Write();
1731  resAr_vs_ToT_ec->Write();
1732 
1733  tresAr_vs_HT_trt->Write();
1734  tresAr_vs_HT_ba->Write();
1735  tresAr_vs_HT_bc->Write();
1736  tresAr_vs_HT_ea->Write();
1737  tresAr_vs_HT_ec->Write();
1738 
1739  resAr_vs_HT_trt->Write();
1740  resAr_vs_HT_ba->Write();
1741  resAr_vs_HT_bc->Write();
1742  resAr_vs_HT_ea->Write();
1743  resAr_vs_HT_ec->Write();
1744 
1745  tresAr_vs_SinOverP_trt->Write();
1746  tresAr_vs_SinOverP_ba->Write();
1747  tresAr_vs_SinOverP_bc->Write();
1748  tresAr_vs_SinOverP_ea->Write();
1749  tresAr_vs_SinOverP_ec->Write();
1750 
1751  resAr_vs_SinOverP_trt->Write();
1752  resAr_vs_SinOverP_ba->Write();
1753  resAr_vs_SinOverP_bc->Write();
1754  resAr_vs_SinOverP_ea->Write();
1755  resAr_vs_SinOverP_ec->Write();
1756 
1757  tresAr_vs_CosOverP_trt->Write();
1758  tresAr_vs_CosOverP_ba->Write();
1759  tresAr_vs_CosOverP_bc->Write();
1760  tresAr_vs_CosOverP_ea->Write();
1761  tresAr_vs_CosOverP_ec->Write();
1762 
1763  resAr_vs_CosOverP_trt->Write();
1764  resAr_vs_CosOverP_ba->Write();
1765  resAr_vs_CosOverP_bc->Write();
1766  resAr_vs_CosOverP_ea->Write();
1767  resAr_vs_CosOverP_ec->Write();
1768  } // Close argon part
1769 
1770  ttfile->Write();
1771  ttfile->Close();
1772  }
1773 
1774  //*********************************************************************
1775  // SCANNING BINARY FILE
1776  }
1777  else
1778  {
1779  //*********************************************************************
1780 
1781  cout << "SCANNING BINARY HISTOGRAM FILE " << argv[ifiles + 2] << endl;
1782 
1783  nhistsadd = 0;
1784  nhists = 0;
1785 
1786  ifstream *ifile = new ifstream(argv[ifiles + 2], ios::in | ios::binary);
1787 
1788  // histogram loop
1789  while (true)
1790  {
1791 
1792  // reading histogram
1793  ifile->read((char *)&npop, sizeof(int));
1794  if (ifile->eof())
1795  break;
1796  int *chist = new int[(2 * npop)];
1797  if (npop > 0)
1798  ifile->read((char *)chist, sizeof(int) * 2 * npop);
1799  ifile->read((char *)&sid, sizeof(int));
1800 
1801  if (histmap.find(sid) == histmap.end())
1802  { // create histogram if seen for the first time
1803  // cppcheck-suppress stlFindInsert
1804  histmap[sid] = new CalHist();
1805  nhistsadd++;
1806  }
1807 
1808  for (int ipop = 0; ipop < 2 * npop; ipop = ipop + 2)
1809  {
1810  histmap[sid]->IncreaseBin((short)chist[ipop], (unsigned short)chist[ipop + 1]); // increase the bins
1811  if (chist[ipop] < 100)
1812  {
1813  ntres += chist[ipop + 1];
1814  } // increase hit counters
1815  else if (chist[ipop] >= 100 && chist[ipop] < 200)
1816  nres += chist[ipop + 1];
1817  else
1818  nrt += chist[ipop + 1];
1819  }
1820 
1821  nhists++;
1822 
1823  if (nhists % 10000 == 0)
1824  {
1825  process_mem_usage(vm, rss);
1826  printf("%i HISTOGRAMS READ! %i HISTOGRAMS ADDED! %i BINS ADDED! MAXVALUE: %i VM: %0f RSS: %0f\n", nhists, nhistsadd, nbinsadd, maxvalue, vm, rss);
1827  }
1828 
1829  std::destroy_at(chist);
1830 
1831  if (nhists % 1000000000 == 0)
1832  {
1833  process_mem_usage(vm, rss);
1834  printf("%i HISTOGRAMS READ! %i HISTOGRAMS ADDED! %i BINS ADDED! MAXVALUE: %i VM: %0f RSS: %0f\n", nhists, nhistsadd, nbinsadd, maxvalue, vm, rss);
1835  dump_hists(&histmap, ntbins, nrbins, ntres, argv[1], 0);
1836  for (map<int, CalHist *>::iterator it = histmap.begin(); it != histmap.end(); ++it)
1837  {
1838  delete it->second;
1839  }
1840  histmap.clear();
1841  }
1842  }
1843 
1844  delete ifile;
1845 
1846  cout << nhists << " HISTOGRAMS SACNNED" << endl;
1847  cout << nhistsadd << " HISTOGRAMS ADDED" << endl;
1848 
1849  } // end of if (root or binary histograms)
1850  } // end of file loop
1851 
1852  cout << endl;
1853  cout << "TOT HISTOGRAMS............. " << nhists << endl;
1854  if (nhits!=0){
1855  cout << "TOT HITS IN TIMERES HIST .. " << ntres << " (" << 100 * float(ntres) / float(nhits) << "%)" << endl;
1856  cout << "TOT HITS IN RRES HIST ..... " << nres << " (" << 100 * float(nres) / float(nhits) << "%)" << endl;
1857  cout << "TOT HITS IN RT HIST ....... " << nrt << " (" << 100 * float(nrt) / float(nhits) << "%)" << endl;
1858  } else {
1859  cout << "Number of hits was zero !!\n";
1860  }
1861  cout << endl;
1862 
1863  ofilestat << "TRESHITS " << ntres << endl;
1864  ofilestat.close();
1865  dump_hists(&histmap, ntbins, nrbins, ntres, argv[1], 0);
1866  dump_tracktuple(&trackmap);
1867 
1868  return 0;
1869 }

◆ process_mem_usage()

void process_mem_usage ( double &  vm_usage,
double &  resident_set 
)

Definition at line 41 of file TRTCalib_bhadd.cxx.

42 {
43  using std::ifstream;
44  using std::ios_base;
45  using std::string;
46 
47  vm_usage = 0.0;
48  resident_set = 0.0;
49 
50  // 'file' stat seems to give the most reliable results
51  //
52  ifstream stat_stream("/proc/self/stat", ios_base::in);
53 
54  // dummy vars for leading entries in stat that we don't care about
55  //
56  string pid, comm, state, ppid, pgrp, session, tty_nr;
57  string tpgid, flags, minflt, cminflt, majflt, cmajflt;
58  string utime, stime, cutime, cstime, priority, nice;
59  string O, itrealvalue, starttime;
60 
61  // the two fields we want
62  //
63  unsigned long vsize;
64  long rss;
65 
66  stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt >> utime >> stime >> cutime >> cstime >> priority >> nice >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
67 
68  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
69  vm_usage = vsize / 1024.0;
70  resident_set = rss * page_size_kb;
71 }

◆ readoldpars()

map<string, calibpars> readoldpars ( )

Definition at line 241 of file TRTCalib_bhadd.cxx.

242 {
243  string line;
244  ifstream oldconstfile("precision_constants.txt");
245  int det, lay, mod, stl, stw;
246  float t0, dt0;
247  map<string, calibpars> oldparsmap;
248  char key[100];
249 
250  if (oldconstfile.is_open())
251  {
252  while (!oldconstfile.eof())
253  {
254  getline(oldconstfile, line);
255  if (line.size() > 25 && line.size() < 55)
256  {
257  sscanf(line.data(), "%d %d %d %d %d : %e %e", &det, &lay, &mod, &stl, &stw, &t0, &dt0);
258  if (det >= -3 && lay > -1 && mod > -1 && stl > -1 && stw > -1)
259  {
260  sprintf(key, "_%i_%i_%i_%i_%i", det, lay, mod, stl, stw);
261  oldparsmap[string(key)].t0 = t0;
262  oldparsmap[string(key)].dt0 = dt0;
263  }
264  }
265  }
266  oldconstfile.close();
267  }
268  else{
269  // Output to std::cout since for online calibration this file is not used.
270  std::cout << "Unable to open precision t0 file!\n";
271  }
272 
273 
274  return oldparsmap;
275 }

◆ Simple1dHist()

int Simple1dHist ( float  min,
float  max,
int  nbins,
float  value 
)

Definition at line 24 of file TRTCalib_bhadd.cxx.

25 {
26  if ((value < min) or (value > max))
27  return -1;
28  int binno = (int)(nbins * ((value - min) / (max - min)));
29  return binno;
30 }

◆ Simple2dHist()

int Simple2dHist ( float  minx,
float  maxx,
int  nbinsx,
float  miny,
float  maxy,
int  nbinsy,
float  valuex,
float  valuey 
)

Definition at line 32 of file TRTCalib_bhadd.cxx.

33 {
34  if (valuex < minx or valuex > maxx or valuey < miny or valuey > maxy)
35  return -1;
36  int binnox = (int)(nbinsx * ((valuex - minx) / (maxx - minx)));
37  int binnoy = (int)(nbinsy * ((valuey - miny) / (maxy - miny)));
38  return binnoy * nbinsx + binnox;
39 }
dump_tracktuple
int dump_tracktuple(map< string, trackdata > *trackmap)
Definition: TRTCalib_bhadd.cxx:277
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
extractSporadic.nhists
nhists
Definition: extractSporadic.py:111
CompBHist::npop
int npop
Definition: TRTCalib_bhadd.cxx:156
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CalHist
Definition: TRTCalib_bhadd.cxx:76
checkFileSG.line
line
Definition: checkFileSG.py:75
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CompBHist::Write
void Write(ofstream *)
Definition: TRTCalib_bhadd.cxx:201
Simple1dHist
int Simple1dHist(float min, float max, int nbins, float value)
Definition: TRTCalib_bhadd.cxx:24
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ClusterSeg::residual
@ residual
Definition: ClusterNtuple.h:20
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CalibDbCompareT0.dt0
dt0
Definition: CalibDbCompareT0.py:76
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
validation.ofile
ofile
Definition: validation.py:96
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
skel.it
it
Definition: skel.GENtoEVGEN.py:396
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
athena.value
value
Definition: athena.py:124
python.selector.AtlRunQuerySelectorLhcOlc.priority
priority
Definition: AtlRunQuerySelectorLhcOlc.py:611
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
stime
std::string stime()
return the current data and time
Definition: computils.cxx:214
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Simple2dHist
int Simple2dHist(float minx, float maxx, int nbinsx, float miny, float maxy, int nbinsy, float valuex, float valuey)
Definition: TRTCalib_bhadd.cxx:32
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
process_mem_usage
void process_mem_usage(double &vm_usage, double &resident_set)
Definition: TRTCalib_bhadd.cxx:41
CompBHist
Definition: TRTCalib_bhadd.cxx:143
lwtDev::Component::O
@ O
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
readoldpars
map< string, calibpars > readoldpars()
Definition: TRTCalib_bhadd.cxx:241
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
dump_hists
int dump_hists(map< int, CalHist * > *histmap, int ntbins, int nrbins, int, char *fname, int fileno)
Definition: TRTCalib_bhadd.cxx:292
python.StandardJetMods.pull
pull
Definition: StandardJetMods.py:282
run
Definition: run.py:1
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
ReadCalibFromCool.comm
comm
Definition: ReadCalibFromCool.py:440
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
readCCLHist.float
float
Definition: readCCLHist.py:83
extractSporadic.myFile
myFile
Definition: extractSporadic.py:87
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37