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:
27  HcalTriggerPrimitiveAlgo(bool pf, const std::vector<double>& w, int latency,
28  uint32_t FG_threshold, const std::vector<uint32_t>& FG_HF_thresholds, uint32_t ZS_threshold,
31  uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0);
33 
34  template<typename... Digis>
35  void run(const HcalTPGCoder* incoder,
36  const HcalTPGCompressor* outcoder,
37  const HcalDbService* conditions,
39  const HcalTrigTowerGeometry* trigTowerGeometry,
40  float rctlsb, const HcalFeatureBit* LongvrsShortCut,
41  const Digis&... digis);
42 
43  template<typename T, typename... Args>
44  void addDigis(const T& collection, const Args&... digis) {
45  addDigis(collection);
46  addDigis(digis...);
47  };
48 
49  template<typename T>
50  void addDigis(const T& collection) {
51  for (const auto& digi: collection) {
52  addSignal(digi);
53  }
54  };
55 
56  template<typename D>
58  for (auto i = collection.begin(); i != collection.end(); ++i) {
59  D digi(*i);
60  addSignal(digi);
61  }
62  };
63 
65  void runFEFormatError(const FEDRawDataCollection* rawraw,
66  const HcalElectronicsMap* emap,
68  void setPeakFinderAlgorithm(int algo);
69  void setNCTScaleShift(int);
70  void setRCTScaleShift(int);
71 
72  void setUpgradeFlags(bool hb, bool he, bool hf);
73  void overrideParameters(const edm::ParameterSet& ps);
74 
75  private:
76 
78  void addSignal(const HBHEDataFrame & frame);
79  void addSignal(const HFDataFrame & frame);
80  void addSignal(const QIE10DataFrame& frame);
81  void addSignal(const QIE11DataFrame& frame);
82  void addSignal(const IntegerCaloSamples & samples);
83  void addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb);
84  void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits);
85 
86  bool passTDC(const QIE10DataFrame& digi, int ts) const;
87  bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const;
88  bool validChannel(const QIE10DataFrame& digi, int ts) const;
89  bool needLegacyFG(const HcalTrigTowerDetId& id) const;
90 
92  void analyze(IntegerCaloSamples & samples, HcalTriggerPrimitiveDigi & result);
93  // 2017 and later: QIE11
94  void analyzeQIE11(IntegerCaloSamples& samples, HcalTriggerPrimitiveDigi& result, const HcalFinegrainBit& fg_algo);
95  // Version 0: RCT
96  void analyzeHF(IntegerCaloSamples & samples, HcalTriggerPrimitiveDigi & result, const int hf_lumi_shift);
97  // Version 1: 1x1
98  void analyzeHF2016(
99  const IntegerCaloSamples& SAMPLES,
100  HcalTriggerPrimitiveDigi& result,
101  const int HF_LUMI_SHIFT,
102  const HcalFeatureBit* HCALFEM
103  );
104  // With dual anode readout
105  void analyzeHFQIE10(
106  const IntegerCaloSamples& SAMPLES,
107  HcalTriggerPrimitiveDigi& result,
108  const int HF_LUMI_SHIFT,
109  const HcalFeatureBit* HCALFEM
110  );
111 
112  // Member initialized by constructor
116  double theThreshold;
117  bool peakfind_;
118  std::vector<double> weights_;
119  int latency_;
120  uint32_t FG_threshold_;
121  std::vector<uint32_t> FG_HF_thresholds_;
122  uint32_t ZS_threshold_;
133 
134  // Algo1: isPeak = TS[i-1] < TS[i] && TS[i] >= TS[i+1]
135  // Algo2: isPeak = TSS[i-1] < TSS[i] && TSS[i] >= TSS[i+1],
136  // TSS[i] = TS[i] + TS[i+1]
137  // Default: Algo2
139 
140  // Member not initialzed
141  //std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId & id) const;
142 
144 
145  typedef std::map<HcalTrigTowerDetId, IntegerCaloSamples> SumMap;
146  SumMap theSumMap;
147 
148  struct HFDetails {
153  };
154  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, HFDetails>> HFDetailMap;
155  HFDetailMap theHFDetailMap;
156 
160  std::vector<bool> validity;
161  std::vector<std::bitset<2>> fgbits;
162  std::vector<bool> passTDC;
163  };
164  typedef std::map<HcalTrigTowerDetId, std::map<uint32_t, std::array<HFUpgradeDetails, 4>>> HFUpgradeDetailMap;
165  HFUpgradeDetailMap theHFUpgradeDetailMap;
166 
167  typedef std::vector<IntegerCaloSamples> SumFGContainer;
168  typedef std::map< HcalTrigTowerDetId, SumFGContainer > TowerMapFGSum;
169  TowerMapFGSum theTowerMapFGSum;
170 
171  // ==============================
172  // = HF Veto
173  // ==============================
174  // Sum = Long + Short;" // intermediate calculation.
175  // if ((Short < MinSignalThresholdET OR Long < MinSignalThresholdET)
176  // AND Sum > PMTNoiseThresholdET) VetoedSum = 0;
177  // else VetoedSum = Sum;
178  // ==============================
179  // Map from FG id to veto booleans
181  typedef std::map<uint32_t, std::vector<bool> > TowerMapVeto;
182  TowerMapVeto HF_Veto;
183 
184  typedef std::map<HcalTrigTowerDetId, std::vector<bool> > FGbitMap;
185  FGbitMap fgMap_;
186 
187  typedef std::vector<HcalFinegrainBit::Tower> FGUpgradeContainer;
188  typedef std::map<HcalTrigTowerDetId, FGUpgradeContainer> FGUpgradeMap;
189  FGUpgradeMap fgUpgradeMap_;
190 
191  bool upgrade_hb_ = false;
192  bool upgrade_he_ = false;
193  bool upgrade_hf_ = false;
194 
196 
197  bool override_adc_hf_ = false;
199  bool override_tdc_hf_ = false;
200  unsigned long long override_tdc_hf_value_;
201 
202  // HE constants
203  static const int HBHE_OVERLAP_TOWER = 16;
204  static const int LAST_FINEGRAIN_DEPTH = 6;
205  static const int LAST_FINEGRAIN_TOWER = 28;
206 
207  // Fine-grain in HF ignores tower 29, and starts with 30
208  static const int FIRST_FINEGRAIN_TOWER = 30;
209 
213  // Consider CaloTPGTranscoderULUT.h for values
214  static const int QIE10_MAX_LINEARIZATION_ET = 0x7FF;
215  static const int QIE11_MAX_LINEARIZATION_ET = 0x7FF;
216 };
217 
218 template<typename... Digis>
220  const HcalTPGCompressor* outcoder,
221  const HcalDbService* conditions,
223  const HcalTrigTowerGeometry* trigTowerGeometry,
224  float rctlsb, const HcalFeatureBit* LongvrsShortCut,
225  const Digis&... digis) {
226  theTrigTowerGeometry = trigTowerGeometry;
227 
228  incoder_ = dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
229  outcoder_ = outcoder;
230  conditions_ = conditions;
231 
232  theSumMap.clear();
233  theTowerMapFGSum.clear();
234  HF_Veto.clear();
235  fgMap_.clear();
236  fgUpgradeMap_.clear();
237  theHFDetailMap.clear();
238  theHFUpgradeDetailMap.clear();
239 
240  // Add all digi collections
241  addDigis(digis...);
242 
243  // Prepare the fine-grain calculation algorithm for HB/HE
244  int version = 0;
247  if (override_parameters_.exists("FGVersionHBHE"))
248  version = override_parameters_.getParameter<uint32_t>("FGVersionHBHE");
249  HcalFinegrainBit fg_algo(version);
250 
251  // VME produces additional bits on the front used by lumi but not the
252  // trigger, this shift corrects those out by right shifting over them.
253  for (auto& item: theSumMap) {
254  result.push_back(HcalTriggerPrimitiveDigi(item.first));
255  HcalTrigTowerDetId detId(item.second.id());
256  if(detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower(detId.version())) {
257  if (detId.version() == 0) {
258  analyzeHF(item.second, result.back(), RCTScaleShift);
259  } else if (detId.version() == 1) {
260  if (upgrade_hf_)
261  analyzeHFQIE10(item.second, result.back(), NCTScaleShift, LongvrsShortCut);
262  else
263  analyzeHF2016(item.second, result.back(), NCTScaleShift, LongvrsShortCut);
264  } else {
265  // Things are going to go poorly
266  }
267  }
268  else {
269  // Determine which energy reconstruction path to take based on the
270  // fine-grain availability:
271  // * QIE8 TP add entries into fgMap_
272  // * QIE11 TP add entries into fgUpgradeMap_
273  // (not for tower 16 unless HB is upgraded, too)
274  if (fgMap_.find(item.first) != fgMap_.end()) {
275  analyze(item.second, result.back());
276  } else if (fgUpgradeMap_.find(item.first) != fgUpgradeMap_.end()) {
277  analyzeQIE11(item.second, result.back(), fg_algo);
278  }
279  }
280  }
281 
282  // Free up some memory
283  theSumMap.clear();
284  theTowerMapFGSum.clear();
285  HF_Veto.clear();
286  fgMap_.clear();
287  fgUpgradeMap_.clear();
288  theHFDetailMap.clear();
289  theHFUpgradeDetailMap.clear();
290 
291  return;
292 }
293 
294 #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
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:152
std::map< HcalTrigTowerDetId, SumFGContainer > TowerMapFGSum
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
ZS_threshold
thresholds for setting fine grain bit
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
latency
hardware algo
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