1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
21 //___________________________________________________________________
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.
29 // Latest changes by Christian Holm Christensen
31 #include "AliFMDInput.h" // ALIFMDHIT_H
32 #include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
33 #include "AliLoader.h" // ALILOADER_H
34 #include "AliRunLoader.h" // ALIRUNLOADER_H
35 #include "AliRun.h" // ALIRUN_H
36 #include "AliStack.h" // ALISTACK_H
37 #include "AliRawReaderFile.h" // ALIRAWREADERFILE_H
38 #include "AliFMD.h" // ALIFMD_H
39 #include "AliFMDHit.h" // ALIFMDHIT_H
40 #include "AliFMDDigit.h" // ALIFMDDigit_H
41 #include "AliFMDSDigit.h" // ALIFMDDigit_H
42 #include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
43 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
45 #include <AliESDFMD.h>
46 #include <AliESDEvent.h>
47 #include <AliCDBManager.h>
48 #include <AliCDBEntry.h>
49 #include <AliAlignObjParams.h>
50 #include <TTree.h> // ROOT_TTree
51 #include <TChain.h> // ROOT_TChain
52 #include <TParticle.h> // ROOT_TParticle
53 #include <TString.h> // ROOT_TString
54 #include <TDatabasePDG.h> // ROOT_TDatabasePDG
55 #include <TMath.h> // ROOT_TMath
56 #include <TGeoManager.h> // ROOT_TGeoManager
57 #include <TSystemDirectory.h> // ROOT_TSystemDirectory
58 #include <Riostream.h> // ROOT_Riostream
59 #include <TFile.h> // ROOT_TFile
60 #include <TStreamerInfo.h>
63 //____________________________________________________________________
66 ; // This is here to keep Emacs for indenting the next line
70 //____________________________________________________________________
71 AliFMDInput::AliFMDInput()
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.
107 //____________________________________________________________________
108 AliFMDInput::AliFMDInput(const char* gAliceFile)
109 : fGAliceFile(gAliceFile),
136 // Constructor of an FMD input object. Specify what data to read in
137 // using the AddLoad member function. Sub-classes should at a
138 // minimum overload the member function Event. A full job can be
139 // executed using the member function Run.
142 //____________________________________________________________________
144 AliFMDInput::NEvents() const
146 // Get number of events
147 if (fTreeE) return fTreeE->GetEntries();
151 //____________________________________________________________________
155 // Initialize the object. Get the needed loaders, and such.
157 // Check if we have been initialized
159 AliWarning("Already initialized");
162 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
164 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
166 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
171 if (fLoader->LoadgAlice()) return kFALSE;
172 fRun = fLoader->GetAliRun();
175 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
177 AliError("Failed to get detector FMD from loader");
181 // Get the FMD loader
182 fFMDLoader = fLoader->GetLoader("FMDLoader");
184 AliError("Failed to get detector FMD loader from loader");
187 if (fLoader->LoadHeader()) {
188 AliError("Failed to get event header information from loader");
191 fTreeE = fLoader->TreeE();
193 // Optionally, get the ESD files
194 if (TESTBIT(fTreeMask, kESD)) {
195 fChainE = new TChain("esdTree");
196 TSystemDirectory dir(".",".");
197 TList* files = dir.GetListOfFiles();
198 TSystemFile* file = 0;
200 AliError("No files");
205 while ((file = static_cast<TSystemFile*>(next()))) {
206 TString fname(file->GetName());
207 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
209 fESDEvent = new AliESDEvent();
210 fESDEvent->ReadFromTree(fChainE);
211 // fChainE->SetBranchAddress("ESD", &fMainESD);
215 if (TESTBIT(fTreeMask, kRaw)) {
216 AliInfo("Getting FMD raw data digits");
217 fArrayA = new TClonesArray("AliFMDDigit");
218 fReader = new AliRawReaderFile(-1);
221 // Optionally, get the geometry
222 if (TESTBIT(fTreeMask, kGeometry)) {
223 TString fname(fRun->GetGeometryFileName());
224 if (fname.IsNull()) {
225 Warning("Init", "No file name for the geometry from AliRun");
226 fname = gSystem->DirName(fGAliceFile);
227 fname.Append("/geometry.root");
229 fGeoManager = TGeoManager::Import(fname.Data());
231 Fatal("Init", "No geometry manager found");
234 AliCDBManager* cdb = AliCDBManager::Instance();
235 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
237 AliInfo("Got alignment data from CDB");
238 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
240 AliWarning("Invalid align data from CDB");
243 Int_t nAlign = array->GetEntries();
244 for (Int_t i = 0; i < nAlign; i++) {
245 AliAlignObjParams* a = static_cast<AliAlignObjParams*>(array->At(i));
246 if (!a->ApplyToGeometry()) {
247 AliWarning(Form("Failed to apply alignment to %s",
260 //____________________________________________________________________
262 AliFMDInput::Begin(Int_t event)
264 // Called at the begining of each event. Per default, it gets the
265 // data trees and gets pointers to the output arrays. Users can
266 // overload this, but should call this member function in the
267 // overloaded member function of the derived class.
269 // Check if we have been initialized
271 AliError("Not initialized");
276 if (fLoader->GetEvent(event)) return kFALSE;
277 AliInfo(Form("Now in event %8d/%8d", event, NEvents()));
279 // Possibly load global kinematics information
280 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
281 // AliInfo("Getting kinematics");
282 if (fLoader->LoadKinematics()) return kFALSE;
283 fStack = fLoader->Stack();
286 // Possibly load FMD Hit information
287 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
288 // AliInfo("Getting FMD hits");
289 if (!fFMDLoader || fFMDLoader->LoadHits()) return kFALSE;
290 fTreeH = fFMDLoader->TreeH();
291 if (!fArrayH) fArrayH = fFMD->Hits();
294 // Possibly load FMD Digit information
295 if (TESTBIT(fTreeMask, kDigits)) {
296 // AliInfo("Getting FMD digits");
297 if (!fFMDLoader || fFMDLoader->LoadDigits()) return kFALSE;
298 fTreeD = fFMDLoader->TreeD();
300 if (!fArrayD) fArrayD = fFMD->Digits();
304 AliWarning(Form("Failed to load FMD Digits"));
308 // Possibly load FMD Sdigit information
309 if (TESTBIT(fTreeMask, kSDigits)) {
310 // AliInfo("Getting FMD summable digits");
311 if (!fFMDLoader || fFMDLoader->LoadSDigits()) return kFALSE;
312 fTreeS = fFMDLoader->TreeS();
313 if (!fArrayS) fArrayS = fFMD->SDigits();
316 // Possibly load FMD RecPoints information
317 if (TESTBIT(fTreeMask, kRecPoints)) {
318 // AliInfo("Getting FMD reconstructed points");
319 if (!fFMDLoader || fFMDLoader->LoadRecPoints()) return kFALSE;
320 fTreeR = fFMDLoader->TreeR();
321 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
322 fTreeR->SetBranchAddress("FMD", &fArrayR);
325 // Possibly load FMD ESD information
326 if (TESTBIT(fTreeMask, kESD)) {
327 // AliInfo("Getting FMD event summary data");
328 Int_t read = fChainE->GetEntry(event);
329 if (read <= 0) return kFALSE;
330 fESD = fESDEvent->GetFMDData();
331 if (!fESD) return kFALSE;
333 TFile* f = fChainE->GetFile();
335 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
337 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
338 std::cout << "AliFMDMap class version read is "
339 << info->GetClassVersion() << std::endl;
342 // fESD->CheckNeedUShort(fChainE->GetFile());
346 // Possibly load FMD Digit information
347 if (TESTBIT(fTreeMask, kRaw)) {
348 // AliInfo("Getting FMD raw data digits");
349 if (!fReader->NextEvent()) return kFALSE;
350 AliFMDRawReader r(fReader, 0);
359 //____________________________________________________________________
363 // Process one event. The default implementation one or more of
365 // - ProcessHits if the hits are loaded.
366 // - ProcessDigits if the digits are loaded.
367 // - ProcessSDigits if the sumbable digits are loaded.
368 // - ProcessRecPoints if the reconstructed points are loaded.
369 // - ProcessESD if the event summary data is loaded
371 if (TESTBIT(fTreeMask, kHits))
372 if (!ProcessHits()) return kFALSE;
373 if (TESTBIT(fTreeMask, kTracks))
374 if (!ProcessTracks()) return kFALSE;
375 if (TESTBIT(fTreeMask, kDigits))
376 if (!ProcessDigits()) return kFALSE;
377 if (TESTBIT(fTreeMask, kSDigits))
378 if (!ProcessSDigits()) return kFALSE;
379 if (TESTBIT(fTreeMask, kRaw))
380 if (!ProcessRawDigits()) return kFALSE;
381 if (TESTBIT(fTreeMask, kRecPoints))
382 if (!ProcessRecPoints()) return kFALSE;
383 if (TESTBIT(fTreeMask, kESD))
384 if (!ProcessESDs()) return kFALSE;
389 //____________________________________________________________________
391 AliFMDInput::ProcessHits()
393 // Read the hit tree, and pass each hit to the member function
396 AliError("No hit tree defined");
399 Int_t nTracks = fTreeH->GetEntries();
400 for (Int_t i = 0; i < nTracks; i++) {
401 Int_t hitRead = fTreeH->GetEntry(i);
402 if (hitRead <= 0) continue;
404 AliError("No hit array defined");
407 Int_t nHit = fArrayH->GetEntries();
408 if (nHit <= 0) continue;
409 for (Int_t j = 0; j < nHit; j++) {
410 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
412 TParticle* track = 0;
413 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
414 Int_t trackno = hit->Track();
415 track = fStack->Particle(trackno);
417 if (!ProcessHit(hit, track)) return kFALSE;
423 //____________________________________________________________________
425 AliFMDInput::ProcessTracks()
427 // Read the hit tree, and pass each hit to the member function
430 AliError("No track tree defined");
434 AliError("No hit tree defined");
437 Int_t nTracks = fTreeH->GetEntries();
438 for (Int_t i = 0; i < nTracks; i++) {
439 TParticle* track = fStack->Particle(i);
440 if (!track) continue;
441 Int_t hitRead = fTreeH->GetEntry(i);
442 if (hitRead <= 0) continue;
444 AliError("No hit array defined");
447 Int_t nHit = fArrayH->GetEntries();
448 if (nHit <= 0) continue;
450 for (Int_t j = 0; j < nHit; j++) {
451 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
453 if (!ProcessTrack(i, track, hit)) return kFALSE;
455 // if (!ProcessTrack(i, track, fArrayH)) return kFALSE;
460 //____________________________________________________________________
462 AliFMDInput::ProcessDigits()
464 // Read the digit tree, and pass each digit to the member function
466 Int_t nEv = fTreeD->GetEntries();
467 for (Int_t i = 0; i < nEv; i++) {
468 Int_t digitRead = fTreeD->GetEntry(i);
469 if (digitRead <= 0) continue;
470 Int_t nDigit = fArrayD->GetEntries();
471 if (nDigit <= 0) continue;
472 for (Int_t j = 0; j < nDigit; j++) {
473 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
474 if (!digit) continue;
475 if (!ProcessDigit(digit)) return kFALSE;
481 //____________________________________________________________________
483 AliFMDInput::ProcessSDigits()
485 // Read the summable digit tree, and pass each sumable digit to the
486 // member function ProcessSdigit.
487 Int_t nEv = fTreeD->GetEntries();
488 for (Int_t i = 0; i < nEv; i++) {
489 Int_t sdigitRead = fTreeS->GetEntry(i);
490 if (sdigitRead <= 0) continue;
491 Int_t nSdigit = fArrayS->GetEntries();
492 if (nSdigit <= 0) continue;
493 for (Int_t j = 0; j < nSdigit; j++) {
494 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
495 if (!sdigit) continue;
496 if (!ProcessSDigit(sdigit)) return kFALSE;
502 //____________________________________________________________________
504 AliFMDInput::ProcessRawDigits()
506 // Read the digit tree, and pass each digit to the member function
508 Int_t nDigit = fArrayA->GetEntries();
509 if (nDigit <= 0) return kTRUE;
510 for (Int_t j = 0; j < nDigit; j++) {
511 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
512 if (!digit) continue;
513 if (!ProcessRawDigit(digit)) return kFALSE;
518 //____________________________________________________________________
520 AliFMDInput::ProcessRecPoints()
522 // Read the reconstrcted points tree, and pass each reconstruction
523 // object (AliFMDRecPoint) to either ProcessRecPoint.
524 Int_t nEv = fTreeR->GetEntries();
525 for (Int_t i = 0; i < nEv; i++) {
526 Int_t recRead = fTreeR->GetEntry(i);
527 if (recRead <= 0) continue;
528 Int_t nRecPoint = fArrayR->GetEntries();
529 for (Int_t j = 0; j < nRecPoint; j++) {
530 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
531 if (!recPoint) continue;
532 if (!ProcessRecPoint(recPoint)) return kFALSE;
538 //____________________________________________________________________
540 AliFMDInput::ProcessESDs()
542 // Process event summary data
543 if (!fESD) return kFALSE;
544 for (UShort_t det = 1; det <= 3; det++) {
545 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
546 for (Char_t* rng = rings; *rng != '\0'; rng++) {
547 UShort_t nsec = (*rng == 'I' ? 20 : 40);
548 UShort_t nstr = (*rng == 'I' ? 512 : 256);
549 for (UShort_t sec = 0; sec < nsec; sec++) {
550 for (UShort_t str = 0; str < nstr; str++) {
551 Float_t eta = fESD->Eta(det,*rng,sec,str);
552 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
553 if (!fESD->IsAngleCorrected())
554 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
555 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
563 //____________________________________________________________________
567 // Called at the end of each event. Per default, it unloads the
568 // data trees and resets the pointers to the output arrays. Users
569 // can overload this, but should call this member function in the
570 // overloaded member function of the derived class.
572 // Check if we have been initialized
574 AliError("Not initialized");
577 // Possibly unload global kinematics information
578 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
579 fLoader->UnloadKinematics();
583 // Possibly unload FMD Hit information
584 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
585 fFMDLoader->UnloadHits();
588 // Possibly unload FMD Digit information
589 if (TESTBIT(fTreeMask, kDigits)) {
590 fFMDLoader->UnloadDigits();
593 // Possibly unload FMD Sdigit information
594 if (TESTBIT(fTreeMask, kSDigits)) {
595 fFMDLoader->UnloadSDigits();
598 // Possibly unload FMD RecPoints information
599 if (TESTBIT(fTreeMask, kRecPoints)) {
600 fFMDLoader->UnloadRecPoints();
603 AliInfo("Now out event");
607 //____________________________________________________________________
611 // Run over all events and files references in galice.root
614 if (!(retval = Init())) return retval;
616 Int_t nEvents = NEvents();
617 for (Int_t event = 0; event < nEvents; event++) {
618 if (!(retval = Begin(event))) break;
619 if (!(retval = Event())) break;
620 if (!(retval = End())) break;
622 if (!retval) return retval;
627 //__________________________________________________________________
629 AliFMDInput::MakeLogScale(Int_t n, Double_t min, Double_t max)
631 // Service function to define a logarithmic axis.
634 // min Minimum of axis
635 // max Maximum of axis
639 for (Int_t i = 1; i < n+1; i++) bins[i] = bins[i-1] + (max-min)/n;
642 Float_t dp = n / TMath::Log10(max / min);
643 Float_t pmin = TMath::Log10(min);
644 for (Int_t i = 1; i < n+1; i++) {
645 Float_t p = pmin + i / dp;
646 bins[i] = TMath::Power(10, p);
653 //____________________________________________________________________