"Setting correct gains for Pb-p in simulation"
[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),
36bbdbd3 33 fTrackletSPD(-99999), fNcont(-99999),
34 fVertex(-99999), fVertexSPD(-99999),
35 fMeanAC(-99999), fMeanA(-99999),fMeanC(-99999),
c0fcf951 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),
36bbdbd3 40 fcentralityV0M(0), fcentralityZDC(0), fcentralityTRK(0),
c0fcf951 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");
c0fcf951 90 fT0OutTree->Branch("vertexT0", &fVertex, "fVertex/F");
91 fT0OutTree->Branch("vertexSPD", &fVertexSPD, "vertexSPD/F");
92 fT0OutTree->Branch("meanAC", &fMeanAC,"meanAC/F");
93 fT0OutTree->Branch("meanA", &fMeanA,"meanA/F");
94 fT0OutTree->Branch("meanC", &fMeanC,"meanC/F");
95 fT0OutTree->Branch("trackletSPD", &fTrackletSPD,"trackletSPD/I");
c0fcf951 96 fT0OutTree->Branch("TOFtracks", &fTOFtracks);
97 fT0OutTree->Branch("ESDtracks", &fESDtracks);
98 fT0OutTree->Branch("multV0A", &fMultV0A,"multV0A/F");
99 fT0OutTree->Branch("multV0C", &fMultV0C,"multV0C/F");
100 fT0OutTree->Branch("timeV0A", &fTimeV0A,"timeV0A/F");
101 fT0OutTree->Branch("timeV0C", &fTimeV0C,"timeV0C/F");
102 fT0OutTree->Branch("sumampA", &fSumampA);
103 fT0OutTree->Branch("sumampC", &fSumampC);
104 fT0OutTree->Branch("pileup", &fpileup);
105 fT0OutTree->Branch("trigger", &fTrigger);
106 fT0OutTree->Branch("triggerinput", &fTriggerinput);
107 fT0OutTree->Branch("T0trigger", &fT0Trigger);
108 fT0OutTree->Branch("t0tofTrack", &fT0tofTrack);
109 fT0OutTree->Branch("ZDCcut", &fZDCcut);
110 fT0OutTree->Branch("ftimestamp", &ftimestamp);
111 fT0OutTree->Branch("centralityV0M", &fcentralityV0M);
112 fT0OutTree->Branch("centralityZDC", &fcentralityZDC);
113 fT0OutTree->Branch("centralityTRK", &fcentralityTRK);
c0fcf951 114 for ( Int_t i=0; i<24; i++) {
115 fT0OutTree->Branch(Form("amp%i", i+1), &famp[i]);
116 fT0OutTree->Branch(Form("time%i", i+1), &ftime[i]);
36bbdbd3 117 fT0OutTree->Branch(Form("fRawTime%i", i+1), &fRawTime[i]);
c0fcf951 118 }
119 for ( Int_t i=0; i<5; i++) {
120 fT0OutTree->Branch(Form("fOrA%i", i+1), &fOrA[i]);
121 fT0OutTree->Branch(Form("fOrC%i", i+1), &fOrC[i]);
122 fT0OutTree->Branch(Form("fTVDC%i", i+1), &fTVDC[i]);
c0fcf951 123 }
124 TString pilename[3] = {"T0pileup", "T0background", "T0satellite"};
125 for ( Int_t i=0; i<3; i++)
126 fT0OutTree->Branch(pilename[i].Data(), &fT0pileup[i]);
c0fcf951 127 fT0OutTree->Branch("multEstimator", &fMultiplicity);
128 //ZDC background
129 fT0OutTree->Branch("zbg", &fZDCbg);
130 fESDpid = new AliESDpid();
131
132 fOutputList->Add(fT0OutTree);
133
134 PostData(1, fOutputList);
135
136}
137
138//________________________________________________________________________
139void AliT0CalibAnalysisTask::UserExec(Option_t *)
140{
141 // Main loop
142 // Called for each event
36bbdbd3 143 fVertex= fVertexSPD = fMeanAC = fMeanA = fMeanC = fTrackletSPD = fNcont = -99999;
c0fcf951 144 fMultV0A=fMultV0C=fTimeV0A=fTimeV0C=fMultiplicity = -99999;
145
36bbdbd3 146 for (Int_t i=0; i<24; i++)
147 famp[i] = ftime[i] = fRawTime[i] = -9999;
148
149 for ( Int_t i0=0; i0<5; i0++) {
150 fTVDC[i0]=-9999;
151 fOrC[i0]=-9999;
152 fOrA[i0]=-9999;
c0fcf951 153 }
36bbdbd3 154
c0fcf951 155 Float_t orA , orC, tvdc;
156 orA = orC = tvdc = -9999;
157 fBC = -9999;
158 // Post output data.
159 fESD = dynamic_cast<AliESDEvent*>(InputEvent());
160 if (!fESD) {
161 printf("ERROR: fESD not available\n");
162 return;
163 }
36bbdbd3 164
c0fcf951 165 if(fESD)
166 {
167 // if(fIsSelected)
168 {
169 fZDCbg = kFALSE;
170 /*
36bbdbd3 171 AliTriggerAnalysis *fTriggerAnalysis;
172 Bool_t fZDCbgA = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kZNABG);
173 Bool_t fZDCbgC = fTriggerAnalysis->IsOfflineTriggerFired(fESD, AliTriggerAnalysis::kZNCBG);
174 fZDCbg = (fZDCbgA);
175 cout<<" ZDC back "<<fZDCbgA<<endl;
c0fcf951 176 */
177 AliESDVZERO* esdV0 = fESD->GetVZEROData();
178 const AliMultiplicity *mult = fESD->GetMultiplicity();
179 // printf(" VZERO MULT \n");
180 AliESDTZERO* tz= (AliESDTZERO*) fESD->GetESDTZERO();
36bbdbd3 181
c0fcf951 182 const Double32_t *amp, *time, *mean ;
36bbdbd3 183 fVertex= fVertexSPD = fMeanAC = fMeanA = fMeanC = fTrackletSPD = fNcont =-99999;
c0fcf951 184 fMultV0A=fMultV0C=fTimeV0A=fTimeV0C=fMultiplicity = -99999;
185
186 fSumampA=0;
187 fSumampC=0;
188 fNcont=0;
189 TString triggers = fESD->GetFiredTriggerClasses();
190 fTrigger.SetString(triggers.Data());
c0fcf951 191 TString inputtriggers =fESD-> GetHeader()->GetFiredTriggerInputs();
192 // cout<<inputtriggers<<endl;
193 fTriggerinput.SetString(inputtriggers.Data());
c0fcf951 194 fEvent=fESD->GetEventNumberInFile();
195 fT0Trigger=fESD->GetT0Trig();
196
197 fESDtracks=fESD->GetNumberOfTracks();
c0fcf951 198 ftimestamp=fESD->GetTimeStamp(); // - 1301217882;
199 // printf (" timestamp %d \n", ftimestamp);
200
201 fMultiplicity = AliESDtrackCuts::GetReferenceMultiplicity(fESD);
202 // cout<<" fMultiplicity "<<fMultiplicity<<endl;
203 fOrbit=fESD->GetOrbitNumber();
204 fBC=fESD->GetBunchCrossNumber();
205 fNcont = fESD->GetPrimaryVertexSPD()->GetNContributors();
c0fcf951 206 if(fNcont>=0 ) {
207 fVertexSPD = fESD->GetPrimaryVertex()->GetZ();
208 }
209 fTrackletSPD = mult->GetNumberOfTracklets();
c0fcf951 210 fMultV0A = esdV0->GetMTotV0A();
211 fMultV0C = esdV0->GetMTotV0C();
212 //TOF hit
213 Int_t ntracksMatchedToTOF = 0;
214 Int_t ntracks = fESD->GetNumberOfTracks();
215 for(Int_t itrk=0;itrk<ntracks;itrk++){
216 AliESDtrack* track = fESD->GetTrack(itrk);
217 if (!track) {
218 Printf("ERROR: Could not receive track %d", itrk);
219 continue;
220 }
221 //no track selection just TOF hit
222 if (track->IsOn(AliESDtrack::kTOFout)) ntracksMatchedToTOF++;
223 }
224
225 fTOFtracks = ntracksMatchedToTOF;
226 if(fESDpid){ //get T0_TOF
227 fESDpid->SetTOFResponse(fESD,AliESDpid::kTOF_T0);
228 fT0tofTrack =(Float_t) (fESDpid->GetTOFResponse().GetStartTime(10.0)); //Get start time "from all tracks
229 // printf("@@TOF T0 %f\n",fT0tofTrack);
230 }
c0fcf951 231 fpileup = fESD->IsPileupFromSPD();
232 fTimeV0C = esdV0->GetV0CTime();
233 fTimeV0A = esdV0->GetV0ATime();
36bbdbd3 234 //T0 info
c0fcf951 235 mean = fESD->GetT0TOF();
236 fVertex=fESD->GetT0zVertex();
237 fMeanA = mean[1];
238 fMeanC = mean[2];
239 if (TMath::Abs(fMeanA)<9999 && TMath::Abs(fMeanC)<9999)
36bbdbd3 240 fMeanAC = mean[0] ;
c0fcf951 241 fSumampC = tz->GetMultC();
242 fSumampA = tz->GetMultA();
c0fcf951 243 amp=fESD->GetT0amplitude();
244 time=fESD->GetT0time();
245 for (Int_t i=0; i<24; i++){
246 if( time[i]>100 && amp[i]>0.1){
247 famp[i] = amp[i];
248 ftime[i] = time[i];
249 }
250 }
251
36bbdbd3 252 //new raw OrA OrC TVDC all CFD
c0fcf951 253 for (Int_t ii=0; ii<5; ii++){
254 orA = tz->GetOrA(ii);
255 orC = tz->GetOrC(ii);
256 tvdc = tz->GetTVDC(ii);
257 // printf("@@@@@ new signasl %d %f %f %f \n",ii, orA, orC, tvdc);
258 if(ii==0) {
259 fOrA[ii] = orA;
260 fOrC[ii] = orC;
261 fTVDC[ii] = tvdc;
262 // cout<<tvdc<<" "<<fT0Trigger<<endl;
263 // if (tvdc>-5 && tvdc<5 && tvdc!=0)
264 // cout<<"@@@@@@@@@ "<< tvdc<<" "<<fT0Trigger<<endl;
265 } else {
266 if ( ii>0 && fOrA[ii-1] !=orA) fOrA[ii] = orA;
267 else fOrA[ii]=-9999;
268 if ( ii>0 && fOrC[ii-1] !=orC) fOrC[ii] = orC;
269 else fOrC[ii]=-9999;
270 if ( ii>0 && fTVDC[ii-1] != tvdc) fTVDC[ii] = tvdc;
271 else fTVDC[ii]=-9999;
272 }
c0fcf951 273 }
36bbdbd3 274 for (Int_t iii=0; iii<24; iii++)
275 fRawTime[iii] = tz->GetTimeFull(iii,0);
276
c0fcf951 277 fT0pileup[0] = tz->GetPileupFlag();
278 fT0pileup[1] = tz->GetBackgroundFlag();
279 fT0pileup[2] = tz->GetSatellite();
280
281 AliCentrality *centrality = fESD->GetCentrality();
c0fcf951 282 //The centrality function you can use
4c0e429d 283 if(centrality) {
284 fcentralityV0M = centrality->GetCentralityPercentile("V0M"); // returns the centrality
285 fcentralityTRK = centrality->GetCentralityPercentile("TRK"); // returns the centrality
286 fcentralityZDC = centrality->GetCentralityPercentile("ZEMvsZDC"); // returns the
36bbdbd3 287 }
c0fcf951 288
289 } //selected
290 } //ESD
291
292 fT0OutTree->Fill();
293
294 PostData(1, fOutputList);
295
296}
297
298//________________________________________________________________________
299void AliT0CalibAnalysisTask::Terminate(Option_t *)
300{
301 // Draw result to the screen
302 // Called once at the end of the query
303
304 /* fOutputList = dynamic_cast<TList*> (GetOutputData(1));
305 if (!fOutputList) {
306 printf("ERROR: Output list not available\n");
307 return;
308 }
309 */
310
311}