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);
86  void setNCTScaleShift(int);
87  void setRCTScaleShift(int);
88 
90 
92 
93  void setUpgradeFlags(bool hb, bool he, bool hf);
94  void setFixSaturationFlag(bool fix_saturation);
95  void overrideParameters(const edm::ParameterSet& ps);
96 
97 private:
99  void addSignal(const HBHEDataFrame& frame);
100  void addSignal(const HFDataFrame& frame);
101  //void addSignal(const ZDCDataFrame& frame);
102  void addSignal(const QIE10DataFrame& frame);
103  void addSignal(const QIE11DataFrame& frame);
104  void addSignal(const IntegerCaloSamples& samples);
105  void addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb);
106  void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);
107  void addUpgradeTDCFG(const HcalTrigTowerDetId& id, const QIE11DataFrame& frame);
108 
109  bool passTDC(const QIE10DataFrame& digi, int ts) const;
110  bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
111  bool validChannel(const QIE10DataFrame& digi, int ts) const;
112  bool needLegacyFG(const HcalTrigTowerDetId& id) const;
113  bool needUpgradeID(const HcalTrigTowerDetId& id, int depth) const;
114 
117  // 2017 and later: QIE11
119  std::vector<bool> sample_saturation,
121  const HcalFinegrainBit& fg_algo);
122  // Version 0: RCT
123  void analyzeHF(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const int hf_lumi_shift);
124  // Version 1: 1x1
125  void analyzeHF2016(const IntegerCaloSamples& SAMPLES,
127  const int HF_LUMI_SHIFT,
128  const HcalFeatureBit* HCALFEM);
129  // With dual anode readout
130  void analyzeHFQIE10(const IntegerCaloSamples& SAMPLES,
132  const int HF_LUMI_SHIFT,
133  const HcalFeatureBit* HCALFEM);
134 
136 
137  // Member initialized by constructor
141  double theThreshold;
142  bool peakfind_;
143  std::vector<double> weights_;
144  std::array<std::array<int, 2>, 29> weightsQIE11_;
145  int latency_;
146  uint32_t FG_threshold_;
147  std::vector<uint32_t> FG_HF_thresholds_;
148  uint32_t ZS_threshold_;
163 
164  // Algo1: isPeak = TS[i-1] < TS[i] && TS[i] >= TS[i+1]
165  // Algo2: isPeak = TSS[i-1] < TSS[i] && TSS[i] >= TSS[i+1],
166  // TSS[i] = TS[i] + TS[i+1]
167  // Default: Algo2
169 
170  // Member not initialzed
171  //std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId & id) const;
172 
174 
175  typedef std::map<HcalTrigTowerDetId, IntegerCaloSamples> SumMap;
177 
178  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> SatMap;
180 
181  struct HFDetails {
186  };
187  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, HFDetails>> HFDetailMap;
189 
193  std::vector<bool> validity;
194  std::vector<std::bitset<2>> fgbits;
195  std::vector<bool> passTDC;
196  };
197  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
199 
200  typedef std::vector<IntegerCaloSamples> SumFGContainer;
201  typedef std::map<HcalTrigTowerDetId, SumFGContainer> TowerMapFGSum;
203 
204  // ==============================
205  // = HF Veto
206  // ==============================
207  // Sum = Long + Short;" // intermediate calculation.
208  // if ((Short < MinSignalThresholdET OR Long < MinSignalThresholdET)
209  // AND Sum > PMTNoiseThresholdET) VetoedSum = 0;
210  // else VetoedSum = Sum;
211  // ==============================
212  // Map from FG id to veto booleans
214  typedef std::map<uint32_t, std::vector<bool>> TowerMapVeto;
216 
217  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> FGbitMap;
219 
220  typedef std::vector<HcalFinegrainBit::Tower> FGUpgradeContainer;
221  typedef std::map<HcalTrigTowerDetId, FGUpgradeContainer> FGUpgradeMap;
223 
224  typedef std::vector<HcalFinegrainBit::TowerTDC> FGUpgradeTDCContainer;
225  typedef std::map<HcalTrigTowerDetId, FGUpgradeTDCContainer> FGUpgradeTDCMap;
227 
228  bool upgrade_hb_ = false;
229  bool upgrade_he_ = false;
230  bool upgrade_hf_ = false;
231 
232  bool fix_saturation_ = false;
233 
235 
236  bool override_adc_hf_ = false;
238  bool override_tdc_hf_ = false;
239  unsigned long long override_tdc_hf_value_;
240 
241  // HE constants
242  static const int HBHE_OVERLAP_TOWER = 16;
243  static const int FIRST_DEPTH7_TOWER = 26;
244  static const int LAST_FINEGRAIN_DEPTH = 6;
245  static const int LAST_FINEGRAIN_TOWER = 28;
246 
247  // Fine-grain in HF ignores tower 29, and starts with 30
248  static const int FIRST_FINEGRAIN_TOWER = 30;
249 
253  // Consider CaloTPGTranscoderULUT.h for values
254  static const int QIE10_MAX_LINEARIZATION_ET = 0x7FF;
255  static const int QIE11_MAX_LINEARIZATION_ET = 0x7FF;
256  static const int QIE10_ZDC_MAX_LINEARIZATION_ET = 0x3FF;
257 };
258 
259 template <typename... Digis>
261  const HcalTPGCompressor* outcoder,
262  const HcalDbService* conditions,
264  const HcalTrigTowerGeometry* trigTowerGeometry,
265  float rctlsb,
266  const HcalFeatureBit* LongvrsShortCut,
267  const Digis&... digis) {
268  theTrigTowerGeometry = trigTowerGeometry;
269 
270  incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
271  outcoder_ = outcoder;
273 
274  theSumMap.clear();
275  theSatMap.clear();
276  theTowerMapFGSum.clear();
277  HF_Veto.clear();
278  fgMap_.clear();
279  fgUpgradeMap_.clear();
280  fgUpgradeTDCMap_.clear();
281  theHFDetailMap.clear();
282  theHFUpgradeDetailMap.clear();
283 
284  // Add all digi collections
285  addDigis(digis...);
286 
287  // Prepare the fine-grain calculation algorithm for HB/HE
288  int version = 0;
291  if (override_parameters_.exists("FGVersionHBHE"))
292  version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
293  HcalFinegrainBit fg_algo(version);
294 
295  // VME produces additional bits on the front used by lumi but not the
296  // trigger, this shift corrects those out by right shifting over them.
297  for (auto& item : theSumMap) {
298  result.push_back(HcalTriggerPrimitiveDigi(item.first));
299  HcalTrigTowerDetId detId(item.second.id());
300  if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version()) && detId.ietaAbs() < 42) {
301  if (detId.version() == 0) {
302  analyzeHF(item.second, result.back(), RCTScaleShift);
303  } else if (detId.version() == 1) {
304  if (upgrade_hf_)
306  else
308  } else {
309  // Things are going to go poorly
310  }
311  } else if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version()) && detId.ietaAbs() > 41) {
312  analyzeZDC(item.second, result.back());
313  } else {
314  // Determine which energy reconstruction path to take based on the
315  // fine-grain availability:
316  // * QIE8 TP add entries into fgMap_
317  // * QIE11 TP add entries into fgUpgradeMap_
318  // (not for tower 16 unless HB is upgraded, too)
319  if (fgMap_.find(item.first) != fgMap_.end()) {
320  analyze(item.second, result.back());
321  } else if (fgUpgradeMap_.find(item.first) != fgUpgradeMap_.end()) {
322  SatMap::iterator item_sat = theSatMap.find(detId);
323  if (item_sat == theSatMap.end())
324  analyzeQIE11(item.second, std::vector<bool>(), result.back(), fg_algo);
325  else
326  analyzeQIE11(item.second, item_sat->second, result.back(), fg_algo);
327  }
328  }
329  }
330 
331  // Free up some memory
332  theSumMap.clear();
333  theSatMap.clear();
334  theTowerMapFGSum.clear();
335  HF_Veto.clear();
336  fgMap_.clear();
337  fgUpgradeMap_.clear();
338  fgUpgradeTDCMap_.clear();
339  theHFDetailMap.clear();
340  theHFUpgradeDetailMap.clear();
341 
342  return;
343 }
344 
345 #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)
constexpr uint32_t bits
Definition: gpuClustering.h:25
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
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::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 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
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)