]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
Corrected DigitizeEnergy, amplitud calculation put outside calibration parameters IF
[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 AliEMCALAlignData* AliEMCALLoader::fAlignData = 0; //alignment data
61
62 //____________________________________________________________________________ 
63 AliEMCALLoader::AliEMCALLoader()
64 {
65   fDebug = 0;
66   fHits = new TClonesArray("AliEMCALHit");
67   fDigits = new TClonesArray("AliEMCALDigit");
68   fSDigits = new TClonesArray("AliEMCALDigit");
69   fRecPoints = new TObjArray();
70 }
71
72 //____________________________________________________________________________ 
73 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
74   AliLoader(detname,eventfoldername)
75 {
76   fDebug=0;
77   fHits = new TClonesArray("AliEMCALHit");
78   fDigits = new TClonesArray("AliEMCALDigit");
79   fSDigits = new TClonesArray("AliEMCALDigit");
80   fRecPoints = new TObjArray();
81 }
82
83 //____________________________________________________________________________ 
84 AliEMCALLoader::~AliEMCALLoader()
85 {
86   // Disconnect trees and remove arrays
87   if (TreeH())
88     TreeH()->SetBranchAddress(fDetectorName,0);
89   if (TreeD())
90     TreeD()->SetBranchAddress(fDetectorName,0);
91   if (TreeS())
92     TreeS()->SetBranchAddress(fDetectorName,0);
93   if (TreeR())
94     TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
95   delete fHits;
96   delete fDigits;
97   delete fSDigits;
98   delete fRecPoints;
99 }
100
101 //____________________________________________________________________________
102 AliEMCALAlignData* AliEMCALLoader::AlignData()
103 {
104   // Check if the instance of AliEMCALAlignData exists, and return it
105   
106   if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) )
107     fAlignData=0x0;
108   return fAlignData;
109 }
110
111 //____________________________________________________________________________ 
112 AliEMCALCalibData* AliEMCALLoader::CalibData()
113
114   // Check if the instance of AliEMCALCalibData exists, and return it
115
116   if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
117     fCalibData=0x0;
118     return fCalibData;
119   }
120
121  return fCalibData;
122
123 }
124
125 //____________________________________________________________________________ 
126 Int_t AliEMCALLoader::CalibrateRaw(Double_t energy, Int_t module, 
127                                    Int_t column, Int_t row)
128 {
129   // Convert energy into digitized amplitude for a cell relId
130   // It is a user responsilibity to open CDB and set
131   // AliEMCALCalibData object by the following operators:
132   // 
133   // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
134   // AliEMCALCalibData* clb = (AliEMCALCalibData*)AliCDBStorage::Instance()
135   //    ->Get(path_to_calibdata,run_number);
136   // AliEMCALGetter* gime = AliEMCALGetter::Instance("galice.root");
137   // gime->SetCalibData(clb);
138
139   if (CalibData() == 0)
140     Warning("CalibrateRaw","Calibration DB is not initiated!");
141
142   Float_t gainFactor = 0.0015; // width of one ADC channel in GeV
143   Float_t pedestal   = 0.005;  // pedestals
144
145   if(CalibData()) {
146     gainFactor = CalibData()->GetADCchannel (module,column,row);
147     pedestal   = CalibData()->GetADCpedestal(module,column,row);
148   }
149   
150   Int_t   amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ; 
151   return amp;
152 }
153
154
155 //____________________________________________________________________________ 
156 Int_t AliEMCALLoader::GetEvent() {
157   AliLoader::GetEvent();  // First call AliLoader to do all the groundwork
158
159   // Now connect and fill TClonesArray
160
161   // Hits
162   TTree *treeH = TreeH();
163   if (treeH) {
164     treeH->SetBranchAddress(fDetectorName,&fHits);
165     if (treeH->GetEntries() > 1)
166       AliWarning("Multiple arrays in treeH no longer supported");
167     treeH->GetEvent(0);
168   }
169
170   // SDigits
171   TTree *treeS = TreeS();
172   if (treeS) {
173     treeS->SetBranchAddress(fDetectorName,&fSDigits);
174     treeS->GetEvent(0);
175   }
176
177   // Digits
178   TTree *treeD = TreeD();
179   if (treeD) {
180     treeD->SetBranchAddress(fDetectorName,&fDigits);
181     treeD->GetEvent(0);
182   }
183
184   // RecPoints
185   TTree *treeR = TreeR();
186   if (treeR) {
187     treeR->SetBranchAddress(fgkECARecPointsBranchName,&fRecPoints);
188     treeR->GetEvent(0);
189   }
190
191   return 0;
192 }