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 
19 #include <map>
20 #include <vector>
21 
22 class CaloGeometry;
23 class IntegerCaloSamples;
24 
26 public:
28  const std::vector<double>& w,
29  int latency,
30  uint32_t FG_threshold,
31  const std::vector<uint32_t>& FG_HF_thresholds,
32  uint32_t ZS_threshold,
33  int numberOfSamples,
38  uint32_t minSignalThreshold = 0,
39  uint32_t PMT_NoiseThreshold = 0);
41 
42  template <typename... Digis>
43  void run(const HcalTPGCoder* incoder,
44  const HcalTPGCompressor* outcoder,
45  const HcalDbService* conditions,
47  const HcalTrigTowerGeometry* trigTowerGeometry,
48  float rctlsb,
50  const Digis&... digis);
51 
52  template <typename T, typename... Args>
53  void addDigis(const T& collection, const Args&... digis) {
54  addDigis(collection);
55  addDigis(digis...);
56  };
57 
58  template <typename T>
59  void addDigis(const T& collection) {
60  for (const auto& digi : collection) {
61  addSignal(digi);
62  }
63  };
64 
65  template <typename D>
67  for (auto i = collection.begin(); i != collection.end(); ++i) {
68  D digi(*i);
69  addSignal(digi);
70  }
71  };
72 
74  void runFEFormatError(const FEDRawDataCollection* rawraw,
75  const HcalElectronicsMap* emap,
77  void setPeakFinderAlgorithm(int algo);
78  void setNCTScaleShift(int);
79  void setRCTScaleShift(int);
80 
81  void setUpgradeFlags(bool hb, bool he, bool hf);
82  void overrideParameters(const edm::ParameterSet& ps);
83 
84 private:
86  void addSignal(const HBHEDataFrame& frame);
87  void addSignal(const HFDataFrame& frame);
88  void addSignal(const QIE10DataFrame& frame);
89  void addSignal(const QIE11DataFrame& frame);
91  void addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb);
92  void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);
93 
94  bool passTDC(const QIE10DataFrame& digi, int ts) const;
95  bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
96  bool validChannel(const QIE10DataFrame& digi, int ts) const;
97  bool needLegacyFG(const HcalTrigTowerDetId& id) const;
98 
100  void analyze(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result);
101  // 2017 and later: QIE11
102  void analyzeQIE11(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const HcalFinegrainBit& fg_algo);
103  // Version 0: RCT
104  void analyzeHF(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const int hf_lumi_shift);
105  // Version 1: 1x1
106  void analyzeHF2016(const IntegerCaloSamples& SAMPLES,
107  HcalTriggerPrimitiveDigi& result,
108  const int HF_LUMI_SHIFT,
109  const HcalFeatureBit* HCALFEM);
110  // With dual anode readout
111  void analyzeHFQIE10(const IntegerCaloSamples& SAMPLES,
112  HcalTriggerPrimitiveDigi& result,
113  const int HF_LUMI_SHIFT,
114  const HcalFeatureBit* HCALFEM);
115 
116  // Member initialized by constructor
120  double theThreshold;
121  bool peakfind_;
122  std::vector<double> weights_;
123  int latency_;
124  uint32_t FG_threshold_;
125  std::vector<uint32_t> FG_HF_thresholds_;
126  uint32_t ZS_threshold_;
137 
138  // Algo1: isPeak = TS[i-1] < TS[i] && TS[i] >= TS[i+1]
139  // Algo2: isPeak = TSS[i-1] < TSS[i] && TSS[i] >= TSS[i+1],
140  // TSS[i] = TS[i] + TS[i+1]
141  // Default: Algo2
143 
144  // Member not initialzed
145  //std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId & id) const;
146 
148 
149  typedef std::map<HcalTrigTowerDetId, IntegerCaloSamples> SumMap;
150  SumMap theSumMap;
151 
152  struct HFDetails {
157  };
158  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, HFDetails>> HFDetailMap;
159  HFDetailMap theHFDetailMap;
160 
164  std::vector<bool> validity;
165  std::vector<std::bitset<2>> fgbits;
166  std::vector<bool> passTDC;
167  };
168  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
169  HFUpgradeDetailMap theHFUpgradeDetailMap;
170 
171  typedef std::vector<IntegerCaloSamples> SumFGContainer;
172  typedef std::map<HcalTrigTowerDetId, SumFGContainer> TowerMapFGSum;
173  TowerMapFGSum theTowerMapFGSum;
174 
175  // ==============================
176  // = HF Veto
177  // ==============================
178  // Sum = Long + Short;" // intermediate calculation.
179  // if ((Short < MinSignalThresholdET OR Long < MinSignalThresholdET)
180  // AND Sum > PMTNoiseThresholdET) VetoedSum = 0;
181  // else VetoedSum = Sum;
182  // ==============================
183  // Map from FG id to veto booleans
185  typedef std::map<uint32_t, std::vector<bool>> TowerMapVeto;
186  TowerMapVeto HF_Veto;
187 
188  typedef std::map<HcalTrigTowerDetId, std::vector<bool>> FGbitMap;
189  FGbitMap fgMap_;
190 
191  typedef std::vector<HcalFinegrainBit::Tower> FGUpgradeContainer;
192  typedef std::map<HcalTrigTowerDetId, FGUpgradeContainer> FGUpgradeMap;
193  FGUpgradeMap fgUpgradeMap_;
194 
195  bool upgrade_hb_ = false;
196  bool upgrade_he_ = false;
197  bool upgrade_hf_ = false;
198 
200 
201  bool override_adc_hf_ = false;
203  bool override_tdc_hf_ = false;
204  unsigned long long override_tdc_hf_value_;
205 
206  // HE constants
207  static const int HBHE_OVERLAP_TOWER = 16;
208  static const int LAST_FINEGRAIN_DEPTH = 6;
209  static const int LAST_FINEGRAIN_TOWER = 28;
210 
211  // Fine-grain in HF ignores tower 29, and starts with 30
212  static const int FIRST_FINEGRAIN_TOWER = 30;
213 
217  // Consider CaloTPGTranscoderULUT.h for values
218  static const int QIE10_MAX_LINEARIZATION_ET = 0x7FF;
219  static const int QIE11_MAX_LINEARIZATION_ET = 0x7FF;
220 };
221 
222 template <typename... Digis>
224  const HcalTPGCompressor* outcoder,
225  const HcalDbService* conditions,
227  const HcalTrigTowerGeometry* trigTowerGeometry,
228  float rctlsb,
230  const Digis&... digis) {
231  theTrigTowerGeometry = trigTowerGeometry;
232 
233  incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
234  outcoder_ = outcoder;
235  conditions_ = conditions;
236 
237  theSumMap.clear();
238  theTowerMapFGSum.clear();
239  HF_Veto.clear();
240  fgMap_.clear();
241  fgUpgradeMap_.clear();
242  theHFDetailMap.clear();
243  theHFUpgradeDetailMap.clear();
244 
245  // Add all digi collections
246  addDigis(digis...);
247 
248  // Prepare the fine-grain calculation algorithm for HB/HE
249  int version = 0;
252  if (override_parameters_.exists("FGVersionHBHE"))
253  version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
254  HcalFinegrainBit fg_algo(version);
255 
256  // VME produces additional bits on the front used by lumi but not the
257  // trigger, this shift corrects those out by right shifting over them.
258  for (auto& item : theSumMap) {
259  result.push_back(HcalTriggerPrimitiveDigi(item.first));
260  HcalTrigTowerDetId detId(item.second.id());
261  if (detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version())) {
262  if (detId.version() == 0) {
263  analyzeHF(item.second, result.back(), RCTScaleShift);
264  } else if (detId.version() == 1) {
265  if (upgrade_hf_)
267  else
269  } else {
270  // Things are going to go poorly
271  }
272  } else {
273  // Determine which energy reconstruction path to take based on the
274  // fine-grain availability:
275  // * QIE8 TP add entries into fgMap_
276  // * QIE11 TP add entries into fgUpgradeMap_
277  // (not for tower 16 unless HB is upgraded, too)
278  if (fgMap_.find(item.first) != fgMap_.end()) {
279  analyze(item.second, result.back());
280  } else if (fgUpgradeMap_.find(item.first) != fgUpgradeMap_.end()) {
281  analyzeQIE11(item.second, result.back(), fg_algo);
282  }
283  }
284  }
285 
286  // Free up some memory
287  theSumMap.clear();
288  theTowerMapFGSum.clear();
289  HF_Veto.clear();
290  fgMap_.clear();
291  fgUpgradeMap_.clear();
292  theHFDetailMap.clear();
293  theHFUpgradeDetailMap.clear();
294 
295  return;
296 }
297 
298 #endif
T getParameter(std::string const &) const
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
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 numberOfSamplesHF, int numberOfPresamplesHF, bool useTDCInMinBiasBits, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
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
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
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
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)
void analyzeQIE11(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const HcalFinegrainBit &fg_algo)
const_iterator begin() const
static const int QIE8_LUT_BITMASK
bool needLegacyFG(const HcalTrigTowerDetId &id) const
bool validChannel(const QIE10DataFrame &digi, int ts) const
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)
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
int getFGVersionHBHE() const
get FineGrain Algorithm Version for HBHE
void runZS(HcalTrigPrimDigiCollection &tp)
static const int QIE10_LUT_BITMASK
std::map< HcalTrigTowerDetId, std::vector< bool > > FGbitMap
std::vector< HcalFinegrainBit::Tower > FGUpgradeContainer
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
std::map< HcalTrigTowerDetId, IntegerCaloSamples > SumMap
const HcalTPParameters * getHcalTPParameters() const
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_
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)
const_reference back() const
int firstHFTower(int version) const