]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
add some missing copy ctors and progress toward code convention compliance
[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 // --- ROOT system ---
43 #include "TTree.h"
44
45 // --- Standard library ---
46
47 // --- AliRoot header files ---
48 #include "AliEMCALLoader.h"
49 #include "AliLog.h"
50 #include "AliCDBLocal.h"
51 #include "AliCDBStorage.h"
52 #include "AliCDBManager.h"
53 #include "AliEMCALHit.h"
54
55 ClassImp(AliEMCALLoader)
56   
57 const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
58 AliEMCALCalibData* AliEMCALLoader::fgCalibData = 0; //calibation data
59 AliEMCALAlignData* AliEMCALLoader::fgAlignData = 0; //alignment data
60
61 //____________________________________________________________________________ 
62 AliEMCALLoader::AliEMCALLoader()
63 {
64   //Default constructor for EMCAL Loader Class
65
66   fDebug = 0;
67   fHits = new TClonesArray("AliEMCALHit");
68   fDigits = new TClonesArray("AliEMCALDigit");
69   fSDigits = new TClonesArray("AliEMCALDigit");
70   fRecPoints = new TObjArray();
71 }
72
73 //____________________________________________________________________________ 
74 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
75   AliLoader(detname,eventfoldername)
76 {
77   //Specific constructor for EMCAL Loader class
78
79   fDebug=0;
80   fHits = new TClonesArray("AliEMCALHit");
81   fDigits = new TClonesArray("AliEMCALDigit");
82   fSDigits = new TClonesArray("AliEMCALDigit");
83   fRecPoints = new TObjArray();
84 }
85
86 //____________________________________________________________________________
87 AliEMCALLoader::AliEMCALLoader(const AliEMCALLoader & obj):AliLoader(obj)
88 {
89   //copy ctor
90
91   fDebug = obj.fDebug;
92   fHits = obj.fHits;
93   fDigits = obj.fDigits;
94   fSDigits = obj.fSDigits;
95   fRecPoints = obj.fRecPoints;
96
97 }
98
99 //____________________________________________________________________________ 
100 AliEMCALLoader::~AliEMCALLoader()
101 {
102   // Disconnect trees and remove arrays
103   if (TreeH())
104     TreeH()->SetBranchAddress(fDetectorName,0);
105   if (TreeD())
106     TreeD()->SetBranchAddress(fDetectorName,0);
107   if (TreeS())
108     TreeS()->SetBranchAddress(fDetectorName,0);
109   if (TreeR())
110     TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
111   delete fHits;
112   delete fDigits;
113   delete fSDigits;
114   delete fRecPoints;
115 }
116
117 //____________________________________________________________________________
118 AliEMCALAlignData* AliEMCALLoader::AlignData()
119 {
120   // Check if the instance of AliEMCALAlignData exists, and return it
121   
122   if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) )
123     fgAlignData=0x0;
124   return fgAlignData;
125 }
126
127 //____________________________________________________________________________ 
128 AliEMCALCalibData* AliEMCALLoader::CalibData()
129
130   // Check if the instance of AliEMCALCalibData exists, and return it
131
132   if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) 
133     fgCalibData=0x0;
134   
135   return fgCalibData;
136   
137 }
138
139 //____________________________________________________________________________ 
140 Int_t AliEMCALLoader::CalibrateRaw(Double_t energy, Int_t module, 
141                                    Int_t column, Int_t row)
142 {
143   // Convert energy into digitized amplitude for a cell relId
144   // It is a user responsilibity to open CDB and set
145   // AliEMCALCalibData object by the following operators:
146   // 
147   // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
148   // AliEMCALCalibData* clb = (AliEMCALCalibData*)AliCDBStorage::Instance()
149   //    ->Get(path_to_calibdata,run_number);
150   // AliEMCALGetter* gime = AliEMCALGetter::Instance("galice.root");
151   // gime->SetCalibData(clb);
152
153   if (CalibData() == 0)
154     Warning("CalibrateRaw","Calibration DB is not initiated!");
155
156   Float_t gainFactor = 0.00305;//0.0015; // width of one ADC channel in GeV
157   Float_t pedestal   = 0.009;//0.005;  // pedestals
158
159   if(CalibData()) {
160     gainFactor = CalibData()->GetADCchannel (module,column,row);
161     pedestal   = CalibData()->GetADCpedestal(module,column,row);
162   }
163   
164   Int_t   amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ; 
165   return amp;
166 }
167
168 //____________________________________________________________________________ 
169 Int_t AliEMCALLoader::GetEvent() 
170 {
171   //Method to load all of the data
172   //members of the EMCAL for a given
173   //event from the Trees
174
175   AliLoader::GetEvent();  // First call AliLoader to do all the groundwork
176   
177   // Now connect and fill TClonesArray
178
179   // Hits
180    TTree *treeH = TreeH();
181    
182    if (treeH) {
183      Int_t nEnt = treeH->GetEntries();  // TreeH has array of hits for every primary
184      fHits->Clear();
185      Int_t index = 0;
186      TClonesArray *temp_arr = new TClonesArray("AliEMCALHit");
187      treeH->SetBranchAddress(fDetectorName,&temp_arr);
188      for (Int_t iEnt = 0; iEnt < nEnt; iEnt++) {
189        treeH->GetEntry(iEnt);
190        Int_t nHit = temp_arr->GetEntriesFast();
191        for (Int_t iHit = 0; iHit < nHit; iHit++) {
192          new ((*fHits)[index]) AliEMCALHit(*((AliEMCALHit*)temp_arr->At(iHit)));
193          index++;
194        }
195      }
196    }
197   
198    // SDigits
199    TTree *treeS = TreeS();
200    if (treeS) {
201      treeS->SetBranchAddress(fDetectorName,&fSDigits);
202      treeS->GetEvent(0);
203    }
204    
205    // Digits
206    TTree *treeD = TreeD();
207    if (treeD) {
208      treeD->SetBranchAddress(fDetectorName,&fDigits);
209      treeD->GetEvent(0);
210    }
211
212    // RecPoints
213    TTree *treeR = TreeR();
214    if (treeR) {
215      treeR->SetBranchAddress(fgkECARecPointsBranchName,&fRecPoints);
216      treeR->GetEvent(0);
217    }
218    
219    return 0;
220 }