]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODInputHandler.cxx
Adding the individual channel mult in order to be used in the event plane calculation.
[u/mrichter/AliRoot.git] / STEER / AliAODInputHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     Event handler for AOD input 
20 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TSystem.h>
24 #include <TTree.h>
25 #include <TList.h>
26 #include <TNamed.h>
27 #include <TFile.h>
28 #include <TH2.h>
29
30 #include "AliAODInputHandler.h"
31 #include "AliAODEvent.h"
32 #include "AliVCuts.h"
33
34 ClassImp(AliAODInputHandler)
35
36 static Option_t *gAODDataType = "AOD";
37
38 //______________________________________________________________________________
39 AliAODInputHandler::AliAODInputHandler() :
40     AliInputEventHandler(),
41     fEvent(0),
42     fMCEvent(new AliMCEvent()),
43     fFriends(new TList()),
44     fMergeEvents(kFALSE),
45     fFileToMerge(0),
46     fTreeToMerge(0),
47     fAODEventToMerge(0),
48     fMergeOffset(0)
49 {
50   // Default constructor
51   fHistStatistics[0] = fHistStatistics[1] = NULL;
52 }
53
54 //______________________________________________________________________________
55 AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
56   AliInputEventHandler(name, title),
57   fEvent(0),
58   fMCEvent(new AliMCEvent()),
59   fFriends(new TList()),
60   fMergeEvents(kFALSE),
61   fFileToMerge(0),
62   fTreeToMerge(0),
63   fAODEventToMerge(0),
64   fMergeOffset(0)
65 {
66     // Constructor
67   fHistStatistics[0] = fHistStatistics[1] = NULL;
68 }
69
70 //______________________________________________________________________________
71 AliAODInputHandler::~AliAODInputHandler() 
72 {
73 // Destructor
74   fFriends->Delete();
75   if (fHistStatistics[0]) {
76     delete fHistStatistics[0];
77     fHistStatistics[0] = 0;
78   }
79   if (fHistStatistics[1]) {
80     delete fHistStatistics[1];
81     fHistStatistics[1] = 0;
82   }
83 }
84
85 //______________________________________________________________________________
86 Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt)
87 {
88     // Initialisation necessary for each new tree
89   if (!fMergeEvents) {
90     fTree = tree;
91     TIter next(fFriends);
92     TNamed* obj;
93         
94     if (!fTree) return kFALSE;
95     fTree->GetEntries();
96 //    fTree->GetEntry(0);
97     TString aodTreeFName,aodFriendTreeFName;
98     TTree *ttree = fTree->GetTree();
99     if (!ttree) ttree = fTree;
100     aodTreeFName = ttree->GetCurrentFile()->GetName();
101
102     while((obj = (TNamed*)next())) {
103       aodFriendTreeFName = aodTreeFName;
104       aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
105       aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
106       ttree->AddFriend("aodTree", aodFriendTreeFName.Data());
107     }
108   } else {
109   // Friends have to be merged
110     TNamed* filename = (TNamed*) (fFriends->At(0));
111     fFileToMerge = new TFile(filename->GetName());
112          if (fFileToMerge) {
113       fFileToMerge->GetObject("aodTree", fTreeToMerge);
114            if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
115            fAODEventToMerge->ReadFromTree(fTreeToMerge);
116     }
117   }
118
119   SwitchOffBranches();
120   SwitchOnBranches();
121     
122   // Get pointer to AOD event
123   if (!fEvent) fEvent = new AliAODEvent();
124
125   fEvent->ReadFromTree(fTree);
126   
127   if (fMixingHandler) fMixingHandler->Init(tree, opt);
128
129   return kTRUE;
130 }
131
132 //______________________________________________________________________________
133 Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
134 {
135     //
136     TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
137     if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
138     if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
139     
140     fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
141
142     if (fMixingHandler) fMixingHandler->BeginEvent(entry);
143     
144     return kTRUE;
145 }
146
147 //______________________________________________________________________________
148 Bool_t AliAODInputHandler::Notify(const char* path)
149 {
150   // Notifaction of directory change
151   if (fMixingHandler) fMixingHandler->Notify(path);
152   TTree *ttree = fTree->GetTree();
153   if (!ttree) ttree = fTree;
154   TString statFname(gSystem->DirName(ttree->GetCurrentFile()->GetName()));
155   statFname += "/EventStat_temp.root";
156   TFile *statFile = TFile::Open(statFname, "READ");
157   if (statFile) {
158      TList *list = (TList*)statFile->Get("cstatsout");
159      if (list) {
160         AliVCuts *physSel = (AliVCuts*)list->At(0);
161         if (physSel) {
162            TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL"));
163            TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0"));
164            if (fHistStatistics[0] && hAll) {
165               TList tmplist;
166               tmplist.Add(hAll);
167               fHistStatistics[0]->Merge(&tmplist);
168               tmplist.Clear();
169               tmplist.Add(hBin0);
170               if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist);
171            } else {
172              fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone());
173              fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone());
174              fHistStatistics[0]->SetDirectory(0);
175              fHistStatistics[1]->SetDirectory(0);
176            }   
177         }
178         delete list;
179      }
180      delete statFile;
181   }
182   return kTRUE;
183 }
184
185 //______________________________________________________________________________
186 Bool_t AliAODInputHandler::FinishEvent()
187 {
188   // Finish event
189   if (fMixingHandler) fMixingHandler->FinishEvent();
190   return kTRUE;
191 }
192
193 //______________________________________________________________________________
194 void AliAODInputHandler::AddFriend(char* filename)
195 {
196     // Add a friend tree 
197     TNamed* obj = new TNamed(filename, filename);
198     fFriends->Add(obj);
199 }
200
201 //______________________________________________________________________________
202 Option_t *AliAODInputHandler::GetDataType() const
203 {
204 // Returns handled data type.
205    return gAODDataType;
206 }
207
208 //______________________________________________________________________________
209 TObject *AliAODInputHandler::GetStatistics(Option_t *option) const
210 {
211 // Get the statistics histogram(s) from the physics selection object. This
212 // should be called during FinishTaskOutput(). Option can be empty (default
213 // statistics histogram) or BIN0.
214    TString opt(option);
215    opt.ToUpper();
216    if (opt=="BIN0") return fHistStatistics[1];
217    return fHistStatistics[0];
218 }