6 #include "/afs/rhic.bnl.gov/star/packages/DEV/StRoot/StEEmcUtil/EEfeeRaw/EEdims.h"
13 Int_t mTowerCrateYield[MaxTwCrates];
14 Int_t mMapmtCrateYield[MaxMapmtCrates];
15 Int_t mTowerChanYield[MaxTwCrates][MaxTwCrateCh];
16 Int_t mMapmtChanYield[MaxMapmtCrates][MaxMapmtCrateCh];
25 TGraphErrors *towerCrateCurves[MaxTwCrates];
26 TGraphErrors *mapmtCrateCurves[MaxMapmtCrates];
28 TGraphErrors *towerChanCurves[MaxTwCrates][MaxTwCrateCh];
29 TGraphErrors *mapmtChanCurves[MaxMapmtCrates][MaxMapmtCrateCh];
35 Bool_t doprint =
false;
37 void plotEEmcL2Timing(
const Char_t *input_dir=
"timing_files/")
41 chainFiles(input_dir);
44 setBranches(input_dir);
47 Long64_t nruns = chain -> GetEntries();
54 for ( Long64_t i = 0; i < nruns; i++ )
68 std::cout <<
"--------------------------------------------------------" << std::endl;
69 std::cout <<
"to view timing curves for any crate" << std::endl;
70 std::cout << std::endl;
71 std::cout <<
"towerChannels(icrate) -- icrate = 0-5 for tower crates 1-6"<<std::endl;
73 std::cout <<
"print() -- make gif/pdf files for all crates and channels"<<std::endl;
81 for ( Int_t ii=0;ii<MaxTwCrates;ii++ ) drawChannels(ii);
90 TCanvas *towers=
new TCanvas(
"towers",
"towers",500,400);
91 const Char_t *opt[]={
"ALP",
"LP",
"LP",
"LP",
"LP",
"LP"};
93 TLegend *legend=
new TLegend(0.125,0.6,0.325,0.85);
96 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
98 towerCrateCurves[icr]->Sort();
99 towerCrateCurves[icr]->Draw(opt[icr]);
100 TString crname=
"tw crate ";crname+=icr+1;
101 legend->AddEntry( towerCrateCurves[icr], crname,
"lp" );
102 if ( towerCrateCurves[icr]->GetYaxis()->GetXmax() > ymax )
103 ymax=towerCrateCurves[icr]->GetYaxis()->GetXmax();
105 towerCrateCurves[0]->SetTitle(
"EEMC Tower Crate Timing Curves");
106 towerCrateCurves[0]->GetXaxis()->SetTitle(
"TCD phase[ns]");
107 TString ytitle=Form(
"Integral [ped+%i,ped+%i] / N_{events}",mTowerMin,mTowerMax);
108 towerCrateCurves[0]->GetYaxis()->SetTitle(ytitle);
109 towerCrateCurves[0]->GetYaxis()->SetRangeUser(0.,ymax);
112 if(doprint)towers->Print(
"tower_crates.gif");
118 for ( Int_t icr = 0; icr<MaxMapmtCrates; icr+=4 )
121 TString cname=
"mapmt";cname+=icr+MinMapmtCrateID;
122 mapmt=
new TCanvas(cname,cname,500,400);
123 TString title=
"EEMC Mapmt Crate Timing Curves ";
124 title+=icr+MinMapmtCrateID;
126 title+=icr+MinMapmtCrateID+3;
127 legend=
new TLegend(0.625,0.12,0.825,0.375);
130 for ( Int_t jcr=0;jcr<4;jcr++ ) {
132 Int_t crateid=MinMapmtCrateID+index;
134 mapmtCrateCurves[index]->Sort();
135 mapmtCrateCurves[index]->Draw(opt[jcr]);
136 if ( mapmtCrateCurves[index]->GetYaxis()->GetXmax() > ymax )
137 ymax=mapmtCrateCurves[index]->GetYaxis()->GetXmax();
138 TString crname=
"mapmt crate ";crname+=crateid;
139 legend->AddEntry(mapmtCrateCurves[index],crname,
"lp");
142 mapmtCrateCurves[icr]->SetTitle(title);
143 mapmtCrateCurves[icr]->GetXaxis()->SetTitle(
"TCD phase[ns]");
144 mapmtCrateCurves[icr]->GetYaxis()->SetTitle(
"Integral [ped+25,ped+125] / Nevents");
145 TString ytitle=Form(
"Integral [ped+%i,ped+%i] / N_{events}",mMapmtMin,mMapmtMax);
146 mapmtCrateCurves[icr]->GetYaxis()->SetTitle(ytitle);
147 mapmtCrateCurves[icr]->GetYaxis()->SetRangeUser(0.,ymax*1.05);
150 TString oname=
"mapmt_crates_";
151 oname+=icr+MinMapmtCrateID;
153 oname+=icr+MinMapmtCrateID+4;
154 if(doprint)mapmt->Print(oname+
".gif");
161 void mapmtChannels( Int_t crate )
164 static const Int_t stride=16;
165 Int_t crateid = MinMapmtCrateID+crate;
168 TString fname=
"mapmt-crate-";fname+=crate+MinMapmtCrateID;fname+=
".ps";
169 TCanvas *canvas=
new TCanvas(
"canvas",
"canvas",850/2,1100/2);
174 for ( Int_t ich=0;ich<192;ich+=stride )
177 canvas->cd(1+icanvas%2);
181 TString pname=
"crate";
188 const Char_t *opts[]={
"ALP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP"};
192 Double_t sum[stride];
for ( Int_t jj=0;jj<stride;jj++ )sum[jj]=0.;
194 for ( Int_t jch=0;jch<stride;jch++ )
197 Double_t *Y=mapmtChanCurves[crate][index]->GetY();
198 for ( Int_t ipoint=0;ipoint<npoints;ipoint++ ) {
199 if ( Y[ipoint]>ymax ) ymax=Y[ipoint];
202 if ( sum[jch]>max ) max=sum[jch];
204 if ( max <= 0. )
continue;
208 TLegend *legend=
new TLegend(0.55,0.11,0.85,0.525);
209 for ( Int_t jch=0;jch<stride;jch++ )
212 mapmtChanCurves[crate][index]->SetMarkerSize(0.75);
214 Double_t *X=mapmtChanCurves[crate][index]->GetX();
215 Double_t *Y=mapmtChanCurves[crate][index]->GetY();
216 Double_t *EY=mapmtChanCurves[crate][index]->GetEY();
217 if ( sum[jch]<= 0. )
continue;
219 for ( Int_t ip=0;ip<npoints;ip++ ){
220 Float_t shift = 0.5+ ((float)jch) - ((float)stride)/2.0;
224 EY[ip]*=max/sum[jch];
227 mapmtChanCurves[crate][index]->Sort();
229 mapmtChanCurves[crate][index]->GetXaxis()->SetRangeUser(0.,ymax*1.05);
230 mapmtChanCurves[crate][index]->SetMarkerColor(38+jch);
231 mapmtChanCurves[crate][index]->SetLineColor(38+jch);
232 mapmtChanCurves[crate][index]->SetMinimum(0.);
233 mapmtChanCurves[crate][index]->Draw(opts[jch]);
235 TString label=
"crate ";label+=crate+1;label+=
" chan ";label+=index;
236 legend->AddEntry(mapmtChanCurves[crate][index],label,
"lp");
244 canvas->Print(fname+
"(");
251 canvas->Print(fname+
")");
252 gSystem->Exec(TString(
"ps2pdf ")+fname);
256 void towerChannels( Int_t crate )
259 static const Int_t stride=12;
261 TString fname=
"tower-crate-";fname+=crate+1;fname+=
".ps";
263 canvas =
new TCanvas(
"canvas",
"canvas",850/2,1100/2);
268 for ( Int_t ich=0;ich<120;ich+=stride )
271 canvas->cd(1+icanvas%2);
277 TString pname=
"crate";
284 const Char_t *opts[]={
"ALP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP"};
287 Double_t sum[stride];
for ( Int_t jj=0;jj<stride;jj++ )sum[jj]=0.;
289 for ( Int_t jch=0;jch<stride;jch++ )
293 Double_t *Y=towerChanCurves[crate][index]->GetY();
294 for ( Int_t ipoint=0;ipoint<npoints;ipoint++ ) sum[jch]+=Y[ipoint];
295 if ( sum[jch]>max ) max=sum[jch];
297 if ( max <= 0. )
continue;
299 TLegend *legend=
new TLegend(0.125,0.15,0.325,0.45);
300 for ( Int_t jch=0;jch<stride;jch++ )
304 towerChanCurves[crate][index]->SetMarkerSize(0.75);
306 Double_t *X=towerChanCurves[crate][index]->GetX();
307 Double_t *Y=towerChanCurves[crate][index]->GetY();
308 Double_t *EY=towerChanCurves[crate][index]->GetEY();
309 if ( sum[jch]<= 0. )
continue;
311 for ( Int_t ip=0;ip<npoints;ip++ ){
312 Float_t shift = 0.5+ ((float)jch) - ((float)stride)/2.0;
316 EY[ip]*=max/sum[jch];
320 towerChanCurves[crate][index]->Sort();
321 towerChanCurves[crate][index]->SetMinimum(0.);
322 towerChanCurves[crate][index]->SetMarkerColor(38+jch);
323 towerChanCurves[crate][index]->SetLineColor(38+jch);
324 towerChanCurves[crate][index]->Draw(opts[jch]);
326 TString label=
"crate ";label+=crate+1;label+=
" chan ";label+=index;
327 legend->AddEntry(towerChanCurves[crate][index],label,
"lp");
335 if ( doprint ) canvas->Print(fname+
"(");
342 canvas->Print(fname+
")");
343 gSystem->Exec(TString(
"ps2pdf ")+fname);
351 void fillCrates(Int_t ipoint)
355 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
357 Float_t yield = (Float_t)mTowerCrateYield[icr];
358 Float_t total = (Float_t)mTotalYield;
359 if ( total > 10.0 ) {
360 Float_t eyield = TMath::Sqrt(yield);
361 Float_t etotal = TMath::Sqrt(total);
362 Float_t r = yield / total;
363 Float_t e1 = (yield>0)? eyield/yield : 0.0;
364 Float_t e2 = etotal/total;
365 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
366 towerCrateCurves[icr]->SetPoint(ipoint, mTowerDelay, r );
367 towerCrateCurves[icr]->SetPointError( ipoint, 0., er );
370 towerCrateCurves[icr]->SetPoint(ipoint, mTowerDelay, -1.0 );
371 towerCrateCurves[icr]->SetPointError( ipoint, 0., 0. );
375 for ( Int_t icr=0;icr<MaxMapmtCrates;icr++ )
377 Float_t yield = (Float_t)mMapmtCrateYield[icr];
378 Float_t total = (Float_t)mTotalYield;
379 if ( total > 10.0 ) {
380 Float_t eyield = TMath::Sqrt(yield);
381 Float_t etotal = TMath::Sqrt(total);
382 Float_t r = yield / total;
383 Float_t e1 = (yield>0)? eyield/yield : 0.0;
384 Float_t e2 = etotal/total;
385 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
386 mapmtCrateCurves[icr]->SetPoint(ipoint, mMapmtDelay, r );
387 mapmtCrateCurves[icr]->SetPointError( ipoint, 0., er );
390 mapmtCrateCurves[icr]->SetPoint(ipoint, mMapmtDelay, -1. );
391 mapmtCrateCurves[icr]->SetPointError( ipoint, 0., 0. );
397 void fillChannels(Int_t ipoint)
402 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
404 for ( Int_t ich=0;ich<MaxTwCrateCh;ich++ )
407 Float_t yield = (Float_t)mTowerChanYield[icr][ich];
408 Float_t total = (Float_t)mTotalYield;
409 if ( total > 10.0 ) {
410 Float_t eyield = TMath::Sqrt(yield);
411 Float_t etotal = TMath::Sqrt(total);
412 Float_t r = yield / total;
413 Float_t e1 = (yield>0)? eyield/yield : 0.0;
414 Float_t e2 = etotal/total;
415 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
416 towerChanCurves[icr][ich]->SetPoint(ipoint, mTowerDelay, r );
417 towerChanCurves[icr][ich]->SetPointError( ipoint, 0., er );
420 towerChanCurves[icr][ich]->SetPoint(ipoint, mTowerDelay, -1.0 );
421 towerChanCurves[icr][ich]->SetPointError( ipoint, 0., 0. );
428 for ( Int_t icr=0;icr<MaxMapmtCrates;icr++ )
430 for ( Int_t ich=0;ich<MaxMapmtCrateCh;ich++ )
433 Float_t yield = (Float_t)mMapmtChanYield[icr][ich];
434 Float_t total = (Float_t)mTotalYield;
435 if ( total > 10.0 ) {
436 Float_t eyield = TMath::Sqrt(yield);
437 Float_t etotal = TMath::Sqrt(total);
438 Float_t r = yield / total;
439 Float_t e1 = (yield>0)? eyield/yield : 0.0;
440 Float_t e2 = etotal/total;
441 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
442 mapmtChanCurves[icr][ich]->SetPoint(ipoint, mMapmtDelay, r );
443 mapmtChanCurves[icr][ich]->SetPointError( ipoint, 0., er );
446 mapmtChanCurves[icr][ich]->SetPoint(ipoint, mMapmtDelay, -1.0 );
447 mapmtChanCurves[icr][ich]->SetPointError( ipoint, 0., 0. );
457 for ( Int_t i=0;i<MaxTwCrates;i++ ){
458 towerCrateCurves[i] =
new TGraphErrors(npoints);
459 towerCrateCurves[i]->SetMarkerStyle(20+i);
460 towerCrateCurves[i]->SetMarkerColor(i+1);
461 towerCrateCurves[i]->SetLineColor(i+1);
463 for ( Int_t j=0;j<MaxTwCrateCh;j++ )
464 towerChanCurves[i][j]=(TGraphErrors*)towerCrateCurves[i]->Clone();
467 for ( Int_t i=0;i<MaxMapmtCrates;i++ ){
468 mapmtCrateCurves[i]=
new TGraphErrors(npoints);
469 mapmtCrateCurves[i]->SetMarkerStyle(20+i%4);
470 mapmtCrateCurves[i]->SetMarkerColor(1+i%4);
471 mapmtCrateCurves[i]->SetLineColor(1+i%4);
473 for ( Int_t j=0;j<MaxMapmtCrateCh;j++ )
474 mapmtChanCurves[i][j]=(TGraphErrors*)mapmtCrateCurves[i]->Clone();
483 void chainFiles(
const Char_t *path)
485 chain=
new TChain(
"timing",
"Timing summary");
488 std::cout <<
"chaining files in " << path << std::endl;
489 TSystemDirectory *dir =
new TSystemDirectory(
"dir",path);
491 TIter next( dir->GetListOfFiles() );
493 while ( file = (TObject*)next() )
495 TString name=file->GetName();
498 if ( name.Contains(
".root") ) {
500 std::cout <<
" + " << name << std::endl;
508 void setBranches(
const Char_t *dir)
511 chain->SetBranchAddress(
"mRunNumber", &mRunNumber );
512 chain->SetBranchAddress(
"mTowerDelay", &mTowerDelay );
513 chain->SetBranchAddress(
"mMapmtDelay", &mMapmtDelay );
515 chain->SetBranchAddress(
"mTotalYield", &mTotalYield );
516 chain->SetBranchAddress(
"mTowerCrateYield", &mTowerCrateYield );
517 chain->SetBranchAddress(
"mMapmtCrateYield", &mMapmtCrateYield );
518 chain->SetBranchAddress(
"mTowerChanYield", &mTowerChanYield );
519 chain->SetBranchAddress(
"mMapmtChanYield", &mMapmtChanYield );
521 chain->SetBranchAddress(
"mTowerMin",&mTowerMin);
522 chain->SetBranchAddress(
"mTowerMax",&mTowerMax);
523 chain->SetBranchAddress(
"mMapmtMin",&mMapmtMin);
524 chain->SetBranchAddress(
"mMapmtMax",&mMapmtMax);