CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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,
36  int numberOfPresamples,
37  int numberOfFilterPresamplesHBQIE11,
38  int numberOfFilterPresamplesHEQIE11,
41  bool useTDCInMinBiasBits,
42  uint32_t minSignalThreshold = 0,
43  uint32_t PMT_NoiseThreshold = 0);
45 
46  template <typename... Digis>
47  void run(const HcalTPGCoder* incoder,
48  const HcalTPGCompressor* outcoder,
51  const HcalTrigTowerGeometry* trigTowerGeometry,
52  float rctlsb,
54  const Digis&... digis);
55 
56  template <typename T, typename... Args>
57  void addDigis(const T& collection, const Args&... digis) {
58  addDigis(collection);
59  addDigis(digis...);
60  };
61 
62  template <typename T>
63  void addDigis(const T& collection) {
64  for (const auto& digi : collection) {
65  addSignal(digi);
66  }
67  };
68 
69  template <typename D>
71  for (auto i = collection.begin(); i != collection.end(); ++i) {
72  D digi(*i);
73  addSignal(digi);
74  }
75  };
76 
78  void runFEFormatError(const FEDRawDataCollection* rawraw,
79  const HcalElectronicsMap* emap,
81  void setPeakFinderAlgorithm(int algo);
82  void setWeightsQIE11(const edm::ParameterSet& weightsQIE11);
83  void setWeightQIE11(int aieta, double weight);
84  void setNCTScaleShift(int);
85  void setRCTScaleShift(int);
86 
87  void setNumFilterPresamplesHBQIE11(int presamples) { numberOfFilterPresamplesHBQIE11_ = presamples; }
88 
89  void setNumFilterPresamplesHEQIE11(int presamples) { numberOfFilterPresamplesHEQIE11_ = presamples; }
90 
91  void setUpgradeFlags(bool hb, bool he, bool hf);
92  void setFixSaturationFlag(bool fix_saturation);
93  void overrideParameters(const edm::ParameterSet& ps);
94 
95 private:
97  void addSignal(const HBHEDataFrame& frame);
98  void addSignal(const HFDataFrame& frame);
99  void addSignal(const QIE10DataFrame& frame);
100  void addSignal(const QIE11DataFrame& frame);
101  void addSignal(const IntegerCaloSamples& samples);
102  void addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb);
103  void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);
104  void addUpgradeTDCFG(const HcalTrigTowerDetId& id, const QIE11DataFrame& frame);
105 
106  bool passTDC(const QIE10DataFrame& digi, int ts) const;
107  bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
108  bool validChannel(const QIE10DataFrame& digi, int ts) const;
109  bool needLegacyFG(const HcalTrigTowerDetId& id) const;
110  bool needUpgradeID(const HcalTrigTowerDetId& id, int depth) const;
111 
113  void analyze(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result);
114  // 2017 and later: QIE11
115  void analyzeQIE11(IntegerCaloSamples& samples,
116  std::vector<bool> sample_saturation,
117  HcalTriggerPrimitiveDigi& result,
118  const HcalFinegrainBit& fg_algo);
119  // Version 0: RCT
120  void analyzeHF(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const int hf_lumi_shift);
121  // Version 1: 1x1
122  void analyzeHF2016(const IntegerCaloSamples& SAMPLES,
123  HcalTriggerPrimitiveDigi& result,
124  const int HF_LUMI_SHIFT,
125  const HcalFeatureBit* HCALFEM);
126  // With dual anode readout
127  void analyzeHFQIE10(const IntegerCaloSamples& SAMPLES,
128  HcalTriggerPrimitiveDigi& result,
129  const int HF_LUMI_SHIFT,
130  const HcalFeatureBit* HCALFEM);
131 
132  // Member initialized by constructor
136  double theThreshold;
137  bool peakfind_;
138  std::vector<double> weights_;
139  std::array<std::array<double, 2>, 29> weightsQIE11_;
140  int latency_;
141  uint32_t FG_threshold_;
142  std::vector<uint32_t> FG_HF_thresholds_;
143  uint32_t ZS_threshold_;
156 
157  // Algo1: isPeak = TS[i-1] < TS[i] && TS[i] >= TS[i+1]
158  // Algo2: isPeak = TSS[i-1] < TSS[i] && TSS[i] >= TSS[i+1],
159  // TSS[i] = TS[i] + TS[i+1]
160  // Default: Algo2
162 
163  // Member not initialzed
164  //std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId & id) const;
165 
167 
168  typedef std::map<HcalTrigTowerDetId, IntegerCaloSamples> SumMap;
170 
171  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> SatMap;
173 
174  struct HFDetails {
179  };
180  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, HFDetails>> HFDetailMap;
182 
186  std::vector<bool> validity;
187  std::vector<std::bitset<2>> fgbits;
188  std::vector<bool> passTDC;
189  };
190  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
192 
193  typedef std::vector<IntegerCaloSamples> SumFGContainer;
194  typedef std::map<HcalTrigTowerDetId, SumFGContainer> TowerMapFGSum;
196 
197  // ==============================
198  // = HF Veto
199  // ==============================
200  // Sum = Long + Short;" // intermediate calculation.
201  // if ((Short < MinSignalThresholdET OR Long < MinSignalThresholdET)
202  // AND Sum > PMTNoiseThresholdET) VetoedSum = 0;
203  // else VetoedSum = Sum;
204  // ==============================
205  // Map from FG id to veto booleans
207  typedef std::map<uint32_t, std::vector<bool>> TowerMapVeto;
209 
210  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> FGbitMap;
212 
213  typedef std::vector<HcalFinegrainBit::Tower> FGUpgradeContainer;
214  typedef std::map<HcalTrigTowerDetId, FGUpgradeContainer> FGUpgradeMap;
216 
217  typedef std::vector<HcalFinegrainBit::TowerTDC> FGUpgradeTDCContainer;
218  typedef std::map<HcalTrigTowerDetId, FGUpgradeTDCContainer> FGUpgradeTDCMap;
220 
221  bool upgrade_hb_ = false;
222  bool upgrade_he_ = false;
223  bool upgrade_hf_ = false;
224 
225  bool fix_saturation_ = false;
226 
228 
229  bool override_adc_hf_ = false;
231  bool override_tdc_hf_ = false;
232  unsigned long long override_tdc_hf_value_;
233 
234  // HE constants
235  static const int HBHE_OVERLAP_TOWER = 16;
236  static const int FIRST_DEPTH7_TOWER = 26;
237  static const int LAST_FINEGRAIN_DEPTH = 6;
238  static const int LAST_FINEGRAIN_TOWER = 28;
239 
240  // Fine-grain in HF ignores tower 29, and starts with 30
241  static const int FIRST_FINEGRAIN_TOWER = 30;
242 
246  // Consider CaloTPGTranscoderULUT.h for values
247  static const int QIE10_MAX_LINEARIZATION_ET = 0x7FF;
248  static const int QIE11_MAX_LINEARIZATION_ET = 0x7FF;
249 };
250 
251 template <typename... Digis>
253  const HcalTPGCompressor* outcoder,
254  const HcalDbService* conditions,
256  const HcalTrigTowerGeometry* trigTowerGeometry,
257  float rctlsb,
258  const HcalFeatureBit* LongvrsShortCut,
259  const Digis&... digis) {
260  theTrigTowerGeometry = trigTowerGeometry;
261 
262  incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
263  outcoder_ = outcoder;
265 
266  theSumMap.clear();
267  theSatMap.clear();
268  theTowerMapFGSum.clear();
269  HF_Veto.clear();
270  fgMap_.clear();
271  fgUpgradeMap_.clear();
272  fgUpgradeTDCMap_.clear();
273  theHFDetailMap.clear();
274  theHFUpgradeDetailMap.clear();
275 
276  // Add all digi collections
277  addDigis(digis...);
278 
279  // Prepare the fine-grain calculation algorithm for HB/HE
280  int version = 0;
283  if (override_parameters_.exists("FGVersionHBHE"))
284  version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
285  HcalFinegrainBit fg_algo(version);
286 
287  // VME produces additional bits on the front used by lumi but not the
288  // trigger, this shift corrects those out by right shifting over them.
289  for (auto& item : theSumMap) {
290  result.push_back(HcalTriggerPrimitiveDigi(item.first));
291  HcalTrigTowerDetId detId(item.second.id());
292  if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version())) {
293  if (detId.version() == 0) {
294  analyzeHF(item.second, result.back(), RCTScaleShift);
295  } else if (detId.version() == 1) {
296  if (upgrade_hf_)
298  else
300  } else {
301  // Things are going to go poorly
302  }
303  } else {
304  // Determine which energy reconstruction path to take based on the
305  // fine-grain availability:
306  // * QIE8 TP add entries into fgMap_
307  // * QIE11 TP add entries into fgUpgradeMap_
308  // (not for tower 16 unless HB is upgraded, too)
309  if (fgMap_.find(item.first) != fgMap_.end()) {
310  analyze(item.second, result.back());
311  } else if (fgUpgradeMap_.find(item.first) != fgUpgradeMap_.end()) {
312  SatMap::iterator item_sat = theSatMap.find(detId);
313  if (item_sat == theSatMap.end())
314  analyzeQIE11(item.second, std::vector<bool>(), result.back(), fg_algo);
315  else
316  analyzeQIE11(item.second, item_sat->second, result.back(), fg_algo);
317  }
318  }
319  }
320 
321  // Free up some memory
322  theSumMap.clear();
323  theSatMap.clear();
324  theTowerMapFGSum.clear();
325  HF_Veto.clear();
326  fgMap_.clear();
327  fgUpgradeMap_.clear();
328  fgUpgradeTDCMap_.clear();
329  theHFDetailMap.clear();
330  theHFUpgradeDetailMap.clear();
331 
332  return;
333 }
334 
335 #endif
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)
std::map< uint32_t, std::vector< bool > > TowerMapVeto
std::vector< uint32_t > FG_HF_thresholds_
HFUpgradeDetailMap theHFUpgradeDetailMap
bool passTDC(const QIE10DataFrame &digi, int ts) const
void analyzeHF(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const int hf_lumi_shift)
const double w
Definition: UKUtility.cc:23
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
Definition: Activities.doc:12
std::map< HcalTrigTowerDetId, FGUpgradeTDCContainer > FGUpgradeTDCMap
static const int QIE10_MAX_LINEARIZATION_ET
void analyzeHF2016(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
static const int QIE11_LUT_BITMASK
void analyzeHFQIE10(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
bool exists(std::string const &parameterName) const
checks if a parameter exists
void push_back(T const &t)
const HcalTPGCompressor * outcoder_
std::map< HcalTrigTowerDetId, FGUpgradeContainer > FGUpgradeMap
void addFG(const HcalTrigTowerDetId &id, std::vector< bool > &msb)
const_iterator begin() const
The iterator returned can not safely be used across threads.
static const int QIE8_LUT_BITMASK
bool needLegacyFG(const HcalTrigTowerDetId &id) const
tuple numberOfSamplesHF
bool validChannel(const QIE10DataFrame &digi, int ts) const
tuple result
Definition: mps_fire.py:311
std::vector< IntegerCaloSamples > SumFGContainer
std::map< HcalTrigTowerDetId, SumFGContainer > TowerMapFGSum
const HcalTrigTowerGeometry * theTrigTowerGeometry
const HcalDbService * conditions_
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 setNumFilterPresamplesHEQIE11(int presamples)
int getFGVersionHBHE() const
get FineGrain Algorithm Version for HBHE
void runZS(HcalTrigPrimDigiCollection &tp)
static const int QIE10_LUT_BITMASK
bool needUpgradeID(const HcalTrigTowerDetId &id, int depth) const
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
std::array< std::array< double, 2 >, 29 > weightsQIE11_
void addDigis(const T &collection, const Args &...digis)
void addDigis(const T &collection)
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
unsigned long long override_tdc_hf_value_
bool validUpgradeFG(const HcalTrigTowerDetId &id, int depth) const
static const int QIE11_MAX_LINEARIZATION_ET
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< HcalTrigTowerDetId, IntegerCaloSamples > SumMap
const HcalTPParameters * getHcalTPParameters() const
tuple numberOfPresamplesHF
void addUpgradeFG(const HcalTrigTowerDetId &id, int depth, const std::vector< std::bitset< 2 >> &bits)
const_iterator end() const
std::map< HcalTrigTowerDetId, std::map< uint32_t, std::array< HFUpgradeDetails, 4 > > > HFUpgradeDetailMap
const HcaluLUTTPGCoder * incoder_
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)
void setNumFilterPresamplesHBQIE11(int presamples)
void setWeightQIE11(int aieta, double weight)
int weight
Definition: histoStyle.py:51
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)
const_reference back() const
void setFixSaturationFlag(bool fix_saturation)
int firstHFTower(int version) const