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