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