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()
104 // Constructor of an FMD input object. Specify what data to read in
105 // using the AddLoad member function. Sub-classes should at a
106 // minimum overload the member function Event. A full job can be
107 // executed using the member function Run.
112 //____________________________________________________________________
113 AliFMDInput::AliFMDInput(const char* gAliceFile)
114 : fGAliceFile(gAliceFile),
144 // Constructor of an FMD input object. Specify what data to read in
145 // using the AddLoad member function. Sub-classes should at a
146 // minimum overload the member function Event. A full job can be
147 // executed using the member function Run.
150 //____________________________________________________________________
152 AliFMDInput::NEvents() const
154 // Get number of events
155 if (fTreeE) return fTreeE->GetEntries();
159 //____________________________________________________________________
163 // Initialize the object. Get the needed loaders, and such.
165 // Check if we have been initialized
167 AliWarning("Already initialized");
170 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
172 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
174 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
179 if (fLoader->LoadgAlice()) return kFALSE;
180 fRun = fLoader->GetAliRun();
183 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
185 AliError("Failed to get detector FMD from loader");
189 // Get the FMD loader
190 fFMDLoader = fLoader->GetLoader("FMDLoader");
192 AliError("Failed to get detector FMD loader from loader");
195 if (fLoader->LoadHeader()) {
196 AliError("Failed to get event header information from loader");
199 fTreeE = fLoader->TreeE();
201 // Optionally, get the ESD files
202 if (TESTBIT(fTreeMask, kESD)) {
203 fChainE = new TChain("esdTree");
204 TSystemDirectory dir(".",".");
205 TList* files = dir.GetListOfFiles();
206 TSystemFile* file = 0;
208 AliError("No files");
213 while ((file = static_cast<TSystemFile*>(next()))) {
214 TString fname(file->GetName());
215 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
217 fESDEvent = new AliESDEvent();
218 fESDEvent->ReadFromTree(fChainE);
219 // fChainE->SetBranchAddress("ESD", &fMainESD);
223 if (TESTBIT(fTreeMask, kRaw)) {
224 AliInfo("Getting FMD raw data digits");
225 fArrayA = new TClonesArray("AliFMDDigit");
226 if (!fRawFile.IsNull() && fRawFile.EndsWith(".root"))
227 fReader = new AliRawReaderRoot(fRawFile.Data());
228 else if (!fRawFile.IsNull() && fRawFile.EndsWith(".raw"))
229 fReader = new AliRawReaderDate(fRawFile.Data());
231 fReader = new AliRawReaderFile(-1);
235 // Optionally, get the geometry
236 if (TESTBIT(fTreeMask, kGeometry)) {
237 TString fname(fRun->GetGeometryFileName());
238 if (fname.IsNull()) {
239 Warning("Init", "No file name for the geometry from AliRun");
240 fname = gSystem->DirName(fGAliceFile);
241 fname.Append("/geometry.root");
243 fGeoManager = TGeoManager::Import(fname.Data());
245 Fatal("Init", "No geometry manager found");
248 AliCDBManager* cdb = AliCDBManager::Instance();
249 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
251 AliInfo("Got alignment data from CDB");
252 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
254 AliWarning("Invalid align data from CDB");
257 Int_t nAlign = array->GetEntries();
258 for (Int_t i = 0; i < nAlign; i++) {
259 AliAlignObjParams* a = static_cast<AliAlignObjParams*>(array->At(i));
260 if (!a->ApplyToGeometry()) {
261 AliWarning(Form("Failed to apply alignment to %s",
274 //____________________________________________________________________
276 AliFMDInput::Begin(Int_t event)
278 // Called at the begining of each event. Per default, it gets the
279 // data trees and gets pointers to the output arrays. Users can
280 // overload this, but should call this member function in the
281 // overloaded member function of the derived class.
283 // Check if we have been initialized
285 AliError("Not initialized");
290 if (fLoader->GetEvent(event)) return kFALSE;
291 AliInfo(Form("Now in event %8d/%8d", event, NEvents()));
293 // Possibly load global kinematics information
294 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
295 // AliInfo("Getting kinematics");
296 if (fLoader->LoadKinematics()) return kFALSE;
297 fStack = fLoader->Stack();
300 // Possibly load FMD Hit information
301 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
302 // AliInfo("Getting FMD hits");
303 if (!fFMDLoader || fFMDLoader->LoadHits()) return kFALSE;
304 fTreeH = fFMDLoader->TreeH();
305 if (!fArrayH) fArrayH = fFMD->Hits();
308 // Possibly load heaedr information
309 if (TESTBIT(fTreeMask, kHeader)) {
310 // AliInfo("Getting FMD hits");
311 if (!fLoader /* || fLoader->LoadHeader()*/) return kFALSE;
312 fHeader = fLoader->GetHeader();
315 // Possibly load FMD Digit information
316 if (TESTBIT(fTreeMask, kDigits)) {
317 // AliInfo("Getting FMD digits");
318 if (!fFMDLoader || fFMDLoader->LoadDigits()) return kFALSE;
319 fTreeD = fFMDLoader->TreeD();
321 if (!fArrayD) fArrayD = fFMD->Digits();
325 AliWarning(Form("Failed to load FMD Digits"));
329 // Possibly load FMD Sdigit information
330 if (TESTBIT(fTreeMask, kSDigits)) {
331 // AliInfo("Getting FMD summable digits");
332 if (!fFMDLoader || fFMDLoader->LoadSDigits()) return kFALSE;
333 fTreeS = fFMDLoader->TreeS();
334 if (!fArrayS) fArrayS = fFMD->SDigits();
337 // Possibly load FMD RecPoints information
338 if (TESTBIT(fTreeMask, kRecPoints)) {
339 // AliInfo("Getting FMD reconstructed points");
340 if (!fFMDLoader || fFMDLoader->LoadRecPoints()) return kFALSE;
341 fTreeR = fFMDLoader->TreeR();
342 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
343 fTreeR->SetBranchAddress("FMD", &fArrayR);
346 // Possibly load FMD ESD information
347 if (TESTBIT(fTreeMask, kESD)) {
348 // AliInfo("Getting FMD event summary data");
349 Int_t read = fChainE->GetEntry(event);
350 if (read <= 0) return kFALSE;
351 fESD = fESDEvent->GetFMDData();
352 if (!fESD) return kFALSE;
354 TFile* f = fChainE->GetFile();
356 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
358 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
359 std::cout << "AliFMDMap class version read is "
360 << info->GetClassVersion() << std::endl;
363 // fESD->CheckNeedUShort(fChainE->GetFile());
367 // Possibly load FMD Digit information
368 if (TESTBIT(fTreeMask, kRaw)) {
369 // AliInfo("Getting FMD raw data digits");
370 if (!fReader->NextEvent()) return kFALSE;
371 AliFMDRawReader r(fReader, 0);
380 //____________________________________________________________________
384 // Process one event. The default implementation one or more of
386 // - ProcessHits if the hits are loaded.
387 // - ProcessDigits if the digits are loaded.
388 // - ProcessSDigits if the sumbable digits are loaded.
389 // - ProcessRecPoints if the reconstructed points are loaded.
390 // - ProcessESD if the event summary data is loaded
392 if (TESTBIT(fTreeMask, kHits))
393 if (!ProcessHits()) return kFALSE;
394 if (TESTBIT(fTreeMask, kTracks))
395 if (!ProcessTracks()) return kFALSE;
396 if (TESTBIT(fTreeMask, kDigits))
397 if (!ProcessDigits()) return kFALSE;
398 if (TESTBIT(fTreeMask, kSDigits))
399 if (!ProcessSDigits()) return kFALSE;
400 if (TESTBIT(fTreeMask, kRaw))
401 if (!ProcessRawDigits()) return kFALSE;
402 if (TESTBIT(fTreeMask, kRecPoints))
403 if (!ProcessRecPoints()) return kFALSE;
404 if (TESTBIT(fTreeMask, kESD))
405 if (!ProcessESDs()) return kFALSE;
410 //____________________________________________________________________
412 AliFMDInput::ProcessHits()
414 // Read the hit tree, and pass each hit to the member function
417 AliError("No hit tree defined");
421 AliError("No hit array defined");
425 Int_t nTracks = fTreeH->GetEntries();
426 for (Int_t i = 0; i < nTracks; i++) {
427 Int_t hitRead = fTreeH->GetEntry(i);
428 if (hitRead <= 0) continue;
430 Int_t nHit = fArrayH->GetEntries();
431 if (nHit <= 0) continue;
433 for (Int_t j = 0; j < nHit; j++) {
434 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
437 TParticle* track = 0;
438 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
439 Int_t trackno = hit->Track();
440 track = fStack->Particle(trackno);
442 if (!ProcessHit(hit, track)) return kFALSE;
448 //____________________________________________________________________
450 AliFMDInput::ProcessTracks()
452 // Read the hit tree, and pass each hit to the member function
455 AliError("No track tree defined");
459 AliError("No hit tree defined");
463 AliError("No hit array defined");
467 // Int_t nTracks = fStack->GetNtrack();
468 Int_t nTracks = fTreeH->GetEntries();
469 for (Int_t i = 0; i < nTracks; i++) {
470 Int_t trackno = nTracks - i - 1;
471 TParticle* track = fStack->Particle(trackno);
472 if (!track) continue;
474 // Get the hits for this track.
475 Int_t hitRead = fTreeH->GetEntry(i);
476 Int_t nHit = fArrayH->GetEntries();
477 if (nHit == 0 || hitRead <= 0) {
478 // Let user code see the track, even if there's no hits.
479 if (!ProcessTrack(trackno, track, 0)) return kFALSE;
483 // Loop over the hits corresponding to this track.
484 for (Int_t j = 0; j < nHit; j++) {
485 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
486 if (!ProcessTrack(trackno, track, hit)) return kFALSE;
492 //____________________________________________________________________
494 AliFMDInput::ProcessDigits()
496 // Read the digit tree, and pass each digit to the member function
498 Int_t nEv = fTreeD->GetEntries();
499 for (Int_t i = 0; i < nEv; i++) {
500 Int_t digitRead = fTreeD->GetEntry(i);
501 if (digitRead <= 0) continue;
502 Int_t nDigit = fArrayD->GetEntries();
503 if (nDigit <= 0) continue;
504 for (Int_t j = 0; j < nDigit; j++) {
505 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
506 if (!digit) continue;
507 if (!ProcessDigit(digit)) return kFALSE;
513 //____________________________________________________________________
515 AliFMDInput::ProcessSDigits()
517 // Read the summable digit tree, and pass each sumable digit to the
518 // member function ProcessSdigit.
519 Int_t nEv = fTreeD->GetEntries();
520 for (Int_t i = 0; i < nEv; i++) {
521 Int_t sdigitRead = fTreeS->GetEntry(i);
522 if (sdigitRead <= 0) continue;
523 Int_t nSdigit = fArrayS->GetEntries();
524 if (nSdigit <= 0) continue;
525 for (Int_t j = 0; j < nSdigit; j++) {
526 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
527 if (!sdigit) continue;
528 if (!ProcessSDigit(sdigit)) return kFALSE;
534 //____________________________________________________________________
536 AliFMDInput::ProcessRawDigits()
538 // Read the digit tree, and pass each digit to the member function
540 Int_t nDigit = fArrayA->GetEntries();
541 if (nDigit <= 0) return kTRUE;
542 for (Int_t j = 0; j < nDigit; j++) {
543 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
544 if (!digit) continue;
545 if (!ProcessRawDigit(digit)) return kFALSE;
550 //____________________________________________________________________
552 AliFMDInput::ProcessRecPoints()
554 // Read the reconstrcted points tree, and pass each reconstruction
555 // object (AliFMDRecPoint) to either ProcessRecPoint.
556 Int_t nEv = fTreeR->GetEntries();
557 for (Int_t i = 0; i < nEv; i++) {
558 Int_t recRead = fTreeR->GetEntry(i);
559 if (recRead <= 0) continue;
560 Int_t nRecPoint = fArrayR->GetEntries();
561 for (Int_t j = 0; j < nRecPoint; j++) {
562 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
563 if (!recPoint) continue;
564 if (!ProcessRecPoint(recPoint)) return kFALSE;
570 //____________________________________________________________________
572 AliFMDInput::ProcessESDs()
574 // Process event summary data
575 if (!fESD) return kFALSE;
576 for (UShort_t det = 1; det <= 3; det++) {
577 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
578 for (Char_t* rng = rings; *rng != '\0'; rng++) {
579 UShort_t nsec = (*rng == 'I' ? 20 : 40);
580 UShort_t nstr = (*rng == 'I' ? 512 : 256);
581 for (UShort_t sec = 0; sec < nsec; sec++) {
582 for (UShort_t str = 0; str < nstr; str++) {
583 Float_t eta = fESD->Eta(det,*rng,sec,str);
584 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
585 if (!fESD->IsAngleCorrected())
586 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
587 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
595 //____________________________________________________________________
599 // Called at the end of each event. Per default, it unloads the
600 // data trees and resets the pointers to the output arrays. Users
601 // can overload this, but should call this member function in the
602 // overloaded member function of the derived class.
604 // Check if we have been initialized
606 AliError("Not initialized");
609 // Possibly unload global kinematics information
610 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
611 fLoader->UnloadKinematics();
615 // Possibly unload FMD Hit information
616 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
617 fFMDLoader->UnloadHits();
620 // Possibly unload FMD Digit information
621 if (TESTBIT(fTreeMask, kDigits)) {
622 fFMDLoader->UnloadDigits();
625 // Possibly unload FMD Sdigit information
626 if (TESTBIT(fTreeMask, kSDigits)) {
627 fFMDLoader->UnloadSDigits();
630 // Possibly unload FMD RecPoints information
631 if (TESTBIT(fTreeMask, kRecPoints)) {
632 fFMDLoader->UnloadRecPoints();
635 // AliInfo("Now out event");
639 //____________________________________________________________________
643 // Run over all events and files references in galice.root
646 if (!(retval = Init())) return retval;
648 Int_t nEvents = NEvents();
649 for (Int_t event = 0; event < nEvents; event++) {
650 if (!(retval = Begin(event))) break;
651 if (!(retval = Event())) break;
652 if (!(retval = End())) break;
654 if (!retval) return retval;
659 //__________________________________________________________________
661 AliFMDInput::MakeLogScale(Int_t n, Double_t min, Double_t max)
663 // Service function to define a logarithmic axis.
666 // min Minimum of axis
667 // max Maximum of axis
671 for (Int_t i = 1; i < n+1; i++) bins[i] = bins[i-1] + (max-min)/n;
674 Float_t dp = n / TMath::Log10(max / min);
675 Float_t pmin = TMath::Log10(min);
676 for (Int_t i = 1; i < n+1; i++) {
677 Float_t p = pmin + i / dp;
678 bins[i] = TMath::Power(10, p);
685 //____________________________________________________________________