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 "AliRawReaderRoot.h" // ALIRAWREADERROOT_H
39 #include "AliRawReaderDate.h" // ALIRAWREADERDATE_H
40 #include "AliFMD.h" // ALIFMD_H
41 #include "AliFMDHit.h" // ALIFMDHIT_H
42 #include "AliFMDDigit.h" // ALIFMDDigit_H
43 #include "AliFMDSDigit.h" // ALIFMDDigit_H
44 #include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
45 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
47 #include <AliESDFMD.h>
48 #include <AliESDEvent.h>
49 #include <AliCDBManager.h>
50 #include <AliCDBEntry.h>
51 #include <AliAlignObjParams.h>
52 #include <TTree.h> // ROOT_TTree
53 #include <TChain.h> // ROOT_TChain
54 #include <TParticle.h> // ROOT_TParticle
55 #include <TString.h> // ROOT_TString
56 #include <TDatabasePDG.h> // ROOT_TDatabasePDG
57 #include <TMath.h> // ROOT_TMath
58 #include <TGeoManager.h> // ROOT_TGeoManager
59 #include <TSystemDirectory.h> // ROOT_TSystemDirectory
60 #include <Riostream.h> // ROOT_Riostream
61 #include <TFile.h> // ROOT_TFile
62 #include <TStreamerInfo.h>
65 //____________________________________________________________________
68 ; // This is here to keep Emacs for indenting the next line
72 //____________________________________________________________________
73 AliFMDInput::AliFMDInput()
74 : TNamed("AliFMDInput", "Input handler for various FMD data"),
105 // Constructor of an FMD input object. Specify what data to read in
106 // using the AddLoad member function. Sub-classes should at a
107 // minimum overload the member function Event. A full job can be
108 // executed using the member function Run.
113 //____________________________________________________________________
114 AliFMDInput::AliFMDInput(const char* gAliceFile)
115 : TNamed("AliFMDInput", "Input handler for various FMD data"),
116 fGAliceFile(gAliceFile),
146 // Constructor of an FMD input object. Specify what data to read in
147 // using the AddLoad member function. Sub-classes should at a
148 // minimum overload the member function Event. A full job can be
149 // executed using the member function Run.
152 //____________________________________________________________________
154 AliFMDInput::NEvents() const
156 // Get number of events
157 if (TESTBIT(fTreeMask, kRaw)) return -1;
158 if (fTreeE) return fTreeE->GetEntries();
162 //____________________________________________________________________
166 // Initialize the object. Get the needed loaders, and such.
168 // Check if we have been initialized
170 AliWarning("Already initialized");
174 if (!TESTBIT(fTreeMask, kRaw)) {
175 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
177 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
179 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
183 if (fLoader->LoadgAlice()) return kFALSE;
184 fRun = fLoader->GetAliRun();
187 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
189 AliError("Failed to get detector FMD from loader");
193 // Get the FMD loader
194 fFMDLoader = fLoader->GetLoader("FMDLoader");
196 AliError("Failed to get detector FMD loader from loader");
199 if (fLoader->LoadHeader()) {
200 AliError("Failed to get event header information from loader");
203 fTreeE = fLoader->TreeE();
206 // Optionally, get the ESD files
207 if (TESTBIT(fTreeMask, kESD)) {
208 fChainE = new TChain("esdTree");
209 TSystemDirectory dir(".",".");
210 TList* files = dir.GetListOfFiles();
211 TSystemFile* file = 0;
213 AliError("No files");
218 while ((file = static_cast<TSystemFile*>(next()))) {
219 TString fname(file->GetName());
220 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
222 fESDEvent = new AliESDEvent();
223 fESDEvent->ReadFromTree(fChainE);
224 // fChainE->SetBranchAddress("ESD", &fMainESD);
228 if (TESTBIT(fTreeMask, kRaw)) {
229 AliInfo("Getting FMD raw data digits");
230 fArrayA = new TClonesArray("AliFMDDigit");
232 if (!fRawFile.IsNull() && fRawFile.EndsWith(".root"))
233 fReader = new AliRawReaderRoot(fRawFile.Data());
234 else if (!fRawFile.IsNull() && fRawFile.EndsWith(".raw"))
235 fReader = new AliRawReaderDate(fRawFile.Data());
237 fReader = new AliRawReaderFile(-1);
239 if(!fRawFile.IsNull())
240 fReader = AliRawReader::Create(fRawFile.Data());
242 fReader = new AliRawReaderFile(-1);
246 // Optionally, get the geometry
247 if (TESTBIT(fTreeMask, kGeometry)) {
249 TString fname(fRun->GetGeometryFileName());
250 if (fname.IsNull()) {
251 Warning("Init", "No file name for the geometry from AliRun");
252 fname = gSystem->DirName(fGAliceFile);
253 fname.Append("/geometry.root");
255 fGeoManager = TGeoManager::Import(fname.Data());
257 Fatal("Init", "No geometry manager found");
262 AliGeomManager::LoadGeometry();
264 AliCDBManager* cdb = AliCDBManager::Instance();
265 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
267 AliInfo("Got alignment data from CDB");
268 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
270 AliWarning("Invalid align data from CDB");
273 Int_t nAlign = array->GetEntries();
274 for (Int_t i = 0; i < nAlign; i++) {
275 AliAlignObjParams* a = static_cast<AliAlignObjParams*>(array->At(i));
276 if (!a->ApplyToGeometry()) {
277 AliWarning(Form("Failed to apply alignment to %s",
290 //____________________________________________________________________
292 AliFMDInput::Begin(Int_t event)
294 // Called at the begining of each event. Per default, it gets the
295 // data trees and gets pointers to the output arrays. Users can
296 // overload this, but should call this member function in the
297 // overloaded member function of the derived class.
299 // Check if we have been initialized
301 AliError("Not initialized");
306 if (fLoader && fLoader->GetEvent(event)) return kFALSE;
307 AliInfo(Form("Now in event %8d/%8d", event, NEvents()));
309 // Possibly load global kinematics information
310 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
311 // AliInfo("Getting kinematics");
312 if (fLoader->LoadKinematics("READ")) return kFALSE;
313 fStack = fLoader->Stack();
316 // Possibly load FMD Hit information
317 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
318 // AliInfo("Getting FMD hits");
319 if (!fFMDLoader || fFMDLoader->LoadHits("READ")) return kFALSE;
320 fTreeH = fFMDLoader->TreeH();
321 if (!fArrayH) fArrayH = fFMD->Hits();
324 // Possibly load heaedr information
325 if (TESTBIT(fTreeMask, kHeader)) {
326 // AliInfo("Getting FMD hits");
327 if (!fLoader /* || fLoader->LoadHeader()*/) return kFALSE;
328 fHeader = fLoader->GetHeader();
331 // Possibly load FMD Digit information
332 if (TESTBIT(fTreeMask, kDigits)) {
333 // AliInfo("Getting FMD digits");
334 if (!fFMDLoader || fFMDLoader->LoadDigits("READ")) return kFALSE;
335 fTreeD = fFMDLoader->TreeD();
337 if (!fArrayD) fArrayD = fFMD->Digits();
341 AliWarning(Form("Failed to load FMD Digits"));
345 // Possibly load FMD Sdigit information
346 if (TESTBIT(fTreeMask, kSDigits)) {
347 // AliInfo("Getting FMD summable digits");
348 if (!fFMDLoader || fFMDLoader->LoadSDigits("READ")) return kFALSE;
349 fTreeS = fFMDLoader->TreeS();
350 if (!fArrayS) fArrayS = fFMD->SDigits();
353 // Possibly load FMD RecPoints information
354 if (TESTBIT(fTreeMask, kRecPoints)) {
355 // AliInfo("Getting FMD reconstructed points");
356 if (!fFMDLoader || fFMDLoader->LoadRecPoints("READ")) return kFALSE;
357 fTreeR = fFMDLoader->TreeR();
358 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
359 fTreeR->SetBranchAddress("FMD", &fArrayR);
362 // Possibly load FMD ESD information
363 if (TESTBIT(fTreeMask, kESD)) {
364 // AliInfo("Getting FMD event summary data");
365 Int_t read = fChainE->GetEntry(event);
366 if (read <= 0) return kFALSE;
367 fESD = fESDEvent->GetFMDData();
368 if (!fESD) return kFALSE;
370 TFile* f = fChainE->GetFile();
372 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
374 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
375 std::cout << "AliFMDMap class version read is "
376 << info->GetClassVersion() << std::endl;
379 // fESD->CheckNeedUShort(fChainE->GetFile());
383 // Possibly load FMD Digit information
384 if (TESTBIT(fTreeMask, kRaw)) {
385 AliInfo("Getting FMD raw data digits");
386 if (!fReader->NextEvent()) return kFALSE;
387 AliFMDRawReader r(fReader, 0);
390 AliFMDDebug(1, ("Got a total of %d digits", fArrayA->GetEntriesFast()));
397 //____________________________________________________________________
401 // Process one event. The default implementation one or more of
403 // - ProcessHits if the hits are loaded.
404 // - ProcessDigits if the digits are loaded.
405 // - ProcessSDigits if the sumbable digits are loaded.
406 // - ProcessRecPoints if the reconstructed points are loaded.
407 // - ProcessESD if the event summary data is loaded
409 if (TESTBIT(fTreeMask, kHits))
410 if (!ProcessHits()) return kFALSE;
411 if (TESTBIT(fTreeMask, kTracks))
412 if (!ProcessTracks()) return kFALSE;
413 if (TESTBIT(fTreeMask, kDigits))
414 if (!ProcessDigits()) return kFALSE;
415 if (TESTBIT(fTreeMask, kSDigits))
416 if (!ProcessSDigits()) return kFALSE;
417 if (TESTBIT(fTreeMask, kRaw))
418 if (!ProcessRawDigits()) return kFALSE;
419 if (TESTBIT(fTreeMask, kRecPoints))
420 if (!ProcessRecPoints()) return kFALSE;
421 if (TESTBIT(fTreeMask, kESD))
422 if (!ProcessESDs()) return kFALSE;
427 //____________________________________________________________________
429 AliFMDInput::ProcessHits()
431 // Read the hit tree, and pass each hit to the member function
434 AliError("No hit tree defined");
438 AliError("No hit array defined");
442 Int_t nTracks = fTreeH->GetEntries();
443 for (Int_t i = 0; i < nTracks; i++) {
444 Int_t hitRead = fTreeH->GetEntry(i);
445 if (hitRead <= 0) continue;
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));
454 TParticle* track = 0;
455 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
456 Int_t trackno = hit->Track();
457 track = fStack->Particle(trackno);
459 if (!ProcessHit(hit, track)) return kFALSE;
465 //____________________________________________________________________
467 AliFMDInput::ProcessTracks()
469 // Read the hit tree, and pass each hit to the member function
472 AliError("No track tree defined");
476 AliError("No hit tree defined");
480 AliError("No hit array defined");
484 // Int_t nTracks = fStack->GetNtrack();
485 Int_t nTracks = fTreeH->GetEntries();
486 for (Int_t i = 0; i < nTracks; i++) {
487 Int_t trackno = nTracks - i - 1;
488 TParticle* track = fStack->Particle(trackno);
489 if (!track) continue;
491 // Get the hits for this track.
492 Int_t hitRead = fTreeH->GetEntry(i);
493 Int_t nHit = fArrayH->GetEntries();
494 if (nHit == 0 || hitRead <= 0) {
495 // Let user code see the track, even if there's no hits.
496 if (!ProcessTrack(trackno, track, 0)) return kFALSE;
500 // Loop over the hits corresponding to this track.
501 for (Int_t j = 0; j < nHit; j++) {
502 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
503 if (!ProcessTrack(trackno, track, hit)) return kFALSE;
509 //____________________________________________________________________
511 AliFMDInput::ProcessDigits()
513 // Read the digit tree, and pass each digit to the member function
516 AliError("No digit tree defined");
520 AliError("No digit array defined");
524 Int_t nEv = fTreeD->GetEntries();
525 for (Int_t i = 0; i < nEv; i++) {
526 Int_t digitRead = fTreeD->GetEntry(i);
527 if (digitRead <= 0) continue;
528 Int_t nDigit = fArrayD->GetEntries();
529 AliFMDDebug(0, ("Got %5d digits for this event", nDigit));
530 if (nDigit <= 0) continue;
531 for (Int_t j = 0; j < nDigit; j++) {
532 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
533 if (!digit) continue;
534 if (!ProcessDigit(digit)) return kFALSE;
540 //____________________________________________________________________
542 AliFMDInput::ProcessSDigits()
544 // Read the summable digit tree, and pass each sumable digit to the
545 // member function ProcessSdigit.
547 AliWarning("No sdigit tree defined");
548 return kTRUE; // Empty SDigits is fine
551 AliWarning("No sdigit array defined");
552 return kTRUE; // Empty SDigits is fine
555 Int_t nEv = fTreeS->GetEntries();
556 for (Int_t i = 0; i < nEv; i++) {
557 Int_t sdigitRead = fTreeS->GetEntry(i);
558 if (sdigitRead <= 0) continue;
559 Int_t nSdigit = fArrayS->GetEntries();
560 AliFMDDebug(0, ("Got %5d digits for this event", nSdigit));
561 if (nSdigit <= 0) continue;
562 for (Int_t j = 0; j < nSdigit; j++) {
563 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
564 if (!sdigit) continue;
565 if (!ProcessSDigit(sdigit)) return kFALSE;
571 //____________________________________________________________________
573 AliFMDInput::ProcessRawDigits()
575 // Read the digit tree, and pass each digit to the member function
578 AliError("No raw digit array defined");
582 Int_t nDigit = fArrayA->GetEntries();
583 if (nDigit <= 0) return kTRUE;
584 for (Int_t j = 0; j < nDigit; j++) {
585 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
586 if (!digit) continue;
587 if (AliLog::GetDebugLevel("FMD","") >= 40 && j < 30)
589 if (!ProcessRawDigit(digit)) return kFALSE;
594 //____________________________________________________________________
596 AliFMDInput::ProcessRecPoints()
598 // Read the reconstrcted points tree, and pass each reconstruction
599 // object (AliFMDRecPoint) to either ProcessRecPoint.
601 AliError("No recpoint tree defined");
605 AliError("No recpoints array defined");
609 Int_t nEv = fTreeR->GetEntries();
610 for (Int_t i = 0; i < nEv; i++) {
611 Int_t recRead = fTreeR->GetEntry(i);
612 if (recRead <= 0) continue;
613 Int_t nRecPoint = fArrayR->GetEntries();
614 for (Int_t j = 0; j < nRecPoint; j++) {
615 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
616 if (!recPoint) continue;
617 if (!ProcessRecPoint(recPoint)) return kFALSE;
623 //____________________________________________________________________
625 AliFMDInput::ProcessESDs()
627 // Process event summary data
628 if (!fESD) return kFALSE;
629 for (UShort_t det = 1; det <= 3; det++) {
630 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
631 for (Char_t* rng = rings; *rng != '\0'; rng++) {
632 UShort_t nsec = (*rng == 'I' ? 20 : 40);
633 UShort_t nstr = (*rng == 'I' ? 512 : 256);
634 for (UShort_t sec = 0; sec < nsec; sec++) {
635 for (UShort_t str = 0; str < nstr; str++) {
636 Float_t eta = fESD->Eta(det,*rng,sec,str);
637 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
638 if (!fESD->IsAngleCorrected())
639 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
640 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
648 //____________________________________________________________________
652 // Called at the end of each event. Per default, it unloads the
653 // data trees and resets the pointers to the output arrays. Users
654 // can overload this, but should call this member function in the
655 // overloaded member function of the derived class.
657 // Check if we have been initialized
659 AliError("Not initialized");
662 // Possibly unload global kinematics information
663 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
664 fLoader->UnloadKinematics();
668 // Possibly unload FMD Hit information
669 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
670 fFMDLoader->UnloadHits();
673 // Possibly unload FMD Digit information
674 if (TESTBIT(fTreeMask, kDigits)) {
675 fFMDLoader->UnloadDigits();
678 // Possibly unload FMD Sdigit information
679 if (TESTBIT(fTreeMask, kSDigits)) {
680 fFMDLoader->UnloadSDigits();
683 // Possibly unload FMD RecPoints information
684 if (TESTBIT(fTreeMask, kRecPoints)) {
685 fFMDLoader->UnloadRecPoints();
688 // AliInfo("Now out event");
692 //____________________________________________________________________
696 // Run over all events and files references in galice.root
699 if (!(retval = Init())) return retval;
701 Int_t nEvents = NEvents();
702 for (Int_t event = 0; nEvents < 0 || event < nEvents; event++) {
703 if (!(retval = Begin(event))) break;
704 if (!(retval = Event())) break;
705 if (!(retval = End())) break;
707 if (!retval) return retval;
712 //__________________________________________________________________
714 AliFMDInput::MakeLogScale(Int_t n, Double_t min, Double_t max)
716 // Service function to define a logarithmic axis.
719 // min Minimum of axis
720 // max Maximum of axis
724 for (Int_t i = 1; i < n+1; i++) bins[i] = bins[i-1] + (max-min)/n;
727 Float_t dp = n / TMath::Log10(max / min);
728 Float_t pmin = TMath::Log10(min);
729 for (Int_t i = 1; i < n+1; i++) {
730 Float_t p = pmin + i / dp;
731 bins[i] = TMath::Power(10, p);
738 //____________________________________________________________________