Task for analysis train on p-A data
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / GEO / AliAnalysisTaskZDCpA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /////////////////////////////////////////////////////////////
17 //                                                         //
18 //      Class to analyze ZDC data                          //
19 //                                                         //
20 /////////////////////////////////////////////////////////////
21
22 #include <TList.h>
23 #include <TH1F.h>
24 #include <TH2F.h>
25 #include <TFile.h>
26 #include <TString.h>
27 #include <TCanvas.h>
28
29 #include "AliAnalysisManager.h"
30 #include "AliInputEventHandler.h"
31 #include "AliVEvent.h"
32 #include "AliESD.h"
33 #include "AliESDEvent.h"
34 #include "AliESDHeader.h"
35 #include "AliESDInputHandler.h"
36 #include "AliESDZDC.h"
37 #include "AliMultiplicity.h"
38 #include "AliAODHandler.h"
39 #include "AliAODEvent.h"
40 #include "AliAODHeader.h"
41 #include "AliAODVertex.h"
42 #include "AliAODVZERO.h"
43 #include "AliAODZDC.h"
44 #include "AliAODMCHeader.h"
45 #include "AliMCEventHandler.h"
46 #include "AliMCEvent.h"
47 #include "AliHeader.h"
48 #include "AliAODMCParticle.h"
49 #include "AliAnalysisTaskSE.h"
50 #include "AliGenEventHeader.h"
51 #include "AliGenHijingEventHeader.h"
52 #include "AliPhysicsSelectionTask.h"
53 #include "AliPhysicsSelection.h"
54 #include "AliBackgroundSelection.h"
55 #include "AliTriggerAnalysis.h"
56 #include "AliCentrality.h"
57 #include "AliAnalysisTaskZDCpA.h"
58
59 ClassImp(AliAnalysisTaskZDCpA)
60
61
62 //________________________________________________________________________
63 AliAnalysisTaskZDCpA::AliAnalysisTaskZDCpA():
64   AliAnalysisTaskSE(),
65     fAnalysisInput(kESD),
66     fIsMCInput(kFALSE),
67     fCentrLowLim(0),
68     fCentrUpLim(0), 
69     fCentrEstimator(0),
70     fOutput(0x0),
71     fhZNCvsZNA(0x0),    
72     fhZPCvsZPA(0x0), 
73     fhZNCvsZPC(0x0),
74     fhZNAvsZPA(0x0),
75     fhZNAvsZEM(0x0),      
76     fhZNCvsZEM(0x0),      
77     fhZNAwV0M(0x0),      
78     fhZNCwV0M(0x0),      
79     fhZNAvsVZERO(0x0),    
80     fhZNCvsVZERO(0x0),    
81     fhZDCAvsTracklets(0x0),   
82     fhZDCCvsTracklets(0x0),   
83     fhVZEROvsZEM(0x0),   
84     fhDebunch(0x0),      
85     fhZNCcentroid(0x0),  
86     fhZNAcentroid(0x0),
87     fhZNCvscentrality(0x0),
88     fhZNAvscentrality(0x0),
89     fhZPCvscentrality(0x0),
90     fhZPAvscentrality(0x0),
91     fhZNCpmcvscentr(0x0),
92     fhZNApmcvscentr(0x0),
93     fhZPCpmcvscentr(0x0),
94     fhZPApmcvscentr(0x0)
95 {   
96    // Default constructor
97    for(int i=0; i<5; i++){
98      fhZNCPM[i] = 0x0;
99      fhZNAPM[i] = 0x0;    
100      fhZPCPM[i] = 0x0;      
101      fhZPAPM[i] = 0x0;      
102      fhZNCPMlg[i] = 0x0;    
103      fhZNAPMlg[i] = 0x0;    
104      fhZPCPMlg[i] = 0x0;    
105      fhZPAPMlg[i] = 0x0;    
106    }
107    for(int i=0; i<2; i++) fhZEM[i] = 0x0;  
108    for(int i=0; i<6; i++){
109      fhTDCraw[i] = 0x0;  
110      fhTDC[i] = 0x0;  
111    }
112    for(int i=0; i<4; i++){
113      fhZNCPMQiPMC[i] = 0x0;
114      fhZNAPMQiPMC[i] = 0x0;
115      fhZPCPMQiPMC[i] = 0x0;
116      fhZPAPMQiPMC[i] = 0x0;
117      fhPMCvsPMQ[i] = 0x0;
118    }  
119 }   
120
121 //________________________________________________________________________
122 AliAnalysisTaskZDCpA::AliAnalysisTaskZDCpA(const char *name):
123   AliAnalysisTaskSE(name),
124     fAnalysisInput(kESD),
125     fIsMCInput(kFALSE),
126     fCentrLowLim(0.),
127     fCentrUpLim(100.), 
128     fCentrEstimator("V0M"),
129     fOutput(0x0),
130     fhZNCvsZNA(0x0),    
131     fhZPCvsZPA(0x0), 
132     fhZNCvsZPC(0x0),
133     fhZNAvsZPA(0x0),
134     fhZNAvsZEM(0x0),      
135     fhZNCvsZEM(0x0),      
136     fhZNAwV0M(0x0),    
137     fhZNCwV0M(0x0),    
138     fhZNAvsVZERO(0x0),    
139     fhZNCvsVZERO(0x0),    
140     fhZDCAvsTracklets(0x0),   
141     fhZDCCvsTracklets(0x0),   
142     fhVZEROvsZEM(0x0),   
143     fhDebunch(0x0),      
144     fhZNCcentroid(0x0),  
145     fhZNAcentroid(0x0),
146     fhZNCvscentrality(0x0),
147     fhZNAvscentrality(0x0),
148     fhZPCvscentrality(0x0),
149     fhZPAvscentrality(0x0),
150     fhZNCpmcvscentr(0x0),
151     fhZNApmcvscentr(0x0),
152     fhZPCpmcvscentr(0x0),
153     fhZPApmcvscentr(0x0)
154 {
155
156    for(int i=0; i<5; i++){
157      fhZNCPM[i] = 0x0;
158      fhZNAPM[i] = 0x0;    
159      fhZPCPM[i] = 0x0;      
160      fhZPAPM[i] = 0x0;      
161      fhZNCPMlg[i] = 0x0;    
162      fhZNAPMlg[i] = 0x0;    
163      fhZPCPMlg[i] = 0x0;    
164      fhZPAPMlg[i] = 0x0;    
165    }
166    for(int i=0; i<2; i++) fhZEM[i] = 0x0;  
167    for(int i=0; i<6; i++){
168      fhTDCraw[i] = 0x0;  
169      fhTDC[i] = 0x0;  
170    }
171    for(int i=0; i<4; i++){
172      fhZNCPMQiPMC[i] = 0x0;
173      fhZNAPMQiPMC[i] = 0x0;
174      fhZPCPMQiPMC[i] = 0x0;
175      fhZPAPMQiPMC[i] = 0x0;
176      fhPMCvsPMQ[i] = 0x0;
177    }  
178   
179   // Output slot #1 writes into a TList container
180   DefineOutput(1, TList::Class()); 
181
182 }
183
184 //________________________________________________________________________
185 AliAnalysisTaskZDCpA& AliAnalysisTaskZDCpA::operator=(const AliAnalysisTaskZDCpA& c)
186 {
187   //
188   // Assignment operator
189   //
190   if (this!=&c) {
191     AliAnalysisTaskSE::operator=(c);
192   }
193   return *this;
194 }
195
196 //________________________________________________________________________
197 AliAnalysisTaskZDCpA::AliAnalysisTaskZDCpA(const AliAnalysisTaskZDCpA& ana):
198   AliAnalysisTaskSE(ana),
199     fAnalysisInput(ana.fAnalysisInput),
200     fIsMCInput(ana.fIsMCInput),
201     fCentrLowLim(ana.fCentrLowLim),
202     fCentrUpLim(ana.fCentrUpLim), 
203     fCentrEstimator(ana.fCentrEstimator),
204     fOutput(ana.fOutput),
205     fhZNCvsZNA(ana.fhZNCvsZNA),    
206     fhZPCvsZPA(ana.fhZPCvsZPA), 
207     fhZNCvsZPC(ana.fhZNCvsZPC),
208     fhZNAvsZPA(ana.fhZNAvsZPA),
209     fhZNAvsZEM(ana.fhZNAvsZEM),      
210     fhZNCvsZEM(ana.fhZNCvsZEM),      
211     fhZNAwV0M(ana.fhZNAwV0M),    
212     fhZNCwV0M(ana.fhZNCwV0M),    
213     fhZNAvsVZERO(ana.fhZNAvsVZERO),    
214     fhZNCvsVZERO(ana.fhZNCvsVZERO),    
215     fhZDCAvsTracklets(ana.fhZDCAvsTracklets), 
216     fhZDCCvsTracklets(ana.fhZDCCvsTracklets), 
217     fhVZEROvsZEM(ana.fhVZEROvsZEM),   
218     fhDebunch(ana.fhDebunch),      
219     fhZNCcentroid(ana.fhZNCcentroid),  
220     fhZNAcentroid(ana.fhZNAcentroid),
221     fhZNCvscentrality(ana.fhZNCvscentrality),
222     fhZNAvscentrality(ana.fhZNAvscentrality),
223     fhZPCvscentrality(ana.fhZPCvscentrality),
224     fhZPAvscentrality(ana.fhZPAvscentrality),
225     fhZNCpmcvscentr(ana.fhZNCpmcvscentr),
226     fhZNApmcvscentr(ana.fhZNApmcvscentr),
227     fhZPCpmcvscentr(ana.fhZPCpmcvscentr),
228     fhZPApmcvscentr(ana.fhZPApmcvscentr)
229 {
230   //
231   // Copy Constructor   
232   //
233   for(int i=0; i<5; i++){
234      fhZNCPM[i] = ana.fhZNCPM[i];
235      fhZNAPM[i] = ana.fhZNAPM[i];    
236      fhZPCPM[i] = ana.fhZPCPM[i];     
237      fhZPAPM[i] = ana.fhZPAPM[i];             
238      fhZNCPMlg[i] = ana.fhZNCPMlg[i];    
239      fhZNAPMlg[i] = ana.fhZNAPMlg[i];    
240      fhZPCPMlg[i] = ana.fhZPCPMlg[i];    
241      fhZPAPMlg[i] = ana.fhZPAPMlg[i];    
242    }
243    for(int i=0; i<2; i++) fhZEM[i] = ana.fhZEM[i];  
244    for(int i=0; i<6; i++){
245      fhTDCraw[i] = ana.fhTDCraw[i];  
246      fhTDC[i] = ana.fhTDC[i];  
247    }
248    for(int i=0; i<4; i++) fhPMCvsPMQ[i] = ana.fhPMCvsPMQ[i];  
249    for(int i=0; i<4; i++){
250      fhZNCPMQiPMC[i] = ana.fhZNCPMQiPMC[i];
251      fhZNAPMQiPMC[i] = ana.fhZNAPMQiPMC[i];
252      fhZPCPMQiPMC[i] = ana.fhZPCPMQiPMC[i];
253      fhZPAPMQiPMC[i] = ana.fhZPAPMQiPMC[i];
254      fhPMCvsPMQ[i] = ana.fhPMCvsPMQ[i];
255    }  
256 }
257  
258 //________________________________________________________________________
259 AliAnalysisTaskZDCpA::~AliAnalysisTaskZDCpA()
260 {
261   // Destructor
262   if(fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()){
263     delete fOutput; fOutput=0;
264   } 
265    
266 }  
267
268 //________________________________________________________________________
269 void AliAnalysisTaskZDCpA::UserCreateOutputObjects()
270 {
271   // Create the output containers
272   //printf("  AliAnalysisTaskZDCpA::UserCreateOutputObjects()\n\n");
273   fOutput = new TList;
274   fOutput->SetOwner();
275   //fOutput->SetName("output");
276   
277   for(int i=0; i<5; i++){
278      char hname[20];
279      sprintf(hname,"hZNCPM%d",i);
280      fhZNCPM[i] = new TH1F(hname, hname, 250, -50., 2450);
281      fOutput->Add(fhZNCPM[i]);
282      //
283      sprintf(hname,"hZNAPM%d",i);
284      fhZNAPM[i] = new TH1F(hname, hname, 250, -50., 2450);    
285      fOutput->Add(fhZNAPM[i]);
286      //
287      sprintf(hname,"hZPCPM%d",i);
288      fhZPCPM[i] = new TH1F(hname, hname, 250, -50., 2450);      
289      fOutput->Add(fhZPCPM[i]);
290      //
291      sprintf(hname,"hZPAPM%d",i);
292      fhZPAPM[i] = new TH1F(hname, hname, 250, -50., 2450);              
293      fOutput->Add(fhZPAPM[i]);
294      //
295      sprintf(hname,"hZNCPMlg%d",i);
296      fhZNCPMlg[i] = new TH1F(hname, hname, 200, -50., 950);      
297      fOutput->Add(fhZNCPMlg[i]);
298      //
299      sprintf(hname,"hZNAPMlg%d",i);
300      fhZNAPMlg[i] = new TH1F(hname, hname, 200, -50., 950);      
301      fOutput->Add(fhZNAPMlg[i]);
302      //
303      sprintf(hname,"hZPCPMlg%d",i);
304      fhZPCPMlg[i] = new TH1F(hname, hname, 200, -50., 950);      
305      fOutput->Add(fhZPCPMlg[i]);
306      //
307      sprintf(hname,"hZPAPMlg%d",i);
308      fhZPAPMlg[i] = new TH1F(hname, hname, 200, -50., 950);      
309      fOutput->Add(fhZPAPMlg[i]);
310      //
311      if(i<4){
312        //
313        char hnamenc[20];
314        sprintf(hnamenc, "hZNCPMQ%dPMC",i+1);
315        fhZNCPMQiPMC[i] = new TH1F(hnamenc, hnamenc, 100, 0., 1.);
316        fOutput->Add(fhZNCPMQiPMC[i]);
317        //
318        char hnamena[20];
319        sprintf(hnamena, "hZNAPMQ%dPMC",i+1);
320        fhZNAPMQiPMC[i] = new TH1F(hnamena, hnamena, 100, 0., 1.);
321        fOutput->Add(fhZNAPMQiPMC[i]);
322        //
323        char hnamepc[20];
324        sprintf(hnamepc, "hZPCPMQ%dPMC",i+1);
325        fhZPCPMQiPMC[i] = new TH1F(hnamepc, hnamepc, 100, 0., 1.);
326        fOutput->Add(fhZPCPMQiPMC[i]);
327        //
328        char hnamepa[20];
329        sprintf(hnamepa, "hZPAPMQ%dPMC",i+1);
330        fhZPAPMQiPMC[i] = new TH1F(hnamepa, hnamepa, 100, 0., 1.);
331        fOutput->Add(fhZPAPMQiPMC[i]);
332      }
333    }
334    for(int i=0; i<6; i++){
335      if(i==0){
336        fhZEM[i] = new TH1F("hZEM1","hZEM1",200,-10.,1990.);
337        fhTDCraw[i] = new TH1F("hTDCZEM1raw", "hTDCZEM1raw", 200, -200., 0.);
338        fhTDC[i] = new TH1F("hTDCZEM1", "hTDCZEM1", 200, -150., 50.);
339        fhPMCvsPMQ[i] = new TH2F("hPMCvsPMQZNC","hPMCvsPMQZNC",100,0.,2000,100,0.,2000);
340        //
341        fOutput->Add(fhZEM[i]);
342        fOutput->Add(fhPMCvsPMQ[i]);
343      }
344      else if(i==1){
345        fhZEM[i] = new TH1F("hZEM2","hZEM2",200,-10.,1990.);
346        fhTDCraw[i] = new TH1F("hTDCZEM2raw", "hTDCZEM2raw", 200, -200., 0.);
347        fhTDC[i] = new TH1F("hTDCZEM2", "hTDCZEM2", 200, -150., 50.);
348        fhPMCvsPMQ[i] = new TH2F("hPMCvsPMQZPC","hPMCvsPMQZPC",100,0.,2000,100,0.,2000);
349        //
350        fOutput->Add(fhZEM[i]);
351        fOutput->Add(fhPMCvsPMQ[i]);
352      }
353      else if(i==2){
354        fhTDCraw[i] = new TH1F("hTDCZNCraw", "hTDCZNCraw", 200, -200., 0.);
355        fhTDC[i] = new TH1F("hTDCZNC", "hTDCZNC", 200, -150., 50.);
356        fhPMCvsPMQ[i] = new TH2F("hPMCvsPMQZNA","hPMCvsPMQZNA",100,0.,2000,100,0.,2000);
357        //
358        fOutput->Add(fhPMCvsPMQ[i]);
359      }
360      else if(i==3){
361        fhTDCraw[i] = new TH1F("hTDCZPCraw", "hTDCZPCraw", 200, -200., 0.);
362        fhTDC[i] = new TH1F("hTDCZPC", "hTDCZPC", 200, -150., 50.);
363        fhPMCvsPMQ[i] = new TH2F("hPMCvsPMQZPA","hPMCvsPMQZPA",100,0.,2000,100,0.,2000);
364        //
365        fOutput->Add(fhPMCvsPMQ[i]);
366      }
367      else if(i==4){
368        fhTDCraw[i] = new TH1F("hTDCZNAraw", "hTDCZNAraw", 200, -200., 0.);
369        fhTDC[i] = new TH1F("hTDCZNA", "hTDCZNA", 200, -150., 50.);
370      }
371      else if(i==5){
372        fhTDCraw[i] = new TH1F("hTDCZPAraw", "hTDCZPAraw", 200, -200., 0.);
373        fhTDC[i] = new TH1F("hTDCZPA", "hTDCZPA", 200, -150., 50.);
374      }
375      //
376      fOutput->Add(fhTDC[i]);
377   }
378   
379   
380   fhZNCvsZNA = new TH2F("hZNCvsZNA","hZNCvsZNA",250,-50.,2450,200,-50.,2450);
381   fOutput->Add(fhZNCvsZNA);
382   fhZPCvsZPA = new TH2F("hZPCvsZPA","hZPCvsZPA",250,-50.,2450,200,-50.,2450);   
383   fOutput->Add(fhZPCvsZPA);
384   fhZNCvsZPC = new TH2F("hZNCvsZPC","hZNCvsZPC",250,-50.,2450,200,-50.,2450);
385   fOutput->Add(fhZNCvsZPC);
386   fhZNAvsZPA = new TH2F("hZNAvsZPA","hZNAvsZPA",250,-50.,2450,200,-50.,2450);   
387   fOutput->Add(fhZNAvsZPA);
388   fhZNAvsZEM = new TH2F("hZNAvsZEM","hZNAvsZEM",250,0.,2500.,250,0.,2500.);     
389   fOutput->Add(fhZNAvsZEM);
390   fhZNCvsZEM = new TH2F("hZNCvsZEM","hZNCvsZEM",250,0.,2500.,250,0.,2500.);     
391   fOutput->Add(fhZNCvsZEM);
392   fhZNAwV0M = new TH1F("hZNAwV0M","hZNA wV0M",250,0.,2500.);    
393   fOutput->Add(fhZNAwV0M);
394   fhZNCwV0M = new TH1F("hZNCwV0M","hZNC wV0M",250,0.,2500.);    
395   fOutput->Add(fhZNCwV0M);
396   fhZNAvsVZERO = new TH2F("hZNAvsVZERO","ZNA vs. VZERO",250,0.,25000.,250,0.,2500.);    
397   fOutput->Add(fhZNAvsVZERO);
398   fhZNCvsVZERO = new TH2F("hZNCvsVZERO","ZNC vs. VZERO",250,0.,25000.,250,0.,2500.);    
399   fOutput->Add(fhZNCvsVZERO);
400   fhZDCAvsTracklets = new TH2F("hZDCAvsTracklets","hZDCAvsTracklets",200,0.,4000.,250,0.,2500.);
401   fOutput->Add(fhZDCAvsTracklets);
402   fhZDCCvsTracklets = new TH2F("hZDCCvsTracklets","hZDCCvsTracklets",200,0.,4000.,250,0.,2500.);
403   fOutput->Add(fhZDCCvsTracklets);
404   fhVZEROvsZEM = new TH2F("hVZEROvsZEM","hVZEROvsZEM",250,0.,2500.,250,0.,25000.);      
405   fOutput->Add(fhVZEROvsZEM);
406   fhDebunch = new TH2F("hDebunch","hDebunch",240,-100.,-40.,240,-30.,30.);      
407   fOutput->Add(fhDebunch);
408   fhZNCcentroid = new TH2F("hZNCcentroid","hZNCcentroid",100,-3.5,3.5,100,-3.5,3.5);    
409   fOutput->Add(fhZNCcentroid);
410   fhZNAcentroid = new TH2F("hZNAcentroid","hZNAcentroid",100,-3.5,3.5,100,-3.5,3.5);    
411   fOutput->Add(fhZNAcentroid);
412   
413   fhZNCvscentrality = new TH2F("hZNCvscentrality","ZNC vs. centrality",100,0.,100.,100,0.,100.);
414   fOutput->Add(fhZNCvscentrality);
415   fhZNAvscentrality = new TH2F("hZNAvscentrality","ZNA vs. centrality",100,0.,100.,100,0.,100.);
416   fOutput->Add(fhZNAvscentrality);
417   fhZPCvscentrality = new TH2F("hZPCvscentrality","ZPC vs. centrality",100,0.,100.,100,0.,100.);
418   fOutput->Add(fhZPCvscentrality);
419   fhZPAvscentrality = new TH2F("hZPAvscentrality","ZPA vs. centrality",100,0.,100.,100,0.,100.);
420   fOutput->Add(fhZPAvscentrality);
421   
422   fhZNCpmcvscentr = new TH2F("hZNCpmcvscentr","ZNC PMC vs. centrality",100,0.,100.,100,0.,100.);
423   fOutput->Add(fhZNCpmcvscentr);
424   fhZNApmcvscentr = new TH2F("hZNApmcvscentr","ZNA PMC vs. centrality",100,0.,100.,100,0.,100.);
425   fOutput->Add(fhZNApmcvscentr);
426   fhZPCpmcvscentr = new TH2F("hZPCpmcvscentr","ZPC PMC vs. centrality",100,0.,100.,100,0.,100.);
427   fOutput->Add(fhZPCpmcvscentr);
428   fhZPApmcvscentr = new TH2F("hZPApmcvscentr","ZPA PMC vs. centrality",100,0.,100.,100,0.,100.);
429   fOutput->Add(fhZPApmcvscentr);
430  
431   PostData(1, fOutput);
432 }
433
434 //________________________________________________________________________
435 void AliAnalysisTaskZDCpA::UserExec(Option_t */*option*/)
436 {
437   // Execute analysis for current event:
438
439   if(!InputEvent()){
440     printf("ERROR: InputEvent not available");
441     return;
442   }
443   
444   if(fAnalysisInput==kESD){
445       
446       AliESDEvent* esd = dynamic_cast<AliESDEvent*> (InputEvent());
447       if(!esd) return;
448       
449       // Select PHYSICS events (type=7, for data)
450       if(!fIsMCInput && esd->GetEventType()!=7) return; 
451
452       // ********* MC INFO *********************************
453       /*if(fIsMCInput){
454         AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
455         if(!eventHandler){
456           printf("ERROR: Could not retrieve MC event handler");
457           return;
458         }
459    
460         AliMCEvent* mcEvent = eventHandler->MCEvent();
461         if(!mcEvent){
462           printf("ERROR: Could not retrieve MC event");
463           return;
464         }
465       }*/
466       // ****************************************************
467      
468      // PHYSICS SELECTION
469 //     AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
470 //     AliInputEventHandler *hdr = (AliInputEventHandler*)am->GetInputEventHandler();
471 //     printf("  PS selection %d\n",hdr->IsEventSelected());
472 //     if(hdr->IsEventSelected() & AliVEvent::kAnyINT){      
473       
474       AliCentrality *centrality = esd->GetCentrality();
475       Float_t centrperc = centrality->GetCentralityPercentile(fCentrEstimator.Data());
476       if(centrperc<fCentrLowLim || centrperc>fCentrUpLim) return;
477       
478       // ***** Trigger selection
479       /*TString triggerClass = esd->GetFiredTriggerClasses();
480       sprintf(fTrigClass,"%s",triggerClass.Data());*/
481           
482       const AliMultiplicity *mult = esd->GetMultiplicity();
483       Int_t nTracklets = mult->GetNumberOfTracklets();
484       //for(Int_t ilay=0; ilay<6; ilay++) fNClusters[ilay] = mult->GetNumberOfITSClusters(ilay);
485       //Int_t nClusterslay1 = mult->GetNumberOfITSClusters(1);
486       
487       AliESDVZERO *vzeroAOD = esd->GetVZEROData();
488       Float_t multV0A = vzeroAOD->GetMTotV0A();
489       Float_t multV0C = vzeroAOD->GetMTotV0C();
490
491       AliESDZDC *esdZDC = esd->GetESDZDC();
492       
493       Float_t tdc[32][4], tdcSum=-999, tdcDiff=-999;
494       Bool_t tdcMult[6] = {kFALSE};
495       for(Int_t itdc=0; itdc<32; itdc++){
496          for(Int_t i=0; i<4; i++){
497            if(esdZDC->GetZDCTDCData(itdc, i)!=0.){ 
498              tdc[itdc][i] = esdZDC->GetZDCTDCCorrected(itdc, i);
499              if(itdc>=8 && itdc<=13){
500                tdcMult[itdc-8] = kTRUE;
501                fhTDC[itdc-8]->Fill(tdc[itdc][i]);
502              }
503              else if(itdc==15 && i==0){
504                for(int ich=8; ich<=13; ich++) fhTDCraw[ich-8]->Fill(esdZDC->GetZDCTDCData(ich, 0)-esdZDC->GetZDCTDCData(itdc, i));
505              }
506            }
507          }
508       }
509       Bool_t zem1 = tdcMult[0];
510       Bool_t zem2 = tdcMult[1];
511       Bool_t znc  = tdcMult[2];
512       Bool_t zpc  = tdcMult[3];
513       Bool_t zna  = tdcMult[4];
514       Bool_t zpa  = tdcMult[5];
515       if(znc && zna){
516         tdcSum = esdZDC->GetZNTDCSum(0);
517         tdcDiff = esdZDC->GetZNTDCDiff(0);
518         fhDebunch->Fill(tdcDiff, tdcSum);          
519       }
520       
521       Float_t energyZNC  = (Float_t) (esdZDC->GetZNCEnergy());
522       Float_t energyZPC  = (Float_t) (esdZDC->GetZPCEnergy());
523       Float_t energyZNA  = (Float_t) (esdZDC->GetZNAEnergy());
524       Float_t energyZPA  = (Float_t) (esdZDC->GetZPAEnergy());
525       Float_t energyZEM1 = (Float_t) (esdZDC->GetZEM1Energy());
526       Float_t energyZEM2 = (Float_t) (esdZDC->GetZEM2Energy());
527       
528       const Double_t * towZNC = esdZDC->GetZNCTowerEnergy();
529       const Double_t * towZPC = esdZDC->GetZPCTowerEnergy();
530       const Double_t * towZNA = esdZDC->GetZNATowerEnergy();
531       const Double_t * towZPA = esdZDC->GetZPATowerEnergy();
532       //
533       const Double_t * towZNClg = esdZDC->GetZNCTowerEnergyLR();
534       const Double_t * towZPClg = esdZDC->GetZPCTowerEnergyLR();
535       const Double_t * towZNAlg = esdZDC->GetZNATowerEnergyLR();
536       const Double_t * towZPAlg = esdZDC->GetZPATowerEnergyLR();
537       
538       Double_t xyZNC[2]={-99.,-99.}, xyZNA[2]={-99.,-99.};
539       esdZDC->GetZNCentroidInPbPb(esd->GetBeamEnergy(), xyZNC, xyZNA);    
540       fhZNCcentroid->Fill(xyZNC[0], xyZNC[1]);
541       fhZNAcentroid->Fill(xyZNA[0], xyZNA[1]);
542       
543       /* //Only for MC
544       fbZDC = esdZDC->GetImpactParameter();
545       fNpartZDC = esdZDC->GetZDCParticipants();
546       fbZDCA = esdZDC->GetImpactParamSideA();
547       fNpartZDCA = esdZDC->GetZDCPartSideA();
548       fbZDCC = esdZDC->GetImpactParamSideC();
549       fNpartZDCC = esdZDC->GetZDCPartSideC();*/
550       
551       if(znc){
552         for(int i=0; i<5; i++){
553            fhZNCPM[i]->Fill(towZNC[i]);
554            fhZNCPMlg[i]->Fill(towZNClg[i]);
555            if((i<4) && (towZNC[0]>0.)) fhZNCPMQiPMC[i]->Fill(towZNC[i+1]/towZNC[0]);
556         }
557         fhPMCvsPMQ[0]->Fill(towZNC[1]+towZNC[2]+towZNC[3]+towZNC[4], towZNC[0]);
558       }
559       if(zpc){
560         for(int i=0; i<5; i++){
561            fhZPCPM[i]->Fill(towZPC[i]);
562            fhZPCPMlg[i]->Fill(towZPClg[i]);
563            if(((i<4) && towZPC[0]>0.)) fhZPCPMQiPMC[i]->Fill(towZPC[i+1]/towZPC[0]);
564         }
565         fhPMCvsPMQ[1]->Fill(towZPC[1]+towZPC[2]+towZPC[3]+towZPC[4], towZPC[0]);
566       }
567       if(zna){
568         for(int i=0; i<5; i++){
569            fhZNAPM[i]->Fill(towZNA[i]);
570            fhZNAPMlg[i]->Fill(towZNAlg[i]);
571            if(((i<4) && towZNA[0]>0.)) fhZNAPMQiPMC[i]->Fill(towZNA[i+1]/towZNA[0]);
572         }
573         fhPMCvsPMQ[2]->Fill(towZNA[1]+towZNA[2]+towZNA[3]+towZNA[4], towZNA[0]);
574       }
575       if(zpa){
576         for(int i=0; i<5; i++){
577            fhZPAPM[i]->Fill(towZPA[i]);
578            fhZPAPMlg[i]->Fill(towZPAlg[i]);
579            if(((i<4) && towZPA[0]>0.)) fhZPAPMQiPMC[i]->Fill(towZPA[i+1]/towZPA[0]);
580         }
581         fhPMCvsPMQ[3]->Fill(towZPA[1]+towZPA[2]+towZPA[3]+towZPA[4], towZPA[0]);
582       }
583       if(zem1) fhZEM[0]->Fill(energyZEM1);
584       if(zem2) fhZEM[1]->Fill(energyZEM2);
585       
586       if(znc || zna){
587         fhZNCvsZNA->Fill(energyZNA, energyZNC);
588         fhZPCvsZPA->Fill(energyZPA, energyZPC);
589         fhZNCvsZPC->Fill(energyZPC, energyZNC);
590         fhZNAvsZPA->Fill(energyZPA, energyZNA);
591         fhZNAvsZEM->Fill(energyZEM1+energyZEM2, energyZNA);     
592         fhZNCvsZEM->Fill(energyZEM1+energyZEM2, energyZNC);     
593         fhZNAwV0M->Fill(energyZNA, centrperc);   
594         fhZNCwV0M->Fill(energyZNC, centrperc);   
595         fhZNAvsVZERO->Fill(multV0A+multV0C, energyZNA); 
596         fhZNCvsVZERO->Fill(multV0A+multV0C, energyZNC); 
597         fhZDCAvsTracklets->Fill((Float_t) (nTracklets), energyZNA+energyZPA);
598         fhZDCCvsTracklets->Fill((Float_t) (nTracklets), energyZNC+energyZPC);
599         fhVZEROvsZEM->Fill(energyZEM1+energyZEM2, multV0A+multV0C);     
600                 
601         fhZNCvscentrality->Fill(centrperc, energyZNC);
602         fhZNAvscentrality->Fill(centrperc, energyZNA);
603         fhZPCvscentrality->Fill(centrperc, energyZPC);
604         fhZPAvscentrality->Fill(centrperc, energyZPA);
605         
606         fhZNCpmcvscentr->Fill(centrperc, towZNC[0]);
607         fhZNApmcvscentr->Fill(centrperc, towZNA[0]);
608         fhZPCpmcvscentr->Fill(centrperc, towZPC[0]);
609         fhZPApmcvscentr->Fill(centrperc, towZPA[0]);
610         
611       }
612 //    } // PHYSICS SELECTION
613       
614   }   
615   else if(fAnalysisInput==kAOD){
616       
617     AliAODEvent *aod =  dynamic_cast<AliAODEvent*> (InputEvent());
618     if(!aod){
619        printf("AODs not available");
620        return;
621     }
622     
623     // Select PHYSICS events (type=7, for data)
624     //if(!fIsMCInput && aod->GetEventType()!=7) return; 
625     
626     // PHYSICS SELECTION
627     AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
628     AliInputEventHandler *hdr = (AliInputEventHandler*)am->GetInputEventHandler();
629     if(hdr->IsEventSelected() & AliVEvent::kAnyINT){      
630            
631       AliCentrality* centrality = aod->GetCentrality();
632       Float_t centrperc = centrality->GetCentralityPercentile(fCentrEstimator.Data());
633       
634       /*AliAODHeader *aodheader =  aod->GetHeader();
635       AliCentrality *centralityp = aodheader->GetCentralityP();
636       Float_t centrperc = centralityp->GetCentralityPercentile(fCentrEstimator.Data());
637       */
638
639       if(centrperc<fCentrLowLim || centrperc>fCentrUpLim)  return;
640      
641       // ***** Trigger selection
642       /*TString triggerClass = aod->GetFiredTriggerClasses();
643       sprintf(fTrigClass,"%s",triggerClass.Data());
644       
645       const AliAODVertex *vertex = aod->GetPrimaryVertexSPD();
646       fxVertex = vertex->GetX();
647       fyVertex = vertex->GetY();
648       fzVertex = vertex->GetZ();*/
649       
650       AliAODTracklets *trackl = aod->GetTracklets();
651       Int_t nTracklets = trackl->GetNumberOfTracklets();
652           
653       AliAODVZERO *vzeroAOD = aod->GetVZEROData();
654       Float_t multV0A = vzeroAOD->GetMTotV0A();
655       Float_t multV0C = vzeroAOD->GetMTotV0C();
656         
657       AliAODZDC *aodZDC = aod->GetZDCData();
658             
659       Float_t energyZNC  = (Float_t) (aodZDC->GetZNCEnergy());
660       Float_t energyZPC  = (Float_t) (aodZDC->GetZPCEnergy());
661       Float_t energyZNA  = (Float_t) (aodZDC->GetZNAEnergy());
662       Float_t energyZPA  = (Float_t) (aodZDC->GetZPAEnergy());
663       Float_t energyZEM1 = (Float_t) (aodZDC->GetZEM1Energy());
664       Float_t energyZEM2 = (Float_t) (aodZDC->GetZEM2Energy());
665       
666       const Double_t * towZNC = aodZDC->GetZNCTowerEnergy();
667       const Double_t * towZPC = aodZDC->GetZPCTowerEnergy();
668       const Double_t * towZNA = aodZDC->GetZNATowerEnergy();
669       const Double_t * towZPA = aodZDC->GetZPATowerEnergy();
670       //
671       const Double_t * towZNClg = aodZDC->GetZNCTowerEnergyLR();
672       const Double_t * towZNAlg = aodZDC->GetZNATowerEnergyLR();
673       //
674       Double_t towZPClg[5], towZPAlg[5]={0.};
675       for(Int_t it=0; it<5; it++){
676          towZPClg[it] = 8*towZPC[it];
677          towZPAlg[it] = 8*towZNA[it];  
678       }
679
680       Double_t xyZNC[2]={-99.,-99.}, xyZNA[2]={-99.,-99.};
681       aodZDC->GetZNCentroidInPbPb(1380., xyZNC, xyZNA);
682       fhZNCcentroid->Fill(xyZNC[0], xyZNC[1]);
683       fhZNAcentroid->Fill(xyZNA[0], xyZNA[1]);
684     
685       Float_t tdcSum = aodZDC->GetZDCTimeSum();
686       Float_t tdcDiff = aodZDC->GetZDCTimeDiff();
687       fhDebunch->Fill(tdcDiff, tdcSum);
688       
689       for(int i=0; i<5; i++){
690          fhZNCPM[i]->Fill(towZNC[i]);
691          fhZNCPMlg[i]->Fill(towZNClg[i]);
692          if((i<4) && (towZNC[0]>0.)) fhZNCPMQiPMC[i]->Fill(towZNC[i+1]/towZNC[0]);
693       }
694       fhPMCvsPMQ[0]->Fill(towZNC[1]+towZNC[2]+towZNC[3]+towZNC[4], towZNC[0]);
695       for(int i=0; i<5; i++){
696          fhZPCPM[i]->Fill(towZPC[i]);
697          fhZPCPMlg[i]->Fill(towZPClg[i]);
698          if(((i<4) && towZPC[0]>0.)) fhZPCPMQiPMC[i]->Fill(towZPC[i+1]/towZPC[0]);
699       }
700       fhPMCvsPMQ[1]->Fill(towZPC[1]+towZPC[2]+towZPC[3]+towZPC[4], towZPC[0]);
701       for(int i=0; i<5; i++){
702          fhZNAPM[i]->Fill(towZNA[i]);
703          fhZNAPMlg[i]->Fill(towZNAlg[i]);
704          if(((i<4) && towZNA[0]>0.)) fhZNAPMQiPMC[i]->Fill(towZNA[i+1]/towZNA[0]);
705       }
706       fhPMCvsPMQ[2]->Fill(towZNA[1]+towZNA[2]+towZNA[3]+towZNA[4], towZNA[0]);
707       for(int i=0; i<5; i++){
708          fhZPAPM[i]->Fill(towZPA[i]);
709          fhZPAPMlg[i]->Fill(towZPAlg[i]);
710          if(((i<4) && towZPA[0]>0.)) fhZPAPMQiPMC[i]->Fill(towZPA[i+1]/towZPA[0]);
711       }
712       fhPMCvsPMQ[3]->Fill(towZPA[1]+towZPA[2]+towZPA[3]+towZPA[4], towZPA[0]);
713       fhZEM[0]->Fill(energyZEM1);
714       fhZEM[1]->Fill(energyZEM2);
715       
716       fhZNCvsZNA->Fill(energyZNA, energyZNC);
717       fhZPCvsZPA->Fill(energyZPA, energyZPC);
718       fhZNCvsZPC->Fill(energyZPC, energyZNC);
719       fhZNAvsZPA->Fill(energyZPA, energyZNA);
720       fhZNAvsZEM->Fill(energyZEM1+energyZEM2, energyZNA);    
721       fhZNCvsZEM->Fill(energyZEM1+energyZEM2, energyZNC);    
722       fhZNAwV0M->Fill(energyZNA, centrperc);         
723       fhZNCwV0M->Fill(energyZNC, centrperc);    
724       fhZNAvsVZERO->Fill(multV0A+multV0C, energyZNA);        
725       fhZNCvsVZERO->Fill(multV0A+multV0C, energyZNC);        
726       fhZDCAvsTracklets->Fill((Float_t) (nTracklets), energyZNA+energyZPA);
727       fhZDCCvsTracklets->Fill((Float_t) (nTracklets), energyZNC+energyZPC);
728       fhVZEROvsZEM->Fill(energyZEM1+energyZEM2, multV0A+multV0C);     
729       
730       fhZNCvscentrality->Fill(centrperc, energyZNC);
731       fhZNAvscentrality->Fill(centrperc, energyZNA);
732       fhZPCvscentrality->Fill(centrperc, energyZPC);
733       fhZPAvscentrality->Fill(centrperc, energyZPA);
734         
735       fhZNCpmcvscentr->Fill(centrperc, towZNC[0]);
736       fhZNApmcvscentr->Fill(centrperc, towZNA[0]);
737       fhZPCpmcvscentr->Fill(centrperc, towZPC[0]);
738       fhZPApmcvscentr->Fill(centrperc, towZPA[0]);
739
740     } // PHYSICS SELECTION
741   }
742   
743   PostData(1, fOutput);
744    
745 }
746
747
748
749 //________________________________________________________________________
750 void AliAnalysisTaskZDCpA::Terminate(Option_t */*option*/)
751 {
752   // Terminate analysis
753   //
754 /*  if(fDebug > 1) printf(" **** AliAnalysisTaskZDCpA::Terminate() \n");
755   
756   //fOutput = dynamic_cast<TList*> (GetOutputData(1));
757   //if(!fOutput) printf("ERROR: fOutput not available\n");
758 */
759 }