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("./")),
65 // Default constructor
67 // Be sure to add all particles to the PDG database
68 AliPDG::AddParticlesToPdgDataBase();
71 AliMCEventHandler::AliMCEventHandler(const char* name, const char* title) :
72 AliVEventHandler(name, title),
73 fMCEvent(new AliMCEvent()),
84 fPathName(new TString("./")),
93 // Be sure to add all particles to the PDG database
94 AliPDG::AddParticlesToPdgDataBase();
96 AliMCEventHandler::~AliMCEventHandler()
105 Bool_t AliMCEventHandler::Init(Option_t* opt)
109 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
111 fFileE = TFile::Open(Form("%sgalice.root", fPathName->Data()));
112 if (!fFileE) AliFatal(Form("AliMCEventHandler:galice.root not found in directory %s ! \n", fPathName->Data()));
116 fFileE->GetObject("TE", fTreeE);
117 // Connect Tree E to the MCEvent
118 fMCEvent->ConnectTreeE(fTreeE);
119 fNEvent = fTreeE->GetEntries();
122 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
123 if (!fFileK) AliFatal(Form("AliMCEventHandler:Kinematics.root not found in directory %s ! \n", fPathName));
124 fEventsPerFile = fFileK->GetNkeys() - fFileK->GetNProcessIDs();
128 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
129 if (!fFileTR) AliWarning(Form("AliMCEventHandler:TrackRefs.root not found in directory %s ! \n", fPathName->Data()));
132 // Reset the event number
135 AliInfo(Form("Number of events in this directory %5d \n", fNEvent));
139 Bool_t AliMCEventHandler::GetEvent(Int_t iev)
141 // Load the event number iev
143 // Calculate the file number
144 Int_t inew = iev / fEventsPerFile;
145 if (inew != fFileNumber) {
147 if (!OpenFile(fFileNumber)){
153 sprintf(folder, "Event%d", iev);
155 fTreeE->GetEntry(iev);
157 fFileK->GetObject(folder, fDirK);
159 AliWarning(Form("AliMCEventHandler: Event #%5d not found\n", iev));
162 fDirK ->GetObject("TreeK", fTreeK);
163 // Connect TreeK to MCEvent
164 fMCEvent->ConnectTreeK(fTreeK);
167 // Check which format has been read
168 fFileTR->GetObject(folder, fDirTR);
169 fDirTR->GetObject("TreeTR", fTreeTR);
171 // Connect TR to MCEvent
172 fMCEvent->ConnectTreeTR(fTreeTR);
178 Bool_t AliMCEventHandler::OpenFile(Int_t i)
183 fExtension = Form("%d", i);
190 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
192 AliFatal(Form("AliMCEventHandler:Kinematics%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
197 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
199 AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
206 Bool_t AliMCEventHandler::BeginEvent(Long64_t entry)
208 // Read the next event
216 if (entry >= fNEvent) {
217 AliWarning(Form("AliMCEventHandler: Event number out of range %5d %5d\n", entry,fNEvent));
220 return GetEvent(entry);
223 Int_t AliMCEventHandler::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*& trefs)
226 return (fMCEvent->GetParticleAndTR(i, particle, trefs));
229 void AliMCEventHandler::DrawCheck(Int_t i, Int_t search)
231 // Retrieve entry i and draw momentum vector and hits
232 fMCEvent->DrawCheck(i, search);
235 Bool_t AliMCEventHandler::Notify(const char *path)
237 // Notify about directory change
238 // The directory is taken from the 'path' argument
240 TString fileName(path);
241 if(fileName.Contains("AliESDs.root")){
242 fileName.ReplaceAll("AliESDs.root", "");
244 else if(fileName.Contains("AliAOD.root")){
245 fileName.ReplaceAll("AliAOD.root", "");
247 else if(fileName.Contains("galice.root")){
248 // for running with galice and kinematics alone...
249 fileName.ReplaceAll("galice.root", "");
252 *fPathName = fileName;
253 AliInfo(Form("Notify() Path: %s\n", fPathName->Data()));
261 void AliMCEventHandler::ResetIO()
263 // Clear header and stack
267 delete fTreeE; fTreeE = 0;
270 if (fFileE) {delete fFileE; fFileE = 0;}
271 if (fFileK) {delete fFileK; fFileK = 0;}
272 if (fFileTR) {delete fFileTR; fFileTR = 0;}
277 Bool_t AliMCEventHandler::FinishEvent()
279 // Clean-up after each event
280 delete fDirTR; fDirTR = 0;
281 delete fDirK; fDirK = 0;
282 fMCEvent->FinishEvent();
286 Bool_t AliMCEventHandler::Terminate()
292 Bool_t AliMCEventHandler::TerminateIO()
299 void AliMCEventHandler::SetInputPath(const char* fname)
301 // Set the input path name
303 fPathName = new TString(fname);