]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliAnalysisTaskZDC.cxx
Correcting fot BEAM2 phase and using L0 for timing
[u/mrichter/AliRoot.git] / ZDC / AliAnalysisTaskZDC.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 <TH2F.h>
24 #include <TH1F.h>
25 #include <TFile.h>
26 #include <TString.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 "AliAODVertex.h"
40 #include "AliAODMCHeader.h"
41 #include "AliMCEventHandler.h"
42 #include "AliMCEvent.h"
43 #include "AliHeader.h"
44 #include "AliAODMCParticle.h"
45 #include "AliAnalysisTaskSE.h"
46 #include "AliGenEventHeader.h"
47 #include "AliGenHijingEventHeader.h"
48 #include "AliPhysicsSelectionTask.h"
49 #include "AliPhysicsSelection.h"
50 #include "AliBackgroundSelection.h"
51 #include "AliTriggerAnalysis.h"
52 #include "AliCentrality.h"
53 #include "AliAnalysisTaskZDC.h"
54
55 ClassImp(AliAnalysisTaskZDC)
56
57
58 //________________________________________________________________________
59 AliAnalysisTaskZDC::AliAnalysisTaskZDC():
60   AliAnalysisTaskSE(),
61     fDebug(0),
62     fIsMCInput(kFALSE),
63     fOutput(0x0),
64     fhZNCSpectrum(0x0),
65     fhZNASpectrum(0x0),
66     fhZPCSpectrum(0x0),
67     fhZPASpectrum(0x0),
68     fhZEM1Spectrum(0x0),
69     fhZEM2Spectrum(0x0),
70     fhZNCpmc(0x0),       
71     fhZNApmc(0x0),       
72     fhZPCpmc(0x0),       
73     fhZPApmc(0x0),       
74     fhZNCCentroid(0x0), 
75     fhZNACentroid(0x0), 
76     fhZNCemd(0x0),         
77     fhZNAemd(0x0),
78     fhPMCZNCemd(0x0), 
79     fhPMCZNAemd(0x0) 
80 {   
81    // Default constructor
82 }   
83
84 //________________________________________________________________________
85 AliAnalysisTaskZDC::AliAnalysisTaskZDC(const char *name):
86   AliAnalysisTaskSE(name),
87     fDebug(0),
88     fIsMCInput(kFALSE),
89     fOutput(0x0),
90     fhZNCSpectrum(0x0),
91     fhZNASpectrum(0x0),
92     fhZPCSpectrum(0x0),
93     fhZPASpectrum(0x0),
94     fhZEM1Spectrum(0x0),
95     fhZEM2Spectrum(0x0),
96     fhZNCpmc(0x0),       
97     fhZNApmc(0x0),       
98     fhZPCpmc(0x0),       
99     fhZPApmc(0x0),       
100     fhZNCCentroid(0x0), 
101     fhZNACentroid(0x0), 
102     fhZNCemd(0x0),         
103     fhZNAemd(0x0),
104     fhPMCZNCemd(0x0), 
105     fhPMCZNAemd(0x0) 
106 {  
107   // Output slot #1 writes into a TList container
108   DefineOutput(1, TList::Class()); 
109
110 }
111
112 //________________________________________________________________________
113 AliAnalysisTaskZDC& AliAnalysisTaskZDC::operator=(const AliAnalysisTaskZDC& c)
114 {
115   //
116   // Assignment operator
117   //
118   if (this!=&c) {
119     AliAnalysisTaskSE::operator=(c);
120   }
121   return *this;
122 }
123
124 //________________________________________________________________________
125 AliAnalysisTaskZDC::AliAnalysisTaskZDC(const AliAnalysisTaskZDC& ana):
126   AliAnalysisTaskSE(ana),
127   fDebug(ana.fDebug),     
128   fIsMCInput(ana.fIsMCInput),
129   fOutput(ana.fOutput),
130   fhZNCSpectrum(ana.fhZNCSpectrum),
131   fhZNASpectrum(ana.fhZNASpectrum),
132   fhZPCSpectrum(ana.fhZPCSpectrum),
133   fhZPASpectrum(ana.fhZPASpectrum),
134   fhZEM1Spectrum(ana.fhZEM1Spectrum),
135   fhZEM2Spectrum(ana.fhZEM2Spectrum),
136   fhZNCpmc(ana.fhZNCpmc),       
137   fhZNApmc(ana.fhZNApmc),       
138   fhZPCpmc(ana.fhZPCpmc),       
139   fhZPApmc(ana.fhZPApmc),       
140   fhZNCCentroid(ana.fhZNCCentroid), 
141   fhZNACentroid(ana.fhZNACentroid), 
142   fhZNCemd(ana.fhZNCemd),        
143   fhZNAemd(ana.fhZNAemd),
144   fhPMCZNCemd(ana.fhPMCZNCemd), 
145   fhPMCZNAemd(ana.fhPMCZNAemd)
146 {
147   //
148   // Copy Constructor   
149   //
150 }
151  
152 //________________________________________________________________________
153 AliAnalysisTaskZDC::~AliAnalysisTaskZDC()
154 {
155   // Destructor
156   if(fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()){
157     delete fOutput; fOutput=0;
158   } 
159    
160 }  
161
162 //________________________________________________________________________
163 void AliAnalysisTaskZDC::UserCreateOutputObjects()
164 {
165   // Create the output containers
166
167   fOutput = new TList;
168   fOutput->SetOwner();
169   //fOutput->SetName("output");
170   
171   fhTDCZNSum = new TH1F("fhTDCZNSum","TDC_{ZNC}+TDC_{ZNA}",60,-600.,-540.);
172   fhTDCZNSum->GetXaxis()->SetTitle("TDC_{ZNC}+TDC_{ZNA} (ns)");
173   fOutput->Add(fhTDCZNSum);      
174   
175   fhTDCZNDiff = new TH1F("fhTDCZNDiff","TDC_{ZNC}-TDC_{ZNA}",60,-30.,30.);
176   fhTDCZNDiff->GetXaxis()->SetTitle("TDC_{ZNC}-TDC_{ZNA} (ns)");
177   fOutput->Add(fhTDCZNDiff);      
178   
179   fhZNCSpectrum = new TH1F("fhZNCSpectrum", "ZNC signal", 100,0., 3000.);
180   fOutput->Add(fhZNCSpectrum);      
181   fhZNASpectrum = new TH1F("fhZNASpectrum", "ZNA signal", 100,0., 3000.) ;
182   fOutput->Add(fhZNASpectrum);      
183   fhZPCSpectrum = new TH1F("fhZPCSpectrum", "ZPC signal", 100,0., 3000.) ;
184   fOutput->Add(fhZPCSpectrum);      
185   fhZPASpectrum = new TH1F("fhZPASpectrum", "ZPA signal", 100,0., 3000.) ;
186   fOutput->Add(fhZPASpectrum);      
187   fhZEM1Spectrum = new TH1F("fhZEM1Spectrum", "ZEM1 signal", 100,0., 2500.);
188   fOutput->Add(fhZEM1Spectrum);      
189   fhZEM2Spectrum = new TH1F("fhZEM2Spectrum", "ZEM2 signal", 100,0., 2500.);
190   fOutput->Add(fhZEM2Spectrum);      
191   
192   fhZNCpmc = new TH1F("fhZNCpmc","ZNC PMC",100, 0., 1200.);
193   fOutput->Add(fhZNCpmc);      
194   fhZNApmc = new TH1F("fhZNApmc","ZNA PMC",100, 0., 1200.); 
195   fOutput->Add(fhZNApmc);      
196   fhZPCpmc = new TH1F("fhZPCpmc","ZPC PMC",100, 0., 1200.); 
197   fOutput->Add(fhZPCpmc);      
198   fhZPApmc = new TH1F("fhZPApmc","ZPA PMC",100, 0., 1200.); 
199   fOutput->Add(fhZPApmc);      
200   
201   fhZNCCentroid = new TH2F("fhZNCCentroid","Centroid over ZNC",70,-3.5,3.5,70,-3.5,3.5); 
202   fOutput->Add(fhZNCCentroid);      
203   fhZNACentroid = new TH2F("fhZNACentroid","Centroid over ZNA",70,-3.5,3.5,70,-3.5,3.5); 
204   fOutput->Add(fhZNACentroid);      
205   
206   fhZNCemd = new TH1F("fhZNCemd","ZNC signal lg",100,0.,1000.);  
207   fOutput->Add(fhZNCemd);      
208   fhZNAemd = new TH1F("fhZNAemd","ZNA signal lg",100,0.,1000.);  
209   fOutput->Add(fhZNAemd);      
210   fhPMCZNCemd = new TH1F("fhPMCZNCemd","ZNC PMC lg",100, 10., 500.);   
211   fOutput->Add(fhPMCZNCemd);      
212   fhPMCZNAemd = new TH1F("fhPMCZNAemd","ZNA PMC lg",100, 10., 500.);   
213   fOutput->Add(fhPMCZNAemd);      
214     
215   PostData(1, fOutput);
216 }
217
218 //________________________________________________________________________
219 void AliAnalysisTaskZDC::UserExec(Option_t */*option*/)
220 {
221   // Execute analysis for current event:
222   if(fDebug>1) printf(" **** AliAnalysisTaskZDC::UserExec() \n");
223   
224   if (!InputEvent()) {
225     Printf("ERROR: InputEvent not available");
226     return;
227   }
228
229       
230   AliESDEvent* esd = dynamic_cast<AliESDEvent*> (InputEvent());
231   // Select PHYSICS events (type=7, for data)
232   if(!fIsMCInput && esd->GetEventType()!=7) return; 
233   
234   // ********* MC INFO *********************************
235   if(fIsMCInput){
236
237     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
238     if (!eventHandler) {
239       Printf("ERROR: Could not retrieve MC event handler");
240       return;
241     }
242   
243     AliMCEvent* mcEvent = eventHandler->MCEvent();
244     if (!mcEvent) {
245       Printf("ERROR: Could not retrieve MC event");
246       return;
247    }
248
249     AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
250     if(!genHeader){
251       printf("  Event generator header not available!!!\n");
252       return;
253     }
254
255     if(genHeader->InheritsFrom(AliGenHijingEventHeader::Class())){
256       Float_t bMC = ((AliGenHijingEventHeader*) genHeader)->ImpactParameter();
257       Int_t specNeutronProj = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsn();
258       Int_t specProtonProj  = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsp();
259       Int_t specNeutronTarg = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsn();
260       Int_t specProtonTarg  = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsp();
261       Int_t npartTargMC = 208-(specNeutronTarg+specProtonTarg);
262       Int_t npartProjMC = 208-(specNeutronProj+specProtonProj);
263     }  
264
265   }
266   // ****************************************************
267   
268   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
269   
270   if((((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB)){
271     
272     AliESDZDC *esdZDC = esd->GetESDZDC();
273   
274     for(Int_t i=0; i<4; i++){
275       fhTDCZNSum->Fill(esdZDC->GetZNTDCDiff(i));  
276       fhTDCZNDiff->Fill(esdZDC->GetZNTDCSum(i)); 
277     }
278     fhZNCSpectrum->Fill(esdZDC->GetZDCN1Energy());      
279     fhZNASpectrum->Fill(esdZDC->GetZDCN2Energy());
280     fhZPCSpectrum->Fill(esdZDC->GetZDCP1Energy());              
281     fhZPASpectrum->Fill(esdZDC->GetZDCP2Energy());      
282     fhZEM1Spectrum->Fill(esdZDC->GetZDCEMEnergy(0));
283     fhZEM2Spectrum->Fill(esdZDC->GetZDCEMEnergy(1));
284   
285     const Double_t * towZNC = esdZDC->GetZN1TowerEnergy();
286     const Double_t * towZPC = esdZDC->GetZP1TowerEnergy();
287     const Double_t * towZNA = esdZDC->GetZN2TowerEnergy();
288     const Double_t * towZPA = esdZDC->GetZP2TowerEnergy();
289     //    
290     fhZNCpmc->Fill(towZNC[0]);    
291     fhZNApmc->Fill(towZPC[0]);    
292     fhZPCpmc->Fill(towZNA[0]);    
293     fhZPApmc->Fill(towZPA[0]);    
294   
295     Double_t xyZNC[2]={-99.,-99.}, xyZNA[2]={-99.,-99.};
296     //esdZDC->GetZNCentroidInPbPb(fBeamEnergy, xyZNC, xyZNA);
297     esdZDC->GetZNCentroidInpp(xyZNC, xyZNA);
298     
299     fhZNCCentroid->Fill(xyZNC[0], xyZNC[1]); 
300     fhZNACentroid->Fill(xyZNA[0], xyZNA[1]); 
301     
302     const Double_t * towZNCLG = esdZDC->GetZN1TowerEnergyLR();
303     const Double_t * towZNALG = esdZDC->GetZN2TowerEnergyLR();
304     Double_t znclg=0., znalg=0.;
305     for(Int_t iq=0; iq<5; iq++){
306        znclg += towZNCLG[iq];
307        znalg += towZNALG[iq];
308     }
309     fhZNCemd->Fill(znclg);       
310     fhZNAemd->Fill(znalg);       
311     fhPMCZNCemd->Fill(towZNCLG[0]);   
312     fhPMCZNAemd->Fill(towZNALG[0]);   
313   
314     PostData(1, fOutput);
315   
316   }
317    
318 }
319
320
321
322 //________________________________________________________________________
323 void AliAnalysisTaskZDC::Terminate(Option_t */*option*/)
324 {
325   // Terminate analysis
326   //
327 }