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