changes for Vertex and Tracks classes
[u/mrichter/AliRoot.git] / PWGPP / 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 #include "AliESDpid.h"
17
18 //#include "AliCDBMetaData.h"
19 //#include "AliCDBId.h"
20 //#include "AliCDBEntry.h"
21 //#include "AliCDBManager.h"
22 //#include "AliCDBStorage.h"
23
24 // Task should calculate channels offset 
25 // Authors: Alla
26 //last change 23 Feb 2012 FK
27
28 ClassImp(AliT0AnalysisTaskQA)
29 //________________________________________________________________________
30 AliT0AnalysisTaskQA::AliT0AnalysisTaskQA() 
31   : AliAnalysisTaskSE(),  fESD(0x0), fTzeroObject(0x0),
32   fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0), fTzeroTof(0x0),
33     fRunNumber(0),fTimeVSAmplitude(0x0),fCFDVSPmtId(0x0),fSPDVertexVST0Vertex(0x0),
34     fOrAvsNtracks(0x0), fOrCvsNtracks(0x0), fT0vsNtracks(0x0),fT0TimevsT0Tof(0x0),
35     fESDpid(new AliESDpid())
36 {
37   // Constructor
38
39   // Define input and output slots here
40   // Input slot #0 works with a TChain
41
42 // ########### NEVER define slots in the IO constructor
43 //  DefineInput(0,  TChain::Class());
44 //  DefineOutput(1, TObjArray::Class());
45 }
46
47
48 //________________________________________________________________________
49 AliT0AnalysisTaskQA::AliT0AnalysisTaskQA(const char *name) 
50   : AliAnalysisTaskSE(name),  fESD(0x0), fTzeroObject(0x0),
51   fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0), fTzeroTof(0x0),
52     fRunNumber(0),fTimeVSAmplitude(0x0),fCFDVSPmtId(0x0),fSPDVertexVST0Vertex(0x0),
53     fOrAvsNtracks(0x0), fOrCvsNtracks(0x0), fT0vsNtracks(0x0),fT0TimevsT0Tof(0x0),
54     fESDpid(new AliESDpid())
55 {
56   // Constructor
57   // Define input and output slots here
58   // Input slot #0 works with a TChain
59   DefineInput(0, TChain::Class());
60   DefineOutput(1, TObjArray::Class());
61   // Output slot #0 id reserved by the base class for AOD
62   // Output slot #1 writes into a TH1 container
63 }
64
65 //________________________________________________________________________
66 AliT0AnalysisTaskQA::~AliT0AnalysisTaskQA() 
67 {
68   // Destructor
69   // printf("AliT0CalibOffsetChannels~AliT0CalibOffsetChannels() ");
70   delete fTzeroORA;
71   delete fTzeroORC;
72   delete fResolution;
73   delete fTzeroORAplusORC;
74   delete fTzeroTof;
75   delete [] fTimeVSAmplitude;
76   delete fCFDVSPmtId;
77   delete fSPDVertexVST0Vertex;
78   delete fOrAvsNtracks;
79   delete fOrCvsNtracks;
80   delete fT0vsNtracks;
81   delete fT0TimevsT0Tof;
82
83   delete fESDpid;
84   delete fTzeroObject;
85 }
86
87 //------------------------------------------------------------------
88 void AliT0AnalysisTaskQA::UserCreateOutputObjects()
89 {
90   // Create histograms
91  fTimeVSAmplitude = new TH2F*[kNPMT0];
92
93  for (Int_t i=0; i<kNPMT0; i++) {
94     fTimeVSAmplitude[i]= new TH2F (Form("fTimeVSAmplitude%d",i+1),"fTimeVsAmplitude",60, -10, 50,500,2000,7000);
95   }
96
97   fTzeroORAplusORC = new TH1F("fTzeroORAplusORC","ORA+ORC /2",100,-2000,2000);   //or A plus or C 
98   fTzeroTof        = new TH1F("fTzeroTof","t0 from TOF",100,-2000,2000);   //t0 start time from TOF
99   fResolution      = new TH1F("fResolution","fResolution",100,-500,500);// or A minus or C spectrum
100   fTzeroORA        = new TH1F("fTzeroORA","fTzeroORA",100,-2000,2000);// or A spectrum
101   fTzeroORC        = new TH1F("fTzeroORC","fTzeroORC",100,-2000,2000);// or C spectrum
102   fCFDVSPmtId      = new TH2F("fCFDVSPmtId","fCFDVSPmtId",24,0,24,500,2000,7000);  // 
103   fSPDVertexVST0Vertex = new TH2F("fSPDVertexVST0Vertex","fSPDVertexVST0Vertex",30,-30,30,30,-30,30);
104   fOrAvsNtracks = new TH2F("fAvstracks", "A vs tracks",200, 0, 1000, 200, -1000, 1000);
105   fOrCvsNtracks = new TH2F("fCvstracks", "C vs tracks",200, 0, 1000, 200, -1000, 1000);
106   fT0vsNtracks  = new TH2F("fT0ACvstrackes", "T0AC vs tracks",200, 0, 1000, 200, -1000, 1000); 
107   fT0TimevsT0Tof = new TH2F("fT0TimevsT0Tof", "fT0TimevsT0Tof",50, -1000,1000, 50, -1000,1000); 
108
109   fTzeroObject     = new TObjArray(0);
110   fTzeroObject->SetOwner(kTRUE);
111   
112   for (Int_t i=0; i<kNPMT0; i++)
113     fTzeroObject->AddAtAndExpand(fTimeVSAmplitude[i],i);
114
115   fTzeroObject->AddAtAndExpand(fCFDVSPmtId,24);
116   fTzeroObject->AddAtAndExpand(fSPDVertexVST0Vertex,25);
117   fTzeroObject->AddAtAndExpand(fTzeroORAplusORC, 26);
118   fTzeroObject->AddAtAndExpand(fResolution, 27);
119   fTzeroObject->AddAtAndExpand(fTzeroORA, 28);
120   fTzeroObject->AddAtAndExpand(fTzeroORC, 29);
121   fTzeroObject->AddAtAndExpand(fT0vsNtracks, 30);
122   fTzeroObject->AddAtAndExpand(fOrAvsNtracks,31);
123   fTzeroObject->AddAtAndExpand(fOrCvsNtracks, 32);
124   fTzeroObject->AddAtAndExpand(fTzeroTof, 33);
125   fTzeroObject->AddAtAndExpand(fT0TimevsT0Tof, 34);
126
127   PostData(1, fTzeroObject);
128   // Called once
129 }
130
131 //________________________________________________________________________
132 void AliT0AnalysisTaskQA::UserExec(Option_t *) 
133 {
134   // Main loop
135   // Called for each event
136
137   // Post output data.
138   fESD = dynamic_cast<AliESDEvent*>(InputEvent());
139   if (!fESD) {
140     printf("ERROR: fESD not available\n");
141     return;
142   }
143
144   fRunNumber =  fESD->GetRunNumber() ; 
145
146   const Double32_t* time = fESD->GetT0time();
147   const Double32_t* amplitude = fESD->GetT0amplitude();
148
149  
150   for (Int_t i=0; i<kNPMT0; i++) {
151     if(time[i]<9999 &&abs(time[i])>1e-8 && amplitude[i]<9999&&abs(amplitude[i])>1e-8 )
152       {
153         //      cout<<"time "<<time[i]<<" amplitude "<<amplitude[i]<<endl;
154         fTimeVSAmplitude[i]->Fill(amplitude[i],time[i]);
155         fCFDVSPmtId->Fill(i,time[i]);
156       }
157   }
158
159   const Double32_t* mean = fESD->GetT0TOF();
160   Double32_t orA = mean[1];
161   Double32_t orC = mean[2];
162   Int_t ntracks = fESD->GetNumberOfTracks();
163
164   Int_t ntracksMatchedToTOF = 0; 
165   for(Int_t itrk=0;itrk<ntracks;itrk++){
166     AliESDtrack* track = fESD->GetTrack(itrk);
167     if (!track) {
168       Printf("ERROR: Could not receive track %d", itrk);
169       continue;
170     }
171     //no track selection just TOF hit
172     if (track->IsOn(AliESDtrack::kTOFout)) ntracksMatchedToTOF++;
173   }
174
175   if(orA<9999){
176     fTzeroORA->Fill(orA);
177     fOrAvsNtracks->Fill(ntracksMatchedToTOF, orA);
178   }
179   if(orC<9999) {
180     fTzeroORC->Fill(orC);
181     fOrCvsNtracks->Fill(ntracksMatchedToTOF, orC);
182   }
183   if(orA<9999 && orC<9999) {
184     fResolution->Fill((orA-orC)/2.);
185     fTzeroORAplusORC->Fill(mean[0]);
186     fT0vsNtracks->Fill(ntracksMatchedToTOF, mean[0]);
187   }
188
189   if(fESDpid){ //get T0_TOF 
190     fESDpid->SetTOFResponse(fESD,AliESDpid::kTOF_T0);
191     Float_t t0tofTrack =(Float_t) (fESDpid->GetTOFResponse().GetStartTime(10.0)); //Get start time from all tracks 
192     if (t0tofTrack !=0) fTzeroTof->Fill(t0tofTrack);
193
194     if(orA<9999 && orC<9999 && t0tofTrack !=0){ // T0 time  and  TOF time simultaneously
195       fT0TimevsT0Tof->Fill(t0tofTrack, mean[0]);
196     }
197   }
198   
199   Double32_t t0vertex = fESD->GetT0zVertex();
200   //  cout << "t0 vertex "<<t0vertex<<endl;
201   Double32_t esdzvertex;
202   const AliESDVertex * esdvertex = fESD->GetPrimaryVertex();
203   Int_t nofcontrib=-1;
204   if(esdvertex && t0vertex<999)
205     {
206       nofcontrib=esdvertex->GetNContributors();
207       if(nofcontrib>1)
208         {
209           esdzvertex=esdvertex->GetZ();
210           //      cout << "esd vertex "<<esdzvertex<<endl;
211           fSPDVertexVST0Vertex->Fill(t0vertex,esdzvertex);
212         }
213     }
214   // printf("%f   %f  %f\n",orA,orC,time);
215   PostData(1, fTzeroObject);
216 }      
217  //________________________________________________________________________
218 void AliT0AnalysisTaskQA::Terminate(Option_t *) 
219 {
220   
221    // Called once at the end of the query
222 }