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)),
85 Ctor(calibMode,calib,recoParams);
88 //_____________________________________________________________________________
89 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
90 const char* calibMode)
92 fLogger(new AliMUONLogger(20000)),
105 Ctor(calibMode,calib,0x0);
108 //_____________________________________________________________________________
110 AliMUONDigitCalibrator::Ctor(const char* calibMode,
111 const AliMUONCalibrationData& calib,
112 const AliMUONRecoParam* recoParams)
116 TString cMode(calibMode);
119 if ( cMode == "NOGAIN" )
121 fApplyGains = fgkNoGain;
122 AliInfo("Will NOT apply gain correction");
124 else if ( cMode == "GAINCONSTANTCAPA" )
126 fApplyGains = fgkGainConstantCapa;
127 AliInfo("Will apply gain correction, but with constant capacitance");
129 else if ( cMode == "GAIN" )
131 fApplyGains = fgkGain;
132 AliInfo("Will apply gain correction, with measured capacitances");
134 else if ( cMode == "INJECTIONGAIN")
136 fApplyGains = fgkInjectionGain;
137 AliInfo("Will apply injection gain correction, with EMELEC factory gains");
141 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
142 fApplyGains = fgkNoGain;
145 // Load mapping manu store
146 if ( ! AliMpCDB::LoadManuStore() ) {
147 AliFatal("Could not access manu store from OCDB !");
150 fStatusMaker = new AliMUONPadStatusMaker(calib);
152 // Set default values, as loose as reasonable
154 fChargeSigmaCut = 3.0;
156 Int_t mask(0x8080); // reject pads where ped *or* hv are missing
160 // if we have reco params, we use limits and cuts from there :
162 fStatusMaker->SetHVSt12Limits(recoParams->HVSt12LowLimit(),recoParams->HVSt12HighLimit());
163 fStatusMaker->SetHVSt345Limits(recoParams->HVSt345LowLimit(),recoParams->HVSt345HighLimit());
164 fStatusMaker->SetPedMeanLimits(recoParams->PedMeanLowLimit(),recoParams->PedMeanHighLimit());
165 fStatusMaker->SetPedSigmaLimits(recoParams->PedSigmaLowLimit(),recoParams->PedSigmaHighLimit());
166 fStatusMaker->SetGainA1Limits(recoParams->GainA1LowLimit(),recoParams->GainA1HighLimit());
167 fStatusMaker->SetGainA2Limits(recoParams->GainA2LowLimit(),recoParams->GainA2HighLimit());
168 fStatusMaker->SetGainThresLimits(recoParams->GainThresLowLimit(),recoParams->GainThresHighLimit());
170 mask = recoParams->PadGoodnessMask();
171 //WARNING : getting this mask wrong is a very effective way of getting
172 //no digits at all out of this class ;-)
174 fChargeSigmaCut = recoParams->ChargeSigmaCut();
177 Bool_t deferredInitialization = kTRUE;
179 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
181 fPedestals = calib.Pedestals();
183 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
184 // to get the saturation value...
186 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
188 fCapacitances = calib.Capacitances();
192 //_____________________________________________________________________________
193 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
197 delete fStatusMapMaker;
199 AliInfo("Summary of messages:");
202 AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
203 fNumberOfPads,fNumberOfBadPads,
204 ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
209 //_____________________________________________________________________________
211 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
213 /// Calibrate the digits contained in digitStore
214 TIter next(digitStore.CreateTrackerIterator());
215 AliMUONVDigit* digit;
217 fStatusMapMaker->RefreshRejectProbabilities(); // this will do something only for simulations
218 // (and only for those simulations where the reject list contain probabilities which are
219 // different from zero or one)
221 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
223 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
225 if ( digit->IsCalibrated() )
227 fLogger->Log("ERROR : trying to calibrate a digit twice");
231 digit->Calibrated(kTRUE);
235 Bool_t isSaturated(kFALSE);
239 Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
241 digit->SetStatusMap(statusMap);
245 charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
246 digit->ADC(),fChargeSigmaCut,&isSaturated);
250 AliDebug(3,Form("Rejecting the pad DE %4d MANU %4d CH %2d ADC %6d STATUSMAP %x STATUS %s",
251 digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
252 digit->ADC(),statusMap,
253 fStatusMaker->AsString(fStatusMaker->PadStatus(digit->DetElemId(),digit->ManuId(),digit->ManuChannel())).Data()));
259 digit->SetCharge(charge);
260 digit->Saturated(isSaturated);
264 //_____________________________________________________________________________
266 AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
267 Float_t adc, Float_t nsigmas,
268 Bool_t* isSaturated) const
271 /// Calibrate one digit
274 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
275 (fPedestals->FindObject(detElemId,manuId));
279 // no pedestal -> no charge
280 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
285 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
286 (fGains->FindObject(detElemId,manuId));
290 if ( fApplyGains != fgkNoGain )
292 // no gain -> no charge
293 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
299 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
301 // Gain (mV/fC) = 1/(a0*capa) with a0~1.25 and capa~0.2
303 Float_t capa(0.2); // capa = 0.2 and a0 = 1.25
304 Float_t a0(1.25); // is equivalent to gain = 4 mV/fC
306 Float_t adc2mv(0.61); // 1 ADC channel = 0.61 mV
307 Float_t injGain(4); // By default the gain is set to 4 mV/fC
309 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
312 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
314 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
318 capa = param->ValueAsFloat(manuChannel,0);
319 injGain = param->ValueAsFloat(manuChannel,1);
323 // If capa not found in the OCDB we use default value
324 fLogger->Log(Form("No capa (injGain) found for serialNumber=%d",serialNumber));
329 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
331 if ( fApplyGains == fgkGain || fApplyGains == fgkGainConstantCapa )
333 a0 = gain->ValueAsFloat(manuChannel,0);
334 a1 = gain->ValueAsFloat(manuChannel,1);
335 Int_t thres = gain->ValueAsInt(manuChannel,2);
342 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
344 charge *= capa*adc2mv;
346 else if ( fApplyGains == fgkInjectionGain )
349 charge = padc*adc2mv/injGain;
353 charge = a0*padc*capa*adc2mv;
359 Int_t saturation(3000);
361 if ( gain && ( fApplyGains != fgkNoGain ) )
363 saturation = gain->ValueAsInt(manuChannel,4);
366 if ( padc >= saturation )
368 *isSaturated = kTRUE;
372 *isSaturated = kFALSE;
379 //_____________________________________________________________________________
381 AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
382 Int_t* statusMap) const
385 /// Check if a given pad is ok or not.
387 // First a protection against bad input parameters
388 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
389 if (!de) return kFALSE; // not existing DE
390 if (!de->IsExistingChannel(manuId,manuChannel))
392 // non-existing (might happen when we get parity errors in read-out
393 // that spoils the manuId
396 if (!de->IsConnectedChannel(manuId,manuChannel))
398 // existing (in read-out), but not connected channel
402 // ok, now we have a valid channel number, so let's see if that pad
403 // behaves or not ;-)
405 Int_t sm = fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
407 if (statusMap) *statusMap = sm;
409 if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
411 // pad itself is bad (not testing its neighbours at this stage)
418 //_____________________________________________________________________________
420 AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
422 /// Return the status of the given pad
423 return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
426 //_____________________________________________________________________________
428 AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
430 /// Return the status map of the given pad
431 return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);