]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDInputHandler.cxx
Do not reset a zero pointer to MC info
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
CommitLineData
d3dd3d14 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 ESD input
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
933fd60f 23#include <TTree.h>
1aa09fd1 24#include <TChain.h>
25#include <TFile.h>
26#include <TArchiveFile.h>
27#include <TObjArray.h>
28#include <TSystem.h>
300d5701 29#include <TString.h>
30#include <TObjString.h>
80e1b60a 31#include <TProcessID.h>
f0f29480 32#include <TMap.h>
d3dd3d14 33
34#include "AliESDInputHandler.h"
35#include "AliESDEvent.h"
620ad672 36#include "AliESDfriend.h"
b2af62ab 37#include "AliVCuts.h"
d3dd3d14 38#include "AliESD.h"
1aa09fd1 39#include "AliRunTag.h"
40#include "AliEventTag.h"
300d5701 41#include "AliLog.h"
d3dd3d14 42
43ClassImp(AliESDInputHandler)
44
c2b6979d 45static Option_t *gESDDataType = "ESD";
46
d3dd3d14 47//______________________________________________________________________________
6989bff3 48AliESDInputHandler::AliESDInputHandler() :
49 AliInputEventHandler(),
0cd61c1d 50 fEvent(0x0),
620ad672 51 fFriend(0x0),
67675e42 52 fESDpid(0x0),
1aa09fd1 53 fAnalysisType(0),
4d2a7370 54 fNEvents(0),
6ccd727b 55 fHLTEvent(0x0),
56 fHLTTree(0x0),
57 fUseHLT(kFALSE),
f0f29480 58 fTagCutSumm(0x0),
1aa09fd1 59 fUseTags(kFALSE),
60 fChainT(0),
61 fTreeT(0),
98c482f7 62 fRunTag(0),
b626cd71 63 fReadFriends(1),
64 fFriendFileName("AliESDfriends.root")
d3dd3d14 65{
66 // default constructor
67}
68
69//______________________________________________________________________________
70AliESDInputHandler::~AliESDInputHandler()
71{
1aa09fd1 72 // destructor
6989bff3 73 // delete fEvent;
d3dd3d14 74}
75
76//______________________________________________________________________________
77AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
67675e42 78 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
b626cd71 79 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(1), fFriendFileName("AliESDfriends.root")
d3dd3d14 80{
e12e402c 81 // Constructor
d3dd3d14 82}
83
1aa09fd1 84Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
d3dd3d14 85{
300d5701 86 // Initialisation necessary for each new tree
1aa09fd1 87 fAnalysisType = opt;
88 fTree = tree;
300d5701 89
6073f8c9 90 if (!fTree) return kFALSE;
6ccd727b 91 fTree->GetEntry(0);
92
d3dd3d14 93 // Get pointer to ESD event
b760bbe2 94
98c482f7 95 if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
ee7c441c 96 // Try to add ESDfriend. branch as friend
97 TString esdTreeFName, esdFriendTreeFName;
98 TTree* theTree = fTree->GetTree();
99 if (!theTree) theTree = tree;
100 esdTreeFName = (theTree->GetCurrentFile())->GetName();
101 esdFriendTreeFName = esdTreeFName;
b626cd71 102 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
03a8000a 103 theTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
ee7c441c 104 }
105
b481861d 106 SwitchOffBranches();
107 SwitchOnBranches();
108
efea3f54 109 if (!fEvent) fEvent = new AliESDEvent();
60996693 110 fEvent->ReadFromTree(fTree);
4d2a7370 111 fNEvents = fTree->GetEntries();
cd95dd6f 112 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
d3dd3d14 113 return kTRUE;
114}
115
6ccd727b 116Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
d3dd3d14 117{
9b98c4df 118
d3dd3d14 119 // Copy from old to new format if necessary
d7749dec 120 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
121 if (old) {
d3dd3d14 122 ((AliESDEvent*)fEvent)->CopyFromOldESD();
123 old->Reset();
d7749dec 124 }
6ccd727b 125
126 if (fHLTTree) {
127 fHLTTree->GetEntry(entry);
128 }
129
f0ee78b0 130 fNewEvent = kTRUE;
b2af62ab 131 //
132 // Event selection
133 //
134 if (fEventCuts)
9b98c4df 135 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
620ad672 136 //
137 // Friends
138 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
139
d7749dec 140 return kTRUE;
d3dd3d14 141}
142
e12e402c 143Bool_t AliESDInputHandler::FinishEvent()
144{
145 // Finish the event
146 if(fEvent)fEvent->Reset();
147 return kTRUE;
6989bff3 148}
149
1aa09fd1 150Bool_t AliESDInputHandler::Notify(const char* path)
151{
152 // Notify a directory change
a5112f7d 153 AliInfo(Form("Directory change %s \n", path));
154 //
50aaaf00 155 if (fUseHLT) {
156 // Get HLTesdTree from current file
157 TTree* cTree = fTree;
158 if (fTree->GetTree()) cTree = fTree->GetTree();
159 TFile* cFile = cTree->GetCurrentFile();
160 cFile->GetObject("HLTesdTree", fHLTTree);
161
162 if (fHLTTree) {
163 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
164 fHLTEvent->ReadFromTree(fHLTTree);
165 }
166 }
167
1aa09fd1 168 if (!fUseTags) return (kTRUE);
169
170 Bool_t zip = kFALSE;
171
172 TString fileName(path);
173 if(fileName.Contains("#AliESDs.root")){
1aa09fd1 174 zip = kTRUE;
175 }
176 else if (fileName.Contains("AliESDs.root")){
177 fileName.ReplaceAll("AliESDs.root", "");
178 }
179 else if(fileName.Contains("#AliAOD.root")){
1aa09fd1 180 zip = kTRUE;
181 }
182 else if(fileName.Contains("AliAOD.root")){
183 fileName.ReplaceAll("AliAOD.root", "");
184 }
185 else if(fileName.Contains("#galice.root")){
186 // For running with galice and kinematics alone...
1aa09fd1 187 zip = kTRUE;
188 }
189 else if(fileName.Contains("galice.root")){
190 // For running with galice and kinematics alone...
191 fileName.ReplaceAll("galice.root", "");
192 }
193
1aa09fd1 194
be4763e2 195 TString pathName("./");
196 if (fileName.Length() != 0) {
197 pathName = fileName;
198 }
199
200 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
6ccd727b 201
1aa09fd1 202 if (fRunTag) {
203 fRunTag->Clear();
204 } else {
205 fRunTag = new AliRunTag();
206 }
207
208 delete fTreeT; fTreeT = 0;
6ccd727b 209
1aa09fd1 210 if (fChainT) {
211 delete fChainT;
212 fChainT = 0;
213 }
214
215 if (!fChainT) {
216 fChainT = new TChain("T");
217 }
218
219
220
221 const char* tagPattern = "ESD.tag.root";
222 const char* name = 0x0;
223 TString tagFilename;
224 if (zip) {
8ac5c1d7 225 TFile* file = fTree->GetCurrentFile();
1aa09fd1 226 TArchiveFile* arch = file->GetArchive();
227 TObjArray* arr = arch->GetMembers();
228 TIter next(arr);
229
7cec0871 230 while ((file = (TFile*) next())) {
1aa09fd1 231 name = file->GetName();
232 if (strstr(name,tagPattern)) {
be4763e2 233 tagFilename = pathName.Data();
1aa09fd1 234 tagFilename += "#";
235 tagFilename += name;
236 fChainT->Add(tagFilename);
237 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
238 }//pattern check
239 } // archive file loop
240 } else {
be4763e2 241 void * dirp = gSystem->OpenDirectory(pathName.Data());
1aa09fd1 242 while((name = gSystem->GetDirEntry(dirp))) {
243 if (strstr(name,tagPattern)) {
be4763e2 244 tagFilename = pathName.Data();
1aa09fd1 245 tagFilename += "/";
246 tagFilename += name;
247 fChainT->Add(tagFilename);
248 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
249 }//pattern check
250 }//directory loop
251 }
252 fChainT->SetBranchAddress("AliTAG",&fRunTag);
253 fChainT->GetEntry(0);
254 return kTRUE;
255}
256
257
c2b6979d 258
259Option_t *AliESDInputHandler::GetDataType() const
260{
261// Returns handled data type.
262 return gESDDataType;
263}
f0f29480 264
265Int_t AliESDInputHandler::GetNEventAcceptedInFile()
266{
267 // Get number of events in file accepted by the tag cuts
268 // return -1 if no info is available
269 if (!fTagCutSumm) {
270 TList *luo = fTree->GetUserInfo();
271 if (!luo) {
272 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
273 return -1;
274 }
275 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
276 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
277 if (fTagCutSumm) break;
278 }
279 if (!fTagCutSumm) {
280 AliInfo(Form("No tag summary map in input tree\n"));
281 return -1;
282 }
283 }
284
285 TObjString *ostr = 0;
286 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
287 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
288 else {
289 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
290 return -1;
291 }
292 char *iTagInfo;
293 iTagInfo = strdup(ostr->GetString().Data());
294
295 Int_t iAcc = atoi(strtok(iTagInfo, ","));
296
297 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
298
299 free(iTagInfo);
300
301 return iAcc;
302}
303Int_t AliESDInputHandler::GetNEventRejectedInFile()
304{
305 // Get number of events in file rejected by the tag cuts
306 // return -1 if no info is available
307 if (!fTagCutSumm) {
308 TList *luo = fTree->GetUserInfo();
309 if (!luo) {
310 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
311 return -1;
312 }
313 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
314 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
315 if (fTagCutSumm) break;
316 }
317 if (!fTagCutSumm) {
318 AliInfo(Form("No tag summary map in input tree\n"));
319 return -1;
320 }
321 }
322
323 TObjString *ostr = 0;
324 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
325 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
326 else {
327 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
328 return -1;
329 }
330 char *iTagInfo;
331 iTagInfo = strdup(ostr->GetString().Data());
332
333 strtok(iTagInfo, ",");
334 Int_t iRej = atoi(strtok(NULL, ","));
335
336 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
337
338 free(iTagInfo);
339
340 return iRej;
341}
c334d0d3 342Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
343{
344 // Get number of events in the full chain
345 // Count accepted and rejected events
346 // return kFALSE if no info is available
347 if (!fTagCutSumm) {
348 TList *luo = fTree->GetUserInfo();
349 if (!luo) {
350 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
351 return kFALSE;
352 }
353 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
354 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
355 if (fTagCutSumm) break;
356 }
357 if (!fTagCutSumm) {
358 AliInfo(Form("No tag summary map in input tree\n"));
359 return kFALSE;
360 }
361 }
362
363 TMapIter *tIter = new TMapIter(fTagCutSumm);
364
365 Int_t iTotList=0, iAccList=0, iRejList=0;
366
367 TObject *cobj;
9a587f77 368 while ((cobj = tIter->Next())) {
c334d0d3 369 TObjString *kstr = (TObjString *) cobj;
370 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
371 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
372 char *iTagInfo;
373 iTagInfo = strdup(vstr->GetString().Data());
374
375 Int_t iAcc = atoi(strtok(iTagInfo, ","));
376 Int_t iRej = atoi(strtok(NULL, ","));
377
378 iAccList += iAcc;
379 iRejList += iRej;
380 iTotList += (iAcc+iRej);
381 }
382
383 *aTotal = iTotList;
384 *aAccepted = iAccList;
385 *aRejected = iRejList;
386
387 return kTRUE;
388}
389
390Int_t AliESDInputHandler::GetNFilesEmpty()
391{
392 // Count number of files in which all events were de-selected
393 // For such files Notify() will NOT be called
394 // return -1 if no info is available
395 if (!fTagCutSumm) {
396 TList *luo = fTree->GetUserInfo();
397 if (!luo) {
398 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
399 return -1;
400 }
401 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
402 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
403 if (fTagCutSumm) break;
404 }
405 if (!fTagCutSumm) {
406 AliInfo(Form("No tag summary map in input tree\n"));
407 return -1;
408 }
409 }
410
411 TMapIter *tIter = new TMapIter(fTagCutSumm);
412
413 Int_t iFilesEmpty = 0;
414
415 TObject *cobj;
9a587f77 416 while ((cobj = tIter->Next())) {
c334d0d3 417 TObjString *kstr = (TObjString *) cobj;
418 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
419 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
420 char *iTagInfo;
421 iTagInfo = strdup(vstr->GetString().Data());
422
423 Int_t iAcc = atoi(strtok(iTagInfo, ","));
424 Int_t iRej = atoi(strtok(NULL, ","));
425
426 if ((iAcc == 0) && ((iRej+iAcc)>0))
427 iFilesEmpty++;
428 }
429
430 return iFilesEmpty;
431
432}