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 "AliMUONVCalibParam.h"
26 #include "AliMUONVDigit.h"
27 #include "AliMUONVDigitStore.h"
28 #include "AliMUONVStore.h"
29 #include "AliMpBusPatch.h"
30 #include "AliMpConstants.h"
31 #include "AliMpDDLStore.h"
32 #include "AliMpDEIterator.h"
33 #include "AliMpDetElement.h"
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONDigitCalibrator
37 /// Class used to calibrate digits (either real or simulated ones).
39 /// The calibration consists of subtracting the pedestal
40 /// and multiplying by a gain, so that
41 /// Signal = (ADC-pedestal)*gain
43 /// Please note also that for the moment, if a digit lies on a dead channel
44 /// we remove this digit from the list of digits.
45 /// FIXME: this has to be revisited. By using the AliMUONDigit::fFlags we
46 /// should in principle flag a digit as bad w/o removing it, but this
47 /// then requires some changes in the cluster finder to deal with this extra
48 /// information correctly (e.g. to set a quality for the cluster if it contains
51 /// \author Laurent Aphecetche
52 //-----------------------------------------------------------------------------
56 ClassImp(AliMUONDigitCalibrator)
59 const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
60 const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
61 const Int_t AliMUONDigitCalibrator::fgkGain(2);
63 //_____________________________________________________________________________
64 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
65 const char* calibMode)
67 fLogger(new AliMUONLogger(20000)),
74 fNofChannelsPerDE(new TExMap)
78 TString cMode(calibMode);
81 if ( cMode == "NOGAIN" )
83 fApplyGains = fgkNoGain;
84 AliInfo("Will NOT apply gain correction");
86 else if ( cMode == "GAINCONSTANTCAPA" )
88 fApplyGains = fgkGainConstantCapa;
89 AliInfo("Will apply gain correction, but with constant capacitance");
91 else if ( cMode == "GAIN" )
93 fApplyGains = fgkGain;
94 AliInfo("Will apply gain correction, with measured capacitances");
98 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
99 fApplyGains = fgkNoGain;
102 fStatusMaker = new AliMUONPadStatusMaker(calib);
104 // this is here that we decide on our "goodness" policy, i.e.
105 // what do we call an invalid pad (a pad maybe bad because its HV
106 // was too low, or its pedestals too high, etc..)
107 // FIXME: find a way not to hard-code the goodness policy (i.e. the limits)
109 fStatusMaker->SetHVSt12Limits(1300,1600);
110 fStatusMaker->SetHVSt345Limits(1500,2000);
111 fStatusMaker->SetPedMeanLimits(50,200);
112 fStatusMaker->SetPedSigmaLimits(0.1,3);
115 //FIXME: kind of fake one for the moment, we consider dead only
116 // if ped and/or hv value missing.
117 //WARNING : getting this mask wrong is a very effective way of getting
118 //no digits at all out of this class ;-)
120 Bool_t deferredInitialization = kTRUE;
122 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
124 fPedestals = calib.Pedestals();
126 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
127 // to get the saturation value...
129 if ( fApplyGains == fgkGain )
131 fCapacitances = calib.Capacitances();
134 // FIXME: get the nof of channels per de directly within AliMpDetElement ?
135 // or use the AliMUONTrackerData class for that ?
141 while ( !it.IsDone() )
144 AliMpDetElement* det = it.CurrentDE();
145 Int_t detElemId = det->GetId();
148 for ( Int_t i = 0; i < det->GetNofBusPatches(); ++i )
150 Int_t busPatchId = det->GetBusPatchId(i);
151 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
152 for ( Int_t j = 0; j < bp->GetNofManus(); ++j )
154 Int_t manuId = bp->GetManuId(j);
155 nchannels += det->NofChannelsInManu(manuId);
161 fNofChannelsPerDE->Add((Long_t)detElemId,(Long_t)nchannels);
165 //_____________________________________________________________________________
166 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
170 delete fStatusMapMaker;
172 AliInfo("Summary of messages:");
176 delete fNofChannelsPerDE;
179 //_____________________________________________________________________________
181 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
183 /// Calibrate the digits contained in digitStore
184 TIter next(digitStore.CreateTrackerIterator());
185 AliMUONVDigit* digit;
187 Double_t nsigmas(3.0);
189 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
191 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
193 if ( digit->DetElemId() != detElemId )
195 // Find out occupancy of that DE
196 detElemId = digit->DetElemId();
197 Double_t nchannels = fNofChannelsPerDE->GetValue(detElemId);
198 Double_t occ = digitStore.GetSize(detElemId)/nchannels;
201 nsigmas = 10.0; // enlarge (a lot) sigma cut if occupancy is high
202 // (which probably means zero suppression was not exactly OK).
203 fLogger->Log(Form("Will use %5.0f*sigma cut for DE %04d "
204 "due to high occupancy",nsigmas,detElemId));
212 CalibrateDigit(*digit,nsigmas);
216 //_____________________________________________________________________________
218 AliMUONDigitCalibrator::CalibrateDigit(AliMUONVDigit& digit, Double_t nsigmas)
220 /// Calibrate one digit
222 if ( digit.IsCalibrated() )
224 fLogger->Log("ERROR : trying to calibrate a digit twice");
228 Int_t statusMap = fStatusMapMaker->StatusMap(digit.DetElemId(),
230 digit.ManuChannel());
232 digit.SetStatusMap(statusMap);
233 digit.Calibrated(kTRUE);
235 if ( ( statusMap & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
237 // pad itself is bad (not testing its neighbours at this stage)
239 fLogger->Log(Form("%s:%d:Channel detElemId %d manuId %d "
240 "manuChannel %d is bad %x",__FILE__,__LINE__,
241 digit.DetElemId(),digit.ManuId(),
242 digit.ManuChannel(),digit.StatusMap()));
246 // If the channel is good, go on with the calibration itself.
248 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
249 (fPedestals->FindObject(digit.DetElemId(),digit.ManuId()));
253 // no pedestal -> no charge
256 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",
257 digit.DetElemId(),digit.ManuId()));
262 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
263 (fGains->FindObject(digit.DetElemId(),digit.ManuId()));
267 if ( fApplyGains != fgkNoGain )
269 // no gain -> no charge
272 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
273 digit.DetElemId(),digit.ManuId()));
278 Int_t manuChannel = digit.ManuChannel();
279 Float_t adc = digit.ADC();
280 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
284 if ( fApplyGains == fgkGainConstantCapa )
288 else if ( fApplyGains == fgkGain )
290 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(digit.DetElemId());
292 Int_t serialNumber = de->GetManuSerialFromId(digit.ManuId());
294 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
298 capa = param->ValueAsFloat(digit.ManuChannel());
302 fLogger->Log(Form("No capa found for serialNumber=%d",serialNumber));
307 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
309 if ( fApplyGains != fgkNoGain )
311 Float_t a0 = gain->ValueAsFloat(manuChannel,0);
312 Float_t a1 = gain->ValueAsFloat(manuChannel,1);
313 Int_t thres = gain->ValueAsInt(manuChannel,2);
320 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
330 digit.SetCharge(charge);
332 Int_t saturation(3000);
336 saturation = gain->ValueAsInt(manuChannel,4);
339 if ( padc >= saturation )
341 digit.Saturated(kTRUE);