]>
Commit | Line | Data |
---|---|---|
3fbf06a3 | 1 | |
ec4af4c1 | 2 | /************************************************************************** |
3 | * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. * | |
4 | * * | |
5 | * Author: The ALICE Off-line Project. * | |
6 | * Contributors are mentioned in the code where appropriate. * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | /* $Id$ */ | |
18 | ||
19 | //------------------------------------------------------------------------- | |
20 | // Implementation of the Virtual Event Handler Interface for AOD | |
21 | // Author: Andreas Morsch, CERN | |
22 | //------------------------------------------------------------------------- | |
23 | ||
052994fb | 24 | |
ec4af4c1 | 25 | #include <TTree.h> |
e910dd36 | 26 | #include <TFile.h> |
7970f4ac | 27 | #include <TString.h> |
dce1b636 | 28 | #include <TList.h> |
160959a9 | 29 | #include <TROOT.h> |
e910dd36 | 30 | |
da97a08a | 31 | #include "AliLog.h" |
ec4af4c1 | 32 | #include "AliAODHandler.h" |
33 | #include "AliAODEvent.h" | |
aa7e002c | 34 | #include "AliAODExtension.h" |
da97a08a | 35 | #include "AliAODTracklets.h" |
36 | #include "AliStack.h" | |
37 | #include "AliAODMCParticle.h" | |
dce1b636 | 38 | #include "AliAODMCHeader.h" |
da97a08a | 39 | #include "AliMCEventHandler.h" |
40 | #include "AliMCEvent.h" | |
dce1b636 | 41 | #include "AliGenEventHeader.h" |
42 | #include "AliGenHijingEventHeader.h" | |
43 | #include "AliGenDPMjetEventHeader.h" | |
44 | #include "AliGenPythiaEventHeader.h" | |
45 | #include "AliGenCocktailEventHeader.h" | |
26ba01d4 | 46 | #include "AliCodeTimer.h" |
47 | #include "AliAODBranchReplicator.h" | |
48 | #include "Riostream.h" | |
ec4af4c1 | 49 | |
66b0310c | 50 | using std::endl; |
51 | using std::cout; | |
ec4af4c1 | 52 | ClassImp(AliAODHandler) |
53 | ||
54 | //______________________________________________________________________________ | |
55 | AliAODHandler::AliAODHandler() : | |
f3214a54 | 56 | AliVEventHandler(), |
78f7f935 | 57 | fIsStandard(kTRUE), |
da97a08a | 58 | fFillAOD(kTRUE), |
41b01ae4 | 59 | fFillAODRun(kTRUE), |
ca2834f6 | 60 | fFillExtension(kTRUE), |
7c3a9fbf | 61 | fNeedsHeaderReplication(kFALSE), |
2981307f | 62 | fNeedsTOFHeaderReplication(kFALSE), |
63 | fNeedsVZEROReplication(kFALSE), | |
75754ba8 | 64 | fNeedsTracksBranchReplication(kFALSE), |
65 | fNeedsVerticesBranchReplication(kFALSE), | |
66 | fNeedsV0sBranchReplication(kFALSE), | |
e0107012 | 67 | fNeedsCascadesBranchReplication(kFALSE), |
75754ba8 | 68 | fNeedsTrackletsBranchReplication(kFALSE), |
69 | fNeedsPMDClustersBranchReplication(kFALSE), | |
70 | fNeedsJetsBranchReplication(kFALSE), | |
71 | fNeedsFMDClustersBranchReplication(kFALSE), | |
72 | fNeedsCaloClustersBranchReplication(kFALSE), | |
720f7306 | 73 | fNeedsCaloTriggerBranchReplication(kFALSE), |
3549c522 | 74 | fNeedsMCParticlesBranchReplication(kFALSE), |
866d8d78 | 75 | fNeedsDimuonsBranchReplication(kFALSE), |
fc05a533 | 76 | fNeedsHMPIDBranchReplication(kFALSE), |
75754ba8 | 77 | fAODIsReplicated(kFALSE), |
4fa36885 | 78 | fTreeBuffSize(30000000), |
79 | fMemCountAOD(0), | |
ec4af4c1 | 80 | fAODEvent(NULL), |
da97a08a | 81 | fMCEventH(NULL), |
e910dd36 | 82 | fTreeA(NULL), |
83 | fFileA(NULL), | |
9066c676 | 84 | fFileName(""), |
582cfeb5 | 85 | fExtensions(NULL), |
86 | fFilters(NULL) | |
ec4af4c1 | 87 | { |
88 | // default constructor | |
89 | } | |
90 | ||
91 | //______________________________________________________________________________ | |
92 | AliAODHandler::AliAODHandler(const char* name, const char* title): | |
f3214a54 | 93 | AliVEventHandler(name, title), |
78f7f935 | 94 | fIsStandard(kTRUE), |
da97a08a | 95 | fFillAOD(kTRUE), |
41b01ae4 | 96 | fFillAODRun(kTRUE), |
ca2834f6 | 97 | fFillExtension(kTRUE), |
7c3a9fbf | 98 | fNeedsHeaderReplication(kFALSE), |
2981307f | 99 | fNeedsTOFHeaderReplication(kFALSE), |
100 | fNeedsVZEROReplication(kFALSE), | |
75754ba8 | 101 | fNeedsTracksBranchReplication(kFALSE), |
102 | fNeedsVerticesBranchReplication(kFALSE), | |
103 | fNeedsV0sBranchReplication(kFALSE), | |
e0107012 | 104 | fNeedsCascadesBranchReplication(kFALSE), |
75754ba8 | 105 | fNeedsTrackletsBranchReplication(kFALSE), |
106 | fNeedsPMDClustersBranchReplication(kFALSE), | |
107 | fNeedsJetsBranchReplication(kFALSE), | |
108 | fNeedsFMDClustersBranchReplication(kFALSE), | |
109 | fNeedsCaloClustersBranchReplication(kFALSE), | |
fc05a533 | 110 | fNeedsCaloTriggerBranchReplication(kFALSE), |
3549c522 | 111 | fNeedsMCParticlesBranchReplication(kFALSE), |
866d8d78 | 112 | fNeedsDimuonsBranchReplication(kFALSE), |
fc05a533 | 113 | fNeedsHMPIDBranchReplication(kFALSE), |
75754ba8 | 114 | fAODIsReplicated(kFALSE), |
4fa36885 | 115 | fTreeBuffSize(30000000), |
116 | fMemCountAOD(0), | |
ec4af4c1 | 117 | fAODEvent(NULL), |
da97a08a | 118 | fMCEventH(NULL), |
e910dd36 | 119 | fTreeA(NULL), |
120 | fFileA(NULL), | |
9066c676 | 121 | fFileName(""), |
582cfeb5 | 122 | fExtensions(NULL), |
123 | fFilters(NULL) | |
ec4af4c1 | 124 | { |
582cfeb5 | 125 | // Normal constructor. |
ec4af4c1 | 126 | } |
127 | ||
128 | //______________________________________________________________________________ | |
129 | AliAODHandler::~AliAODHandler() | |
130 | { | |
9066c676 | 131 | // Destructor. |
14d6fad5 | 132 | |
133 | delete fAODEvent; | |
134 | ||
9eb17d61 | 135 | if (fFileA) fFileA->Close(); |
74e11085 | 136 | |
9eb17d61 | 137 | delete fFileA; |
14d6fad5 | 138 | delete fTreeA; |
139 | delete fExtensions; | |
140 | delete fFilters; | |
ec4af4c1 | 141 | } |
142 | ||
7970f4ac | 143 | //______________________________________________________________________________ |
300d5701 | 144 | Bool_t AliAODHandler::Init(Option_t* opt) |
ec4af4c1 | 145 | { |
6989bff3 | 146 | // Initialize IO |
147 | // | |
148 | // Create the AODevent object | |
e0107012 | 149 | |
4e6d5854 | 150 | Bool_t createStdAOD = fIsStandard || fFillAOD; |
aa399a26 | 151 | if(!fAODEvent && createStdAOD){ |
ec4af4c1 | 152 | fAODEvent = new AliAODEvent(); |
c8fe2783 | 153 | if (fIsStandard) |
154 | fAODEvent->CreateStdContent(); | |
6989bff3 | 155 | } |
156 | // | |
157 | // File opening according to execution mode | |
7970f4ac | 158 | TString option(opt); |
159 | option.ToLower(); | |
aa399a26 | 160 | if (createStdAOD) { |
161 | TDirectory *owd = gDirectory; | |
162 | if (option.Contains("proof")) { | |
163 | // proof | |
164 | // Merging via files. Need to access analysis manager via interpreter. | |
165 | gROOT->ProcessLine(Form("AliAnalysisDataContainer *c_common_out = AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer();")); | |
166 | gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(c_common_out, \"RECREATE\");")); | |
167 | fFileA = gFile; | |
168 | } else { | |
169 | // local and grid | |
170 | fFileA = new TFile(fFileName.Data(), "RECREATE"); | |
171 | } | |
172 | CreateTree(1); | |
173 | owd->cd(); | |
174 | } | |
9066c676 | 175 | if (fExtensions) { |
176 | TIter next(fExtensions); | |
177 | AliAODExtension *ext; | |
178 | while ((ext=(AliAODExtension*)next())) ext->Init(option); | |
179 | } | |
582cfeb5 | 180 | if (fFilters) { |
181 | TIter nextf(fFilters); | |
182 | AliAODExtension *filteredAOD; | |
183 | while ((filteredAOD=(AliAODExtension*)nextf())) { | |
184 | filteredAOD->SetEvent(fAODEvent); | |
185 | filteredAOD->Init(option); | |
14d6fad5 | 186 | } |
582cfeb5 | 187 | } |
14d6fad5 | 188 | |
6989bff3 | 189 | return kTRUE; |
ec4af4c1 | 190 | } |
191 | ||
26ba01d4 | 192 | //______________________________________________________________________________ |
193 | void AliAODHandler::Print(Option_t* opt) const | |
194 | { | |
195 | // Print info about this object | |
196 | ||
197 | cout << opt << Form("IsStandard %d filename=%s",fIsStandard,fFileName.Data()) << endl; | |
198 | ||
199 | if ( fExtensions ) | |
200 | { | |
201 | cout << opt << fExtensions->GetEntries() << " extensions :" << endl; | |
b5b9155e | 202 | PrintExtensions(*fExtensions); |
26ba01d4 | 203 | } |
204 | if ( fFilters ) | |
205 | { | |
206 | cout << opt << fFilters->GetEntries() << " filters :" << endl; | |
b5b9155e | 207 | PrintExtensions(*fFilters); |
26ba01d4 | 208 | } |
209 | } | |
210 | ||
211 | //______________________________________________________________________________ | |
b5b9155e | 212 | void AliAODHandler::PrintExtensions(const TObjArray& array) const |
26ba01d4 | 213 | { |
214 | // Show the list of aod extensions | |
215 | TIter next(&array); | |
216 | AliAODExtension* ext(0x0); | |
217 | while ( ( ext = static_cast<AliAODExtension*>(next()) ) ) | |
218 | { | |
219 | ext->Print(" "); | |
220 | } | |
221 | } | |
222 | ||
9066c676 | 223 | //______________________________________________________________________________ |
da97a08a | 224 | void AliAODHandler::StoreMCParticles(){ |
dce1b636 | 225 | |
da97a08a | 226 | // |
227 | // Remap the labels from ESD stack and store | |
228 | // the AODMCParticles, makes only sense if we have | |
229 | // the mcparticles branch | |
230 | // has to be done here since we cannot know in advance | |
231 | // which particles are needed (e.g. by the tracks etc.) | |
232 | // | |
233 | // Particles have been selected by AliMCEventhanlder->SelectParticle() | |
234 | // To use the MCEventhandler here we need to set it from the outside | |
235 | // can vanish when Handler go to the ANALYSISalice library | |
dce1b636 | 236 | // |
237 | // The Branch booking for mcParticles and mcHeader has to happen | |
238 | // in an external task for now since the AODHandler does not have access | |
239 | // the AnalysisManager. For the same reason the pointer t o the MCEventH | |
240 | // has to passed to the AOD Handler by this task | |
241 | // (doing this in the steering macro would not work on PROOF) | |
da97a08a | 242 | |
aa399a26 | 243 | if (!fAODEvent) return; |
da97a08a | 244 | TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()); |
245 | if(!mcarray)return; | |
da97a08a | 246 | |
dce1b636 | 247 | AliAODMCHeader *mcHeader = (AliAODMCHeader*)fAODEvent->FindListObject(AliAODMCHeader::StdBranchName()); |
248 | if(!mcHeader)return; | |
249 | ||
da97a08a | 250 | // Get the MC Infos.. Handler needs to be set before |
251 | // while adding the branch | |
252 | // This needs to be done, not to depend on the AnalysisManager | |
253 | ||
254 | if(!fMCEventH)return; | |
255 | if(!fMCEventH->MCEvent())return; | |
256 | AliStack *pStack = fMCEventH->MCEvent()->Stack(); | |
257 | if(!pStack)return; | |
258 | ||
259 | fMCEventH->CreateLabelMap(); | |
260 | ||
dce1b636 | 261 | // |
262 | // Get the Event Header | |
263 | // | |
264 | ||
265 | AliHeader* header = fMCEventH->MCEvent()->Header(); | |
9efd8e10 | 266 | // get the MC vertex |
267 | AliGenEventHeader* genHeader = 0; | |
268 | if (header) genHeader = header->GenEventHeader(); | |
269 | if (genHeader) { | |
270 | TArrayF vtxMC(3); | |
271 | genHeader->PrimaryVertex(vtxMC); | |
272 | mcHeader->SetVertex(vtxMC[0],vtxMC[1],vtxMC[2]); | |
9efd8e10 | 273 | // we search the MCEventHeaders first |
274 | // Two cases, cocktail or not... | |
275 | AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader); | |
276 | if(genCocktailHeader){ | |
08078824 | 277 | // we have a coktail header add the name once |
9efd8e10 | 278 | mcHeader->AddGeneratorName(genHeader->GetName()); |
9efd8e10 | 279 | TList* headerList = genCocktailHeader->GetHeaders(); |
08078824 | 280 | // the first entry defines some extra general settings |
281 | AliGenEventHeader *headerEntry = dynamic_cast<AliGenEventHeader*>(headerList->At(0)); | |
282 | if (!headerEntry) { | |
283 | AliFatal("AliGenEventHeader entry not found in the header list"); | |
284 | } else { | |
285 | SetMCHeaderInfo(mcHeader,headerEntry); | |
286 | } | |
9efd8e10 | 287 | } |
288 | else{ | |
08078824 | 289 | // No Cocktail just take the first one |
290 | SetMCHeaderInfo(mcHeader,genHeader); | |
9efd8e10 | 291 | } |
08078824 | 292 | // Add all the headers and names, if no cocktail header |
293 | // there will be only one entry | |
294 | mcHeader->AddCocktailHeaders(genHeader); | |
dce1b636 | 295 | } |
9efd8e10 | 296 | |
dce1b636 | 297 | |
298 | ||
299 | ||
300 | ||
301 | // Store the AliAODParticlesMC | |
93836e1b | 302 | AliMCEvent* mcEvent = fMCEventH->MCEvent(); |
303 | ||
304 | Int_t np = mcEvent->GetNumberOfTracks(); | |
305 | Int_t nprim = mcEvent->GetNumberOfPrimaries(); | |
da97a08a | 306 | |
307 | ||
308 | Int_t j = 0; | |
309 | TClonesArray& l = *mcarray; | |
310 | ||
93836e1b | 311 | for(int i = 0; i < np; ++i){ |
312 | if(fMCEventH->IsParticleSelected(i)){ | |
313 | Int_t flag = 0; | |
6cd07d0a | 314 | AliMCParticle* mcpart = (AliMCParticle*) mcEvent->GetTrack(i); |
93836e1b | 315 | if(i<nprim)flag |= AliAODMCParticle::kPrimary; |
316 | ||
317 | if(mcEvent->IsPhysicalPrimary(i))flag |= AliAODMCParticle::kPhysicalPrim; | |
d4312c7a | 318 | if(mcEvent->IsSecondaryFromWeakDecay(i))flag |= AliAODMCParticle::kSecondaryFromWeakDecay; |
319 | if(mcEvent->IsSecondaryFromMaterial(i))flag |= AliAODMCParticle::kSecondaryFromMaterial; | |
6a9d52e4 | 320 | |
93836e1b | 321 | if(fMCEventH->GetNewLabel(i)!=j){ |
322 | AliError(Form("MISMATCH New label %d j: %d",fMCEventH->GetNewLabel(i),j)); | |
da97a08a | 323 | } |
da97a08a | 324 | |
77f43bb7 | 325 | AliAODMCParticle mcpartTmp(mcpart,i,flag); |
93836e1b | 326 | |
77f43bb7 | 327 | mcpartTmp.SetStatus(mcpart->Particle()->GetStatusCode()); |
6a9d52e4 | 328 | mcpartTmp.SetMCProcessCode(mcpart->Particle()->GetUniqueID()); |
93836e1b | 329 | // |
77f43bb7 | 330 | Int_t d0 = mcpartTmp.GetDaughter(0); |
331 | Int_t d1 = mcpartTmp.GetDaughter(1); | |
332 | Int_t m = mcpartTmp.GetMother(); | |
93836e1b | 333 | |
334 | // other than for the track labels, negative values mean | |
335 | // no daughter/mother so preserve it | |
336 | ||
337 | if(d0<0 && d1<0){ | |
338 | // no first daughter -> no second daughter | |
339 | // nothing to be done | |
340 | // second condition not needed just for sanity check at the end | |
77f43bb7 | 341 | mcpartTmp.SetDaughter(0,d0); |
342 | mcpartTmp.SetDaughter(1,d1); | |
93836e1b | 343 | } else if(d1 < 0 && d0 >= 0) { |
344 | // Only one daughter | |
345 | // second condition not needed just for sanity check at the end | |
346 | if(fMCEventH->IsParticleSelected(d0)){ | |
77f43bb7 | 347 | mcpartTmp.SetDaughter(0,fMCEventH->GetNewLabel(d0)); |
93836e1b | 348 | } else { |
77f43bb7 | 349 | mcpartTmp.SetDaughter(0,-1); |
93836e1b | 350 | } |
77f43bb7 | 351 | mcpartTmp.SetDaughter(1,d1); |
93836e1b | 352 | } |
353 | else if (d0 > 0 && d1 > 0 ){ | |
354 | // we have two or more daughters loop on the stack to see if they are | |
355 | // selected | |
77f43bb7 | 356 | Int_t d0Tmp = -1; |
357 | Int_t d1Tmp = -1; | |
93836e1b | 358 | for(int id = d0; id<=d1;++id){ |
359 | if(fMCEventH->IsParticleSelected(id)){ | |
77f43bb7 | 360 | if(d0Tmp==-1){ |
93836e1b | 361 | // first time |
77f43bb7 | 362 | d0Tmp = fMCEventH->GetNewLabel(id); |
363 | d1Tmp = d0Tmp; // this is to have the same schema as on the stack i.e. with one daugther d0 and d1 are the same | |
93836e1b | 364 | } |
77f43bb7 | 365 | else d1Tmp = fMCEventH->GetNewLabel(id); |
93836e1b | 366 | } |
367 | } | |
77f43bb7 | 368 | mcpartTmp.SetDaughter(0,d0Tmp); |
369 | mcpartTmp.SetDaughter(1,d1Tmp); | |
93836e1b | 370 | } else { |
371 | AliError(Form("Unxpected indices %d %d",d0,d1)); | |
372 | } | |
373 | ||
374 | if(m<0){ | |
77f43bb7 | 375 | mcpartTmp.SetMother(m); |
93836e1b | 376 | } else { |
77f43bb7 | 377 | if(fMCEventH->IsParticleSelected(m))mcpartTmp.SetMother(fMCEventH->GetNewLabel(m)); |
93836e1b | 378 | else AliError(Form("PROBLEM Mother not selected %d \n", m)); |
379 | } | |
6326aeae | 380 | |
77f43bb7 | 381 | new (l[j++]) AliAODMCParticle(mcpartTmp); |
93836e1b | 382 | |
da97a08a | 383 | } |
da97a08a | 384 | } |
93836e1b | 385 | AliInfo(Form("AliAODHandler::StoreMCParticles: Selected %d (Primaries %d / total %d) after validation \n", |
da97a08a | 386 | j,nprim,np)); |
387 | ||
388 | // Set the labels in the AOD output... | |
389 | // Remapping | |
390 | ||
391 | // AODTracks | |
392 | TClonesArray* tracks = fAODEvent->GetTracks(); | |
a2c30af1 | 393 | Int_t tofLabel[3]; |
da97a08a | 394 | if(tracks){ |
4640c275 | 395 | for(int it = 0; it < fAODEvent->GetNumberOfTracks();++it){ |
f15c1f69 | 396 | AliAODTrack *track = dynamic_cast<AliAODTrack*>(fAODEvent->GetTrack(it)); |
397 | if(!track) AliFatal("Not a standard AOD"); | |
da97a08a | 398 | |
91dece68 | 399 | Int_t sign = 1; |
400 | Int_t label = track->GetLabel(); | |
401 | if(label<0){ // preserve the sign for later usage | |
402 | label *= -1; | |
403 | sign = -1; | |
404 | } | |
a2c30af1 | 405 | |
93836e1b | 406 | if (label >= AliMCEvent::BgLabelOffset()) label = mcEvent->BgLabelToIndex(label); |
93836e1b | 407 | if(label > np || track->GetLabel() == 0){ |
408 | AliWarning(Form("Wrong ESD track label %5d (%5d)",track->GetLabel(), label)); | |
da97a08a | 409 | } |
9a58c4d4 | 410 | if(fMCEventH->GetNewLabel(label) == 0) { |
93836e1b | 411 | AliWarning(Form("New label not found for %5d (%5d)",track->GetLabel(), label)); |
da97a08a | 412 | } |
91dece68 | 413 | track->SetLabel(sign*fMCEventH->GetNewLabel(label)); |
a2c30af1 | 414 | |
415 | track->GetTOFLabel(tofLabel); | |
416 | ||
9a58c4d4 | 417 | for (Int_t i = 0; i < 3; i++) { |
a2c30af1 | 418 | label = tofLabel[i]; // esd label |
419 | Int_t nlabel = label; // new label | |
420 | if (label < 0) continue; | |
421 | if (label >= AliMCEvent::BgLabelOffset()) nlabel = mcEvent->BgLabelToIndex(label); | |
422 | if(nlabel > np || label == 0) { | |
423 | AliWarning(Form("Wrong TOF label %5d (%5d)", label, nlabel)); | |
424 | } | |
425 | if(fMCEventH->GetNewLabel(label) == 0){ | |
9a58c4d4 | 426 | AliWarning(Form("New TOF label not found for %5d %5d",i, label )); |
427 | tofLabel[i] = -label; | |
428 | } else { | |
429 | tofLabel[i] = fMCEventH->GetNewLabel(label); | |
a2c30af1 | 430 | } |
a2c30af1 | 431 | } |
432 | track->SetTOFLabel(tofLabel); | |
da97a08a | 433 | } |
434 | } | |
435 | ||
436 | // AOD calo cluster | |
437 | TClonesArray *clusters = fAODEvent->GetCaloClusters(); | |
438 | if(clusters){ | |
c8fe2783 | 439 | for (Int_t iClust = 0;iClust < fAODEvent->GetNumberOfCaloClusters(); ++iClust) { |
da97a08a | 440 | AliAODCaloCluster * cluster = fAODEvent->GetCaloCluster(iClust); |
c8fe2783 | 441 | UInt_t nLabel = cluster->GetNLabels(); |
da97a08a | 442 | // Ugly but do not want to fragment memory by creating |
443 | // new Int_t (nLabel) | |
444 | Int_t* labels = const_cast<Int_t*>(cluster->GetLabels()); | |
445 | if (labels){ | |
446 | for(UInt_t i = 0;i < nLabel;++i){ | |
c8fe2783 | 447 | labels[i] = fMCEventH->GetNewLabel(cluster->GetLabelAt(i)); |
da97a08a | 448 | } |
449 | } | |
450 | // cluster->SetLabels(labels,nLabel); | |
451 | }// iClust | |
452 | }// clusters | |
60d77596 | 453 | |
454 | // AOD calo cells MC label re-index | |
455 | Int_t iCell, nCell, cellMCLabel, cellMCLabelNew;; | |
456 | Short_t cellAbsId; | |
457 | Double_t cellE, cellT, cellEFrac; | |
458 | AliAODCaloCells *cells; | |
459 | ||
460 | // EMCal | |
461 | cells = fAODEvent->GetEMCALCells(); | |
462 | if( cells ){ | |
463 | nCell = cells->GetNumberOfCells() ; | |
464 | for( iCell = 0; iCell < nCell; iCell++ ){ | |
465 | cells->GetCell( iCell, cellAbsId, cellE, cellT, cellMCLabel, cellEFrac ); | |
466 | // GetNewLabel returns 1 in case when -1 is supplied | |
467 | if( cellMCLabel < 0 ) | |
468 | cellMCLabelNew = cellMCLabel; | |
469 | else | |
470 | cellMCLabelNew = fMCEventH->GetNewLabel( cellMCLabel ); | |
471 | ||
472 | cells->SetCell( iCell, cellAbsId, cellE, cellT, cellMCLabelNew, cellEFrac ); | |
473 | } | |
474 | } | |
475 | // PHOS | |
476 | cells = fAODEvent->GetPHOSCells(); | |
477 | if( cells ){ | |
478 | nCell = cells->GetNumberOfCells() ; | |
479 | for( iCell = 0; iCell < nCell; iCell++ ){ | |
480 | cells->GetCell( iCell, cellAbsId, cellE, cellT, cellMCLabel, cellEFrac ); | |
481 | // GetNewLabel returns 1 in case when -1 is supplied | |
482 | if( cellMCLabel < 0 ) | |
483 | cellMCLabelNew = cellMCLabel; | |
484 | else | |
485 | cellMCLabelNew = fMCEventH->GetNewLabel( cellMCLabel ); | |
486 | ||
487 | cells->SetCell( iCell, cellAbsId, cellE, cellT, cellMCLabelNew, cellEFrac ); | |
488 | } | |
489 | } | |
da97a08a | 490 | |
491 | // AOD tracklets | |
492 | AliAODTracklets *tracklets = fAODEvent->GetTracklets(); | |
493 | if(tracklets){ | |
494 | for(int it = 0;it < tracklets->GetNumberOfTracklets();++it){ | |
495 | int label0 = tracklets->GetLabel(it,0); | |
496 | int label1 = tracklets->GetLabel(it,1); | |
497 | if(label0>=0)label0 = fMCEventH->GetNewLabel(label0); | |
498 | if(label1>=0)label1 = fMCEventH->GetNewLabel(label1); | |
499 | tracklets->SetLabel(it,0,label0); | |
500 | tracklets->SetLabel(it,1,label1); | |
501 | } | |
502 | } | |
503 | ||
504 | } | |
505 | ||
9066c676 | 506 | //______________________________________________________________________________ |
5f380da9 | 507 | Bool_t AliAODHandler::FinishEvent() |
ec4af4c1 | 508 | { |
da97a08a | 509 | // Fill data structures |
4e6d5854 | 510 | if(fFillAOD && fFillAODRun && fAODEvent){ |
b8b7dd5c | 511 | fAODEvent->MakeEntriesReferencable(); |
e0107012 | 512 | fTreeA->BranchRef(); |
b8b7dd5c | 513 | FillTree(); |
4e6d5854 | 514 | } |
f133e976 | 515 | |
ca2834f6 | 516 | if ((fFillAOD && fFillAODRun) || fFillExtension) { |
307b6330 | 517 | if (fExtensions && fFillExtension) { |
518 | // fFillExtension can be set by the ESD filter or by a delta filter in case of AOD inputs | |
14d6fad5 | 519 | TIter next(fExtensions); |
520 | AliAODExtension *ext; | |
521 | while ((ext=(AliAODExtension*)next())) ext->FinishEvent(); | |
522 | } | |
307b6330 | 523 | if (fFilters && fFillAOD && fFillAODRun) { |
14d6fad5 | 524 | TIter nextf(fFilters); |
525 | AliAODExtension *ext; | |
526 | while ((ext=(AliAODExtension*)nextf())) { | |
b8b7dd5c | 527 | ext->FinishEvent(); |
14d6fad5 | 528 | } |
529 | } | |
aa399a26 | 530 | } |
14d6fad5 | 531 | |
dddc33c5 | 532 | if (fIsStandard && fAODEvent) |
14d6fad5 | 533 | { |
534 | fAODEvent->ResetStd(); | |
535 | } | |
536 | ||
537 | if (fAODEvent) | |
538 | { | |
539 | TClonesArray *mcarray = static_cast<TClonesArray*>(fAODEvent->FindListObject(AliAODMCParticle::StdBranchName())); | |
ef89f372 | 540 | if(mcarray) mcarray->Delete(); |
541 | ||
14d6fad5 | 542 | AliAODMCHeader *mcHeader = static_cast<AliAODMCHeader*>(fAODEvent->FindListObject(AliAODMCHeader::StdBranchName())); |
ef89f372 | 543 | if(mcHeader) mcHeader->Reset(); |
544 | } | |
14d6fad5 | 545 | |
da97a08a | 546 | // Reset AOD replication flag |
547 | fAODIsReplicated = kFALSE; | |
548 | return kTRUE; | |
ec4af4c1 | 549 | } |
550 | ||
7970f4ac | 551 | //______________________________________________________________________________ |
ec4af4c1 | 552 | Bool_t AliAODHandler::Terminate() |
553 | { | |
9066c676 | 554 | // Terminate |
555 | AddAODtoTreeUserInfo(); | |
14d6fad5 | 556 | |
557 | TIter nextF(fFilters); | |
558 | AliAODExtension *ext; | |
559 | while ((ext=static_cast<AliAODExtension*>(nextF()))) | |
560 | { | |
561 | ext->AddAODtoTreeUserInfo(); | |
562 | } | |
563 | ||
564 | TIter nextE(fExtensions); | |
565 | while ((ext=static_cast<AliAODExtension*>(nextE()))) | |
566 | { | |
567 | ext->AddAODtoTreeUserInfo(); | |
568 | } | |
569 | ||
9066c676 | 570 | return kTRUE; |
ec4af4c1 | 571 | } |
572 | ||
7970f4ac | 573 | //______________________________________________________________________________ |
ec4af4c1 | 574 | Bool_t AliAODHandler::TerminateIO() |
575 | { | |
9066c676 | 576 | // Terminate IO |
577 | if (fFileA) { | |
aa399a26 | 578 | fFileA->Write(); |
9066c676 | 579 | fFileA->Close(); |
580 | delete fFileA; | |
581 | fFileA = 0; | |
48f1c230 | 582 | // When closing the file, the tree is also deleted. |
583 | fTreeA = 0; | |
9066c676 | 584 | } |
14d6fad5 | 585 | |
586 | TIter nextF(fFilters); | |
587 | AliAODExtension *ext; | |
588 | while ((ext=static_cast<AliAODExtension*>(nextF()))) | |
589 | { | |
590 | ext->TerminateIO(); | |
9066c676 | 591 | } |
14d6fad5 | 592 | |
593 | TIter nextE(fExtensions); | |
594 | while ((ext=static_cast<AliAODExtension*>(nextE()))) | |
595 | { | |
596 | ext->TerminateIO(); | |
582cfeb5 | 597 | } |
14d6fad5 | 598 | |
9066c676 | 599 | return kTRUE; |
ec4af4c1 | 600 | } |
601 | ||
7970f4ac | 602 | //______________________________________________________________________________ |
954526ed | 603 | void AliAODHandler::CreateTree(Int_t flag) |
ec4af4c1 | 604 | { |
605 | // Creates the AOD Tree | |
f3214a54 | 606 | fTreeA = new TTree("aodTree", "AliAOD tree"); |
ec4af4c1 | 607 | fTreeA->Branch(fAODEvent->GetList()); |
954526ed | 608 | if (flag == 0) fTreeA->SetDirectory(0); |
4fa36885 | 609 | fMemCountAOD = 0; |
ec4af4c1 | 610 | } |
611 | ||
7970f4ac | 612 | //______________________________________________________________________________ |
ec4af4c1 | 613 | void AliAODHandler::FillTree() |
614 | { | |
866d8d78 | 615 | |
ec4af4c1 | 616 | // Fill the AOD Tree |
4fa36885 | 617 | Long64_t nbf = fTreeA->Fill(); |
618 | if (fTreeBuffSize>0 && fTreeA->GetAutoFlush()<0 && (fMemCountAOD += nbf)>fTreeBuffSize ) { // default limit is still not reached | |
619 | nbf = fTreeA->GetZipBytes(); | |
620 | if (nbf>0) nbf = -nbf; | |
621 | else nbf = fTreeA->GetEntries(); | |
622 | fTreeA->SetAutoFlush(nbf); | |
623 | AliInfo(Form("Calling fTreeA->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld", | |
624 | nbf,fMemCountAOD,fTreeA->GetTotBytes(),fTreeA->GetZipBytes())); | |
625 | } | |
626 | ||
ec4af4c1 | 627 | } |
628 | ||
7970f4ac | 629 | //______________________________________________________________________________ |
ec4af4c1 | 630 | void AliAODHandler::AddAODtoTreeUserInfo() |
631 | { | |
dce1b636 | 632 | // Add aod event to tree user info |
aa399a26 | 633 | if (fTreeA) fTreeA->GetUserInfo()->Add(fAODEvent); |
48f1c230 | 634 | // Now the tree owns our fAODEvent... |
635 | fAODEvent = 0; | |
ec4af4c1 | 636 | } |
490e9023 | 637 | |
7970f4ac | 638 | //______________________________________________________________________________ |
9066c676 | 639 | void AliAODHandler::AddBranch(const char* cname, void* addobj, const char* filename) |
490e9023 | 640 | { |
14d6fad5 | 641 | // Add a new branch to the aod. Added optional filename parameter if the |
642 | // branch should be written to a separate file. | |
643 | ||
644 | if (strlen(filename)) | |
645 | { | |
646 | AliAODExtension *ext = AddExtension(filename); | |
647 | ext->AddBranch(cname, addobj); | |
648 | return; | |
649 | } | |
650 | ||
651 | // Add branch to all filters | |
652 | // Add branch to all filters | |
653 | if (fFilters) { | |
654 | TIter next(fFilters); | |
655 | AliAODExtension *ext; | |
656 | while ((ext=(AliAODExtension*)next())) ext->AddBranch(cname, addobj); | |
657 | } | |
658 | ||
659 | TDirectory *owd = gDirectory; | |
660 | if (fFileA) | |
661 | { | |
662 | fFileA->cd(); | |
663 | } | |
dce1b636 | 664 | |
14d6fad5 | 665 | char** apointer = (char**) addobj; |
666 | TObject* obj = (TObject*) *apointer; | |
667 | ||
668 | fAODEvent->AddObject(obj); | |
669 | ||
670 | const Int_t kSplitlevel = 99; // default value in TTree::Branch() | |
671 | const Int_t kBufsize = 32000; // default value in TTree::Branch() | |
672 | ||
673 | if (!fTreeA->FindBranch(obj->GetName())) | |
674 | { | |
675 | // Do the same as if we book via | |
676 | // TTree::Branch(TCollection*) | |
677 | ||
678 | fTreeA->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj), | |
679 | kBufsize, kSplitlevel - 1); | |
680 | } | |
681 | owd->cd(); | |
490e9023 | 682 | } |
7970f4ac | 683 | |
9066c676 | 684 | //______________________________________________________________________________ |
0c0825e4 | 685 | AliAODExtension *AliAODHandler::AddExtension(const char *filename, const char *title, Bool_t tomerge) |
9066c676 | 686 | { |
14d6fad5 | 687 | // Add an AOD extension with some branches in a different file. |
26ba01d4 | 688 | |
14d6fad5 | 689 | TString fname(filename); |
690 | if (!fname.EndsWith(".root")) fname += ".root"; | |
691 | if (!fExtensions) { | |
692 | fExtensions = new TObjArray(); | |
693 | fExtensions->SetOwner(); | |
694 | } | |
695 | AliAODExtension *ext = (AliAODExtension*)fExtensions->FindObject(fname); | |
696 | if (!ext) { | |
697 | ext = new AliAODExtension(fname, title); | |
698 | fExtensions->Add(ext); | |
699 | } | |
0c0825e4 | 700 | ext->SetToMerge(tomerge); |
14d6fad5 | 701 | return ext; |
9066c676 | 702 | } |
582cfeb5 | 703 | |
704 | //______________________________________________________________________________ | |
705 | AliAODExtension *AliAODHandler::GetExtension(const char *filename) const | |
706 | { | |
14d6fad5 | 707 | // Getter for AOD extensions via file name. |
708 | if (!fExtensions) return NULL; | |
709 | return (AliAODExtension*)fExtensions->FindObject(filename); | |
582cfeb5 | 710 | } |
711 | ||
712 | //______________________________________________________________________________ | |
0c0825e4 | 713 | AliAODExtension *AliAODHandler::AddFilteredAOD(const char *filename, const char *filtername, Bool_t tomerge) |
582cfeb5 | 714 | { |
14d6fad5 | 715 | // Add an AOD extension that can write only AOD events that pass a user filter. |
716 | if (!fFilters) { | |
717 | fFilters = new TObjArray(); | |
718 | fFilters->SetOwner(); | |
719 | } | |
720 | AliAODExtension *filter = (AliAODExtension*)fFilters->FindObject(filename); | |
721 | if (!filter) { | |
722 | filter = new AliAODExtension(filename, filtername, kTRUE); | |
723 | fFilters->Add(filter); | |
724 | } | |
0c0825e4 | 725 | filter->SetToMerge(tomerge); |
14d6fad5 | 726 | return filter; |
582cfeb5 | 727 | } |
728 | ||
729 | //______________________________________________________________________________ | |
730 | AliAODExtension *AliAODHandler::GetFilteredAOD(const char *filename) const | |
731 | { | |
14d6fad5 | 732 | // Getter for AOD filters via file name. |
733 | if (!fFilters) return NULL; | |
734 | return (AliAODExtension*)fFilters->FindObject(filename); | |
582cfeb5 | 735 | } |
14d6fad5 | 736 | |
7970f4ac | 737 | //______________________________________________________________________________ |
738 | void AliAODHandler::SetOutputFileName(const char* fname) | |
739 | { | |
740 | // Set file name. | |
741 | fFileName = fname; | |
742 | } | |
743 | ||
744 | //______________________________________________________________________________ | |
fdbaa4ce | 745 | const char *AliAODHandler::GetOutputFileName() const |
7970f4ac | 746 | { |
747 | // Get file name. | |
748 | return fFileName.Data(); | |
749 | } | |
dce1b636 | 750 | |
90d50a8c | 751 | //______________________________________________________________________________ |
f6eaa73b | 752 | const char *AliAODHandler::GetExtraOutputs(Bool_t merge) const |
90d50a8c | 753 | { |
14d6fad5 | 754 | // Get extra outputs as a string separated by commas. |
755 | static TString eoutputs; | |
756 | eoutputs = ""; | |
0c0825e4 | 757 | AliAODExtension *obj; |
14d6fad5 | 758 | if (fExtensions) { |
759 | TIter next1(fExtensions); | |
0c0825e4 | 760 | while ((obj=(AliAODExtension*)next1())) { |
f6eaa73b | 761 | if (merge && !obj->IsToMerge()) continue; |
14d6fad5 | 762 | if (!eoutputs.IsNull()) eoutputs += ","; |
763 | eoutputs += obj->GetName(); | |
764 | } | |
765 | } | |
766 | if (fFilters) { | |
767 | TIter next2(fFilters); | |
0c0825e4 | 768 | while ((obj=(AliAODExtension*)next2())) { |
f6eaa73b | 769 | if (merge && !obj->IsToMerge()) continue; |
14d6fad5 | 770 | if (!eoutputs.IsNull()) eoutputs += ","; |
771 | eoutputs += obj->GetName(); | |
772 | } | |
773 | } | |
774 | return eoutputs.Data(); | |
775 | } | |
776 | ||
777 | //______________________________________________________________________________ | |
778 | Bool_t AliAODHandler::HasExtensions() const | |
779 | { | |
780 | // Whether or not we manage extensions | |
781 | ||
782 | if ( fExtensions && fExtensions->GetEntries()>0 ) return kTRUE; | |
783 | ||
784 | return kFALSE; | |
90d50a8c | 785 | } |
786 | ||
9066c676 | 787 | //______________________________________________________________________________ |
dce1b636 | 788 | void AliAODHandler::SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader *genHeader){ |
789 | ||
790 | ||
791 | // Utility function to cover different cases for the AliGenEventHeader | |
792 | // Needed since different ProcessType and ImpactParamter are not | |
793 | // in the base class... | |
dce1b636 | 794 | |
dce1b636 | 795 | if(!genHeader)return; |
796 | AliGenPythiaEventHeader *pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader); | |
08078824 | 797 | if (pythiaGenHeader) { |
798 | mcHeader->SetEventType(pythiaGenHeader->ProcessType()); | |
799 | mcHeader->SetPtHard(pythiaGenHeader->GetPtHard()); | |
800 | return; | |
801 | } | |
802 | ||
803 | AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(genHeader); | |
804 | ||
dce1b636 | 805 | if (dpmJetGenHeader){ |
806 | mcHeader->SetEventType(dpmJetGenHeader->ProcessType()); | |
807 | return; | |
808 | } | |
809 | ||
810 | AliGenHijingEventHeader* hijingGenHeader = dynamic_cast<AliGenHijingEventHeader*>(genHeader); | |
811 | if(hijingGenHeader){ | |
812 | mcHeader->SetImpactParameter(hijingGenHeader->ImpactParameter()); | |
813 | return; | |
814 | } | |
815 | ||
08078824 | 816 | // AliWarning(Form("MC Eventheader not known: %s",genHeader->GetName())); |
817 | ||
dce1b636 | 818 | } |
9066c676 | 819 |