15 #include "TMultiGraph.h"
20 #include "TClonesArray.h"
28 #include "TSpectrum.h"
29 #include "TSpectrum2.h"
30 #include "Math/Minimizer.h"
31 #include "Math/Factory.h"
32 #include "Math/Functor.h"
35 #include "TPaveStats.h"
36 #include "TObjString.h"
37 #include "TApplication.h"
40 #include <TPaletteAxis.h>
45 #include "TFitResult.h"
52 #if defined(prt__sim) || defined(prt__beam) || defined(eic__sim)
57 PrtEvent* prt_event = 0;
60 #if defined(prt__sim) || defined(prt__beam)
62 DataInfo prt_data_info;
82 TString
prt_tdcsid_may2015[] ={
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
"2006",
"2007",
"2008",
"2009",
83 "200a",
"200b",
"200c",
"200d",
"200e",
"200f",
"2010",
"2011",
"2012",
"2013",
84 "2014",
"2015",
"2016",
"2018",
"2019",
"201a",
"201c",
"2020",
"2023",
"2024",
85 "2025",
"2026",
"2027",
"2028",
"2029",
"202a",
"202b",
"202c",
"202d",
"202e",
"202f"
90 TString
prt_tdcsid_jun2015[] ={
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
"2006",
"2007",
"2008",
"2009",
91 "200a",
"200b",
"200c",
"200d",
"200e",
"200f",
"2010",
"2011",
"2012",
"2013",
92 "2014",
"2015",
"2016",
"2018",
"2019",
"201a",
"201c",
"201d",
"202c",
"202d"
97 TString
prt_tdcsid_oct2016[] ={
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
"2006",
"2007",
"2008",
"2009",
99 "2018",
"201b",
"201c",
"201f",
"202c",
"202d",
"202d"
104 TString
prt_tdcsid_jul2018 [] ={
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
"2006",
"2007",
"2008",
"2009",
"200a",
"200b",
"200c",
"200d",
"200e",
"200f",
"2010",
"2011",
"2012",
"2013",
105 "2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"201a",
"201b",
106 "201c",
"201d",
"201e",
"201f"
111 TString
prt_tdcsid_jul2019[] ={
"2014",
"2015",
"2016",
"2017",
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
112 "2006",
"2007",
"2008",
"2009",
"200a",
"200b",
"200c",
"200d",
"200e",
"200f",
140 double prt_mass[]={0.000511,0.1056584,0.139570,0.49368,0.9382723};
141 TString
prt_name[]={
"e",
"muon",
"pion",
"kaon",
"proton"};
143 int prt_color[]={kOrange+6,kCyan+1,kBlue+1,kRed+1,kRed+1};
147 TVector3
prt_fit(TH1 *
h,
double range = 3,
double threshold=20,
double limit=2,
int peakSearch=1,
int bkg = 0, TString opt=
"MQ"){
148 int binmax = h->GetMaximumBin();
149 double xmax = h->GetXaxis()->GetBinCenter(binmax);
150 if(bkg==0)
prt_gaust =
new TF1(
"prt_gaust",
"[0]*exp(-0.5*((x-[1])/[2])^2)",xmax-range,xmax+range);
151 else if(bkg==1)
prt_gaust =
new TF1(
"prt_gaust",
"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]+x*[4]",xmax-range,xmax+range);
153 prt_gaust->SetParNames(
"const",
"mean",
"sigma");
155 double integral = h->Integral(h->GetXaxis()->FindBin(xmax-range),h->GetXaxis()->FindBin(xmax+range));
156 double xxmin, xxmax, sigma1(0), mean1(0), mean2(0);
160 if(integral>threshold){
166 h->Fit(
"prt_gaust",opt,
"",xxmin-range, xxmax+range);
170 nfound =
prt_spect->Search(h,4,
"goff",0.1);
171 std::cout<<
"nfound "<<nfound <<std::endl;
173 prt_gaust =
new TF1(
"prt_gaust",
"gaus(0)",xmax-range,xmax+range);
177 double p1 =
prt_spect->GetPositionX()[0];
178 double p2 =
prt_spect->GetPositionX()[1];
188 prt_gaust =
new TF1(
"prt_gaust",
"gaus(0)",xxmin-range,xxmin+range);
192 prt_gaust =
new TF1(
"prt_gaust",
"gaus(0)+gaus(3)",xmax-range,xmax+range);
201 h->Fit(
"prt_gaust",opt,
"",xxmin-range, xxmax+range);
211 h->Fit(
"prt_gaust",opt,
"",xxmin-range, xxmax+range);
214 if(sigma1>10) sigma1=10;
222 return TVector3(mean1,sigma1,mean2);
225 TGraph *
prt_fitslices(TH2F *
hh,
double minrange=0,
double maxrange=0,
double fitrange=1,
int rebin=1,
int ret=0){
226 TH2F *
h =(TH2F*) hh->Clone(
"h");
229 TGraph *gres =
new TGraph();
230 for (
int i=1;i<h->GetNbinsY();i++){
231 double x = h->GetYaxis()->GetBinCenter(i);
233 if(minrange!=maxrange){
234 TCutG *cut =
new TCutG(
"prt_onepeakcut",5);
237 cut->SetPoint(0,minrange,-1E6);
238 cut->SetPoint(1,minrange, 1E6);
239 cut->SetPoint(2,maxrange, 1E6);
240 cut->SetPoint(3,maxrange,-1E6);
241 cut->SetPoint(4,minrange,-1E6);
243 hp = h->ProjectionX(Form(
"bin%d",i),i,i,
"[prt_onepeakcut]");
245 hp = h->ProjectionX(Form(
"bin%d",i),i,i);
248 TVector3 res =
prt_fit((TH1F*)hp,fitrange,100,2,1,1);
250 if(ret==0) y = res.X();
251 if(ret==1) y = res.Y();
252 if(ret==2) y = res.X() + 0.5*res.Y();
253 if(ret==3) y = res.X() - 0.5*res.Y();
254 if(y==0 || y<minrange || y>maxrange)
continue;
256 gres->SetPoint(point,y,x);
257 gres->SetLineWidth(2);
258 gres->SetLineColor(kRed);
280 TGaxis::SetMaxDigits(4);
283 int dec = TString::BaseConvert(
prt_tdcsid[i],16,10).Atoi();
291 int col = pix/2 - 8*(pix/16);
292 int row = pix%2 + 2*(pix/16);
302 for(
int i=0; i<5; i++){
312 for(
int i=0; i<=tdc; i++){
313 if(i==tdc && (i==2 || i==6 || i==10 || i==14)) ch += tdcChannel-32;
314 else if(i==tdc) ch += tdcChannel;
315 else if(i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) ch += 16;
319 ch = 32*tdc+tdcChannel;
321 ch = 48*tdc+tdcChannel;
331 if(i==2 || i==6 || i==10 || i==14) tch += 16;
332 else if(i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) tch += 16;
353 if(i==2 || i==6 || i==10 || i==14 || i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) tch += 16;
368 return ch - tdcSeqId;
372 return ch + tdcSeqId;
394 static const char alphanum[] =
396 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
397 "abcdefghijklmnopqrstuvwxyz";
399 for (
int i = 0; i <
len; ++i) {
400 str += alphanum[rand() % (
sizeof(alphanum) - 1)];
426 if(cdigi) cdigi->cd();
427 else cdigi =
new TCanvas(
"hp="+sid,
"hp_"+sid,800,400);
432 if(layoutId==2015 || layoutId==5) prt_hpglobal =
new TPad(sid,
"T",0.04,0.04,0.88,0.96);
433 else if(layoutId==2021) prt_hpglobal =
new TPad(sid,
"T",0.12,0.02,0.78,0.98);
434 else if(layoutId==2016) prt_hpglobal =
new TPad(sid,
"T",0.2,0.02,0.75,0.98);
435 else if(layoutId==2017) prt_hpglobal =
new TPad(sid,
"T",0.15,0.02,0.80,0.98);
436 else if(layoutId==2018) prt_hpglobal =
new TPad(sid,
"T",0.05,0.07,0.9,0.93);
437 else if(layoutId==2023) prt_hpglobal =
new TPad(sid,
"T",0.073,0.02,0.877,0.98);
438 else if(layoutId==2030) prt_hpglobal =
new TPad(sid,
"T",0.10,0.025,0.82,0.975);
439 else if(layoutId==2032) prt_hpglobal =
new TPad(sid,
"T",0.04,0.025,0.91,0.975);
440 else if(layoutId==2031) prt_hpglobal =
new TPad(sid,
"T",0.12,0.01,0.80,0.99);
441 else prt_hpglobal =
new TPad(sid,
"T",0.04,0.04,0.96,0.96);
443 prt_hpglobal->SetFillStyle(0);
444 prt_hpglobal->Draw();
447 int nrow = 3, ncol = 5;
448 if(layoutId ==2016) ncol=3;
449 if(layoutId ==2017) ncol=4;
450 if(layoutId ==2018 || layoutId ==2023) {nrow=2; ncol=4;}
451 if(layoutId ==2021) ncol=4;
452 if(layoutId ==2030) {nrow=4; ncol=6;}
453 if(layoutId ==2032) {nrow=4; ncol=7;}
454 if(layoutId ==2031) {nrow=3; ncol=4;}
457 float tbw(0.02), tbh(0.01), shift(0),shiftw(0.02),shifth(0),margin(0.01);
460 for(
int i=0; i<ncol; i++){
461 for(
int j=0; j<nrow; j++){
462 if(j==1) shift = -0.028;
465 if(layoutId == 5) {shift =0; shiftw=0.001; tbw=0.001; tbh=0.001;}
466 if(layoutId == 2021) {
467 if(i==0 && j == nrow-1)
continue;
468 shift =0; shiftw=0.001; tbw=0.001; tbh=0.001;
469 if(i==0) shifth=0.167;
471 if(layoutId == 2016) {
472 shift = -0.01; shiftw=0.01; tbw=0.03; tbh=0.006;
473 if(j==1) shift += 0.015;
475 if(layoutId == 2017) {
477 shift = 0; shiftw=0.01; tbw=0.005; tbh=0.006;
480 if(layoutId == 2018) {
482 shift = 0; shiftw=0.01; tbw=0.005; tbh=0.006;
484 if(layoutId == 2023) {
486 shift = 0; shiftw=0.01; tbw=0.0015; tbh=0.042;
488 if(layoutId == 2030) {
490 shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
493 if(layoutId == 2032) {
495 shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
498 if(layoutId == 2031) {
500 shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
504 prt_hpads[padi] =
new TPad(sid+Form(
"P%d",i*10+j),
"T",
505 i/(ncol+2*margin)+tbw+shift+shiftw,
506 j/(
double)nrow+tbh+shifth,
507 (i+1)/(ncol+2*margin)-tbw+shift+shiftw,
508 (1+j)/(
double)nrow-tbh+shifth, 21);
509 prt_hpads[padi]->SetFillColor(kCyan-8);
510 prt_hpads[padi]->SetMargin(0.055,0.055,0.055,0.055);
511 prt_hpads[padi]->Draw();
516 float tbw(0.02), tbh(0.01), shift(0),shiftw(-0.02);
518 for(
int ii=0; ii<ncol; ii++){
519 for(
int j=0; j<nrow; j++){
520 if(j==1) shift = 0.04;
522 prt_hpads[padi] =
new TPad(Form(
"P%d",ii*10+j),
"T", ii/(
double)ncol+tbw+shift+shiftw , j/(
double)nrow+tbh, (ii+1)/(
double)ncol-tbw+shift+shiftw, (1+j)/(
double)nrow-tbh, 21);
523 prt_hpads[padi]->SetFillColor(kCyan-8);
524 prt_hpads[padi]->SetMargin(0.04,0.04,0.04,0.04);
525 prt_hpads[padi]->Draw();
537 for(
int p=0;
p<nrow*ncol;
p++){
539 if(max<tmax) max = tmax;
546 for(
int p=0;
p<nrow*ncol;
p++){
548 if(max<tmax) max = tmax;
551 TH1F *
h =
new TH1F(
"",
"",tbins,0,max);
552 for(
int p=0;
p<nrow*ncol;
p++){
553 for(
int i=0; i<8; i++){
554 for(
int j=0; j<8; j++){
555 double val =
prt_hdigi[
p]->GetBinContent(i+1,j+1);
556 if(val!=0) h->Fill(val);
562 for(
int i=0; i<tbins; i++){
563 integral = h->Integral(0,i);
565 if(
minz==-2)
minz = h->GetBinCenter(i);
570 for(
int i=tbins; i>0; i--){
571 integral = h->Integral(i,tbins);
573 if(
maxz==-2) max = h->GetBinCenter(i);
582 for(
int p=0;
p<nrow*ncol;
p++){
583 if(layoutId == 1 || layoutId == 4) np =
p%nrow*ncol +
p/3;
586 if(layoutId == 6 &&
p>10)
continue;
603 TPaletteAxis* prt_cdigi_palette;
604 if(layoutId==2018 || layoutId==2023) prt_cdigi_palette =
new TPaletteAxis(0.89,0.1,0.93,0.90,(TH1 *)
prt_hdigi[nnmax]);
605 else if(layoutId==2032) prt_cdigi_palette =
new TPaletteAxis(0.91,0.1,0.94,0.90,(TH1 *)
prt_hdigi[nnmax]);
606 else prt_cdigi_palette =
new TPaletteAxis(0.82,0.1,0.86,0.90,(TH1 *)
prt_hdigi[nnmax]);
607 prt_cdigi_palette->SetName(
"prt_palette");
608 prt_cdigi_palette->Draw();
617 int nrow = 3, ncol = 5, np,
nmax=0, npix=8;
618 if(layoutId ==2016) ncol=3;
619 if(layoutId ==2017) ncol=4;
620 if(layoutId ==2018 || layoutId ==2023) {nrow=2; ncol=4;}
621 if(layoutId ==2021) ncol=4;
622 if(layoutId ==2030) {nrow=4; ncol=6; npix=16;}
623 if(layoutId ==2032) {nrow=4; ncol=7; npix=16;}
624 if(layoutId ==2031) {nrow=3; ncol=4; npix=16;}
627 for(
int p=0;
p<nrow*ncol;
p++){
628 if(layoutId == 1 || layoutId == 4) np =
p%nrow*ncol +
p/3;
629 else if(layoutId == 2030) np =
p%ncol*nrow +
p/ncol;
636 for(
int i=1; i<=npix; i++){
637 for(
int j=1; j<=npix; j++){
639 if(weight>255) weight=255;
640 if(weight > 0)
s += Form(
"%d,%d,%d\n", np, (i-1)*npix+j-1, (
int)weight);
652 prt_hdigi[
m] =
new TH2F( Form(
"mcp%d", m),Form(
"mcp%d", m),8,0.,8.,8,0.,8.);
657 prt_hdigi[
m]->GetXaxis()->SetLabelOffset(100);
658 prt_hdigi[
m]->GetYaxis()->SetLabelOffset(100);
670 prt_hdigi[
m] =
new TH2F( Form(
"mcp%d", m),Form(
"mcp%d", m),16,0,16,16,0,16);
675 prt_hdigi[
m]->GetXaxis()->SetLabelOffset(100);
676 prt_hdigi[
m]->GetYaxis()->SetLabelOffset(100);
694 hist->SetTitle(Form(
"%d hits",(
int)hist->GetEntries()));
695 hist->GetXaxis()->SetTitle(
"z, [cm]");
696 hist->GetXaxis()->SetTitleSize(0.05);
697 hist->GetXaxis()->SetTitleOffset(0.8);
698 hist->GetYaxis()->SetTitle(
"y, [cm]");
699 hist->GetYaxis()->SetTitleSize(0.05);
700 hist->GetYaxis()->SetTitleOffset(0.7);
705 hist->SetTitle(Form(
"%d hits",(
int)hist->GetEntries()));
706 hist->GetXaxis()->SetTitle(
"#theta, [degree]");
707 hist->GetXaxis()->SetTitleSize(0.05);
708 hist->GetXaxis()->SetTitleOffset(0.8);
709 hist->GetYaxis()->SetTitle(
"photons per track, [#]");
710 hist->GetYaxis()->SetTitleSize(0.05);
711 hist->GetYaxis()->SetTitleOffset(0.7);
716 hist->SetTitle(Form(
"%d hits",(
int)hist->GetEntries()));
717 hist->GetXaxis()->SetTitle(
"#theta, [degree]");
718 hist->GetXaxis()->SetTitleSize(0.05);
719 hist->GetXaxis()->SetTitleOffset(0.8);
720 hist->GetYaxis()->SetTitle(
"photons per track, [#]");
721 hist->GetYaxis()->SetTitleSize(0.05);
722 hist->GetYaxis()->SetTitleOffset(0.7);
726 hist->GetXaxis()->SetTitle(
"time, [ns]");
727 hist->GetXaxis()->SetTitleSize(0.05);
728 hist->GetXaxis()->SetTitleOffset(0.8);
729 hist->GetYaxis()->SetTitle(
"entries, #");
730 hist->GetYaxis()->SetTitleSize(0.05);
731 hist->GetYaxis()->SetTitleOffset(0.7);
732 hist->SetLineColor(1);
736 TGaxis::SetMaxDigits(3);
737 hist->GetXaxis()->SetTitle(xtitle);
738 hist->GetXaxis()->SetTitleSize(0.06);
739 hist->GetXaxis()->SetTitleOffset(0.8);
740 hist->GetXaxis()->SetLabelSize(0.05);
741 hist->GetYaxis()->SetTitle(
"entries [#]");
742 hist->GetYaxis()->SetTitleSize(0.06);
743 hist->GetYaxis()->SetTitleOffset(0.7);
744 hist->GetYaxis()->SetLabelSize(0.05);
745 hist->SetLineColor(1);
750 gStyle->SetCanvasColor(0);
751 gStyle->SetCanvasBorderMode(0);
752 gStyle->SetCanvasBorderSize(0);
755 gStyle->SetFrameFillColor(0);
756 gStyle->SetFrameBorderMode(0);
757 gStyle->SetFrameBorderSize(0);
760 gStyle->SetTitleX(0.1);
761 gStyle->SetTitleW(0.8);
762 gStyle->SetTitleBorderSize(0);
763 gStyle->SetTitleFillColor(0);
766 gStyle->SetTitleFont(42,
"xyz");
767 gStyle->SetTitleFont(42,
"pad");
768 gStyle->SetLabelFont(42,
"xyz");
769 gStyle->SetLabelFont(42,
"pad");
772 gStyle->SetStatColor(0);
773 gStyle->SetStatFont(42);
774 gStyle->SetStatBorderSize(1);
775 gStyle->SetStatX(0.975);
776 gStyle->SetStatY(0.9);
782 int prt_coll[]={kBlack,kRed+1,kGreen, kBlue, 4,kCyan-6,kOrange, 7,8,9,10,1,1,1};
783 int prt_colm[]={kBlack,kRed+1,kGreen+2,kBlue+1,4,kCyan-6,kOrange+1,7,8,9,10,1,1,1};
785 int cl=(
id<10)? prt_coll[
id]:
id;
786 int cm=(
id<10)? prt_colm[
id]:
id;
788 g->SetMarkerColor(cm);
789 g->SetMarkerStyle(20);
790 g->SetMarkerSize(0.8);
791 g->SetName(Form(
"gr_%d",
id));
812 const int NCont = 255;
813 gStyle->SetNumberContours(NCont);
815 if (pal < 1 && pal> 15)
return;
818 double stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
819 double red[15][NRGBs] = {{ 0.00, 0.00, 0.87, 1.00, 0.51 },
820 { 0.51, 1.00, 0.87, 0.00, 0.00 },
821 { 0.17, 0.39, 0.62, 0.79, 1.00 },
822 { 1.00, 0.79, 0.62, 0.39, 0.17 },
823 { 0.00, 0.00, 0.00, 0.38, 1.00 },
824 { 1.00, 0.38, 0.00, 0.00, 0.00 },
825 { 0.00, 0.50, 0.89, 0.95, 1.00 },
826 { 1.00, 0.95, 0.89, 0.50, 0.00 },
827 { 0.00, 0.00, 0.38, 0.75, 1.00 },
828 { 0.00, 0.34, 0.61, 0.84, 1.00 },
829 { 0.75, 1.00, 0.24, 0.00, 0.00 },
830 { 0.00, 0.00, 0.24, 1.00, 0.75 },
831 { 0.00, 0.34, 0.61, 0.84, 1.00 },
832 { 1.00, 0.84, 0.61, 0.34, 0.00 },
833 { 0.00, 0.00, 0.80, 1.00, 0.80 }
835 double green[15][NRGBs] = {{ 0.00, 0.81, 1.00, 0.20, 0.00 },
836 { 0.00, 0.20, 1.00, 0.81, 0.00 },
837 { 0.01, 0.02, 0.39, 0.68, 1.00 },
838 { 1.00, 0.68, 0.39, 0.02, 0.01 },
839 { 0.00, 0.00, 0.38, 0.76, 1.00 },
840 { 1.00, 0.76, 0.38, 0.00, 0.00 },
841 { 0.00, 0.00, 0.27, 0.71, 1.00 },
842 { 1.00, 0.71, 0.27, 0.00, 0.00 },
843 { 0.00, 0.35, 0.62, 0.85, 1.00 },
844 { 1.00, 0.75, 0.38, 0.00, 0.00 },
845 { 0.24, 1.00, 0.75, 0.18, 0.00 },
846 { 0.00, 0.18, 0.75, 1.00, 0.24 },
847 { 0.00, 0.34, 0.61, 0.84, 1.00 },
848 { 1.00, 0.84, 0.61, 0.34, 0.00 },
849 { 0.00, 0.85, 1.00, 0.30, 0.00 }
851 double blue[15][NRGBs] = {{ 0.51, 1.00, 0.12, 0.00, 0.00 },
852 { 0.00, 0.00, 0.12, 1.00, 0.51 },
853 { 0.00, 0.09, 0.18, 0.09, 0.00 },
854 { 0.00, 0.09, 0.18, 0.09, 0.00 },
855 { 0.00, 0.47, 0.83, 1.00, 1.00 },
856 { 1.00, 1.00, 0.83, 0.47, 0.00 },
857 { 0.00, 0.00, 0.00, 0.40, 1.00 },
858 { 1.00, 0.40, 0.00, 0.00, 0.00 },
859 { 0.00, 0.00, 0.00, 0.47, 1.00 },
860 { 1.00, 0.47, 0.00, 0.00, 0.00 },
861 { 0.00, 0.62, 1.00, 0.68, 0.12 },
862 { 0.12, 0.68, 1.00, 0.62, 0.00 },
863 { 0.00, 0.34, 0.61, 0.84, 1.00 },
864 { 1.00, 0.84, 0.61, 0.34, 0.00 },
865 { 0.60, 1.00, 0.10, 0.00, 0.00 }
869 TColor::CreateGradientColorTable(NRGBs, stops, red[pal], green[pal], blue[pal], NCont);
873 #if defined(prt__sim) || defined(eic__sim)
874 bool prt_init(TString inFile=
"../build/hits.root",
int bdigi=0, TString savepath=
"",
int setupid = 2019){
876 if(inFile==
"" || gSystem->AccessPathName(inFile))
return false;
882 prt_ch =
new TChain(
"data");
885 prt_ch->SetBranchAddress(
"PrtEvent", &prt_event);
888 std::cout<<
"Entries in chain: "<<
prt_entries <<std::endl;
893 void prt_nextEvent(
int ievent,
int printstep){
895 if(ievent%printstep==0 && ievent!=0) std::cout<<
"Event # "<<ievent<<
" # hits "<<prt_event->GetHitSize()<<std::endl;
897 if(gROOT->GetApplication()){
898 TIter next(gROOT->GetApplication()->InputFiles());
900 while((os = (TObjString*)next())){
906 prt_mom = prt_event->GetMomentum().Mag() +0.01;
916 if(prt_event->GetParticle()<3000 && prt_event->GetParticle()>0){
923 bool prt_init(TString inFile=
"../build/hits.root",
int bdigi=0, TString savepath=
"",
int setupid=2019){
925 if(inFile==
"")
return false;
932 prt_ch =
new TChain(
"data");
935 prt_ch->SetBranchAddress(
"PrtEvent", &prt_event);
943 prt_ch->SetBranchStatus(
"fHitArray.fParentParticleId", 0);
944 prt_ch->SetBranchStatus(
"fHitArray.fNreflectionsInPrizm", 0);
945 prt_ch->SetBranchStatus(
"fHitArray.fPathInPrizm", 0);
946 prt_ch->SetBranchStatus(
"fHitArray.fCherenkovMC", 0);
948 prt_ch->SetBranchStatus(
"fPosition", 0);
951 std::cout<<
"Entries in chain: "<<
prt_entries <<std::endl;
956 void prt_nextEvent(
int ievent,
int printstep){
958 if(ievent%printstep==0 && ievent!=0) cout<<
"Event # "<<ievent<<
" # hits "<<prt_event->GetHitSize()<<endl;
960 if(gROOT->GetApplication()){
962 TIter next(gROOT->GetApplication()->InputFiles());
964 while((os = (TObjString*)next())){
970 prt_mom = prt_event->GetMomentum().Mag() +0.01;
980 if(prt_event->GetParticle()<3000 && prt_event->GetParticle()>0){
991 if(cid==3) cid =kOrange+2;
993 if(style==1) cid=ind+300;
998 int bins=hist->GetXaxis()->GetNbins();
999 double xmin=hist->GetXaxis()->GetBinLowEdge(1);
1000 double xmax=hist->GetXaxis()->GetBinUpEdge(bins);
1001 double_shift=double_shift*(bins/(xmax-
xmin));
1003 if(double_shift<0) shift=TMath::FloorNint(double_shift);
1004 if(double_shift>0) shift=TMath::CeilNint(double_shift);
1005 if(shift==0)
return 0;
1007 for(
int i=1; i<=bins; i++){
1008 if(i+shift<=bins) hist->SetBinContent(i,hist->GetBinContent(i+shift));
1009 if(i+shift>bins) hist->SetBinContent(i,0);
1014 for(
int i=bins; i>0; i--){
1015 if(i+shift>0) hist->SetBinContent(i,hist->GetBinContent(i+shift));
1016 if(i+shift<=0) hist->SetBinContent(i,0);
1028 std::ofstream myfile;
1029 myfile.open (filename);
1035 std::ofstream myfile;
1036 myfile.open (filename);
1039 std::cout<<
"output: "<<filename<<std::endl;
1046 if(finalpath ==
"")
return "";
1050 gSystem->mkdir(dir);
1051 TDatime *
time =
new TDatime();
1052 TString path(
""), stime = Form(
"%d.%d.%d", time->GetDay(),time->GetMonth(),time->GetYear());
1053 gSystem->mkdir(dir+
"/"+stime);
1054 for(
int i=0; i<1000; i++){
1055 path = stime+
"/"+Form(
"arid-%d",i);
1056 if(gSystem->mkdir(dir+
"/"+path)==0)
break;
1058 gSystem->Unlink(dir+
"/last");
1059 gSystem->Symlink(path, dir+
"/last");
1060 finalpath = dir+
"/"+path;
1073 c->Print(path+
"/"+
name+
".png");
1074 if(what>0) c->Print(path+
"/"+
name+
".C");
1075 if(what>1) c->Print(path+
"/"+
name+
".pdf");
1076 if(what>2) c->Print(path+
"/"+
name+
".eps");
1081 if(fabs(c->GetBottomMargin()-0.1)<0.001) c->SetBottomMargin(0.12);
1082 TIter next(c->GetListOfPrimitives());
1085 while((obj = next())){
1086 if(obj->InheritsFrom(
"TH1")){
1087 TH1F *
hh = (TH1F*)obj;
1088 hh->GetXaxis()->SetTitleSize(0.06);
1089 hh->GetYaxis()->SetTitleSize(0.06);
1091 hh->GetXaxis()->SetLabelSize(0.05);
1092 hh->GetYaxis()->SetLabelSize(0.05);
1094 hh->GetXaxis()->SetTitleOffset(0.85);
1095 hh->GetYaxis()->SetTitleOffset(0.76);
1097 if(c->GetWindowHeight()>700){
1098 hh->GetXaxis()->SetTitleSize(0.045);
1099 hh->GetYaxis()->SetTitleSize(0.045);
1101 hh->GetXaxis()->SetLabelSize(0.035);
1102 hh->GetYaxis()->SetLabelSize(0.035);
1104 hh->GetXaxis()->SetTitleOffset(0.85);
1105 hh->GetYaxis()->SetTitleOffset(0.98);
1106 c->SetRightMargin(0.12);
1109 if(c->GetWindowWidth()<=600){
1110 hh->GetXaxis()->SetTitleSize(0.05);
1111 hh->GetYaxis()->SetTitleSize(0.05);
1113 hh->GetXaxis()->SetLabelSize(0.04);
1114 hh->GetYaxis()->SetLabelSize(0.04);
1116 hh->GetXaxis()->SetTitleOffset(0.85);
1117 hh->GetYaxis()->SetTitleOffset(0.92);
1118 c->SetRightMargin(0.12);
1122 if(fabs(c->GetBottomMargin()-0.12)<0.001){
1123 TPaletteAxis *palette = (TPaletteAxis*)hh->GetListOfFunctions()->FindObject(
"palette");
1125 palette->SetY1NDC(0.12);
1133 if(obj->InheritsFrom(
"TGraph")){
1134 TGraph *gg = (TGraph*)obj;
1135 gg->GetXaxis()->SetLabelSize(0.05);
1136 gg->GetXaxis()->SetTitleSize(0.06);
1137 gg->GetXaxis()->SetTitleOffset(0.84);
1139 gg->GetYaxis()->SetLabelSize(0.05);
1140 gg->GetYaxis()->SetTitleSize(0.06);
1141 gg->GetYaxis()->SetTitleOffset(0.8);
1144 if(obj->InheritsFrom(
"TMultiGraph")){
1145 TMultiGraph *gg = (TMultiGraph*)obj;
1146 gg->GetXaxis()->SetLabelSize(0.05);
1147 gg->GetXaxis()->SetTitleSize(0.06);
1148 gg->GetXaxis()->SetTitleOffset(0.84);
1150 gg->GetYaxis()->SetLabelSize(0.05);
1151 gg->GetYaxis()->SetTitleSize(0.06);
1152 gg->GetYaxis()->SetTitleOffset(0.8);
1155 if(obj->InheritsFrom(
"TF1")){
1162 void prt_save(TPad *
c= NULL,TString path=
"",
int what=0,
int style=0){
1163 TString
name =
c->GetName();
1164 Bool_t batch = gROOT->IsBatch();
1167 if(
c && path !=
"") {
1168 int w = 800,
h = 400;
1170 if(style == 1) {w = 800;
h = 500;}
1171 if(style == 2) {w = 800;
h = 600;}
1172 if(style == 3) {w = 800;
h = 400;}
1173 if(style == 5) {w = 800;
h = 900;}
1175 w = ((TCanvas*)
c)->GetWindowWidth();
1176 h = ((TCanvas*)
c)->GetWindowHeight();
1180 if(TString(
c->GetName()).Contains(
"hp") || TString(
c->GetName()).Contains(
"cdigi")) {
1182 cc->SetCanvasSize(800,400);
1183 if(name.Contains(
"=")) name = name.Tokenize(
'=')->First()->GetName();
1185 cc =
new TCanvas(TString(
c->GetName())+
"exp",
"cExport",0,0,w,
h);
1186 cc = (TCanvas*)
c->DrawClone();
1187 cc->SetCanvasSize(w,
h);
1194 c->SetCanvasSize(w,
h);
1199 gROOT->SetBatch(batch);
1203 gSystem->mkdir(
dir);
1210 TIter next(prt_canvaslist);
1212 while((c = (TCanvas*) next())){
1213 if(c->GetName()==
name ||
name==
"*")
break;
1220 if(!prt_canvaslist) prt_canvaslist =
new TList();
1222 prt_canvaslist->Add(c);
1227 if(!prt_canvaslist) prt_canvaslist =
new TList();
1229 prt_canvaslist->Add(c);
1237 TIter next(prt_canvaslist);
1239 while((c = (TCanvas*) next())){
1240 if(c->GetName()==
name ||
name==
"*") prt_canvaslist->Remove(c);
1252 TIter next(prt_canvaslist);
1255 while((c = (TCanvas*) next())){
1259 prt_canvaslist->Remove(c);
1272 TIter next(prt_canvaslist);
1275 while((c = (TCanvas*) next())){
1281 TIter next(prt_canvaslist);
1283 while((c = (TCanvas*) next())){
1284 if(TString(c->GetName())==name){
1287 c->WaitPrimitive(prim);
1293 TAxis *axis = h->GetXaxis();
1294 int bmin = axis->FindBin(xmin);
1295 int bmax = axis->FindBin(xmax);
1296 double integral = h->Integral(bmin,bmax);
1297 integral -= h->GetBinContent(bmin)*(xmin-axis->GetBinLowEdge(bmin))/axis->GetBinWidth(bmin);
1298 integral -= h->GetBinContent(bmax)*(axis->GetBinUpEdge(bmax)-
xmax)/axis->GetBinWidth(bmax);
1309 for(
int i=0; i<size; i++){
1310 double tmax = hists[i]->GetBinContent(hists[i]->GetMaximumBin());
1311 double tmin = hists[i]->GetMinimum();
1312 if(tmax>max) max = tmax;
1313 if(tmin<min) min = tmin;
1316 for(
int i=0; i<size; i++){
1317 hists[i]->GetYaxis()->SetRangeUser(min,max);
1322 for(
int i=0; i<size; i++){
1323 double tmax = hists[i]->GetBinContent(hists[i]->GetMaximumBin());
1324 if(tmax>0)hists[i]->Scale(
max/tmax);
1329 double max = (h1->GetMaximum()>h2->GetMaximum())? h1->GetMaximum() : h2->GetMaximum();
1331 h1->GetYaxis()->SetRangeUser(0,max);
1332 h2->GetYaxis()->SetRangeUser(0,max);
1339 TH1F *
h =
new TH1F(
"h",
"h",g->GetN(),0,
n);
1340 TGraph *gr =
new TGraph();
1341 gr->SetName(g->GetName());
1342 for(
auto i=0; i<
n; i++){
1347 h->Smooth(smoothness);
1349 for(
auto i=0;i<
n;i++){
1351 gr->SetPoint(i,h->GetBinContent(i),
y);
1362 if(pdg==2212) pid=4;
1367 double s = dtof*0.299792458/dist;
1370 double b = prt_mass[4]*prt_mass[4];
1371 double p = sqrt((a - 2*sqrt(a*a+a*b*x-2*a*b+b*b)/s + b)/(x - 4));
1378 double c = 299792458;
1381 double td = l*(sqrt(
p*
p+m1*m1)-sqrt(
p*
p+m2*m2))/(
p*c)*1E9;
1390 Long_t *id(0),*size(0),*flags(0),*modtime(0);
1391 return !gSystem->GetPathInfo(path,
id,size,flags,modtime);
1395 TPRegexp
e(
"[0-9][0-9][0-9]");
1396 return ((TString)str(e)).Atoi();