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>
61 //____________________________________________________________________
64 ; // This is here to keep Emacs for indenting the next line
68 //____________________________________________________________________
69 AliFMDInput::AliFMDInput()
97 // Constructor of an FMD input object. Specify what data to read in
98 // using the AddLoad member function. Sub-classes should at a
99 // minimum overload the member function Event. A full job can be
100 // executed using the member function Run.
105 //____________________________________________________________________
106 AliFMDInput::AliFMDInput(const char* gAliceFile)
107 : fGAliceFile(gAliceFile),
134 // Constructor of an FMD input object. Specify what data to read in
135 // using the AddLoad member function. Sub-classes should at a
136 // minimum overload the member function Event. A full job can be
137 // executed using the member function Run.
140 //____________________________________________________________________
142 AliFMDInput::NEvents() const
144 // Get number of events
145 if (fTreeE) return fTreeE->GetEntries();
149 //____________________________________________________________________
153 // Initialize the object. Get the needed loaders, and such.
155 // Check if we have been initialized
157 AliWarning("Already initialized");
160 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
162 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
164 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
169 if (fLoader->LoadgAlice()) return kFALSE;
170 fRun = fLoader->GetAliRun();
173 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
175 AliError("Failed to get detector FMD from loader");
179 // Get the FMD loader
180 fFMDLoader = fLoader->GetLoader("FMDLoader");
182 AliError("Failed to get detector FMD loader from loader");
185 if (fLoader->LoadHeader()) {
186 AliError("Failed to get event header information from loader");
189 fTreeE = fLoader->TreeE();
191 // Optionally, get the ESD files
192 if (TESTBIT(fTreeMask, kESD)) {
193 fChainE = new TChain("esdTree");
194 TSystemDirectory dir(".",".");
195 TList* files = dir.GetListOfFiles();
196 TSystemFile* file = 0;
198 AliError("No files");
203 while ((file = static_cast<TSystemFile*>(next()))) {
204 TString fname(file->GetName());
205 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
207 fESDEvent = new AliESDEvent();
208 fESDEvent->ReadFromTree(fChainE);
209 // fChainE->SetBranchAddress("ESD", &fMainESD);
213 if (TESTBIT(fTreeMask, kRaw)) {
214 AliInfo("Getting FMD raw data digits");
215 fArrayA = new TClonesArray("AliFMDDigit");
216 fReader = new AliRawReaderFile(-1);
219 // Optionally, get the geometry
220 if (TESTBIT(fTreeMask, kGeometry)) {
221 TString fname(fRun->GetGeometryFileName());
222 if (fname.IsNull()) {
223 Warning("Init", "No file name for the geometry from AliRun");
224 fname = gSystem->DirName(fGAliceFile);
225 fname.Append("/geometry.root");
227 fGeoManager = TGeoManager::Import(fname.Data());
229 Fatal("Init", "No geometry manager found");
232 AliCDBManager* cdb = AliCDBManager::Instance();
233 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
235 AliInfo("Got alignment data from CDB");
236 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
238 AliWarning("Invalid align data from CDB");
241 Int_t nAlign = array->GetEntries();
242 for (Int_t i = 0; i < nAlign; i++) {
243 AliAlignObjParams* a = static_cast<AliAlignObjParams*>(array->At(i));
244 if (!a->ApplyToGeometry()) {
245 AliWarning(Form("Failed to apply alignment to %s",
258 //____________________________________________________________________
260 AliFMDInput::Begin(Int_t event)
262 // Called at the begining of each event. Per default, it gets the
263 // data trees and gets pointers to the output arrays. Users can
264 // overload this, but should call this member function in the
265 // overloaded member function of the derived class.
267 // Check if we have been initialized
269 AliError("Not initialized");
273 if (fLoader->GetEvent(event)) return kFALSE;
274 AliInfo(Form("Now in event %d/%d", event, NEvents()));
276 // Possibly load global kinematics information
277 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
278 AliInfo("Getting kinematics");
279 if (fLoader->LoadKinematics()) return kFALSE;
280 fStack = fLoader->Stack();
282 // Possibly load FMD Hit information
283 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
284 AliInfo("Getting FMD hits");
285 if (fFMDLoader->LoadHits()) return kFALSE;
286 fTreeH = fFMDLoader->TreeH();
287 if (!fArrayH) fArrayH = fFMD->Hits();
289 // Possibly load FMD Digit information
290 if (TESTBIT(fTreeMask, kDigits)) {
291 AliInfo("Getting FMD digits");
292 if (fFMDLoader->LoadDigits()) return kFALSE;
293 fTreeD = fFMDLoader->TreeD();
295 if (!fArrayD) fArrayD = fFMD->Digits();
299 AliWarning(Form("Failed to load FMD Digits"));
302 // Possibly load FMD Sdigit information
303 if (TESTBIT(fTreeMask, kSDigits)) {
304 AliInfo("Getting FMD summable digits");
305 if (fFMDLoader->LoadSDigits()) return kFALSE;
306 fTreeS = fFMDLoader->TreeS();
307 if (!fArrayS) fArrayS = fFMD->SDigits();
309 // Possibly load FMD RecPoints information
310 if (TESTBIT(fTreeMask, kRecPoints)) {
311 AliInfo("Getting FMD reconstructed points");
312 if (fFMDLoader->LoadRecPoints()) return kFALSE;
313 fTreeR = fFMDLoader->TreeR();
314 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
315 fTreeR->SetBranchAddress("FMD", &fArrayR);
316 } // Possibly load FMD ESD information
317 if (TESTBIT(fTreeMask, kESD)) {
318 AliInfo("Getting FMD event summary data");
319 Int_t read = fChainE->GetEntry(event);
320 if (read <= 0) return kFALSE;
321 fESD = fESDEvent->GetFMDData();
322 if (!fESD) return kFALSE;
323 TFile* f = fChainE->GetFile();
325 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
327 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
328 std::cout << "AliFMDMap class version read is "
329 << info->GetClassVersion() << std::endl;
332 // fESD->CheckNeedUShort(fChainE->GetFile());
334 // Possibly load FMD Digit information
335 if (TESTBIT(fTreeMask, kRaw)) {
336 AliInfo("Getting FMD raw data digits");
337 if (!fReader->NextEvent()) return kFALSE;
338 AliFMDRawReader r(fReader, 0);
347 //____________________________________________________________________
351 // Process one event. The default implementation one or more of
353 // - ProcessHits if the hits are loaded.
354 // - ProcessDigits if the digits are loaded.
355 // - ProcessSDigits if the sumbable digits are loaded.
356 // - ProcessRecPoints if the reconstructed points are loaded.
357 // - ProcessESD if the event summary data is loaded
359 if (TESTBIT(fTreeMask, kHits))
360 if (!ProcessHits()) return kFALSE;
361 if (TESTBIT(fTreeMask, kTracks))
362 if (!ProcessTracks()) return kFALSE;
363 if (TESTBIT(fTreeMask, kDigits))
364 if (!ProcessDigits()) return kFALSE;
365 if (TESTBIT(fTreeMask, kSDigits))
366 if (!ProcessSDigits()) return kFALSE;
367 if (TESTBIT(fTreeMask, kRaw))
368 if (!ProcessRawDigits()) return kFALSE;
369 if (TESTBIT(fTreeMask, kRecPoints))
370 if (!ProcessRecPoints()) return kFALSE;
371 if (TESTBIT(fTreeMask, kESD))
372 if (!ProcessESDs()) return kFALSE;
377 //____________________________________________________________________
379 AliFMDInput::ProcessHits()
381 // Read the hit tree, and pass each hit to the member function
384 AliError("No hit tree defined");
387 Int_t nTracks = fTreeH->GetEntries();
388 for (Int_t i = 0; i < nTracks; i++) {
389 Int_t hitRead = fTreeH->GetEntry(i);
390 if (hitRead <= 0) continue;
392 AliError("No hit array defined");
395 Int_t nHit = fArrayH->GetEntries();
396 if (nHit <= 0) continue;
397 for (Int_t j = 0; j < nHit; j++) {
398 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
400 TParticle* track = 0;
401 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
402 Int_t trackno = hit->Track();
403 track = fStack->Particle(trackno);
405 if (!ProcessHit(hit, track)) return kFALSE;
411 //____________________________________________________________________
413 AliFMDInput::ProcessTracks()
415 // Read the hit tree, and pass each hit to the member function
418 AliError("No track tree defined");
422 AliError("No hit tree defined");
425 Int_t nTracks = fTreeH->GetEntries();
426 for (Int_t i = 0; i < nTracks; i++) {
427 TParticle* track = fStack->Particle(i);
428 if (!track) continue;
429 Int_t hitRead = fTreeH->GetEntry(i);
430 if (hitRead <= 0) continue;
432 AliError("No hit array defined");
435 Int_t nHit = fArrayH->GetEntries();
436 if (nHit <= 0) continue;
438 for (Int_t j = 0; j < nHit; j++) {
439 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
441 if (!ProcessTrack(i, track, hit)) return kFALSE;
443 // if (!ProcessTrack(i, track, fArrayH)) return kFALSE;
448 //____________________________________________________________________
450 AliFMDInput::ProcessDigits()
452 // Read the digit tree, and pass each digit to the member function
454 Int_t nEv = fTreeD->GetEntries();
455 for (Int_t i = 0; i < nEv; i++) {
456 Int_t digitRead = fTreeD->GetEntry(i);
457 if (digitRead <= 0) continue;
458 Int_t nDigit = fArrayD->GetEntries();
459 if (nDigit <= 0) continue;
460 for (Int_t j = 0; j < nDigit; j++) {
461 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
462 if (!digit) continue;
463 if (!ProcessDigit(digit)) return kFALSE;
469 //____________________________________________________________________
471 AliFMDInput::ProcessSDigits()
473 // Read the summable digit tree, and pass each sumable digit to the
474 // member function ProcessSdigit.
475 Int_t nEv = fTreeD->GetEntries();
476 for (Int_t i = 0; i < nEv; i++) {
477 Int_t sdigitRead = fTreeS->GetEntry(i);
478 if (sdigitRead <= 0) continue;
479 Int_t nSdigit = fArrayS->GetEntries();
480 if (nSdigit <= 0) continue;
481 for (Int_t j = 0; j < nSdigit; j++) {
482 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
483 if (!sdigit) continue;
484 if (!ProcessSDigit(sdigit)) return kFALSE;
490 //____________________________________________________________________
492 AliFMDInput::ProcessRawDigits()
494 // Read the digit tree, and pass each digit to the member function
496 Int_t nDigit = fArrayA->GetEntries();
497 if (nDigit <= 0) return kTRUE;
498 for (Int_t j = 0; j < nDigit; j++) {
499 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
500 if (!digit) continue;
501 if (!ProcessRawDigit(digit)) return kFALSE;
506 //____________________________________________________________________
508 AliFMDInput::ProcessRecPoints()
510 // Read the reconstrcted points tree, and pass each reconstruction
511 // object (AliFMDRecPoint) to either ProcessRecPoint.
512 Int_t nEv = fTreeR->GetEntries();
513 for (Int_t i = 0; i < nEv; i++) {
514 Int_t recRead = fTreeR->GetEntry(i);
515 if (recRead <= 0) continue;
516 Int_t nRecPoint = fArrayR->GetEntries();
517 for (Int_t j = 0; j < nRecPoint; j++) {
518 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
519 if (!recPoint) continue;
520 if (!ProcessRecPoint(recPoint)) return kFALSE;
526 //____________________________________________________________________
528 AliFMDInput::ProcessESDs()
530 // Process event summary data
531 if (!fESD) return kFALSE;
532 for (UShort_t det = 1; det <= 3; det++) {
533 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
534 for (Char_t* rng = rings; *rng != '\0'; rng++) {
535 UShort_t nsec = (*rng == 'I' ? 20 : 40);
536 UShort_t nstr = (*rng == 'I' ? 512 : 256);
537 for (UShort_t sec = 0; sec < nsec; sec++) {
538 for (UShort_t str = 0; str < nstr; str++) {
539 Float_t eta = fESD->Eta(det,*rng,sec,str);
540 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
541 if (!fESD->IsAngleCorrected())
542 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
543 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
551 //____________________________________________________________________
555 // Called at the end of each event. Per default, it unloads the
556 // data trees and resets the pointers to the output arrays. Users
557 // can overload this, but should call this member function in the
558 // overloaded member function of the derived class.
560 // Check if we have been initialized
562 AliError("Not initialized");
565 // Possibly unload global kinematics information
566 if (TESTBIT(fTreeMask, kKinematics) || TESTBIT(fTreeMask, kTracks)) {
567 fLoader->UnloadKinematics();
571 // Possibly unload FMD Hit information
572 if (TESTBIT(fTreeMask, kHits) || TESTBIT(fTreeMask, kTracks)) {
573 fFMDLoader->UnloadHits();
576 // Possibly unload FMD Digit information
577 if (TESTBIT(fTreeMask, kDigits)) {
578 fFMDLoader->UnloadDigits();
581 // Possibly unload FMD Sdigit information
582 if (TESTBIT(fTreeMask, kSDigits)) {
583 fFMDLoader->UnloadSDigits();
586 // Possibly unload FMD RecPoints information
587 if (TESTBIT(fTreeMask, kRecPoints)) {
588 fFMDLoader->UnloadRecPoints();
591 AliInfo("Now out event");
595 //____________________________________________________________________
599 // Run over all events and files references in galice.root
602 if (!(retval = Init())) return retval;
604 Int_t nEvents = NEvents();
605 for (Int_t event = 0; event < nEvents; event++) {
606 if (!(retval = Begin(event))) break;
607 if (!(retval = Event())) break;
608 if (!(retval = End())) break;
610 if (!retval) return retval;
616 //____________________________________________________________________