CMS 3D CMS Logo

HcalTrigPrimDigiProducer.cc
Go to the documentation of this file.
29 
30 #include <algorithm>
31 #include <vector>
32 
34 public:
35  explicit HcalTrigPrimDigiProducer(const edm::ParameterSet& ps);
37 
39  void beginRun(const edm::Run& r, const edm::EventSetup& c) override;
40  void produce(edm::Event& e, const edm::EventSetup& c) override;
41 
42 private:
44 
46  std::vector<edm::InputTag> inputLabel_;
47  std::vector<edm::InputTag> inputUpgradeLabel_;
48  // this seems a strange way of doing things
51 
54 
57 
60 
65 
66  bool runZS_;
67 
69 
70  bool upgrade_;
71  bool legacy_;
72 
73  bool HFEMB_;
82 };
83 
85  : theAlgo_(ps.getParameter<bool>("peakFilter"),
86  ps.getParameter<std::vector<double> >("weights"),
87  ps.getParameter<int>("latency"),
88  ps.getParameter<uint32_t>("FG_threshold"),
89  ps.getParameter<std::vector<uint32_t> >("FG_HF_thresholds"),
90  ps.getParameter<uint32_t>("ZS_threshold"),
91  ps.getParameter<int>("numberOfSamples"),
92  ps.getParameter<int>("numberOfPresamples"),
93  ps.getParameter<int>("numberOfFilterPresamplesHBQIE11"),
94  ps.getParameter<int>("numberOfFilterPresamplesHEQIE11"),
95  ps.getParameter<int>("numberOfSamplesHF"),
96  ps.getParameter<int>("numberOfPresamplesHF"),
97  ps.getParameter<bool>("useTDCInMinBiasBits"),
98  ps.getParameter<uint32_t>("MinSignalThreshold"),
99  ps.getParameter<uint32_t>("PMTNoiseThreshold")),
100  inputLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputLabel")),
101  inputUpgradeLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputUpgradeLabel")),
102  inputTagFEDRaw_(ps.getParameter<edm::InputTag>("InputTagFEDRaw")),
103  runZS_(ps.getParameter<bool>("RunZS")),
104  runFrontEndFormatError_(ps.getParameter<bool>("FrontEndFormatError")) {
105  std::vector<bool> upgrades = {
106  ps.getParameter<bool>("upgradeHB"), ps.getParameter<bool>("upgradeHE"), ps.getParameter<bool>("upgradeHF")};
107  upgrade_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return a; });
108  legacy_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return !a; });
109 
110  overrideDBvetoThresholdsHE_ = ps.getParameter<bool>("overrideDBvetoThresholdsHE");
111  overrideDBvetoThresholdsHB_ = ps.getParameter<bool>("overrideDBvetoThresholdsHB");
112 
113  overrideDBweightsAndFilterHE_ = ps.getParameter<bool>("overrideDBweightsAndFilterHE");
114  overrideDBweightsAndFilterHB_ = ps.getParameter<bool>("overrideDBweightsAndFilterHB");
115 
118 
119  if (ps.exists("parameters")) {
120  auto pset = ps.getUntrackedParameter<edm::ParameterSet>("parameters");
122  }
123  theAlgo_.setUpgradeFlags(upgrades[0], upgrades[1], upgrades[2]);
124  theAlgo_.setFixSaturationFlag(ps.getParameter<bool>("applySaturationFix"));
125 
126  HFEMB_ = false;
127  if (ps.exists("LSConfig")) {
129  HFEMB_ = LongShortCut_.getParameter<bool>("HcalFeatureHFEMBit");
130  MinLongEnergy_ = LongShortCut_.getParameter<double>("Min_Long_Energy"); //minimum long energy
131  MinShortEnergy_ = LongShortCut_.getParameter<double>("Min_Short_Energy"); //minimum short energy
133  LongShortCut_.getParameter<double>("Long_vrs_Short_Slope"); //slope of the line that cuts are based on
134  LongShortOffset_ = LongShortCut_.getParameter<double>("Long_Short_Offset"); //offset of line
135  }
136  tok_tpgCoder_ = esConsumes<HcalTPGCoder, HcalTPGRecord>();
137  tok_tpgTranscoder_ = esConsumes<CaloTPGTranscoder, CaloTPGRecord>();
138  tok_lutMetadata_ = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
139  tok_trigTowerGeom_ = esConsumes<HcalTrigTowerGeometry, CaloGeometryRecord>();
140  tok_hcalTopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
141 
142  // register for data access
144  tok_raw_ = consumes<FEDRawDataCollection>(inputTagFEDRaw_);
145  }
146 
147  if (legacy_) {
148  tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_[0]);
149  tok_hf_ = consumes<HFDigiCollection>(inputLabel_[1]);
150  }
151 
152  if (upgrade_) {
153  tok_hbhe_up_ = consumes<QIE11DigiCollection>(inputUpgradeLabel_[0]);
154  tok_hf_up_ = consumes<QIE10DigiCollection>(inputUpgradeLabel_[1]);
155  }
156  tok_dbService_ = esConsumes<HcalDbService, HcalDbRecord>();
157  tok_dbService_beginRun_ = esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>();
158  produces<HcalTrigPrimDigiCollection>();
159  theAlgo_.setPeakFinderAlgorithm(ps.getParameter<int>("PeakFinderAlgorithm"));
160 
161  edm::ParameterSet hfSS = ps.getParameter<edm::ParameterSet>("tpScales").getParameter<edm::ParameterSet>("HF");
162 
163  theAlgo_.setNCTScaleShift(hfSS.getParameter<int>("NCTShift"));
164  theAlgo_.setRCTScaleShift(hfSS.getParameter<int>("RCTShift"));
165 }
166 
169  const HcalTopology* topo = &eventSetup.getData(tok_hcalTopo_);
170 
171  const HcalElectronicsMap* emap = db->getHcalMapping();
172 
173  int lastHERing = topo->lastHERing();
174  int lastHBRing = topo->lastHBRing();
175 
176  std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
177  for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
178  HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
179  if (hcalTTDetId.null())
180  continue;
181 
182  int aieta = std::abs(hcalTTDetId.ieta());
183  // Do not let ieta 29 in the map
184  if (aieta >= lastHERing)
185  continue;
186 
187  // Filter weight represented in fixed point 8 bit
188  int fixedPointWeight = 255;
189  // Coded veto threshold in range (0, 2048)
190  // Default, special value of 0 will disable vetoing
191  int codedVetoThreshold = 0;
192  // Number of filter presamples
193  int presamples = 0;
194 
195  // The absence of TT channels in the HcalTPChannelParameters
196  // is intepreted as to not use the new filter
197  auto tpParam = db->getHcalTPChannelParameter(hcalTTDetId, false);
198  if (tpParam) {
199  // Fix number of filter presamples to one if we are using DB weights
200  // Size of filter is already known when using DB weights
201  // Weight from DB represented as 8-bit integer
202  fixedPointWeight = tpParam->getauxi1();
203  codedVetoThreshold = tpParam->getauxi2();
204  presamples = 1;
205  }
206 
207  // If the aieta already has a weight in the map, then move on
208  if (aieta <= lastHBRing) {
210  theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold);
211  }
214  theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
215  }
216  } else if (aieta < lastHERing) {
218  theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold);
219  }
222  theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
223  }
224  }
225  }
226 }
227 
229  // Step A: get the conditions, for the decoding
230  edm::ESHandle<HcalTPGCoder> inputCoder = eventSetup.getHandle(tok_tpgCoder_);
231 
233 
235  float rctlsb = lutMetadata->getRctLsb();
236 
238 
239  // Step B: Create empty output
240  std::unique_ptr<HcalTrigPrimDigiCollection> result(new HcalTrigPrimDigiCollection());
241 
244 
247 
248  if (legacy_) {
249  iEvent.getByToken(tok_hbhe_, hbheDigis);
250  iEvent.getByToken(tok_hf_, hfDigis);
251 
252  // protect here against missing input collections
253  // there is no protection in HcalTriggerPrimitiveAlgo
254 
255  if (!hbheDigis.isValid() and legacy_) {
256  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HBHEDigiCollection with input tag " << inputLabel_[0]
257  << "\nrequested in configuration, but not found in the event."
258  << "\nQuit returning empty product." << std::endl;
259 
260  // put empty HcalTrigPrimDigiCollection in the event
261  iEvent.put(std::move(result));
262 
263  return;
264  }
265 
266  if (!hfDigis.isValid() and legacy_) {
267  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputLabel_[1]
268  << "\nrequested in configuration, but not found in the event."
269  << "\nQuit returning empty product." << std::endl;
270 
271  // put empty HcalTrigPrimDigiCollection in the event
272  iEvent.put(std::move(result));
273 
274  return;
275  }
276  }
277 
278  if (upgrade_) {
279  iEvent.getByToken(tok_hbhe_up_, hbheUpDigis);
280  iEvent.getByToken(tok_hf_up_, hfUpDigis);
281 
282  if (!hbheUpDigis.isValid() and upgrade_) {
283  edm::LogInfo("HcalTrigPrimDigiProducer")
284  << "\nWarning: Upgrade HBHEDigiCollection with input tag " << inputUpgradeLabel_[0]
285  << "\nrequested in configuration, but not found in the event."
286  << "\nQuit returning empty product." << std::endl;
287 
288  // put empty HcalTrigPrimDigiCollection in the event
289  iEvent.put(std::move(result));
290 
291  return;
292  }
293 
294  if (!hfUpDigis.isValid() and upgrade_) {
295  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputUpgradeLabel_[1]
296  << "\nrequested in configuration, but not found in the event."
297  << "\nQuit returning empty product." << std::endl;
298 
299  // put empty HcalTrigPrimDigiCollection in the event
300  iEvent.put(std::move(result));
301 
302  return;
303  }
304  }
305 
307 
308  HcalFeatureBit* hfembit = nullptr;
309 
310  if (HFEMB_) {
311  hfembit = new HcalFeatureHFEMBit(MinShortEnergy_,
315  *pSetup); //inputs values that cut will be based on
316  }
317 
318  // Step C: Invoke the algorithm, passing in inputs and getting back outputs.
319  if (legacy_ and not upgrade_) {
320  theAlgo_.run(inputCoder.product(),
321  outTranscoder->getHcalCompressor().get(),
322  pSetup.product(),
323  *result,
324  &(*pG),
325  rctlsb,
326  hfembit,
327  *hbheDigis,
328  *hfDigis);
329  } else if (legacy_ and upgrade_) {
330  theAlgo_.run(inputCoder.product(),
331  outTranscoder->getHcalCompressor().get(),
332  pSetup.product(),
333  *result,
334  &(*pG),
335  rctlsb,
336  hfembit,
337  *hbheDigis,
338  *hfDigis,
339  *hbheUpDigis,
340  *hfUpDigis);
341  } else {
342  theAlgo_.run(inputCoder.product(),
343  outTranscoder->getHcalCompressor().get(),
344  pSetup.product(),
345  *result,
346  &(*pG),
347  rctlsb,
348  hfembit,
349  *hbheUpDigis,
350  *hfUpDigis);
351  }
352 
353  // Step C.1: Run FE Format Error / ZS for real data.
355  const HcalElectronicsMap* emap = pSetup->getHcalMapping();
356 
358  iEvent.getByToken(tok_raw_, fedHandle);
359 
360  if (fedHandle.isValid() && emap != nullptr) {
361  theAlgo_.runFEFormatError(fedHandle.product(), emap, *result);
362  } else {
363  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: FEDRawDataCollection with input tag " << inputTagFEDRaw_
364  << "\nrequested in configuration, but not found in the event."
365  << "\nQuit returning empty product." << std::endl;
366 
367  // produce empty HcalTrigPrimDigiCollection and put it in the event
368  std::unique_ptr<HcalTrigPrimDigiCollection> emptyResult(new HcalTrigPrimDigiCollection());
369 
370  iEvent.put(std::move(emptyResult));
371 
372  return;
373  }
374  }
375 
376  if (runZS_)
378 
379  edm::LogInfo("HcalTrigPrimDigiProducer") << "HcalTrigPrims: " << result->size();
380 
381  // Step D: Put outputs into event
382  iEvent.put(std::move(result));
383 }
384 
387 
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
edm::InputTag inputTagFEDRaw_
input tag for FEDRawDataCollection
edm::ESGetToken< HcalTrigTowerGeometry, CaloGeometryRecord > tok_trigTowerGeom_
void produce(edm::Event &e, const edm::EventSetup &c) override
void runFEFormatError(const FEDRawDataCollection *rawraw, const HcalElectronicsMap *emap, HcalTrigPrimDigiCollection &result)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
HcalTrigPrimDigiProducer(const edm::ParameterSet &ps)
edm::ESGetToken< HcalDbService, HcalDbRecord > tok_dbService_beginRun_
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
std::vector< edm::InputTag > inputUpgradeLabel_
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
HcalTriggerPrimitiveAlgo theAlgo_
const HcalElectronicsMap * getHcalMapping() const
void setCodedVetoThresholds(const edm::ParameterSet &codedVetoThresholds)
edm::EDGetTokenT< HFDigiCollection > tok_hf_
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
void setWeightQIE11(int aieta, int weight)
std::shared_ptr< const HcalTPGCompressor > getHcalCompressor() const
int lastHBRing() const
Definition: HcalTopology.h:89
void setNumFilterPresamplesHEQIE11(int presamples)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > tok_tpgTranscoder_
void setCodedVetoThreshold(int aieta, int codedVetoThreshold)
void runZS(HcalTrigPrimDigiCollection &tp)
edm::EDGetTokenT< QIE10DigiCollection > tok_hf_up_
edm::ESGetToken< HcalTPGCoder, HcalTPGRecord > tok_tpgCoder_
Log< level::Info, false > LogInfo
void run(const HcalTPGCoder *incoder, const HcalTPGCompressor *outcoder, const HcalDbService *conditions, HcalTrigPrimDigiCollection &result, const HcalTrigTowerGeometry *trigTowerGeometry, float rctlsb, const HcalFeatureBit *LongvrsShortCut, const Digis &... digis)
float getRctLsb() const
edm::ESGetToken< HcalLutMetadata, HcalLutMetadataRcd > tok_lutMetadata_
edm::EDGetTokenT< QIE11DigiCollection > tok_hbhe_up_
edm::ESGetToken< HcalDbService, HcalDbRecord > tok_dbService_
bool isValid() const
Definition: HandleBase.h:70
void setNumFilterPresamplesHBQIE11(int presamples)
HLT enums.
double a
Definition: hdecay.h:121
int lastHERing() const
Definition: HcalTopology.h:91
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
std::vector< edm::InputTag > inputLabel_
input tags for HCAL digis
void setUpgradeFlags(bool hb, bool he, bool hf)
void overrideParameters(const edm::ParameterSet &ps)
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_hcalTopo_
void setWeightsQIE11(const edm::ParameterSet &weightsQIE11)
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhe_
Definition: Run.h:45
void setFixSaturationFlag(bool fix_saturation)