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];
34 Bool_t doprint =
true;
37 void plotEEmcTiming(
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++ )
65 for ( Int_t ii=0;ii<MaxTwCrates;ii++ ) towerChannels(ii);
66 for ( Int_t ii=0;ii<MaxMapmtCrates;ii++ ) mapmtChannels(ii);
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;
72 std::cout <<
"mapmtChannels(icrate) -- icrate = 0-47 for mapmt crates 1-48"<<std::endl;
80 for ( Int_t ii=0;ii<MaxTwCrates;ii++ ) drawChannels(ii);
81 for ( Int_t ii=0;ii<MaxMapmtCrates;ii++ ) drawMapmt(ii);
89 TCanvas *towers=
new TCanvas(
"towers",
"towers",500,400);
90 const Char_t *opt[]={
"ALP",
"LP",
"LP",
"LP",
"LP",
"LP"};
92 TLegend *legend=
new TLegend(0.125,0.6,0.325,0.85);
95 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
97 towerCrateCurves[icr]->Sort();
98 towerCrateCurves[icr]->Draw(opt[icr]);
99 TString crname=
"tw crate ";crname+=icr+1;
100 legend->AddEntry( towerCrateCurves[icr], crname,
"lp" );
101 if ( towerCrateCurves[icr]->GetYaxis()->GetXmax() > ymax )
102 ymax=towerCrateCurves[icr]->GetYaxis()->GetXmax();
104 towerCrateCurves[0]->SetTitle(
"EEMC Tower Crate Timing Curves");
105 towerCrateCurves[0]->GetXaxis()->SetTitle(
"TCD phase[ns]");
106 TString ytitle=Form(
"Integral [ped+%i,ped+%i] / N_{events}",mTowerMin,mTowerMax);
107 towerCrateCurves[0]->GetYaxis()->SetTitle(ytitle);
108 towerCrateCurves[0]->GetYaxis()->SetRangeUser(0.,ymax);
111 if(doprint)towers->Print(
"tower_crates.gif");
116 for ( Int_t icr = 0; icr<MaxMapmtCrates; icr+=4 )
119 TString cname=
"mapmt";cname+=icr+MinMapmtCrateID;
120 mapmt=
new TCanvas(cname,cname,500,400);
121 TString title=
"EEMC Mapmt Crate Timing Curves ";
122 title+=icr+MinMapmtCrateID;
124 title+=icr+MinMapmtCrateID+3;
125 legend=
new TLegend(0.625,0.12,0.825,0.375);
128 for ( Int_t jcr=0;jcr<4;jcr++ ) {
130 Int_t crateid=MinMapmtCrateID+index;
132 mapmtCrateCurves[index]->Sort();
133 mapmtCrateCurves[index]->Draw(opt[jcr]);
134 if ( mapmtCrateCurves[index]->GetYaxis()->GetXmax() > ymax )
135 ymax=mapmtCrateCurves[index]->GetYaxis()->GetXmax();
136 TString crname=
"mapmt crate ";crname+=crateid;
137 legend->AddEntry(mapmtCrateCurves[index],crname,
"lp");
140 mapmtCrateCurves[icr]->SetTitle(title);
141 mapmtCrateCurves[icr]->GetXaxis()->SetTitle(
"TCD phase[ns]");
142 mapmtCrateCurves[icr]->GetYaxis()->SetTitle(
"Integral [ped+25,ped+125] / Nevents");
143 TString ytitle=Form(
"Integral [ped+%i,ped+%i] / N_{events}",mMapmtMin,mMapmtMax);
144 mapmtCrateCurves[icr]->GetYaxis()->SetTitle(ytitle);
145 mapmtCrateCurves[icr]->GetYaxis()->SetRangeUser(0.,ymax*1.05);
148 TString oname=
"mapmt_crates_";
149 oname+=icr+MinMapmtCrateID;
151 oname+=icr+MinMapmtCrateID+4;
152 if(doprint)mapmt->Print(oname+
".gif");
159 void mapmtChannels( Int_t crate )
162 static const Int_t stride=16;
163 Int_t crateid = MinMapmtCrateID+crate;
166 TString fname=
"mapmt-crate-";fname+=crate+MinMapmtCrateID;fname+=
".ps";
167 TCanvas *canvas=
new TCanvas(
"canvas",
"canvas",850/2,1100/2);
172 for ( Int_t ich=0;ich<192;ich+=stride )
175 canvas->cd(1+icanvas%2);
179 TString pname=
"crate";
186 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"};
190 Double_t sum[stride];
for ( Int_t jj=0;jj<stride;jj++ )sum[jj]=0.;
192 for ( Int_t jch=0;jch<stride;jch++ )
195 Double_t *Y=mapmtChanCurves[crate][index]->GetY();
196 for ( Int_t ipoint=0;ipoint<npoints;ipoint++ ) {
197 if ( Y[ipoint]>ymax ) ymax=Y[ipoint];
200 if ( sum[jch]>max ) max=sum[jch];
202 if ( max <= 0. )
continue;
206 TLegend *legend=
new TLegend(0.55,0.11,0.85,0.525);
207 for ( Int_t jch=0;jch<stride;jch++ )
210 mapmtChanCurves[crate][index]->SetMarkerSize(0.75);
212 Double_t *X=mapmtChanCurves[crate][index]->GetX();
213 Double_t *Y=mapmtChanCurves[crate][index]->GetY();
214 Double_t *EY=mapmtChanCurves[crate][index]->GetEY();
215 if ( sum[jch]<= 0. )
continue;
217 for ( Int_t ip=0;ip<npoints;ip++ ){
218 Float_t shift = 0.5+ ((float)jch) - ((float)stride)/2.0;
222 EY[ip]*=max/sum[jch];
225 mapmtChanCurves[crate][index]->Sort();
227 mapmtChanCurves[crate][index]->GetXaxis()->SetRangeUser(0.,ymax*1.05);
228 mapmtChanCurves[crate][index]->SetMarkerColor(38+jch);
229 mapmtChanCurves[crate][index]->SetLineColor(38+jch);
230 mapmtChanCurves[crate][index]->SetMinimum(0.);
231 mapmtChanCurves[crate][index]->Draw(opts[jch]);
233 TString label=
"crate ";label+=crate+1;label+=
" chan ";label+=index;
234 legend->AddEntry(mapmtChanCurves[crate][index],label,
"lp");
242 canvas->Print(fname+
"(");
249 canvas->Print(fname+
")");
250 gSystem->Exec(TString(
"ps2pdf ")+fname);
254 void towerChannels( Int_t crate )
257 static const Int_t stride=12;
259 TString fname=
"tower-crate-";fname+=crate+1;fname+=
".ps";
260 TCanvas *canvas=
new TCanvas(
"canvas",
"canvas",850/2,1100/2);
264 for ( Int_t ich=0;ich<120;ich+=stride )
267 canvas->cd(1+icanvas%2);
273 TString pname=
"crate";
280 const Char_t *opts[]={
"ALP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP",
"LP"};
283 Double_t sum[stride];
for ( Int_t jj=0;jj<stride;jj++ )sum[jj]=0.;
285 for ( Int_t jch=0;jch<stride;jch++ )
289 Double_t *Y=towerChanCurves[crate][index]->GetY();
290 for ( Int_t ipoint=0;ipoint<npoints;ipoint++ ) sum[jch]+=Y[ipoint];
291 if ( sum[jch]>max ) max=sum[jch];
293 if ( max <= 0. )
continue;
295 TLegend *legend=
new TLegend(0.125,0.15,0.325,0.45);
296 for ( Int_t jch=0;jch<stride;jch++ )
300 towerChanCurves[crate][index]->SetMarkerSize(0.75);
302 Double_t *X=towerChanCurves[crate][index]->GetX();
303 Double_t *Y=towerChanCurves[crate][index]->GetY();
304 Double_t *EY=towerChanCurves[crate][index]->GetEY();
305 if ( sum[jch]<= 0. )
continue;
307 for ( Int_t ip=0;ip<npoints;ip++ ){
308 Float_t shift = 0.5+ ((float)jch) - ((float)stride)/2.0;
312 EY[ip]*=max/sum[jch];
316 towerChanCurves[crate][index]->Sort();
317 towerChanCurves[crate][index]->SetMinimum(0.);
318 towerChanCurves[crate][index]->SetMarkerColor(38+jch);
319 towerChanCurves[crate][index]->SetLineColor(38+jch);
320 towerChanCurves[crate][index]->Draw(opts[jch]);
322 TString label=
"crate ";label+=crate+1;label+=
" chan ";label+=index;
323 legend->AddEntry(towerChanCurves[crate][index],label,
"lp");
331 canvas->Print(fname+
"(");
337 canvas->Print(fname+
")");
338 gSystem->Exec(TString(
"ps2pdf ")+fname);
345 void fillCrates(Int_t ipoint)
349 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
351 Float_t yield = (Float_t)mTowerCrateYield[icr];
352 Float_t total = (Float_t)mTotalYield;
353 if ( total > 10.0 ) {
354 Float_t eyield = TMath::Sqrt(yield);
355 Float_t etotal = TMath::Sqrt(total);
356 Float_t r = yield / total;
357 Float_t e1 = (yield>0)? eyield/yield : 0.0;
358 Float_t e2 = etotal/total;
359 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
360 towerCrateCurves[icr]->SetPoint(ipoint, mTowerDelay, r );
361 towerCrateCurves[icr]->SetPointError( ipoint, 0., er );
364 towerCrateCurves[icr]->SetPoint(ipoint, mTowerDelay, -1.0 );
365 towerCrateCurves[icr]->SetPointError( ipoint, 0., 0. );
369 for ( Int_t icr=0;icr<MaxMapmtCrates;icr++ )
371 Float_t yield = (Float_t)mMapmtCrateYield[icr];
372 Float_t total = (Float_t)mTotalYield;
373 if ( total > 10.0 ) {
374 Float_t eyield = TMath::Sqrt(yield);
375 Float_t etotal = TMath::Sqrt(total);
376 Float_t r = yield / total;
377 Float_t e1 = (yield>0)? eyield/yield : 0.0;
378 Float_t e2 = etotal/total;
379 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
380 mapmtCrateCurves[icr]->SetPoint(ipoint, mMapmtDelay, r );
381 mapmtCrateCurves[icr]->SetPointError( ipoint, 0., er );
384 mapmtCrateCurves[icr]->SetPoint(ipoint, mMapmtDelay, -1. );
385 mapmtCrateCurves[icr]->SetPointError( ipoint, 0., 0. );
391 void fillChannels(Int_t ipoint)
396 for ( Int_t icr=0;icr<MaxTwCrates;icr++ )
398 for ( Int_t ich=0;ich<MaxTwCrateCh;ich++ )
401 Float_t yield = (Float_t)mTowerChanYield[icr][ich];
402 Float_t total = (Float_t)mTotalYield;
403 if ( total > 10.0 ) {
404 Float_t eyield = TMath::Sqrt(yield);
405 Float_t etotal = TMath::Sqrt(total);
406 Float_t r = yield / total;
407 Float_t e1 = (yield>0)? eyield/yield : 0.0;
408 Float_t e2 = etotal/total;
409 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
410 towerChanCurves[icr][ich]->SetPoint(ipoint, mTowerDelay, r );
411 towerChanCurves[icr][ich]->SetPointError( ipoint, 0., er );
414 towerChanCurves[icr][ich]->SetPoint(ipoint, mTowerDelay, -1.0 );
415 towerChanCurves[icr][ich]->SetPointError( ipoint, 0., 0. );
422 for ( Int_t icr=0;icr<MaxMapmtCrates;icr++ )
424 for ( Int_t ich=0;ich<MaxMapmtCrateCh;ich++ )
427 Float_t yield = (Float_t)mMapmtChanYield[icr][ich];
428 Float_t total = (Float_t)mTotalYield;
429 if ( total > 10.0 ) {
430 Float_t eyield = TMath::Sqrt(yield);
431 Float_t etotal = TMath::Sqrt(total);
432 Float_t r = yield / total;
433 Float_t e1 = (yield>0)? eyield/yield : 0.0;
434 Float_t e2 = etotal/total;
435 Float_t er = r * TMath::Sqrt( e1*e1 + e2*e2 );
436 mapmtChanCurves[icr][ich]->SetPoint(ipoint, mMapmtDelay, r );
437 mapmtChanCurves[icr][ich]->SetPointError( ipoint, 0., er );
440 mapmtChanCurves[icr][ich]->SetPoint(ipoint, mMapmtDelay, -1.0 );
441 mapmtChanCurves[icr][ich]->SetPointError( ipoint, 0., 0. );
451 for ( Int_t i=0;i<MaxTwCrates;i++ ){
452 towerCrateCurves[i] =
new TGraphErrors(npoints);
453 towerCrateCurves[i]->SetMarkerStyle(20+i);
454 towerCrateCurves[i]->SetMarkerColor(i+1);
455 towerCrateCurves[i]->SetLineColor(i+1);
457 for ( Int_t j=0;j<MaxTwCrateCh;j++ )
458 towerChanCurves[i][j]=(TGraphErrors*)towerCrateCurves[i]->Clone();
461 for ( Int_t i=0;i<MaxMapmtCrates;i++ ){
462 mapmtCrateCurves[i]=
new TGraphErrors(npoints);
463 mapmtCrateCurves[i]->SetMarkerStyle(20+i%4);
464 mapmtCrateCurves[i]->SetMarkerColor(1+i%4);
465 mapmtCrateCurves[i]->SetLineColor(1+i%4);
467 for ( Int_t j=0;j<MaxMapmtCrateCh;j++ )
468 mapmtChanCurves[i][j]=(TGraphErrors*)mapmtCrateCurves[i]->Clone();
477 void chainFiles(
const Char_t *path)
479 chain=
new TChain(
"timing",
"Timing summary");
482 std::cout <<
"chaining files in " << path << std::endl;
483 TSystemDirectory *dir =
new TSystemDirectory(
"dir",path);
485 TIter next( dir->GetListOfFiles() );
487 while ( file = (TObject*)next() )
489 TString name=file->GetName();
492 if ( name.Contains(
".root") ) {
494 std::cout <<
" + " << name << std::endl;
502 void setBranches(
const Char_t *dir)
505 chain->SetBranchAddress(
"mRunNumber", &mRunNumber );
506 chain->SetBranchAddress(
"mTowerDelay", &mTowerDelay );
507 chain->SetBranchAddress(
"mMapmtDelay", &mMapmtDelay );
509 chain->SetBranchAddress(
"mTotalYield", &mTotalYield );
510 chain->SetBranchAddress(
"mTowerCrateYield", &mTowerCrateYield );
511 chain->SetBranchAddress(
"mMapmtCrateYield", &mMapmtCrateYield );
512 chain->SetBranchAddress(
"mTowerChanYield", &mTowerChanYield );
513 chain->SetBranchAddress(
"mMapmtChanYield", &mMapmtChanYield );
515 chain->SetBranchAddress(
"mTowerMin",&mTowerMin);
516 chain->SetBranchAddress(
"mTowerMax",&mTowerMax);
517 chain->SetBranchAddress(
"mMapmtMin",&mMapmtMin);
518 chain->SetBranchAddress(
"mMapmtMax",&mMapmtMax);