]>
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" |
397596ed | 35 | |
36 | ClassImp(AliAODInputHandler) | |
37 | ||
c2b6979d | 38 | static Option_t *gAODDataType = "AOD"; |
39 | ||
397596ed | 40 | //______________________________________________________________________________ |
41 | AliAODInputHandler::AliAODInputHandler() : | |
90e04a88 | 42 | AliInputEventHandler(), |
4195c9c9 | 43 | fEvent(0), |
8bf273e1 | 44 | fMCEvent(0), |
45 | fFriends(0), | |
9006fe9c | 46 | fAODpidUtil(0x0), |
1f842495 | 47 | fMergeEvents(kFALSE), |
abf59beb | 48 | fMergeTracks(kTRUE), |
49 | fMergeEMCALClusters(kTRUE), | |
50 | fMergePHOSClusters(kTRUE), | |
51 | fMergeEMCALCells(kTRUE), | |
720f7306 | 52 | fMergePHOSCells(kTRUE), |
53 | fMergeEMCALTrigger(kTRUE), | |
54 | fMergePHOSTrigger(kTRUE), | |
25c90fa8 | 55 | fFriendsConnected(kFALSE), |
1f842495 | 56 | fFileToMerge(0), |
57 | fTreeToMerge(0), | |
04daa8bf | 58 | fAODEventToMerge(0), |
59 | fMergeOffset(0) | |
397596ed | 60 | { |
26772015 | 61 | // Default constructor |
70908d05 | 62 | fHistStatistics[0] = fHistStatistics[1] = NULL; |
397596ed | 63 | } |
64 | ||
65 | //______________________________________________________________________________ | |
26772015 | 66 | AliAODInputHandler::AliAODInputHandler(const char* name, const char* title): |
67 | AliInputEventHandler(name, title), | |
68 | fEvent(0), | |
04a79fa0 | 69 | fMCEvent(new AliMCEvent()), |
1f842495 | 70 | fFriends(new TList()), |
9006fe9c | 71 | fAODpidUtil(0x0), |
1f842495 | 72 | fMergeEvents(kFALSE), |
abf59beb | 73 | fMergeTracks(kTRUE), |
74 | fMergeEMCALClusters(kTRUE), | |
75 | fMergePHOSClusters(kTRUE), | |
76 | fMergeEMCALCells(kTRUE), | |
77 | fMergePHOSCells(kTRUE), | |
720f7306 | 78 | fMergeEMCALTrigger(kTRUE), |
79 | fMergePHOSTrigger(kTRUE), | |
25c90fa8 | 80 | fFriendsConnected(kFALSE), |
1f842495 | 81 | fFileToMerge(0), |
82 | fTreeToMerge(0), | |
04daa8bf | 83 | fAODEventToMerge(0), |
84 | fMergeOffset(0) | |
397596ed | 85 | { |
26772015 | 86 | // Constructor |
70908d05 | 87 | fHistStatistics[0] = fHistStatistics[1] = NULL; |
397596ed | 88 | } |
89 | ||
90 | //______________________________________________________________________________ | |
26772015 | 91 | AliAODInputHandler::~AliAODInputHandler() |
397596ed | 92 | { |
26772015 | 93 | // Destructor |
70908d05 | 94 | fFriends->Delete(); |
d697d7a2 | 95 | delete fHistStatistics[0]; |
96 | delete fHistStatistics[1]; | |
9006fe9c | 97 | delete fAODpidUtil; |
397596ed | 98 | } |
99 | ||
70908d05 | 100 | //______________________________________________________________________________ |
b890a10d | 101 | Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt) |
397596ed | 102 | { |
300d5701 | 103 | // Initialisation necessary for each new tree |
70908d05 | 104 | fTree = tree; |
70908d05 | 105 | if (!fTree) return kFALSE; |
32e5a29c | 106 | fTree->GetEntries(); |
25c90fa8 | 107 | ConnectFriends(); |
d329cad3 | 108 | |
25c90fa8 | 109 | SwitchOffBranches(); |
110 | SwitchOnBranches(); | |
4195c9c9 | 111 | |
25c90fa8 | 112 | // Get pointer to AOD event |
113 | if (!fEvent) fEvent = new AliAODEvent(); | |
114 | ||
115 | fEvent->ReadFromTree(fTree); | |
116 | ||
117 | if (fMixingHandler) fMixingHandler->Init(tree, opt); | |
118 | ||
119 | return kTRUE; | |
397596ed | 120 | } |
121 | ||
70908d05 | 122 | //______________________________________________________________________________ |
1f842495 | 123 | Bool_t AliAODInputHandler::BeginEvent(Long64_t entry) |
fbb264e0 | 124 | { |
5e6a3170 | 125 | // Begin event |
04a79fa0 | 126 | TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles")); |
127 | if (mcParticles) fMCEvent->SetParticleArray(mcParticles); | |
3a50455f | 128 | |
129 | // When merging, get current event number from GetReadEntry(), | |
130 | // entry gives the events in the current file | |
131 | if (fTreeToMerge) fTreeToMerge->GetEntry(GetReadEntry() + fMergeOffset); | |
132 | ||
0c6c629b | 133 | fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger(); |
b890a10d | 134 | |
135 | if (fMixingHandler) fMixingHandler->BeginEvent(entry); | |
0c6c629b | 136 | |
fbb264e0 | 137 | return kTRUE; |
138 | } | |
139 | ||
70908d05 | 140 | //______________________________________________________________________________ |
b890a10d | 141 | Bool_t AliAODInputHandler::Notify(const char* path) |
142 | { | |
143 | // Notifaction of directory change | |
144 | if (fMixingHandler) fMixingHandler->Notify(path); | |
25c90fa8 | 145 | if (!fFriendsConnected) { |
146 | ConnectFriends(); | |
147 | fEvent->ReadFromTree(fTree, "reconnect"); | |
148 | } | |
149 | fFriendsConnected = kFALSE; | |
150 | ||
70908d05 | 151 | TTree *ttree = fTree->GetTree(); |
152 | if (!ttree) ttree = fTree; | |
f4de59f4 | 153 | TString statFname(ttree->GetCurrentFile()->GetName()); |
1c446360 | 154 | AliInfo(Form("Moving to file %s", statFname.Data())); |
f4de59f4 | 155 | Int_t indarchive = statFname.Index("#"); |
156 | if (indarchive<0) { | |
157 | statFname = gSystem->DirName(statFname); | |
158 | statFname += "/"; | |
159 | } else { | |
160 | statFname.Remove(indarchive+1); | |
161 | } | |
162 | statFname += "EventStat_temp.root"; | |
163 | TFile *statFile = 0; | |
164 | if (IsCheckStatistics()) statFile = TFile::Open(statFname, "READ"); | |
70908d05 | 165 | if (statFile) { |
166 | TList *list = (TList*)statFile->Get("cstatsout"); | |
167 | if (list) { | |
168 | AliVCuts *physSel = (AliVCuts*)list->At(0); | |
169 | if (physSel) { | |
170 | TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL")); | |
171 | TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0")); | |
172 | if (fHistStatistics[0] && hAll) { | |
173 | TList tmplist; | |
174 | tmplist.Add(hAll); | |
175 | fHistStatistics[0]->Merge(&tmplist); | |
176 | tmplist.Clear(); | |
177 | tmplist.Add(hBin0); | |
178 | if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist); | |
179 | } else { | |
de73700a | 180 | if (hAll && hBin0) { |
181 | fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone()); | |
182 | fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone()); | |
183 | fHistStatistics[0]->SetDirectory(0); | |
184 | fHistStatistics[1]->SetDirectory(0); | |
185 | } | |
70908d05 | 186 | } |
187 | } | |
3ba74948 | 188 | delete list; |
70908d05 | 189 | } |
b8047d30 | 190 | delete statFile; |
70908d05 | 191 | } |
b890a10d | 192 | return kTRUE; |
193 | } | |
194 | ||
70908d05 | 195 | //______________________________________________________________________________ |
b890a10d | 196 | Bool_t AliAODInputHandler::FinishEvent() |
197 | { | |
198 | // Finish event | |
199 | if (fMixingHandler) fMixingHandler->FinishEvent(); | |
483ad248 | 200 | if (fEvent) fEvent->Reset(); |
b890a10d | 201 | return kTRUE; |
202 | } | |
203 | ||
70908d05 | 204 | //______________________________________________________________________________ |
26772015 | 205 | void 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 | 213 | Option_t *AliAODInputHandler::GetDataType() const |
214 | { | |
215 | // Returns handled data type. | |
216 | return gAODDataType; | |
217 | } | |
70908d05 | 218 | |
219 | //______________________________________________________________________________ | |
220 | TObject *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 | |
231 | void 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 | //______________________________________________________________________________ |
262 | void 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 |