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"
31 #include "AliTrackReference.h"
32 #include "AliHeader.h"
38 #include <TParticle.h>
40 #include <TClonesArray.h>
41 #include <TDirectoryFile.h>
43 ClassImp(AliMCEventHandler)
45 AliMCEventHandler::AliMCEventHandler() :
47 fMCEvent(new AliMCEvent()),
58 fPathName(new TString("./")),
66 // Default constructor
68 // Be sure to add all particles to the PDG database
69 AliPDG::AddParticlesToPdgDataBase();
72 AliMCEventHandler::AliMCEventHandler(const char* name, const char* title) :
73 AliVEventHandler(name, title),
74 fMCEvent(new AliMCEvent()),
85 fPathName(new TString("./")),
95 // Be sure to add all particles to the PDG database
96 AliPDG::AddParticlesToPdgDataBase();
98 AliMCEventHandler::~AliMCEventHandler()
107 Bool_t AliMCEventHandler::Init(Option_t* opt)
111 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
113 fFileE = TFile::Open(Form("%sgalice.root", fPathName->Data()));
115 AliError(Form("AliMCEventHandler:galice.root not found in directory %s ! \n", fPathName->Data()));
122 fFileE->GetObject("TE", fTreeE);
123 // Connect Tree E to the MCEvent
124 fMCEvent->ConnectTreeE(fTreeE);
125 fNEvent = fTreeE->GetEntries();
128 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
130 AliError(Form("AliMCEventHandler:Kinematics.root not found in directory %s ! \n", fPathName));
135 fEventsPerFile = fFileK->GetNkeys() - fFileK->GetNProcessIDs();
139 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
141 AliError(Form("AliMCEventHandler:TrackRefs.root not found in directory %s ! \n", fPathName->Data()));
147 // Reset the event number
150 AliInfo(Form("Number of events in this directory %5d \n", fNEvent));
155 Bool_t AliMCEventHandler::GetEvent(Int_t iev)
157 // Load the event number iev
159 // Calculate the file number
160 if (!fInitOk) return kFALSE;
162 Int_t inew = iev / fEventsPerFile;
163 if (inew != fFileNumber) {
165 if (!OpenFile(fFileNumber)){
171 sprintf(folder, "Event%d", iev);
173 fTreeE->GetEntry(iev);
175 fFileK->GetObject(folder, fDirK);
177 AliWarning(Form("AliMCEventHandler: Event #%5d not found\n", iev));
180 fDirK ->GetObject("TreeK", fTreeK);
181 // Connect TreeK to MCEvent
182 fMCEvent->ConnectTreeK(fTreeK);
185 // Check which format has been read
186 fFileTR->GetObject(folder, fDirTR);
187 fDirTR->GetObject("TreeTR", fTreeTR);
189 // Connect TR to MCEvent
190 fMCEvent->ConnectTreeTR(fTreeTR);
196 Bool_t AliMCEventHandler::OpenFile(Int_t i)
200 fExtension = Form("%d", i);
207 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
209 AliError(Form("AliMCEventHandler:Kinematics%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
216 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
218 AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
228 Bool_t AliMCEventHandler::BeginEvent(Long64_t entry)
230 // Read the next event
238 if (entry >= fNEvent) {
239 AliWarning(Form("AliMCEventHandler: Event number out of range %5d %5d\n", entry,fNEvent));
242 return GetEvent(entry);
245 Int_t AliMCEventHandler::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*& trefs)
251 return (fMCEvent->GetParticleAndTR(i, particle, trefs));
255 void AliMCEventHandler::DrawCheck(Int_t i, Int_t search)
257 // Retrieve entry i and draw momentum vector and hits
258 fMCEvent->DrawCheck(i, search);
261 Bool_t AliMCEventHandler::Notify(const char *path)
263 // Notify about directory change
264 // The directory is taken from the 'path' argument
266 TString fileName(path);
267 if(fileName.Contains("AliESDs.root")){
268 fileName.ReplaceAll("AliESDs.root", "");
270 else if(fileName.Contains("AliAOD.root")){
271 fileName.ReplaceAll("AliAOD.root", "");
273 else if(fileName.Contains("galice.root")){
274 // for running with galice and kinematics alone...
275 fileName.ReplaceAll("galice.root", "");
278 *fPathName = fileName;
279 AliInfo(Form("Notify() Path: %s\n", fPathName->Data()));
287 void AliMCEventHandler::ResetIO()
289 // Clear header and stack
290 if (fInitOk) fMCEvent->Clean();
293 delete fTreeE; fTreeE = 0;
296 if (fFileE) {delete fFileE; fFileE = 0;}
297 if (fFileK) {delete fFileK; fFileK = 0;}
298 if (fFileTR) {delete fFileTR; fFileTR = 0;}
304 Bool_t AliMCEventHandler::FinishEvent()
306 // Clean-up after each event
307 delete fDirTR; fDirTR = 0;
308 delete fDirK; fDirK = 0;
309 if (fInitOk) fMCEvent->FinishEvent();
313 Bool_t AliMCEventHandler::Terminate()
319 Bool_t AliMCEventHandler::TerminateIO()
326 void AliMCEventHandler::SetInputPath(const char* fname)
328 // Set the input path name
330 fPathName = new TString(fname);