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