efficiency histograms added
[u/mrichter/AliRoot.git] / PWG1 / T0 / AliT0AnalysisTaskQA.cxx
1 #include "TChain.h"
2 #include "TTree.h"
3 #include "TH1F.h"
4 #include "TF1.h"
5 #include "TH2F.h"
6 #include "TCanvas.h"
7 #include "TObjArray.h"
8
9 #include "AliAnalysisTask.h"
10 #include "AliAnalysisManager.h"
11
12 #include "AliESDEvent.h"
13 #include "AliESDInputHandler.h"
14
15 #include "AliT0AnalysisTaskQA.h"
16
17 //#include "AliCDBMetaData.h"
18 //#include "AliCDBId.h"
19 //#include "AliCDBEntry.h"
20 //#include "AliCDBManager.h"
21 //#include "AliCDBStorage.h"
22
23 // Task should calculate channels offset 
24 // Authors: Alla 
25
26 ClassImp(AliT0AnalysisTaskQA)
27 //________________________________________________________________________
28 AliT0AnalysisTaskQA::AliT0AnalysisTaskQA() 
29   : AliAnalysisTaskSE(),  fESD(0x0), fTzeroObject(0x0),
30   fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0),
31     fRunNumber(0),fTimeVSAmplitude(0x0),fCFDVSPmtId(0x0),fSPDVertexVST0Vertex(0x0),
32     fOrAvsNtracks(0), fOrCvsNtracks(0), fT0vsNtracks(0) 
33 {
34   // Constructor
35
36   // Define input and output slots here
37   // Input slot #0 works with a TChain
38
39 // ########### NEVER define slots in the IO constructor
40 //  DefineInput(0,  TChain::Class());
41 //  DefineOutput(1, TObjArray::Class());
42 }
43
44
45 //________________________________________________________________________
46 AliT0AnalysisTaskQA::AliT0AnalysisTaskQA(const char *name) 
47   : AliAnalysisTaskSE(name),  fESD(0x0), fTzeroObject(0x0),
48   fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0),
49     fRunNumber(0),fTimeVSAmplitude(0x0),fCFDVSPmtId(0x0),fSPDVertexVST0Vertex(0x0),
50     fOrAvsNtracks(0), fOrCvsNtracks(0), fT0vsNtracks(0) 
51 {
52   // Constructor
53   // Define input and output slots here
54   // Input slot #0 works with a TChain
55   DefineInput(0, TChain::Class());
56   DefineOutput(1, TObjArray::Class());
57   // Output slot #0 id reserved by the base class for AOD
58   // Output slot #1 writes into a TH1 container
59 }
60
61 //________________________________________________________________________
62 AliT0AnalysisTaskQA::~AliT0AnalysisTaskQA() 
63 {
64   // Destructor
65   // printf("AliT0CalibOffsetChannels~AliT0CalibOffsetChannels() ");
66   delete fTzeroObject; // This deletes everything ...
67 }
68
69 //------------------------------------------------------------------
70 void AliT0AnalysisTaskQA::UserCreateOutputObjects()
71 {
72   // Create histograms
73  fTimeVSAmplitude = new TH2F*[NPMT0];
74
75  for (Int_t i=0; i<NPMT0; i++) {
76     fTimeVSAmplitude[i]= new TH2F (Form("fTimeVSAmplitude%d",i+1),"fTimeVsAmplitude",60, -10, 50,1500,1000,7000);
77   }
78
79   fTzeroORAplusORC = new TH1F("fTzeroORAplusORC","ORA+ORC /2",100,-2000,2000);   //or A plus or C 
80   fResolution      = new TH1F("fResolution","fResolution",100,-2000,2000);// or A minus or C spectrum
81   fTzeroORA        = new TH1F("fTzeroORA","fTzeroORA",100,-2000,2000);// or A spectrum
82   fTzeroORC        = new TH1F("fTzeroORC","fTzeroORC",100,-2000,2000);// or C spectrum
83   fCFDVSPmtId      = new TH2F("fCFDVSPmtId","fCFDVSPmtId",24,0,24,1500,1000,7000);  // 
84   fSPDVertexVST0Vertex = new TH2F("fSPDVertexVST0Vertex","fSPDVertexVST0Vertex",30,-30,30,30,-30,30);
85   fOrAvsNtracks    = new TH2F("fAvstracks", "Avstracks",200, 0, 1000, 500, -1000, 1000);
86   fOrCvsNtracks    = new TH2F("fCvstracks", "Cvstracks",200, 0, 1000, 500, -1000, 1000);
87   fT0vsNtracks     = new TH2F("fT0ACvstrackles", "T0ACvstracks",200, 0, 1000, 500, -1000, 1000); 
88    fEffAC = new TH1F("EffAC","T0Eff ", 200, 0, 1000);
89    fEffA = new TH1F("EffA","T0AEff ", 200, 0, 1000);
90    fEffC = new TH1F("EffC","T0CEff ", 200, 0, 1000);
91    ftracksEffSPD= new TH1F("ftracksEffSPD","SPDeff", 200, 0, 1000);
92
93   fTzeroObject     = new TObjArray();
94   fTzeroObject->SetOwner(kTRUE);
95   
96   for (Int_t i=0; i<24; i++)
97     fTzeroObject->AddAtAndExpand(fTimeVSAmplitude[i],i);
98
99   fTzeroObject->AddAtAndExpand(fCFDVSPmtId,24);
100   fTzeroObject->AddAtAndExpand(fSPDVertexVST0Vertex,25);
101   fTzeroObject->AddAtAndExpand(fTzeroORAplusORC, 26);
102   fTzeroObject->AddAtAndExpand(fResolution, 27);
103   fTzeroObject->AddAtAndExpand(fTzeroORA, 28);
104   fTzeroObject->AddAtAndExpand(fTzeroORC, 29);
105   fTzeroObject->AddAtAndExpand(fT0vsNtracks, 30);
106   fTzeroObject->AddAtAndExpand(fOrAvsNtracks,31);
107   fTzeroObject->AddAtAndExpand(fOrCvsNtracks, 32);
108   fTzeroObject->AddAtAndExpand(fEffC, 33);
109   fTzeroObject->AddAtAndExpand(fEffA, 34);
110   fTzeroObject->AddAtAndExpand(fEffAC, 35);
111   fTzeroObject->AddAtAndExpand(ftracksEffSPD, 36);
112
113   PostData(1, fTzeroObject);
114   // Called once
115 }
116
117 //________________________________________________________________________
118 void AliT0AnalysisTaskQA::UserExec(Option_t *) 
119 {
120   // Main loop
121   // Called for each event
122
123   // Post output data.
124   fESD = dynamic_cast<AliESDEvent*>(InputEvent());
125   if (!fESD) {
126     printf("ERROR: fESD not available\n");
127     return;
128   }
129
130   fRunNumber =  fESD->GetRunNumber() ; 
131
132   const Double32_t* time = fESD->GetT0time();
133   const Double32_t* amplitude = fESD->GetT0amplitude();
134
135  
136   for (Int_t i=0; i<24; i++) {
137     if(time[i]<9999 &&abs(time[i])>1e-8 && amplitude[i]<9999&&abs(amplitude[i])>1e-8 )
138       {
139         //      cout<<"time "<<time[i]<<" amplitude "<<amplitude[i]<<endl;
140         fTimeVSAmplitude[i]->Fill(amplitude[i],time[i]);
141         fCFDVSPmtId->Fill(i,time[i]);
142       }
143   }
144
145   const Double32_t* mean = fESD->GetT0TOF();
146   Double32_t orA = mean[1];
147   Double32_t orC = mean[2];
148   Int_t ntracks = fESD->GetNumberOfTracks(); 
149
150   if(orA<99999){
151     fTzeroORA->Fill(orA);
152     fOrAvsNtracks->Fill(ntracks, orA);
153     fEffA->Fill(ntracks);
154   }
155   if(orC<99999) {
156     fTzeroORC->Fill(orC);
157     fOrCvsNtracks->Fill(ntracks, orC);
158     fEffC->Fill(ntracks);
159    }
160   if(orA<99999 && orC<99999) {
161     fResolution->Fill((orA-orC)/2.);
162     fTzeroORAplusORC->Fill(mean[0]);
163     fEffAC->Fill(ntracks);
164     fT0vsNtracks->Fill(ntracks, mean[0]);
165   }
166   
167   Double32_t t0vertex = fESD->GetT0zVertex();
168   Double32_t esdzvertex;
169   const AliESDVertex * esdvertex = fESD->GetPrimaryVertex();
170   Int_t nofcontrib=-1;
171   nofcontrib=esdvertex->GetNContributors();
172   if(nofcontrib>0)    ftracksEffSPD->Fill(ntracks);
173    if(esdvertex && t0vertex<999)
174     {
175       if(nofcontrib>0)
176         {
177           esdzvertex=esdvertex->GetZv();
178           fSPDVertexVST0Vertex->Fill(t0vertex,esdzvertex);
179         }
180     }
181   PostData(1, fTzeroObject);
182 }      
183  //________________________________________________________________________
184 void AliT0AnalysisTaskQA::Terminate(Option_t *) 
185 {
186   
187    // Called once at the end of the query
188 }