1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONDigitCalibrator.h"
21 #include "AliMUONCalibrationData.h"
22 #include "AliMUONLogger.h"
23 #include "AliMUONPadStatusMaker.h"
24 #include "AliMUONPadStatusMapMaker.h"
25 #include "AliMUONRecoParam.h"
26 #include "AliMUONVCalibParam.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMUONVStore.h"
30 #include "AliMpBusPatch.h"
31 #include "AliMpConstants.h"
33 #include "AliMpDDLStore.h"
34 #include "AliMpDEIterator.h"
35 #include "AliMpDetElement.h"
36 #include "AliMpManuStore.h"
38 //-----------------------------------------------------------------------------
39 /// \class AliMUONDigitCalibrator
40 /// Class used to calibrate digits (either real or simulated ones).
42 /// The calibration consists of subtracting the pedestal
43 /// and multiplying by a gain, so that
44 /// Signal = (ADC-pedestal)*gain
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
54 /// \author Laurent Aphecetche
55 //-----------------------------------------------------------------------------
59 ClassImp(AliMUONDigitCalibrator)
62 const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
63 const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
64 const Int_t AliMUONDigitCalibrator::fgkGain(2);
65 const Int_t AliMUONDigitCalibrator::fgkInjectionGain(3);
67 //_____________________________________________________________________________
68 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
69 const AliMUONRecoParam* recoParams,
70 const char* calibMode)
72 fLogger(new AliMUONLogger(20000)),
86 Ctor(calibMode,calib,recoParams);
89 //_____________________________________________________________________________
90 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
91 const char* calibMode)
93 fLogger(new AliMUONLogger(20000)),
107 Ctor(calibMode,calib,0x0);
110 //_____________________________________________________________________________
112 AliMUONDigitCalibrator::Ctor(const char* calibMode,
113 const AliMUONCalibrationData& calib,
114 const AliMUONRecoParam* recoParams)
118 TString cMode(calibMode);
121 if ( cMode == "NOGAIN" )
123 fApplyGains = fgkNoGain;
124 AliInfo("Will NOT apply gain correction");
126 else if ( cMode == "GAINCONSTANTCAPA" )
128 fApplyGains = fgkGainConstantCapa;
129 AliInfo("Will apply gain correction, but with constant capacitance");
131 else if ( cMode == "GAIN" )
133 fApplyGains = fgkGain;
134 AliInfo("Will apply gain correction, with measured capacitances");
136 else if ( cMode == "INJECTIONGAIN")
138 fApplyGains = fgkInjectionGain;
139 AliInfo("Will apply injection gain correction, with EMELEC factory gains");
143 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
144 fApplyGains = fgkNoGain;
147 // Load mapping manu store
148 if ( ! AliMpCDB::LoadManuStore() ) {
149 AliFatal("Could not access manu store from OCDB !");
152 fStatusMaker = new AliMUONPadStatusMaker(calib);
154 // Set default values, as loose as reasonable
156 fChargeSigmaCut = 3.0;
158 fMask = 0x8080; // reject pads where ped *or* hv are missing
162 // if we have reco params, we use limits and cuts from there :
164 fStatusMaker->SetLimits(*recoParams);
166 fMask = recoParams->PadGoodnessMask();
167 //WARNING : getting this mask wrong is a very effective way of getting
168 //no digits at all out of this class ;-)
170 fChargeSigmaCut = recoParams->ChargeSigmaCut();
173 Bool_t deferredInitialization = kTRUE;
175 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,fMask,deferredInitialization);
177 fPedestals = calib.Pedestals();
179 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
180 // to get the saturation value...
182 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
184 fCapacitances = calib.Capacitances();
188 //_____________________________________________________________________________
189 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
193 if ( fNumberOfPads > 0 )
197 fStatusMaker->Report(fMask);
200 AliInfo("Summary of messages:");
204 AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
205 fNumberOfPads,fNumberOfBadPads,
206 ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
210 delete fStatusMapMaker;
214 //_____________________________________________________________________________
216 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
218 /// Calibrate the digits contained in digitStore
219 TIter next(digitStore.CreateTrackerIterator());
220 AliMUONVDigit* digit;
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)
226 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
228 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
230 if ( digit->IsCalibrated() )
232 fLogger->Log("ERROR : trying to calibrate a digit twice");
236 digit->Calibrated(kTRUE);
240 Bool_t isSaturated(kFALSE);
244 Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
246 digit->SetStatusMap(statusMap);
250 charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
251 digit->ADC(),fChargeSigmaCut,&isSaturated);
258 digit->SetCharge(charge);
259 digit->Saturated(isSaturated);
263 //_____________________________________________________________________________
265 AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
266 Float_t adc, Float_t nsigmas,
267 Bool_t* isSaturated) const
270 /// Calibrate one digit
273 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
274 (fPedestals->FindObject(detElemId,manuId));
278 // no pedestal -> no charge
279 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
284 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
285 (fGains->FindObject(detElemId,manuId));
289 if ( fApplyGains != fgkNoGain )
291 // no gain -> no charge
292 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
298 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
300 // Gain (mV/fC) = 1/(a0*capa) with a0~1.25 and capa~0.2
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
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
308 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
311 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
313 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
317 capa = param->ValueAsFloat(manuChannel,0);
318 injGain = param->ValueAsFloat(manuChannel,1);
322 // If capa not found in the OCDB we use default value
323 fLogger->Log(Form("No capa (injGain) found for serialNumber=%d",serialNumber));
328 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
330 if ( fApplyGains == fgkGain || fApplyGains == fgkGainConstantCapa )
332 a0 = gain->ValueAsFloat(manuChannel,0);
333 a1 = gain->ValueAsFloat(manuChannel,1);
334 Int_t thres = gain->ValueAsInt(manuChannel,2);
341 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
343 charge *= capa*adc2mv;
345 else if ( fApplyGains == fgkInjectionGain )
348 charge = padc*adc2mv/injGain;
352 charge = a0*padc*capa*adc2mv;
358 Int_t saturation(3000);
360 if ( gain && ( fApplyGains != fgkNoGain ) )
362 saturation = gain->ValueAsInt(manuChannel,4);
365 if ( padc >= saturation )
367 *isSaturated = kTRUE;
371 *isSaturated = kFALSE;
378 //_____________________________________________________________________________
380 AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
381 Int_t* statusMap) const
384 /// Check if a given pad is ok or not.
386 // First a protection against bad input parameters
387 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
388 if (!de) return kFALSE; // not existing DE
389 if (!de->IsExistingChannel(manuId,manuChannel))
391 // non-existing (might happen when we get parity errors in read-out
392 // that spoils the manuId
395 if (!de->IsConnectedChannel(manuId,manuChannel))
397 // existing (in read-out), but not connected channel
401 // ok, now we have a valid channel number, so let's see if that pad
402 // behaves or not ;-)
404 Int_t sm = fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
406 if (statusMap) *statusMap = sm;
408 if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
410 // pad itself is bad (not testing its neighbours at this stage)
417 //_____________________________________________________________________________
419 AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
421 /// Return the status of the given pad
422 return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
425 //_____________________________________________________________________________
427 AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
429 /// Return the status map of the given pad
430 return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);