24 const std::vector<double>&
w,
27 const std::vector<uint32_t>& FG_HF_thresholds,
30 int numberOfPresamples,
31 int numberOfFilterPresamplesHBQIE11,
32 int numberOfFilterPresamplesHEQIE11,
35 bool useTDCInMinBiasBits,
36 uint32_t minSignalThreshold,
37 uint32_t PMT_NoiseThreshold)
44 FG_threshold_(FG_threshold),
45 FG_HF_thresholds_(FG_HF_thresholds),
46 ZS_threshold_(ZS_threshold),
47 numberOfSamples_(numberOfSamples),
48 numberOfPresamples_(numberOfPresamples),
49 numberOfFilterPresamplesHBQIE11_(numberOfFilterPresamplesHBQIE11),
50 numberOfFilterPresamplesHEQIE11_(numberOfFilterPresamplesHEQIE11),
51 numberOfSamplesHF_(numberOfSamplesHF),
52 numberOfPresamplesHF_(numberOfPresamplesHF),
53 useTDCInMinBiasBits_(useTDCInMinBiasBits),
54 minSignalThreshold_(minSignalThreshold),
55 PMT_NoiseThreshold_(PMT_NoiseThreshold),
58 peak_finder_algorithm_(2),
59 override_parameters_() {
101 assert(ids.size() == 1 || ids.size() == 2);
107 std::vector<bool> msb;
110 if (ids.size() == 2) {
113 for (
int i = 0;
i < samples1.size(); ++
i) {
114 samples1[
i] = uint32_t(samples1[
i] * 0.5);
115 samples2[
i] = samples1[
i];
128 std::vector<HcalTrigTowerDetId>::const_iterator it;
129 for (it = ids.begin(); it != ids.end(); ++it) {
142 if (trig_tower_id.
version() == 0) {
148 theTowerMapFGSum.insert(std::pair<HcalTrigTowerDetId, SumFGContainer>(trig_tower_id, sumFG));
152 SumFGContainer::iterator sumFGItr;
153 for (sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
154 if (sumFGItr->id() == fgid) {
159 if (sumFGItr != sumFG.end()) {
160 for (
int i = 0;
i < samples.size(); ++
i) {
161 (*sumFGItr)[
i] += samples[
i];
167 for (
int i = 0;
i < samples.size(); ++
i) {
168 sumFGSamples[
i] = samples[
i];
170 sumFG.push_back(sumFGSamples);
175 vector<bool> vetoBits(samples.size(),
false);
178 for (
int i = 0;
i < samples.size(); ++
i) {
185 else if (trig_tower_id.
version() == 1) {
192 }
else if (frame.
id().
depth() == 2) {
197 edm::LogWarning(
"HcalTPAlgo") <<
"Unable to figure out what to do with data frame for " << frame.
id();
216 for (
const auto&
id : ids) {
218 edm::LogError(
"HcalTPAlgo") <<
"Encountered QIE10 data frame mapped to TP version 0:" <<
id;
222 int nsamples = frame.
samples();
236 auto& detail = details[fid.depth() - 1];
237 detail.samples = samples;
239 detail.validity.resize(nsamples);
240 detail.passTDC.resize(nsamples);
242 for (
int idx = 0; idx < nsamples; ++idx) {
244 detail.passTDC[idx] =
passTDC(frame, idx);
256 assert(ids.size() == 1 || ids.size() == 2);
262 std::vector<std::bitset<2>> msb(frame.
samples(), 0);
265 if (ids.size() == 2) {
268 for (
int i = 0;
i < samples1.size(); ++
i) {
269 samples1[
i] = uint32_t(samples1[
i]);
270 samples2[
i] = samples1[
i];
284 SumMap::iterator itr =
theSumMap.find(
id);
287 theSumMap.insert(std::make_pair(
id, samples));
290 for (
int i = 0;
i < samples.
size(); ++
i) {
291 (itr->second)[
i] += samples[
i];
297 SatMap::iterator itr_sat =
theSatMap.find(
id);
302 vector<bool> check_sat;
303 for (
int i = 0;
i < samples.
size(); ++
i) {
305 check_sat.push_back(
true);
307 check_sat.push_back(
false);
309 theSatMap.insert(std::make_pair(
id, check_sat));
311 for (
int i = 0;
i < samples.
size(); ++
i) {
313 (itr_sat->second)[
i] =
true;
321 std::vector<bool>& msb =
fgMap_[samples.
id()];
325 for (
int ibin = 0; ibin < int(samples.
size()) - shrink; ++ibin) {
326 int algosumvalue = 0;
327 for (
unsigned int i = 0;
i <
weights_.size();
i++) {
329 algosumvalue += int(samples[ibin +
i] *
weights_[
i]);
331 if (algosumvalue < 0)
336 sum[ibin] = algosumvalue;
342 int shift = dgPresamples - tpPresamples;
343 int dgSamples = samples.
size();
348 <<
"TP presample or size from the configuration file is out of the accessible range. Using digi values from "
351 tpPresamples = dgPresamples - shrink;
356 std::vector<int> finegrain(tpSamples,
false);
359 output.setPresamples(tpPresamples);
361 for (
int ibin = 0; ibin < tpSamples; ++ibin) {
364 int idx = ibin +
shift;
371 isPeak = (samples[idx] > samples[idx - 1] && samples[idx] >= samples[idx + 1] && samples[idx] >
theThreshold);
374 isPeak = (sum[idx] > sum[idx - 1] && sum[idx] >= sum[idx + 1] && sum[idx] >
theThreshold);
382 finegrain[ibin] = msb[idx];
389 finegrain[ibin] = msb[idx];
402 vector<bool> sample_saturation,
410 unsigned int dgSamples = samples.
size();
411 unsigned int dgPresamples = samples.
presamples();
421 unsigned int shift = dgPresamples - tpPresamples;
424 unsigned int shrink = filterSamples - 1;
433 bool force_saturation[samples.
size()];
434 for (
int i = 0;
i < samples.
size();
i++) {
435 force_saturation[
i] =
false;
439 for (
unsigned int ibin = 0; ibin < dgSamples - shrink; ++ibin) {
440 int algosumvalue = 0;
441 bool check_sat =
false;
442 for (
unsigned int i = 0;
i < filterSamples;
i++) {
446 unsigned int sample = samples[ibin +
i];
455 double segmentationFactor = 1.0;
456 if (ids.size() == 2) {
457 segmentationFactor = 0.5;
463 algosumvalue += int(sample * segmentationFactor * theWeight);
465 if (algosumvalue < 0)
470 sum[ibin] = algosumvalue;
473 force_saturation[ibin] =
true;
476 std::vector<int> finegrain(tpSamples,
false);
479 output.setPresamples(tpPresamples);
481 for (
unsigned int ibin = 0; ibin < tpSamples; ++ibin) {
484 int idx = ibin + shift - filterPresamples;
492 bool isPeak = (sum[idx] > sum[idx - 1] && sum[idx] >= sum[idx + 1] && sum[idx] >
theThreshold);
508 finegrain[ibin] = fg_algo.
compute(timingTDC[idx + filterPresamples], ids[0]).to_ulong() |
509 fg_algo.
compute(msb[idx + filterPresamples]).to_ulong() << 4;
510 if (ibin == tpPresamples && (idx + filterPresamples) != dgPresamples)
512 <<
"TP SOI (tpPresamples = " << tpPresamples
513 <<
") is not aligned with digi SOI (dgPresamples = " << dgPresamples <<
")";
520 const int hf_lumi_shift) {
526 int shift = dgPresamples - tpPresamples;
527 int dgSamples = samples.
size();
529 if (shift < 0 || shift + tpSamples > dgSamples) {
531 <<
"TP presample or size from the configuration file is out of the accessible range. Using digi values from "
533 tpPresamples = dgPresamples;
535 tpSamples = dgSamples;
538 std::vector<int> finegrain(tpSamples,
false);
546 for (SumFGContainer::const_iterator sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
547 const std::vector<bool>&
veto =
HF_Veto[sumFGItr->id().rawId()];
548 for (
int ibin = 0; ibin < tpSamples; ++ibin) {
549 int idx = ibin +
shift;
551 bool vetoed = idx < int(veto.size()) && veto[idx];
553 samples[idx] += (*sumFGItr)[idx];
554 finegrain[ibin] = (finegrain[ibin] || (*sumFGItr)[idx] >=
FG_threshold_);
560 output.setPresamples(tpPresamples);
562 for (
int ibin = 0; ibin < tpSamples; ++ibin) {
563 int idx = ibin +
shift;
564 output[ibin] = samples[idx] >> hf_lumi_shift;
566 if (
output[ibin] > MAX_OUTPUT)
567 output[ibin] = MAX_OUTPUT;
574 const int hf_lumi_shift,
595 for (
const auto&
item : it->second) {
596 auto& details =
item.second;
598 const int IDX = ibin + SHIFT;
599 int long_fiber_val = 0;
600 if (IDX < details.long_fiber.size()) {
601 long_fiber_val = details.long_fiber[IDX];
603 int short_fiber_val = 0;
604 if (IDX < details.short_fiber.size()) {
605 short_fiber_val = details.short_fiber[IDX];
607 output[ibin] += (long_fiber_val + short_fiber_val);
609 uint32_t ADCLong = details.LongDigi[ibin].adc();
610 uint32_t ADCShort = details.ShortDigi[ibin].adc();
615 if (embit !=
nullptr)
616 finegrain[ibin][0] = embit->
fineGrainbit(details.ShortDigi, details.LongDigi, ibin);
626 std::vector<int> finegrain_converted;
627 finegrain_converted.reserve(finegrain.size());
628 for (
const auto& fg : finegrain)
629 finegrain_converted.push_back(fg.to_ulong());
635 auto adc_threshold =
parameters->getADCThresholdHF();
643 if (digi[ts].
adc() < adc_threshold)
646 return (1ul << digi[ts].le_tdc()) & tdc_mask;
663 const int hf_lumi_shift,
669 assert(hf_lumi_shift >= 2);
685 for (
const auto&
item : it->second) {
686 auto& details =
item.second;
688 const int idx = ibin +
shift;
690 int long_fiber_val = 0;
691 int long_fiber_count = 0;
692 int short_fiber_val = 0;
693 int short_fiber_count = 0;
695 bool saturated =
false;
697 for (
auto i : {0, 2}) {
698 if (idx < details[
i].samples.
size() and details[
i].validity[idx] and details[
i].passTDC[idx]) {
699 long_fiber_val += details[
i].samples[idx];
704 for (
auto i : {1, 3}) {
705 if (idx < details[
i].samples.
size() and details[
i].validity[idx] and details[
i].passTDC[idx]) {
706 short_fiber_val += details[
i].samples[idx];
719 if (long_fiber_count == 2)
720 long_fiber_val >>= 1;
721 if (short_fiber_count == 2)
722 short_fiber_val >>= 1;
724 auto sum = long_fiber_val + short_fiber_val;
728 if (long_fiber_count > 0 and short_fiber_count > 0)
734 for (
const auto& detail : details) {
735 if (idx <
int(detail.digi.size()) and detail.validity[idx] and
739 finegrain[ibin][1] = finegrain[ibin][1]
or detail.fgbits[idx][0];
743 finegrain[ibin][0] = finegrain[ibin][0]
or detail.fgbits[idx][1];
748 finegrain[ibin][0] = embit->
fineGrainbit(details[1].digi,
752 details[1].validity[idx],
753 details[3].validity[idx],
754 details[0].validity[idx],
755 details[2].validity[idx],
764 std::vector<int> finegrain_converted;
765 finegrain_converted.reserve(finegrain.size());
766 for (
const auto& fg : finegrain)
767 finegrain_converted.push_back(fg.to_ulong());
774 for (
int i = 0;
i <
tp->size(); ++
i) {
781 tp->setZSInfo(
false,
true);
783 tp->setZSInfo(
true,
false);
790 std::set<uint32_t> FrontEndErrors;
810 for (
int fchan = 0; fchan < 3 && !valid; fchan++) {
811 for (
int fib = 0; fib < 9 && !valid; fib++) {
821 for (std::vector<HcalTrigTowerDetId>::const_iterator triggerId = ids.begin(); triggerId != ids.end();
823 FrontEndErrors.insert(triggerId->rawId());
836 if (FrontEndErrors.find(
tp->id().rawId()) != FrontEndErrors.end()) {
837 for (
int i = 0;
i <
tp->size(); ++
i)
838 tp->setSample(
i, zeroSample);
844 FGbitMap::iterator itr =
fgMap_.find(
id);
845 if (itr !=
fgMap_.end()) {
846 std::vector<bool>& _msb = itr->second;
847 for (
size_t i = 0;
i < msb.size(); ++
i)
848 _msb[
i] = _msb[
i] || msb[
i];
876 unsigned int aieta =
id.ietaAbs();
887 std::vector<bool> pseudo(bits.size(),
false);
896 element.resize(bits.size());
907 element.resize(bits.size());
908 it =
fgUpgradeMap_.insert(std::make_pair(
id, element)).first;
910 for (
unsigned int i = 0;
i < bits.size(); ++
i) {
911 it->second[
i][0][depth - 1] = bits[
i][0];
912 it->second[
i][1][depth - 1] = bits[
i][1];
922 assert(ids.size() == 1 || ids.size() == 2);
928 bool is_compressed =
false;
930 is_compressed = (frame.
flavor() == 3);
937 element.resize(frame.
samples());
941 it->second[
i][detId.depth() - 1] =
942 std::make_pair(std::make_pair(bits12_15[
i], is_compressed), std::make_pair(frame[i].tdc(), samples1[i]));
949 for (
auto& ietaStr : ietaStrs) {
951 auto const&
v = weightsQIE11.
getParameter<std::vector<double>>(ietaStr);
963 if (algo <= 0 || algo > 2)
964 throw cms::Exception(
"ERROR: Only algo 1 & 2 are supported.") << std::endl;
constexpr void setHTR(int crate, int slot, int tb)
void addUpgradeTDCFG(const HcalTrigTowerDetId &id, const QIE11DataFrame &frame)
void analyze(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result)
adds the actual digis
void runFEFormatError(const FEDRawDataCollection *rawraw, const HcalElectronicsMap *emap, HcalTrigPrimDigiCollection &result)
int presamples() const
access presample information
std::vector< uint32_t > FG_HF_thresholds_
constexpr int ietaAbs() const
get the absolute value of the cell ieta
HFUpgradeDetailMap theHFUpgradeDetailMap
bool passTDC(const QIE10DataFrame &digi, int ts) const
void analyzeHF(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const int hf_lumi_shift)
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
std::vector< HcalTrigTowerDetId > towerIds(const HcalDetId &cellId) const
the mapping to and from DetIds
uint16_t *__restrict__ id
bool useTDCInMinBiasBits_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
static const int QIE10_MAX_LINEARIZATION_ET
constexpr edm::DataFrame::id_type id() const
void analyzeHF2016(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
constexpr bool null() const
is this a null id ?
static const int FIRST_DEPTH7_TOWER
int peak_finder_algorithm_
void analyzeHFQIE10(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
static const int LAST_FINEGRAIN_TOWER
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static const int QIE10_LINEARIZATION_ET
const HcalTPGCompressor * outcoder_
static const int LAST_FINEGRAIN_DEPTH
constexpr const HcalDetId & id() const
void setPresamples(int pre)
set presample information
void addFG(const HcalTrigTowerDetId &id, std::vector< bool > &msb)
bool needLegacyFG(const HcalTrigTowerDetId &id) const
Log< level::Error, false > LogError
IntegerCaloSamples long_fiber
std::vector< unsigned short > group0FGbits(const QIE11DataFrame &df) const
static const int HBHE_OVERLAP_TOWER
size_t size() const
Lenght of the data buffer in bytes.
TowerMapFGSum theTowerMapFGSum
bool validChannel(const QIE10DataFrame &digi, int ts) const
uint32_t minSignalThreshold_
static const int FIRST_FINEGRAIN_TOWER
constexpr DetId detid() const
Get the detector id.
constexpr HcalSubdetector subdet() const
get the subdetector
std::vector< IntegerCaloSamples > SumFGContainer
int size() const
get the size
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
const HcalTrigTowerGeometry * theTrigTowerGeometry
const HcalDbService * conditions_
constexpr int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
void lookupMSB(const HBHEDataFrame &df, std::vector< bool > &msb) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
constexpr uint32_t maskDepth() const
get the tower depth
constexpr int presamples() const
for backward compatibility
static const int QIE11_LINEARIZATION_ET
constexpr int size() const
total number of samples in the digi
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
constexpr bool linkError() const
std::vector< double > weights_
void compress(const IntegerCaloSamples &ics, const std::vector< int > &fineGrain, HcalTriggerPrimitiveDigi &digi) const
std::vector< std::string > getParameterNames() const
int numberOfPresamplesHF_
IntegerCaloSamples short_fiber
void runZS(HcalTrigPrimDigiCollection &tp)
bool needUpgradeID(const HcalTrigTowerDetId &id, int depth) const
std::vector< T >::iterator iterator
constexpr int size() const
total number of samples in the digi
void analyzeQIE11(IntegerCaloSamples &samples, std::vector< bool > sample_saturation, HcalTriggerPrimitiveDigi &result, const HcalFinegrainBit &fg_algo)
const_iterator end() const
Log< level::Info, false > LogInfo
std::vector< HcalFinegrainBit::TowerTDC > FGUpgradeTDCContainer
std::vector< HcalFinegrainBit::Tower > FGUpgradeContainer
std::array< std::array< double, 2 >, 29 > weightsQIE11_
void setNCTScaleShift(int)
virtual bool fineGrainbit(const QIE10DataFrame &short1, const QIE10DataFrame &short2, const QIE10DataFrame &long1, const QIE10DataFrame &long2, bool validShort1, bool validShort2, bool validLong1, bool validLong2, int idx) const =0
constexpr int samples() const
total number of samples in the digi
uint32_t override_adc_hf_value_
uint32_t PMT_NoiseThreshold_
unsigned long long override_tdc_hf_value_
bool validUpgradeFG(const HcalTrigTowerDetId &id, int depth) const
unsigned int getErrorsWord() const
Get the errors word.
static const int QIE11_MAX_LINEARIZATION_ET
int version() const
get the version code for the trigger tower
constexpr int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
const HcalTopology & topology() const
constexpr int flavor() const
get the flavor of the frame
void adc2Linear(const HBHEDataFrame &df, IntegerCaloSamples &ics) const override
T getParameter(std::string const &) const
constexpr int presamples() const
for backward compatibility
const HcalTPParameters * getHcalTPParameters() const
tuple numberOfPresamplesHF
void addUpgradeFG(const HcalTrigTowerDetId &id, int depth, const std::vector< std::bitset< 2 >> &bits)
constexpr int samples() const
total number of samples in the digi
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
FGUpgradeTDCMap fgUpgradeTDCMap_
const HcaluLUTTPGCoder * incoder_
constexpr edm::DataFrame::id_type id() const
HcalTriggerPrimitiveAlgo(bool pf, const std::vector< double > &w, int latency, uint32_t FG_threshold, const std::vector< uint32_t > &FG_HF_thresholds, uint32_t ZS_threshold, int numberOfSamples, int numberOfPresamples, int numberOfFilterPresamplesHBQIE11, int numberOfFilterPresamplesHEQIE11, int numberOfSamplesHF, int numberOfPresamplesHF, bool useTDCInMinBiasBits, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static const int QIE8_LINEARIZATION_ET
HFDetailMap theHFDetailMap
static unsigned int const shift
std::bitset< 2 > compute(const Tower &) const
void setWeightQIE11(int aieta, double weight)
constexpr int depth() const
get the tower depth
Log< level::Warning, false > LogWarning
DetId id() const
get the (generic) id
void setRCTScaleShift(int)
int numberOfFilterPresamplesHEQIE11_
edm::ParameterSet override_parameters_
Readout chain identification for Hcal.
FGUpgradeMap fgUpgradeMap_
void addSignal(const HBHEDataFrame &frame)
adds the signal to the map
void setUpgradeFlags(bool hb, bool he, bool hf)
const HcalTPChannelParameter * getHcalTPChannelParameter(const HcalGenericDetId &fId, bool throwOnFail=true) const
void overrideParameters(const edm::ParameterSet &ps)
void setWeightsQIE11(const edm::ParameterSet &weightsQIE11)
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
~HcalTriggerPrimitiveAlgo()
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
void setPeakFinderAlgorithm(int algo)
const_iterator begin() const
uint16_t *__restrict__ uint16_t const *__restrict__ adc
constexpr HcalDetId const & id() const
void setFixSaturationFlag(bool fix_saturation)
uint32_t getMask() const
get mask for channel validity and self trigger information
int numberOfFilterPresamplesHBQIE11_
constexpr Detector det() const
get the detector field from this detid