113 for(
int d = 0; d < 2; d++ ){
114 for(
int ft = 0; ft < 32; ft++ ){
115 for(
int sl = 0; sl < 15; sl++ )
120 TH1F *timefeb[2][32][16];
121 TF1 *fit1 =
new TF1(
"fit1" ,
"gaus" , 3 );
123 double Hist_entries, Fit_mean, Fit_sigma, Fit_error;
125 std::vector< std::vector<double> > myvec;
127 tfilename =
"TimingFile" + nrun +
"_" + name +
".txt";
131 std::cout<<
" +++++ The file:" << tfilename <<
" is empty, time-fit will not be performed +++"<<std::endl;
137 string Filename =
"OFCTime_PerFEB_" + name +
".root";
138 TFile *FebTime =
new TFile( Filename.c_str(),
"READ");
140 double median2, TotalE = 0.0;
141 int dete = -1, side, feedT, slot;
143 std::vector<double> myvector;
144 std::vector<double> myvector2;
145 std::vector<double> energy;
148 string ffname =
"mediantest_" + nrun +
"_" + name +
".txt";
149 ff.open(ffname.c_str(), ios::out);
151 for(
uint l = 0; l < (myvec.size() -1); l++ ){
152 float mean = myvec[l][4];
153 double E = myvec[l][5];
154 myvector.push_back(
mean);
155 myvector2.push_back(
mean);
159 if( ( myvec[l][3] != myvec[l+1][3] ) || ( l == myvec.size()-2 ) ){
166 side = int(myvec[l][1]);
167 feedT = int(myvec[l][2]);
168 slot = int(myvec[l][3]);
169 if( name ==
"EMB" ) dete = 0;
170 else if( name ==
"EMEC" ) dete = 1;
171 else if( name ==
"HEC" ) dete = 2;
172 else if( name ==
"FCAL" ) dete = 3;
173 ff << dete <<
" " << side <<
" " << feedT <<
" " << slot <<
" " << median2 << endl;
174 Median[side][feedT][slot] = median2;
178 string savename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
180 file.open(savename.c_str(), ios::out);
184 std::vector<double> timevector;
187 if( name ==
"EMB" ) det = 0;
188 else if( name ==
"EMEC" ) det = 1;
189 else if( name ==
"HEC" ) det = 2;
190 else if( name ==
"FCAL" ) det = 3;
192 for(
int d = 0; d < 2; d++ ){
193 for(
int ft = 0; ft < 32; ft++ ){
194 for(
int sl = 0; sl < 15; sl++ ){
196 ostringstream histname;
197 histname <<
"h_" << name <<
"_" << d <<
"_" << ft <<
"_" << sl+1;
198 timefeb[d][ft][sl+1] = (TH1F*)FebTime->Get(histname.str().c_str());
199 if( !timefeb[d][ft][sl+1] )
202 Hist_entries = timefeb[d][ft][sl+1]->GetEntries();
204 if( Hist_entries == 0 )
continue;
206 timefeb[d][ft][sl+1]->Fit(
"fit1",
"mE",
"N",-10, 10 );
210 rms = fit1->GetParameter(2);
211 double n1 = -99., n2 = -99.;
212 rmsDist=timefeb[d][ft][sl+1]->GetRMS();
214 max = timefeb[d][ft][sl+1]->GetXaxis()->GetBinCenter(timefeb[d][ft][sl+1]->GetMaximumBin());
216 if( name ==
"FCAL" ) n1 = n2 = 0.8;
217 else if( name ==
"EMEC" ){
218 if( sl+1 == 13 && rmsDist > 3.0 ){
221 else if( rmsDist > 3. && sl+1 > 13 ){
224 else if( sl+1 == 9 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) )
226 else if( ( sl+1 == 8 || sl+1 == 9 ) && rmsDist > 3.0 )
228 else if( sl+1 == 8 && ft == 13 )
233 else if( name ==
"HEC" ) n1 = n2 = 1.5;
235 if( sl+1 == 9 || sl+1 == 10 ){
238 else if( sl+1 >= 2 && sl+1 < 6 ){
241 else if( sl+1 == 14 ){
248 timefeb[d][ft][sl+1]->Fit(
"fit1",
"mE",
"N",
max-n1*rms,
max+n2*rms);
249 Fit_mean = fit1->GetParameter(1);
250 Fit_sigma = fit1->GetParameter(2);
251 Fit_error = fit1->GetParError(1);
253 median_error = 1.253*timefeb[d][ft][sl+1]->GetRMS()/sqrt(Hist_entries);
256 if( Hist_entries <= 50 ){
257 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
259 else if( gMinuit->fCstatu ==
"SUCCESSFUL" && Fit_error >= Fit_mean && Fit_sigma > 1.5*rmsDist ){
260 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
262 else if( gMinuit->fCstatu !=
"SUCCESSFUL" ){
263 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
266 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " << Fit_mean <<
" " << Fit_error << endl;
287 TH1F *
h =
new TH1F( Form(
"h_%d", dete) , Form(
"h_%d", dete) , 160, -20, 20 );
290 TH1F *h1 =
new TH1F( Form(
"h1_%d", dete) , Form(
"h1_%d", dete) , 100, 0, 15000 );
291 TH2F *h2 =
new TH2F( Form(
"h2_%d", dete) , Form(
"h2_%d", dete) , 100, 0, 15000, 160, -20, 20 );
298 if( !history )
continue;
312 for(
uint j = 0; j < history->
nData(); j++ ){
313 int Gain = history->
data(j)->
gain();
314 int NumberRun = history->
data(j)->
run();
316 if( history->
data(j)->
problems(
true) !=
"None" )
continue;
320 if( fabs( history->
data(j)->
ofcTime() ) > 20 )
continue;
326 if( ( calo <= 3 && Gain == 0 ) || ( calo == 4 && Gain == 1 ) || ( calo == 5 && Gain == 1 && NumberRun < 216867 ) || ( calo == 5 && Gain == 0 && NumberRun >= 216867 ) )
h->Fill( t, e );
327 if( ( calo <= 3 && Gain == 0 ) || ( calo == 4 && Gain == 1 ) || ( calo == 5 && Gain == 1 && NumberRun < 216867 ) || ( calo == 5 && Gain == 0 && NumberRun >=216867 ) ) h1->Fill( history->
data(j)->
quality() );
328 if( ( calo <= 3 && Gain == 0 ) || ( calo == 4 && Gain == 1 ) || ( calo == 5 && Gain == 1 && NumberRun < 216867 ) || ( calo == 5 && Gain == 0 && NumberRun >= 216867) ) h2->Fill( history->
data(j)->
quality(), t );
332 TCanvas *c =
new TCanvas( Form(
"c_%d_%s", dete, nrun.c_str()), Form(
"c_%d_%s", dete, nrun.c_str()), 129,165,700,600 );
334 h->SetTitle(Form(
"hist_%d", dete) );
337 h->GetXaxis()->SetTitle(
"ofcTime [ns]");
340 TF1 *fit =
new TF1(
"fit",
"gaus", 3);
341 fit->SetParameter(1,
h->GetMean());
342 fit->SetParameter(2,
h->GetRMS());
343 fit->SetParLimits(1, -10, 10);
344 fit->SetParLimits(2, 0, 10);
349 h->Fit(
"fit",
"",
"",
mean-rms,
mean+0.5*rms);
350 h->Draw(
"histsame""E2");
352 TFile *fi =
new TFile( Form(
"Time_%d_%s.root", dete, nrun.c_str()),
"RECREATE" );
359 TString path =
"Plots/";
360 c->Print( path+Form(
"Time_%d_%s.eps", dete, nrun.c_str()) );
361 c->Print( path+Form(
"Time_%d_%s.png", dete, nrun.c_str()) );
371 std::string Filename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
373 std::ifstream f(Filename.c_str(), ios::in);
374 std::vector<double>
mean;
375 std::vector<int> side;
382 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
384 if (f.good() && !f.bad() && !f.fail())
393 TH1F *
h =
new TH1F(Form(
"FEB_Av_%s", name.c_str()), Form(
"FEB_Av_%s", name.c_str()), 240, -30., 30.);
394 TH1F *sAh =
new TH1F(Form(
"FEB_Av_%s_sideA", name.c_str()), Form(
"FEB_Av_%s_sideA", name.c_str()), 240, -30., 30.);
395 TH1F *sCh =
new TH1F(Form(
"FEB_Av_%s_sideC", name.c_str()), Form(
"FEB_Av_%s_sideC", name.c_str()), 240, -30., 30.);
397 for (
unsigned int i = 0; i <
mean.size(); i++)
411 TCanvas *c =
new TCanvas(Form(
"c_FEB_Av_%s", name.c_str()), Form(
"c_FEB_Av_%s", name.c_str()), 129, 165, 700, 600);
414 h->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
415 h->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
418 TString path =
"Plots/";
419 c->Print(path + Form(
"t_FEB_%s.png", name.c_str()));
420 c->Print(path + Form(
"t_FEB_%s.eps", name.c_str()));
421 c->Print(path + Form(
"t_FEB_%s.pdf", name.c_str()));
423 TCanvas *sAc =
new TCanvas(Form(
"c_FEB_Av_%s_sideA", name.c_str()), Form(
"c_FEB_Av_%s_sideA", name.c_str()), 129, 165, 700, 600);
426 sAh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
427 sAh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
429 sAc->Print(path + Form(
"t_FEB_%s_sideA.png", name.c_str()));
431 TCanvas *sCc =
new TCanvas(Form(
"c_FEB_Av_%s_sideC", name.c_str()), Form(
"c_FEB_Av_%s_sideC", name.c_str()), 129, 165, 700, 600);
434 sCh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
435 sCh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
437 sCc->Print(path + Form(
"t_FEB_%s_sideC.png", name.c_str()));
439 std::string plotname =
"FEB_average_" + nrun +
"_" + name +
".root";
440 TFile *fi =
new TFile(plotname.c_str(),
"RECREATE");
444 std::string plotnamesA =
"FEB_average_" + nrun +
"_" + name +
"_sideA.root";
445 TFile *fisA =
new TFile(plotnamesA.c_str(),
"RECREATE");
449 std::string plotnamesC =
"FEB_average_" + nrun +
"_" + name +
"_sideC.root";
450 TFile *fisC =
new TFile(plotnamesC.c_str(),
"RECREATE");
461 string Filename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
463 ifstream f( Filename.c_str(), ios::in );
471 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
473 if( f.good() && !f.bad() && !f.fail() ){
475 side.push_back( n2 );
481 TH1F *
h =
new TH1F( Form(
"FEB_Av_%s", name.c_str()), Form(
"FEB_Av_%s", name.c_str()), 120, -15., 15. );
482 TH1F *sAh =
new TH1F( Form(
"FEB_Av_%s_sideA", name.c_str()), Form(
"FEB_Av_%s_sideA", name.c_str()), 120, -15., 15. );
483 TH1F *sCh =
new TH1F( Form(
"FEB_Av_%s_sideC", name.c_str()), Form(
"FEB_Av_%s_sideC", name.c_str()), 120, -15., 15. );
485 for(
unsigned int i=0; i<
mean.size(); i++ ){
488 if( side.at(i) == 1 )
489 sAh->Fill(
mean[i] );
491 sCh->Fill(
mean[i] );
498 TCanvas *c =
new TCanvas( Form(
"c_FEB_Av_%s", name.c_str()), Form(
"c_FEB_Av_%s", name.c_str()), 129,165,700,600 );
501 h->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
502 h->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
505 TString path =
"Plots/";
506 c->Print( path+ Form(
"t_FEB_%s.png", name.c_str()) );
507 c->Print( path+ Form(
"t_FEB_%s.eps", name.c_str()) );
508 c->Print( path+ Form(
"t_FEB_%s.pdf", name.c_str()) );
510 TCanvas *sAc =
new TCanvas( Form(
"c_FEB_Av_%s_sideA", name.c_str()), Form(
"c_FEB_Av_%s_sideA", name.c_str()), 129,165,700,600 );
513 sAh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
514 sAh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
516 sAc->Print( path+ Form(
"t_FEB_%s_sideA.png", name.c_str()) );
518 TCanvas *sCc =
new TCanvas( Form(
"c_FEB_Av_%s_sideC", name.c_str()), Form(
"c_FEB_Av_%s_sideC", name.c_str()), 129,165,700,600 );
521 sCh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
522 sCh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
524 sCc->Print( path+ Form(
"t_FEB_%s_sideC.png", name.c_str()) );
527 std::string plotname =
"FEB_average_" + nrun +
"_" + name +
".root";
528 TFile *fi =
new TFile( plotname.c_str(),
"RECREATE" );
667 TGraphErrors **g =
new TGraphErrors*[15];
668 TGraphErrors **g1 =
new TGraphErrors*[15];
669 TGraphErrors **g2 =
new TGraphErrors*[15];
670 TGraphErrors **g3 =
new TGraphErrors*[15];
671 TGraphErrors **g4 =
new TGraphErrors*[15];
672 TGraphErrors **g5 =
new TGraphErrors*[15];
673 TGraphErrors **g6 =
new TGraphErrors*[15];
675 TGraph** gzero =
new TGraph*[15];
676 TCanvas **c =
new TCanvas*[4];
677 TLatex *l =
new TLatex();
678 l->SetTextSize(0.065);
680 int count = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0, count6 = 0;
681 TString path =
"Plots/";
683 for(
int det = 0; det < 4; det++ ){
686 if( det == 1 )special = 2;
687 for(
int crates = 0; crates < special; crates++ ){
688 string cratename =
"Standard";
689 if( crates == 1 ) cratename =
"Special";
691 for(
int side = 0; side < 2; side++ ){
692 c[side] =
new TCanvas( Form(
"c%d%d%s", det, side, cratename.c_str() ), Form(
"c%d%d%s", det,side, cratename.c_str()), 1100, 600 );
693 c[side]->Divide( 5, 3 );
695 for(
int i = 0; i < 15; i++ ){
696 g[i] =
new TGraphErrors();
697 g1[i] =
new TGraphErrors();
698 g2[i] =
new TGraphErrors();
699 g3[i] =
new TGraphErrors();
700 g4[i] =
new TGraphErrors();
701 g5[i] =
new TGraphErrors();
702 g6[i] =
new TGraphErrors();
704 gzero[i] =
new TGraph();
706 for(
int j = 0; j < 32; j++ ){
707 if( det == 1 && crates == 0 && ( j == 2 || j == 3 || j == 9 || j == 10 || j == 15 || j == 16 || j ==21 || j == 22 ) )
continue;
708 if( det == 1 && crates == 1 && !( j == 2 || j == 3 || j == 9 || j == 10 || j == 15 || j == 16 || j ==21 || j == 22 ) )
continue;
710 gzero[i]->SetPoint( j, j, 0 );
711 if(
param[det][side][j][i+1] == -99 )
continue;
714 g[i]->SetPoint(
count-1, j,
param[det][side][j][i+1] );
715 g[i]->SetPointError(
count-1, 0,
error[det][side][j][i+1] );
718 g[i]->SetMarkerColor(4);
719 g[i]->GetYaxis()->SetRangeUser(-5, 5);
724 g1[i]->SetPoint(count1-1, j,
param[det][side][j][i+1]);
725 g1[i]->SetPointError(count1-1, 0,
error[det][side][j][i+1]);
726 g1[i]->SetMarkerColor(4);
728 else if( j == 3 || j == 10 || j == 16 || j == 22 ){
729 if( i >= 4 && i <= 9 ){
731 g2[i]->SetPoint(count2-1, j,
param[det][side][j][i+1]);
732 g2[i]->SetPointError(count2-1, 0,
error[det][side][j][i+1]);
733 g2[i]->SetMarkerColor(3);
735 else if( i == 0 || i == 1){
737 g3[i]->SetPoint(count3-1, j,
param[det][side][j][i+1]);
738 g3[i]->SetPointError(count3-1, 0,
error[det][side][j][i+1]);
739 g3[i]->SetMarkerColor(6);
742 else if( j == 2 || j == 9 || j == 15 || j == 21 ){
744 g4[i]->SetPoint(count4-1, j,
param[det][side][j][i+1]);
745 g4[i]->SetPointError(count4-1, 0,
error[det][side][j][i+1]);
746 g4[i]->SetMarkerColor(2);
751 g5[i]->SetPoint(count5-1, j,
param[det][side][j][i+1]);
752 g5[i]->SetPointError(count5-1, 0,
error[det][side][j][i+1]);
753 g5[i]->SetMarkerColor(1+12*(j%2));
757 g6[i]->SetPoint(count6-1, j,
param[det][side][j][i+1]);
758 g6[i]->SetPointError(count6-1, 0,
error[det][side][j][i+1]);
759 g6[i]->SetMarkerColor(1+12*(j%2));
762 g[i]->GetYaxis()->SetRangeUser(-5, 5);
766 count = 0; count1 = 0; count2 = 0; count3 = 0; count4 = 0; count5 = 0; count6 = 0;
769 g[i]->GetXaxis()->SetTitle(
"FT");
770 g[i]->GetYaxis()->SetTitle(
"ofcTime[ns]");
771 g[i]->GetXaxis()->SetLabelSize(0.065);
772 g[i]->GetYaxis()->SetLabelSize(0.065);
773 g[i]->SetMarkerSize(0.4);
774 g1[i]->SetMarkerSize(0.4);
775 g2[i]->SetMarkerSize(0.4);
776 g3[i]->SetMarkerSize(0.4);
777 g4[i]->SetMarkerSize(0.4);
778 g5[i]->SetMarkerSize(0.4);
779 g6[i]->SetMarkerSize(0.4);
780 g[i]->SetTitle( Form(
"#color[2]{#bf{Slot %d}}", i+1 ) );
789 gzero[i]->SetMarkerSize(0.2);
792 string detname =
"EMB";
793 if( det == 1 )detname =
"EMEC";
794 else if( det == 2 )detname =
"HEC";
795 else if( det == 3 )detname =
"FCAL";
796 c[side]->Print( path+ Form(
"t_FEB_side%d_%s_%s.png", side, detname.c_str(), cratename.c_str()));
813 if( quality > 4000 ) pass =
false;
817 if( fabs( time ) > 10.00 )pass =
false;
821 if( layer == 0 && energy < 1000. ) pass =
false;
822 if( layer == 1 && energy < 1000. ) pass =
false;
823 if( layer == 2 && energy < 3000. ) pass =
false;
824 if( layer == 3 && energy < 1500. ) pass =
false;
828 if( calo == 2 || calo == 3 ){
829 if( layer == 0 && energy < 1500. ) pass =
false;
831 if( calo == 3 && energy < 3000. ) pass =
false;
832 if( calo == 2 && energy < 1000. ) pass =
false;
836 if( calo == 3 && energy < 2000. ) pass =
false;
837 if( calo == 2 && energy < 3000. ) pass =
false;
840 if( layer == 3 && energy < 2000. ) pass =
false;
841 if( layer == 3 && quality > 10000 ) pass =
false;
842 if( slot == 13 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
843 if( slot == 14 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
844 if( slot == 15 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
847 if( calo == 4 && energy < 3500. ) pass =
false;
848 if( calo == 5 && energy < 10000. ) pass =
false;
858 std::vector< std::vector <double> >
Data;
860 ifstream f(
file.c_str() );
865 if(
file.find(
"EMB" ) <
file.length() )name =
"EMB";
866 else if(
file.find(
"EMEC" ) <
file.length() )name =
"EMEC";
867 else if(
file.find(
"HEC" ) <
file.length() )name =
"HEC";
868 else if(
file.find(
"FCAL" ) <
file.length() )name =
"FCAL";
870 for(
int d = 0; d < 2; d++ ){
871 for(
int ft = 0; ft < 32; ft++ ){
872 for(
int sl = 0; sl < 15; sl++ ){
873 h[d][ft][sl+1] =
new TH1F( Form(
"h_%s_%d_%d_%d", name.c_str(), d, ft, sl+1) , Form(
"h_%s_%d_%d_%d", name.c_str(),d,ft, sl+1), 200, -20, 20 );
874 h[d][ft][sl+1]->Sumw2();
881 if( !f )cerr <<
"Timing File " <<
file <<
"cannot be read" << endl;
887 if( f.good() && !f.bad() && !f.fail() ){
888 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
889 if (n2 < 0 || n2 >= 2 ||
890 n3 < 0 || n3 >= 32 ||
893 cerr <<
"Bad line from timing file " << n2 <<
" " << n3 <<
" " << n4 << endl;
897 Data.push_back(std::vector<double>{
static_cast<double>(n1),
898 static_cast<double>(n2),
899 static_cast<double>(n3),
900 static_cast<double>(n4),
901 static_cast<double>(n5),
902 static_cast<double>(n6)});
904 h[n2][n3][n4]->Fill( n5, n6 );
913 string filename =
"OFCTime_PerFEB_" + name +
".root";
914 TFile *ff =
new TFile( filename.c_str(),
"RECREATE" );
916 for(
int d = 0; d < 2; d++ ){
917 for(
int ft = 0; ft < 32; ft++ ){
918 for(
int sl = 0; sl < 15; sl++ )
919 h[d][ft][sl+1]->Write();
936 TGraph *g =
new TGraph();
937 double wmedian = -99.,
weights, w0 = -1., cumulWeights = 0.0;
938 int Size = time.size();
939 bool wcondition =
false;
941 sort( time.begin(), time.end() );
943 for(
int i = 0; i < Size; i++ ){
944 int pos = std::find( time2.begin(),time2.end(), time[i] ) - time2.begin();
945 weights = weight[pos] / totalW;
946 cumulWeights = cumulWeights +
weights;
947 g->SetPoint( g->GetN(), cumulWeights, time[i] );
948 if( i == 0 ) w0 = weight[pos] / totalW;
949 wcondition = w0 > 0.5;
952 if( wcondition ) wmedian = g->Eval(w0+(1-w0)/2);
953 else wmedian= g->Eval(0.5);
const CellInfo * cellInfo() const
const Data * data(unsigned int i) const