1 #include "AliFMDMCHitHandler.h"
2 #include "AliAnalysisManager.h"
6 #include <TClonesArray.h>
9 #include <AliMCEvent.h>
11 ClassImp(AliFMDMCHitHandler)
12 #if 0 // For Emacs - do not remove
16 //____________________________________________________________________
17 AliFMDMCHitHandler::AliFMDMCHitHandler(const char* name,
19 AliMCEventHandler* parent)
20 : AliMCEventHandler(name, what),
28 fNEventsInContainer(0),
40 //____________________________________________________________________
42 AliFMDMCHitHandler::GetParentPath() const
45 AliWarning("No parent");
48 return fParent->GetInputPath();
51 //____________________________________________________________________
53 AliFMDMCHitHandler::Init(Option_t* opt)
55 // Initialize the input
59 // @return true on success
60 AliDebugF(10,"AliFMDMCHitHandler::Init(\"%s\")", opt);
63 if (option.EqualTo("proof") || option.EqualTo("local")) return true;
67 TClass* cl = gROOT->GetClass(GetTitle());
69 if (cl->InheritsFrom("AliHit")) {
73 else if (cl->InheritsFrom("AliSDigit")) {
77 else if (cl->InheritsFrom("AliDigit")) {
84 if (!t.IsNull()) fTreeName = t;
85 if (!b.IsNull()) fFileBase = b;
88 fArray = new TClonesArray(GetTitle());
90 TTree* treeE = fParent->GetTree();
92 AliError("Parent does not have an events tree");
96 // Get number of events in this directory
98 fNEvents = treeE->GetEntries();
102 if (!OpenFile(fFileNumber)) return false;
106 //____________________________________________________________________
108 AliFMDMCHitHandler::BeginEvent(Long64_t entry)
110 // Called at the beginning of an event
112 // @param entry Entry in tree
114 // @return true on success
115 AliDebugF(10,"AliFMDMCHitHandler::BeginEvent(%lld)", entry);
122 if (fEvent >= fNEvents) {
123 AliWarningF("Event number out of range %d/%d", fEvent, fNEvents);
127 if (fNEventsPerFile < 0) {
128 TTree* treeK = fParent->TreeK();
130 AliError("Parent does not have a kinematics tree");
134 TFile* fileK = treeK->GetCurrentFile();
136 AliError("Kinematics tree has no associated file");
139 // Get the number of events per file
140 fNEventsPerFile = fileK->GetNkeys() - fileK->GetNProcessIDs();
142 return LoadEvent(fEvent);
144 //____________________________________________________________________
146 AliFMDMCHitHandler::Notify(const char* path)
148 // Called when the input file is changed
150 // @param path New path
152 // @return true on success
153 AliDebugF(10,"AliFMDMCHitHandler::Notify(\"%s\")", path);
156 //____________________________________________________________________
158 AliFMDMCHitHandler::FinishEvent()
160 // Called at the end of an event
162 // @return true on success
163 AliDebug(10,"AliFMDMCHitHandler::FinishEvent()");
166 //____________________________________________________________________
168 AliFMDMCHitHandler::Terminate()
170 // Called at the end of a job
172 // @return true on success
173 AliDebug(10,"AliFMDMCHitHandler::Terminate()");
176 //____________________________________________________________________
178 AliFMDMCHitHandler::TerminateIO()
180 // Called at the end of a sub-job
182 // @return true on success
183 AliDebug(10,"AliFMDMCHitHandler::TerminateIO()");
187 //____________________________________________________________________
189 AliFMDMCHitHandler::ResetIO()
194 AliDebug(10,"AliFMDMCHitHandler::ResetIO()");
196 TString* path = GetParentPath();
197 AliDebugF(10,"Got parent path %s", path ? path->Data() : "null");
204 //____________________________________________________________________
206 AliFMDMCHitHandler::OpenFile(Int_t fileNo)
208 TString* path = GetParentPath();
209 AliDebugF(10,"Got parent path %s", path ? path->Data() : "null");
210 if (!path) return false;
213 if (fileNo > 0) ext = TString::Format("%d", fileNo);
215 TString w(GetTitle());
216 if (w.EndsWith("s")) w.Chop();
218 TString fn = TString::Format("%s%s.%s%s.root",
219 path->Data(), GetName(),
220 fFileBase.Data(), ext.Data());
221 Info("Init", "Opening %s", fn.Data());
222 fFile = TFile::Open(fn, "READ");
224 AliErrorF("Failed to open %s", fn.Data());
231 //____________________________________________________________________
233 AliFMDMCHitHandler::LoadEvent(Int_t iev)
237 // @param iev Event number
239 // @return true on success
240 AliDebugF(10,"AliFMDMCHitHandler::LoadEvent(%d)", iev);
242 Int_t iNew = iev / fNEventsPerFile;
243 if (iNew != fFileNumber) {
245 if (!OpenFile(fFileNumber)) return false;
247 if (!fFile) return false;
249 TString folder = TString::Format("Event%d", iev);
250 fFile->GetObject(folder, fDir);
252 AliWarningF("Folder %s not found in file", folder.Data());
256 fDir->GetObject(fTreeName, fTree);
258 AliWarningF("Folder %s does not contain the %s tree %s",
259 folder.Data(), GetTitle(), fTreeName.Data());
263 fTree->SetBranchAddress(GetName(), &fArray);
268 //____________________________________________________________________
270 AliFMDMCHitHandler::Create(const char* name, const char* what)
272 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
274 ::Error("AliFMDMCHitHandler::Create", "No analysis manager");
278 AliVEventHandler* vmc = mgr->GetMCtruthEventHandler();
280 ::Error("AliFMDMCHitHandler::Create", "No MC truth handler");
284 AliMCEventHandler* mc = dynamic_cast<AliMCEventHandler*>(vmc);
286 ::Error("AliFMDMCHitHandler::Create",
287 "MC truth handler not a AliMCEventHandler, but %s",
292 AliFMDMCHitHandler* ret = new AliFMDMCHitHandler(name, what, mc);
293 mc->AddSubsidiaryHandler(ret);
298 //____________________________________________________________________
300 AliFMDMCHitHandler::GetParticleArray(AliFMDMCHitHandler* handler,
304 ::Error("AliFMDMCHitHandler::GetArray", "No handler passed");
308 AliMCEventHandler* mc = handler->GetParent();
310 ::Error("AliFMDMCHitHandler::GetArray", "Handler has no parent");
314 AliMCEvent* event = mc->MCEvent();
316 ::Error("AliFMDMCHitHandler::GetArray", "No MC event");
320 AliStack* stack = event->Stack();
322 ::Error("AliFMDMCHitHandler::GetArray", "Event has no stack");
326 TTree* tree = handler->GetTree();
328 ::Error("AliFMDMCHitHandler::GetArray", "Handler has no tree");
332 Int_t treeIdx = stack->TreeKEntry(particle);
333 if (treeIdx < 0 || treeIdx >= tree->GetEntries()) {
334 ::Error("AliFMDMCHitHandler::GetArray",
335 "Index %d of %d out of bounds [0,%lld]", treeIdx, particle,
336 tree->GetEntries()-1);
340 tree->GetEntry(treeIdx);
342 return handler->GetArray();
347 //____________________________________________________________________