]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
3d4320bed1be8c5a7fd6b34f831987561fdca2e5
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 //  A singleton. This class should be used in the analysis stage to get 
20 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21 //  instead of directly reading them from galice.root file. 
22 //                  
23 //  MvL Feb 2006:
24 //  The AliEMCALLoader now holds the TClonesArray and TObjArray for reading
25 //  Hits, Dgits, SDigits and RecPoints. Filling is managed in the GetEvent()
26 //  method.
27 //
28 //  Creation/writing of files is managed by the relevant parts of the 
29 //  reconstruction software (AliEMCALDigitiser etx)
30 //
31 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
32 //*--         Completely redesigned by Dmitri Peressounko March 2001  
33 //
34 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
35 //*--         systematic usage of TFolders without changing the interface
36 // 
37 //*-- Marco van Leeuwen, Jan 2006: complete revision to simplify reading
38 //*--         and fit better in general ALICE scheme
39 //
40 //////////////////////////////////////////////////////////////////////////////
41
42
43 // --- ROOT system ---
44
45 #include "TTree.h"
46
47 // --- Standard library ---
48
49 // --- AliRoot header files ---
50 #include "AliEMCALLoader.h"
51 #include "AliLog.h"
52 #include "AliCDBLocal.h"
53 #include "AliCDBStorage.h"
54 #include "AliCDBManager.h"
55
56 ClassImp(AliEMCALLoader)
57   
58 const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
59 AliEMCALCalibData* AliEMCALLoader::fCalibData = 0; //calibation data
60
61 //____________________________________________________________________________ 
62 AliEMCALLoader::AliEMCALLoader()
63 {
64   fDebug = 0;
65   fHits = new TClonesArray("AliEMCALHit");
66   fDigits = new TClonesArray("AliEMCALDigit");
67   fSDigits = new TClonesArray("AliEMCALDigit");
68   fRecPoints = new TObjArray();
69 }
70
71 //____________________________________________________________________________ 
72 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
73   AliLoader(detname,eventfoldername)
74 {
75   fDebug=0;
76   fHits = new TClonesArray("AliEMCALHit");
77   fDigits = new TClonesArray("AliEMCALDigit");
78   fSDigits = new TClonesArray("AliEMCALDigit");
79   fRecPoints = new TObjArray();
80 }
81
82 //____________________________________________________________________________ 
83 AliEMCALLoader::~AliEMCALLoader()
84 {
85   // Disconnect trees and remove arrays
86   if (TreeH())
87     TreeH()->SetBranchAddress(fDetectorName,0);
88   if (TreeD())
89     TreeD()->SetBranchAddress(fDetectorName,0);
90   if (TreeS())
91     TreeS()->SetBranchAddress(fDetectorName,0);
92   if (TreeR())
93     TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
94   delete fHits;
95   delete fDigits;
96   delete fSDigits;
97   delete fRecPoints;
98 }
99
100 //____________________________________________________________________________ 
101 AliEMCALCalibData* AliEMCALLoader::CalibData()
102
103   //Get the Calibration data list
104
105   if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
106     fCalibData=0x0;
107     Warning("CalibData","Calibration DB is not initiated!");
108     return fCalibData;
109   }
110
111  return fCalibData;
112
113 }
114
115 //____________________________________________________________________________ 
116 Int_t AliEMCALLoader::CalibrateRaw(Double_t energy, Int_t module, 
117                                    Int_t column, Int_t row)
118 {
119   // Convert energy into digitized amplitude for a cell relId
120   // It is a user responsilibity to open CDB and set
121   // AliEMCALCalibData object by the following operators:
122   // 
123   // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
124   // AliEMCALCalibData* clb = (AliEMCALCalibData*)AliCDBStorage::Instance()
125   //    ->Get(path_to_calibdata,run_number);
126   // AliEMCALGetter* gime = AliEMCALGetter::Instance("galice.root");
127   // gime->SetCalibData(clb);
128
129   if (CalibData() == 0)
130     Warning("CalibrateRaw","Calibration DB is not initiated!");
131
132   Float_t gainFactor = 0.0015; // width of one ADC channel in GeV
133   Float_t pedestal   = 0.005;  // pedestals
134
135   if(CalibData()) {
136     gainFactor = CalibData()->GetADCchannel (module,column,row);
137     pedestal   = CalibData()->GetADCpedestal(module,column,row);
138   }
139   
140   Int_t   amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ; 
141   return amp;
142 }
143
144
145 //____________________________________________________________________________ 
146 Int_t AliEMCALLoader::GetEvent() {
147   AliLoader::GetEvent();  // First call AliLoader to do all the groundwork
148
149   // Now connect and fill TClonesArray
150
151   // Hits
152   TTree *treeH = TreeH();
153   if (treeH) {
154     treeH->SetBranchAddress(fDetectorName,&fHits);
155     if (treeH->GetEntries() > 1)
156       AliWarning("Multiple arrays in treeH no longer supported");
157     treeH->GetEvent(0);
158   }
159
160   // SDigits
161   TTree *treeS = TreeS();
162   if (treeS) {
163     treeS->SetBranchAddress(fDetectorName,&fSDigits);
164     treeS->GetEvent(0);
165   }
166
167   // Digits
168   TTree *treeD = TreeD();
169   if (treeD) {
170     treeD->SetBranchAddress(fDetectorName,&fDigits);
171     treeD->GetEvent(0);
172   }
173
174   // RecPoints
175   TTree *treeR = TreeR();
176   if (treeR) {
177     treeR->SetBranchAddress(fgkECARecPointsBranchName,&fRecPoints);
178     treeR->GetEvent(0);
179   }
180
181   return 0;
182 }