91ecef8010aff4ccba525df9d3203f9e4a83727e
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / GEO / AliAnalysisTaskZDCpAcalib.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 <TTree.h>
23 #include <TList.h>
24 #include <TFile.h>
25 #include <TString.h>
26 #include <TCanvas.h>
27
28 #include "AliAnalysisManager.h"
29 #include "AliInputEventHandler.h"
30 #include "AliVEvent.h"
31 #include "AliESD.h"
32 #include "AliESDEvent.h"
33 #include "AliESDHeader.h"
34 #include "AliESDInputHandler.h"
35 #include "AliESDZDC.h"
36 #include "AliMultiplicity.h"
37 #include "AliAODHandler.h"
38 #include "AliAODEvent.h"
39 #include "AliAODHeader.h"
40 #include "AliAODVertex.h"
41 #include "AliAODVZERO.h"
42 #include "AliAODZDC.h"
43 #include "AliAODMCHeader.h"
44 #include "AliMCEventHandler.h"
45 #include "AliMCEvent.h"
46 #include "AliHeader.h"
47 #include "AliAODMCParticle.h"
48 #include "AliAnalysisTaskSE.h"
49 #include "AliGenEventHeader.h"
50 #include "AliGenHijingEventHeader.h"
51 #include "AliPhysicsSelectionTask.h"
52 #include "AliPhysicsSelection.h"
53 #include "AliTriggerAnalysis.h"
54 #include "AliCentrality.h"
55 #include "AliAnalysisTaskZDCpAcalib.h"
56
57 ClassImp(AliAnalysisTaskZDCpAcalib)
58
59
60 //________________________________________________________________________
61 AliAnalysisTaskZDCpAcalib::AliAnalysisTaskZDCpAcalib():
62   AliAnalysisTaskSE(),
63     fDebug(0),
64     fAnalysisInput("ESD"),
65     fIsMCInput(kFALSE),
66     fUseSpecialOutput(kFALSE),
67     fOutput(0x0),
68     fCentralityTree(0x0),
69     fIsEventSelected(kFALSE),
70     fIsV0ATriggered(0),
71     fIsV0CTriggered(0)
72 {   
73    // Default constructor
74
75   for(Int_t itow=0; itow<5; itow++){
76      fZNCtower[itow]=0.;  
77      fZNAtower[itow]=0.;  
78      fZNCtowerLG[itow]=0.;
79      fZNAtowerLG[itow]=0.;
80      fZPCtower[itow]=0.;  
81      fZPAtower[itow]=0.;  
82      fZPCtowerLG[itow]=0.;
83      fZPAtowerLG[itow]=0.;
84
85   }
86   
87   for(Int_t ihit=0; ihit<4; ihit++){
88     fZNCtdc[ihit]=9999;
89     fZNAtdc[ihit]=9999;
90     fZPCtdc[ihit]=9999;
91     fZPAtdc[ihit]=9999;
92   }
93 }   
94
95 //________________________________________________________________________
96 AliAnalysisTaskZDCpAcalib::AliAnalysisTaskZDCpAcalib(const char *name):
97   AliAnalysisTaskSE(name),
98     fDebug(0),
99     fAnalysisInput("ESD"),
100     fIsMCInput(kFALSE),
101     fUseSpecialOutput(kFALSE),
102     fOutput(0x0),
103     fCentralityTree(0x0),
104     fIsEventSelected(kFALSE),
105     fIsV0ATriggered(0),
106     fIsV0CTriggered(0)
107 {
108   // Default constructor
109  
110   for(Int_t itow=0; itow<5; itow++){
111      fZNCtower[itow]=0.;  
112      fZNAtower[itow]=0.;  
113      fZNCtowerLG[itow]=0.;
114      fZNAtowerLG[itow]=0.;
115      fZPCtower[itow]=0.;  
116      fZPAtower[itow]=0.;  
117      fZPCtowerLG[itow]=0.;
118      fZPAtowerLG[itow]=0.;
119
120   }
121   
122   for(Int_t ihit=0; ihit<4; ihit++){
123      fZNCtdc[ihit]=9999;
124      fZNAtdc[ihit]=9999;
125      fZPCtdc[ihit]=9999;
126      fZPAtdc[ihit]=9999;
127   }
128   
129   // Output slot #1 writes into a TList container
130   DefineOutput(1, TList::Class()); 
131   
132 }
133  
134 //________________________________________________________________________
135 AliAnalysisTaskZDCpAcalib::~AliAnalysisTaskZDCpAcalib()
136 {
137   // Destructor
138   if(fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()){
139     delete fOutput; fOutput=0;
140   } 
141   if(fCentralityTree && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()){
142     delete fCentralityTree; fCentralityTree=0;
143   } 
144   
145 }  
146
147 //________________________________________________________________________
148 void AliAnalysisTaskZDCpAcalib::UserCreateOutputObjects()
149 {
150   // Create the output containers
151   if(fDebug>1) printf("AnalysisTaskZDCpAcalib::UserCreateOutputObjects() \n");
152
153   if (fUseSpecialOutput) OpenFile(1);
154
155   // Several histograms are more conveniently managed in a TList
156   fOutput = new TList;
157   fOutput->SetOwner();
158   //fOutput->SetName("output");
159
160     fCentralityTree = new TTree("fCentralityTree", "Centrality vs. multiplicity tree");
161     //
162     fCentralityTree->Branch("trigClass",&fTrigClass,"trigClass/C");
163     fCentralityTree->Branch("eventSelected",&fIsEventSelected,"eventSelected/O");
164     fCentralityTree->Branch("isV0ATriggered", &fIsV0ATriggered,"isV0ATriggered/I");
165     fCentralityTree->Branch("isV0CTriggered", &fIsV0CTriggered,"isV0CTriggered/I");
166     fCentralityTree->Branch("znctower", fZNCtower, "znctower[5]/F");
167     fCentralityTree->Branch("znatower", fZNAtower, "znatower[5]/F");
168     fCentralityTree->Branch("znctowerLG", fZNCtowerLG, "znctowerLG[5]/F");
169     fCentralityTree->Branch("znatowerLG", fZNAtowerLG, "znatowerLG[5]/F");
170     fCentralityTree->Branch("zpctower", fZNCtower, "znctower[5]/F");
171     fCentralityTree->Branch("zpatower", fZNAtower, "znatower[5]/F");
172     fCentralityTree->Branch("zpctowerLG", fZNCtowerLG, "znctowerLG[5]/F");
173     fCentralityTree->Branch("zpatowerLG", fZNAtowerLG, "znatowerLG[5]/F");
174     fCentralityTree->Branch("tdcZNC", fZNCtdc, "tdcZNC[4]/I");
175     fCentralityTree->Branch("tdcZNA", fZNAtdc, "tdcZNA[4]/I");
176     fCentralityTree->Branch("tdcZPC", fZPCtdc, "tdcZPC[4]/I");
177     fCentralityTree->Branch("tdcZPA", fZPAtdc, "tdcZPA[4]/I");
178       
179     fOutput->Add(fCentralityTree);      
180     PostData(1, fOutput);
181   
182 }
183
184 //________________________________________________________________________
185 void AliAnalysisTaskZDCpAcalib::UserExec(Option_t */*option*/)
186 {
187   // Execute analysis for current event:
188   if(fDebug>1) printf(" **** AliAnalysisTaskZDCpAcalib::UserExec() \n");
189   
190   if (!InputEvent()) {
191     Printf("ERROR: InputEvent not available");
192     return;
193   }
194
195   if(fAnalysisInput.CompareTo("ESD")==0){
196       
197       //printf(" \t ***Analizing ESD ev. %d\n",fNev);
198       
199       AliESDEvent* esd = dynamic_cast<AliESDEvent*> (InputEvent());
200       if(!esd) return;
201       
202       // Select PHYSICS events (type=7, for data)
203       if(!fIsMCInput && esd->GetEventType()!=7) return; 
204       
205       // ***** Trigger selection
206       TString triggerClass = esd->GetFiredTriggerClasses();
207       sprintf(fTrigClass,"%s",triggerClass.Data());
208       
209       // use response of AliPhysicsSelection
210       fIsEventSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kCINT5);       
211
212           
213       AliESDVZERO *vzeroAOD = esd->GetVZEROData();
214       fIsV0ATriggered = vzeroAOD->GetV0ADecision();
215       fIsV0CTriggered = vzeroAOD->GetV0CDecision();
216         
217       AliESDZDC *esdZDC = esd->GetESDZDC();
218        
219       const Double_t * towZNC = esdZDC->GetZN1TowerEnergy();
220       const Double_t * towZNA = esdZDC->GetZN2TowerEnergy();
221       const Double_t * towZPC = esdZDC->GetZP1TowerEnergy();
222       const Double_t * towZPA = esdZDC->GetZP2TowerEnergy();
223       //
224       const Double_t * towZNCLG = esdZDC->GetZN1TowerEnergyLR();
225       const Double_t * towZNALG = esdZDC->GetZN2TowerEnergyLR();
226       const Double_t * towZPCLG = esdZDC->GetZP1TowerEnergyLR();
227       const Double_t * towZPALG = esdZDC->GetZP2TowerEnergyLR();
228       //
229       for(Int_t it=0; it<5; it++){
230          fZNCtower[it] = (Float_t) (towZNC[it]);
231          fZNAtower[it] = (Float_t) (towZNA[it]); 
232          fZNCtowerLG[it] = (Float_t) (towZNCLG[it]);
233          fZNAtowerLG[it] = (Float_t) (towZNALG[it]); 
234          fZPCtower[it] = (Float_t) (towZPC[it]);
235          fZPAtower[it] = (Float_t) (towZPA[it]); 
236          fZPCtowerLG[it] = (Float_t) (towZPCLG[it]);
237          fZPAtowerLG[it] = (Float_t) (towZPALG[it]); 
238       }
239
240       for(Int_t i=0; i<4; i++){
241            fZNCtdc[i] = esdZDC->GetZDCTDCData(10, i);
242            fZPCtdc[i] = esdZDC->GetZDCTDCData(11, i);
243            fZNAtdc[i] = esdZDC->GetZDCTDCData(12, i);
244            fZPAtdc[i] = esdZDC->GetZDCTDCData(13, i);
245       }      
246   }   
247   
248   
249   fCentralityTree->Fill();
250  
251   PostData(1, fOutput);
252   
253    
254 }
255
256
257
258 //________________________________________________________________________
259 void AliAnalysisTaskZDCpAcalib::Terminate(Option_t */*option*/)
260 {
261   // Terminate analysis
262   //
263   printf(" **** AliAnalysisTaskZDCpAcalib::Terminate() \n");
264 }