]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDInput.cxx
Added script to extract list of medias and write to file - must be executed in same...
[u/mrichter/AliRoot.git] / FMD / AliFMDInput.cxx
CommitLineData
a1f80595 1/**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
a1f80595 15/* $Id$ */
c2fc1258 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
20*/
a1f80595 21//___________________________________________________________________
22//
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.
28//
29// Latest changes by Christian Holm Christensen
30//
31#include "AliFMDInput.h" // ALIFMDHIT_H
32#include "AliLog.h" // ALILOG_H
8f6ee336 33#include "AliLoader.h" // ALILOADER_H
34#include "AliRunLoader.h" // ALIRUNLOADER_H
35#include "AliRun.h" // ALIRUN_H
36#include "AliStack.h" // ALISTACK_H
d760ea03 37#include "AliRawReaderFile.h" // ALIRAWREADERFILE_H
8f6ee336 38#include "AliFMD.h" // ALIFMD_H
a1f80595 39#include "AliFMDHit.h" // ALIFMDHIT_H
8f6ee336 40#include "AliFMDDigit.h" // ALIFMDDigit_H
02a27b50 41#include "AliFMDSDigit.h" // ALIFMDDigit_H
bf000c32 42#include "AliFMDRecPoint.h" // ALIFMDRECPOINT_H
d760ea03 43#include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
bf000c32 44#include <AliESD.h>
45#include <AliESDFMD.h>
1e8f773e 46#include <AliCDBManager.h>
47#include <AliCDBEntry.h>
48#include <AliAlignObjAngles.h>
8f6ee336 49#include <TTree.h> // ROOT_TTree
bf000c32 50#include <TChain.h> // ROOT_TChain
8f6ee336 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
bf000c32 56#include <TSystemDirectory.h> // ROOT_TSystemDirectory
8f6ee336 57#include <Riostream.h> // ROOT_Riostream
97b4001e 58#include <TFile.h> // ROOT_TFile
a1f80595 59//____________________________________________________________________
60ClassImp(AliFMDInput)
61#if 0
62 ; // This is here to keep Emacs for indenting the next line
63#endif
64
65
66//____________________________________________________________________
67AliFMDInput::AliFMDInput()
68 : fGAliceFile(""),
69 fLoader(0),
70 fRun(0),
71 fStack(0),
72 fFMDLoader(0),
d760ea03 73 fReader(0),
a1f80595 74 fFMD(0),
bf000c32 75 fMainESD(0),
76 fESD(0),
a1f80595 77 fTreeE(0),
78 fTreeH(0),
79 fTreeD(0),
80 fTreeS(0),
81 fTreeR(0),
b5ee4425 82 fTreeA(0),
bf000c32 83 fChainE(0),
a1f80595 84 fArrayE(0),
85 fArrayH(0),
86 fArrayD(0),
87 fArrayS(0),
bf000c32 88 fArrayR(0),
d760ea03 89 fArrayA(0),
b5ee4425 90 fGeoManager(0),
a1f80595 91 fTreeMask(0),
92 fIsInit(kFALSE)
93{
94 // Constructor of an FMD input object. Specify what data to read in
95 // using the AddLoad member function. Sub-classes should at a
96 // minimum overload the member function Event. A full job can be
97 // executed using the member function Run.
98}
99
100
101
102//____________________________________________________________________
103AliFMDInput::AliFMDInput(const char* gAliceFile)
104 : fGAliceFile(gAliceFile),
105 fLoader(0),
106 fRun(0),
107 fStack(0),
108 fFMDLoader(0),
d760ea03 109 fReader(0),
a1f80595 110 fFMD(0),
bf000c32 111 fMainESD(0),
112 fESD(0),
a1f80595 113 fTreeE(0),
114 fTreeH(0),
115 fTreeD(0),
116 fTreeS(0),
117 fTreeR(0),
b5ee4425 118 fTreeA(0),
bf000c32 119 fChainE(0),
a1f80595 120 fArrayE(0),
121 fArrayH(0),
122 fArrayD(0),
123 fArrayS(0),
bf000c32 124 fArrayR(0),
d760ea03 125 fArrayA(0),
b5ee4425 126 fGeoManager(0),
a1f80595 127 fTreeMask(0),
128 fIsInit(kFALSE)
129{
130 // Constructor of an FMD input object. Specify what data to read in
131 // using the AddLoad member function. Sub-classes should at a
132 // minimum overload the member function Event. A full job can be
133 // executed using the member function Run.
134}
135
136//____________________________________________________________________
137Int_t
138AliFMDInput::NEvents() const
139{
140 // Get number of events
141 if (fTreeE) return fTreeE->GetEntries();
142 return -1;
143}
144
145//____________________________________________________________________
146Bool_t
147AliFMDInput::Init()
148{
149 // Initialize the object. Get the needed loaders, and such.
150
151 // Check if we have been initialized
152 if (fIsInit) {
153 AliWarning("Already initialized");
154 return fIsInit;
155 }
156 if (fGAliceFile.IsNull()) fGAliceFile = "galice.root";
157 // Get the loader
158 fLoader = AliRunLoader::Open(fGAliceFile.Data(), "Alice", "read");
159 if (!fLoader) {
160 AliError(Form("Coulnd't read the file %s", fGAliceFile.Data()));
161 return kFALSE;
162 }
163
164 // Get the run
165 if (fLoader->LoadgAlice()) return kFALSE;
166 fRun = fLoader->GetAliRun();
167
168 // Get the FMD
169 fFMD = static_cast<AliFMD*>(fRun->GetDetector("FMD"));
170 if (!fFMD) {
171 AliError("Failed to get detector FMD from loader");
172 return kFALSE;
173 }
174
175 // Get the FMD loader
176 fFMDLoader = fLoader->GetLoader("FMDLoader");
177 if (!fFMDLoader) {
178 AliError("Failed to get detector FMD loader from loader");
179 return kFALSE;
180 }
181 if (fLoader->LoadHeader()) {
182 AliError("Failed to get event header information from loader");
183 return kFALSE;
184 }
185 fTreeE = fLoader->TreeE();
8f6ee336 186
bf000c32 187 // Optionally, get the ESD files
188 if (TESTBIT(fTreeMask, kESD)) {
189 fChainE = new TChain("esdTree");
c2fc1258 190 TSystemDirectory dir(".",".");
bf000c32 191 TList* files = dir.GetListOfFiles();
c2fc1258 192 TSystemFile* file = 0;
193 if (!files) {
194 AliError("No files");
195 return kFALSE;
196 }
bf000c32 197 files->Sort();
198 TIter next(files);
199 while ((file = static_cast<TSystemFile*>(next()))) {
200 TString fname(file->GetName());
201 if (fname.Contains("AliESDs")) fChainE->AddFile(fname.Data());
202 }
203 fChainE->SetBranchAddress("ESD", &fMainESD);
204 }
205
d760ea03 206 if (TESTBIT(fTreeMask, kRaw)) {
207 AliInfo("Getting FMD raw data digits");
208 fArrayA = new TClonesArray("AliFMDDigit");
209 fReader = new AliRawReaderFile(-1);
210 }
211
8f6ee336 212 // Optionally, get the geometry
213 if (TESTBIT(fTreeMask, kGeometry)) {
214 TString fname(fRun->GetGeometryFileName());
215 if (fname.IsNull()) {
216 Warning("Init", "No file name for the geometry from AliRun");
217 fname = gSystem->DirName(fGAliceFile);
218 fname.Append("/geometry.root");
219 }
220 fGeoManager = TGeoManager::Import(fname.Data());
221 if (!fGeoManager) {
222 Fatal("Init", "No geometry manager found");
223 return kFALSE;
224 }
1e8f773e 225 AliCDBManager* cdb = AliCDBManager::Instance();
226 AliCDBEntry* align = cdb->Get("FMD/Align/Data");
227 if (align) {
228 AliInfo("Got alignment data from CDB");
229 TClonesArray* array = dynamic_cast<TClonesArray*>(align->GetObject());
230 if (!array) {
231 AliWarning("Invalid align data from CDB");
232 }
233 else {
234 Int_t nAlign = array->GetEntries();
235 for (Int_t i = 0; i < nAlign; i++) {
236 AliAlignObjAngles* a = static_cast<AliAlignObjAngles*>(array->At(i));
237 if (!a->ApplyToGeometry()) {
238 AliWarning(Form("Failed to apply alignment to %s",
b760c02e 239 a->GetSymName()));
1e8f773e 240 }
241 }
242 }
243 }
8f6ee336 244 }
bf000c32 245
a1f80595 246
247 fIsInit = kTRUE;
248 return fIsInit;
249}
250
251//____________________________________________________________________
252Bool_t
253AliFMDInput::Begin(Int_t event)
254{
255 // Called at the begining of each event. Per default, it gets the
256 // data trees and gets pointers to the output arrays. Users can
257 // overload this, but should call this member function in the
258 // overloaded member function of the derived class.
259
260 // Check if we have been initialized
261 if (!fIsInit) {
262 AliError("Not initialized");
263 return fIsInit;
264 }
265 // Get the event
266 if (fLoader->GetEvent(event)) return kFALSE;
267 AliInfo(Form("Now in event %d/%d", event, NEvents()));
268
269 // Possibly load global kinematics information
270 if (TESTBIT(fTreeMask, kKinematics)) {
271 AliInfo("Getting kinematics");
272 if (fLoader->LoadKinematics()) return kFALSE;
273 fStack = fLoader->Stack();
274 }
275 // Possibly load FMD Hit information
276 if (TESTBIT(fTreeMask, kHits)) {
277 AliInfo("Getting FMD hits");
278 if (fFMDLoader->LoadHits()) return kFALSE;
279 fTreeH = fFMDLoader->TreeH();
280 if (!fArrayH) fArrayH = fFMD->Hits();
281 }
282 // Possibly load FMD Digit information
283 if (TESTBIT(fTreeMask, kDigits)) {
284 AliInfo("Getting FMD digits");
285 if (fFMDLoader->LoadDigits()) return kFALSE;
286 fTreeD = fFMDLoader->TreeD();
a9579262 287 if (fTreeD) {
288 if (!fArrayD) fArrayD = fFMD->Digits();
289 }
290 else {
291 fArrayD = 0;
292 AliWarning(Form("Failed to load FMD Digits"));
293 }
a1f80595 294 }
295 // Possibly load FMD Sdigit information
296 if (TESTBIT(fTreeMask, kSDigits)) {
297 AliInfo("Getting FMD summable digits");
298 if (fFMDLoader->LoadSDigits()) return kFALSE;
299 fTreeS = fFMDLoader->TreeS();
300 if (!fArrayS) fArrayS = fFMD->SDigits();
301 }
302 // Possibly load FMD RecPoints information
303 if (TESTBIT(fTreeMask, kRecPoints)) {
304 AliInfo("Getting FMD reconstructed points");
305 if (fFMDLoader->LoadRecPoints()) return kFALSE;
306 fTreeR = fFMDLoader->TreeR();
bf000c32 307 if (!fArrayR) fArrayR = new TClonesArray("AliFMDRecPoint");
308 fTreeR->SetBranchAddress("FMD", &fArrayR);
d760ea03 309 } // Possibly load FMD ESD information
bf000c32 310 if (TESTBIT(fTreeMask, kESD)) {
311 AliInfo("Getting FMD event summary data");
312 Int_t read = fChainE->GetEntry(event);
313 if (read <= 0) return kFALSE;
314 fESD = fMainESD->GetFMDData();
315 if (!fESD) return kFALSE;
97b4001e 316 TFile* f = fChainE->GetFile();
317 if (f) {
318 TObject* o = f->GetStreamerInfoList()->FindObject("AliFMDMap");
319 if (o) {
320 TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
321 std::cout << "AliFMDMap class version read is "
322 << info->GetClassVersion() << std::endl;
323 }
324 }
325 // fESD->CheckNeedUShort(fChainE->GetFile());
bf000c32 326 }
d760ea03 327 // Possibly load FMD Digit information
328 if (TESTBIT(fTreeMask, kRaw)) {
329 AliInfo("Getting FMD raw data digits");
330 if (!fReader->NextEvent()) return kFALSE;
331 AliFMDRawReader r(fReader, 0);
332 fArrayA->Clear();
333 r.ReadAdcs(fArrayA);
334 }
bf000c32 335
336 return kTRUE;
337}
338
339
340//____________________________________________________________________
341Bool_t
342AliFMDInput::Event()
343{
344 // Process one event. The default implementation one or more of
345 //
346 // - ProcessHits if the hits are loaded.
347 // - ProcessDigits if the digits are loaded.
348 // - ProcessSDigits if the sumbable digits are loaded.
349 // - ProcessRecPoints if the reconstructed points are loaded.
350 // - ProcessESD if the event summary data is loaded
351 //
352 if (TESTBIT(fTreeMask, kHits))
353 if (!ProcessHits()) return kFALSE;
354 if (TESTBIT(fTreeMask, kDigits))
355 if (!ProcessDigits()) return kFALSE;
356 if (TESTBIT(fTreeMask, kSDigits))
357 if (!ProcessSDigits()) return kFALSE;
d760ea03 358 if (TESTBIT(fTreeMask, kRaw))
359 if (!ProcessRawDigits()) return kFALSE;
bf000c32 360 if (TESTBIT(fTreeMask, kRecPoints))
361 if (!ProcessRecPoints()) return kFALSE;
362 if (TESTBIT(fTreeMask, kESD))
a9579262 363 if (!ProcessESDs()) return kFALSE;
bf000c32 364
365 return kTRUE;
366}
367
368//____________________________________________________________________
369Bool_t
370AliFMDInput::ProcessHits()
371{
02a27b50 372 // Read the hit tree, and pass each hit to the member function
373 // ProcessHit.
bf000c32 374 if (!fTreeH) {
375 AliError("No hit tree defined");
376 return kFALSE;
377 }
378 Int_t nTracks = fTreeH->GetEntries();
379 for (Int_t i = 0; i < nTracks; i++) {
380 Int_t hitRead = fTreeH->GetEntry(i);
381 if (hitRead <= 0) continue;
382 if (!fArrayH) {
383 AliError("No hit array defined");
384 return kFALSE;
385 }
386 Int_t nHit = fArrayH->GetEntries();
387 if (nHit <= 0) continue;
388 for (Int_t j = 0; j < nHit; j++) {
389 AliFMDHit* hit = static_cast<AliFMDHit*>(fArrayH->At(j));
390 if (!hit) continue;
391 TParticle* track = 0;
392 if (TESTBIT(fTreeMask, kKinematics) && fStack) {
393 Int_t trackno = hit->Track();
394 track = fStack->Particle(trackno);
395 }
396 if (!ProcessHit(hit, track)) return kFALSE;
397 }
398 }
399 return kTRUE;
400}
401
402//____________________________________________________________________
403Bool_t
404AliFMDInput::ProcessDigits()
405{
406 // Read the digit tree, and pass each digit to the member function
407 // ProcessDigit.
408 Int_t nEv = fTreeD->GetEntries();
409 for (Int_t i = 0; i < nEv; i++) {
410 Int_t digitRead = fTreeD->GetEntry(i);
411 if (digitRead <= 0) continue;
412 Int_t nDigit = fArrayD->GetEntries();
413 if (nDigit <= 0) continue;
414 for (Int_t j = 0; j < nDigit; j++) {
415 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayD->At(j));
416 if (!digit) continue;
417 if (!ProcessDigit(digit)) return kFALSE;
418 }
419 }
420 return kTRUE;
421}
422
423//____________________________________________________________________
424Bool_t
425AliFMDInput::ProcessSDigits()
426{
427 // Read the summable digit tree, and pass each sumable digit to the
428 // member function ProcessSdigit.
429 Int_t nEv = fTreeD->GetEntries();
430 for (Int_t i = 0; i < nEv; i++) {
431 Int_t sdigitRead = fTreeS->GetEntry(i);
432 if (sdigitRead <= 0) continue;
433 Int_t nSdigit = fArrayS->GetEntries();
434 if (nSdigit <= 0) continue;
435 for (Int_t j = 0; j < nSdigit; j++) {
436 AliFMDSDigit* sdigit = static_cast<AliFMDSDigit*>(fArrayS->At(j));
437 if (!sdigit) continue;
438 if (!ProcessSDigit(sdigit)) return kFALSE;
439 }
440 }
441 return kTRUE;
442}
443
d760ea03 444//____________________________________________________________________
445Bool_t
446AliFMDInput::ProcessRawDigits()
447{
448 // Read the digit tree, and pass each digit to the member function
449 // ProcessDigit.
450 Int_t nDigit = fArrayA->GetEntries();
451 if (nDigit <= 0) return kTRUE;
452 for (Int_t j = 0; j < nDigit; j++) {
453 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fArrayA->At(j));
454 if (!digit) continue;
455 if (!ProcessRawDigit(digit)) return kFALSE;
456 }
457 return kTRUE;
458}
459
bf000c32 460//____________________________________________________________________
461Bool_t
462AliFMDInput::ProcessRecPoints()
463{
464 // Read the reconstrcted points tree, and pass each reconstruction
465 // object (AliFMDRecPoint) to either ProcessRecPoint.
466 Int_t nEv = fTreeR->GetEntries();
467 for (Int_t i = 0; i < nEv; i++) {
468 Int_t recRead = fTreeR->GetEntry(i);
469 if (recRead <= 0) continue;
470 Int_t nRecPoint = fArrayR->GetEntries();
471 for (Int_t j = 0; j < nRecPoint; j++) {
472 AliFMDRecPoint* recPoint = static_cast<AliFMDRecPoint*>(fArrayR->At(j));
473 if (!recPoint) continue;
474 if (!ProcessRecPoint(recPoint)) return kFALSE;
475 }
a1f80595 476 }
477 return kTRUE;
478}
479
a9579262 480//____________________________________________________________________
481Bool_t
482AliFMDInput::ProcessESDs()
483{
484 // Process event summary data
485 if (!fESD) return kFALSE;
486 for (UShort_t det = 1; det <= 3; det++) {
487 Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
488 for (Char_t* rng = rings; *rng != '\0'; rng++) {
489 UShort_t nsec = (*rng == 'I' ? 20 : 40);
490 UShort_t nstr = (*rng == 'I' ? 512 : 256);
491 for (UShort_t sec = 0; sec < nsec; sec++) {
492 for (UShort_t str = 0; str < nstr; str++) {
493 Float_t eta = fESD->Eta(det,*rng,sec,str);
494 Float_t mult = fESD->Multiplicity(det,*rng,sec,str);
97b4001e 495 if (!fESD->IsAngleCorrected())
496 mult *= TMath::Abs(TMath::Cos(2.*TMath::ATan(TMath::Exp(-eta))));
a9579262 497 if (!ProcessESD(det, *rng, sec, str, eta, mult)) continue;
498 }
499 }
500 }
501 }
502 return kTRUE;
503}
504
a1f80595 505//____________________________________________________________________
506Bool_t
507AliFMDInput::End()
508{
509 // Called at the end of each event. Per default, it unloads the
510 // data trees and resets the pointers to the output arrays. Users
511 // can overload this, but should call this member function in the
512 // overloaded member function of the derived class.
513
514 // Check if we have been initialized
515 if (!fIsInit) {
516 AliError("Not initialized");
517 return fIsInit;
518 }
519 // Possibly unload global kinematics information
520 if (TESTBIT(fTreeMask, kKinematics)) {
521 fLoader->UnloadKinematics();
522 // fTreeK = 0;
523 fStack = 0;
524 }
525 // Possibly unload FMD Hit information
526 if (TESTBIT(fTreeMask, kHits)) {
527 fFMDLoader->UnloadHits();
528 fTreeH = 0;
529 }
530 // Possibly unload FMD Digit information
531 if (TESTBIT(fTreeMask, kDigits)) {
532 fFMDLoader->UnloadDigits();
533 fTreeD = 0;
534 }
535 // Possibly unload FMD Sdigit information
536 if (TESTBIT(fTreeMask, kSDigits)) {
537 fFMDLoader->UnloadSDigits();
538 fTreeS = 0;
539 }
540 // Possibly unload FMD RecPoints information
541 if (TESTBIT(fTreeMask, kRecPoints)) {
542 fFMDLoader->UnloadRecPoints();
543 fTreeR = 0;
544 }
545 AliInfo("Now out event");
546 return kTRUE;
547}
548
549//____________________________________________________________________
550Bool_t
551AliFMDInput::Run()
552{
553 // Run over all events and files references in galice.root
554
555 Bool_t retval;
556 if (!(retval = Init())) return retval;
557
558 Int_t nEvents = NEvents();
559 for (Int_t event = 0; event < nEvents; event++) {
560 if (!(retval = Begin(event))) break;
561 if (!(retval = Event())) break;
562 if (!(retval = End())) break;
563 }
564 if (!retval) return retval;
565 retval = Finish();
566 return retval;
567}
568
a1f80595 569
a1f80595 570//____________________________________________________________________
571//
572// EOF
573//