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 "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
42 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
44 #include <AliESDFMD.h>
45 #include <AliCDBManager.h>
46 #include <AliCDBEntry.h>
47 #include <AliAlignObjAngles.h>
48 #include <TTree.h> // ROOT_TTree
49 #include <TChain.h> // ROOT_TChain
50 #include <TParticle.h> // ROOT_TParticle
51 #include <TString.h> // ROOT_TString
52 #include <TDatabasePDG.h> // ROOT_TDatabasePDG
53 #include <TMath.h> // ROOT_TMath
54 #include <TGeoManager.h> // ROOT_TGeoManager
55 #include <TSystemDirectory.h> // ROOT_TSystemDirectory
56 #include <Riostream.h> // ROOT_Riostream
58 //____________________________________________________________________
61 ; // This is here to keep Emacs for indenting the next line
65 //____________________________________________________________________
66 AliFMDInput::AliFMDInput()
91 // Constructor of an FMD input object. Specify what data to read in
92 // using the AddLoad member function. Sub-classes should at a
93 // minimum overload the member function Event. A full job can be
94 // executed using the member function Run.
99 //____________________________________________________________________
100 AliFMDInput::AliFMDInput(const char* gAliceFile)
101 : fGAliceFile(gAliceFile),
125 // Constructor of an FMD input object. Specify what data to read in
126 // using the AddLoad member function. Sub-classes should at a
127 // minimum overload the member function Event. A full job can be
128 // executed using the member function Run.
131 //____________________________________________________________________
133 AliFMDInput::NEvents() const
135 // Get number of events
136 if (fTreeE) return fTreeE->GetEntries();
140 //____________________________________________________________________
144 // Initialize the object. Get the needed loaders, and such.
146 // Check if we have been initialized
148 AliWarning("Already initialized");
151 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
153 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
155 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
160 if (fLoader->LoadgAlice()) return kFALSE;
161 fRun = fLoader->GetAliRun();
164 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
166 AliError("Failed to get detector FMD from loader");
170 // Get the FMD loader
171 fFMDLoader = fLoader->GetLoader("FMDLoader");
173 AliError("Failed to get detector FMD loader from loader");
176 if (fLoader->LoadHeader()) {
177 AliError("Failed to get event header information from loader");
180 fTreeE = fLoader->TreeE();
182 // Optionally, get the ESD files
183 if (TESTBIT(fTreeMask, kESD)) {
184 fChainE = new TChain("esdTree");
185 TSystemDirectory dir(".",".");
186 TList* files = dir.GetListOfFiles();
187 TSystemFile* file = 0;
189 AliError("No files");
194 while ((file = static_cast<TSystemFile*>(next()))) {
195 TString fname(file->GetName());
196 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
198 fChainE->SetBranchAddress("ESD", &fMainESD);
201 if (TESTBIT(fTreeMask, kRaw)) {
202 AliInfo("Getting FMD raw data digits");
203 fArrayA = new TClonesArray("AliFMDDigit");
204 fReader = new AliRawReaderFile(-1);
207 // Optionally, get the geometry
208 if (TESTBIT(fTreeMask, kGeometry)) {
209 TString fname(fRun->GetGeometryFileName());
210 if (fname.IsNull()) {
211 Warning("Init", "No file name for the geometry from AliRun");
212 fname = gSystem->DirName(fGAliceFile);
213 fname.Append("/geometry.root");
215 fGeoManager = TGeoManager::Import(fname.Data());
217 Fatal("Init", "No geometry manager found");
220 AliCDBManager* cdb = AliCDBManager::Instance();
221 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
223 AliInfo("Got alignment data from CDB");
224 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
226 AliWarning("Invalid align data from CDB");
229 Int_t nAlign = array->GetEntries();
230 for (Int_t i = 0; i < nAlign; i++) {
231 AliAlignObjAngles* a = static_cast<AliAlignObjAngles*>(array->At(i));
232 if (!a->ApplyToGeometry()) {
233 AliWarning(Form("Failed to apply alignment to %s",
246 //____________________________________________________________________
248 AliFMDInput::Begin(Int_t event)
250 // Called at the begining of each event. Per default, it gets the
251 // data trees and gets pointers to the output arrays. Users can
252 // overload this, but should call this member function in the
253 // overloaded member function of the derived class.
255 // Check if we have been initialized
257 AliError("Not initialized");
261 if (fLoader->GetEvent(event)) return kFALSE;
262 AliInfo(Form("Now in event %d/%d", event, NEvents()));
264 // Possibly load global kinematics information
265 if (TESTBIT(fTreeMask, kKinematics)) {
266 AliInfo("Getting kinematics");
267 if (fLoader->LoadKinematics()) return kFALSE;
268 fStack = fLoader->Stack();
270 // Possibly load FMD Hit information
271 if (TESTBIT(fTreeMask, kHits)) {
272 AliInfo("Getting FMD hits");
273 if (fFMDLoader->LoadHits()) return kFALSE;
274 fTreeH = fFMDLoader->TreeH();
275 if (!fArrayH) fArrayH = fFMD->Hits();
277 // Possibly load FMD Digit information
278 if (TESTBIT(fTreeMask, kDigits)) {
279 AliInfo("Getting FMD digits");
280 if (fFMDLoader->LoadDigits()) return kFALSE;
281 fTreeD = fFMDLoader->TreeD();
282 if (!fArrayD) fArrayD = fFMD->Digits();
284 // Possibly load FMD Sdigit information
285 if (TESTBIT(fTreeMask, kSDigits)) {
286 AliInfo("Getting FMD summable digits");
287 if (fFMDLoader->LoadSDigits()) return kFALSE;
288 fTreeS = fFMDLoader->TreeS();
289 if (!fArrayS) fArrayS = fFMD->SDigits();
291 // Possibly load FMD RecPoints information
292 if (TESTBIT(fTreeMask, kRecPoints)) {
293 AliInfo("Getting FMD reconstructed points");
294 if (fFMDLoader->LoadRecPoints()) return kFALSE;
295 fTreeR = fFMDLoader->TreeR();
296 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
297 fTreeR->SetBranchAddress("FMD", &fArrayR);
298 } // Possibly load FMD ESD information
299 if (TESTBIT(fTreeMask, kESD)) {
300 AliInfo("Getting FMD event summary data");
301 Int_t read = fChainE->GetEntry(event);
302 if (read <= 0) return kFALSE;
303 fESD = fMainESD->GetFMDData();
304 if (!fESD) return kFALSE;
306 // Possibly load FMD Digit information
307 if (TESTBIT(fTreeMask, kRaw)) {
308 AliInfo("Getting FMD raw data digits");
309 if (!fReader->NextEvent()) return kFALSE;
310 AliFMDRawReader r(fReader, 0);
319 //____________________________________________________________________
323 // Process one event. The default implementation one or more of
325 // - ProcessHits if the hits are loaded.
326 // - ProcessDigits if the digits are loaded.
327 // - ProcessSDigits if the sumbable digits are loaded.
328 // - ProcessRecPoints if the reconstructed points are loaded.
329 // - ProcessESD if the event summary data is loaded
331 if (TESTBIT(fTreeMask, kHits))
332 if (!ProcessHits()) return kFALSE;
333 if (TESTBIT(fTreeMask, kDigits))
334 if (!ProcessDigits()) return kFALSE;
335 if (TESTBIT(fTreeMask, kSDigits))
336 if (!ProcessSDigits()) return kFALSE;
337 if (TESTBIT(fTreeMask, kRaw))
338 if (!ProcessRawDigits()) return kFALSE;
339 if (TESTBIT(fTreeMask, kRecPoints))
340 if (!ProcessRecPoints()) return kFALSE;
341 if (TESTBIT(fTreeMask, kESD))
342 if (!ProcessESD(fESD)) return kFALSE;
347 //____________________________________________________________________
349 AliFMDInput::ProcessHits()
352 AliError("No hit tree defined");
355 Int_t nTracks = fTreeH->GetEntries();
356 for (Int_t i = 0; i < nTracks; i++) {
357 Int_t hitRead = fTreeH->GetEntry(i);
358 if (hitRead <= 0) continue;
360 AliError("No hit array defined");
363 Int_t nHit = fArrayH->GetEntries();
364 if (nHit <= 0) continue;
365 for (Int_t j = 0; j < nHit; j++) {
366 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
368 TParticle* track = 0;
369 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
370 Int_t trackno = hit->Track();
371 track = fStack->Particle(trackno);
373 if (!ProcessHit(hit, track)) return kFALSE;
379 //____________________________________________________________________
381 AliFMDInput::ProcessDigits()
383 // Read the digit tree, and pass each digit to the member function
385 Int_t nEv = fTreeD->GetEntries();
386 for (Int_t i = 0; i < nEv; i++) {
387 Int_t digitRead = fTreeD->GetEntry(i);
388 if (digitRead <= 0) continue;
389 Int_t nDigit = fArrayD->GetEntries();
390 if (nDigit <= 0) continue;
391 for (Int_t j = 0; j < nDigit; j++) {
392 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
393 if (!digit) continue;
394 if (!ProcessDigit(digit)) return kFALSE;
400 //____________________________________________________________________
402 AliFMDInput::ProcessSDigits()
404 // Read the summable digit tree, and pass each sumable digit to the
405 // member function ProcessSdigit.
406 Int_t nEv = fTreeD->GetEntries();
407 for (Int_t i = 0; i < nEv; i++) {
408 Int_t sdigitRead = fTreeS->GetEntry(i);
409 if (sdigitRead <= 0) continue;
410 Int_t nSdigit = fArrayS->GetEntries();
411 if (nSdigit <= 0) continue;
412 for (Int_t j = 0; j < nSdigit; j++) {
413 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
414 if (!sdigit) continue;
415 if (!ProcessSDigit(sdigit)) return kFALSE;
421 //____________________________________________________________________
423 AliFMDInput::ProcessRawDigits()
425 // Read the digit tree, and pass each digit to the member function
427 Int_t nDigit = fArrayA->GetEntries();
428 if (nDigit <= 0) return kTRUE;
429 for (Int_t j = 0; j < nDigit; j++) {
430 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
431 if (!digit) continue;
432 if (!ProcessRawDigit(digit)) return kFALSE;
437 //____________________________________________________________________
439 AliFMDInput::ProcessRecPoints()
441 // Read the reconstrcted points tree, and pass each reconstruction
442 // object (AliFMDRecPoint) to either ProcessRecPoint.
443 Int_t nEv = fTreeR->GetEntries();
444 for (Int_t i = 0; i < nEv; i++) {
445 Int_t recRead = fTreeR->GetEntry(i);
446 if (recRead <= 0) continue;
447 Int_t nRecPoint = fArrayR->GetEntries();
448 for (Int_t j = 0; j < nRecPoint; j++) {
449 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
450 if (!recPoint) continue;
451 if (!ProcessRecPoint(recPoint)) return kFALSE;
457 //____________________________________________________________________
461 // Called at the end of each event. Per default, it unloads the
462 // data trees and resets the pointers to the output arrays. Users
463 // can overload this, but should call this member function in the
464 // overloaded member function of the derived class.
466 // Check if we have been initialized
468 AliError("Not initialized");
471 // Possibly unload global kinematics information
472 if (TESTBIT(fTreeMask, kKinematics)) {
473 fLoader->UnloadKinematics();
477 // Possibly unload FMD Hit information
478 if (TESTBIT(fTreeMask, kHits)) {
479 fFMDLoader->UnloadHits();
482 // Possibly unload FMD Digit information
483 if (TESTBIT(fTreeMask, kDigits)) {
484 fFMDLoader->UnloadDigits();
487 // Possibly unload FMD Sdigit information
488 if (TESTBIT(fTreeMask, kSDigits)) {
489 fFMDLoader->UnloadSDigits();
492 // Possibly unload FMD RecPoints information
493 if (TESTBIT(fTreeMask, kRecPoints)) {
494 fFMDLoader->UnloadRecPoints();
497 AliInfo("Now out event");
501 //____________________________________________________________________
505 // Run over all events and files references in galice.root
508 if (!(retval = Init())) return retval;
510 Int_t nEvents = NEvents();
511 for (Int_t event = 0; event < nEvents; event++) {
512 if (!(retval = Begin(event))) break;
513 if (!(retval = Event())) break;
514 if (!(retval = End())) break;
516 if (!retval) return retval;
521 //====================================================================
522 ClassImp(AliFMDInputHits)
528 //====================================================================
529 ClassImp(AliFMDInputDigits)
534 //====================================================================
535 ClassImp(AliFMDInputSDigits)
540 //====================================================================
541 ClassImp(AliFMDInputRecPoints)
546 //____________________________________________________________________