22#include <TDirectory.h>
26#include <TGraphErrors.h>
114 rthist.resize (nbinsr*nbinst+200);
118RtGraph::RtGraph(TH2F* rtHist,
int binvar,
const char* binlabel,
bool pflag, TDirectory* dir){
121 npoints = binvar==0 ? rtHist->GetNbinsX() : rtHist->GetNbinsY() ;
132 TH1D** hslizes =
new TH1D*[
npoints];
150 TDirectory* binhistdir = dir->mkdir(
"binhist");
152 std::cout <<
" Calibrator::RtGraph: " <<
" Directory " << std::string(binhistdir->GetPath()) <<
" binlabel " << std::string(binlabel) << std::endl;
155 std::cout <<
" Calibrator::RtGraph: " <<
" number of points " <<
npoints <<
" binvar " << binvar << std::endl;
159 m_chname = std::string(Form(
"%s slize_%i",binlabel,i));
160 m_chtit = binvar==0 ? std::string(Form(
"bin %i : %4.2f < %s < %4.2f [ns]",i,rtHist->GetXaxis()->GetBinLowEdge(i+1),binlabel,rtHist->GetXaxis()->GetBinUpEdge(i+1))) :
161 std::string(Form(
"bin %i : %4.2f < %s < %4.2f [mm]",i,rtHist->GetYaxis()->GetBinLowEdge(i+1),binlabel,rtHist->GetYaxis()->GetBinUpEdge(i+1))) ;
162 hslizes[i] = binvar==0 ? rtHist->ProjectionY(
m_chname.data(),i+1,i+1) :
163 rtHist->ProjectionX(
m_chname.data(),i+1,i+1);
164 hslizes[i]->SetTitle(
m_chtit.data());
166 hslizes[i]->SetDirectory(
nullptr);
170 for (
int j=1;j<=hslizes[i]->GetNbinsX();j++) {
171 float val=hslizes[i]->GetBinContent(j);
175 m_leftval[i] = hslizes[i]->GetBinContent(j-1);
176 m_rightval[i] = hslizes[i]->GetBinContent(j+1);
191 if (i<(
float)hslizes[i]->GetNbinsX()/2)
m_btype[i]=
LOW;
195 int rtEntries = rtHist->GetEntries();
196 if(rtEntries==0) rtEntries=1;
200 float frmin=0,frmax=0;
205 if (
m_btype[i]==
LOW) {frmin = hslizes[i]->GetBinCenter(1); frmax = hslizes[i]->GetBinCenter(
m_maxbin[i]+4);}
209 std::unique_ptr<TF1> ff(
new TF1(
"dtfitfunc",
"gaus"));
211 ff->SetRange(frmin,frmax);
213 m_t = binvar==0 ? rtHist->GetXaxis()->GetBinCenter(i+1) : rtHist->GetYaxis()->GetBinCenter(i+1);
214 m_et = binvar==0 ? rtHist->GetXaxis()->GetBinWidth(1)/std::sqrt(12.0) : rtHist->GetYaxis()->GetBinWidth(1)/std::sqrt(12.0);
232 fitresult=hslizes[i]->Fit(
"dtfitfunc",
"QR");
233 ff->SetRange(
m_mean-1.0*ff->GetParameter(2),
m_mean+1.0*ff->GetParameter(2));
234 fitresult=hslizes[i]->Fit(
"dtfitfunc",
"QR");
235 m_d = ff->GetParameter(1);
236 m_ed = ff->GetParError(1);
237 std::cout << fitresult <<
" " <<
m_ed << std::endl;
268 rtgr->SetTitle((std::string(
"binning in ") + binlabel).
data());
270 trgr->SetTitle((std::string(
"binning in ") + binlabel).
data());
272 rtgr->SetMarkerStyle(1) ;
273 rtgr->SetMarkerColor(2) ;
274 rtgr->SetLineColor(2) ;
275 rtgr->SetName(
"rtgraph") ;
276 trgr->SetMarkerStyle(1) ;
277 trgr->SetMarkerColor(2) ;
278 trgr->SetLineColor(2) ;
279 trgr->SetName(
"trgraph") ;
305 double t = par[0]+
r*(par[1]+(
r*(par[2]+
r*par[3])));
311 double r = par[1]*(t-par[0]) + par[2]*(t-par[0])*(t-par[0]) + par[3]*(t-par[0])*(t-par[0])*(t-par[0]);
317 double rmin0 = par[0];
320 double t_const = par[3];
322 double t = t_const + 2*rho/v*std::asin(std::sqrt(rmin0*rmin0*(1-0.25*
r*
r)+
r*
r)/(2*rho));
327 double rmin0 = par[0];
330 double t_const = par[3];
332 double r_squared = (4*rho*rho*std::sin(v*(t-t_const)/(2*rho))-rmin0*rmin0)/(1-0.25*rmin0*rmin0);
333 double r=r_squared>0 ? std::sqrt(r_squared) : 0.0;
384Calibrator::Calibrator(
int lev,
const std::string& nme,
int mint0,
int minrt,
const std::string& rtr,
const std::string& rtb,
float t0sft)
433 if ( (value<
min) || (value>
max) )
return -1;
434 if (
max-
min == 0 )
return -1;
435 int binno=(int)(nbins*((value-
min)/(
max-
min)));
440 if ( (valuex<minx) || (valuex>maxx) || (valuey<miny) || (valuey>maxy) )
return -1;
441 if(maxx-minx == 0 || maxy-miny==0)
return -1;
442 int binnox=(int)(nbinsx*((valuex-minx)/(maxx-minx)));
443 int binnoy=(int)(nbinsy*((valuey-miny)/(maxy-miny)));
444 return binnoy*nbinsx+binnox;
448 if((
int)n==0)
return oldmean;
449 return oldmean*((n-1)/n)+newvalue/n;
454 return data.find(key) !=
data.end();
468 std::string yn[2]={
"NO",
"YES"};
469 std::string info = std::string(Form(
"CONFIGURATION %-16s: dort=%-3s, dot0=%-3s, dores=%-3s, selection=",
m_name.data(),yn[
dort].data(),yn[
dot0].data(),yn[
dores].data()));
471 if (isel==-3) info += std::string(
"all");
472 else if (isel==-4) info += std::string(
"none");
473 else info += std::string(Form(
"%2i,",isel));
479 int units = (int)
data.size();
480 if(units==0) units++;
481 std::string info = std::string(Form(
"STATISTICS %16s: nunits=%8i, nhits=%9i, hits/unit=%11.1f",
m_name.data(), units,
m_nhits, (
float)
m_nhits/(
float)units ));
486 std::string optstr=
"";
487 if (
dort) optstr +=
'R';
488 if (
dot0) optstr +=
'T';
507 std::string selstr=
"";
510 else for (
int isel :
selection) selstr += std::string(Form(
"%i",isel));
516 int nbins=
data[key].rtgraph->tval.size();
517 double maxt=
data[key].rtgraph->tval[nbins-1];
518 double mint=
data[key].rtgraph->tval[0];
520 std::string brt =
"";
521 brt += Form(
"%f %f %i ",mint,maxt,nbins);
523 for (
int ip=0; ip<nbins;ip++){
524 brt += Form(
"%f ",
data[key].rtgraph->rval[ip]);
532 std::ifstream oldconstfile(
"calib_constants_in.txt");
536 if (oldconstfile.is_open())
538 while (!oldconstfile.eof() )
540 oldconstfile >> key >>
t0;
542 std::cout <<
"UPDATED OLD T0: " << key <<
" " <<
data[key].oldt02 <<
" -> " <<
t0 << std::endl;
546 oldconstfile.close();
550 std::cout <<
"NO OLD T0S FILE FOUND. USING AVERAGE VALUES!" << std::endl;
555float Calibrator::FitRt
ATLAS_NOT_THREAD_SAFE (
const std::string& key,
const std::string& opt, TH2F* rtHist, TDirectory* dir){
560 RtGraph* rtg = m_rtbinning.find(
't')==std::string::npos ?
new RtGraph(rtHist,1,std::string(
"abs(rtrack)").
data(),!bequiet,dir) :
new RtGraph(rtHist,0,std::string(
"t-t0").
data(),!bequiet,dir);
562 TF1 dtfitfunc(
"dtfitfunc",
"gaus(0)");
564 gStyle->SetOptFit(1111);
565 gStyle->SetPalette(1);
568 TF1 *trfunc,*rtfunc,*oldrtfunc;
573 trfunc->SetParameters(0.3, 1.0, 0.05, -3.);
574 double rmin0Limits[2]={0.0,2.0};
575 double rhoLimits[2]={0.0,10.};
576 double vLimits[2]={0.0,1.0};
577 trfunc->SetParLimits(0,rmin0Limits[0],rmin0Limits[1]);
578 trfunc->SetParLimits(1,rhoLimits[0],rhoLimits[1]);
579 trfunc->SetParLimits(2,vLimits[0],vLimits[1]);
580 rtg->
trgr->SetTitle(
"Dines' R-t sqrt(..)");
583 trfunc =
new TF1(
"trfunc",
pol3deg,0,3,4);
586 trfunc->SetParameters(0.0, 0.0, 0.0, 0.0);
587 rtg->
trgr->SetTitle(
"Polynomial R-t");
591 trfunc->SetRange(0,2);
592 if (opt.find(
'3')==std::string::npos) trfunc->FixParameter(3,0);
593 trfunc->SetLineColor(4) ;
594 rtg->
trgr->Fit(trfunc,
"QR");
595 if (!bequiet) rtg->
trgr->Write();
599 rtfunc->SetRange(0,45);
600 if (opt.find(
'3')==std::string::npos) rtfunc->FixParameter(3,0);
601 rtfunc->SetLineColor(4) ;
603 rtfunc->SetParameters(trfunc->GetParameter(0),trfunc->GetParameter(1),trfunc->GetParameter(2),trfunc->GetParameter(3));
607 rtfunc->SetParameters(0.000000e+00, 6.269950e-02, -3.370054e-04, -1.244642e-07);
608 if(rtg->
rtgr !=
nullptr) {
609 rtg->
rtgr->Fit(rtfunc,
"QR");
610 for (
int ipnt=0; ipnt<rtg->
rtgr->GetN(); ipnt++){
611 float deriv = rtfunc->Derivative(rtg->
rtgr->GetX()[ipnt]);
612 if(fabs(deriv)<1.0e-24) deriv=0.05;
613 rtg->
rtgr->SetPointError(ipnt , rtg->
rtgr->GetEY()[ipnt]/deriv , rtg->
rtgr->GetEY()[ipnt]);
615 rtg->
rtgr->Fit(rtfunc,
"R");
619 if (!bequiet and (rtg->
rtgr !=
nullptr)) rtg->
rtgr->Write();
622 oldrtfunc->SetRange(0,45);
623 oldrtfunc->SetLineColor(1) ;
624 oldrtfunc->SetLineStyle(2) ;
625 oldrtfunc->SetLineWidth(1) ;
626 oldrtfunc->SetParameters(
data[key].oldrtpar[0],
data[key].oldrtpar[1],
data[key].oldrtpar[2],
data[key].oldrtpar[3]);
628 if (!bequiet) oldrtfunc->Write();
630 rtpars[0] = rtfunc->GetParameter(0);
631 rtpars[1] = rtfunc->GetParameter(1);
632 rtpars[2] = rtfunc->GetParameter(2);
633 rtpars[3] = rtfunc->GetParameter(3);
641 float precision = 0.0001;
644 float driftradius = rtpars[0]+tdrift*(rtpars[1]+tdrift*(rtpars[2]));
645 float residual = std::abs(rdrift) - driftradius;
646 while (std::abs(residual) > precision) {
648 drdt = rtpars[1]+tdrift*(2*rtpars[2]);
649 if(fabs(drdt)<1.0e-24) drdt=0.05;
650 tdrift = tdrift + residual/drdt;
652 driftradius = rtpars[0]+tdrift*(rtpars[1]+tdrift*(rtpars[2]));
653 residual = rdrift - driftradius;
656 if (ntries>maxtries){
662 if (opt.find(
'0')==std::string::npos) {
664 data[key].rtpar[0] = rtpars[0];
665 data[key].rtpar[1] = rtpars[1];
666 data[key].rtpar[2] = rtpars[2];
667 data[key].rtpar[3] = 0;
669 data[key].rtpar[0] = 0;
670 data[key].rtpar[1] = rtpars[1] + 2*tdrift*rtpars[2] + 3*tdrift*tdrift*rtpars[3];
671 data[key].rtpar[2] = rtpars[2] + 3*tdrift*rtpars[3];
672 data[key].rtpar[3] = rtpars[3];
676 data[key].rtpar[0] = rtpars[0];
677 data[key].rtpar[1] = rtpars[1];
678 data[key].rtpar[2] = rtpars[2];
679 data[key].rtpar[3] = rtpars[3];
682 data[key].rtgraph=rtg;
694 float mean = tresHist->GetMean();
695 float rms = tresHist->GetRMS();
698 for (
int j=1; j<=tresHist->GetNbinsX()+1;j++){
699 val=tresHist->GetBinContent(j);
707 data[key].tresMean = 0;
708 float fitmean=tresHist->GetBinCenter(maxbin);
709 if (std::abs(fitmean)>5.0){
711 data[key].t0err = rms;
712 data[key].t0fittype = 1;
717 if (fitrms>5.0) fitrms=5.0;
719 tresHist->Fit(
"gaus",
"QR",
"",
mean-rms,
mean+rms);
720 if (tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2) < m_mintres ||
721 tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2) > m_maxtres) {
723 data[key].t0err = rms;
724 data[key].t0fittype = 1;
728 tresHist->Fit(
"gaus",
"QR",
"",tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2),tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2));
729 if (tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2) < m_mintres ||
730 tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2) > m_maxtres) {
731 data[key].tres = tresHist->GetFunction(
"gaus")->GetParameter(2);
732 data[key].tresMean = tresHist->GetFunction(
"gaus")->GetParameter(1);
733 data[key].t0err = tresHist->GetFunction(
"gaus")->GetParError(1);
734 data[key].t0fittype = 2;
735 return tresHist->GetFunction(
"gaus")->GetParameter(1);
738 tresHist->Fit(
"gaus",
"QR",
"",tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2),tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2));
739 if (tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2) < m_mintres ||
740 tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2) > m_maxtres) {
741 data[key].tres = tresHist->GetFunction(
"gaus")->GetParameter(2);
742 data[key].tresMean = tresHist->GetFunction(
"gaus")->GetParameter(1);
743 data[key].t0err = tresHist->GetFunction(
"gaus")->GetParError(1);
744 data[key].t0fittype = 2;
745 return tresHist->GetFunction(
"gaus")->GetParameter(1);
748 tresHist->Fit(
"gaus",
"QR",
"",tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2),tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2));
749 if (tresHist->GetFunction(
"gaus")->GetParameter(1) - tresHist->GetFunction(
"gaus")->GetParameter(2) < m_mintres ||
750 tresHist->GetFunction(
"gaus")->GetParameter(1) + tresHist->GetFunction(
"gaus")->GetParameter(2) > m_maxtres) {
752 data[key].t0err = rms;
753 data[key].t0fittype = 1;
757 data[key].tres = tresHist->GetFunction(
"gaus")->GetParameter(2);
758 data[key].tresMean = tresHist->GetFunction(
"gaus")->GetParameter(1);
759 data[key].t0err = tresHist->GetFunction(
"gaus")->GetParError(1);
760 data[key].t0fittype = 2;
763 if ( std::abs(tresHist->GetFunction(
"gaus")->GetParameter(2))>10 || std::abs(tresHist->GetFunction(
"gaus")->GetParameter(1))>10 ) {
765 data[key].tres = tresHist->GetRMS();
766 data[key].tresMean = tresHist->GetMean();
767 data[key].t0err = tresHist->GetRMS();
768 data[key].t0fittype = 6;
769 return tresHist->GetMean();
773 gStyle->SetOptFit(1111);
775 return tresHist->GetFunction(
"gaus")->GetParameter(1);
781 float mean = resHist->GetMean();
783 resHist->Fit(
"gaus",
"QRI",
"",
mean-0.3,
mean+0.3);
784 resHist->Fit(
"gaus",
"QRI",
"",resHist->GetFunction(
"gaus")->GetParameter(1) - 1.5*resHist->GetFunction(
"gaus")->GetParameter(2),resHist->GetFunction(
"gaus")->GetParameter(1) + 1.5*resHist->GetFunction(
"gaus")->GetParameter(2));
785 resHist->Fit(
"gaus",
"QRI",
"",resHist->GetFunction(
"gaus")->GetParameter(1) - 1.5*resHist->GetFunction(
"gaus")->GetParameter(2),resHist->GetFunction(
"gaus")->GetParameter(1) + 1.5*resHist->GetFunction(
"gaus")->GetParameter(2));
786 resHist->Fit(
"gaus",
"QRI",
"",resHist->GetFunction(
"gaus")->GetParameter(1) - 1.5*resHist->GetFunction(
"gaus")->GetParameter(2),resHist->GetFunction(
"gaus")->GetParameter(1) + 1.5*resHist->GetFunction(
"gaus")->GetParameter(2));
788 gStyle->SetOptFit(1111);
790 data[
key].res=resHist->GetFunction(
"gaus")->GetParameter(2);
791 data[
key].resMean=resHist->GetFunction(
"gaus")->GetParameter(1);
792 data[
key].reserr=resHist->GetFunction(
"gaus")->GetParError(2);
794 return resHist->GetFunction(
"gaus")->GetParameter(2);
801 bool calrt=opt.find(
'R')!=std::string::npos;
802 bool calt0=opt.find(
'T')!=std::string::npos;
803 bool donothing=opt.find(
'N')!=std::string::npos;
804 bool prnt=opt.find(
'P')!=std::string::npos;
805 bool useref=opt.find(
'B')!=std::string::npos;
806 bool useshortstw=opt.find(
'S')!=std::string::npos;
808 if (donothing)
return dir;
810 data[key].calflag=
true;
812 bool enough_t0 =
data[key].ntres>=m_mint0stat;
813 bool enough_rt =
data[key].nrt>=m_minrtstat;
815 if ((enough_rt && calrt) || (enough_t0 && calt0)) {
816 m_hdirs[key] = dir->mkdir(Form(
"%s%s",m_name.data(),key.data()));
819 std::cout <<
" Calibrator::Calibrate Parent Directory: " << std::string(dir->GetPath()) << std::endl;
820 std::cout <<
" Calibrator::Calibrate key " << key <<
" name " << m_name <<
" entries for rt " <<
data[key].nrt <<
" min req " << m_minrtstat << std::endl;
821 std::cout <<
" Calibrator::Calibrate key " << key <<
" entries for t0 " <<
data[key].ntres <<
" min req " << m_mint0stat << std::endl;
822 std::cout <<
" Calibrator::Calibrate Directory: " << std::string(m_hdirs[key]->GetPath()) << std::endl;
825 else m_hdirs[key]=dir;
828 if ((enough_rt && calrt) || (enough_t0 && calt0)) {
830 m_resHists[key] =
new TH1F(
"residual",
"residual",m_nbinsres,m_minres,m_maxres);
832 for (
int i=0;i<100;i++) {
833 m_resHists[key]->SetBinContent(i+1,
data[key].
reshist[i]);
834 ncont+=
data[key].reshist[i];
836 m_resHists[key]->SetEntries((
int)
data[key].nres);
837 if (bequiet) m_resHists[key]->SetDirectory(
nullptr);
839 std::cout <<
" No bin content " << std::endl;
841 FitResidual(key,m_resHists[key]);
847 if (prnt) printf(
"Calibrator::calibrate %8s %-14s: \n",m_name.data(),key.data());
853 data[key].rtflag=
true;
856 for (
int i=0;i<4;i++)
data[key].rtpar[i]=
data[key].oldrtpar[i];
857 if (prnt) printf(
"RT << %7i (%8.1e) %8.1e %8.1e %8.1e, %3.2f : ",
data[key].nrt,
data[key].rtpar[0],
data[key].rtpar[1],
data[key].rtpar[2],
data[key].rtpar[3],
data[key].rtt0);
861 if ((calrt && enough_rt) || level==0) {
862 data[key].rtflag=
true;
863 m_rtHists[key] =
new TH2F(
"rt-relation",
"rt-relation",m_nbinst,m_mint,m_maxt,m_nbinsr,m_minr,m_maxr);
864 for (
int i=0;i<m_nbinst;i++) {
865 for (
int j=0;j<m_nbinsr;j++) {
866 m_rtHists[key]->SetBinContent(i+1,j+1,
data[key].
rthist[i+m_nbinst*j]);
869 m_rtHists[key]->SetEntries(
data[key].nrt);
870 if(level<2) std::cout <<
" Calibrator::calibrate do rt fit for key " << key <<
" with number of entries " << m_rtHists[key]->GetEntries() << std::endl;
872 m_rtHists[key]->SetDirectory(
nullptr);
873 if(level<2) std::cout <<
" remove this level from calout.root file " << std::endl;
875 data[key].rtt0=FitRt(key,opt,m_rtHists[key],m_hdirs[key]);
876 if (prnt) printf(
"RT %7i (%8.1e) %8.1e %8.1e %8.1e, %3.2f : ",
data[key].nrt,
data[key].rtpar[0],
data[key].rtpar[1],
data[key].rtpar[2],
data[key]. rtpar[3],
data[key].rtt0);
882 for (
int i=0;i<4;i++)
data[key].rtpar[i]=caldata_above->
rtpar[i];
883 if (prnt) printf(
"RT /\\ %7i (%8.1e) %8.1e %8.1e %8.1e, %3.2f : ",
data[key].nrt,
data[key].rtpar[0],
data[key].rtpar[1],
data[key].rtpar[2],
data[key].rtpar[3],
data[key].rtt0);
892 data[key].t0flag=
true;
896 data[key].t0fittype = 5;
897 if (prnt) printf(
"T0 << %7i %05.2f%+05.2f%+05.2f=%05.2f \n",
data[key].ntres,
data[key].oldt02, 0.0,
data[key].rtt0,
data[key].
t0);
900 if (useref && level==5){
903 data[key].t0flag=
true;
904 data[key].t0=caldata_above->
t0 +
data[key].reft0 +
data[key].rtt0;
906 data[key].t0off=
data[key].t0-caldata_above->
t0;
907 data[key].t0fittype = 3;
908 if (prnt) printf(
"T0 ** %7i %05.2f%+05.2f%+05.2f=%05.2f \n",
data[key].ntres, caldata_above->
t0,
data[key].reft0,
data[key].rtt0,
data[key].t0);
912 if ((calt0 && enough_t0) || level==0) {
913 data[key].t0flag=
true;
914 m_tresHists[key] =
new TH1F(
"timeresidual",
"time residual",m_nbinstres,m_mintres,m_maxtres);
916 for (
int i=0;i<100;i++) {
917 m_tresHists[key]->SetBinContent(i+1,
data[key].m_treshist[i]);
919 m_tresHists[key]->SetEntries(
data[key].ntres);
920 if(level<2) std::cout <<
" Calibrator::calibrate do t0 fit for key " << key <<
" Numb. entries " << m_rtHists[key]->GetEntries() << std::endl;
922 if(level<2) std::cout <<
" Calibrator::calibrate: remove this level from calibout.root " << std::endl;
923 m_tresHists[key]->SetDirectory(
nullptr);
926 data[key].t0=
data[key].oldt02 + FitTimeResidual(key,m_tresHists[key]) +
data[key].rtt0 + m_t0shift;
927 data[key].t0off=
data[key].t0-caldata_above->
t0;
930 if (prnt) printf(
"T0 %7i %05.2f%+05.2f%+05.2f%+05.2f=%05.2f \n",
data[key].ntres,
data[key].oldt02,
data[key].
t0-
data[key].oldt02-
data[key].rtt0,
data[key].rtt0, m_t0shift,
data[key].
t0);
938 if (
data[key].oldt02 + (caldata_above->
t0 - caldata_above->
oldt02) >0)
data[key].t0=
data[key].oldt02 + (caldata_above->
t0 - caldata_above->
oldt02);
939 else data[key].t0= 0;
943 if ((level == 6 && useshortstw) && std::abs(
data[key].det)<2 && (
data[key].lay==0 &&
data[key].stl<9) )
data[key].t0=caldata_above->
t0-0.75;
946 data[key].t0fittype = 4;
947 if (prnt) printf(
"T0 /\\ %7i %05.2f%+05.2f%+05.2f=%05.2f \n",
data[key].ntres, caldata_above->
t0, caldata_above->
oldt02,
data[key].oldt02 ,
data[key].t0);
953 if (prnt && !bequiet) std::cout <<
" H";
955 if (prnt) std::cout << std::endl;
978 if (hist ==
nullptr){
979 std::cout <<
"OUT OF MEMORY!" << std::endl;
990 if (makehist) hist->rthist[i]=0;
992 if (makehist) hist->m_treshist[i]=0;
993 if (makehist) hist->reshist[i]=0;
997 if (binhist==
nullptr){
1000 if (makehist) hist->m_treshist[tresbin]=d.weight;
1005 if (makehist) hist->reshist[resbin]=1;
1009 if (makehist) hist->rthist[rtbin]=1;
1018 if(
level<2) std::cout <<
" Calibrator::AddHit called for key " << key <<
" add histogram with "<< npop <<
" non-zero bins " << std::endl;
1020 for(
int ipop=2;ipop<2*npop+2;ipop=ipop+2) {
1023 value=binhist[ipop+1];
1029 if (makehist) hist->m_treshist[ibin]=(float)value;
1030 hist->sumt0+=d.t0*value;
1032 else if (ibin>=100 && ibin<200) {
1035 if (makehist) hist->reshist[ibin-100]=(float)value;
1040 if (makehist) hist->rthist[ibin-200]=(float)value;
1047 if (
level>0) hist->det=d.det;
else hist->det=-3;
1048 if (
level>1) hist->lay=d.lay;
else hist->lay=-3;
1049 if (
level>2) hist->mod=d.mod;
else hist->mod=-3;
1050 if (
level>3) hist->brd=d.brd;
else hist->brd=-3;
1051 if (
level>4) hist->chp=d.chp;
else hist->chp=-3;
1052 if (
level>5) hist->stw=d.stw;
else hist->stw=-3;
1053 if (
level>2) hist->stl=d.stl;
else hist->stl=-3;
1054 if (
level>5) hist->sid=d.sid;
else hist->sid=-3;
1061 if (
level==5) hist->reft0=d.rt0;
else hist->reft0=0;
1072 hist->oldrtpar[0]=d.rtpar[0];
1073 hist->oldrtpar[1]=d.rtpar[1];
1074 hist->oldrtpar[2]=d.rtpar[2];
1075 hist->oldrtpar[3]=d.rtpar[3];
1083 hist->calflag=
false;
1087 for (
unsigned int i =0; i < 4; i++){
1088 hist->rtpar[i]=-10.0;
1099 if(
level<2) std::cout <<
" First hit for det " <<
data[key].det <<
" lay " <<
data[key].lay <<
" t0 " <<
data[key].t0 <<
" upd t0 " <<
data[key].oldt02 <<
" nhits: " <<
data[key].nhits << std::endl;
1108 if (binhist==
nullptr){
1111 if (makehist)
data[key].m_treshist[tresbin]=
data[key].m_treshist[tresbin]+d.weight;
1116 if (makehist)
data[key].reshist[resbin]++;
1120 if (makehist)
data[key].rthist[rtbin]++;
1124 data[key].sumt0+=d.t0;
1132 for(
int ipop=2;ipop<2*npop+2;ipop=ipop+2) {
1135 value=binhist[ipop+1];
1140 data[key].ntres+=value;
1141 if (makehist)
data[key].m_treshist[ibin]+=(float)value;
1142 data[key].sumt0+=d.t0*value;
1144 else if (ibin>=100 && ibin<200) {
1146 data[key].nres+=value;
1147 if (makehist)
data[key].reshist[ibin-100]+=(float)value;
1151 data[key].nrt+=value;
1152 if (makehist)
data[key].rthist[ibin-200]+=(float)value;
1160 data[key].sumx+=d.x;
1161 data[key].sumy+=d.y;
1162 data[key].sumz+=d.z;
1182 TNtuple* stattup =
new TNtuple(Form(
"%stuple",
m_name.data()),
"statistics",
"det:lay:mod:brd:chp:sid:stl:stw:rtflag:t0flag:t0:oldt0:rt0:dt0:t0offset:ftype:nhits:nt0:nrt:res:resMean:dres:tres:tresMean:x:y:z");
1183 for(std::map<std::string,caldata>::iterator ihist=
data.begin(); ihist!=
data.end(); ++ihist){
1184 if ((ihist->second).calflag) {
1186 float const ntvar[27]={
1187 float((ihist->second).det),
1188 float((ihist->second).lay),
1189 float((ihist->second).mod),
1190 float((ihist->second).brd),
1191 float((ihist->second).chp),
1192 float((ihist->second).sid),
1193 float((ihist->second).stl),
1194 float((ihist->second).stw),
1195 float((
int)(ihist->second).rtflag),
1196 float((
int)(ihist->second).t0flag),
1198 float((ihist->second).oldt02),
1200 (ihist->second).reft0,
1201 (ihist->second).t0err,
1202 (ihist->second).t0off,
1203 float((ihist->second).t0fittype),
1204 (ihist->second).nhits,
1205 (
float)(ihist->second).ntres,
1206 (
float)(ihist->second).nrt,
1207 (
float)(ihist->second).
res,
1208 (
float)(ihist->second).resMean,
1209 (ihist->second).reserr,
1210 (ihist->second).tres,
1211 (ihist->second).tresMean,
1216 stattup->Fill(ntvar);
1227 std::ofstream
dumpfile(
"calib_constants_out.txt", std::ios::out | std::ios::app);
1229 for (
const std::pair<const std::string, caldata>& p :
data) {
1230 dumpfile << p.first <<
" " << p.second.t0 <<
" " << std::endl;
double trrel_dines(double *x, double *par)
double pol3deg2(double *x, double *par)
double pol3deg(double *x, double *par)
double rtrel_dines(double *x, double *par)
float reshist[100]
the 1D residual histogram (100 bins)
float rthist[640]
the 2D rt histogram (20x32 bins)
std::ofstream dumpfile("dumpfile.log")
char data[hepevt_bytes_allocation_ATLAS]
std::pair< std::vector< unsigned int >, bool > res
TGraphErrors * GetEntries(TH2F *histo)
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
bool not0
if true the old t0 valus is copied to the new one
bool printrt
if true an rt entry in the calibration output file is prined for each sub-module in this sub-level
std::set< int > selection
a set containing the sub-modules to be calibrated
int m_nbinsres
number of bins in the 1D residual histogram
bool nort
if true the old rt parameters are copied to the new ones
bool dort
if true an rt fit is made, if false the value from the level above is used
int m_nbinstres
number of bins in the 1D time residual histogram
bool usep0
if true the 0th order coeficcient of the rt fit function is not set to 0 in the calibration output fi...
float m_mint
lower limit of t in 2D rt histogram
int Simple1dHist(float, float, int, float)
A 1D histograming function.
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 ...
std::string GetOptString() const
Creates a string summarizing what is being done at this sub-level.
float m_maxt
upper limit of t in 2D rt histogram
bool floatp3
if true the 3rd order coeficcient of the rt fit function is not fixed to 0
std::map< std::string, caldata > data
A map between the sub-module identifier string and the calibration data structure (caldata)
std::string GetBinnedRt(const std::string &)
bool printlog
if true a log entry is prined for each sub-modile in this sub-level
bool HasKey(const std::string &) const
...
int UpdateOldConstants()
...
int level
the sub-level of the Calibrator instance
float m_maxres
upper limit of 1D residual histogram
bool useshortstraws
if true a shift of -0.75 ns is applied for straws in layer ==0, strawlayer < 9, and when doing calibr...
int m_nbinsr
number of r-bins in the 2D rt histogram
float AccumulativeMean(float, float, float)
Increments a single bin in all three histograms in a sub-module.
int m_minrtstat
minimum number of hits in a sub-module required to do an R-t calibration
float m_maxtres
upper limit of 1D time residual histogram
bool dot0
if true a time residual fit is made, if false the value from the level above is used
int Simple2dHist(float, float, int, float, float, int, float, float)
A 2D histograming function.
float m_t0shift
the t0 shift
float m_maxr
upper limit of r in 2D rt histogram
std::string GetSelString()
Creates a string summarizing which modules are being calibrated at this sub-level.
float m_mintres
lower limit of 1D time residual histogram
std::string m_name
The name of the Calibrator instance.
void WriteStat(TDirectory *)
Creates an ntuple with entries containing data associated with the sub-modules in a sub level.
int m_nbinst
number of t-bins in the 2D rt histogram
std::string m_rtbinning
The direction to do the R-t binning.
bool printt0
if true a t0 entry in the calibration output file is prined for each sub-module in this sub-level
bool bequiet
if true no histograms are written to the root file
float m_minr
lower limit of r in 2D rt histogram
std::string PrintStat()
Prints some sub-level statistics.
bool dores
if true a residual fit is made
float m_minres
lower limit of 1D residual histogram
bool usebref
if true chip reference t0 values (offset from board mean) are used
bool m_isdines
true if the rt relation is Dines'
bool CheckSelection(int)
Checks if a given sub-module is selected for calibration.
int m_mint0stat
minimum number of hits in a sub-module required to do a t0 calibration
A class for generating a r-t and t-r graphs by binning the 2D histograms in Calibrator::rtHists in r ...
TGraphErrors * trgr
the t(r) graph
std::string m_chname
the histogram name
TGraphErrors * rtgr
the r(t) graph
std::string m_chtit
the histogram title
std::vector< double > rval
array of the histograms for all bins
RtGraph(TH2F *, int, const char *, bool, TDirectory *)
the constructor
int npoints
the number of graph points
std::vector< double > tval
the r values
float mintime
the minimum t-value
A structure to contain data associated with the calibration of a certain sub-module.
int nrt
number of rt histogram entries
int stw
straw number (within the strawlayer)
std::vector< float > m_treshist
the 1D time residual histogram (100 bins)
float reft0
the reference t0 (offset from board mean)
int det
detector (barrel or end-cap)
int ntres
number of time residual histogram entries
float t0err
the new to error
float reserr
the residual error
float y
sub-module y position (average of all straws in the module)
float rtt0
the t0 fron the R-t fit
float tres
the time residual
float z
sub-module z position (average of all straws in the module)
std::vector< float > reshist
the 1D residual histogram (100 bins)
bool rtflag
flag indicating if an R-t calibration has been made
bool calflag
flag indicating if any calibration has been made
bool t0flag
flag indicating if a t0 calibration has been made
float x
sub-module x position (average of all straws in the module)
int nres
number of residual histogram entries
float tresMean
the time residual mean
RtGraph * rtgraph
the rt graph
float t0off
the t0 offset from the level below
float resMean
the residual mean
std::vector< float > rthist
the 2D rt histogram (20x32 bins)
std::array< float, 4 > rtpar
the new rt-parameters
int t0fittype
the type of time residual fit that was made
double oldt02
the old sub-module t0 (average of t0 for all straws in the module)
float nhits
the number of straws in the sub-module
A structure to contain hit data.
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
std::string find(const std::string &s)
return a remapped string