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