fixing bug in par file creation when package name was equally to a directory name...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskAODCentralityMaker.cxx
CommitLineData
c94a2509 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// AliAnalysisTaskSE to make AOD centrality
19// Author: Alberica Toia, CERN, Alberica.Toia@cern.ch
20//
21/////////////////////////////////////////////////////////////
22
23#include <TROOT.h>
24#include <TSystem.h>
25
26#include "AliVEvent.h"
27#include "AliESDEvent.h"
28#include "AliAODEvent.h"
29#include "AliAODCentrality.h"
c94a2509 30#include "AliAnalysisManager.h"
c94a2509 31#include "AliESDInputHandler.h"
32#include "AliESDZDC.h"
33#include "AliESDFMD.h"
34#include "AliESDVZERO.h"
35#include "AliMultiplicity.h"
36#include "AliAODHandler.h"
42f0d071 37#include "AliAODHeader.h"
c94a2509 38#include "AliAODEvent.h"
39#include "AliAODVertex.h"
c94a2509 40#include "AliMCEvent.h"
41#include "AliMCEventHandler.h"
42#include "AliMCParticle.h"
43#include "AliStack.h"
44#include "AliHeader.h"
c94a2509 45#include "AliGenEventHeader.h"
46#include "AliGenHijingEventHeader.h"
c94a2509 47#include "AliAnalysisTaskAODCentralityMaker.h"
48
49ClassImp(AliAnalysisTaskAODCentralityMaker)
50
51
52//________________________________________________________________________
53AliAnalysisTaskAODCentralityMaker::AliAnalysisTaskAODCentralityMaker():
54AliAnalysisTaskSE(),
55fAODCentrality(0),
56fDeltaAODFileName("AliAOD.Centrality.root"),
42f0d071 57fAODHeader (0),
58fIsMCInput (0)
c94a2509 59{
60 // Default constructor
c94a2509 61}
62
63//________________________________________________________________________
64AliAnalysisTaskAODCentralityMaker::AliAnalysisTaskAODCentralityMaker(const char *name):
65AliAnalysisTaskSE(name),
66fAODCentrality(0),
67fDeltaAODFileName("AliAOD.Centrality.root"),
42f0d071 68fAODHeader (0),
69fIsMCInput (0)
c94a2509 70{
71 // Standard constructor
c94a2509 72}
73
74
75//________________________________________________________________________
76AliAnalysisTaskAODCentralityMaker::~AliAnalysisTaskAODCentralityMaker()
77{
78 // Destructor
79}
80
81//________________________________________________________________________
82void AliAnalysisTaskAODCentralityMaker::Init()
83{
84 // Initialization
85 if(fDebug > 1) printf("AnalysisTaskAODCentralityMaker::Init() \n");
86 AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile(fDeltaAODFileName.Data());
87
88 return;
89}
90
91//________________________________________________________________________
92void AliAnalysisTaskAODCentralityMaker::UserCreateOutputObjects()
93{
94
95 // Create the output container
96 //
97 if(fDebug > 1) printf("AnalysisTaskAODCentralityMaker::UserCreateOutPutData() \n");
98 // Support both the case when the AOD + deltaAOD are produced in an ESD
99 // analysis or if the deltaAOD is produced on an analysis on AOD's. (A.G. 27/04/09)
100 if(!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) {
101 Fatal("UserCreateOutputObjects", "This task needs an AOD handler");
102 return;
103 }
104 TString filename = fDeltaAODFileName;
105 // When running on standard AOD to produce deltas, IsStandardAOD is never set,
106 // If AODEvent is NULL, new branches have to be added to the new file(s) (A.G. 15/01/10)
107 if(!IsStandardAOD() && AODEvent()) filename = "";
108
109 fAODCentrality = new AliAODCentrality();
110 fAODCentrality->SetName("AODCentrality");
111 AddAODBranch("AliAODCentrality", &fAODCentrality, filename);
112
42f0d071 113
114 fAODHeader = new AliAODHeader();
115 AddAODBranch("AliAODHeader", &fAODHeader, filename);
c94a2509 116 return;
117}
118
42f0d071 119
c94a2509 120//________________________________________________________________________
121void AliAnalysisTaskAODCentralityMaker::UserExec(Option_t */*option*/)
122{
42f0d071 123 AliVEvent* event = InputEvent();
124 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event);
c94a2509 125
42f0d071 126 Float_t beamEnergy = esd->GetBeamEnergy();
127 Int_t nTracks = event->GetNumberOfTracks();
128 Int_t nPmdTracks = esd->GetNumberOfPmdTracks();
c94a2509 129
130 // ***** V0 info
131 AliESDVZERO* esdV0 = esd->GetVZEROData();
42f0d071 132 Double_t multV0A = esdV0->GetMTotV0A();
133 Double_t multV0C = esdV0->GetMTotV0C();
c94a2509 134
c94a2509 135
136 // ***** vertex info
137 const AliESDVertex *vertex = esd->GetPrimaryVertexSPD();
42f0d071 138 Double_t xVertex = vertex->GetX();
139 Double_t yVertex = vertex->GetY();
140 Double_t zVertex = vertex->GetZ();
141 Bool_t vertexer3d;
142
143 if(vertex->IsFromVertexer3D()) vertexer3d = kTRUE;
144 else vertexer3d = kFALSE;
c94a2509 145 Double_t vertex3[3];
146 vertex->GetXYZ(vertex3);
147
148 // ***** CB info (tracklets, clusters, chips)
149 const AliMultiplicity *mult = esd->GetMultiplicity();
42f0d071 150 Int_t nTracklets = mult->GetNumberOfTracklets();
151 Int_t nSingleClusters;
152 Int_t nClusters[6];
c94a2509 153
42f0d071 154 for(Int_t ilay = 0; ilay < 6; ilay++){
155 nClusters[ilay] = mult->GetNumberOfITSClusters(ilay);
c94a2509 156 }
42f0d071 157 nSingleClusters = mult->GetNumberOfSingleClusters();
158
159 Int_t nChips[2];
160 for(Int_t ilay = 0; ilay < 2; ilay++){
161 nChips[ilay] = mult->GetNumberOfFiredChips(ilay);
c94a2509 162 }
163
164 // ***** FMD info
165 AliESDFMD *fmd = esd->GetFMDData();
166 Float_t totalMultA = 0;
167 Float_t totalMultC = 0;
42f0d071 168 const Float_t fmdLowCut = 0.4;
c94a2509 169
42f0d071 170 for(UShort_t det = 1;det <= 3; det++) {
171 Int_t nRings = (det==1 ? 1 : 2);
172 for (UShort_t ir = 0; ir < nRings; ir++) {
173 Char_t ring = (ir == 0 ? 'I' : 'O');
174 UShort_t nsec = (ir == 0 ? 20 : 40);
175 UShort_t nstr = (ir == 0 ? 512 : 256);
176 for(UShort_t sec =0; sec < nsec; sec++) {
177 for(UShort_t strip = 0; strip < nstr; strip++) {
178 Float_t fmdMult = fmd->Multiplicity(det,ring,sec,strip);
179 if(fmdMult == 0 || fmdMult == AliESDFMD::kInvalidMult) continue;
180 Float_t nParticles=0;
181 if(fmdMult > fmdLowCut) {
182 nParticles = 1.;
183 }
c94a2509 184
42f0d071 185 if (det<3) totalMultA = totalMultA + nParticles;
186 else totalMultC = totalMultC + nParticles;
187
188 }
c94a2509 189 }
c94a2509 190 }
c94a2509 191 }
42f0d071 192 Float_t multFMDA = totalMultA;
193 Float_t multFMDC = totalMultC;
c94a2509 194
195 // ***** ZDC info
196 AliESDZDC *esdZDC = esd->GetESDZDC();
42f0d071 197 UInt_t esdFlag = esdZDC->GetESDQuality();
c94a2509 198
42f0d071 199 Float_t znCEnergy = (Float_t) (esdZDC->GetZDCN1Energy());
200 Float_t zpCEnergy = (Float_t) (esdZDC->GetZDCP1Energy());
201 Float_t znAEnergy = (Float_t) (esdZDC->GetZDCN2Energy());
202 Float_t zpAEnergy = (Float_t) (esdZDC->GetZDCP2Energy());
203 Float_t zem1Energy = (Float_t) (esdZDC->GetZDCEMEnergy(0));
204 Float_t zem2Energy = (Float_t) (esdZDC->GetZDCEMEnergy(1));
c94a2509 205
42f0d071 206 Double_t bZDC = esdZDC->GetImpactParameter();
207 Int_t nPartZDC = esdZDC->GetZDCParticipants();
208 Double_t bZDCA = esdZDC->GetImpactParamSideA();
209 Int_t nPartZDCA = esdZDC->GetZDCPartSideA();
210 Double_t bZDCC = esdZDC->GetImpactParamSideC();
211 Int_t nPartZDCC = esdZDC->GetZDCPartSideC();
c94a2509 212
213 const Double_t * towZNC = esdZDC->GetZN1TowerEnergy();
214 const Double_t * towZPC = esdZDC->GetZP1TowerEnergy();
215 const Double_t * towZNA = esdZDC->GetZN2TowerEnergy();
216 const Double_t * towZPA = esdZDC->GetZP2TowerEnergy();
217 //
42f0d071 218 Float_t znCtower[5]; // ZNC 5 tower signals
219 Float_t zpCtower[5]; // ZPC 5 tower signals
220 Float_t znAtower[5]; // ZNA 5 tower signals
221 Float_t zpAtower[5]; // ZPA 5 tower signals
222 Float_t centrZNC[2]; // centroid over ZNC
223 Float_t centrZNA[2]; // centroid over ZNA
224
225 for(Int_t it = 0; it < 5; it++){
226 znCtower[it] = (Float_t) (towZNC[it]);
227 zpCtower[it] = (Float_t) (towZPC[it]);
228 znAtower[it] = (Float_t) (towZNA[it]);
229 zpAtower[it] = (Float_t) (towZPA[it]);
c94a2509 230 }
231
42f0d071 232 Double_t xyZNC[2] = {-99.,-99.};
233 Double_t xyZNA[2] = {-99.,-99.};
234
235 esdZDC->GetZNCentroidInPbPb(beamEnergy, xyZNC, xyZNA);
236 for(Int_t it = 0; it < 2; it++){
237 centrZNC[it] = xyZNC[it];
238 centrZNA[it] = xyZNA[it];
c94a2509 239 }
240
241 // ***** MC info
42f0d071 242 Double_t bMC = 0.;
243 Int_t specNeutronProj = 0;
244 Int_t specProtonProj = 0;
245 Int_t specNeutronTarg = 0;
246 Int_t specProtonTarg = 0;
247 Int_t nPartTargMC = 0;
248 Int_t nPartProjMC = 0;
249 Int_t nnColl = 0;
250 Int_t nnwColl = 0;
251 Int_t nwNColl = 0;
252 Int_t nwNwColl = 0;
253
c94a2509 254 if(fIsMCInput){
255
256 AliMCEvent* mcEvent = MCEvent();
257 if (!mcEvent) {
258 printf(" Could not retrieve MC event!!!\n");
259 return;
260 }
261
42f0d071 262 Int_t nMyTracks_gen = 0;
c94a2509 263 AliStack *stack = 0x0; // needed for MC studies
264 stack = MCEvent()->Stack();
265 for (Int_t iTrack = 0; iTrack < MCEvent()->GetNumberOfTracks(); iTrack++) {
266 //get properties of mc particle
267 AliMCParticle* mcP = (AliMCParticle*) MCEvent()->GetTrack(iTrack);
268 // Primaries only
269 if (!(stack->IsPhysicalPrimary(mcP->Label()))) continue;
270 //charged tracks only
271 if (mcP->Particle()->GetPDG()->Charge() == 0) continue;
272 //same cuts as on ESDtracks
273 // if(TMath::Abs(mcP->Eta())>0.9)continue;
274 // if(mcP->Pt()<0.2)continue;
275 // if(mcP->Pt()>200)continue;
276
42f0d071 277 nMyTracks_gen ++;
c94a2509 278 }
279
280 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
281 if(!genHeader){
282 printf(" Event generator header not available!!!\n");
283 return;
284 }
285
42f0d071 286
c94a2509 287 if(genHeader->InheritsFrom(AliGenHijingEventHeader::Class())){
42f0d071 288 bMC = ((AliGenHijingEventHeader*) genHeader)->ImpactParameter();
289 specNeutronProj = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsn();
290 specProtonProj = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsp();
291 specNeutronTarg = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsn();
292 specProtonTarg = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsp();
293 nPartTargMC = Int_t (208.-(specNeutronTarg+specProtonTarg));
294 nPartProjMC = Int_t (208.-(specNeutronProj+specProtonProj));
295 nnColl = ((AliGenHijingEventHeader*) genHeader)->NN();
296 nnwColl = ((AliGenHijingEventHeader*) genHeader)->NNw();
297 nwNColl = ((AliGenHijingEventHeader*) genHeader)->NwN();
298 nwNwColl = ((AliGenHijingEventHeader*) genHeader)->NwNw();
c94a2509 299 }
c94a2509 300 }
301
42f0d071 302 fAODCentrality->SetxVertex (xVertex );
303 fAODCentrality->SetyVertex (yVertex );
304 fAODCentrality->SetzVertex (zVertex );
305 fAODCentrality->SetVertexer3d (vertexer3d );
306 fAODCentrality->SetbMC (bMC);
307 fAODCentrality->SetNpartTargMC (nPartTargMC);
308 fAODCentrality->SetNpartProjMC (nPartProjMC);
309 fAODCentrality->SetNNColl (nnColl);
310 fAODCentrality->SetNNwColl (nnwColl);
311 fAODCentrality->SetNwNColl (nwNColl);
312 fAODCentrality->SetNwNwColl (nwNwColl);
313 fAODCentrality->SetNTracklets (nTracklets);
314 fAODCentrality->SetNSingleClusters (nSingleClusters);
c94a2509 315 fAODCentrality->SetNClusters (
42f0d071 316 nClusters[0],
317 nClusters[1],
318 nClusters[2],
319 nClusters[3],
320 nClusters[4],
321 nClusters[5]);
c94a2509 322 fAODCentrality->SetNChips (
42f0d071 323 nChips[0],
324 nChips[1]);
325 fAODCentrality->SetbZDC (bZDC);
326 fAODCentrality->SetNpartZDC (nPartZDC);
327 fAODCentrality->SetbZDCA (bZDCA);
328 fAODCentrality->SetNpartZDCA (nPartZDCA);
329 fAODCentrality->SetbZDCC (bZDCC);
330 fAODCentrality->SetNpartZDCC (nPartZDCC);
331 fAODCentrality->SetESDFlag (esdFlag);
332 fAODCentrality->SetZNCEnergy (znCEnergy);
333 fAODCentrality->SetZPCEnergy (zpCEnergy);
334 fAODCentrality->SetZNAEnergy (znAEnergy);
335 fAODCentrality->SetZPAEnergy (zpAEnergy);
336 fAODCentrality->SetZEM1Energy (zem1Energy);
337 fAODCentrality->SetZEM2Energy (zem2Energy);
c94a2509 338 fAODCentrality->SetZNCtower (
42f0d071 339 znCtower[0],
340 znCtower[1],
341 znCtower[2],
342 znCtower[3],
343 znCtower[4]);
c94a2509 344 fAODCentrality->SetZPCtower (
42f0d071 345 zpCtower[0],
346 zpCtower[1],
347 zpCtower[2],
348 zpCtower[3],
349 zpCtower[4]);
c94a2509 350
351 fAODCentrality-> SetZNAtower (
42f0d071 352 znAtower[0],
353 znAtower[1],
354 znAtower[2],
355 znAtower[3],
356 znAtower[4]);
c94a2509 357 fAODCentrality-> SetZPAtower (
42f0d071 358 zpAtower[0],
359 zpAtower[1],
360 zpAtower[2],
361 zpAtower[3],
362 zpAtower[4]);
c94a2509 363 fAODCentrality-> SetCentrZNC (
42f0d071 364 centrZNC[0],
365 centrZNC[1]);
c94a2509 366 fAODCentrality-> SetCentrZNA (
42f0d071 367 centrZNA[0],
368 centrZNA[1]);
369 fAODCentrality-> SetNTracks (nTracks);
370 fAODCentrality-> SetNPmdTracks (nPmdTracks);
371 fAODCentrality-> SetMultV0A (multV0A);
372 fAODCentrality-> SetMultV0C (multV0C);
373 fAODCentrality-> SetMultFMDA (multFMDA);
374 fAODCentrality-> SetMultFMDC (multFMDC);
c94a2509 375
42f0d071 376//
377// Header Replication
378//
379 AliAODHeader* hdr = AODEvent()->GetHeader();
380 *fAODHeader = *hdr;
381//
c94a2509 382 return;
383}
384
385//________________________________________________________________________
386void AliAnalysisTaskAODCentralityMaker::Terminate(Option_t */*option*/)
387{
388 // Terminate analysis
389 //
390 if(fDebug > 1) printf("AnalysisTaskAODCentralityMaker: Terminate() \n");
391}