]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODInputHandler.cxx
Simple class to export/import data in the HEP data format (import very limited in...
[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),
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);
04daa8bf 130 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
1f842495 131
0c6c629b 132 fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
b890a10d 133
134 if (fMixingHandler) fMixingHandler->BeginEvent(entry);
0c6c629b 135
fbb264e0 136 return kTRUE;
137}
138
70908d05 139//______________________________________________________________________________
b890a10d 140Bool_t AliAODInputHandler::Notify(const char* path)
141{
142 // Notifaction of directory change
143 if (fMixingHandler) fMixingHandler->Notify(path);
25c90fa8 144 if (!fFriendsConnected) {
145 ConnectFriends();
146 fEvent->ReadFromTree(fTree, "reconnect");
147 }
148 fFriendsConnected = kFALSE;
149
70908d05 150 TTree *ttree = fTree->GetTree();
151 if (!ttree) ttree = fTree;
f4de59f4 152 TString statFname(ttree->GetCurrentFile()->GetName());
153 Int_t indarchive = statFname.Index("#");
154 if (indarchive<0) {
155 statFname = gSystem->DirName(statFname);
156 statFname += "/";
157 } else {
158 statFname.Remove(indarchive+1);
159 }
160 statFname += "EventStat_temp.root";
161 TFile *statFile = 0;
162 if (IsCheckStatistics()) statFile = TFile::Open(statFname, "READ");
70908d05 163 if (statFile) {
164 TList *list = (TList*)statFile->Get("cstatsout");
165 if (list) {
166 AliVCuts *physSel = (AliVCuts*)list->At(0);
167 if (physSel) {
168 TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL"));
169 TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0"));
170 if (fHistStatistics[0] && hAll) {
171 TList tmplist;
172 tmplist.Add(hAll);
173 fHistStatistics[0]->Merge(&tmplist);
174 tmplist.Clear();
175 tmplist.Add(hBin0);
176 if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist);
177 } else {
de73700a 178 if (hAll && hBin0) {
179 fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone());
180 fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone());
181 fHistStatistics[0]->SetDirectory(0);
182 fHistStatistics[1]->SetDirectory(0);
183 }
70908d05 184 }
185 }
3ba74948 186 delete list;
70908d05 187 }
b8047d30 188 delete statFile;
70908d05 189 }
b890a10d 190 return kTRUE;
191}
192
70908d05 193//______________________________________________________________________________
b890a10d 194Bool_t AliAODInputHandler::FinishEvent()
195{
196 // Finish event
197 if (fMixingHandler) fMixingHandler->FinishEvent();
198 return kTRUE;
199}
200
70908d05 201//______________________________________________________________________________
26772015 202void AliAODInputHandler::AddFriend(char* filename)
203{
204 // Add a friend tree
205 TNamed* obj = new TNamed(filename, filename);
206 fFriends->Add(obj);
207}
c2b6979d 208
70908d05 209//______________________________________________________________________________
c2b6979d 210Option_t *AliAODInputHandler::GetDataType() const
211{
212// Returns handled data type.
213 return gAODDataType;
214}
70908d05 215
216//______________________________________________________________________________
217TObject *AliAODInputHandler::GetStatistics(Option_t *option) const
218{
219// Get the statistics histogram(s) from the physics selection object. This
220// should be called during FinishTaskOutput(). Option can be empty (default
221// statistics histogram) or BIN0.
222 TString opt(option);
223 opt.ToUpper();
224 if (opt=="BIN0") return fHistStatistics[1];
225 return fHistStatistics[0];
226}
25c90fa8 227
228void AliAODInputHandler::ConnectFriends()
229{
230 // Connect the friend trees
231 if (!fMergeEvents) {
232 TIter next(fFriends);
233 TNamed* obj;
234 TString aodTreeFName,aodFriendTreeFName;
235 TTree *ttree = fTree->GetTree();
236 if (!ttree) ttree = fTree;
237 aodTreeFName = ttree->GetCurrentFile()->GetName();
238
239 while((obj = (TNamed*)next())) {
240 aodFriendTreeFName = aodTreeFName;
241 aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
242 aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
243 ttree->AddFriend("aodTree", aodFriendTreeFName.Data());
244 }
245 } else {
246 // Friends have to be merged
247 TNamed* filename = (TNamed*) (fFriends->At(0));
248 fFileToMerge = new TFile(filename->GetName());
249 if (fFileToMerge) {
250 fFileToMerge->GetObject("aodTree", fTreeToMerge);
251 if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
252 fAODEventToMerge->ReadFromTree(fTreeToMerge);
253 }
254 }
255 fFriendsConnected = kTRUE;
256}
257
9006fe9c 258//______________________________________________________________________________
259void AliAODInputHandler::CreatePIDResponse(Bool_t isMC/*=kFALSE*/)
260{
261 //
262 // create the pid response object if it does not exist yet
263 //
264 if (fAODpidUtil) return;
265 fAODpidUtil=new AliAODpidUtil(isMC);
266
267}
268