75 template <
class DFrame>
76 class RawChargeFromSample {
87 inline double getRawCharge(
const double decodedCharge,
const double pedestal)
const {
return decodedCharge; }
101 : siPMParameter_(*properties.siPMParameter),
102 fcByPE_(siPMParameter_.getFCByPE()),
103 corr_(
cond.getHcalSiPMCharacteristics()->getNonLinearities(siPMParameter_.getType())) {
105 throw cms::Exception(
"HBHEPhase1BadDB") <<
"Invalid fC/PE conversion factor" << std::endl;
111 for (
int ts = firstTS; ts < lastTS; ++ts) {
116 const double effectivePixelsFired = sipmQ / fcByPE_;
117 factor_ = corr_.getRecoCorrectionFactor(effectivePixelsFired);
120 inline double getRawCharge(
const double decodedCharge,
const double pedestal)
const {
140 float getDifferentialChargeGain(
const HcalQIECoder& coder,
143 const unsigned capid,
144 const bool isQIE11) {
146 static const unsigned mantissaMaskQIE8 = 0x1f;
147 static const unsigned mantissaMaskQIE11 = 0x3f;
149 const float q = coder.
charge(shape,
adc, capid);
150 const unsigned mantissaMask = isQIE11 ? mantissaMaskQIE11 : mantissaMaskQIE8;
151 const unsigned mantissa =
adc & mantissaMask;
156 if (mantissa == 0
U || mantissa == mantissaMask - 1
U)
158 else if (mantissa == 1
U || mantissa == mantissaMask)
161 const float qup = coder.
charge(shape,
adc + 1
U, capid);
162 const float qdown = coder.
charge(shape,
adc - 1
U, capid);
163 const float upGain = qup -
q;
164 const float downGain =
q - qdown;
165 const float averageGain = (qup - qdown) / 2.
f;
166 if (
std::abs(upGain - downGain) < 0.01f * averageGain)
175 const float q2up = coder.
charge(shape,
adc + 2
U, capid);
176 const float q2down = coder.
charge(shape,
adc - 2
U, capid);
177 const float upGain2 = q2up - qup;
178 const float downGain2 = qdown - q2down;
189 std::pair<bool, bool> findHWErrors(
const HBHEDataFrame&
df,
const unsigned len) {
190 bool linkErr =
false;
191 bool capidErr =
false;
193 int expectedCapid =
df[0].capid();
194 for (
unsigned i = 0;
i < len; ++
i) {
197 if (
df[
i].capid() != expectedCapid)
199 expectedCapid = (expectedCapid + 1) % 4;
202 return std::pair<bool, bool>(linkErr, capidErr);
205 std::pair<bool, bool> findHWErrors(
const QIE11DataFrame&
df,
const unsigned ) {
206 return std::pair<bool, bool>(
df.linkError(),
df.capidError());
209 std::unique_ptr<HBHEStatusBitSetter> parse_HBHEStatusBitSetter(
const edm::ParameterSet& psdigi) {
210 return std::make_unique<HBHEStatusBitSetter>(
214 psdigi.
getParameter<std::vector<edm::ParameterSet> >(
"pulseShapeParameterSets"));
217 std::unique_ptr<HBHEPulseShapeFlagSetter> parse_HBHEPulseShapeFlagSetter(
const edm::ParameterSet& psPulseShape,
218 const bool setLegacyFlags) {
219 return std::make_unique<HBHEPulseShapeFlagSetter>(
220 psPulseShape.
getParameter<
double>(
"MinimumChargeThreshold"),
221 psPulseShape.
getParameter<
double>(
"TS4TS5ChargeThreshold"),
222 psPulseShape.
getParameter<
double>(
"TS3TS4ChargeThreshold"),
223 psPulseShape.
getParameter<
double>(
"TS3TS4UpperChargeThreshold"),
224 psPulseShape.
getParameter<
double>(
"TS5TS6ChargeThreshold"),
225 psPulseShape.
getParameter<
double>(
"TS5TS6UpperChargeThreshold"),
228 psPulseShape.
getParameter<
unsigned int>(
"TrianglePeakTS"),
229 psPulseShape.
getParameter<std::vector<double> >(
"LinearThreshold"),
230 psPulseShape.
getParameter<std::vector<double> >(
"LinearCut"),
231 psPulseShape.
getParameter<std::vector<double> >(
"RMS8MaxThreshold"),
232 psPulseShape.
getParameter<std::vector<double> >(
"RMS8MaxCut"),
233 psPulseShape.
getParameter<std::vector<double> >(
"LeftSlopeThreshold"),
234 psPulseShape.
getParameter<std::vector<double> >(
"LeftSlopeCut"),
235 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeThreshold"),
236 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeCut"),
237 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeSmallThreshold"),
238 psPulseShape.
getParameter<std::vector<double> >(
"RightSlopeSmallCut"),
239 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5LowerThreshold"),
240 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5LowerCut"),
241 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5UpperThreshold"),
242 psPulseShape.
getParameter<std::vector<double> >(
"TS4TS5UpperCut"),
252 const int determineIndexShift(
const int soi,
const int nRead,
const int soiWanted,
const int nReadWanted) {
253 assert(nReadWanted <= nRead);
254 if (soi < 0 || soi >= nRead)
257 return std::clamp(soi - soiWanted, 0, nRead - nReadWanted);
266 const unsigned six_bits_mask = 0x3f;
267 const int soiWanted = 3;
268 const int nRead =
frame.size();
269 const int nTSToCopy =
std::min(5, nRead);
270 const int tsShift = determineIndexShift(soi, nRead, soiWanted, nTSToCopy);
273 for (
int ts = 0; ts < nTSToCopy; ++ts)
274 setField(&packed, six_bits_mask, ts * 6,
frame[ts + tsShift].tdc());
277 setBit(&packed, 30,
true);
323 std::unique_ptr<AbsHBHEPhase1Algo>
reco_;
342 template <
class DataFrame,
class Collection>
347 const bool isRealData,
374 : algoConfigClass_(conf.getParameter<
std::
string>(
"algoConfigClass")),
375 processQIE8_(conf.getParameter<
bool>(
"processQIE8")),
376 processQIE11_(conf.getParameter<
bool>(
"processQIE11")),
377 saveInfos_(conf.getParameter<
bool>(
"saveInfos")),
378 saveDroppedInfos_(conf.getParameter<
bool>(
"saveDroppedInfos")),
379 makeRecHits_(conf.getParameter<
bool>(
"makeRecHits")),
380 dropZSmarkedPassed_(conf.getParameter<
bool>(
"dropZSmarkedPassed")),
381 tsFromDB_(conf.getParameter<
bool>(
"tsFromDB")),
382 recoParamsFromDB_(conf.getParameter<
bool>(
"recoParamsFromDB")),
383 saveEffectivePedestal_(conf.getParameter<
bool>(
"saveEffectivePedestal")),
384 use8ts_(conf.getParameter<
bool>(
"use8ts")),
385 sipmQTSShift_(conf.getParameter<
int>(
"sipmQTSShift")),
386 sipmQNTStoSum_(conf.getParameter<
int>(
"sipmQNTStoSum")),
387 setNegativeFlagsQIE8_(conf.getParameter<
bool>(
"setNegativeFlagsQIE8")),
388 setNegativeFlagsQIE11_(conf.getParameter<
bool>(
"setNegativeFlagsQIE11")),
389 setNoiseFlagsQIE8_(conf.getParameter<
bool>(
"setNoiseFlagsQIE8")),
390 setNoiseFlagsQIE11_(conf.getParameter<
bool>(
"setNoiseFlagsQIE11")),
391 setPulseShapeFlagsQIE8_(conf.getParameter<
bool>(
"setPulseShapeFlagsQIE8")),
392 setPulseShapeFlagsQIE11_(conf.getParameter<
bool>(
"setPulseShapeFlagsQIE11")),
394 negEFilter_(nullptr) {
397 throw cms::Exception(
"HBHEPhase1BadConfig") <<
"Invalid HBHEPhase1Algo algorithm configuration" << std::endl;
424 produces<HBHEChannelInfoCollection>();
427 produces<HBHERecHitCollection>();
430 htopoToken_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
432 propertiesToken_ = esConsumes<HcalChannelPropertiesVec, HcalChannelPropertiesRecord>();
434 negToken_ = esConsumes<HBHENegativeEFilter, HBHENegativeEFilterRcd>();
436 feMapToken_ = esConsumes<HcalFrontEndMap, HcalFrontEndMapRcd, edm::Transition::BeginRun>();
447 template <
class DFrame,
class Collection>
452 const bool isRealData,
463 for (
typename Collection::const_iterator it = coll.begin(); it != coll.end(); ++it) {
464 const DFrame&
frame(*it);
482 bool dropByZS =
false;
484 if (
frame.zsMarkAndPass())
486 if (dropByZS && skipDroppedChannels)
494 double darkCurrent = 0.;
508 const int nRead =
cs.size();
526 int nTSToCopy =
maxTS;
529 const int soiWanted = 3;
535 tsShift = determineIndexShift(soi, nRead, soiWanted, nTSToCopy);
539 for (
int copyTS = 0; copyTS < nTSToCopy; ++copyTS) {
540 const int inputTS = copyTS + tsShift;
542 const uint8_t
adc =
s.adc();
543 const int capid =
s.capid();
547 const double rawCharge = rcfs.getRawCharge(
cs[inputTS], pAndGain.pedestal(
false));
548 const float t = getTDCTimeFromSample(
s);
549 const float dfc = getDifferentialChargeGain(
555 pAndGain.pedestal(saveEffectivePeds),
556 pAndGain.pedestalWidth(saveEffectivePeds),
558 pAndGain.gainWidth(),
565 const int fitSoi = soi - tsShift;
567 const std::pair<bool, bool> hwerr = findHWErrors(
frame,
maxTS);
582 const bool makeThisRechit = !channelInfo->
isDropped();
584 infos->push_back(*channelInfo);
587 if (
rechits && makeThisRechit) {
643 const unsigned nRead =
info.nSamples();
644 for (
unsigned i = 0;
i < nRead; ++
i)
668 unsigned maxOutputSize = 0;
672 maxOutputSize += hbDigis->
size();
678 maxOutputSize += heDigis->
size();
682 std::unique_ptr<HBHEChannelInfoCollection>
infos;
684 infos = std::make_unique<HBHEChannelInfoCollection>();
685 infos->reserve(maxOutputSize);
688 std::unique_ptr<HBHERecHitCollection>
out;
690 out = std::make_unique<HBHERecHitCollection>();
691 out->reserve(maxOutputSize);
695 const bool isData =
e.isRealData();
725 if (
reco_->isConfigurable()) {
729 <<
"Invalid HBHEPhase1Reconstructor \"algoConfigClass\" parameter value \"" <<
algoConfigClass_ <<
'"'
733 <<
"Failed to configure HBHEPhase1Algo algorithm from EventSetup" << std::endl;
744 edm::LogWarning(
"EventSetup") <<
"HBHEPhase1Reconstructor failed to get HcalFrontEndMap!" << std::endl;
753 #define add_param_set(name) \
754 edm::ParameterSetDescription name; \
755 name.setAllowAnything(); \
756 desc.add<edm::ParameterSetDescription>(#name, name)
765 desc.add<
bool>(
"processQIE8");
766 desc.add<
bool>(
"processQIE11");
767 desc.add<
bool>(
"saveInfos");
768 desc.add<
bool>(
"saveDroppedInfos");
769 desc.add<
bool>(
"makeRecHits");
770 desc.add<
bool>(
"dropZSmarkedPassed");
771 desc.add<
bool>(
"tsFromDB");
772 desc.add<
bool>(
"recoParamsFromDB");
773 desc.add<
bool>(
"saveEffectivePedestal",
false);
774 desc.add<
bool>(
"use8ts",
false);
775 desc.add<
int>(
"sipmQTSShift", 0);
776 desc.add<
int>(
"sipmQNTStoSum", 3);
777 desc.add<
bool>(
"setNegativeFlagsQIE8");
778 desc.add<
bool>(
"setNegativeFlagsQIE11");
779 desc.add<
bool>(
"setNoiseFlagsQIE8");
780 desc.add<
bool>(
"setNoiseFlagsQIE11");
781 desc.add<
bool>(
"setPulseShapeFlagsQIE8");
782 desc.add<
bool>(
"setPulseShapeFlagsQIE11");
783 desc.add<
bool>(
"setLegacyFlagsQIE8");
784 desc.add<
bool>(
"setLegacyFlagsQIE11");