TPC ALTRO mapping class
[u/mrichter/AliRoot.git] / FMD / AliFMDInput.cxx
CommitLineData
a1f80595 1/**************************************************************************
2 * Copyright(c) 2004, 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//___________________________________________________________________
19//
20// The classes defined here, are utility classes for reading in data
21// for the FMD. They are put in a seperate library to not polute the
22// normal libraries. The classes are intended to be used as base
23// classes for customized class that do some sort of analysis on the
24// various types of data produced by the FMD.
25//
26// Latest changes by Christian Holm Christensen
27//
28#include "AliFMDInput.h" // ALIFMDHIT_H
29#include "AliLog.h" // ALILOG_H
8f6ee336 30#include "AliLoader.h" // ALILOADER_H
31#include "AliRunLoader.h" // ALIRUNLOADER_H
32#include "AliRun.h" // ALIRUN_H
33#include "AliStack.h" // ALISTACK_H
34#include "AliFMD.h" // ALIFMD_H
a1f80595 35#include "AliFMDHit.h" // ALIFMDHIT_H
8f6ee336 36#include "AliFMDDigit.h" // ALIFMDDigit_H
37#include "AliFMDMultStrip.h" // ALIFMDMultStrip_H
38#include "AliFMDMultRegion.h" // ALIFMDMultRegion_H
39#include <TTree.h> // ROOT_TTree
40#include <TParticle.h> // ROOT_TParticle
41#include <TString.h> // ROOT_TString
42#include <TDatabasePDG.h> // ROOT_TDatabasePDG
43#include <TMath.h> // ROOT_TMath
44#include <TGeoManager.h> // ROOT_TGeoManager
45#include <Riostream.h> // ROOT_Riostream
a1f80595 46
47//____________________________________________________________________
48ClassImp(AliFMDInput)
49#if 0
50 ; // This is here to keep Emacs for indenting the next line
51#endif
52
53
54//____________________________________________________________________
55AliFMDInput::AliFMDInput()
56 : fGAliceFile(""),
57 fLoader(0),
58 fRun(0),
59 fStack(0),
60 fFMDLoader(0),
61 fFMD(0),
62 fTreeE(0),
63 fTreeH(0),
64 fTreeD(0),
65 fTreeS(0),
66 fTreeR(0),
67 fArrayE(0),
68 fArrayH(0),
69 fArrayD(0),
70 fArrayS(0),
71 fArrayN(0),
72 fArrayP(0),
73 fTreeMask(0),
74 fIsInit(kFALSE)
75{
76 // Constructor of an FMD input object. Specify what data to read in
77 // using the AddLoad member function. Sub-classes should at a
78 // minimum overload the member function Event. A full job can be
79 // executed using the member function Run.
80}
81
82
83
84//____________________________________________________________________
85AliFMDInput::AliFMDInput(const char* gAliceFile)
86 : fGAliceFile(gAliceFile),
87 fLoader(0),
88 fRun(0),
89 fStack(0),
90 fFMDLoader(0),
91 fFMD(0),
92 fTreeE(0),
93 fTreeH(0),
94 fTreeD(0),
95 fTreeS(0),
96 fTreeR(0),
97 fArrayE(0),
98 fArrayH(0),
99 fArrayD(0),
100 fArrayS(0),
101 fArrayN(0),
102 fArrayP(0),
103 fTreeMask(0),
104 fIsInit(kFALSE)
105{
106 // Constructor of an FMD input object. Specify what data to read in
107 // using the AddLoad member function. Sub-classes should at a
108 // minimum overload the member function Event. A full job can be
109 // executed using the member function Run.
110}
111
112//____________________________________________________________________
113Int_t
114AliFMDInput::NEvents() const
115{
116 // Get number of events
117 if (fTreeE) return fTreeE->GetEntries();
118 return -1;
119}
120
121//____________________________________________________________________
122Bool_t
123AliFMDInput::Init()
124{
125 // Initialize the object. Get the needed loaders, and such.
126
127 // Check if we have been initialized
128 if (fIsInit) {
129 AliWarning("Already initialized");
130 return fIsInit;
131 }
132 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
133 // Get the loader
134 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
135 if (!fLoader) {
136 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
137 return kFALSE;
138 }
139
140 // Get the run
141 if (fLoader->LoadgAlice()) return kFALSE;
142 fRun = fLoader->GetAliRun();
143
144 // Get the FMD
145 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
146 if (!fFMD) {
147 AliError("Failed to get detector FMD from loader");
148 return kFALSE;
149 }
150
151 // Get the FMD loader
152 fFMDLoader = fLoader->GetLoader("FMDLoader");
153 if (!fFMDLoader) {
154 AliError("Failed to get detector FMD loader from loader");
155 return kFALSE;
156 }
157 if (fLoader->LoadHeader()) {
158 AliError("Failed to get event header information from loader");
159 return kFALSE;
160 }
161 fTreeE = fLoader->TreeE();
8f6ee336 162
163 // Optionally, get the geometry
164 if (TESTBIT(fTreeMask, kGeometry)) {
165 TString fname(fRun->GetGeometryFileName());
166 if (fname.IsNull()) {
167 Warning("Init", "No file name for the geometry from AliRun");
168 fname = gSystem->DirName(fGAliceFile);
169 fname.Append("/geometry.root");
170 }
171 fGeoManager = TGeoManager::Import(fname.Data());
172 if (!fGeoManager) {
173 Fatal("Init", "No geometry manager found");
174 return kFALSE;
175 }
176 }
a1f80595 177
178 fIsInit = kTRUE;
179 return fIsInit;
180}
181
182//____________________________________________________________________
183Bool_t
184AliFMDInput::Begin(Int_t event)
185{
186 // Called at the begining of each event. Per default, it gets the
187 // data trees and gets pointers to the output arrays. Users can
188 // overload this, but should call this member function in the
189 // overloaded member function of the derived class.
190
191 // Check if we have been initialized
192 if (!fIsInit) {
193 AliError("Not initialized");
194 return fIsInit;
195 }
196 // Get the event
197 if (fLoader->GetEvent(event)) return kFALSE;
198 AliInfo(Form("Now in event %d/%d", event, NEvents()));
199
200 // Possibly load global kinematics information
201 if (TESTBIT(fTreeMask, kKinematics)) {
202 AliInfo("Getting kinematics");
203 if (fLoader->LoadKinematics()) return kFALSE;
204 fStack = fLoader->Stack();
205 }
206 // Possibly load FMD Hit information
207 if (TESTBIT(fTreeMask, kHits)) {
208 AliInfo("Getting FMD hits");
209 if (fFMDLoader->LoadHits()) return kFALSE;
210 fTreeH = fFMDLoader->TreeH();
211 if (!fArrayH) fArrayH = fFMD->Hits();
212 }
213 // Possibly load FMD Digit information
214 if (TESTBIT(fTreeMask, kDigits)) {
215 AliInfo("Getting FMD digits");
216 if (fFMDLoader->LoadDigits()) return kFALSE;
217 fTreeD = fFMDLoader->TreeD();
218 if (!fArrayD) fArrayD = fFMD->Digits();
219 }
220 // Possibly load FMD Sdigit information
221 if (TESTBIT(fTreeMask, kSDigits)) {
222 AliInfo("Getting FMD summable digits");
223 if (fFMDLoader->LoadSDigits()) return kFALSE;
224 fTreeS = fFMDLoader->TreeS();
225 if (!fArrayS) fArrayS = fFMD->SDigits();
226 }
227 // Possibly load FMD RecPoints information
228 if (TESTBIT(fTreeMask, kRecPoints)) {
229 AliInfo("Getting FMD reconstructed points");
230 if (fFMDLoader->LoadRecPoints()) return kFALSE;
231 fTreeR = fFMDLoader->TreeR();
232 if (!fArrayN) fArrayN = new TClonesArray("AliFMDMultStrip");
8f6ee336 233 // if (!fArrayP) fArrayP = new TClonesArray("AliFMDMultRegion");
234 fTreeR->SetBranchAddress("FMD", &fArrayN);
235 // fTreeR->SetBranchAddress("FMDPoisson", &fArrayP);
a1f80595 236 }
237 return kTRUE;
238}
239
240//____________________________________________________________________
241Bool_t
242AliFMDInput::End()
243{
244 // Called at the end of each event. Per default, it unloads the
245 // data trees and resets the pointers to the output arrays. Users
246 // can overload this, but should call this member function in the
247 // overloaded member function of the derived class.
248
249 // Check if we have been initialized
250 if (!fIsInit) {
251 AliError("Not initialized");
252 return fIsInit;
253 }
254 // Possibly unload global kinematics information
255 if (TESTBIT(fTreeMask, kKinematics)) {
256 fLoader->UnloadKinematics();
257 // fTreeK = 0;
258 fStack = 0;
259 }
260 // Possibly unload FMD Hit information
261 if (TESTBIT(fTreeMask, kHits)) {
262 fFMDLoader->UnloadHits();
263 fTreeH = 0;
264 }
265 // Possibly unload FMD Digit information
266 if (TESTBIT(fTreeMask, kDigits)) {
267 fFMDLoader->UnloadDigits();
268 fTreeD = 0;
269 }
270 // Possibly unload FMD Sdigit information
271 if (TESTBIT(fTreeMask, kSDigits)) {
272 fFMDLoader->UnloadSDigits();
273 fTreeS = 0;
274 }
275 // Possibly unload FMD RecPoints information
276 if (TESTBIT(fTreeMask, kRecPoints)) {
277 fFMDLoader->UnloadRecPoints();
278 fTreeR = 0;
279 }
280 AliInfo("Now out event");
281 return kTRUE;
282}
283
284//____________________________________________________________________
285Bool_t
286AliFMDInput::Run()
287{
288 // Run over all events and files references in galice.root
289
290 Bool_t retval;
291 if (!(retval = Init())) return retval;
292
293 Int_t nEvents = NEvents();
294 for (Int_t event = 0; event < nEvents; event++) {
295 if (!(retval = Begin(event))) break;
296 if (!(retval = Event())) break;
297 if (!(retval = End())) break;
298 }
299 if (!retval) return retval;
300 retval = Finish();
301 return retval;
302}
303
304//====================================================================
305ClassImp(AliFMDInputHits)
306#if 0
307 ;
308#endif
309
310Bool_t
311AliFMDInputHits::Event()
312{
313 // Read the hit tree, and pass each hit to the member function
314 // ProcessHit. Optionally, if the user said `AddLoad(kKinematics)'
315 // the track corresponding to the hit will also be passed to the
316 // ProcessHit member function of the derived class.
317 if (!fTreeH) {
318 AliError("No hit tree defined");
319 return kFALSE;
320 }
321 Int_t nTracks = fTreeH->GetEntries();
322 for (Int_t i = 0; i < nTracks; i++) {
323 Int_t hitRead = fTreeH->GetEntry(i);
324 if (hitRead <= 0) continue;
325 if (!fArrayH) {
326 AliError("No hit array defined");
327 return kFALSE;
328 }
329 Int_t nHit = fArrayH->GetEntries();
330 if (nHit <= 0) continue;
331 for (Int_t j = 0; j < nHit; j++) {
332 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
333 if (!hit) continue;
334 TParticle* track = 0;
335 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
336 Int_t trackno = hit->Track();
337 track = fStack->Particle(trackno);
338 }
339 if (!ProcessHit(hit, track)) return kFALSE;
340 }
341 }
342 return kTRUE;
343}
344
345//====================================================================
346ClassImp(AliFMDInputDigits)
347#if 0
348 ;
349#endif
350
351Bool_t
352AliFMDInputDigits::Event()
353{
354 // Read the digit tree, and pass each digit to the member function
355 // ProcessDigit.
356 Int_t nEv = fTreeD->GetEntries();
357 for (Int_t i = 0; i < nEv; i++) {
358 Int_t digitRead = fTreeD->GetEntry(i);
359 if (digitRead <= 0) continue;
360 Int_t nDigit = fArrayD->GetEntries();
361 if (nDigit <= 0) continue;
362 for (Int_t j = 0; j < nDigit; j++) {
363 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
364 if (!digit) continue;
365 if (!ProcessDigit(digit)) return kFALSE;
366 }
367 }
368 return kTRUE;
369}
370
371//====================================================================
372ClassImp(AliFMDInputSDigits)
373#if 0
374 ;
375#endif
376
377Bool_t
378AliFMDInputSDigits::Event()
379{
380 // Read the summable digit tree, and pass each sumable digit to the
381 // member function ProcessSdigit.
382 Int_t nEv = fTreeD->GetEntries();
383 for (Int_t i = 0; i < nEv; i++) {
384 Int_t sdigitRead = fTreeS->GetEntry(i);
385 if (sdigitRead <= 0) continue;
386 Int_t nSdigit = fArrayS->GetEntries();
387 if (nSdigit <= 0) continue;
388 for (Int_t j = 0; j < nSdigit; j++) {
389 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
390 if (!sdigit) continue;
391 if (!ProcessSDigit(sdigit)) return kFALSE;
392 }
393 }
394 return kTRUE;
395}
396
397//====================================================================
398ClassImp(AliFMDInputRecPoints)
399#if 0
400 ;
401#endif
402
403Bool_t
404AliFMDInputRecPoints::Event()
405{
406 // Read the reconstrcted points tree, and pass each reconstruction
407 // object to either ProcessStrip (for AliFMDMultStrip objects), or
408 // ProcessRegion (for AliFMDMultRegion objects).
409 Int_t nEv = fTreeR->GetEntries();
410 for (Int_t i = 0; i < nEv; i++) {
411 Int_t recRead = fTreeR->GetEntry(i);
412 if (recRead <= 0) continue;
413 Int_t nRecStrip = fArrayN->GetEntries();
414 for (Int_t j = 0; j < nRecStrip; j++) {
415 AliFMDMultStrip* strip = static_cast<AliFMDMultStrip*>(fArrayN->At(j));
416 if (!strip) continue;
417 if (!ProcessStrip(strip)) return kFALSE;
418 }
419 Int_t nRecRegion = fArrayP->GetEntries();
420 for (Int_t j = 0; j < nRecRegion; j++) {
421 AliFMDMultRegion* region =static_cast<AliFMDMultRegion*>(fArrayP->At(j));
422 if (!region) continue;
423 if (!ProcessRegion(region)) return kFALSE;
424 }
425 }
426 return kTRUE;
427}
428
429
430
431//____________________________________________________________________
432//
433// EOF
434//