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