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