112 for(
int d = 0; d < 2; d++ ){
113 for(
int ft = 0; ft < 32; ft++ ){
114 for(
int sl = 0; sl < 15; sl++ )
119 TH1F *timefeb[2][32][16];
120 TF1 *fit1 =
new TF1(
"fit1" ,
"gaus" , 3 );
122 double Hist_entries, Fit_mean, Fit_sigma, Fit_error;
124 std::vector< std::vector<double> > myvec;
126 tfilename =
"TimingFile" + nrun +
"_" + name +
".txt";
130 std::cout<<
" +++++ The file:" << tfilename <<
" is empty, time-fit will not be performed +++"<<std::endl;
136 string Filename =
"OFCTime_PerFEB_" + name +
".root";
137 TFile *FebTime =
new TFile( Filename.c_str(),
"READ");
139 double median2, TotalE = 0.0;
140 int dete = -1, side, feedT, slot;
142 std::vector<double> myvector;
143 std::vector<double> myvector2;
144 std::vector<double> energy;
147 string ffname =
"mediantest_" + nrun +
"_" + name +
".txt";
148 ff.open(ffname.c_str(), ios::out);
150 for(
uint l = 0; l < (myvec.size() -1); l++ ){
151 float mean = myvec[l][4];
152 double E = myvec[l][5];
153 myvector.push_back(
mean);
154 myvector2.push_back(
mean);
158 if( ( myvec[l][3] != myvec[l+1][3] ) || ( l == myvec.size()-2 ) ){
165 side = int(myvec[l][1]);
166 feedT = int(myvec[l][2]);
167 slot = int(myvec[l][3]);
168 if( name ==
"EMB" ) dete = 0;
169 else if( name ==
"EMEC" ) dete = 1;
170 else if( name ==
"HEC" ) dete = 2;
171 else if( name ==
"FCAL" ) dete = 3;
172 ff << dete <<
" " << side <<
" " << feedT <<
" " << slot <<
" " << median2 << endl;
173 Median[side][feedT][slot] = median2;
177 string savename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
179 file.open(savename.c_str(), ios::out);
183 std::vector<double> timevector;
186 if( name ==
"EMB" ) det = 0;
187 else if( name ==
"EMEC" ) det = 1;
188 else if( name ==
"HEC" ) det = 2;
189 else if( name ==
"FCAL" ) det = 3;
191 for(
int d = 0; d < 2; d++ ){
192 for(
int ft = 0; ft < 32; ft++ ){
193 for(
int sl = 0; sl < 15; sl++ ){
195 ostringstream histname;
196 histname <<
"h_" << name <<
"_" << d <<
"_" << ft <<
"_" << sl+1;
197 timefeb[d][ft][sl+1] = (TH1F*)FebTime->Get(histname.str().c_str());
198 if( !timefeb[d][ft][sl+1] )
201 Hist_entries = timefeb[d][ft][sl+1]->GetEntries();
203 if( Hist_entries == 0 )
continue;
205 timefeb[d][ft][sl+1]->Fit(
"fit1",
"mE",
"N",-10, 10 );
209 rms = fit1->GetParameter(2);
210 double n1 = -99., n2 = -99.;
211 rmsDist=timefeb[d][ft][sl+1]->GetRMS();
213 max = timefeb[d][ft][sl+1]->GetXaxis()->GetBinCenter(timefeb[d][ft][sl+1]->GetMaximumBin());
215 if( name ==
"FCAL" ) n1 = n2 = 0.8;
216 else if( name ==
"EMEC" ){
217 if( sl+1 == 13 && rmsDist > 3.0 ){
220 else if( rmsDist > 3. && sl+1 > 13 ){
223 else if( sl+1 == 9 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) )
225 else if( ( sl+1 == 8 || sl+1 == 9 ) && rmsDist > 3.0 )
227 else if( sl+1 == 8 && ft == 13 )
232 else if( name ==
"HEC" ) n1 = n2 = 1.5;
234 if( sl+1 == 9 || sl+1 == 10 ){
237 else if( sl+1 >= 2 && sl+1 < 6 ){
240 else if( sl+1 == 14 ){
247 timefeb[d][ft][sl+1]->Fit(
"fit1",
"mE",
"N",
max-n1*rms,
max+n2*rms);
248 Fit_mean = fit1->GetParameter(1);
249 Fit_sigma = fit1->GetParameter(2);
250 Fit_error = fit1->GetParError(1);
252 median_error = 1.253*timefeb[d][ft][sl+1]->GetRMS()/sqrt(Hist_entries);
255 if( Hist_entries <= 50 ){
256 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
258 else if( gMinuit->fCstatu ==
"SUCCESSFUL" && Fit_error >= Fit_mean && Fit_sigma > 1.5*rmsDist ){
259 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
261 else if( gMinuit->fCstatu !=
"SUCCESSFUL" ){
262 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " <<
Median[d][ft][sl+1] <<
" " << median_error << endl;
265 file << det <<
" " << d <<
" " << ft <<
" " << sl+1 <<
" " << Fit_mean <<
" " << Fit_error << endl;
286 TH1F *
h =
new TH1F( Form(
"h_%d", dete) , Form(
"h_%d", dete) , 160, -20, 20 );
289 TH1F *h1 =
new TH1F( Form(
"h1_%d", dete) , Form(
"h1_%d", dete) , 100, 0, 15000 );
290 TH2F *h2 =
new TH2F( Form(
"h2_%d", dete) , Form(
"h2_%d", dete) , 100, 0, 15000, 160, -20, 20 );
297 if( !history )
continue;
311 for(
uint j = 0; j < history->
nData(); j++ ){
312 int Gain = history->
data(j)->
gain();
313 int NumberRun = history->
data(j)->
run();
315 if( history->
data(j)->
problems(
true) !=
"None" )
continue;
319 if( fabs( history->
data(j)->
ofcTime() ) > 20 )
continue;
325 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 );
326 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() );
327 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 );
331 TCanvas *c =
new TCanvas( Form(
"c_%d_%s", dete, nrun.c_str()), Form(
"c_%d_%s", dete, nrun.c_str()), 129,165,700,600 );
333 h->SetTitle(Form(
"hist_%d", dete) );
336 h->GetXaxis()->SetTitle(
"ofcTime [ns]");
339 TF1 *fit =
new TF1(
"fit",
"gaus", 3);
340 fit->SetParameter(1,
h->GetMean());
341 fit->SetParameter(2,
h->GetRMS());
342 fit->SetParLimits(1, -10, 10);
343 fit->SetParLimits(2, 0, 10);
348 h->Fit(
"fit",
"",
"",
mean-rms,
mean+0.5*rms);
349 h->Draw(
"histsame""E2");
351 TFile *fi =
new TFile( Form(
"Time_%d_%s.root", dete, nrun.c_str()),
"RECREATE" );
358 TString path =
"Plots/";
359 c->Print( path+Form(
"Time_%d_%s.eps", dete, nrun.c_str()) );
360 c->Print( path+Form(
"Time_%d_%s.png", dete, nrun.c_str()) );
370 std::string Filename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
372 std::ifstream f(Filename.c_str(), ios::in);
373 std::vector<double>
mean;
374 std::vector<int> side;
381 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
383 if (f.good() && !f.bad() && !f.fail())
392 TH1F *
h =
new TH1F(Form(
"FEB_Av_%s", name.c_str()), Form(
"FEB_Av_%s", name.c_str()), 240, -30., 30.);
393 TH1F *sAh =
new TH1F(Form(
"FEB_Av_%s_sideA", name.c_str()), Form(
"FEB_Av_%s_sideA", name.c_str()), 240, -30., 30.);
394 TH1F *sCh =
new TH1F(Form(
"FEB_Av_%s_sideC", name.c_str()), Form(
"FEB_Av_%s_sideC", name.c_str()), 240, -30., 30.);
396 for (
unsigned int i = 0; i <
mean.size(); i++)
410 TCanvas *c =
new TCanvas(Form(
"c_FEB_Av_%s", name.c_str()), Form(
"c_FEB_Av_%s", name.c_str()), 129, 165, 700, 600);
413 h->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
414 h->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
417 TString path =
"Plots/";
418 c->Print(path + Form(
"t_FEB_%s.png", name.c_str()));
419 c->Print(path + Form(
"t_FEB_%s.eps", name.c_str()));
420 c->Print(path + Form(
"t_FEB_%s.pdf", name.c_str()));
422 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);
425 sAh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
426 sAh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
428 sAc->Print(path + Form(
"t_FEB_%s_sideA.png", name.c_str()));
430 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);
433 sCh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
434 sCh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
436 sCc->Print(path + Form(
"t_FEB_%s_sideC.png", name.c_str()));
438 std::string plotname =
"FEB_average_" + nrun +
"_" + name +
".root";
439 TFile *fi =
new TFile(plotname.c_str(),
"RECREATE");
443 std::string plotnamesA =
"FEB_average_" + nrun +
"_" + name +
"_sideA.root";
444 TFile *fisA =
new TFile(plotnamesA.c_str(),
"RECREATE");
448 std::string plotnamesC =
"FEB_average_" + nrun +
"_" + name +
"_sideC.root";
449 TFile *fisC =
new TFile(plotnamesC.c_str(),
"RECREATE");
460 string Filename =
"FEB_time_fitMean_" + nrun +
"_" + name +
".txt";
462 ifstream f( Filename.c_str(), ios::in );
470 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
472 if( f.good() && !f.bad() && !f.fail() ){
474 side.push_back( n2 );
480 TH1F *
h =
new TH1F( Form(
"FEB_Av_%s", name.c_str()), Form(
"FEB_Av_%s", name.c_str()), 120, -15., 15. );
481 TH1F *sAh =
new TH1F( Form(
"FEB_Av_%s_sideA", name.c_str()), Form(
"FEB_Av_%s_sideA", name.c_str()), 120, -15., 15. );
482 TH1F *sCh =
new TH1F( Form(
"FEB_Av_%s_sideC", name.c_str()), Form(
"FEB_Av_%s_sideC", name.c_str()), 120, -15., 15. );
484 for(
unsigned int i=0; i<
mean.size(); i++ ){
487 if( side.at(i) == 1 )
488 sAh->Fill(
mean[i] );
490 sCh->Fill(
mean[i] );
497 TCanvas *c =
new TCanvas( Form(
"c_FEB_Av_%s", name.c_str()), Form(
"c_FEB_Av_%s", name.c_str()), 129,165,700,600 );
500 h->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
501 h->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
504 TString path =
"Plots/";
505 c->Print( path+ Form(
"t_FEB_%s.png", name.c_str()) );
506 c->Print( path+ Form(
"t_FEB_%s.eps", name.c_str()) );
507 c->Print( path+ Form(
"t_FEB_%s.pdf", name.c_str()) );
509 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 );
512 sAh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
513 sAh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
515 sAc->Print( path+ Form(
"t_FEB_%s_sideA.png", name.c_str()) );
517 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 );
520 sCh->GetXaxis()->SetTitle(
"<t_{FEB}> [ns]");
521 sCh->GetYaxis()->SetTitle(
"Number of FEBs / 0.25 ns");
523 sCc->Print( path+ Form(
"t_FEB_%s_sideC.png", name.c_str()) );
526 std::string plotname =
"FEB_average_" + nrun +
"_" + name +
".root";
527 TFile *fi =
new TFile( plotname.c_str(),
"RECREATE" );
666 TGraphErrors **g =
new TGraphErrors*[15];
667 TGraphErrors **g1 =
new TGraphErrors*[15];
668 TGraphErrors **g2 =
new TGraphErrors*[15];
669 TGraphErrors **g3 =
new TGraphErrors*[15];
670 TGraphErrors **g4 =
new TGraphErrors*[15];
671 TGraphErrors **g5 =
new TGraphErrors*[15];
672 TGraphErrors **g6 =
new TGraphErrors*[15];
674 TGraph** gzero =
new TGraph*[15];
675 TCanvas **c =
new TCanvas*[4];
676 TLatex *l =
new TLatex();
677 l->SetTextSize(0.065);
679 int count = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0, count6 = 0;
680 TString path =
"Plots/";
682 for(
int det = 0; det < 4; det++ ){
685 if( det == 1 )special = 2;
686 for(
int crates = 0; crates < special; crates++ ){
687 string cratename =
"Standard";
688 if( crates == 1 ) cratename =
"Special";
690 for(
int side = 0; side < 2; side++ ){
691 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 );
692 c[side]->Divide( 5, 3 );
694 for(
int i = 0; i < 15; i++ ){
695 g[i] =
new TGraphErrors();
696 g1[i] =
new TGraphErrors();
697 g2[i] =
new TGraphErrors();
698 g3[i] =
new TGraphErrors();
699 g4[i] =
new TGraphErrors();
700 g5[i] =
new TGraphErrors();
701 g6[i] =
new TGraphErrors();
703 gzero[i] =
new TGraph();
705 for(
int j = 0; j < 32; j++ ){
706 if( det == 1 && crates == 0 && ( j == 2 || j == 3 || j == 9 || j == 10 || j == 15 || j == 16 || j ==21 || j == 22 ) )
continue;
707 if( det == 1 && crates == 1 && !( j == 2 || j == 3 || j == 9 || j == 10 || j == 15 || j == 16 || j ==21 || j == 22 ) )
continue;
709 gzero[i]->SetPoint( j, j, 0 );
710 if(
param[det][side][j][i+1] == -99 )
continue;
713 g[i]->SetPoint(
count-1, j,
param[det][side][j][i+1] );
714 g[i]->SetPointError(
count-1, 0,
error[det][side][j][i+1] );
717 g[i]->SetMarkerColor(4);
718 g[i]->GetYaxis()->SetRangeUser(-5, 5);
723 g1[i]->SetPoint(count1-1, j,
param[det][side][j][i+1]);
724 g1[i]->SetPointError(count1-1, 0,
error[det][side][j][i+1]);
725 g1[i]->SetMarkerColor(4);
727 else if( j == 3 || j == 10 || j == 16 || j == 22 ){
728 if( i >= 4 && i <= 9 ){
730 g2[i]->SetPoint(count2-1, j,
param[det][side][j][i+1]);
731 g2[i]->SetPointError(count2-1, 0,
error[det][side][j][i+1]);
732 g2[i]->SetMarkerColor(3);
734 else if( i == 0 || i == 1){
736 g3[i]->SetPoint(count3-1, j,
param[det][side][j][i+1]);
737 g3[i]->SetPointError(count3-1, 0,
error[det][side][j][i+1]);
738 g3[i]->SetMarkerColor(6);
741 else if( j == 2 || j == 9 || j == 15 || j == 21 ){
743 g4[i]->SetPoint(count4-1, j,
param[det][side][j][i+1]);
744 g4[i]->SetPointError(count4-1, 0,
error[det][side][j][i+1]);
745 g4[i]->SetMarkerColor(2);
750 g5[i]->SetPoint(count5-1, j,
param[det][side][j][i+1]);
751 g5[i]->SetPointError(count5-1, 0,
error[det][side][j][i+1]);
752 g5[i]->SetMarkerColor(1+12*(j%2));
756 g6[i]->SetPoint(count6-1, j,
param[det][side][j][i+1]);
757 g6[i]->SetPointError(count6-1, 0,
error[det][side][j][i+1]);
758 g6[i]->SetMarkerColor(1+12*(j%2));
761 g[i]->GetYaxis()->SetRangeUser(-5, 5);
765 count = 0; count1 = 0; count2 = 0; count3 = 0; count4 = 0; count5 = 0; count6 = 0;
768 g[i]->GetXaxis()->SetTitle(
"FT");
769 g[i]->GetYaxis()->SetTitle(
"ofcTime[ns]");
770 g[i]->GetXaxis()->SetLabelSize(0.065);
771 g[i]->GetYaxis()->SetLabelSize(0.065);
772 g[i]->SetMarkerSize(0.4);
773 g1[i]->SetMarkerSize(0.4);
774 g2[i]->SetMarkerSize(0.4);
775 g3[i]->SetMarkerSize(0.4);
776 g4[i]->SetMarkerSize(0.4);
777 g5[i]->SetMarkerSize(0.4);
778 g6[i]->SetMarkerSize(0.4);
779 g[i]->SetTitle( Form(
"#color[2]{#bf{Slot %d}}", i+1 ) );
788 gzero[i]->SetMarkerSize(0.2);
791 string detname =
"EMB";
792 if( det == 1 )detname =
"EMEC";
793 else if( det == 2 )detname =
"HEC";
794 else if( det == 3 )detname =
"FCAL";
795 c[side]->Print( path+ Form(
"t_FEB_side%d_%s_%s.png", side, detname.c_str(), cratename.c_str()));
812 if( quality > 4000 ) pass =
false;
816 if( fabs( time ) > 10.00 )pass =
false;
820 if( layer == 0 && energy < 1000. ) pass =
false;
821 if( layer == 1 && energy < 1000. ) pass =
false;
822 if( layer == 2 && energy < 3000. ) pass =
false;
823 if( layer == 3 && energy < 1500. ) pass =
false;
827 if( calo == 2 || calo == 3 ){
828 if( layer == 0 && energy < 1500. ) pass =
false;
830 if( calo == 3 && energy < 3000. ) pass =
false;
831 if( calo == 2 && energy < 1000. ) pass =
false;
835 if( calo == 3 && energy < 2000. ) pass =
false;
836 if( calo == 2 && energy < 3000. ) pass =
false;
839 if( layer == 3 && energy < 2000. ) pass =
false;
840 if( layer == 3 && quality > 10000 ) pass =
false;
841 if( slot == 13 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
842 if( slot == 14 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
843 if( slot == 15 && ( ft == 2 || ft == 9 || ft == 15 || ft == 21 ) && quality > 4000 ) pass =
false;
846 if( calo == 4 && energy < 3500. ) pass =
false;
847 if( calo == 5 && energy < 10000. ) pass =
false;
857 std::vector< std::vector <double> >
Data;
859 ifstream f(
file.c_str() );
864 if(
file.find(
"EMB" ) <
file.length() )name =
"EMB";
865 else if(
file.find(
"EMEC" ) <
file.length() )name =
"EMEC";
866 else if(
file.find(
"HEC" ) <
file.length() )name =
"HEC";
867 else if(
file.find(
"FCAL" ) <
file.length() )name =
"FCAL";
869 for(
int d = 0; d < 2; d++ ){
870 for(
int ft = 0; ft < 32; ft++ ){
871 for(
int sl = 0; sl < 15; sl++ ){
872 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 );
873 h[d][ft][sl+1]->Sumw2();
880 if( !f )cerr <<
"Timing File " <<
file <<
"cannot be read" << endl;
886 if( f.good() && !f.bad() && !f.fail() ){
887 f >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
888 if (n2 < 0 || n2 >= 2 ||
889 n3 < 0 || n3 >= 32 ||
892 cerr <<
"Bad line from timing file " << n2 <<
" " << n3 <<
" " << n4 << endl;
896 Data.push_back(std::vector<double>{
static_cast<double>(n1),
897 static_cast<double>(n2),
898 static_cast<double>(n3),
899 static_cast<double>(n4),
900 static_cast<double>(n5),
901 static_cast<double>(n6)});
903 h[n2][n3][n4]->Fill( n5, n6 );
912 string filename =
"OFCTime_PerFEB_" + name +
".root";
913 TFile *ff =
new TFile( filename.c_str(),
"RECREATE" );
915 for(
int d = 0; d < 2; d++ ){
916 for(
int ft = 0; ft < 32; ft++ ){
917 for(
int sl = 0; sl < 15; sl++ )
918 h[d][ft][sl+1]->Write();
935 TGraph *g =
new TGraph();
936 double wmedian = -99.,
weights, w0 = -1., cumulWeights = 0.0;
937 int Size = time.size();
938 bool wcondition =
false;
940 sort( time.begin(), time.end() );
942 for(
int i = 0; i < Size; i++ ){
943 int pos = std::find( time2.begin(),time2.end(), time[i] ) - time2.begin();
944 weights = weight[pos] / totalW;
945 cumulWeights = cumulWeights +
weights;
946 g->SetPoint( g->GetN(), cumulWeights, time[i] );
947 if( i == 0 ) w0 = weight[pos] / totalW;
948 wcondition = w0 > 0.5;
951 if( wcondition ) wmedian = g->Eval(w0+(1-w0)/2);
952 else wmedian= g->Eval(0.5);
const CellInfo * cellInfo() const
const Data * data(unsigned int i) const