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