]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/CheckAlienZDCESD.C
Typo corrected
[u/mrichter/AliRoot.git] / ZDC / CheckAlienZDCESD.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <TROOT.h>
6 #include <Riostream.h>
7 #include <TClassTable.h>
8 #include <TStyle.h>
9 #include <TMath.h>
10 #include <TGrid.h>
11 #include <TFile.h>
12 #include <TCanvas.h>
13 #include <TH1.h>
14 #include <TH2.h>
15 #include <TProfile.h>
16 #include <TLine.h>
17 #include "AliRun.h"
18 #include "AliRunLoader.h"
19 #include "AliPDG.h"
20 #include "STEER/AliESDEvent.h"
21 #include "STEER/AliESDZDC.h"
22
23 #endif
24 void CheckAlienZDCESD(Int_t year=2010, const char* period="10f", 
25         Int_t nRun=0, Int_t recoPass=1, Int_t nMaxFiles=1,
26         Bool_t plot=kTRUE, Bool_t esdWordCut=kFALSE)
27 {
28   
29  if(nRun==0){
30    printf("\n\n YOU MUST PROVIDE A RUN NUMBER!!! \n\n");
31    return;
32  }
33   
34  // Histogram definition
35  // ----------------------------------------------------------------
36 /* TH2F *centroidZNsideC = new TH2F("centroidZNsideC","Impact point over ZNC",100,-5.,5.,100,-5.,5.);
37   centroidZNsideC->SetXTitle("X_{ZNC} (cm)");
38   centroidZNsideC->SetYTitle("Y_{ZNC} (cm)");
39  TH2F * centroidZNsideA = new TH2F("centroidZNsideA","Impact point over ZNA",100,-5.,5.,100,-5.,5.);
40   centroidZNsideA->SetXTitle("X_{ZNA} (cm)");
41   centroidZNsideA->SetYTitle("Y_{ZNA} (cm)");
42 */
43  TH1F * enZNC = new TH1F("enZNC", "ZNC signal",100,0.,2000.);
44   enZNC->SetXTitle("E (GeV)");
45  TH1F * enZPC = new TH1F("enZPC", "ZPC signal",100,0.,2000.);
46   enZPC->SetXTitle("E (GeV)");
47  TH1F * enZNA = new TH1F("enZNA", "ZNA signal",100,0.,2000.);
48   enZNA->SetXTitle("E (GeV)");
49  TH1F * enZPA = new TH1F("enZPA", "ZPA signal",100,0.,2000.);
50   enZPA->SetXTitle("E (GeV)");
51  TH1D * enZEM1 = new TH1D("enZEM1", "Energy in ZEM1",100,0.,2000.);
52   enZEM1->SetXTitle("E (GeV)");
53  TH1D * enZEM2 = new TH1D("enZEM2", "Energy in ZEM2",100,0.,2000.);
54   enZEM2->SetXTitle("E (GeV)");
55  // ----------------------------------------------------------------
56  TH1D * hZNCTow[5]; TH1D * hZPCTow[5]; 
57  TH1D * hZNATow[5]; TH1D * hZPATow[5]; 
58  char nomehistznc[30], nomehistzpc[30], nomehistzna[30], nomehistzpa[30];
59  for(Int_t i=0; i<5; i++){
60    sprintf(nomehistznc,"ZNC-pm%d",i);
61    hZNCTow[i] = new TH1D(nomehistznc, nomehistznc, 100, 0.,1000.);
62    sprintf(nomehistzpc,"ZPC-pm%d",i);
63    hZPCTow[i] = new TH1D(nomehistzpc, nomehistzpc, 100, 0.,1000.);
64    sprintf(nomehistzna,"ZNA-pm%d",i);
65    hZNATow[i] = new TH1D(nomehistzna, nomehistzna, 100, 0.,1000.);
66    sprintf(nomehistzpa,"ZPA-pm%d",i);
67    hZPATow[i] = new TH1D(nomehistzpa, nomehistzpa, 100, 0.,1000.);
68  }
69  //
70 /* TH1D *hSumQZNC = new TH1D("hSumQZNC", "hSumQZNC", 100, 0., 1000.);
71  TH1D *hSumQZPC = new TH1D("hSumQZPC", "hSumQZPC", 100, 0., 1000.);
72  TH1D *hSumQZNA = new TH1D("hSumQZNA", "hSumQZNA", 100, 0., 1000.);
73  TH1D *hSumQZPA = new TH1D("hSumQZPA", "hSumQZPA", 100, 0., 1000.);
74 */
75  //
76  TH1F *hESDword = new TH1F("hESDword","hESDword",6,0.5,6.5);
77  hESDword->SetXTitle("ZDC trigger pattern"); 
78  //
79  TH1F * hTDC[32];
80  char ntdchist[20];
81  for(Int_t itdc=0; itdc<32; itdc++){
82     sprintf(ntdchist,"TDC-ch.%d",itdc);
83     hTDC[itdc] = new TH1F(ntdchist, ntdchist, 160, -350., -310.);
84     hTDC[itdc]->SetXTitle("TDC (ns)");
85  }
86
87  TGrid::Connect("alien:",0,0,"t");
88  gSystem->Exec(Form("gbbox find \"/alice/data/%d/LHC%s/000%d/ESDs/pass%d\" \"AliESDs.root\" > ESDFiles.txt",
89        year, period, nRun, recoPass));
90  FILE* listruns=fopen("ESDFiles.txt","r");
91  
92  char esdFileName[200], filnamalien[200];
93  char yperiod, dirESD;
94  // 
95  Int_t nAnalyzedFiles=0;
96  Int_t nevPhys=0, nevZNC=0, nevZPC=0, nevZNA=0, nevZPA=0, nevZEM1=0, nevZEM2=0;
97  
98  while(!feof(listruns)){
99   
100  if(nAnalyzedFiles!=nMaxFiles){
101   
102   int st = fscanf(listruns,"%s\n",esdFileName);    
103   Char_t directory[100];
104   sprintf(directory,"/alice/data/%d",year);
105   if(!strstr(esdFileName,directory)) continue;
106   sscanf(esdFileName,"/alice/data/%d/LHC%s/000%d/ESDs/pass%d/%s/AliESDs.root",&year,&yperiod,&nRun,&recoPass,&dirESD);
107   sprintf(filnamalien,"alien://%s",esdFileName);
108   printf("\n Opening file: %s\n",filnamalien);
109  
110   // open the ESD file
111   TFile* esdFile = TFile::Open(filnamalien);
112   if(!esdFile) {
113     Error("CheckZDCESD", "opening ESD file %s failed",filnamalien);
114     return;
115   }
116   
117   AliESDEvent* esd = new AliESDEvent();
118   TTree* tree = (TTree*) esdFile->Get("esdTree");
119   if(!tree) {
120     Error("CheckZDCESD", "No ESD tree found");
121     return;
122   }
123   
124   tree->SetBranchStatus("*", 0);
125   tree->SetBranchStatus("AliESDHeader*", 1);
126   tree->SetBranchStatus("AliESDRun*", 1);
127   tree->SetBranchStatus("AliESDZDC*", 1);
128   tree->SetBranchStatus("PrimaryVertex*", 1);
129   tree->SetBranchStatus("SPDVertex*", 1);
130   tree->SetBranchStatus("AliESDVZERO*", 1);
131
132   esd->ReadFromTree(tree);
133   
134   Int_t nevents = (Int_t)tree->GetEntries();
135   printf("\n    No. of events in ESD tree = %d\n", nevents);
136   for(Int_t iEvent=0; iEvent<nevents; iEvent++){
137     // get the event summary data
138     tree->GetEvent(iEvent);
139     
140     //printf("    ev. type %d\n",esd->GetEventType());
141     //
142     if(esd->GetEventType() == 7){
143       nevPhys++;
144       if(!esd) {
145         Error("CheckESD", "no ESD object found for event %d", iEvent);
146         return;
147       }
148     
149       Double_t sumQznc=0., sumQzpc=0., sumQzna=0., sumQzpa=0.;
150     
151       AliESDZDC *esdZDC = esd->GetESDZDC();
152       //Double_t centrZNC={-999.,-999.}, centrZNA={-999.,-999.};
153       //esdZDC->GetZNCentroidInpp(centrZNC, centrZNA);
154       //Short_t npart = esdZDC->GetZDCParticipants();
155       Double_t energyZNC = esdZDC->GetZDCN1Energy();
156       Double_t energyZPC = esdZDC->GetZDCP1Energy();
157       Double_t energyZNA = esdZDC->GetZDCN2Energy();
158       Double_t energyZPA = esdZDC->GetZDCP2Energy();
159       Double_t energyZEM1 = esdZDC->GetZDCEMEnergy(0);
160       Double_t energyZEM2 = esdZDC->GetZDCEMEnergy(1);
161       const Double_t * towZNC = esdZDC->GetZN1TowerEnergy();
162       const Double_t * towZPC = esdZDC->GetZP1TowerEnergy();
163       const Double_t * towZNA = esdZDC->GetZN2TowerEnergy();
164       const Double_t * towZPA = esdZDC->GetZP2TowerEnergy();
165       UInt_t iWord = esdZDC->GetESDQuality();
166       //
167       if((iWord & 0x00000001) == 0x00000001){
168         nevZNA++;   
169         hESDword->Fill(1.);
170       }
171       if((iWord & 0x00000002) == 0x00000002){
172         nevZPA++;   
173         hESDword->Fill(2.);
174       }
175       if((iWord & 0x00000004) == 0x00000004){
176         nevZEM1++;  
177         hESDword->Fill(3.);
178       }
179       if((iWord & 0x00000008) == 0x00000008){
180         nevZEM2++;  
181         hESDword->Fill(4.);
182       }
183       if((iWord & 0x00000010) == 0x00000010){
184         nevZNC++;   
185         hESDword->Fill(5.);
186       }
187       if((iWord & 0x00000020) == 0x00000020){
188         nevZPC++;   
189         hESDword->Fill(6.);
190       }
191       //if(centrZNC[0]!=-999. && centrZNC[1]!=-999) centroidZNsideC->Fill(centrZNC[0], centrZNC[1]);
192       //if(centrZNA[0]!=-999. && centrZNA[1]!=-999) centroidZNsideA->Fill(centrZNA[0], centrZNA[1]);
193       enZNC->Fill(energyZNC);
194       enZPC->Fill(energyZPC);
195       enZNA->Fill(energyZNA);
196       enZPA->Fill(energyZPA);
197       enZEM1->Fill(energyZEM1);
198       enZEM2->Fill(energyZEM2);
199       //
200       for(Int_t jj=0; jj<5; jj++){
201         if(esdWordCut){
202           if((iWord & 0x00000010) == 0x00000010) hZNCTow[jj]->Fill(towZNC[jj]);
203           if((iWord & 0x00000020) == 0x00000020) hZPCTow[jj]->Fill(towZPC[jj]);
204           if((iWord & 0x00000001) == 0x00000001) hZNATow[jj]->Fill(towZNA[jj]);
205           if((iWord & 0x00000002) == 0x00000002) hZPATow[jj]->Fill(towZPA[jj]);
206         }
207         else{
208           hZNCTow[jj]->Fill(towZNC[jj]);
209           hZPCTow[jj]->Fill(towZPC[jj]);
210           hZNATow[jj]->Fill(towZNA[jj]);
211           hZPATow[jj]->Fill(towZPA[jj]);
212         }
213         //
214         if(jj!=0){
215           if(esdWordCut){
216             if((iWord & 0x00000010) == 0x00000010) sumQznc += towZNC[jj];
217             if((iWord & 0x00000020) == 0x00000020) sumQzpc += towZPC[jj];
218             if((iWord & 0x00000001) == 0x00000001) sumQzna += towZNA[jj];
219             if((iWord & 0x00000002) == 0x00000002) sumQzpa += towZPA[jj];
220           }
221           else{
222             sumQznc += towZNC[jj];
223             sumQzpc += towZPC[jj];
224             sumQzna += towZNA[jj];
225             sumQzpa += towZPA[jj];
226           }
227         }
228       }
229       //
230 /*      if(esdWordCut){
231         if((iWord & 0x00000010) == 0x00000010) {
232           hSumQZNC->Fill(sumQznc);
233           //
234           //if(centrZNA[0]!=-999. && centrZNA[1]!=-999) centroidZNsideC->Fill(centrZNA[0], centrZNA[1]);
235         }
236         //
237         if((iWord & 0x00000020) == 0x00000020) {
238           hSumQZPC->Fill(sumQzpc);
239         }
240         
241       }
242       else{
243         hSumQZNC->Fill(sumQznc);
244         //
245         hSumQZPC->Fill(sumQzpc);
246       }
247       //
248       hSumQZNA->Fill(sumQzna);
249       hSumQZPA->Fill(sumQzpa);
250 */
251       Float_t tdcData[32][4];
252       for(Int_t isc=0; isc<32; isc++){
253         for(Int_t i=0; i<4; i++) tdcData[isc][i] = esdZDC->GetZDCTDCData(isc, i);
254       }
255       for(Int_t itdc=0; itdc<32; itdc++){
256          for(Int_t j=0; j<4; j++){
257             if((itdc>=0 || itdc<=9) && (tdcData[itdc][j]!=0)){
258                hTDC[itdc]->Fill(tdcData[itdc][j]-tdcData[15][j]);
259             } 
260          }
261       }
262       
263     }
264     
265   }
266   
267   nAnalyzedFiles++;
268   esdFile->Close();
269   }//if(nAnalyzedFiles<=nMaxFiles)
270   else{
271    printf("\t %d files analyzed\n\n",nMaxFiles);
272    break;
273   }
274  } // while closing
275   
276  printf("    No. of events over threshold: ZNA: %d  ZPA: %d  ZEM1: %d "
277         " ZEM2: %d  ZNC: %d  ZPC: %d\n\n", 
278         nevZNA, nevZPA, nevZEM1, nevZEM2, nevZNC, nevZPC);
279         
280  if(plot){  
281   //***********************************************************
282   // #### ROOT initialization
283   gROOT->Reset();
284   gStyle->SetCanvasColor(10);
285   gStyle->SetFrameFillColor(10);
286   gStyle->SetOptTitle(1);
287   if(esdWordCut) gStyle->SetOptStat(1111111);
288   else gStyle->SetOptStat(1111);
289   gStyle->SetOptFit(0);
290   gStyle->SetTitleTextColor(4);
291   gStyle->SetStatTextColor(4);
292   gStyle->SetStatX(0.92);
293   gStyle->SetStatY(0.92);
294   gStyle->SetLineColor(1);
295   gStyle->SetPalette(1);
296   gStyle->SetPadTopMargin(0.04);
297   gStyle->SetPadRightMargin(0.04);
298   gStyle->SetPadBottomMargin(0.14);
299   gStyle->SetPadLeftMargin(0.16); 
300    
301
302   //-------------------------------------------------
303   TCanvas *c1 = new TCanvas("c1","ZDCs + ZEMs signals",400,0,500,800);
304   c1->Divide(2,3);
305   c1->cd(1);
306   gPad->SetLogy(1);
307   enZNC->Draw("");
308   enZNC->SetLineColor(kBlue);
309   enZNC->SetFillColor(kBlue);
310   c1->cd(2);
311   gPad->SetLogy(1);
312   enZPC->Draw("");
313   enZPC->SetLineColor(kBlue+3);
314   enZPC->SetFillColor(kBlue+3);
315   c1->cd(3);
316   gPad->SetLogy(1);
317   enZEM1->SetLineColor(kRed);
318   enZEM1->SetFillColor(kRed);
319   enZEM1->Draw("");
320   c1->cd(4);
321   gPad->SetLogy(1);
322   enZEM2->SetLineColor(kRed);
323   enZEM2->SetFillColor(kRed);
324   enZEM2->Draw("");
325   c1->cd(5);
326   gPad->SetLogy(1);
327   enZNA->Draw("");
328   enZNA->SetLineColor(kRed);
329   enZNA->SetFillColor(kRed);
330   c1->cd(6);
331   gPad->SetLogy(1);
332   enZPA->Draw("");
333   enZPA->SetLineColor(kRed+1);
334   enZPA->SetFillColor(kRed+1);  
335   
336   //-------------------------------------------------
337   TCanvas *c3 = new TCanvas("c3","Side C ZDCs",0,0,800,400);
338   c3->Divide(5,2);
339   c3->cd(1);
340   gPad->SetLogy(1);
341   hZNCTow[0]->SetLineColor(kBlue);
342   hZNCTow[0]->SetFillColor(kBlue);
343   hZNCTow[0]->Draw("");
344   c3->cd(2);
345   gPad->SetLogy(1);
346   hZNCTow[1]->SetLineColor(kBlue);
347   hZNCTow[1]->SetFillColor(kBlue);
348   hZNCTow[1]->Draw("");
349   c3->cd(3);
350   gPad->SetLogy(1);
351   hZNCTow[2]->SetLineColor(kBlue);
352   hZNCTow[2]->SetFillColor(kBlue);
353   hZNCTow[2]->Draw("");
354   c3->cd(4);
355   gPad->SetLogy(1);
356   hZNCTow[3]->SetLineColor(kBlue);
357   hZNCTow[3]->SetFillColor(kBlue);
358   hZNCTow[3]->Draw("");
359   c3->cd(5);
360   gPad->SetLogy(1);
361   hZNCTow[4]->SetLineColor(kBlue);
362   hZNCTow[4]->SetFillColor(kBlue);
363   hZNCTow[4]->Draw("");
364   //
365   c3->cd(6);
366   gPad->SetLogy(1);
367   hZPCTow[0]->SetLineColor(kBlue+3);
368   hZPCTow[0]->SetFillColor(kBlue+3);
369   hZPCTow[0]->Draw("");
370   c3->cd(7);
371   gPad->SetLogy(1);
372   hZPCTow[1]->SetLineColor(kBlue+3);
373   hZPCTow[1]->SetFillColor(kBlue+3);
374   hZPCTow[1]->Draw("");
375   c3->cd(8);
376   gPad->SetLogy(1);
377   hZPCTow[2]->SetLineColor(kBlue+3);
378   hZPCTow[2]->SetFillColor(kBlue+3);
379   hZPCTow[2]->Draw("");
380   c3->cd(9);
381   gPad->SetLogy(1);
382   hZPCTow[3]->SetLineColor(kBlue+3);
383   hZPCTow[3]->SetFillColor(kBlue+3);
384   hZPCTow[3]->Draw("");
385   c3->cd(10);
386   gPad->SetLogy(1);
387   hZPCTow[4]->SetLineColor(kBlue+3);
388   hZPCTow[4]->SetFillColor(kBlue+3);
389   hZPCTow[4]->Draw("");
390   
391   
392   //-------------------------------------------------
393   TCanvas *c32 = new TCanvas("c32","side A ZDCs",700,0,800,400);
394   c32->Divide(5,2);
395   c32->cd(1);
396   gPad->SetLogy(1);
397   hZNATow[0]->SetLineColor(kRed);
398   hZNATow[0]->SetFillColor(kRed);
399   hZNATow[0]->Draw("");
400   c32->cd(2);
401   gPad->SetLogy(1);
402   hZNATow[1]->SetLineColor(kRed);
403   hZNATow[1]->SetFillColor(kRed);
404   hZNATow[1]->Draw("");
405   c32->cd(3);
406   gPad->SetLogy(1);
407   hZNATow[2]->SetLineColor(kRed);
408   hZNATow[2]->SetFillColor(kRed);
409   hZNATow[2]->Draw("");
410   c32->cd(4);
411   gPad->SetLogy(1);
412   hZNATow[3]->SetLineColor(kRed);
413   hZNATow[3]->SetFillColor(kRed);
414   hZNATow[3]->Draw("");
415   c32->cd(5);
416   gPad->SetLogy(1);
417   hZNATow[4]->SetLineColor(kRed);
418   hZNATow[4]->SetFillColor(kRed);
419   hZNATow[4]->Draw("");
420   //
421   c32->cd(6);
422   gPad->SetLogy(1);
423   hZPATow[0]->SetLineColor(kRed+1);
424   hZPATow[0]->SetFillColor(kRed+1);
425   hZPATow[0]->Draw("");
426   c32->cd(7);
427   gPad->SetLogy(1);
428   hZPATow[1]->SetLineColor(kRed+1);
429   hZPATow[1]->SetFillColor(kRed+1);
430   hZPATow[1]->Draw("");
431   c32->cd(8);
432   gPad->SetLogy(1);
433   hZPATow[2]->SetLineColor(kRed+1);
434   hZPATow[2]->SetFillColor(kRed+1);
435   hZPATow[2]->Draw("");
436   c32->cd(9);
437   gPad->SetLogy(1);
438   hZPATow[3]->SetLineColor(kRed+1);
439   hZPATow[3]->SetFillColor(kRed+1);
440   hZPATow[3]->Draw("");
441   c32->cd(10);
442   gPad->SetLogy(1);
443   hZPATow[4]->SetLineColor(kRed+1);
444   hZPATow[4]->SetFillColor(kRed+1);
445   hZPATow[4]->Draw("");
446   
447   //-------------------------------------------------
448   TCanvas *c4 = new TCanvas("c4","TDCs",400,0,700,500);
449   c4->Divide(3,2);
450   c4->cd(1);
451   hTDC[1]->SetFillColor(kPink); hTDC[1]->SetLineColor(kPink);
452   hTDC[1]->Draw("");
453   c4->cd(2);
454   hTDC[3]->SetFillColor(kPink+4); hTDC[3]->SetLineColor(kPink+4);
455   hTDC[3]->Draw("");
456   c4->cd(3);
457   hTDC[5]->SetFillColor(kGreen); hTDC[5]->SetLineColor(kGreen);
458   hTDC[5]->Draw("");
459   c4->cd(4);
460   hTDC[7]->SetFillColor(kGreen+2); hTDC[7]->SetLineColor(kGreen+2);
461   hTDC[7]->Draw("");
462   c4->cd(5);
463   hTDC[8]->SetFillColor(kAzure); hTDC[8]->SetLineColor(kAzure);
464   hTDC[8]->Draw("");
465   c4->cd(6);
466   hTDC[9]->SetFillColor(kAzure+5); hTDC[9]->SetLineColor(kAzure+5);
467   hTDC[9]->Draw("");
468  }
469    
470   TFile * fileout = new TFile("ESDhistos.root","recreate");
471   fileout->cd();
472   //centroidZNsideC->Write();
473   //centroidZNsideA->Write();
474   enZNC->Write();
475   enZNA->Write();
476   enZPC->Write();
477   enZPA->Write();
478   enZEM1->Write();
479   enZEM2->Write();
480   for(Int_t jj=0; jj<5; jj++){
481       hZNCTow[jj]->Write();
482       hZPCTow[jj]->Write();
483       hZNATow[jj]->Write();
484       hZPATow[jj]->Write();
485   }
486   /*hSumQZNC->Write();
487   hSumQZPC->Write();
488   hSumQZNA->Write();
489   hSumQZPA->Write();*/
490   //
491   hESDword->Write();
492   for(Int_t jj=0; jj<9; jj++) hTDC[jj]->Write();
493   //
494   fileout->Close();
495
496 }