]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitCalibrator.cxx
Fixing once again the QA
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitCalibrator.cxx
CommitLineData
d99769c3 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#include "AliMUONDigitCalibrator.h"
19
861d6ce8 20#include "AliLog.h"
d99769c3 21#include "AliMUONCalibrationData.h"
fe6ed686 22#include "AliMUONLogger.h"
d1c20d08 23#include "AliMUONPadStatusMaker.h"
24#include "AliMUONPadStatusMapMaker.h"
de487b6e 25#include "AliMUONRecoParam.h"
c795d086 26#include "AliMUONVCalibParam.h"
861d6ce8 27#include "AliMUONVDigit.h"
28#include "AliMUONVDigitStore.h"
29#include "AliMUONVStore.h"
30#include "AliMpBusPatch.h"
de98fdc9 31#include "AliMpConstants.h"
ab167304 32#include "AliMpCDB.h"
de98fdc9 33#include "AliMpDDLStore.h"
861d6ce8 34#include "AliMpDEIterator.h"
35#include "AliMpDetElement.h"
ab167304 36#include "AliMpManuStore.h"
d99769c3 37
3d1463c8 38//-----------------------------------------------------------------------------
7945aae7 39/// \class AliMUONDigitCalibrator
1171bb0a 40/// Class used to calibrate digits (either real or simulated ones).
41///
42/// The calibration consists of subtracting the pedestal
43/// and multiplying by a gain, so that
44/// Signal = (ADC-pedestal)*gain
45///
46/// Please note also that for the moment, if a digit lies on a dead channel
47/// we remove this digit from the list of digits.
48/// FIXME: this has to be revisited. By using the AliMUONDigit::fFlags we
49/// should in principle flag a digit as bad w/o removing it, but this
50/// then requires some changes in the cluster finder to deal with this extra
51/// information correctly (e.g. to set a quality for the cluster if it contains
52/// bad digits).
53///
7945aae7 54/// \author Laurent Aphecetche
3d1463c8 55//-----------------------------------------------------------------------------
7945aae7 56
1171bb0a 57
7945aae7 58/// \cond CLASSIMP
d99769c3 59ClassImp(AliMUONDigitCalibrator)
7945aae7 60/// \endcond
d99769c3 61
de98fdc9 62const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
63const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
64const Int_t AliMUONDigitCalibrator::fgkGain(2);
65
d99769c3 66//_____________________________________________________________________________
de98fdc9 67AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
ab167304 68 const AliMUONRecoParam* recoParams,
de98fdc9 69 const char* calibMode)
42825ed9 70: TObject(),
3b6f7dce 71fLogger(new AliMUONLogger(20000)),
49e396d9 72fStatusMaker(0x0),
73fStatusMapMaker(0x0),
74fPedestals(0x0),
de98fdc9 75fGains(0x0),
76fApplyGains(0),
de487b6e 77fCapacitances(0x0),
78fNumberOfBadPads(0),
170f4046 79fNumberOfPads(0),
80fChargeSigmaCut(0)
d99769c3 81{
42825ed9 82 /// ctor
de98fdc9 83
de487b6e 84 Ctor(calibMode,calib,recoParams);
85}
86
87//_____________________________________________________________________________
88AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
89 const char* calibMode)
90: TObject(),
91fLogger(new AliMUONLogger(20000)),
92fStatusMaker(0x0),
93fStatusMapMaker(0x0),
94fPedestals(0x0),
95fGains(0x0),
96fApplyGains(0),
97fCapacitances(0x0),
98fNumberOfBadPads(0),
170f4046 99fNumberOfPads(0),
100fChargeSigmaCut(0)
de487b6e 101{
102 /// ctor
103
104 Ctor(calibMode,calib,0x0);
105}
106
107//_____________________________________________________________________________
108void
109AliMUONDigitCalibrator::Ctor(const char* calibMode,
110 const AliMUONCalibrationData& calib,
111 const AliMUONRecoParam* recoParams)
112{
113 /// designated ctor
114
de98fdc9 115 TString cMode(calibMode);
116 cMode.ToUpper();
117
118 if ( cMode == "NOGAIN" )
119 {
120 fApplyGains = fgkNoGain;
121 AliInfo("Will NOT apply gain correction");
122 }
3b6f7dce 123 else if ( cMode == "GAINCONSTANTCAPA" )
de98fdc9 124 {
125 fApplyGains = fgkGainConstantCapa;
126 AliInfo("Will apply gain correction, but with constant capacitance");
127 }
128 else if ( cMode == "GAIN" )
129 {
130 fApplyGains = fgkGain;
131 AliInfo("Will apply gain correction, with measured capacitances");
132 }
133 else
134 {
135 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
136 fApplyGains = fgkNoGain;
137 }
138
ab167304 139 // Load mapping manu store
140 if ( ! AliMpCDB::LoadManuStore() ) {
141 AliFatal("Could not access manu store from OCDB !");
142 }
143
49e396d9 144 fStatusMaker = new AliMUONPadStatusMaker(calib);
145
170f4046 146 // Set default values, as loose as reasonable
147
148 fChargeSigmaCut = 3.0;
149
150 Int_t mask(0x8080); // reject pads where ped *or* hv are missing
de487b6e 151
de487b6e 152 if ( recoParams )
153 {
170f4046 154 // if we have reco params, we use limits and cuts from there :
155
de487b6e 156 fStatusMaker->SetHVSt12Limits(recoParams->HVSt12LowLimit(),recoParams->HVSt12HighLimit());
157 fStatusMaker->SetHVSt345Limits(recoParams->HVSt345LowLimit(),recoParams->HVSt345HighLimit());
158 fStatusMaker->SetPedMeanLimits(recoParams->PedMeanLowLimit(),recoParams->PedMeanHighLimit());
159 fStatusMaker->SetPedSigmaLimits(recoParams->PedSigmaLowLimit(),recoParams->PedSigmaHighLimit());
160 fStatusMaker->SetGainA1Limits(recoParams->GainA1LowLimit(),recoParams->GainA1HighLimit());
161 fStatusMaker->SetGainA2Limits(recoParams->GainA2LowLimit(),recoParams->GainA2HighLimit());
162 fStatusMaker->SetGainThresLimits(recoParams->GainThresLowLimit(),recoParams->GainThresHighLimit());
170f4046 163
164 mask = recoParams->PadGoodnessMask();
de487b6e 165 //WARNING : getting this mask wrong is a very effective way of getting
166 //no digits at all out of this class ;-)
170f4046 167
168 fChargeSigmaCut = recoParams->ChargeSigmaCut();
de487b6e 169 }
49e396d9 170
171 Bool_t deferredInitialization = kTRUE;
172
173 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
174
175 fPedestals = calib.Pedestals();
de98fdc9 176
177 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
178 // to get the saturation value...
179
180 if ( fApplyGains == fgkGain )
181 {
182 fCapacitances = calib.Capacitances();
183 }
d99769c3 184}
185
186//_____________________________________________________________________________
187AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
188{
d1c20d08 189 /// dtor.
49e396d9 190 delete fStatusMaker;
191 delete fStatusMapMaker;
fe6ed686 192
193 AliInfo("Summary of messages:");
194 fLogger->Print();
195
de487b6e 196 AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
197 fNumberOfPads,fNumberOfBadPads,
198 ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
199
fe6ed686 200 delete fLogger;
d99769c3 201}
202
203//_____________________________________________________________________________
204void
42825ed9 205AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
d99769c3 206{
42825ed9 207 /// Calibrate the digits contained in digitStore
208 TIter next(digitStore.CreateTrackerIterator());
209 AliMUONVDigit* digit;
0045b488 210
211 fStatusMapMaker->RefreshRejectProbabilities(); // this will do something only for simulations
212 // (and only for those simulations where the reject list contain probabilities which are
213 // different from zero or one)
861d6ce8 214
215 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
c795d086 216
42825ed9 217 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
d99769c3 218 {
de487b6e 219 if ( digit->IsCalibrated() )
220 {
221 fLogger->Log("ERROR : trying to calibrate a digit twice");
222 return;
223 }
224
225 digit->Calibrated(kTRUE);
226
de487b6e 227 Float_t charge(0.0);
228 Int_t statusMap;
229 Bool_t isSaturated(kFALSE);
8bf22fd6 230
231 ++fNumberOfPads;
232
de487b6e 233 Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
234
235 digit->SetStatusMap(statusMap);
236
237 if (ok)
238 {
de487b6e 239 charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
0045b488 240 digit->ADC(),fChargeSigmaCut,&isSaturated);
de487b6e 241 }
242 else
243 {
0045b488 244 AliDebug(3,Form("Rejecting the pad DE %4d MANU %4d CH %2d ADC %6d STATUSMAP %x STATUS %s",
245 digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
246 digit->ADC(),statusMap,
247 fStatusMaker->AsString(fStatusMaker->PadStatus(digit->DetElemId(),digit->ManuId(),digit->ManuChannel())).Data()));
248
de487b6e 249 ++fNumberOfBadPads;
0045b488 250
de487b6e 251 }
252
253 digit->SetCharge(charge);
254 digit->Saturated(isSaturated);
42825ed9 255 }
256}
257
258//_____________________________________________________________________________
de487b6e 259Float_t
260AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
261 Float_t adc, Float_t nsigmas,
262 Bool_t* isSaturated) const
263
42825ed9 264{
265 /// Calibrate one digit
266
cf27231a 267
de487b6e 268 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
269 (fPedestals->FindObject(detElemId,manuId));
49e396d9 270
de487b6e 271 if (!pedestal)
42825ed9 272 {
de487b6e 273 // no pedestal -> no charge
274 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
275 return 0.0;
42825ed9 276 }
de487b6e 277
278
279 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
280 (fGains->FindObject(detElemId,manuId));
281
282 if (!gain)
42825ed9 283 {
de487b6e 284 if ( fApplyGains != fgkNoGain )
d99769c3 285 {
de487b6e 286 // no gain -> no charge
287 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
288 detElemId,manuId));
289 return 0.0;
42825ed9 290 }
de487b6e 291 }
292
293 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
294 Float_t charge(0);
295 Float_t capa(1.0);
296
297 if ( fApplyGains == fgkGainConstantCapa )
298 {
299 capa = 0.2; // pF
300 }
301 else if ( fApplyGains == fgkGain )
302 {
3b6f7dce 303
ab167304 304
305 Int_t serialNumber
306 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
3b6f7dce 307
de487b6e 308 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
309
310 if ( param )
42825ed9 311 {
de487b6e 312 capa = param->ValueAsFloat(manuChannel);
42825ed9 313 }
de487b6e 314 else
de98fdc9 315 {
de487b6e 316 fLogger->Log(Form("No capa found for serialNumber=%d",serialNumber));
317 capa = 0.0;
de98fdc9 318 }
de487b6e 319 }
320
321 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
322 {
323 if ( fApplyGains != fgkNoGain )
de98fdc9 324 {
de487b6e 325 Float_t a0 = gain->ValueAsFloat(manuChannel,0);
326 Float_t a1 = gain->ValueAsFloat(manuChannel,1);
327 Int_t thres = gain->ValueAsInt(manuChannel,2);
328 if ( padc < thres )
3b6f7dce 329 {
de487b6e 330 charge = a0*padc;
3b6f7dce 331 }
332 else
333 {
de487b6e 334 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
3b6f7dce 335 }
de98fdc9 336 }
de487b6e 337 else
42825ed9 338 {
de487b6e 339 charge = padc;
42825ed9 340 }
de487b6e 341 }
342
343 charge *= capa;
344
345 if ( isSaturated )
346 {
3b6f7dce 347 Int_t saturation(3000);
de487b6e 348
6b191dea 349 if ( gain && ( fApplyGains != fgkNoGain ) )
3b6f7dce 350 {
351 saturation = gain->ValueAsInt(manuChannel,4);
352 }
de487b6e 353
de98fdc9 354 if ( padc >= saturation )
42825ed9 355 {
de487b6e 356 *isSaturated = kTRUE;
357 }
358 else
359 {
ada26c2d 360 *isSaturated = kFALSE;
d99769c3 361 }
362 }
de487b6e 363
364 return charge;
d99769c3 365}
de487b6e 366
367//_____________________________________________________________________________
368Bool_t
369AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
370 Int_t* statusMap) const
371
372{
373 /// Check if a given pad is ok or not.
374
375 // First a protection against bad input parameters
376 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
377 if (!de) return kFALSE; // not existing DE
378 if (!de->IsExistingChannel(manuId,manuChannel))
379 {
380 // non-existing (might happen when we get parity errors in read-out
381 // that spoils the manuId
382 return kFALSE;
383 }
384 if (!de->IsConnectedChannel(manuId,manuChannel))
385 {
386 // existing (in read-out), but not connected channel
387 return kFALSE;
388 }
389
390 // ok, now we have a valid channel number, so let's see if that pad
391 // behaves or not ;-)
392
393 Int_t sm = fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
394
395 if (statusMap) *statusMap = sm;
396
397 if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
398 {
399 // pad itself is bad (not testing its neighbours at this stage)
400 return kFALSE;
401 }
402
403 return kTRUE;
404}
405
406//_____________________________________________________________________________
407Int_t
408AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
409{
410 /// Return the status of the given pad
411 return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
412}
413
414//_____________________________________________________________________________
415Int_t
416AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
417{
418 /// Return the status map of the given pad
419 return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
420
421}
422