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