1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Event handler for ESD input
20 // Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
26 #include <TArchiveFile.h>
27 #include <TObjArray.h>
30 #include <TObjString.h>
31 #include <TProcessID.h>
34 #include "AliESDInputHandler.h"
35 #include "AliESDEvent.h"
36 #include "AliESDfriend.h"
39 #include "AliRunTag.h"
40 #include "AliEventTag.h"
43 ClassImp(AliESDInputHandler)
45 static Option_t *gESDDataType = "ESD";
47 //______________________________________________________________________________
48 AliESDInputHandler::AliESDInputHandler() :
49 AliInputEventHandler(),
64 fFriendFileName("AliESDfriends.root")
66 // default constructor
69 //______________________________________________________________________________
70 AliESDInputHandler::~AliESDInputHandler()
75 //______________________________________________________________________________
76 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
77 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
78 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(0), fFriendFileName("AliESDfriends.root")
83 //______________________________________________________________________________
84 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
87 // Initialisation necessary for each new tree
92 if (!fTree) return kFALSE;
96 if (!fEvent) fEvent = new AliESDEvent();
97 fEvent->ReadFromTree(fTree);
98 fNEvents = fTree->GetEntries();
100 if (fMixingHandler) fMixingHandler->Init(tree, opt);
105 //______________________________________________________________________________
106 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
109 // Copy from old to new format if necessary
110 static Bool_t called = kFALSE;
111 if (!called && fEventCuts && IsUserCallSelectionMask())
112 AliInfo(Form("The ESD input handler expects that the first task calls AliESDInputHandler::CheckSelectionMask() %s", fEventCuts->ClassName()));
113 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
115 ((AliESDEvent*)fEvent)->CopyFromOldESD();
120 fHLTTree->GetEntry(entry);
127 fIsSelectedResult = 0;
128 if (fEventCuts && !IsUserCallSelectionMask())
129 fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
132 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
135 if (fMixingHandler) fMixingHandler->BeginEvent(entry);
140 //______________________________________________________________________________
141 void AliESDInputHandler::CheckSelectionMask()
143 // This method can be called by a task only if IsUserCallSelectionMask is true.
144 if (!fEventCuts || !IsUserCallSelectionMask()) return;
145 fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
148 //______________________________________________________________________________
149 Bool_t AliESDInputHandler::FinishEvent()
152 if(fEvent)fEvent->Reset();
153 if (fMixingHandler) fMixingHandler->FinishEvent();
157 //______________________________________________________________________________
158 Bool_t AliESDInputHandler::Notify(const char* path)
160 // Notify a directory change
161 AliInfo(Form("Directory change %s \n", path));
163 // Handle the friends first
165 if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
166 // Try to add ESDfriend. branch as friend
167 TString esdTreeFName, esdFriendTreeFName;
168 esdTreeFName = (fTree->GetCurrentFile())->GetName();
169 esdFriendTreeFName = esdTreeFName;
170 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
171 TTree* cTree = fTree->GetTree();
172 if (!cTree) cTree = fTree;
173 cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
174 cTree->SetBranchStatus("ESDfriend.", 1);
175 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
176 if (fFriend) cTree->SetBranchAddress("ESDfriend.", &fFriend);
182 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
185 // Get HLTesdTree from current file
186 TTree* cTree = fTree;
187 if (fTree->GetTree()) cTree = fTree->GetTree();
188 TFile* cFile = cTree->GetCurrentFile();
189 cFile->GetObject("HLTesdTree", fHLTTree);
192 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
193 fHLTEvent->ReadFromTree(fHLTTree);
198 if (fMixingHandler) fMixingHandler->Notify(path);
204 TString fileName(path);
205 if(fileName.Contains("#AliESDs.root")){
208 else if (fileName.Contains("AliESDs.root")){
209 fileName.ReplaceAll("AliESDs.root", "");
211 else if(fileName.Contains("#AliAOD.root")){
214 else if(fileName.Contains("AliAOD.root")){
215 fileName.ReplaceAll("AliAOD.root", "");
217 else if(fileName.Contains("#galice.root")){
218 // For running with galice and kinematics alone...
221 else if(fileName.Contains("galice.root")){
222 // For running with galice and kinematics alone...
223 fileName.ReplaceAll("galice.root", "");
227 TString pathName("./");
228 if (fileName.Length() != 0) {
232 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
237 fRunTag = new AliRunTag();
240 delete fTreeT; fTreeT = 0;
248 fChainT = new TChain("T");
253 const char* tagPattern = "ESD.tag.root";
254 const char* name = 0x0;
257 TFile* file = fTree->GetCurrentFile();
258 TArchiveFile* arch = file->GetArchive();
259 TObjArray* arr = arch->GetMembers();
262 while ((file = (TFile*) next())) {
263 name = file->GetName();
264 if (strstr(name,tagPattern)) {
265 tagFilename = pathName.Data();
268 fChainT->Add(tagFilename);
269 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
271 } // archive file loop
273 void * dirp = gSystem->OpenDirectory(pathName.Data());
274 while((name = gSystem->GetDirEntry(dirp))) {
275 if (strstr(name,tagPattern)) {
276 tagFilename = pathName.Data();
279 fChainT->Add(tagFilename);
280 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
284 fChainT->SetBranchAddress("AliTAG",&fRunTag);
285 fChainT->GetEntry(0);
287 if (fMixingHandler) fMixingHandler->Notify(path);
292 //______________________________________________________________________________
293 Option_t *AliESDInputHandler::GetDataType() const
295 // Returns handled data type.
299 //______________________________________________________________________________
300 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
302 // Get number of events in file accepted by the tag cuts
303 // return -1 if no info is available
305 TList *luo = fTree->GetUserInfo();
307 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
310 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
311 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
312 if (fTagCutSumm) break;
315 AliInfo(Form("No tag summary map in input tree\n"));
320 TObjString *ostr = 0;
321 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
322 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
324 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
328 iTagInfo = strdup(ostr->GetString().Data());
330 Int_t iAcc = atoi(strtok(iTagInfo, ","));
332 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
339 //______________________________________________________________________________
340 Int_t AliESDInputHandler::GetNEventRejectedInFile()
342 // Get number of events in file rejected by the tag cuts
343 // return -1 if no info is available
345 TList *luo = fTree->GetUserInfo();
347 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
350 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
351 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
352 if (fTagCutSumm) break;
355 AliInfo(Form("No tag summary map in input tree\n"));
360 TObjString *ostr = 0;
361 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
362 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
364 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
368 iTagInfo = strdup(ostr->GetString().Data());
370 strtok(iTagInfo, ",");
371 Int_t iRej = atoi(strtok(NULL, ","));
373 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
380 //______________________________________________________________________________
381 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
383 // Get number of events in the full chain
384 // Count accepted and rejected events
385 // return kFALSE if no info is available
387 TList *luo = fTree->GetUserInfo();
389 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
392 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
393 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
394 if (fTagCutSumm) break;
397 AliInfo(Form("No tag summary map in input tree\n"));
402 TMapIter *tIter = new TMapIter(fTagCutSumm);
404 Int_t iTotList=0, iAccList=0, iRejList=0;
407 while ((cobj = tIter->Next())) {
408 TObjString *kstr = (TObjString *) cobj;
409 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
410 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
412 iTagInfo = strdup(vstr->GetString().Data());
414 Int_t iAcc = atoi(strtok(iTagInfo, ","));
415 Int_t iRej = atoi(strtok(NULL, ","));
419 iTotList += (iAcc+iRej);
423 *aAccepted = iAccList;
424 *aRejected = iRejList;
429 //______________________________________________________________________________
430 Int_t AliESDInputHandler::GetNFilesEmpty()
432 // Count number of files in which all events were de-selected
433 // For such files Notify() will NOT be called
434 // return -1 if no info is available
436 TList *luo = fTree->GetUserInfo();
438 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
441 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
442 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
443 if (fTagCutSumm) break;
446 AliInfo(Form("No tag summary map in input tree\n"));
451 TMapIter *tIter = new TMapIter(fTagCutSumm);
453 Int_t iFilesEmpty = 0;
456 while ((cobj = tIter->Next())) {
457 TObjString *kstr = (TObjString *) cobj;
458 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
459 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
461 iTagInfo = strdup(vstr->GetString().Data());
463 Int_t iAcc = atoi(strtok(iTagInfo, ","));
464 Int_t iRej = atoi(strtok(NULL, ","));
466 if ((iAcc == 0) && ((iRej+iAcc)>0))
474 //______________________________________________________________________________
475 TObject *AliESDInputHandler::GetStatistics(Option_t *option) const
477 // Get the statistics histogram(s) from the physics selection object. This
478 // should be called during FinishTaskOutput(). Option can be empty (default
479 // statistics histogram) or BIN0.
480 if (!fEventCuts) return NULL;
483 if (opt=="BIN0") return fEventCuts->GetStatistics("BIN0");
484 else return fEventCuts->GetStatistics("ALL");