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