]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitCalibrator.cxx
MUON trigger inputs following trigger naming conventions
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitCalibrator.cxx
CommitLineData
d99769c3 1/**************************************************************************
66cdf5b3 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 **************************************************************************/
d99769c3 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);
66cdf5b3 65const Int_t AliMUONDigitCalibrator::fgkInjectionGain(3);
de98fdc9 66
d99769c3 67//_____________________________________________________________________________
de98fdc9 68AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
ab167304 69 const AliMUONRecoParam* recoParams,
de98fdc9 70 const char* calibMode)
42825ed9 71: TObject(),
3b6f7dce 72fLogger(new AliMUONLogger(20000)),
49e396d9 73fStatusMaker(0x0),
74fStatusMapMaker(0x0),
75fPedestals(0x0),
de98fdc9 76fGains(0x0),
77fApplyGains(0),
de487b6e 78fCapacitances(0x0),
79fNumberOfBadPads(0),
170f4046 80fNumberOfPads(0),
411a502a 81fChargeSigmaCut(0),
82fMask(0)
d99769c3 83{
42825ed9 84 /// ctor
de98fdc9 85
de487b6e 86 Ctor(calibMode,calib,recoParams);
87}
88
89//_____________________________________________________________________________
90AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
91 const char* calibMode)
92: TObject(),
93fLogger(new AliMUONLogger(20000)),
94fStatusMaker(0x0),
95fStatusMapMaker(0x0),
96fPedestals(0x0),
97fGains(0x0),
98fApplyGains(0),
99fCapacitances(0x0),
100fNumberOfBadPads(0),
170f4046 101fNumberOfPads(0),
411a502a 102fChargeSigmaCut(0),
103fMask(0)
de487b6e 104{
105 /// ctor
106
107 Ctor(calibMode,calib,0x0);
108}
109
110//_____________________________________________________________________________
111void
112AliMUONDigitCalibrator::Ctor(const char* calibMode,
113 const AliMUONCalibrationData& calib,
114 const AliMUONRecoParam* recoParams)
115{
116 /// designated ctor
117
de98fdc9 118 TString cMode(calibMode);
119 cMode.ToUpper();
120
121 if ( cMode == "NOGAIN" )
122 {
123 fApplyGains = fgkNoGain;
124 AliInfo("Will NOT apply gain correction");
125 }
3b6f7dce 126 else if ( cMode == "GAINCONSTANTCAPA" )
de98fdc9 127 {
128 fApplyGains = fgkGainConstantCapa;
129 AliInfo("Will apply gain correction, but with constant capacitance");
130 }
131 else if ( cMode == "GAIN" )
132 {
133 fApplyGains = fgkGain;
134 AliInfo("Will apply gain correction, with measured capacitances");
135 }
66cdf5b3 136 else if ( cMode == "INJECTIONGAIN")
137 {
138 fApplyGains = fgkInjectionGain;
139 AliInfo("Will apply injection gain correction, with EMELEC factory gains");
140 }
de98fdc9 141 else
142 {
143 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
144 fApplyGains = fgkNoGain;
145 }
66cdf5b3 146
ab167304 147 // Load mapping manu store
148 if ( ! AliMpCDB::LoadManuStore() ) {
149 AliFatal("Could not access manu store from OCDB !");
150 }
66cdf5b3 151
49e396d9 152 fStatusMaker = new AliMUONPadStatusMaker(calib);
153
170f4046 154 // Set default values, as loose as reasonable
66cdf5b3 155
170f4046 156 fChargeSigmaCut = 3.0;
157
411a502a 158 fMask = 0x8080; // reject pads where ped *or* hv are missing
de487b6e 159
de487b6e 160 if ( recoParams )
161 {
170f4046 162 // if we have reco params, we use limits and cuts from there :
163
411a502a 164 fStatusMaker->SetLimits(*recoParams);
165
166 fMask = recoParams->PadGoodnessMask();
de487b6e 167 //WARNING : getting this mask wrong is a very effective way of getting
168 //no digits at all out of this class ;-)
170f4046 169
170 fChargeSigmaCut = recoParams->ChargeSigmaCut();
de487b6e 171 }
49e396d9 172
173 Bool_t deferredInitialization = kTRUE;
174
411a502a 175 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,fMask,deferredInitialization);
49e396d9 176
177 fPedestals = calib.Pedestals();
66cdf5b3 178
de98fdc9 179 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
180 // to get the saturation value...
66cdf5b3 181
6b31d882 182 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
de98fdc9 183 {
184 fCapacitances = calib.Capacitances();
185 }
d99769c3 186}
187
188//_____________________________________________________________________________
189AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
190{
d1c20d08 191 /// dtor.
411a502a 192
193 if ( fNumberOfPads > 0 )
194 {
195 if ( fStatusMaker )
196 {
197 fStatusMaker->Report(fMask);
198 }
199
200 AliInfo("Summary of messages:");
201
202 fLogger->Print();
203
204 AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
205 fNumberOfPads,fNumberOfBadPads,
206 ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
207 }
208
49e396d9 209 delete fStatusMaker;
210 delete fStatusMapMaker;
fe6ed686 211 delete fLogger;
d99769c3 212}
213
214//_____________________________________________________________________________
215void
42825ed9 216AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
d99769c3 217{
42825ed9 218 /// Calibrate the digits contained in digitStore
219 TIter next(digitStore.CreateTrackerIterator());
220 AliMUONVDigit* digit;
66cdf5b3 221
0045b488 222 fStatusMapMaker->RefreshRejectProbabilities(); // this will do something only for simulations
223 // (and only for those simulations where the reject list contain probabilities which are
224 // different from zero or one)
861d6ce8 225
226 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
c795d086 227
42825ed9 228 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
d99769c3 229 {
de487b6e 230 if ( digit->IsCalibrated() )
231 {
232 fLogger->Log("ERROR : trying to calibrate a digit twice");
233 return;
234 }
235
236 digit->Calibrated(kTRUE);
237
de487b6e 238 Float_t charge(0.0);
239 Int_t statusMap;
240 Bool_t isSaturated(kFALSE);
66cdf5b3 241
8bf22fd6 242 ++fNumberOfPads;
66cdf5b3 243
de487b6e 244 Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
66cdf5b3 245
de487b6e 246 digit->SetStatusMap(statusMap);
247
248 if (ok)
249 {
de487b6e 250 charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
0045b488 251 digit->ADC(),fChargeSigmaCut,&isSaturated);
de487b6e 252 }
253 else
254 {
411a502a 255 ++fNumberOfBadPads;
de487b6e 256 }
257
258 digit->SetCharge(charge);
259 digit->Saturated(isSaturated);
42825ed9 260 }
261}
262
263//_____________________________________________________________________________
de487b6e 264Float_t
265AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
266 Float_t adc, Float_t nsigmas,
267 Bool_t* isSaturated) const
268
42825ed9 269{
270 /// Calibrate one digit
db068204 271 /// Return the digit charge, in fC
cf27231a 272
de487b6e 273 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
274 (fPedestals->FindObject(detElemId,manuId));
49e396d9 275
de487b6e 276 if (!pedestal)
42825ed9 277 {
de487b6e 278 // no pedestal -> no charge
279 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
280 return 0.0;
42825ed9 281 }
de487b6e 282
283
284 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
285 (fGains->FindObject(detElemId,manuId));
286
287 if (!gain)
42825ed9 288 {
de487b6e 289 if ( fApplyGains != fgkNoGain )
d99769c3 290 {
de487b6e 291 // no gain -> no charge
292 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
293 detElemId,manuId));
294 return 0.0;
42825ed9 295 }
de487b6e 296 }
297
298 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
de487b6e 299
66cdf5b3 300 // Gain (mV/fC) = 1/(a0*capa) with a0~1.25 and capa~0.2
301 Float_t charge(0);
302 Float_t capa(0.2); // capa = 0.2 and a0 = 1.25
303 Float_t a0(1.25); // is equivalent to gain = 4 mV/fC
304 Float_t a1(0);
305 Float_t adc2mv(0.61); // 1 ADC channel = 0.61 mV
306 Float_t injGain(4); // By default the gain is set to 4 mV/fC
db068204 307 //
308 // Note that the ChargeMax (for one pad) is roughly 4096 * 0.61 mV/channel / 4 mV/fC = 625 fC
309
66cdf5b3 310 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
de487b6e 311 {
ab167304 312 Int_t serialNumber
66cdf5b3 313 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
3b6f7dce 314
de487b6e 315 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
316
317 if ( param )
42825ed9 318 {
66cdf5b3 319 capa = param->ValueAsFloat(manuChannel,0);
320 injGain = param->ValueAsFloat(manuChannel,1);
db068204 321 if ( injGain < 0 )
322 {
323 fLogger->Log(Form("injGain is %e < 0 for serialNumber=%d",injGain,serialNumber));
324 return 0.0;
325 }
42825ed9 326 }
de487b6e 327 else
de98fdc9 328 {
db068204 329 // If capa not found in the OCDB we exit
66cdf5b3 330 fLogger->Log(Form("No capa (injGain) found for serialNumber=%d",serialNumber));
331 return 0.0;
de98fdc9 332 }
de487b6e 333 }
334
335 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
336 {
66cdf5b3 337 if ( fApplyGains == fgkGain || fApplyGains == fgkGainConstantCapa )
de98fdc9 338 {
66cdf5b3 339 a0 = gain->ValueAsFloat(manuChannel,0);
340 a1 = gain->ValueAsFloat(manuChannel,1);
de487b6e 341 Int_t thres = gain->ValueAsInt(manuChannel,2);
342 if ( padc < thres )
3b6f7dce 343 {
de487b6e 344 charge = a0*padc;
3b6f7dce 345 }
346 else
347 {
de487b6e 348 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
3b6f7dce 349 }
66cdf5b3 350 charge *= capa*adc2mv;
de98fdc9 351 }
66cdf5b3 352 else if ( fApplyGains == fgkInjectionGain )
42825ed9 353 {
66cdf5b3 354
355 charge = padc*adc2mv/injGain;
42825ed9 356 }
66cdf5b3 357 else
358 {
359 charge = a0*padc*capa*adc2mv;
360 }
de487b6e 361 }
362
de487b6e 363 if ( isSaturated )
364 {
3b6f7dce 365 Int_t saturation(3000);
66cdf5b3 366
6b191dea 367 if ( gain && ( fApplyGains != fgkNoGain ) )
3b6f7dce 368 {
369 saturation = gain->ValueAsInt(manuChannel,4);
370 }
66cdf5b3 371
de98fdc9 372 if ( padc >= saturation )
42825ed9 373 {
de487b6e 374 *isSaturated = kTRUE;
375 }
376 else
377 {
ada26c2d 378 *isSaturated = kFALSE;
d99769c3 379 }
380 }
de487b6e 381
58e1d4ed 382 return ( charge > 0.0 ? charge : 0.0 );
d99769c3 383}
de487b6e 384
385//_____________________________________________________________________________
386Bool_t
387AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
388 Int_t* statusMap) const
389
390{
391 /// Check if a given pad is ok or not.
392
393 // First a protection against bad input parameters
394 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
395 if (!de) return kFALSE; // not existing DE
396 if (!de->IsExistingChannel(manuId,manuChannel))
397 {
398 // non-existing (might happen when we get parity errors in read-out
399 // that spoils the manuId
400 return kFALSE;
401 }
402 if (!de->IsConnectedChannel(manuId,manuChannel))
403 {
404 // existing (in read-out), but not connected channel
405 return kFALSE;
406 }
407
408 // ok, now we have a valid channel number, so let's see if that pad
409 // behaves or not ;-)
410
411 Int_t sm = fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
412
413 if (statusMap) *statusMap = sm;
414
415 if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
416 {
417 // pad itself is bad (not testing its neighbours at this stage)
418 return kFALSE;
419 }
420
421 return kTRUE;
422}
423
424//_____________________________________________________________________________
425Int_t
426AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
427{
428 /// Return the status of the given pad
429 return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
430}
431
432//_____________________________________________________________________________
433Int_t
434AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
435{
436 /// Return the status map of the given pad
437 return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
438
439}
440