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 
62 
63  bool runZS_;
64 
66 
67  bool upgrade_;
68  bool legacy_;
69 
70  bool HFEMB_;
79 };
80 
82  : theAlgo_(ps.getParameter<bool>("peakFilter"),
83  ps.getParameter<std::vector<double> >("weights"),
84  ps.getParameter<int>("latency"),
85  ps.getParameter<uint32_t>("FG_threshold"),
86  ps.getParameter<std::vector<uint32_t> >("FG_HF_thresholds"),
87  ps.getParameter<uint32_t>("ZS_threshold"),
88  ps.getParameter<int>("numberOfSamples"),
89  ps.getParameter<int>("numberOfPresamples"),
90  ps.getParameter<int>("numberOfFilterPresamplesHBQIE11"),
91  ps.getParameter<int>("numberOfFilterPresamplesHEQIE11"),
92  ps.getParameter<int>("numberOfSamplesHF"),
93  ps.getParameter<int>("numberOfPresamplesHF"),
94  ps.getParameter<bool>("useTDCInMinBiasBits"),
95  ps.getParameter<uint32_t>("MinSignalThreshold"),
96  ps.getParameter<uint32_t>("PMTNoiseThreshold")),
97  inputLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputLabel")),
98  inputUpgradeLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputUpgradeLabel")),
99  inputTagFEDRaw_(ps.getParameter<edm::InputTag>("InputTagFEDRaw")),
100  runZS_(ps.getParameter<bool>("RunZS")),
101  runFrontEndFormatError_(ps.getParameter<bool>("FrontEndFormatError")) {
102  std::vector<bool> upgrades = {
103  ps.getParameter<bool>("upgradeHB"), ps.getParameter<bool>("upgradeHE"), ps.getParameter<bool>("upgradeHF")};
104  upgrade_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return a; });
105  legacy_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return !a; });
106 
107  overrideDBweightsAndFilterHE_ = ps.getParameter<bool>("overrideDBweightsAndFilterHE");
108  overrideDBweightsAndFilterHB_ = ps.getParameter<bool>("overrideDBweightsAndFilterHB");
109 
111 
112  if (ps.exists("parameters")) {
113  auto pset = ps.getUntrackedParameter<edm::ParameterSet>("parameters");
115  }
116  theAlgo_.setUpgradeFlags(upgrades[0], upgrades[1], upgrades[2]);
117  theAlgo_.setFixSaturationFlag(ps.getParameter<bool>("applySaturationFix"));
118 
119  HFEMB_ = false;
120  if (ps.exists("LSConfig")) {
122  HFEMB_ = LongShortCut_.getParameter<bool>("HcalFeatureHFEMBit");
123  MinLongEnergy_ = LongShortCut_.getParameter<double>("Min_Long_Energy"); //minimum long energy
124  MinShortEnergy_ = LongShortCut_.getParameter<double>("Min_Short_Energy"); //minimum short energy
126  LongShortCut_.getParameter<double>("Long_vrs_Short_Slope"); //slope of the line that cuts are based on
127  LongShortOffset_ = LongShortCut_.getParameter<double>("Long_Short_Offset"); //offset of line
128  }
129  tok_tpgCoder_ = esConsumes<HcalTPGCoder, HcalTPGRecord>();
130  tok_tpgTranscoder_ = esConsumes<CaloTPGTranscoder, CaloTPGRecord>();
131  tok_lutMetadata_ = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
132  tok_trigTowerGeom_ = esConsumes<HcalTrigTowerGeometry, CaloGeometryRecord>();
133  tok_hcalTopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
134 
135  // register for data access
137  tok_raw_ = consumes<FEDRawDataCollection>(inputTagFEDRaw_);
138  }
139 
140  if (legacy_) {
141  tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_[0]);
142  tok_hf_ = consumes<HFDigiCollection>(inputLabel_[1]);
143  }
144 
145  if (upgrade_) {
146  tok_hbhe_up_ = consumes<QIE11DigiCollection>(inputUpgradeLabel_[0]);
147  tok_hf_up_ = consumes<QIE10DigiCollection>(inputUpgradeLabel_[1]);
148  }
149  tok_dbService_ = esConsumes<HcalDbService, HcalDbRecord>();
150  tok_dbService_beginRun_ = esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>();
151  produces<HcalTrigPrimDigiCollection>();
152  theAlgo_.setPeakFinderAlgorithm(ps.getParameter<int>("PeakFinderAlgorithm"));
153 
154  edm::ParameterSet hfSS = ps.getParameter<edm::ParameterSet>("tpScales").getParameter<edm::ParameterSet>("HF");
155 
156  theAlgo_.setNCTScaleShift(hfSS.getParameter<int>("NCTShift"));
157  theAlgo_.setRCTScaleShift(hfSS.getParameter<int>("RCTShift"));
158 }
159 
162  const HcalTopology* topo = &eventSetup.getData(tok_hcalTopo_);
163 
164  const HcalElectronicsMap* emap = db->getHcalMapping();
165 
166  int lastHERing = topo->lastHERing();
167  int lastHBRing = topo->lastHBRing();
168 
169  std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
170  for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
171  HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
172  if (hcalTTDetId.null())
173  continue;
174 
175  int aieta = abs(hcalTTDetId.ieta());
176 
177  // Filter weight represented in fixed point 8 bit
178  int fixedPointWeight = -1;
179 
180  // The absence of TT channels in the HcalTPChannelParameters
181  // is intepreted as to not use the new filter
182  auto tpParam = db->getHcalTPChannelParameter(hcalTTDetId, false);
183  if (tpParam)
184  fixedPointWeight = tpParam->getauxi1();
185 
186  // Do not let ieta 29 in the map
187  // If the aieta already has a weight in the map, then move on
188  if (aieta <= lastHBRing) {
189  // Fix number of filter presamples to one if we are using DB weights
190  // Size of filter is already known when using DB weights
191  // Weight from DB represented as 8-bit integer
193  if (fixedPointWeight != -1) {
195  theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
196  } else {
198  theAlgo_.setWeightQIE11(aieta, 255);
199  }
200  }
201  } else if (aieta < lastHERing) {
203  if (fixedPointWeight != -1) {
205  theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
206  } else {
208  theAlgo_.setWeightQIE11(aieta, 255);
209  }
210  }
211  }
212  }
213 }
214 
216  // Step A: get the conditions, for the decoding
217  edm::ESHandle<HcalTPGCoder> inputCoder = eventSetup.getHandle(tok_tpgCoder_);
218 
220 
222  float rctlsb = lutMetadata->getRctLsb();
223 
225 
226  // Step B: Create empty output
227  std::unique_ptr<HcalTrigPrimDigiCollection> result(new HcalTrigPrimDigiCollection());
228 
231 
234 
235  if (legacy_) {
236  iEvent.getByToken(tok_hbhe_, hbheDigis);
237  iEvent.getByToken(tok_hf_, hfDigis);
238 
239  // protect here against missing input collections
240  // there is no protection in HcalTriggerPrimitiveAlgo
241 
242  if (!hbheDigis.isValid() and legacy_) {
243  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HBHEDigiCollection with input tag " << inputLabel_[0]
244  << "\nrequested in configuration, but not found in the event."
245  << "\nQuit returning empty product." << std::endl;
246 
247  // put empty HcalTrigPrimDigiCollection in the event
248  iEvent.put(std::move(result));
249 
250  return;
251  }
252 
253  if (!hfDigis.isValid() and legacy_) {
254  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputLabel_[1]
255  << "\nrequested in configuration, but not found in the event."
256  << "\nQuit returning empty product." << std::endl;
257 
258  // put empty HcalTrigPrimDigiCollection in the event
259  iEvent.put(std::move(result));
260 
261  return;
262  }
263  }
264 
265  if (upgrade_) {
266  iEvent.getByToken(tok_hbhe_up_, hbheUpDigis);
267  iEvent.getByToken(tok_hf_up_, hfUpDigis);
268 
269  if (!hbheUpDigis.isValid() and upgrade_) {
270  edm::LogInfo("HcalTrigPrimDigiProducer")
271  << "\nWarning: Upgrade HBHEDigiCollection with input tag " << inputUpgradeLabel_[0]
272  << "\nrequested in configuration, but not found in the event."
273  << "\nQuit returning empty product." << std::endl;
274 
275  // put empty HcalTrigPrimDigiCollection in the event
276  iEvent.put(std::move(result));
277 
278  return;
279  }
280 
281  if (!hfUpDigis.isValid() and upgrade_) {
282  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputUpgradeLabel_[1]
283  << "\nrequested in configuration, but not found in the event."
284  << "\nQuit returning empty product." << std::endl;
285 
286  // put empty HcalTrigPrimDigiCollection in the event
287  iEvent.put(std::move(result));
288 
289  return;
290  }
291  }
292 
294 
295  HcalFeatureBit* hfembit = nullptr;
296 
297  if (HFEMB_) {
298  hfembit = new HcalFeatureHFEMBit(MinShortEnergy_,
302  *pSetup); //inputs values that cut will be based on
303  }
304 
305  // Step C: Invoke the algorithm, passing in inputs and getting back outputs.
306  if (legacy_ and not upgrade_) {
307  theAlgo_.run(inputCoder.product(),
308  outTranscoder->getHcalCompressor().get(),
309  pSetup.product(),
310  *result,
311  &(*pG),
312  rctlsb,
313  hfembit,
314  *hbheDigis,
315  *hfDigis);
316  } else if (legacy_ and upgrade_) {
317  theAlgo_.run(inputCoder.product(),
318  outTranscoder->getHcalCompressor().get(),
319  pSetup.product(),
320  *result,
321  &(*pG),
322  rctlsb,
323  hfembit,
324  *hbheDigis,
325  *hfDigis,
326  *hbheUpDigis,
327  *hfUpDigis);
328  } else {
329  theAlgo_.run(inputCoder.product(),
330  outTranscoder->getHcalCompressor().get(),
331  pSetup.product(),
332  *result,
333  &(*pG),
334  rctlsb,
335  hfembit,
336  *hbheUpDigis,
337  *hfUpDigis);
338  }
339 
340  // Step C.1: Run FE Format Error / ZS for real data.
342  const HcalElectronicsMap* emap = pSetup->getHcalMapping();
343 
345  iEvent.getByToken(tok_raw_, fedHandle);
346 
347  if (fedHandle.isValid() && emap != nullptr) {
348  theAlgo_.runFEFormatError(fedHandle.product(), emap, *result);
349  } else {
350  edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: FEDRawDataCollection with input tag " << inputTagFEDRaw_
351  << "\nrequested in configuration, but not found in the event."
352  << "\nQuit returning empty product." << std::endl;
353 
354  // produce empty HcalTrigPrimDigiCollection and put it in the event
355  std::unique_ptr<HcalTrigPrimDigiCollection> emptyResult(new HcalTrigPrimDigiCollection());
356 
357  iEvent.put(std::move(emptyResult));
358 
359  return;
360  }
361  }
362 
363  if (runZS_)
365 
366  // edm::LogInfo("HcalTrigPrimDigiProducer") << "HcalTrigPrims: " << result->size();
367 
368  // Step D: Put outputs into event
369  iEvent.put(std::move(result));
370 }
371 
374 
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
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:92
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 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:94
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)