]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSRawDigiProducer.cxx
improve libgfortran detection (like is done for ROOT now).
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawDigiProducer.cxx
CommitLineData
7bc140a5 1/**************************************************************************
2 * Copyright(c) 2007, 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//This class produces PHOS digits of one event
19//using AliPHOSRawDecoder.
20//
21// For example:
22// TClonesArray *digits = new TClonesArray("AliPHOSDigit",100);
23// AliRawReader* rawReader = new AliRawReaderDate("2006run2211.raw");
24// AliPHOSRawDecoder dc(rawReader);
25// while (rawReader->NextEvent()) {
26// AliPHOSRawDigiProducer producer;
27// producer.MakeDigits(digits,&dc);
28// }
29
30// Author: Boris Polichtchouk
31
32// --- ROOT system ---
88fb5e50 33#include "TClonesArray.h"
34
7bc140a5 35// --- AliRoot header files ---
88fb5e50 36#include "AliPHOSRawDigiProducer.h"
37#include "AliPHOSRawDecoder.h"
38#include "AliPHOSGeometry.h"
39#include "AliPHOSDigit.h"
c0394bfb 40#include "AliPHOSRecoParam.h"
41#include "AliPHOSCalibData.h"
42#include "AliLog.h"
88fb5e50 43
44ClassImp(AliPHOSRawDigiProducer)
45
c0394bfb 46AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ;
47
48//--------------------------------------------------------------------------------------
49AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():TObject(),
50 fEmcMinE(0.),fCpvMinE(0.),fEmcCrystals(0),fGeom(0){
51
52}
53//--------------------------------------------------------------------------------------
54AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* parEmc, const AliPHOSRecoParam* parCpv):TObject(),
55 fEmcMinE(0.),fCpvMinE(0.),fEmcCrystals(0),fGeom(0){
56
57 if(!parEmc) AliFatal("Reconstruction parameters for EMC not set!");
58 if(!parCpv) AliFatal("Reconstruction parameters for CPV not set!");
59
60 fEmcMinE = parEmc->GetMinE();
61 fCpvMinE = parCpv->GetMinE();
62
63 fGeom=AliPHOSGeometry::GetInstance() ;
64 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
65
66 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
67
68 GetCalibrationParameters() ;
69}
70//--------------------------------------------------------------------------------------
71AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):TObject(),
72 fEmcMinE(0.),fCpvMinE(0.),fEmcCrystals(0),fGeom(0){
73
74 fEmcMinE = dp.fEmcMinE ;
75 fCpvMinE = dp.fCpvMinE ;
76 fEmcCrystals = dp.fEmcCrystals ;
77 fGeom = dp.fGeom ;
78}
79//--------------------------------------------------------------------------------------
80AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp){
81 if(&dp == this) return *this;
82
83 fEmcMinE = dp.fEmcMinE ;
84 fCpvMinE = dp.fCpvMinE ;
85 fEmcCrystals = dp.fEmcCrystals ;
86 fGeom = dp.fGeom ;
87 return *this;
88}
89
7bc140a5 90//--------------------------------------------------------------------------------------
88fb5e50 91void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
92{
7bc140a5 93 //Makes the job.
94 //TClonesArray *digits and raw data decoder should be provided by calling function.
95
88fb5e50 96 digits->Clear();
97
88fb5e50 98 Int_t iDigit = 0 ;
88fb5e50 99 Int_t relId[4], absId =0;
100
c0394bfb 101 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
102 const Double_t highLowDiff=2. ; //Maximal difference between High and Low channels in LG adc channels
88fb5e50 103
c0394bfb 104 //Temporary array for LowGain digits
105 TClonesArray tmpLG("AliPHOSDigit",10000) ;
106 Int_t ilgDigit=0 ;
107
108 while (decoder->NextDigit()) {
34827459 109
c0394bfb 110 Double_t energy=decoder->GetEnergy() ;
111 if(energy<=baseLine) //in ADC channels
112 continue ;
1267d56d 113
c0394bfb 114 Bool_t lowGainFlag = decoder->IsLowGain();
88fb5e50 115
116 relId[0] = decoder->GetModule();
117 relId[1] = 0;
118 relId[2] = decoder->GetRow();
119 relId[3] = decoder->GetColumn();
c0394bfb 120 fGeom->RelToAbsNumbering(relId, absId);
121
122 Double_t time = decoder->GetTime() ;
123 time = CalibrateT(time,relId,lowGainFlag) ;
124
125 energy = CalibrateE(energy,relId,lowGainFlag) ;
126
127 if(energy <= 0.)
128 continue;
129
130 if(lowGainFlag){
131 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
132 ilgDigit++ ;
133 }
134 else{
135 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
136 //If there is no LogGain it wil be removed by cut on Min E
137 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
138 else
139 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
140 iDigit++;
141 }
142 }
143
144 //Now scan created LG and HG digits and keep only those which appeared in both lists
145 //replace energy of HighGain digits only if there is overflow
146 //negative energy (overflow)
147 digits->Sort() ;
148 tmpLG.Sort() ;
149 Int_t iLG = 0;
150 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
151 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
152 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
153 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
154 while(iLG<nLG1 && digHG->GetId()> digLG->GetId()){
155 iLG++ ;
156 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
157 }
158 if(digHG->GetId() == digLG->GetId()){ //we found pair
159 if(digHG->GetEnergy()<0.){ //This is overflow in HG
160 digHG->SetTime(digLG->GetTime()) ;
161 digHG->SetEnergy(digLG->GetEnergy()) ;
162 }
163 else{ //Make approximate comparison of HG and LG energies
164 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy())/16./0.005 ; //aproximate difference in LG ADC ch.
165 if(TMath::Abs(de)>highLowDiff){ //too strong difference, remove digit
166 digits->RemoveAt(iDig) ;
88fb5e50 167 }
168 }
88fb5e50 169 }
c0394bfb 170 else{ //no pair - remove
171 // temporary fix for dead LG channels
172 Int_t absId=digHG->GetId() ;
173 Int_t relId[4] ;
174 fGeom->AbsToRelNumbering(absId,relId) ;
175 if(relId[2]%2==1 && relId[3]%16==4)
176 continue ;
177 digits->RemoveAt(iDig) ;
178 }
179 }
180
181 CleanDigits(digits) ;
182
183}
184//____________________________________________________________________________
185Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
186{
187 // Convert EMC measured amplitude into real energy.
188 // Calibration parameters are taken from calibration data base for raw data,
189 // or from digitizer parameters for simulated data.
190 if(fgCalibData){
191 Int_t module = relId[0];
192 Int_t column = relId[3];
193 Int_t row = relId[2];
194 if(relId[1]==0) { // this is EMC
195 if(isLowGain){
196 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
88fb5e50 197 }
c0394bfb 198 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
199 return amp ;
200 }
201 }
202 return 0;
203}
204//____________________________________________________________________________
205Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
206{
207 //Calibrate time
208 if(fgCalibData){
209 Int_t module = relId[0];
210 Int_t column = relId[3];
211 Int_t row = relId[2];
212 if(relId[1]==0) { // this is EMC
213 time += fgCalibData->GetTimeShiftEmc(module,column,row);
214 return time ;
215 }
216 }
217
218 return -999.;
219}
220//____________________________________________________________________________
221void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
222{
223 // remove digits with amplitudes below threshold.
224 // remove digits in bad channels
225 // sort digits with icreasing AbsId
226
227 //remove digits in bad map and below threshold
228 Bool_t isBadMap = 0 ;
229 if(fgCalibData->GetNumOfEmcBadChannels()){
230 isBadMap=1 ;
231 }
232
233 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
234 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
235 if(!digit)
236 continue ;
237 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
238 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
239 digits->RemoveAt(i) ;
240 continue ;
241 }
242 if(isBadMap){ //check bad map now
243 Int_t relid[4] ;
244 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
245 if(fgCalibData->IsBadChannelEmc(relid[0],relid[2],relid[3])){
246 digits->RemoveAt(i) ;
88fb5e50 247 }
248 }
88fb5e50 249 }
250
c0394bfb 251 //Compress, sort and set indexes
252 digits->Compress() ;
253// digits->Sort(); already sorted earlier
254 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
255 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
256 digit->SetIndexInList(i) ;
257 }
258}
259//____________________________________________________________________________
260Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
261{
262 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
263 return digit->GetId() <= fEmcCrystals ;
264
265}
266
267//____________________________________________________________________________
268Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
269{
270 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
271 return digit->GetId() > fEmcCrystals ;
272}
273//____________________________________________________________________________
274void AliPHOSRawDigiProducer::GetCalibrationParameters()
275{
276 // Set calibration parameters:
277 // if calibration database exists, they are read from database,
278 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
279 //
280 // It is a user responsilibity to open CDB before reconstruction, for example:
281 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
282
283 if (!fgCalibData){
284 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
285 }
286 if (fgCalibData->GetCalibDataEmc() == 0)
287 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
288 if (fgCalibData->GetCalibDataCpv() == 0)
289 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");
88fb5e50 290}