T0calib lib added
[u/mrichter/AliRoot.git] / T0 / AliT0CalibAnalysisTask.cxx
CommitLineData
c0fcf951 1#include "TChain.h"
2#include "TTree.h"
3#include "TList.h"
4#include "TH1F.h"
5#include "TH2F.h"
6#include "TCanvas.h"
7#include "TMath.h"
8#include "TObjString.h"
9
10#include "AliAnalysisTask.h"
11#include "AliPhysicsSelection.h"
12#include "AliAnalysisManager.h"
13
14#include "AliESDEvent.h"
15#include "AliESDfriend.h"
16#include "AliESDInputHandler.h"
17#include "AliESDTZEROfriend.h"
18#include "AliT0CalibAnalysisTask.h"
19#include "AliESDVZERO.h"
20#include "AliMultiplicity.h"
21#include "AliTriggerAnalysis.h"
22#include "AliESDpid.h"
23#include "AliESDtrackCuts.h"
24#include "AliCentrality.h"
25#include "AliVEvent.h"
26
27ClassImp(AliT0CalibAnalysisTask)
28
29//________________________________________________________________________
30AliT0CalibAnalysisTask::AliT0CalibAnalysisTask(const char *name)
31 : AliAnalysisTaskSE(name), fESD(0), fOutputList(0),
32 fT0OutTree(0x0), fEvent(-99999), fOrbit(-99999), fBC(-99999),
33 fTrackletSPD(-99999), fClustersSPD(-99999), fNcont(-99999), fNcontTPC(-99999),
34 fVertex(-99999), fVertexcalc(-99999), fVertexSPD(-99999), fVertexTPC(-99999),
35 fMeanAC(-99999), fMeanA(-99999),fMeanC(-99999), fMeanACcalc(-99999), fMeanAcalc(-99999), fMeanCcalc(-99999),
36 fMultV0A(-99999), fMultV0C(-99999),fTimeV0A(-99999),fTimeV0C(-99999), fSumampA(-99999), fSumampC(-99999),
37 ftimestamp(0), fSep2(0),
38 fZDCcut(kFALSE), fT0Trigger(0), fpileup(kFALSE), fTrigger(0x0),
39 fT0_amplitude(0x0), fT0_time(0x0),
40 fcentralityV0M(0), fcentralityZDC(0), fcentralityTRK(0), fcentralityCLA(0),
41 fESDtracks(0),
4c0e429d 42 fMultiplicity(-99999),
c0fcf951 43 fTriggerinput(0x0), fZDCbg(kFALSE),
44 fTOFtracks(0), fT0tofTrack(0),
45 fESDpid(new AliESDpid())
46{
47 // Constructor
48
49 // Define input and output slots here
50 // Input slot #0 works with a TChain
51 DefineInput(0, TChain::Class());
52 // Output slot #0 id reserved by the base class for AOD
53 // Output slot #1 writes into a TH1 container
54 DefineOutput(1, TList::Class());
55}
56
57//________________________________________________________________________
58AliT0CalibAnalysisTask::~AliT0CalibAnalysisTask()
59{
60// Destructor
61 if (fT0OutTree) delete fT0OutTree ;
62}
63
64//_____________________________________________________________________________
65Bool_t AliT0CalibAnalysisTask::UserNotify()
66{
67//
68// Calls the mother class Notify()
69//
70
71// AliDebug(AliLog::kDebug,"<-");
72 // AliDebug(AliLog::kDebug,"->");
73
74 return AliAnalysisTaskSE::UserNotify();
75}
76
77//________________________________________________________________________
78void AliT0CalibAnalysisTask::UserCreateOutputObjects()
79{
80 // Create histograms
81 // Called once
82 fOutputList = new TList();
83 fOutputList->SetOwner(); // Will delete the histos on cleanup
84
85 fT0OutTree=new TTree("t0tree","None here");
86 fT0OutTree->Branch("fNevent", &fEvent);
87 fT0OutTree->Branch("fOrbit", &fOrbit);
88 fT0OutTree->Branch("fBC", &fBC);
89 fT0OutTree->Branch("fNcont", &fNcont, "fNcont/I");
90 fT0OutTree->Branch("fNcontTPC", &fNcontTPC);
91 fT0OutTree->Branch("fVertexTPC", &fVertexTPC);
92 fT0OutTree->Branch("vertexT0", &fVertex, "fVertex/F");
93 fT0OutTree->Branch("vertexSPD", &fVertexSPD, "vertexSPD/F");
94 fT0OutTree->Branch("meanAC", &fMeanAC,"meanAC/F");
95 fT0OutTree->Branch("meanA", &fMeanA,"meanA/F");
96 fT0OutTree->Branch("meanC", &fMeanC,"meanC/F");
97 fT0OutTree->Branch("trackletSPD", &fTrackletSPD,"trackletSPD/I");
98 fT0OutTree->Branch("clustersSPD", &fClustersSPD,"clustersSPD/I");
99 fT0OutTree->Branch("TOFtracks", &fTOFtracks);
100 fT0OutTree->Branch("ESDtracks", &fESDtracks);
101 fT0OutTree->Branch("multV0A", &fMultV0A,"multV0A/F");
102 fT0OutTree->Branch("multV0C", &fMultV0C,"multV0C/F");
103 fT0OutTree->Branch("timeV0A", &fTimeV0A,"timeV0A/F");
104 fT0OutTree->Branch("timeV0C", &fTimeV0C,"timeV0C/F");
105 fT0OutTree->Branch("sumampA", &fSumampA);
106 fT0OutTree->Branch("sumampC", &fSumampC);
107 fT0OutTree->Branch("pileup", &fpileup);
108 fT0OutTree->Branch("trigger", &fTrigger);
109 fT0OutTree->Branch("triggerinput", &fTriggerinput);
110 fT0OutTree->Branch("T0trigger", &fT0Trigger);
111 fT0OutTree->Branch("t0tofTrack", &fT0tofTrack);
112 fT0OutTree->Branch("ZDCcut", &fZDCcut);
113 fT0OutTree->Branch("ftimestamp", &ftimestamp);
114 fT0OutTree->Branch("centralityV0M", &fcentralityV0M);
115 fT0OutTree->Branch("centralityZDC", &fcentralityZDC);
116 fT0OutTree->Branch("centralityTRK", &fcentralityTRK);
117 fT0OutTree->Branch("centralityCLA", &fcentralityCLA);
118 for ( Int_t i=0; i<24; i++) {
119 fT0OutTree->Branch(Form("amp%i", i+1), &famp[i]);
120 fT0OutTree->Branch(Form("time%i", i+1), &ftime[i]);
4c0e429d 121 fT0OutTree->Branch(Form("ftimefriend%i", i+1), &ftimefriend[i]);
122 fT0OutTree->Branch(Form("fampfriend%i", i+1), &fampfriend[i]);
123 fT0OutTree->Branch(Form("fampledfriend%i", i+1), &fampledfriend[i]);
c0fcf951 124 }
125 for ( Int_t i=0; i<5; i++) {
126 fT0OutTree->Branch(Form("fOrA%i", i+1), &fOrA[i]);
127 fT0OutTree->Branch(Form("fOrC%i", i+1), &fOrC[i]);
128 fT0OutTree->Branch(Form("fTVDC%i", i+1), &fTVDC[i]);
129 for ( Int_t ii=0; ii<24; ii++)
130 fT0OutTree->Branch(Form("fRawTime%i_%i", ii+1, i+1), &fRawTime[ii][i]);
131 }
132 TString pilename[3] = {"T0pileup", "T0background", "T0satellite"};
133 for ( Int_t i=0; i<3; i++)
134 fT0OutTree->Branch(pilename[i].Data(), &fT0pileup[i]);
135 fT0OutTree->Branch("meanACbest", &fMeanACcalc,"meanACcalc/F");
136 fT0OutTree->Branch("meanAbest", &fMeanAcalc,"meanAcalc/F");
137 fT0OutTree->Branch("meanCbest", &fMeanCcalc,"meanCcalc/F");
138 fT0OutTree->Branch("multEstimator", &fMultiplicity);
139 //ZDC background
140 fT0OutTree->Branch("zbg", &fZDCbg);
141 fESDpid = new AliESDpid();
142
143 fOutputList->Add(fT0OutTree);
144
145 PostData(1, fOutputList);
146
147}
148
149//________________________________________________________________________
150void AliT0CalibAnalysisTask::UserExec(Option_t *)
151{
152 // Main loop
153 // Called for each event
154 fVertex= fVertexSPD = fMeanAC = fMeanA = fMeanC = fTrackletSPD=-99999;
155 fMeanACcalc = fMeanAcalc = fMeanCcalc = fNcont = fNcontTPC = -99999;
156 fMultV0A=fMultV0C=fTimeV0A=fTimeV0C=fMultiplicity = -99999;
157
158 for (Int_t i=0; i<24; i++) {
159 famp[i] = ftime[i] = -9999;
160 for ( Int_t i0=0; i0<5; i0++) {
161 fRawTime[i][i0] = -9999;
162 if(i0==0) {
163 fTVDC[i0]=-9999;
164 fOrC[i0]=-9999;
165 fOrA[i0]=-9999;
166 }
167 }
168 }
169 Float_t orA , orC, tvdc;
170 orA = orC = tvdc = -9999;
171 fBC = -9999;
172 // Post output data.
173 fESD = dynamic_cast<AliESDEvent*>(InputEvent());
174 if (!fESD) {
175 printf("ERROR: fESD not available\n");
176 return;
177 }
178
179 if(fESD)
180 {
181 // if(fIsSelected)
182 {
183 fZDCbg = kFALSE;
184 /*
185 AliTriggerAnalysis *fTriggerAnalysis;
186 Bool_t fZDCbgA = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kZNABG);
187 Bool_t fZDCbgC = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kZNCBG);
188 fZDCbg = (fZDCbgA);
189 cout<<" ZDC back "<<fZDCbgA<<endl;
190 */
191 AliESDVZERO* esdV0 = fESD->GetVZEROData();
192 const AliMultiplicity *mult = fESD->GetMultiplicity();
193 // printf(" VZERO MULT \n");
194 AliESDTZERO* tz= (AliESDTZERO*) fESD->GetESDTZERO();
195
196 const Double32_t *amp, *time, *mean ;
197 const Double32_t *meanbest;
198 fVertex= fVertexSPD = fMeanAC = fMeanA = fMeanC = fTrackletSPD=-99999;
199 fMeanACcalc = fMeanAcalc = fMeanCcalc = fNcont = fNcontTPC -99999;
200 fMultV0A=fMultV0C=fTimeV0A=fTimeV0C=fMultiplicity = -99999;
201
202 fSumampA=0;
203 fSumampC=0;
204 fNcont=0;
205 TString triggers = fESD->GetFiredTriggerClasses();
206 fTrigger.SetString(triggers.Data());
207 if ( !triggers.Contains("Z") ) cout<<triggers<<endl;
208 TString inputtriggers =fESD-> GetHeader()->GetFiredTriggerInputs();
209 // cout<<inputtriggers<<endl;
210 fTriggerinput.SetString(inputtriggers.Data());
211
212
213 fEvent=fESD->GetEventNumberInFile();
214 fT0Trigger=fESD->GetT0Trig();
215
216 fESDtracks=fESD->GetNumberOfTracks();
217 AliTriggerAnalysis *trigAna = new AliTriggerAnalysis;
218 ftimestamp=fESD->GetTimeStamp(); // - 1301217882;
219 // printf (" timestamp %d \n", ftimestamp);
220
221 fMultiplicity = AliESDtrackCuts::GetReferenceMultiplicity(fESD);
222 // cout<<" fMultiplicity "<<fMultiplicity<<endl;
223 fOrbit=fESD->GetOrbitNumber();
224 fBC=fESD->GetBunchCrossNumber();
225 fNcont = fESD->GetPrimaryVertexSPD()->GetNContributors();
226 fNcontTPC = fESD->GetPrimaryVertexTPC()->GetNContributors();
227 if(fNcontTPC>=2 )
228 fVertexTPC = fESD->GetPrimaryVertexTPC() ->GetZ();
229 if(fNcont>=0 ) {
230 fVertexSPD = fESD->GetPrimaryVertex()->GetZ();
231 }
232 fTrackletSPD = mult->GetNumberOfTracklets();
233 fClustersSPD = mult->GetNumberOfITSClusters(0);
234 fMultV0A = esdV0->GetMTotV0A();
235 fMultV0C = esdV0->GetMTotV0C();
236 //TOF hit
237 Int_t ntracksMatchedToTOF = 0;
238 Int_t ntracks = fESD->GetNumberOfTracks();
239 for(Int_t itrk=0;itrk<ntracks;itrk++){
240 AliESDtrack* track = fESD->GetTrack(itrk);
241 if (!track) {
242 Printf("ERROR: Could not receive track %d", itrk);
243 continue;
244 }
245 //no track selection just TOF hit
246 if (track->IsOn(AliESDtrack::kTOFout)) ntracksMatchedToTOF++;
247 }
248
249 fTOFtracks = ntracksMatchedToTOF;
250 if(fESDpid){ //get T0_TOF
251 fESDpid->SetTOFResponse(fESD,AliESDpid::kTOF_T0);
252 fT0tofTrack =(Float_t) (fESDpid->GetTOFResponse().GetStartTime(10.0)); //Get start time "from all tracks
253 // printf("@@TOF T0 %f\n",fT0tofTrack);
254 }
255
256
257 fpileup = fESD->IsPileupFromSPD();
258 fTimeV0C = esdV0->GetV0CTime();
259 fTimeV0A = esdV0->GetV0ATime();
260 // printf(" Vo info \n");
261
262
263 mean = fESD->GetT0TOF();
264 fVertex=fESD->GetT0zVertex();
265 fMeanA = mean[1];
266 fMeanC = mean[2];
267 if (TMath::Abs(fMeanA)<9999 && TMath::Abs(fMeanC)<9999)
268 fMeanAC = mean[0] ;
269 fSumampC = tz->GetMultC();
270 fSumampA = tz->GetMultA();
271 // printf("!!!!!!!!fSumampC %f fSumampA %f \n",fSumampC, fSumampA);
272
273 amp=fESD->GetT0amplitude();
274 time=fESD->GetT0time();
275 for (Int_t i=0; i<24; i++){
276 if( time[i]>100 && amp[i]>0.1){
277 famp[i] = amp[i];
278 ftime[i] = time[i];
279 }
280 }
281
282 //new raw OrA OrC TVDC
283 meanbest = tz->GetT0TOFbest();
284 fMeanAcalc = meanbest[1];
285 fMeanCcalc = meanbest[2];
286 if (TMath::Abs(fMeanAcalc)<9999 && TMath::Abs(fMeanCcalc)<9999)
287 fMeanACcalc = meanbest[0] ;
288 for (Int_t ii=0; ii<5; ii++){
289 orA = tz->GetOrA(ii);
290 orC = tz->GetOrC(ii);
291 tvdc = tz->GetTVDC(ii);
292 // printf("@@@@@ new signasl %d %f %f %f \n",ii, orA, orC, tvdc);
293 if(ii==0) {
294 fOrA[ii] = orA;
295 fOrC[ii] = orC;
296 fTVDC[ii] = tvdc;
297 // cout<<tvdc<<" "<<fT0Trigger<<endl;
298 // if (tvdc>-5 && tvdc<5 && tvdc!=0)
299 // cout<<"@@@@@@@@@ "<< tvdc<<" "<<fT0Trigger<<endl;
300 } else {
301 if ( ii>0 && fOrA[ii-1] !=orA) fOrA[ii] = orA;
302 else fOrA[ii]=-9999;
303 if ( ii>0 && fOrC[ii-1] !=orC) fOrC[ii] = orC;
304 else fOrC[ii]=-9999;
305 if ( ii>0 && fTVDC[ii-1] != tvdc) fTVDC[ii] = tvdc;
306 else fTVDC[ii]=-9999;
307 }
308 for (Int_t iii=0; iii<24; iii++)
309 fRawTime[iii][ii] = tz->GetTimeFull(iii,ii);
310 }
311 fT0pileup[0] = tz->GetPileupFlag();
312 fT0pileup[1] = tz->GetBackgroundFlag();
313 fT0pileup[2] = tz->GetSatellite();
314
315 AliCentrality *centrality = fESD->GetCentrality();
316
317 //The centrality function you can use
4c0e429d 318 if(centrality) {
319 fcentralityV0M = centrality->GetCentralityPercentile("V0M"); // returns the centrality
320 fcentralityTRK = centrality->GetCentralityPercentile("TRK"); // returns the centrality
321 fcentralityZDC = centrality->GetCentralityPercentile("ZEMvsZDC"); // returns the
322 }
323 AliESDfriend* esdFriend = static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
324 if (esdFriend) {
325 // cout<<" !!!!!esdFriend "<<endl;
326 AliESDTZEROfriend * t0friend =esdFriend-> GetTZEROfriend();
327 // cout<<" !!!!t0friend "<<t0friend<<endl;
328 if(t0friend){
329 Double_t *ftimefr = t0friend->GetT0timeCorr();
330 Double_t *fampqtcfr = t0friend->GetT0ampQTC();
331 Double_t *fampledfr = t0friend->GetT0ampLEDminCFD();
332 for (Int_t iii=0; iii<24; iii++){
333 ftimefriend[iii]=ftimefr[iii];
334 fampfriend[iii]=fampqtcfr[iii];
335 fampledfriend[iii]=fampledfr[iii];
336 // cout<<" friend "<<ftimefriend[iii]<<endl;
337 }
338 } //t0friend
339 } //ESDfriend
c0fcf951 340
c0fcf951 341
342 } //selected
343 } //ESD
344
345 fT0OutTree->Fill();
346
347 PostData(1, fOutputList);
348
349}
350
351//________________________________________________________________________
352void AliT0CalibAnalysisTask::Terminate(Option_t *)
353{
354 // Draw result to the screen
355 // Called once at the end of the query
356
357 /* fOutputList = dynamic_cast<TList*> (GetOutputData(1));
358 if (!fOutputList) {
359 printf("ERROR: Output list not available\n");
360 return;
361 }
362 */
363
364}