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