]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODInputHandler.cxx
- update handling of arrayDictionary
[u/mrichter/AliRoot.git] / STEER / AliAODInputHandler.cxx
CommitLineData
397596ed 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
3ba74948 23#include <TSystem.h>
933fd60f 24#include <TTree.h>
26772015 25#include <TList.h>
26#include <TNamed.h>
fb0cfe69 27#include <TFile.h>
70908d05 28#include <TH2.h>
397596ed 29
30#include "AliAODInputHandler.h"
31#include "AliAODEvent.h"
70908d05 32#include "AliVCuts.h"
5e6a3170 33#include "AliMCEvent.h"
9006fe9c 34#include "AliAODpidUtil.h"
397596ed 35
36ClassImp(AliAODInputHandler)
37
c2b6979d 38static Option_t *gAODDataType = "AOD";
39
397596ed 40//______________________________________________________________________________
41AliAODInputHandler::AliAODInputHandler() :
90e04a88 42 AliInputEventHandler(),
4195c9c9 43 fEvent(0),
04a79fa0 44 fMCEvent(new AliMCEvent()),
1f842495 45 fFriends(new TList()),
9006fe9c 46 fAODpidUtil(0x0),
1f842495 47 fMergeEvents(kFALSE),
25c90fa8 48 fFriendsConnected(kFALSE),
1f842495 49 fFileToMerge(0),
50 fTreeToMerge(0),
04daa8bf 51 fAODEventToMerge(0),
52 fMergeOffset(0)
397596ed 53{
26772015 54 // Default constructor
70908d05 55 fHistStatistics[0] = fHistStatistics[1] = NULL;
397596ed 56}
57
58//______________________________________________________________________________
26772015 59AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
60 AliInputEventHandler(name, title),
61 fEvent(0),
04a79fa0 62 fMCEvent(new AliMCEvent()),
1f842495 63 fFriends(new TList()),
9006fe9c 64 fAODpidUtil(0x0),
1f842495 65 fMergeEvents(kFALSE),
25c90fa8 66 fFriendsConnected(kFALSE),
1f842495 67 fFileToMerge(0),
68 fTreeToMerge(0),
04daa8bf 69 fAODEventToMerge(0),
70 fMergeOffset(0)
397596ed 71{
26772015 72 // Constructor
70908d05 73 fHistStatistics[0] = fHistStatistics[1] = NULL;
397596ed 74}
75
76//______________________________________________________________________________
26772015 77AliAODInputHandler::~AliAODInputHandler()
397596ed 78{
26772015 79// Destructor
70908d05 80 fFriends->Delete();
81 if (fHistStatistics[0]) {
82 delete fHistStatistics[0];
83 fHistStatistics[0] = 0;
84 }
85 if (fHistStatistics[1]) {
86 delete fHistStatistics[1];
87 fHistStatistics[1] = 0;
88 }
9006fe9c 89 delete fAODpidUtil;
397596ed 90}
91
70908d05 92//______________________________________________________________________________
b890a10d 93Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt)
397596ed 94{
300d5701 95 // Initialisation necessary for each new tree
70908d05 96 fTree = tree;
70908d05 97 if (!fTree) return kFALSE;
32e5a29c 98 fTree->GetEntries();
25c90fa8 99 ConnectFriends();
d329cad3 100
25c90fa8 101 SwitchOffBranches();
102 SwitchOnBranches();
4195c9c9 103
25c90fa8 104 // Get pointer to AOD event
105 if (!fEvent) fEvent = new AliAODEvent();
106
107 fEvent->ReadFromTree(fTree);
108
109 if (fMixingHandler) fMixingHandler->Init(tree, opt);
110
111 return kTRUE;
397596ed 112}
113
70908d05 114//______________________________________________________________________________
1f842495 115Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
fbb264e0 116{
5e6a3170 117 // Begin event
04a79fa0 118 TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
119 if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
04daa8bf 120 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
1f842495 121
0c6c629b 122 fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
b890a10d 123
124 if (fMixingHandler) fMixingHandler->BeginEvent(entry);
0c6c629b 125
fbb264e0 126 return kTRUE;
127}
128
70908d05 129//______________________________________________________________________________
b890a10d 130Bool_t AliAODInputHandler::Notify(const char* path)
131{
132 // Notifaction of directory change
133 if (fMixingHandler) fMixingHandler->Notify(path);
25c90fa8 134 if (!fFriendsConnected) {
135 ConnectFriends();
136 fEvent->ReadFromTree(fTree, "reconnect");
137 }
138 fFriendsConnected = kFALSE;
139
70908d05 140 TTree *ttree = fTree->GetTree();
141 if (!ttree) ttree = fTree;
f4de59f4 142 TString statFname(ttree->GetCurrentFile()->GetName());
143 Int_t indarchive = statFname.Index("#");
144 if (indarchive<0) {
145 statFname = gSystem->DirName(statFname);
146 statFname += "/";
147 } else {
148 statFname.Remove(indarchive+1);
149 }
150 statFname += "EventStat_temp.root";
151 TFile *statFile = 0;
152 if (IsCheckStatistics()) statFile = TFile::Open(statFname, "READ");
70908d05 153 if (statFile) {
154 TList *list = (TList*)statFile->Get("cstatsout");
155 if (list) {
156 AliVCuts *physSel = (AliVCuts*)list->At(0);
157 if (physSel) {
158 TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL"));
159 TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0"));
160 if (fHistStatistics[0] && hAll) {
161 TList tmplist;
162 tmplist.Add(hAll);
163 fHistStatistics[0]->Merge(&tmplist);
164 tmplist.Clear();
165 tmplist.Add(hBin0);
166 if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist);
167 } else {
de73700a 168 if (hAll && hBin0) {
169 fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone());
170 fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone());
171 fHistStatistics[0]->SetDirectory(0);
172 fHistStatistics[1]->SetDirectory(0);
173 }
70908d05 174 }
175 }
3ba74948 176 delete list;
70908d05 177 }
b8047d30 178 delete statFile;
70908d05 179 }
b890a10d 180 return kTRUE;
181}
182
70908d05 183//______________________________________________________________________________
b890a10d 184Bool_t AliAODInputHandler::FinishEvent()
185{
186 // Finish event
187 if (fMixingHandler) fMixingHandler->FinishEvent();
188 return kTRUE;
189}
190
70908d05 191//______________________________________________________________________________
26772015 192void AliAODInputHandler::AddFriend(char* filename)
193{
194 // Add a friend tree
195 TNamed* obj = new TNamed(filename, filename);
196 fFriends->Add(obj);
197}
c2b6979d 198
70908d05 199//______________________________________________________________________________
c2b6979d 200Option_t *AliAODInputHandler::GetDataType() const
201{
202// Returns handled data type.
203 return gAODDataType;
204}
70908d05 205
206//______________________________________________________________________________
207TObject *AliAODInputHandler::GetStatistics(Option_t *option) const
208{
209// Get the statistics histogram(s) from the physics selection object. This
210// should be called during FinishTaskOutput(). Option can be empty (default
211// statistics histogram) or BIN0.
212 TString opt(option);
213 opt.ToUpper();
214 if (opt=="BIN0") return fHistStatistics[1];
215 return fHistStatistics[0];
216}
25c90fa8 217
218void AliAODInputHandler::ConnectFriends()
219{
220 // Connect the friend trees
221 if (!fMergeEvents) {
222 TIter next(fFriends);
223 TNamed* obj;
224 TString aodTreeFName,aodFriendTreeFName;
225 TTree *ttree = fTree->GetTree();
226 if (!ttree) ttree = fTree;
227 aodTreeFName = ttree->GetCurrentFile()->GetName();
228
229 while((obj = (TNamed*)next())) {
230 aodFriendTreeFName = aodTreeFName;
231 aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
232 aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
233 ttree->AddFriend("aodTree", aodFriendTreeFName.Data());
234 }
235 } else {
236 // Friends have to be merged
237 TNamed* filename = (TNamed*) (fFriends->At(0));
238 fFileToMerge = new TFile(filename->GetName());
239 if (fFileToMerge) {
240 fFileToMerge->GetObject("aodTree", fTreeToMerge);
241 if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
242 fAODEventToMerge->ReadFromTree(fTreeToMerge);
243 }
244 }
245 fFriendsConnected = kTRUE;
246}
247
9006fe9c 248//______________________________________________________________________________
249void AliAODInputHandler::CreatePIDResponse(Bool_t isMC/*=kFALSE*/)
250{
251 //
252 // create the pid response object if it does not exist yet
253 //
254 if (fAODpidUtil) return;
255 fAODpidUtil=new AliAODpidUtil(isMC);
256
257}
258