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 "AliLog.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 <AliCDBManager.h>
47 #include <AliCDBEntry.h>
48 #include <AliAlignObjAngles.h>
49 #include <TTree.h> // ROOT_TTree
50 #include <TChain.h> // ROOT_TChain
51 #include <TParticle.h> // ROOT_TParticle
52 #include <TString.h> // ROOT_TString
53 #include <TDatabasePDG.h> // ROOT_TDatabasePDG
54 #include <TMath.h> // ROOT_TMath
55 #include <TGeoManager.h> // ROOT_TGeoManager
56 #include <TSystemDirectory.h> // ROOT_TSystemDirectory
57 #include <Riostream.h> // ROOT_Riostream
58 #include <TFile.h> // ROOT_TFile
59 #include <TStreamerInfo.h>
60 //____________________________________________________________________
63 ; // This is here to keep Emacs for indenting the next line
67 //____________________________________________________________________
68 AliFMDInput::AliFMDInput()
95 // Constructor of an FMD input object. Specify what data to read in
96 // using the AddLoad member function. Sub-classes should at a
97 // minimum overload the member function Event. A full job can be
98 // executed using the member function Run.
103 //____________________________________________________________________
104 AliFMDInput::AliFMDInput(const char* gAliceFile)
105 : fGAliceFile(gAliceFile),
131 // Constructor of an FMD input object. Specify what data to read in
132 // using the AddLoad member function. Sub-classes should at a
133 // minimum overload the member function Event. A full job can be
134 // executed using the member function Run.
137 //____________________________________________________________________
139 AliFMDInput::NEvents() const
141 // Get number of events
142 if (fTreeE) return fTreeE->GetEntries();
146 //____________________________________________________________________
150 // Initialize the object. Get the needed loaders, and such.
152 // Check if we have been initialized
154 AliWarning("Already initialized");
157 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
159 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
161 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
166 if (fLoader->LoadgAlice()) return kFALSE;
167 fRun = fLoader->GetAliRun();
170 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
172 AliError("Failed to get detector FMD from loader");
176 // Get the FMD loader
177 fFMDLoader = fLoader->GetLoader("FMDLoader");
179 AliError("Failed to get detector FMD loader from loader");
182 if (fLoader->LoadHeader()) {
183 AliError("Failed to get event header information from loader");
186 fTreeE = fLoader->TreeE();
188 // Optionally, get the ESD files
189 if (TESTBIT(fTreeMask, kESD)) {
190 fChainE = new TChain("esdTree");
191 TSystemDirectory dir(".",".");
192 TList* files = dir.GetListOfFiles();
193 TSystemFile* file = 0;
195 AliError("No files");
200 while ((file = static_cast<TSystemFile*>(next()))) {
201 TString fname(file->GetName());
202 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
204 fChainE->SetBranchAddress("ESD", &fMainESD);
207 if (TESTBIT(fTreeMask, kRaw)) {
208 AliInfo("Getting FMD raw data digits");
209 fArrayA = new TClonesArray("AliFMDDigit");
210 fReader = new AliRawReaderFile(-1);
213 // Optionally, get the geometry
214 if (TESTBIT(fTreeMask, kGeometry)) {
215 TString fname(fRun->GetGeometryFileName());
216 if (fname.IsNull()) {
217 Warning("Init", "No file name for the geometry from AliRun");
218 fname = gSystem->DirName(fGAliceFile);
219 fname.Append("/geometry.root");
221 fGeoManager = TGeoManager::Import(fname.Data());
223 Fatal("Init", "No geometry manager found");
226 AliCDBManager* cdb = AliCDBManager::Instance();
227 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
229 AliInfo("Got alignment data from CDB");
230 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
232 AliWarning("Invalid align data from CDB");
235 Int_t nAlign = array->GetEntries();
236 for (Int_t i = 0; i < nAlign; i++) {
237 AliAlignObjAngles* a = static_cast<AliAlignObjAngles*>(array->At(i));
238 if (!a->ApplyToGeometry()) {
239 AliWarning(Form("Failed to apply alignment to %s",
252 //____________________________________________________________________
254 AliFMDInput::Begin(Int_t event)
256 // Called at the begining of each event. Per default, it gets the
257 // data trees and gets pointers to the output arrays. Users can
258 // overload this, but should call this member function in the
259 // overloaded member function of the derived class.
261 // Check if we have been initialized
263 AliError("Not initialized");
267 if (fLoader->GetEvent(event)) return kFALSE;
268 AliInfo(Form("Now in event %d/%d", event, NEvents()));
270 // Possibly load global kinematics information
271 if (TESTBIT(fTreeMask, kKinematics)) {
272 AliInfo("Getting kinematics");
273 if (fLoader->LoadKinematics()) return kFALSE;
274 fStack = fLoader->Stack();
276 // Possibly load FMD Hit information
277 if (TESTBIT(fTreeMask, kHits)) {
278 AliInfo("Getting FMD hits");
279 if (fFMDLoader->LoadHits()) return kFALSE;
280 fTreeH = fFMDLoader->TreeH();
281 if (!fArrayH) fArrayH = fFMD->Hits();
283 // Possibly load FMD Digit information
284 if (TESTBIT(fTreeMask, kDigits)) {
285 AliInfo("Getting FMD digits");
286 if (fFMDLoader->LoadDigits()) return kFALSE;
287 fTreeD = fFMDLoader->TreeD();
289 if (!fArrayD) fArrayD = fFMD->Digits();
293 AliWarning(Form("Failed to load FMD Digits"));
296 // Possibly load FMD Sdigit information
297 if (TESTBIT(fTreeMask, kSDigits)) {
298 AliInfo("Getting FMD summable digits");
299 if (fFMDLoader->LoadSDigits()) return kFALSE;
300 fTreeS = fFMDLoader->TreeS();
301 if (!fArrayS) fArrayS = fFMD->SDigits();
303 // Possibly load FMD RecPoints information
304 if (TESTBIT(fTreeMask, kRecPoints)) {
305 AliInfo("Getting FMD reconstructed points");
306 if (fFMDLoader->LoadRecPoints()) return kFALSE;
307 fTreeR = fFMDLoader->TreeR();
308 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
309 fTreeR->SetBranchAddress("FMD", &fArrayR);
310 } // Possibly load FMD ESD information
311 if (TESTBIT(fTreeMask, kESD)) {
312 AliInfo("Getting FMD event summary data");
313 Int_t read = fChainE->GetEntry(event);
314 if (read <= 0) return kFALSE;
315 fESD = fMainESD->GetFMDData();
316 if (!fESD) return kFALSE;
317 TFile* f = fChainE->GetFile();
319 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
321 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
322 std::cout << "AliFMDMap class version read is "
323 << info->GetClassVersion() << std::endl;
326 // fESD->CheckNeedUShort(fChainE->GetFile());
328 // Possibly load FMD Digit information
329 if (TESTBIT(fTreeMask, kRaw)) {
330 AliInfo("Getting FMD raw data digits");
331 if (!fReader->NextEvent()) return kFALSE;
332 AliFMDRawReader r(fReader, 0);
341 //____________________________________________________________________
345 // Process one event. The default implementation one or more of
347 // - ProcessHits if the hits are loaded.
348 // - ProcessDigits if the digits are loaded.
349 // - ProcessSDigits if the sumbable digits are loaded.
350 // - ProcessRecPoints if the reconstructed points are loaded.
351 // - ProcessESD if the event summary data is loaded
353 if (TESTBIT(fTreeMask, kHits))
354 if (!ProcessHits()) return kFALSE;
355 if (TESTBIT(fTreeMask, kDigits))
356 if (!ProcessDigits()) return kFALSE;
357 if (TESTBIT(fTreeMask, kSDigits))
358 if (!ProcessSDigits()) return kFALSE;
359 if (TESTBIT(fTreeMask, kRaw))
360 if (!ProcessRawDigits()) return kFALSE;
361 if (TESTBIT(fTreeMask, kRecPoints))
362 if (!ProcessRecPoints()) return kFALSE;
363 if (TESTBIT(fTreeMask, kESD))
364 if (!ProcessESDs()) return kFALSE;
369 //____________________________________________________________________
371 AliFMDInput::ProcessHits()
373 // Read the hit tree, and pass each hit to the member function
376 AliError("No hit tree defined");
379 Int_t nTracks = fTreeH->GetEntries();
380 for (Int_t i = 0; i < nTracks; i++) {
381 Int_t hitRead = fTreeH->GetEntry(i);
382 if (hitRead <= 0) continue;
384 AliError("No hit array defined");
387 Int_t nHit = fArrayH->GetEntries();
388 if (nHit <= 0) continue;
389 for (Int_t j = 0; j < nHit; j++) {
390 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
392 TParticle* track = 0;
393 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
394 Int_t trackno = hit->Track();
395 track = fStack->Particle(trackno);
397 if (!ProcessHit(hit, track)) return kFALSE;
403 //____________________________________________________________________
405 AliFMDInput::ProcessDigits()
407 // Read the digit tree, and pass each digit to the member function
409 Int_t nEv = fTreeD->GetEntries();
410 for (Int_t i = 0; i < nEv; i++) {
411 Int_t digitRead = fTreeD->GetEntry(i);
412 if (digitRead <= 0) continue;
413 Int_t nDigit = fArrayD->GetEntries();
414 if (nDigit <= 0) continue;
415 for (Int_t j = 0; j < nDigit; j++) {
416 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
417 if (!digit) continue;
418 if (!ProcessDigit(digit)) return kFALSE;
424 //____________________________________________________________________
426 AliFMDInput::ProcessSDigits()
428 // Read the summable digit tree, and pass each sumable digit to the
429 // member function ProcessSdigit.
430 Int_t nEv = fTreeD->GetEntries();
431 for (Int_t i = 0; i < nEv; i++) {
432 Int_t sdigitRead = fTreeS->GetEntry(i);
433 if (sdigitRead <= 0) continue;
434 Int_t nSdigit = fArrayS->GetEntries();
435 if (nSdigit <= 0) continue;
436 for (Int_t j = 0; j < nSdigit; j++) {
437 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
438 if (!sdigit) continue;
439 if (!ProcessSDigit(sdigit)) return kFALSE;
445 //____________________________________________________________________
447 AliFMDInput::ProcessRawDigits()
449 // Read the digit tree, and pass each digit to the member function
451 Int_t nDigit = fArrayA->GetEntries();
452 if (nDigit <= 0) return kTRUE;
453 for (Int_t j = 0; j < nDigit; j++) {
454 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
455 if (!digit) continue;
456 if (!ProcessRawDigit(digit)) return kFALSE;
461 //____________________________________________________________________
463 AliFMDInput::ProcessRecPoints()
465 // Read the reconstrcted points tree, and pass each reconstruction
466 // object (AliFMDRecPoint) to either ProcessRecPoint.
467 Int_t nEv = fTreeR->GetEntries();
468 for (Int_t i = 0; i < nEv; i++) {
469 Int_t recRead = fTreeR->GetEntry(i);
470 if (recRead <= 0) continue;
471 Int_t nRecPoint = fArrayR->GetEntries();
472 for (Int_t j = 0; j < nRecPoint; j++) {
473 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
474 if (!recPoint) continue;
475 if (!ProcessRecPoint(recPoint)) return kFALSE;
481 //____________________________________________________________________
483 AliFMDInput::ProcessESDs()
485 // Process event summary data
486 if (!fESD) return kFALSE;
487 for (UShort_t det = 1; det <= 3; det++) {
488 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
489 for (Char_t* rng = rings; *rng != '\0'; rng++) {
490 UShort_t nsec = (*rng == 'I' ? 20 : 40);
491 UShort_t nstr = (*rng == 'I' ? 512 : 256);
492 for (UShort_t sec = 0; sec < nsec; sec++) {
493 for (UShort_t str = 0; str < nstr; str++) {
494 Float_t eta = fESD->Eta(det,*rng,sec,str);
495 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
496 if (!fESD->IsAngleCorrected())
497 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
498 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
506 //____________________________________________________________________
510 // Called at the end of each event. Per default, it unloads the
511 // data trees and resets the pointers to the output arrays. Users
512 // can overload this, but should call this member function in the
513 // overloaded member function of the derived class.
515 // Check if we have been initialized
517 AliError("Not initialized");
520 // Possibly unload global kinematics information
521 if (TESTBIT(fTreeMask, kKinematics)) {
522 fLoader->UnloadKinematics();
526 // Possibly unload FMD Hit information
527 if (TESTBIT(fTreeMask, kHits)) {
528 fFMDLoader->UnloadHits();
531 // Possibly unload FMD Digit information
532 if (TESTBIT(fTreeMask, kDigits)) {
533 fFMDLoader->UnloadDigits();
536 // Possibly unload FMD Sdigit information
537 if (TESTBIT(fTreeMask, kSDigits)) {
538 fFMDLoader->UnloadSDigits();
541 // Possibly unload FMD RecPoints information
542 if (TESTBIT(fTreeMask, kRecPoints)) {
543 fFMDLoader->UnloadRecPoints();
546 AliInfo("Now out event");
550 //____________________________________________________________________
554 // Run over all events and files references in galice.root
557 if (!(retval = Init())) return retval;
559 Int_t nEvents = NEvents();
560 for (Int_t event = 0; event < nEvents; event++) {
561 if (!(retval = Begin(event))) break;
562 if (!(retval = Event())) break;
563 if (!(retval = End())) break;
565 if (!retval) return retval;
571 //____________________________________________________________________