72 template <
class DFrame>
73 class RawChargeFromSample {
84 inline double getRawCharge(
const double decodedCharge,
const double pedestal)
const {
return decodedCharge; }
98 : siPMParameter_(*
cond.getHcalSiPMParameter(
id)),
99 fcByPE_(siPMParameter_.getFCByPE()),
100 corr_(
cond.getHcalSiPMCharacteristics()->getNonLinearities(siPMParameter_.getType())) {
102 throw cms::Exception(
"HBHEPhase1BadDB") <<
"Invalid fC/PE conversion factor for SiPM " <<
id << std::endl;
109 for (
int ts = firstTS; ts < lastTS; ++ts) {
114 const double effectivePixelsFired = sipmQ / fcByPE_;
115 factor_ = corr_.getRecoCorrectionFactor(effectivePixelsFired);
118 inline double getRawCharge(
const double decodedCharge,
const double pedestal)
const {
138 float getDifferentialChargeGain(
const HcalQIECoder& coder,
141 const unsigned capid,
142 const bool isQIE11) {
144 static const unsigned mantissaMaskQIE8 = 0x1f;
145 static const unsigned mantissaMaskQIE11 = 0x3f;
147 const float q = coder.
charge(shape,
adc, capid);
148 const unsigned mantissaMask = isQIE11 ? mantissaMaskQIE11 : mantissaMaskQIE8;
149 const unsigned mantissa =
adc & mantissaMask;
154 if (mantissa == 0
U || mantissa == mantissaMask - 1
U)
156 else if (mantissa == 1
U || mantissa == mantissaMask)
159 const float qup = coder.
charge(shape,
adc + 1
U, capid);
160 const float qdown = coder.
charge(shape,
adc - 1
U, capid);
161 const float upGain = qup -
q;
162 const float downGain =
q - qdown;
163 const float averageGain = (qup - qdown) / 2.
f;
164 if (
std::abs(upGain - downGain) < 0.01f * averageGain)
173 const float q2up = coder.
charge(shape,
adc + 2
U, capid);
174 const float q2down = coder.
charge(shape,
adc - 2
U, capid);
175 const float upGain2 = q2up - qup;
176 const float downGain2 = qdown - q2down;
187 std::pair<bool, bool> findHWErrors(
const HBHEDataFrame& df,
const unsigned len) {
188 bool linkErr =
false;
189 bool capidErr =
false;
191 int expectedCapid = df[0].capid();
192 for (
unsigned i = 0;
i < len; ++
i) {
195 if (df[
i].capid() != expectedCapid)
197 expectedCapid = (expectedCapid + 1) % 4;
200 return std::pair<bool, bool>(linkErr, capidErr);
203 std::pair<bool, bool> findHWErrors(
const QIE11DataFrame& df,
const unsigned ) {
207 std::unique_ptr<HBHEStatusBitSetter> parse_HBHEStatusBitSetter(
const edm::ParameterSet& psdigi) {
208 return std::make_unique<HBHEStatusBitSetter>(
212 psdigi.
getParameter<std::vector<edm::ParameterSet> >(
"pulseShapeParameterSets"));
215 std::unique_ptr<HBHEPulseShapeFlagSetter> parse_HBHEPulseShapeFlagSetter(
const edm::ParameterSet& psPulseShape,
216 const bool setLegacyFlags) {
217 return std::make_unique<HBHEPulseShapeFlagSetter>(
218 psPulseShape.
getParameter<
double>(
"MinimumChargeThreshold"),
219 psPulseShape.
getParameter<
double>(
"TS4TS5ChargeThreshold"),
220 psPulseShape.
getParameter<
double>(
"TS3TS4ChargeThreshold"),
221 psPulseShape.
getParameter<
double>(
"TS3TS4UpperChargeThreshold"),
222 psPulseShape.
getParameter<
double>(
"TS5TS6ChargeThreshold"),
223 psPulseShape.
getParameter<
double>(
"TS5TS6UpperChargeThreshold"),
226 psPulseShape.
getParameter<
unsigned int>(
"TrianglePeakTS"),
227 psPulseShape.
getParameter<std::vector<double> >(
"LinearThreshold"),
228 psPulseShape.
getParameter<std::vector<double> >(
"LinearCut"),
229 psPulseShape.
getParameter<std::vector<double> >(
"RMS8MaxThreshold"),
230 psPulseShape.
getParameter<std::vector<double> >(
"RMS8MaxCut"),
231 psPulseShape.
getParameter<std::vector<double> >(
"LeftSlopeThreshold"),
232 psPulseShape.
getParameter<std::vector<double> >(
"LeftSlopeCut"),
233 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeThreshold"),
234 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeCut"),
235 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeSmallThreshold"),
236 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeSmallCut"),
237 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5LowerThreshold"),
238 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5LowerCut"),
239 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5UpperThreshold"),
240 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5UpperCut"),
288 std::unique_ptr<AbsHBHEPhase1Algo>
reco_;
301 template <
class DataFrame,
class Collection>
306 const bool isRealData,
332 : algoConfigClass_(conf.getParameter<
std::
string>(
"algoConfigClass")),
333 processQIE8_(conf.getParameter<
bool>(
"processQIE8")),
334 processQIE11_(conf.getParameter<
bool>(
"processQIE11")),
335 saveInfos_(conf.getParameter<
bool>(
"saveInfos")),
336 saveDroppedInfos_(conf.getParameter<
bool>(
"saveDroppedInfos")),
337 makeRecHits_(conf.getParameter<
bool>(
"makeRecHits")),
338 dropZSmarkedPassed_(conf.getParameter<
bool>(
"dropZSmarkedPassed")),
339 tsFromDB_(conf.getParameter<
bool>(
"tsFromDB")),
340 recoParamsFromDB_(conf.getParameter<
bool>(
"recoParamsFromDB")),
341 saveEffectivePedestal_(conf.getParameter<
bool>(
"saveEffectivePedestal")),
342 use8ts_(conf.getParameter<
bool>(
"use8ts")),
343 sipmQTSShift_(conf.getParameter<
int>(
"sipmQTSShift")),
344 sipmQNTStoSum_(conf.getParameter<
int>(
"sipmQNTStoSum")),
345 setNegativeFlagsQIE8_(conf.getParameter<
bool>(
"setNegativeFlagsQIE8")),
346 setNegativeFlagsQIE11_(conf.getParameter<
bool>(
"setNegativeFlagsQIE11")),
347 setNoiseFlagsQIE8_(conf.getParameter<
bool>(
"setNoiseFlagsQIE8")),
348 setNoiseFlagsQIE11_(conf.getParameter<
bool>(
"setNoiseFlagsQIE11")),
349 setPulseShapeFlagsQIE8_(conf.getParameter<
bool>(
"setPulseShapeFlagsQIE8")),
350 setPulseShapeFlagsQIE11_(conf.getParameter<
bool>(
"setPulseShapeFlagsQIE11")),
352 negEFilter_(nullptr) {
355 throw cms::Exception(
"HBHEPhase1BadConfig") <<
"Invalid HBHEPhase1Algo algorithm configuration" << std::endl;
382 produces<HBHEChannelInfoCollection>();
385 produces<HBHERecHitCollection>();
396 template <
class DFrame,
class Collection>
401 const bool isRealData,
405 const bool use8ts_) {
413 for (
typename Collection::const_iterator it = coll.begin(); it != coll.end(); ++it) {
414 const DFrame&
frame(*it);
427 if (taggedBadByDb && skipDroppedChannels)
431 bool dropByZS =
false;
433 if (
frame.zsMarkAndPass())
435 if (dropByZS && skipDroppedChannels)
448 const double fcByPE = siPMParameter.
getFCByPE();
454 lambda =
cond.getHcalSiPMCharacteristics()->getCrossTalk(siPMParameter.getType());
462 const int nRead =
cs.size();
480 int nTSToCopy =
maxTS;
483 const int soiWanted = 3;
489 tsShift = soi - soiWanted;
496 const int nExcessTS = nRead - nTSToCopy;
497 if (tsShift > nExcessTS)
503 for (
int copyTS = 0; copyTS < nTSToCopy; ++copyTS) {
504 const int inputTS = copyTS + tsShift;
506 const uint8_t
adc =
s.adc();
507 const int capid =
s.capid();
510 const double pedestal = saveEffectivePeds ?
calib.effpedestal(capid) :
calib.pedestal(capid);
512 const double gain =
calib.respcorrgain(capid);
515 const double rawCharge = rcfs.getRawCharge(
cs[inputTS],
calib.pedestal(capid));
516 const float t = getTDCTimeFromSample(
s);
517 const float dfc = getDifferentialChargeGain(*channelCoder, *shape,
adc, capid, channelInfo->
hasTimeInfo());
524 const int fitSoi = soi - tsShift;
526 const std::pair<bool, bool> hwerr = findHWErrors(
frame,
maxTS);
537 taggedBadByDb || dropByZS);
540 const bool makeThisRechit = !channelInfo->
isDropped();
542 infos->push_back(*channelInfo);
545 if (
rechits && makeThisRechit) {
595 const unsigned nRead =
info.nSamples();
596 for (
unsigned i = 0;
i < nRead; ++
i)
630 unsigned maxOutputSize = 0;
634 maxOutputSize += hbDigis->
size();
640 maxOutputSize += heDigis->
size();
644 std::unique_ptr<HBHEChannelInfoCollection>
infos;
646 infos = std::make_unique<HBHEChannelInfoCollection>();
647 infos->reserve(maxOutputSize);
650 std::unique_ptr<HBHERecHitCollection>
out;
652 out = std::make_unique<HBHERecHitCollection>();
653 out->reserve(maxOutputSize);
657 const bool isData =
e.isRealData();
663 processData<HBHEDataFrame>(
674 processData<QIE11DataFrame>(
691 paramTS_ = std::make_unique<HcalRecoParams>(*
p.product());
693 if (
reco_->isConfigurable()) {
697 <<
"Invalid HBHEPhase1Reconstructor \"algoConfigClass\" parameter value \"" <<
algoConfigClass_ <<
'"'
701 <<
"Failed to configure HBHEPhase1Algo algorithm from EventSetup" << std::endl;
713 edm::LogWarning(
"EventSetup") <<
"HBHEPhase1Reconstructor failed to get HcalFrontEndMap!" << std::endl;
721 #define add_param_set(name) \
722 edm::ParameterSetDescription name; \
723 name.setAllowAnything(); \
724 desc.add<edm::ParameterSetDescription>(#name, name)
733 desc.
add<
bool>(
"processQIE8");
734 desc.
add<
bool>(
"processQIE11");
735 desc.
add<
bool>(
"saveInfos");
736 desc.
add<
bool>(
"saveDroppedInfos");
737 desc.
add<
bool>(
"makeRecHits");
738 desc.
add<
bool>(
"dropZSmarkedPassed");
739 desc.
add<
bool>(
"tsFromDB");
740 desc.
add<
bool>(
"recoParamsFromDB");
741 desc.
add<
bool>(
"saveEffectivePedestal",
false);
742 desc.
add<
bool>(
"use8ts",
false);
743 desc.
add<
int>(
"sipmQTSShift", 0);
744 desc.
add<
int>(
"sipmQNTStoSum", 3);
745 desc.
add<
bool>(
"setNegativeFlagsQIE8");
746 desc.
add<
bool>(
"setNegativeFlagsQIE11");
747 desc.
add<
bool>(
"setNoiseFlagsQIE8");
748 desc.
add<
bool>(
"setNoiseFlagsQIE11");
749 desc.
add<
bool>(
"setPulseShapeFlagsQIE8");
750 desc.
add<
bool>(
"setPulseShapeFlagsQIE11");
751 desc.
add<
bool>(
"setLegacyFlagsQIE8");
752 desc.
add<
bool>(
"setLegacyFlagsQIE11");