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