CMS 3D CMS Logo

EcalTrigPrimProducer.cc
Go to the documentation of this file.
1 
18 
26 
31 
69 
72 
73 #include <memory>
74 
76 
78 public:
79  explicit EcalTrigPrimProducer(const edm::ParameterSet &conf);
80 
81  ~EcalTrigPrimProducer() override;
82 
83  void beginRun(const edm::Run &run, const edm::EventSetup &es) override;
84  void endRun(const edm::Run &, const edm::EventSetup &) override;
85  void produce(edm::Event &e, const edm::EventSetup &c) override;
86 
87  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
88 
89 private:
90  std::unique_ptr<EcalTrigPrimFunctionalAlgo> algo_;
92  bool tcpFormat_;
93  bool debug_;
94  bool famos_;
98 
100  //these are only used if we also handle the endcap
103 
104  // for EcalFenixStrip...
105  // get parameter records for xtals
109 
110  // for strips
118 
119  // .. and for EcalFenixTcp
120  // get parameter records for towers
128  // TPG TP mode
130 
133 
134  // method to get EventSetupRecords
135  unsigned long long getRecords(edm::EventSetup const &setup);
136  unsigned long long cacheID_;
137 };
138 
140  : barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
141  tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
142  debug_(iConfig.getParameter<bool>("Debug")),
143  famos_(iConfig.getParameter<bool>("Famos")),
144  tpInfoPrintout_(iConfig.getParameter<bool>("TPinfoPrintout")),
145  tokenEB_(consumes<EBDigiCollection>(
146  edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEB")))),
147  tokenEE_(consumes<EEDigiCollection>(
148  edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEE")))),
149  tokenEcalMapping_(esConsumes<edm::Transition::BeginRun>()),
150  tokenEcalTPGLinearization_(esConsumes()),
151  tokenEcalTPGPedestals_(esConsumes()),
152  tokenEcalTPGCrystalStatus_(esConsumes()),
153  tokenEcalTPGSlidingWindow_(esConsumes()),
154  tokenEcalTPGWeightIdMap_(esConsumes()),
155  tokenEcalTPGWeightGroup_(esConsumes()),
156  tokenEcalTPGOddWeightIdMap_(esConsumes()),
157  tokenEcalTPGOddWeightGroup_(esConsumes()),
158  tokenEcalTPGFineGrainStripEE_(esConsumes()),
159  tokenEcalTPGStripStatus_(esConsumes()),
160  tokenEcalTPGFineGrainEBGroup_(esConsumes()),
161  tokenEcalTPGLutGroup_(esConsumes()),
162  tokenEcalTPGLutIdMap_(esConsumes()),
163  tokenEcalTPGFineGrainEBIdMap_(esConsumes()),
164  tokenEcalTPGFineGrainTowerEE_(esConsumes()),
165  tokenEcalTPGTowerStatus_(esConsumes()),
166  tokenEcalTPGSpike_(esConsumes()),
167  tokenEcalTPGTPMode_(esConsumes()),
168  binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")),
169  fillBinOfMaximumFromHistory_(-1 == binOfMaximum_),
170  cacheID_(0) {
171  // register your products
172  produces<EcalTrigPrimDigiCollection>();
173  if (tcpFormat_)
174  produces<EcalTrigPrimDigiCollection>("formatTCP");
175  if (not barrelOnly_) {
176  tokenEndcapGeom_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalEndcap"));
177  tokenETTMap_ = esConsumes<edm::Transition::BeginRun>();
178  }
179 }
180 
181 static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory) {
182  // get binOfMax
183  // try first in cfg, then in ProcessHistory
184  // =6 is default (1-10 possible values)
185  int binOfMaximum = 0; // starts at 1!
186  if (not iFillFromHistory) {
187  binOfMaximum = iPSetValue;
188  edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum found in cfg file : " << binOfMaximum;
189  }
190 
191  // search backwards in history looking for the particular module
192  const std::string kModuleName{"ecalUnsuppressedDigis"};
193  for (auto it = iHistory.rbegin(), itEnd = iHistory.rend(); it != itEnd; ++it) {
194  auto const &topLevelPSet = getParameterSet(it->parameterSetID());
195  if (topLevelPSet.exists(kModuleName)) {
196  int psetBinOfMax = topLevelPSet.getParameter<edm::ParameterSet>(kModuleName).getParameter<int>("binOfMaximum");
197 
198  if (not iFillFromHistory) {
199  if (psetBinOfMax != binOfMaximum)
200  edm::LogWarning("EcalTPG") << "binofMaximum given in configuration (=" << binOfMaximum
201  << ") is different from the one found in ProductRegistration(=" << psetBinOfMax
202  << ")!!!";
203  } else {
204  binOfMaximum = psetBinOfMax;
205  edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum "
206  "found in ProductRegistry : "
207  << binOfMaximum;
208  }
209  break;
210  }
211  }
212  if (binOfMaximum == 0) {
213  binOfMaximum = 6;
214  edm::LogWarning("EcalTPG") << "Could not find product registry of EBDigiCollection (label "
215  "ecalUnsuppressedDigis), had to set the following parameters by "
216  "Hand: binOfMaximum="
217  << binOfMaximum;
218  }
219  return binOfMaximum;
220 }
221 
223  // ProcessHistory is guaranteed to be constant for an entire Run
225 
226  auto const &ecalmapping = setup.getData(tokenEcalMapping_);
227  if (barrelOnly_) {
228  algo_ = std::make_unique<EcalTrigPrimFunctionalAlgo>(
230  } else {
231  auto const &endcapGeometry = setup.getData(tokenEndcapGeom_);
232  auto const &eTTmap = setup.getData(tokenETTMap_);
233  algo_ = std::make_unique<EcalTrigPrimFunctionalAlgo>(
234  &eTTmap, &endcapGeometry, &ecalmapping, binOfMaximum_, tcpFormat_, debug_, famos_, tpInfoPrintout_);
235  }
236 }
237 
239  algo_.reset();
240  cacheID_ = 0;
241 }
242 
244  // get Eventsetup records
245 
246  // for EcalFenixStrip...
247  // get parameter records for xtals
248  const EcalTPGLinearizationConst *ecaltpLin = &setup.getData(tokenEcalTPGLinearization_);
249  const EcalTPGPedestals *ecaltpPed = &setup.getData(tokenEcalTPGPedestals_);
250  const EcalTPGCrystalStatus *ecaltpgBadX = &setup.getData(tokenEcalTPGCrystalStatus_);
251 
252  // for strips
253  const EcalTPGSlidingWindow *ecaltpgSlidW = &setup.getData(tokenEcalTPGSlidingWindow_);
254  const EcalTPGWeightIdMap *ecaltpgWeightMap = &setup.getData(tokenEcalTPGWeightIdMap_);
255  const EcalTPGWeightGroup *ecaltpgWeightGroup = &setup.getData(tokenEcalTPGWeightGroup_);
256  const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap = &setup.getData(tokenEcalTPGOddWeightIdMap_);
257  const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup = &setup.getData(tokenEcalTPGOddWeightGroup_);
258  const EcalTPGFineGrainStripEE *ecaltpgFgStripEE = &setup.getData(tokenEcalTPGFineGrainStripEE_);
259  const EcalTPGStripStatus *ecaltpgStripStatus = &setup.getData(tokenEcalTPGStripStatus_);
260  const EcalTPGTPMode *ecaltpgTPMode = &setup.getData(tokenEcalTPGTPMode_);
261 
262  algo_->setPointers(ecaltpLin,
263  ecaltpPed,
264  ecaltpgSlidW,
265  ecaltpgWeightMap,
266  ecaltpgWeightGroup,
267  ecaltpgOddWeightMap,
268  ecaltpgOddWeightGroup,
269  ecaltpgFgStripEE,
270  ecaltpgBadX,
271  ecaltpgStripStatus,
272  ecaltpgTPMode);
273 
274  // .. and for EcalFenixTcp
275  // get parameter records for towers
276  const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup = &setup.getData(tokenEcalTPGFineGrainEBGroup_);
277  const EcalTPGLutGroup *ecaltpgLutGroup = &setup.getData(tokenEcalTPGLutGroup_);
278  const EcalTPGLutIdMap *ecaltpgLut = &setup.getData(tokenEcalTPGLutIdMap_);
279  const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB = &setup.getData(tokenEcalTPGFineGrainEBIdMap_);
280  const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE = &setup.getData(tokenEcalTPGFineGrainTowerEE_);
281  const EcalTPGTowerStatus *ecaltpgBadTT = &setup.getData(tokenEcalTPGTowerStatus_);
282  const EcalTPGSpike *ecaltpgSpike = &setup.getData(tokenEcalTPGSpike_);
283 
284  algo_->setPointers2(ecaltpgFgEBGroup,
285  ecaltpgLutGroup,
286  ecaltpgLut,
287  ecaltpgFineGrainEB,
288  ecaltpgFineGrainTowerEE,
289  ecaltpgBadTT,
290  ecaltpgSpike,
291  ecaltpgTPMode);
292 
293  // we will suppose that everything is to be updated if the
294  // EcalTPGLinearizationConstRcd has changed
295  return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
296 }
297 
299 
300 // ------------ method called to produce the data ------------
302  // update constants if necessary
304  cacheID_ = this->getRecords(iSetup);
305 
306  // get input collections
307 
310  bool barrel = true;
311  bool endcap = true;
312  if (barrelOnly_)
313  endcap = false;
314 
315  if (!e.getByToken(tokenEB_, ebDigis)) {
316  barrel = false;
318  labelsForToken(tokenEB_, labels);
319  edm::LogWarning("EcalTPG") << " Couldnt find Barrel dataframes with producer " << labels.module << " and label "
320  << labels.productInstance << "!!!";
321  }
322  if (!barrelOnly_) {
323  if (!e.getByToken(tokenEE_, eeDigis)) {
324  endcap = false;
326  labelsForToken(tokenEE_, labels);
327  edm::LogWarning("EcalTPG") << " Couldnt find Endcap dataframes with producer " << labels.module << " and label "
328  << labels.productInstance << "!!!";
329  }
330  }
331  if (!barrel && !endcap) {
333  labelsForToken(tokenEB_, labels);
334  throw cms::Exception(" ProductNotFound") << "No EBDataFrames(EEDataFrames) with producer " << labels.module
335  << " and label " << labels.productInstance << " found in input!!\n";
336  }
337 
338  if (!barrelOnly_)
339  LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
340  << ebDigis.product()->size() << ", Number of EEDataFrames " << eeDigis.product()->size();
341  else
342  LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
343  << ebDigis.product()->size();
344 
345  auto pOut = std::make_unique<EcalTrigPrimDigiCollection>();
346  auto pOutTcp = std::make_unique<EcalTrigPrimDigiCollection>();
347 
348  // invoke algorithm
349 
350  const EBDigiCollection *ebdc = nullptr;
351  const EEDigiCollection *eedc = nullptr;
352  if (barrel) {
353  ebdc = ebDigis.product();
354  algo_->run(ebdc, *pOut, *pOutTcp);
355  }
356 
357  if (endcap) {
358  eedc = eeDigis.product();
359  algo_->run(eedc, *pOut, *pOutTcp);
360  }
361 
362  edm::LogInfo("produce") << "For Barrel + Endcap, " << pOut->size() << " TP Digis were produced";
363 
364  // debug prints if TP >0
365 
366  for (unsigned int i = 0; i < pOut->size(); ++i) {
367  bool print = false;
368  for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
369  if ((*pOut)[i][isam].raw())
370  print = true;
371  }
372  if (print)
373  LogDebug("EcalTPG") << " For tower " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i];
374  }
375  if (barrelOnly_)
376  LogDebug("EcalTPG") << "\n =================> For Barrel , " << pOut->size()
377  << " TP Digis were produced (including zero ones)";
378  else
379  LogDebug("EcalTPG") << "\n =================> For Barrel + Endcap, " << pOut->size()
380  << " TP Digis were produced (including zero ones)";
381 
382  // put result into the Event
383 
384  e.put(std::move(pOut));
385  if (tcpFormat_)
386  e.put(std::move(pOutTcp), "formatTCP");
387 }
388 
391  desc.add<bool>("BarrelOnly", false);
392  desc.add<bool>("TcpOutput", false);
393  desc.add<bool>("Debug", false);
394  desc.add<bool>("Famos", false);
395  desc.add<std::string>("Label", "simEcalUnsuppressedDigis");
396  desc.add<std::string>("InstanceEB", "");
397  desc.add<std::string>("InstanceEE", "");
398  const std::string kComment(
399  "A value of -1 will make the module lookup the value of 'binOfMaximum' "
400  "from the module 'ecalUnsuppressedDigis' from the process history. "
401  "Allowed values are -1 and from 1-10.");
402  // The code before the existence of fillDescriptions did something special if
403  // 'binOfMaximum' was missing. This replicates that behavior.
404  desc.add<int>("binOfMaximum", -1)->setComment(kComment);
405  desc.add<bool>("TPinfoPrintout", false);
406  descriptions.addDefault(desc);
407 }
408 
edm::ESGetToken< EcalTPGSlidingWindow, EcalTPGSlidingWindowRcd > tokenEcalTPGSlidingWindow_
edm::ESGetToken< EcalTPGFineGrainStripEE, EcalTPGFineGrainStripEERcd > tokenEcalTPGFineGrainStripEE_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< EcalTPGLutIdMap, EcalTPGLutIdMapRcd > tokenEcalTPGLutIdMap_
void endRun(const edm::Run &, const edm::EventSetup &) override
edm::ESGetToken< EcalTPGTowerStatus, EcalTPGTowerStatusRcd > tokenEcalTPGTowerStatus_
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory)
T const * product() const
Definition: Handle.h:70
edm::ESGetToken< EcalTPGFineGrainTowerEE, EcalTPGFineGrainTowerEERcd > tokenEcalTPGFineGrainTowerEE_
EcalTrigPrimProducer(const edm::ParameterSet &conf)
edm::ESGetToken< EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd > tokenEcalTPGCrystalStatus_
edm::ESGetToken< EcalTPGOddWeightGroup, EcalTPGOddWeightGroupRcd > tokenEcalTPGOddWeightGroup_
const_reverse_iterator rend() const
std::unique_ptr< EcalTrigPrimFunctionalAlgo > algo_
unsigned long long cacheIdentifier() const
void produce(edm::Event &e, const edm::EventSetup &c) override
unsigned long long cacheID_
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > tokenEcalMapping_
void addDefault(ParameterSetDescription const &psetDescription)
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > tokenETTMap_
edm::ESGetToken< EcalTPGWeightIdMap, EcalTPGWeightIdMapRcd > tokenEcalTPGWeightIdMap_
unsigned long long getRecords(edm::EventSetup const &setup)
static const char *const kComment
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
T get() const
Definition: EventSetup.h:79
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EBDigiCollection > tokenEB_
edm::ESGetToken< EcalTPGStripStatus, EcalTPGStripStatusRcd > tokenEcalTPGStripStatus_
edm::ESGetToken< EcalTPGLinearizationConst, EcalTPGLinearizationConstRcd > tokenEcalTPGLinearization_
edm::ESGetToken< EcalTPGPedestals, EcalTPGPedestalsRcd > tokenEcalTPGPedestals_
Log< level::Info, false > LogInfo
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESGetToken< EcalTPGTPMode, EcalTPGTPModeRcd > tokenEcalTPGTPMode_
edm::ESGetToken< EcalTPGFineGrainEBIdMap, EcalTPGFineGrainEBIdMapRcd > tokenEcalTPGFineGrainEBIdMap_
const_reverse_iterator rbegin() const
edm::ESGetToken< CaloSubdetectorGeometry, EcalEndcapGeometryRecord > tokenEndcapGeom_
ParameterSet const & getParameterSet(ParameterSetID const &id)
HLT enums.
edm::ESGetToken< EcalTPGOddWeightIdMap, EcalTPGOddWeightIdMapRcd > tokenEcalTPGOddWeightIdMap_
edm::EDGetTokenT< EEDigiCollection > tokenEE_
edm::ESGetToken< EcalTPGLutGroup, EcalTPGLutGroupRcd > tokenEcalTPGLutGroup_
edm::ESGetToken< EcalTPGSpike, EcalTPGSpikeRcd > tokenEcalTPGSpike_
Log< level::Warning, false > LogWarning
edm::ESGetToken< EcalTPGWeightGroup, EcalTPGWeightGroupRcd > tokenEcalTPGWeightGroup_
def move(src, dest)
Definition: eostools.py:511
edm::ESGetToken< EcalTPGFineGrainEBGroup, EcalTPGFineGrainEBGroupRcd > tokenEcalTPGFineGrainEBGroup_
static std::string topLevelPSet(std::string const &iName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:268
Definition: Run.h:45
#define LogDebug(id)