CMS 3D CMS Logo

HcalTriggerPrimitiveAlgo.h
Go to the documentation of this file.
1 #ifndef HcalSimAlgos_HcalTriggerPrimitiveAlgo_h
2 #define HcalSimAlgos_HcalTriggerPrimitiveAlgo_h
3 
6 
11 
13 
15 
18 
20 
21 #include <map>
22 #include <vector>
23 
24 class CaloGeometry;
25 class IntegerCaloSamples;
26 
28 public:
30  const std::vector<double>& w,
31  int latency,
32  uint32_t FG_threshold,
33  const std::vector<uint32_t>& FG_HF_thresholds,
34  uint32_t ZS_threshold,
35  int numberOfSamples,
41  int numberOfSamplesZDC,
42  int numberOfPresamplesZDC,
44  uint32_t minSignalThreshold = 0,
45  uint32_t PMT_NoiseThreshold = 0);
47 
48  template <typename... Digis>
49  void run(const HcalTPGCoder* incoder,
50  const HcalTPGCompressor* outcoder,
53  const HcalTrigTowerGeometry* trigTowerGeometry,
54  float rctlsb,
56  const Digis&... digis);
57 
58  template <typename T, typename... Args>
59  void addDigis(const T& collection, const Args&... digis) {
61  addDigis(digis...);
62  };
63 
64  template <typename T>
65  void addDigis(const T& collection) {
66  for (const auto& digi : collection) {
67  addSignal(digi);
68  }
69  };
70 
71  template <typename D>
73  for (auto i = collection.begin(); i != collection.end(); ++i) {
74  D digi(*i);
75  addSignal(digi);
76  }
77  };
78 
80  void runFEFormatError(const FEDRawDataCollection* rawraw,
81  const HcalElectronicsMap* emap,
83  void setPeakFinderAlgorithm(int algo);
85  void setWeightQIE11(int aieta, int weight);
87  void setCodedVetoThreshold(int aieta, int codedVetoThreshold);
88  void setNCTScaleShift(int);
89  void setRCTScaleShift(int);
90 
92 
94 
95  void setUpgradeFlags(bool hb, bool he, bool hf);
96  void setFixSaturationFlag(bool fix_saturation);
97  void overrideParameters(const edm::ParameterSet& ps);
98 
99 private:
101  void addSignal(const HBHEDataFrame& frame);
102  void addSignal(const HFDataFrame& frame);
103  //void addSignal(const ZDCDataFrame& frame);
104  void addSignal(const QIE10DataFrame& frame);
105  void addSignal(const QIE11DataFrame& frame);
106  void addSignal(const IntegerCaloSamples& samples);
107  void addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb);
108  void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);
109  void addUpgradeTDCFG(const HcalTrigTowerDetId& id, const QIE11DataFrame& frame);
110 
111  bool passTDC(const QIE10DataFrame& digi, int ts) const;
112  bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
113  bool validChannel(const QIE10DataFrame& digi, int ts) const;
114  bool needLegacyFG(const HcalTrigTowerDetId& id) const;
115  bool needUpgradeID(const HcalTrigTowerDetId& id, int depth) const;
116 
119  // 2017 and later: QIE11
121  std::vector<bool> sample_saturation,
123  const HcalFinegrainBit& fg_algo);
124  // Version 0: RCT
125  void analyzeHF(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const int hf_lumi_shift);
126  // Version 1: 1x1
127  void analyzeHF2016(const IntegerCaloSamples& SAMPLES,
129  const int HF_LUMI_SHIFT,
130  const HcalFeatureBit* HCALFEM);
131  // With dual anode readout
132  void analyzeHFQIE10(const IntegerCaloSamples& SAMPLES,
134  const int HF_LUMI_SHIFT,
135  const HcalFeatureBit* HCALFEM);
136 
138 
139  // Member initialized by constructor
143  double theThreshold;
144  bool peakfind_;
145  std::vector<double> weights_;
146  std::array<std::array<int, 2>, 29> weightsQIE11_;
147  std::array<int, 29> codedVetoThresholds_;
148  int latency_;
149  uint32_t FG_threshold_;
150  std::vector<uint32_t> FG_HF_thresholds_;
151  uint32_t ZS_threshold_;
166 
167  // Algo1: isPeak = TS[i-1] < TS[i] && TS[i] >= TS[i+1]
168  // Algo2: isPeak = TSS[i-1] < TSS[i] && TSS[i] >= TSS[i+1],
169  // TSS[i] = TS[i] + TS[i+1]
170  // Default: Algo2
172 
173  // Member not initialzed
174  //std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId & id) const;
175 
177 
178  typedef std::map<HcalTrigTowerDetId, IntegerCaloSamples> SumMap;
180 
181  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> SatMap;
183 
184  struct HFDetails {
189  };
190  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, HFDetails>> HFDetailMap;
192 
196  std::vector<bool> validity;
197  std::vector<std::bitset<2>> fgbits;
198  std::vector<bool> passTDC;
199  };
200  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
202 
203  typedef std::vector<IntegerCaloSamples> SumFGContainer;
204  typedef std::map<HcalTrigTowerDetId, SumFGContainer> TowerMapFGSum;
206 
207  // ==============================
208  // = HF Veto
209  // ==============================
210  // Sum = Long + Short;" // intermediate calculation.
211  // if ((Short < MinSignalThresholdET OR Long < MinSignalThresholdET)
212  // AND Sum > PMTNoiseThresholdET) VetoedSum = 0;
213  // else VetoedSum = Sum;
214  // ==============================
215  // Map from FG id to veto booleans
217  typedef std::map<uint32_t, std::vector<bool>> TowerMapVeto;
219 
220  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> FGbitMap;
222 
223  typedef std::vector<HcalFinegrainBit::Tower> FGUpgradeContainer;
224  typedef std::map<HcalTrigTowerDetId, FGUpgradeContainer> FGUpgradeMap;
226 
227  typedef std::vector<HcalFinegrainBit::TowerTDC> FGUpgradeTDCContainer;
228  typedef std::map<HcalTrigTowerDetId, FGUpgradeTDCContainer> FGUpgradeTDCMap;
230 
231  bool upgrade_hb_ = false;
232  bool upgrade_he_ = false;
233  bool upgrade_hf_ = false;
234 
235  bool fix_saturation_ = false;
236 
238 
239  bool override_adc_hf_ = false;
241  bool override_tdc_hf_ = false;
242  unsigned long long override_tdc_hf_value_;
243 
244  // HE constants
245  static const int HBHE_OVERLAP_TOWER = 16;
246  static const int FIRST_DEPTH7_TOWER = 26;
247  static const int LAST_FINEGRAIN_DEPTH = 6;
248  static const int LAST_FINEGRAIN_TOWER = 28;
249 
250  // Fine-grain in HF ignores tower 29, and starts with 30
251  static const int FIRST_FINEGRAIN_TOWER = 30;
252 
256  // Consider CaloTPGTranscoderULUT.h for values
257  static const int QIE10_MAX_LINEARIZATION_ET = 0x7FF;
258  static const int QIE11_MAX_LINEARIZATION_ET = 0x7FF;
259  static const int QIE10_ZDC_MAX_LINEARIZATION_ET = 0x3FF;
260 };
261 
262 template <typename... Digis>
264  const HcalTPGCompressor* outcoder,
265  const HcalDbService* conditions,
267  const HcalTrigTowerGeometry* trigTowerGeometry,
268  float rctlsb,
269  const HcalFeatureBit* LongvrsShortCut,
270  const Digis&... digis) {
271  theTrigTowerGeometry = trigTowerGeometry;
272 
273  incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
274  outcoder_ = outcoder;
276 
277  theSumMap.clear();
278  theSatMap.clear();
279  theTowerMapFGSum.clear();
280  HF_Veto.clear();
281  fgMap_.clear();
282  fgUpgradeMap_.clear();
283  fgUpgradeTDCMap_.clear();
284  theHFDetailMap.clear();
285  theHFUpgradeDetailMap.clear();
286 
287  // Add all digi collections
288  addDigis(digis...);
289 
290  // Prepare the fine-grain calculation algorithm for HB/HE
291  int version = 0;
294  if (override_parameters_.exists("FGVersionHBHE"))
295  version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
296  HcalFinegrainBit fg_algo(version);
297 
298  // VME produces additional bits on the front used by lumi but not the
299  // trigger, this shift corrects those out by right shifting over them.
300  for (auto& item : theSumMap) {
301  result.push_back(HcalTriggerPrimitiveDigi(item.first));
302  HcalTrigTowerDetId detId(item.second.id());
303  if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version()) && detId.ietaAbs() < 42) {
304  if (detId.version() == 0) {
305  analyzeHF(item.second, result.back(), RCTScaleShift);
306  } else if (detId.version() == 1) {
307  if (upgrade_hf_)
309  else
311  } else {
312  // Things are going to go poorly
313  }
314  } else if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version()) && detId.ietaAbs() > 41) {
315  analyzeZDC(item.second, result.back());
316  } else {
317  // Determine which energy reconstruction path to take based on the
318  // fine-grain availability:
319  // * QIE8 TP add entries into fgMap_
320  // * QIE11 TP add entries into fgUpgradeMap_
321  // (not for tower 16 unless HB is upgraded, too)
322  if (fgMap_.find(item.first) != fgMap_.end()) {
323  analyze(item.second, result.back());
324  } else if (fgUpgradeMap_.find(item.first) != fgUpgradeMap_.end()) {
325  SatMap::iterator item_sat = theSatMap.find(detId);
326  if (item_sat == theSatMap.end())
327  analyzeQIE11(item.second, std::vector<bool>(), result.back(), fg_algo);
328  else
329  analyzeQIE11(item.second, item_sat->second, result.back(), fg_algo);
330  }
331  }
332  }
333 
334  // Free up some memory
335  theSumMap.clear();
336  theSatMap.clear();
337  theTowerMapFGSum.clear();
338  HF_Veto.clear();
339  fgMap_.clear();
340  fgUpgradeMap_.clear();
341  fgUpgradeTDCMap_.clear();
342  theHFDetailMap.clear();
343  theHFUpgradeDetailMap.clear();
344 
345  return;
346 }
347 
348 #endif
bool validUpgradeFG(const HcalTrigTowerDetId &id, int depth) const
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)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::map< uint32_t, std::vector< bool > > TowerMapVeto
std::vector< uint32_t > FG_HF_thresholds_
HFUpgradeDetailMap theHFUpgradeDetailMap
int getFGVersionHBHE() const
get FineGrain Algorithm Version for HBHE
void analyzeHF(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const int hf_lumi_shift)
std::map< HcalTrigTowerDetId, FGUpgradeTDCContainer > FGUpgradeTDCMap
static const int QIE10_MAX_LINEARIZATION_ET
T w() const
void analyzeHF2016(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
static const int QIE11_LUT_BITMASK
bool exists(std::string const &parameterName) const
checks if a parameter exists
void analyzeHFQIE10(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
bool needLegacyFG(const HcalTrigTowerDetId &id) const
const HcalTPGCompressor * outcoder_
Definition: weight.py:1
std::map< HcalTrigTowerDetId, FGUpgradeContainer > FGUpgradeMap
void addFG(const HcalTrigTowerDetId &id, std::vector< bool > &msb)
static const int QIE8_LUT_BITMASK
void setCodedVetoThresholds(const edm::ParameterSet &codedVetoThresholds)
static const int QIE10_ZDC_MAX_LINEARIZATION_ET
std::array< std::array< int, 2 >, 29 > weightsQIE11_
int firstHFTower(int version) const
std::vector< IntegerCaloSamples > SumFGContainer
std::array< int, 29 > codedVetoThresholds_
std::map< HcalTrigTowerDetId, SumFGContainer > TowerMapFGSum
const HcalTrigTowerGeometry * theTrigTowerGeometry
const HcalDbService * conditions_
weightsQIE11
hardware algo
void setWeightQIE11(int aieta, int weight)
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool needUpgradeID(const HcalTrigTowerDetId &id, int depth) const
void setNumFilterPresamplesHEQIE11(int presamples)
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, int numberOfSamplesZDC, int numberOfPresamplesZDC, bool useTDCInMinBiasBits, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
const HcalTPParameters * getHcalTPParameters() const
void setCodedVetoThreshold(int aieta, int codedVetoThreshold)
void runZS(HcalTrigPrimDigiCollection &tp)
static const int QIE10_LUT_BITMASK
void analyzeQIE11(IntegerCaloSamples &samples, std::vector< bool > sample_saturation, HcalTriggerPrimitiveDigi &result, const HcalFinegrainBit &fg_algo)
std::map< HcalTrigTowerDetId, std::vector< bool > > SatMap
std::map< HcalTrigTowerDetId, std::vector< bool > > FGbitMap
std::vector< HcalFinegrainBit::TowerTDC > FGUpgradeTDCContainer
std::vector< HcalFinegrainBit::Tower > FGUpgradeContainer
void run(const HcalTPGCoder *incoder, const HcalTPGCompressor *outcoder, const HcalDbService *conditions, HcalTrigPrimDigiCollection &result, const HcalTrigTowerGeometry *trigTowerGeometry, float rctlsb, const HcalFeatureBit *LongvrsShortCut, const Digis &... digis)
void addDigis(const T &collection)
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
unsigned long long override_tdc_hf_value_
static const int QIE11_MAX_LINEARIZATION_ET
std::map< HcalTrigTowerDetId, IntegerCaloSamples > SumMap
void addDigis(const T &collection, const Args &... digis)
void addUpgradeFG(const HcalTrigTowerDetId &id, int depth, const std::vector< std::bitset< 2 >> &bits)
std::map< HcalTrigTowerDetId, std::map< uint32_t, std::array< HFUpgradeDetails, 4 > > > HFUpgradeDetailMap
const HcaluLUTTPGCoder * incoder_
void setNumFilterPresamplesHBQIE11(int presamples)
bool passTDC(const QIE10DataFrame &digi, int ts) const
codedVetoThresholds
threshold for setting TP zero suppression
bool validChannel(const QIE10DataFrame &digi, int ts) const
void analyzeZDC(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result)
long double T
void addSignal(const HBHEDataFrame &frame)
adds the signal to the map
std::map< HcalTrigTowerDetId, std::map< uint32_t, HFDetails > > HFDetailMap
void setUpgradeFlags(bool hb, bool he, bool hf)
void addDigis(const HcalDataFrameContainer< D > &collection)
void overrideParameters(const edm::ParameterSet &ps)
void setWeightsQIE11(const edm::ParameterSet &weightsQIE11)
void setFixSaturationFlag(bool fix_saturation)