Added ITS Alignment interface to MillePede2 and related supermodule 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 **************************************************************************/
a1f80595 15/* $Id$ */
c2fc1258 16/** @file AliFMDInput.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:42:40 2006
19 @brief FMD utility classes for reading FMD data
20*/
a1f80595 21//___________________________________________________________________
22//
23// The classes defined here, are utility classes for reading in data
24// for the FMD. They are put in a seperate library to not polute the
25// normal libraries. The classes are intended to be used as base
26// classes for customized class that do some sort of analysis on the
27// various types of data produced by the FMD.
28//
29// Latest changes by Christian Holm Christensen
30//
31#include "AliFMDInput.h" // ALIFMDHIT_H
69893a66 32#include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
8f6ee336 33#include "AliLoader.h" // ALILOADER_H
34#include "AliRunLoader.h" // ALIRUNLOADER_H
35#include "AliRun.h" // ALIRUN_H
36#include "AliStack.h" // ALISTACK_H
d760ea03 37#include "AliRawReaderFile.h" // ALIRAWREADERFILE_H
039842fe 38#include "AliRawReaderRoot.h" // ALIRAWREADERROOT_H
39#include "AliRawReaderDate.h" // ALIRAWREADERDATE_H
8f6ee336 40#include "AliFMD.h" // ALIFMD_H
a1f80595 41#include "AliFMDHit.h" // ALIFMDHIT_H
8f6ee336 42#include "AliFMDDigit.h" // ALIFMDDigit_H
02a27b50 43#include "AliFMDSDigit.h" // ALIFMDDigit_H
bf000c32 44#include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
d760ea03 45#include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
bf000c32 46#include <AliESD.h>
47#include <AliESDFMD.h>
df137876 48#include <AliESDEvent.h>
1e8f773e 49#include <AliCDBManager.h>
50#include <AliCDBEntry.h>
90dbf5fb 51#include <AliAlignObjParams.h>
08d168d9 52#include <AliTrackReference.h>
8f6ee336 53#include <TTree.h> // ROOT_TTree
bf000c32 54#include <TChain.h> // ROOT_TChain
8f6ee336 55#include <TParticle.h> // ROOT_TParticle
56#include <TString.h> // ROOT_TString
57#include <TDatabasePDG.h> // ROOT_TDatabasePDG
58#include <TMath.h> // ROOT_TMath
59#include <TGeoManager.h> // ROOT_TGeoManager
bf000c32 60#include <TSystemDirectory.h> // ROOT_TSystemDirectory
8f6ee336 61#include <Riostream.h> // ROOT_Riostream
97b4001e 62#include <TFile.h> // ROOT_TFile
a1e17193 63#include <TStreamerInfo.h>
7003fbd0 64#include <TArrayF.h>
65
a1f80595 66//____________________________________________________________________
67ClassImp(AliFMDInput)
68#if 0
69 ; // This is here to keep Emacs for indenting the next line
70#endif
71
72
73//____________________________________________________________________
74AliFMDInput::AliFMDInput()
42f1b2f5 75 : TNamed("AliFMDInput", "Input handler for various FMD data"),
76 fGAliceFile(""),
a1f80595 77 fLoader(0),
78 fRun(0),
79 fStack(0),
80 fFMDLoader(0),
d760ea03 81 fReader(0),
5cf05dbb 82 fFMDReader(0),
a1f80595 83 fFMD(0),
bf000c32 84 fESD(0),
df137876 85 fESDEvent(0),
a1f80595 86 fTreeE(0),
87 fTreeH(0),
08d168d9 88 fTreeTR(0),
a1f80595 89 fTreeD(0),
90 fTreeS(0),
91 fTreeR(0),
b5ee4425 92 fTreeA(0),
bf000c32 93 fChainE(0),
a1f80595 94 fArrayE(0),
95 fArrayH(0),
96 fArrayD(0),
97 fArrayS(0),
bf000c32 98 fArrayR(0),
d760ea03 99 fArrayA(0),
17e542eb 100 fHeader(0),
b5ee4425 101 fGeoManager(0),
a1f80595 102 fTreeMask(0),
039842fe 103 fRawFile(""),
17e542eb 104 fIsInit(kFALSE),
105 fEventCount(0)
a1f80595 106{
df137876 107
a1f80595 108 // Constructor of an FMD input object. Specify what data to read in
109 // using the AddLoad member function. Sub-classes should at a
110 // minimum overload the member function Event. A full job can be
111 // executed using the member function Run.
112}
113
114
115
116//____________________________________________________________________
117AliFMDInput::AliFMDInput(const char* gAliceFile)
42f1b2f5 118 : TNamed("AliFMDInput", "Input handler for various FMD data"),
119 fGAliceFile(gAliceFile),
a1f80595 120 fLoader(0),
121 fRun(0),
122 fStack(0),
123 fFMDLoader(0),
d760ea03 124 fReader(0),
5cf05dbb 125 fFMDReader(0),
a1f80595 126 fFMD(0),
bf000c32 127 fESD(0),
df137876 128 fESDEvent(0),
a1f80595 129 fTreeE(0),
130 fTreeH(0),
08d168d9 131 fTreeTR(0),
a1f80595 132 fTreeD(0),
133 fTreeS(0),
134 fTreeR(0),
b5ee4425 135 fTreeA(0),
bf000c32 136 fChainE(0),
a1f80595 137 fArrayE(0),
138 fArrayH(0),
139 fArrayD(0),
140 fArrayS(0),
bf000c32 141 fArrayR(0),
d760ea03 142 fArrayA(0),
17e542eb 143 fHeader(0),
b5ee4425 144 fGeoManager(0),
a1f80595 145 fTreeMask(0),
039842fe 146 fRawFile(""),
17e542eb 147 fIsInit(kFALSE),
148 fEventCount(0)
a1f80595 149{
df137876 150
a1f80595 151 // Constructor of an FMD input object. Specify what data to read in
152 // using the AddLoad member function. Sub-classes should at a
153 // minimum overload the member function Event. A full job can be
154 // executed using the member function Run.
155}
156
157//____________________________________________________________________
158Int_t
159AliFMDInput::NEvents() const
160{
161 // Get number of events
7af3df7f 162 if (TESTBIT(fTreeMask, kRaw)) return fReader->GetNumberOfEvents();
a1f80595 163 if (fTreeE) return fTreeE->GetEntries();
164 return -1;
165}
166
167//____________________________________________________________________
168Bool_t
169AliFMDInput::Init()
170{
171 // Initialize the object. Get the needed loaders, and such.
172
173 // Check if we have been initialized
174 if (fIsInit) {
175 AliWarning("Already initialized");
176 return fIsInit;
177 }
a1f80595 178 // Get the run
08d168d9 179 if (!TESTBIT(fTreeMask, kRaw) &&
180 !TESTBIT(fTreeMask, kESD)) {
59194467 181 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
182 // Get the loader
183 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
184 if (!fLoader) {
185 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
186 return kFALSE;
187 }
a1f80595 188
59194467 189 if (fLoader->LoadgAlice()) return kFALSE;
190 fRun = fLoader->GetAliRun();
a1f80595 191
59194467 192 // Get the FMD
193 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
194 if (!fFMD) {
195 AliError("Failed to get detector FMD from loader");
196 return kFALSE;
197 }
198
199 // Get the FMD loader
200 fFMDLoader = fLoader->GetLoader("FMDLoader");
201 if (!fFMDLoader) {
202 AliError("Failed to get detector FMD loader from loader");
203 return kFALSE;
204 }
205 if (fLoader->LoadHeader()) {
206 AliError("Failed to get event header information from loader");
207 return kFALSE;
208 }
209 fTreeE = fLoader->TreeE();
a1f80595 210 }
8f6ee336 211
bf000c32 212 // Optionally, get the ESD files
213 if (TESTBIT(fTreeMask, kESD)) {
214 fChainE = new TChain("esdTree");
c2fc1258 215 TSystemDirectory dir(".",".");
bf000c32 216 TList* files = dir.GetListOfFiles();
c2fc1258 217 TSystemFile* file = 0;
218 if (!files) {
219 AliError("No files");
220 return kFALSE;
221 }
bf000c32 222 files->Sort();
223 TIter next(files);
224 while ((file = static_cast<TSystemFile*>(next()))) {
225 TString fname(file->GetName());
226 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
227 }
df137876 228 fESDEvent = new AliESDEvent();
229 fESDEvent->ReadFromTree(fChainE);
230 // fChainE->SetBranchAddress("ESD", &fMainESD);
231
bf000c32 232 }
233
d760ea03 234 if (TESTBIT(fTreeMask, kRaw)) {
235 AliInfo("Getting FMD raw data digits");
236 fArrayA = new TClonesArray("AliFMDDigit");
0b1b2076 237#if 0
238 if (!fRawFile.IsNull() && fRawFile.EndsWith(".root"))
039842fe 239 fReader = new AliRawReaderRoot(fRawFile.Data());
240 else if (!fRawFile.IsNull() && fRawFile.EndsWith(".raw"))
241 fReader = new AliRawReaderDate(fRawFile.Data());
242 else
243 fReader = new AliRawReaderFile(-1);
0b1b2076 244#else
245 if(!fRawFile.IsNull())
246 fReader = AliRawReader::Create(fRawFile.Data());
247 else
248 fReader = new AliRawReaderFile(-1);
249#endif
5cf05dbb 250 fFMDReader = new AliFMDRawReader(fReader, 0);
d760ea03 251 }
252
8f6ee336 253 // Optionally, get the geometry
254 if (TESTBIT(fTreeMask, kGeometry)) {
59194467 255 if (fRun) {
256 TString fname(fRun->GetGeometryFileName());
257 if (fname.IsNull()) {
258 Warning("Init", "No file name for the geometry from AliRun");
259 fname = gSystem->DirName(fGAliceFile);
260 fname.Append("/geometry.root");
261 }
262 fGeoManager = TGeoManager::Import(fname.Data());
263 if (!fGeoManager) {
264 Fatal("Init", "No geometry manager found");
265 return kFALSE;
266 }
8f6ee336 267 }
59194467 268 else {
269 AliGeomManager::LoadGeometry();
8f6ee336 270 }
1e8f773e 271 AliCDBManager* cdb = AliCDBManager::Instance();
272 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
273 if (align) {
274 AliInfo("Got alignment data from CDB");
275 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
276 if (!array) {
277 AliWarning("Invalid align data from CDB");
278 }
279 else {
280 Int_t nAlign = array->GetEntries();
281 for (Int_t i = 0; i < nAlign; i++) {
90dbf5fb 282 AliAlignObjParams* a = static_cast<AliAlignObjParams*>(array->At(i));
1e8f773e 283 if (!a->ApplyToGeometry()) {
284 AliWarning(Form("Failed to apply alignment to %s",
b760c02e 285 a->GetSymName()));
1e8f773e 286 }
287 }
288 }
289 }
8f6ee336 290 }
bf000c32 291
69893a66 292 fEventCount = 0;
a1f80595 293 fIsInit = kTRUE;
294 return fIsInit;
295}
296
297//____________________________________________________________________
298Bool_t
299AliFMDInput::Begin(Int_t event)
300{
301 // Called at the begining of each event. Per default, it gets the
302 // data trees and gets pointers to the output arrays. Users can
303 // overload this, but should call this member function in the
304 // overloaded member function of the derived class.
305
306 // Check if we have been initialized
307 if (!fIsInit) {
308 AliError("Not initialized");
309 return fIsInit;
310 }
7003fbd0 311
a1f80595 312 // Get the event
59194467 313 if (fLoader && fLoader->GetEvent(event)) return kFALSE;
69893a66 314 AliInfo(Form("Now in event %8d/%8d", event, NEvents()));
a1f80595 315
316 // Possibly load global kinematics information
f95a63c4 317 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
69893a66 318 // AliInfo("Getting kinematics");
42f1b2f5 319 if (fLoader->LoadKinematics("READ")) return kFALSE;
a1f80595 320 fStack = fLoader->Stack();
321 }
7003fbd0 322
a1f80595 323 // Possibly load FMD Hit information
f95a63c4 324 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
69893a66 325 // AliInfo("Getting FMD hits");
42f1b2f5 326 if (!fFMDLoader || fFMDLoader->LoadHits("READ")) return kFALSE;
a1f80595 327 fTreeH = fFMDLoader->TreeH();
328 if (!fArrayH) fArrayH = fFMD->Hits();
329 }
08d168d9 330
331 // Possibly load FMD TrackReference information
332 if (TESTBIT(fTreeMask, kTrackRefs) || TESTBIT(fTreeMask, kTracks)) {
333 // AliInfo("Getting FMD hits");
334 if (!fLoader || fLoader->LoadTrackRefs("READ")) return kFALSE;
335 fTreeTR = fLoader->TreeTR();
336 if (!fArrayTR) fArrayTR = new TClonesArray("AliTrackReference");
337 fTreeTR->SetBranchAddress("TrackReferences", &fArrayTR);
338 }
339
9b98d361 340 // Possibly load heaedr information
341 if (TESTBIT(fTreeMask, kHeader)) {
342 // AliInfo("Getting FMD hits");
343 if (!fLoader /* || fLoader->LoadHeader()*/) return kFALSE;
344 fHeader = fLoader->GetHeader();
345 }
346
a1f80595 347 // Possibly load FMD Digit information
348 if (TESTBIT(fTreeMask, kDigits)) {
69893a66 349 // AliInfo("Getting FMD digits");
42f1b2f5 350 if (!fFMDLoader || fFMDLoader->LoadDigits("READ")) return kFALSE;
a1f80595 351 fTreeD = fFMDLoader->TreeD();
a9579262 352 if (fTreeD) {
353 if (!fArrayD) fArrayD = fFMD->Digits();
354 }
355 else {
356 fArrayD = 0;
357 AliWarning(Form("Failed to load FMD Digits"));
358 }
a1f80595 359 }
7003fbd0 360
a1f80595 361 // Possibly load FMD Sdigit information
362 if (TESTBIT(fTreeMask, kSDigits)) {
69893a66 363 // AliInfo("Getting FMD summable digits");
42f1b2f5 364 if (!fFMDLoader || fFMDLoader->LoadSDigits("READ")) return kFALSE;
a1f80595 365 fTreeS = fFMDLoader->TreeS();
366 if (!fArrayS) fArrayS = fFMD->SDigits();
367 }
7003fbd0 368
a1f80595 369 // Possibly load FMD RecPoints information
370 if (TESTBIT(fTreeMask, kRecPoints)) {
69893a66 371 // AliInfo("Getting FMD reconstructed points");
42f1b2f5 372 if (!fFMDLoader || fFMDLoader->LoadRecPoints("READ")) return kFALSE;
a1f80595 373 fTreeR = fFMDLoader->TreeR();
bf000c32 374 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
375 fTreeR->SetBranchAddress("FMD", &fArrayR);
7003fbd0 376 }
377
378 // Possibly load FMD ESD information
bf000c32 379 if (TESTBIT(fTreeMask, kESD)) {
69893a66 380 // AliInfo("Getting FMD event summary data");
bf000c32 381 Int_t read = fChainE->GetEntry(event);
382 if (read <= 0) return kFALSE;
df137876 383 fESD = fESDEvent->GetFMDData();
bf000c32 384 if (!fESD) return kFALSE;
7003fbd0 385#if 0
97b4001e 386 TFile* f = fChainE->GetFile();
387 if (f) {
388 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
389 if (o) {
390 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
391 std::cout << "AliFMDMap class version read is "
392 << info->GetClassVersion() << std::endl;
393 }
394 }
395 // fESD->CheckNeedUShort(fChainE->GetFile());
7003fbd0 396#endif
bf000c32 397 }
7003fbd0 398
d760ea03 399 // Possibly load FMD Digit information
400 if (TESTBIT(fTreeMask, kRaw)) {
5cf05dbb 401 // AliInfo("Getting FMD raw data digits");
d760ea03 402 if (!fReader->NextEvent()) return kFALSE;
5cf05dbb 403 // AliFMDRawReader r(fReader, 0);
d760ea03 404 fArrayA->Clear();
5cf05dbb 405 fFMDReader->ReadAdcs(fArrayA);
59194467 406 AliFMDDebug(1, ("Got a total of %d digits", fArrayA->GetEntriesFast()));
d760ea03 407 }
69893a66 408 fEventCount++;
bf000c32 409 return kTRUE;
410}
411
412
413//____________________________________________________________________
414Bool_t
415AliFMDInput::Event()
416{
417 // Process one event. The default implementation one or more of
418 //
419 // - ProcessHits if the hits are loaded.
420 // - ProcessDigits if the digits are loaded.
421 // - ProcessSDigits if the sumbable digits are loaded.
422 // - ProcessRecPoints if the reconstructed points are loaded.
423 // - ProcessESD if the event summary data is loaded
424 //
425 if (TESTBIT(fTreeMask, kHits))
426 if (!ProcessHits()) return kFALSE;
08d168d9 427 if (TESTBIT(fTreeMask, kTrackRefs))
428 if (!ProcessTrackRefs()) return kFALSE;
f95a63c4 429 if (TESTBIT(fTreeMask, kTracks))
430 if (!ProcessTracks()) return kFALSE;
bf000c32 431 if (TESTBIT(fTreeMask, kDigits))
432 if (!ProcessDigits()) return kFALSE;
433 if (TESTBIT(fTreeMask, kSDigits))
434 if (!ProcessSDigits()) return kFALSE;
d760ea03 435 if (TESTBIT(fTreeMask, kRaw))
436 if (!ProcessRawDigits()) return kFALSE;
bf000c32 437 if (TESTBIT(fTreeMask, kRecPoints))
438 if (!ProcessRecPoints()) return kFALSE;
439 if (TESTBIT(fTreeMask, kESD))
a9579262 440 if (!ProcessESDs()) return kFALSE;
bf000c32 441
442 return kTRUE;
443}
444
445//____________________________________________________________________
446Bool_t
447AliFMDInput::ProcessHits()
448{
02a27b50 449 // Read the hit tree, and pass each hit to the member function
450 // ProcessHit.
bf000c32 451 if (!fTreeH) {
452 AliError("No hit tree defined");
453 return kFALSE;
454 }
ddaa8027 455 if (!fArrayH) {
456 AliError("No hit array defined");
457 return kFALSE;
458 }
459
bf000c32 460 Int_t nTracks = fTreeH->GetEntries();
461 for (Int_t i = 0; i < nTracks; i++) {
462 Int_t hitRead = fTreeH->GetEntry(i);
463 if (hitRead <= 0) continue;
ddaa8027 464
bf000c32 465 Int_t nHit = fArrayH->GetEntries();
466 if (nHit <= 0) continue;
ddaa8027 467
bf000c32 468 for (Int_t j = 0; j < nHit; j++) {
469 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
470 if (!hit) continue;
ddaa8027 471
bf000c32 472 TParticle* track = 0;
473 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
474 Int_t trackno = hit->Track();
475 track = fStack->Particle(trackno);
476 }
477 if (!ProcessHit(hit, track)) return kFALSE;
478 }
479 }
480 return kTRUE;
481}
08d168d9 482//____________________________________________________________________
483Bool_t
484AliFMDInput::ProcessTrackRefs()
485{
486 // Read the reconstrcted points tree, and pass each reconstruction
487 // object (AliFMDRecPoint) to either ProcessRecPoint.
488 if (!fTreeTR) {
489 AliError("No track reference tree defined");
490 return kFALSE;
491 }
492 if (!fArrayTR) {
493 AliError("No track reference array defined");
494 return kFALSE;
495 }
bf000c32 496
08d168d9 497 Int_t nEv = fTreeTR->GetEntries();
498 for (Int_t i = 0; i < nEv; i++) {
499 Int_t trRead = fTreeTR->GetEntry(i);
500 if (trRead <= 0) continue;
501 Int_t nTrackRefs = fArrayTR->GetEntries();
502 for (Int_t j = 0; j < nTrackRefs; j++) {
503 AliTrackReference* trackRef = static_cast<AliTrackReference*>(fArrayTR->At(j));
504 if (!trackRef) continue;
505 if (trackRef->DetectorId() != AliTrackReference::kFMD) continue;
506 TParticle* track = 0;
507 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
508 Int_t trackno = trackRef->GetTrack();
509 track = fStack->Particle(trackno);
510 }
511 if (!ProcessTrackRef(trackRef,track)) return kFALSE;
512 }
513 }
514 return kTRUE;
515}
f95a63c4 516//____________________________________________________________________
517Bool_t
518AliFMDInput::ProcessTracks()
519{
520 // Read the hit tree, and pass each hit to the member function
ddaa8027 521 // ProcessTrack.
f95a63c4 522 if (!fStack) {
523 AliError("No track tree defined");
524 return kFALSE;
525 }
526 if (!fTreeH) {
527 AliError("No hit tree defined");
528 return kFALSE;
529 }
ddaa8027 530 if (!fArrayH) {
531 AliError("No hit array defined");
532 return kFALSE;
533 }
534
535 // Int_t nTracks = fStack->GetNtrack();
f95a63c4 536 Int_t nTracks = fTreeH->GetEntries();
537 for (Int_t i = 0; i < nTracks; i++) {
ddaa8027 538 Int_t trackno = nTracks - i - 1;
539 TParticle* track = fStack->Particle(trackno);
f95a63c4 540 if (!track) continue;
ddaa8027 541
542 // Get the hits for this track.
f95a63c4 543 Int_t hitRead = fTreeH->GetEntry(i);
ddaa8027 544 Int_t nHit = fArrayH->GetEntries();
545 if (nHit == 0 || hitRead <= 0) {
546 // Let user code see the track, even if there's no hits.
547 if (!ProcessTrack(trackno, track, 0)) return kFALSE;
548 continue;
f95a63c4 549 }
f95a63c4 550
ddaa8027 551 // Loop over the hits corresponding to this track.
f95a63c4 552 for (Int_t j = 0; j < nHit; j++) {
553 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
ddaa8027 554 if (!ProcessTrack(trackno, track, hit)) return kFALSE;
555 }
f95a63c4 556 }
557 return kTRUE;
558}
559
bf000c32 560//____________________________________________________________________
561Bool_t
562AliFMDInput::ProcessDigits()
563{
564 // Read the digit tree, and pass each digit to the member function
565 // ProcessDigit.
42f1b2f5 566 if (!fTreeD) {
567 AliError("No digit tree defined");
568 return kFALSE;
569 }
570 if (!fArrayD) {
571 AliError("No digit array defined");
572 return kFALSE;
573 }
574
bf000c32 575 Int_t nEv = fTreeD->GetEntries();
576 for (Int_t i = 0; i < nEv; i++) {
577 Int_t digitRead = fTreeD->GetEntry(i);
578 if (digitRead <= 0) continue;
579 Int_t nDigit = fArrayD->GetEntries();
42f1b2f5 580 AliFMDDebug(0, ("Got %5d digits for this event", nDigit));
bf000c32 581 if (nDigit <= 0) continue;
582 for (Int_t j = 0; j < nDigit; j++) {
583 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
584 if (!digit) continue;
585 if (!ProcessDigit(digit)) return kFALSE;
586 }
587 }
588 return kTRUE;
589}
590
591//____________________________________________________________________
592Bool_t
593AliFMDInput::ProcessSDigits()
594{
595 // Read the summable digit tree, and pass each sumable digit to the
596 // member function ProcessSdigit.
42f1b2f5 597 if (!fTreeS) {
598 AliWarning("No sdigit tree defined");
599 return kTRUE; // Empty SDigits is fine
600 }
601 if (!fArrayS) {
602 AliWarning("No sdigit array defined");
603 return kTRUE; // Empty SDigits is fine
604 }
605
606 Int_t nEv = fTreeS->GetEntries();
bf000c32 607 for (Int_t i = 0; i < nEv; i++) {
608 Int_t sdigitRead = fTreeS->GetEntry(i);
609 if (sdigitRead <= 0) continue;
610 Int_t nSdigit = fArrayS->GetEntries();
42f1b2f5 611 AliFMDDebug(0, ("Got %5d digits for this event", nSdigit));
bf000c32 612 if (nSdigit <= 0) continue;
613 for (Int_t j = 0; j < nSdigit; j++) {
614 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
615 if (!sdigit) continue;
616 if (!ProcessSDigit(sdigit)) return kFALSE;
617 }
618 }
619 return kTRUE;
620}
621
d760ea03 622//____________________________________________________________________
623Bool_t
624AliFMDInput::ProcessRawDigits()
625{
626 // Read the digit tree, and pass each digit to the member function
627 // ProcessDigit.
42f1b2f5 628 if (!fArrayA) {
629 AliError("No raw digit array defined");
630 return kFALSE;
631 }
632
d760ea03 633 Int_t nDigit = fArrayA->GetEntries();
634 if (nDigit <= 0) return kTRUE;
635 for (Int_t j = 0; j < nDigit; j++) {
636 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
637 if (!digit) continue;
59194467 638 if (AliLog::GetDebugLevel("FMD","") >= 40 && j < 30)
639 digit->Print();
d760ea03 640 if (!ProcessRawDigit(digit)) return kFALSE;
641 }
642 return kTRUE;
643}
644
bf000c32 645//____________________________________________________________________
646Bool_t
647AliFMDInput::ProcessRecPoints()
648{
649 // Read the reconstrcted points tree, and pass each reconstruction
650 // object (AliFMDRecPoint) to either ProcessRecPoint.
42f1b2f5 651 if (!fTreeR) {
652 AliError("No recpoint tree defined");
653 return kFALSE;
654 }
655 if (!fArrayR) {
656 AliError("No recpoints array defined");
657 return kFALSE;
658 }
659
bf000c32 660 Int_t nEv = fTreeR->GetEntries();
661 for (Int_t i = 0; i < nEv; i++) {
662 Int_t recRead = fTreeR->GetEntry(i);
663 if (recRead <= 0) continue;
664 Int_t nRecPoint = fArrayR->GetEntries();
665 for (Int_t j = 0; j < nRecPoint; j++) {
666 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
667 if (!recPoint) continue;
668 if (!ProcessRecPoint(recPoint)) return kFALSE;
669 }
a1f80595 670 }
671 return kTRUE;
672}
673
a9579262 674//____________________________________________________________________
675Bool_t
676AliFMDInput::ProcessESDs()
677{
678 // Process event summary data
679 if (!fESD) return kFALSE;
680 for (UShort_t det = 1; det <= 3; det++) {
681 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
682 for (Char_t* rng = rings; *rng != '\0'; rng++) {
683 UShort_t nsec = (*rng == 'I' ? 20 : 40);
684 UShort_t nstr = (*rng == 'I' ? 512 : 256);
685 for (UShort_t sec = 0; sec < nsec; sec++) {
686 for (UShort_t str = 0; str < nstr; str++) {
687 Float_t eta = fESD->Eta(det,*rng,sec,str);
688 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
97b4001e 689 if (!fESD->IsAngleCorrected())
690 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
a9579262 691 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
692 }
693 }
694 }
695 }
696 return kTRUE;
697}
698
a1f80595 699//____________________________________________________________________
700Bool_t
701AliFMDInput::End()
702{
703 // Called at the end of each event. Per default, it unloads the
704 // data trees and resets the pointers to the output arrays. Users
705 // can overload this, but should call this member function in the
706 // overloaded member function of the derived class.
707
708 // Check if we have been initialized
709 if (!fIsInit) {
710 AliError("Not initialized");
711 return fIsInit;
712 }
713 // Possibly unload global kinematics information
f95a63c4 714 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
a1f80595 715 fLoader->UnloadKinematics();
716 // fTreeK = 0;
717 fStack = 0;
718 }
719 // Possibly unload FMD Hit information
f95a63c4 720 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
a1f80595 721 fFMDLoader->UnloadHits();
722 fTreeH = 0;
723 }
724 // Possibly unload FMD Digit information
725 if (TESTBIT(fTreeMask, kDigits)) {
726 fFMDLoader->UnloadDigits();
727 fTreeD = 0;
728 }
729 // Possibly unload FMD Sdigit information
730 if (TESTBIT(fTreeMask, kSDigits)) {
731 fFMDLoader->UnloadSDigits();
732 fTreeS = 0;
733 }
734 // Possibly unload FMD RecPoints information
735 if (TESTBIT(fTreeMask, kRecPoints)) {
736 fFMDLoader->UnloadRecPoints();
737 fTreeR = 0;
738 }
f48d9b11 739 // AliInfo("Now out event");
a1f80595 740 return kTRUE;
741}
742
743//____________________________________________________________________
744Bool_t
745AliFMDInput::Run()
746{
747 // Run over all events and files references in galice.root
748
749 Bool_t retval;
750 if (!(retval = Init())) return retval;
751
752 Int_t nEvents = NEvents();
59194467 753 for (Int_t event = 0; nEvents < 0 || event < nEvents; event++) {
a1f80595 754 if (!(retval = Begin(event))) break;
755 if (!(retval = Event())) break;
756 if (!(retval = End())) break;
757 }
758 if (!retval) return retval;
759 retval = Finish();
760 return retval;
761}
762
69893a66 763//__________________________________________________________________
764TArrayF
765AliFMDInput::MakeLogScale(Int_t n, Double_t min, Double_t max)
766{
767 // Service function to define a logarithmic axis.
768 // Parameters:
769 // n Number of bins
770 // min Minimum of axis
771 // max Maximum of axis
772 TArrayF bins(n+1);
773 bins[0] = min;
774 if (n <= 20) {
775 for (Int_t i = 1; i < n+1; i++) bins[i] = bins[i-1] + (max-min)/n;
776 return bins;
777 }
778 Float_t dp = n / TMath::Log10(max / min);
779 Float_t pmin = TMath::Log10(min);
780 for (Int_t i = 1; i < n+1; i++) {
781 Float_t p = pmin + i / dp;
782 bins[i] = TMath::Power(10, p);
783 }
784 return bins;
785}
786
787
a1f80595 788
a1f80595 789//____________________________________________________________________
790//
791// EOF
792//