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