1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
17 //---------------------------------------------------------------------------------
18 // Class AliMCEventHandler
19 // This class gives access to MC truth during the analysis.
20 // Monte Carlo truth is containe in the kinematics tree (produced particles) and
21 // the tree of reference hits.
23 // Origin: Andreas Morsch, CERN, andreas.morsch@cern.ch
24 //---------------------------------------------------------------------------------
28 #include "AliMCEventHandler.h"
29 #include "AliMCEvent.h"
30 #include "AliTrackReference.h"
31 #include "AliHeader.h"
37 #include <TParticle.h>
39 #include <TClonesArray.h>
40 #include <TDirectoryFile.h>
42 ClassImp(AliMCEventHandler)
44 AliMCEventHandler::AliMCEventHandler() :
46 fMCEvent(new AliMCEvent()),
57 fPathName(new TString("./")),
63 // Default constructor
66 AliMCEventHandler::AliMCEventHandler(const char* name, const char* title) :
67 AliVEventHandler(name, title),
68 fMCEvent(new AliMCEvent()),
79 fPathName(new TString("./")),
87 AliMCEventHandler::~AliMCEventHandler()
96 Bool_t AliMCEventHandler::Init(Option_t* opt)
100 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
102 fFileE = TFile::Open(Form("%sgalice.root", fPathName->Data()));
103 if (!fFileE) AliFatal(Form("AliMCEventHandler:galice.root not found in directory %s ! \n", fPathName->Data()));
107 fFileE->GetObject("TE", fTreeE);
108 // Connect Tree E to the MCEvent
109 fMCEvent->ConnectTreeE(fTreeE);
110 fNEvent = fTreeE->GetEntries();
113 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
114 if (!fFileK) AliFatal(Form("AliMCEventHandler:Kinematics.root not found in directory %s ! \n", fPathName));
115 fEventsPerFile = fFileK->GetNkeys() - fFileK->GetNProcessIDs();
119 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
120 if (!fFileTR) AliWarning(Form("AliMCEventHandler:TrackRefs.root not found in directory %s ! \n", fPathName->Data()));
123 // Reset the event number
126 printf("AliMCEvenHandler::Init() %d\n",__LINE__);
127 AliInfo(Form("AliMCEventHandler:Number of events in this directory %5d \n", fNEvent));
131 Bool_t AliMCEventHandler::GetEvent(Int_t iev)
133 // Load the event number iev
135 // Calculate the file number
136 Int_t inew = iev / fEventsPerFile;
137 if (inew != fFileNumber) {
139 if (!OpenFile(fFileNumber)){
145 sprintf(folder, "Event%d", iev);
147 fTreeE->GetEntry(iev);
149 fFileK->GetObject(folder, fDirK);
151 AliWarning(Form("AliMCEventHandler: Event #%5d not found\n", iev));
154 fDirK ->GetObject("TreeK", fTreeK);
155 // Connect TreeK to MCEvent
156 fMCEvent->ConnectTreeK(fTreeK);
159 // Check which format has been read
160 fFileTR->GetObject(folder, fDirTR);
161 fDirTR->GetObject("TreeTR", fTreeTR);
163 // Connect TR to MCEvent
164 fMCEvent->ConnectTreeTR(fTreeTR);
170 Bool_t AliMCEventHandler::OpenFile(Int_t i)
175 fExtension = Form("%d", i);
182 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
184 AliFatal(Form("AliMCEventHandler:Kinematics%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
189 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
191 AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
198 Bool_t AliMCEventHandler::BeginEvent(Long64_t entry)
200 // Read the next event
208 if (entry >= fNEvent) {
209 AliWarning(Form("AliMCEventHandler: Event number out of range %5d %5d\n", entry,fNEvent));
212 return GetEvent(entry);
215 Int_t AliMCEventHandler::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*& trefs)
218 return (fMCEvent->GetParticleAndTR(i, particle, trefs));
221 void AliMCEventHandler::DrawCheck(Int_t i, Int_t search)
223 // Retrieve entry i and draw momentum vector and hits
224 fMCEvent->DrawCheck(i, search);
227 Bool_t AliMCEventHandler::Notify(const char *path)
229 // Notify about directory change
230 // The directory is taken from the 'path' argument
232 TString fileName(path);
233 if(fileName.Contains("AliESDs.root")){
234 fileName.ReplaceAll("AliESDs.root", "");
236 else if(fileName.Contains("galice.root")){
237 // for running with galice and kinematics alone...
238 fileName.ReplaceAll("galice.root", "");
241 *fPathName = fileName;
242 printf("AliMCEventHandler::Notify() Path: %s\n", fPathName->Data());
250 void AliMCEventHandler::ResetIO()
252 // Clear header and stack
256 delete fTreeE; fTreeE = 0;
259 if (fFileE) {delete fFileE; fFileE = 0;}
260 if (fFileK) {delete fFileK; fFileK = 0;}
261 if (fFileTR) {delete fFileTR; fFileTR = 0;}
266 Bool_t AliMCEventHandler::FinishEvent()
268 // Clean-up after each event
269 delete fDirTR; fDirTR = 0;
270 delete fDirK; fDirK = 0;
271 fMCEvent->FinishEvent();
275 Bool_t AliMCEventHandler::Terminate()
281 Bool_t AliMCEventHandler::TerminateIO()
288 void AliMCEventHandler::SetInputPath(char* fname)
290 // Set the input path name
292 fPathName = new TString(fname);