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("./")),
62 // Default constructor
65 AliMCEventHandler::AliMCEventHandler(const char* name, const char* title) :
66 AliVEventHandler(name, title),
67 fMCEvent(new AliMCEvent()),
78 fPathName(new TString("./")),
85 AliMCEventHandler::~AliMCEventHandler()
94 Bool_t AliMCEventHandler::InitIO(Option_t* /*opt*/)
98 fFileE = TFile::Open(Form("%sgalice.root", fPathName->Data()));
99 if (!fFileE) AliFatal(Form("AliMCEventHandler:galice.root not found in directory %s ! \n", fPathName->Data()));
103 fFileE->GetObject("TE", fTreeE);
104 // Connect Tree E to the MCEvent
105 fMCEvent->ConnectTreeE(fTreeE);
106 fNEvent = fTreeE->GetEntries();
109 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
110 if (!fFileK) AliFatal(Form("AliMCEventHandler:Kinematics.root not found in directory %s ! \n", fPathName));
111 fEventsPerFile = fFileK->GetNkeys() - fFileK->GetNProcessIDs();
114 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
115 if (!fFileTR) AliWarning(Form("AliMCEventHandler:TrackRefs.root not found in directory %s ! \n", fPathName->Data()));
117 // Reset the event number
121 AliInfo(Form("AliMCEventHandler:Number of events in this directory %5d \n", fNEvent));
125 Bool_t AliMCEventHandler::GetEvent(Int_t iev)
127 // Load the event number iev
129 // Calculate the file number
130 Int_t inew = iev / fEventsPerFile;
131 if (inew != fFileNumber) {
133 if (!OpenFile(fFileNumber)){
139 sprintf(folder, "Event%d", iev);
141 fTreeE->GetEntry(iev);
143 fFileK->GetObject(folder, fDirK);
145 AliWarning(Form("AliMCEventHandler: Event #%5d not found\n", iev));
148 fDirK ->GetObject("TreeK", fTreeK);
149 // Connect TreeK to MCEvent
150 fMCEvent->ConnectTreeK(fTreeK);
153 // Check which format has been read
154 fFileTR->GetObject(folder, fDirTR);
155 fDirTR->GetObject("TreeTR", fTreeTR);
157 // Connect TR to MCEvent
158 fMCEvent->ConnectTreeTR(fTreeTR);
164 Bool_t AliMCEventHandler::OpenFile(Int_t i)
169 fExtension = Form("%d", i);
176 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
178 AliFatal(Form("AliMCEventHandler:Kinematics%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
183 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
185 AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
192 Bool_t AliMCEventHandler::BeginEvent()
194 // Read the next event
196 if (fEvent >= fNEvent) {
197 AliWarning(Form("AliMCEventHandler: Event number out of range %5d\n", fEvent));
200 return GetEvent(fEvent);
203 Int_t AliMCEventHandler::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*& trefs)
206 return (fMCEvent->GetParticleAndTR(i, particle, trefs));
209 void AliMCEventHandler::DrawCheck(Int_t i, Int_t search)
211 // Retrieve entry i and draw momentum vector and hits
212 fMCEvent->DrawCheck(i, search);
215 Bool_t AliMCEventHandler::Notify(const char *path)
217 // Notify about directory change
218 // The directory is taken from the 'path' argument
220 TString fileName(path);
221 if(fileName.Contains("AliESDs.root")){
222 fileName.ReplaceAll("AliESDs.root", "");
224 else if(fileName.Contains("galice.root")){
225 // for running with galice and kinematics alone...
226 fileName.ReplaceAll("galice.root", "");
229 *fPathName = fileName;
230 printf("AliMCEventHandler::Notify() Path: %s\n", fPathName->Data());
237 void AliMCEventHandler::ResetIO()
239 // Clear header and stack
243 delete fTreeE; fTreeE = 0;
246 if (fFileE) delete fFileE;
247 if (fFileK) delete fFileK;
248 if (fFileTR) delete fFileTR;
252 Bool_t AliMCEventHandler::FinishEvent()
254 // Clean-up after each event
255 delete fDirTR; fDirTR = 0;
256 delete fDirK; fDirK = 0;
257 fMCEvent->FinishEvent();
261 Bool_t AliMCEventHandler::Terminate()
267 Bool_t AliMCEventHandler::TerminateIO()
274 void AliMCEventHandler::SetInputPath(char* fname)
276 // Set the input path name
278 fPathName = new TString(fname);