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