]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliMCEventHandler.cxx
Misalignment according survey data
[u/mrichter/AliRoot.git] / STEER / AliMCEventHandler.cxx
CommitLineData
5fe09262 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
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.
22//
23// Origin: Andreas Morsch, CERN, andreas.morsch@cern.ch
24//---------------------------------------------------------------------------------
25
26
27
28#include "AliMCEventHandler.h"
415d9f5c 29#include "AliMCEvent.h"
5fe09262 30#include "AliTrackReference.h"
31#include "AliHeader.h"
32#include "AliStack.h"
2c36081e 33#include "AliLog.h"
5fe09262 34
35#include <TTree.h>
36#include <TFile.h>
37#include <TParticle.h>
0a05cd41 38#include <TString.h>
5fe09262 39#include <TClonesArray.h>
40#include <TDirectoryFile.h>
5fe09262 41
42ClassImp(AliMCEventHandler)
43
44AliMCEventHandler::AliMCEventHandler() :
d2f1d9ef 45 AliVEventHandler(),
415d9f5c 46 fMCEvent(new AliMCEvent()),
5fe09262 47 fFileE(0),
48 fFileK(0),
49 fFileTR(0),
5fe09262 50 fTreeE(0),
51 fTreeK(0),
52 fTreeTR(0),
5efedd31 53 fDirK(0),
54 fDirTR(0),
5fe09262 55 fNEvent(-1),
56 fEvent(-1),
0a05cd41 57 fPathName(new TString("./")),
9aea8469 58 fExtension(""),
59 fFileNumber(0),
60 fEventsPerFile(0)
5fe09262 61{
62 // Default constructor
63}
64
65AliMCEventHandler::AliMCEventHandler(const char* name, const char* title) :
d2f1d9ef 66 AliVEventHandler(name, title),
415d9f5c 67 fMCEvent(new AliMCEvent()),
5fe09262 68 fFileE(0),
69 fFileK(0),
70 fFileTR(0),
5fe09262 71 fTreeE(0),
72 fTreeK(0),
73 fTreeTR(0),
5efedd31 74 fDirK(0),
75 fDirTR(0),
5fe09262 76 fNEvent(-1),
77 fEvent(-1),
0a05cd41 78 fPathName(new TString("./")),
9aea8469 79 fExtension(""),
80 fFileNumber(0),
81 fEventsPerFile(0)
5fe09262 82{
83 // Constructor
84}
85AliMCEventHandler::~AliMCEventHandler()
86{
87 // Destructor
415d9f5c 88 delete fMCEvent;
5fe09262 89 delete fFileE;
90 delete fFileK;
91 delete fFileTR;
92}
93
94Bool_t AliMCEventHandler::InitIO(Option_t* /*opt*/)
95{
96 // Initialize input
97 //
0a05cd41 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()));
5fe09262 100
415d9f5c 101 //
102 // Tree E
5fe09262 103 fFileE->GetObject("TE", fTreeE);
415d9f5c 104 // Connect Tree E to the MCEvent
105 fMCEvent->ConnectTreeE(fTreeE);
5fe09262 106 fNEvent = fTreeE->GetEntries();
107 //
108 // Tree K
0a05cd41 109 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
2c36081e 110 if (!fFileK) AliFatal(Form("AliMCEventHandler:Kinematics.root not found in directory %s ! \n", fPathName));
9aea8469 111 fEventsPerFile = fFileK->GetNkeys() - fFileK->GetNProcessIDs();
5fe09262 112 //
113 // Tree TR
0a05cd41 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()));
5fe09262 116 //
117 // Reset the event number
2c36081e 118 fEvent = -1;
119 fFileNumber = 0;
9aea8469 120
2c36081e 121 AliInfo(Form("AliMCEventHandler:Number of events in this directory %5d \n", fNEvent));
5fe09262 122 return kTRUE;
5fe09262 123}
124
9aea8469 125Bool_t AliMCEventHandler::GetEvent(Int_t iev)
126{
127 // Load the event number iev
2c36081e 128 //
129 // Calculate the file number
415d9f5c 130 Int_t inew = iev / fEventsPerFile;
9aea8469 131 if (inew != fFileNumber) {
132 fFileNumber = inew;
133 if (!OpenFile(fFileNumber)){
134 return kFALSE;
135 }
136 }
2c36081e 137 // Folder name
5fe09262 138 char folder[20];
9aea8469 139 sprintf(folder, "Event%d", iev);
5fe09262 140 // TreeE
9aea8469 141 fTreeE->GetEntry(iev);
5fe09262 142 // Tree K
5efedd31 143 fFileK->GetObject(folder, fDirK);
144 if (!fDirK) {
2c36081e 145 AliWarning(Form("AliMCEventHandler: Event #%5d not found\n", iev));
9aea8469 146 return kFALSE;
147 }
5efedd31 148 fDirK ->GetObject("TreeK", fTreeK);
415d9f5c 149 // Connect TreeK to MCEvent
150 fMCEvent->ConnectTreeK(fTreeK);
5fe09262 151 //Tree TR
07bd4750 152 if (fFileTR) {
5efedd31 153 // Check which format has been read
154 fFileTR->GetObject(folder, fDirTR);
155 fDirTR->GetObject("TreeTR", fTreeTR);
415d9f5c 156 //
157 // Connect TR to MCEvent
158 fMCEvent->ConnectTreeTR(fTreeTR);
5fe09262 159 }
5fe09262 160 //
5fe09262 161 return kTRUE;
9aea8469 162}
163
164Bool_t AliMCEventHandler::OpenFile(Int_t i)
165{
166 // Open file i
167 Bool_t ok = kTRUE;
168 if (i > 0) {
169 fExtension = Form("%d", i);
170 } else {
171 fExtension = "";
172 }
173
174
175 delete fFileK;
0a05cd41 176 fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fExtension));
9aea8469 177 if (!fFileK) {
0a05cd41 178 AliFatal(Form("AliMCEventHandler:Kinematics%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
9aea8469 179 ok = kFALSE;
180 }
181
182 delete fFileTR;
0a05cd41 183 fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fExtension));
9aea8469 184 if (!fFileTR) {
0a05cd41 185 AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fExtension, fPathName->Data()));
9aea8469 186 ok = kFALSE;
187 }
188
189 return ok;
190}
191
192Bool_t AliMCEventHandler::BeginEvent()
193{
194 // Read the next event
195 fEvent++;
196 if (fEvent >= fNEvent) {
2c36081e 197 AliWarning(Form("AliMCEventHandler: Event number out of range %5d\n", fEvent));
9aea8469 198 return kFALSE;
199 }
200 return GetEvent(fEvent);
5fe09262 201}
202
203Int_t AliMCEventHandler::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*& trefs)
204{
205 // Retrieve entry i
415d9f5c 206 return (fMCEvent->GetParticleAndTR(i, particle, trefs));
5fe09262 207}
208
2d8f26f6 209void AliMCEventHandler::DrawCheck(Int_t i, Int_t search)
5fe09262 210{
211 // Retrieve entry i and draw momentum vector and hits
415d9f5c 212 fMCEvent->DrawCheck(i, search);
5fe09262 213}
214
890126ab 215Bool_t AliMCEventHandler::Notify(const char *path)
5fe09262 216{
53faeca4 217 // Notify about directory change
218 // The directory is taken from the 'path' argument
219 // Reconnect trees
220 TString fileName(path);
221 if(fileName.Contains("AliESDs.root")){
222 fileName.ReplaceAll("AliESDs.root", "");
223 }
224 else if(fileName.Contains("galice.root")){
225 // for running with galice and kinematics alone...
226 fileName.ReplaceAll("galice.root", "");
227 }
228
229 *fPathName = fileName;
230 printf("AliMCEventHandler::Notify() Path: %s\n", fPathName->Data());
231
5fe09262 232 ResetIO();
233 InitIO("");
234 return kTRUE;
235}
236
237void AliMCEventHandler::ResetIO()
238{
5efedd31 239// Clear header and stack
415d9f5c 240 fMCEvent->Clean();
5efedd31 241
415d9f5c 242// Delete Tree E
243 delete fTreeE; fTreeE = 0;
5efedd31 244
245// Reset files
5fe09262 246 if (fFileE) delete fFileE;
247 if (fFileK) delete fFileK;
248 if (fFileTR) delete fFileTR;
249}
250
251
252Bool_t AliMCEventHandler::FinishEvent()
253{
5efedd31 254 // Clean-up after each event
255 delete fDirTR; fDirTR = 0;
256 delete fDirK; fDirK = 0;
415d9f5c 257 fMCEvent->FinishEvent();
5fe09262 258 return kTRUE;
259}
260
261Bool_t AliMCEventHandler::Terminate()
262{
263 // Dummy
264 return kTRUE;
265}
266
267Bool_t AliMCEventHandler::TerminateIO()
268{
269 // Dummy
270 return kTRUE;
271}
272
0a05cd41 273
274void AliMCEventHandler::SetInputPath(char* fname)
275{
276 // Set the input path name
277 delete fPathName;
278 fPathName = new TString(fname);
279}