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