CMS 3D CMS Logo

EcalTrigPrimProducer.cc
Go to the documentation of this file.
1 
18 
24 
29 
60 
61 #include "EcalTrigPrimProducer.h"
63 
65  : barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
66  tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
67  debug_(iConfig.getParameter<bool>("Debug")),
68  famos_(iConfig.getParameter<bool>("Famos")),
69  tokenEB_(consumes<EBDigiCollection>(
70  edm::InputTag(iConfig.getParameter<std::string>("Label"),
71  iConfig.getParameter<std::string>("InstanceEB")))),
72  tokenEE_(consumes<EEDigiCollection>(
73  edm::InputTag(iConfig.getParameter<std::string>("Label"),
74  iConfig.getParameter<std::string>("InstanceEE")))),
75  binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")),
76  fillBinOfMaximumFromHistory_(-1 == binOfMaximum_) {
77  // register your products
78  produces<EcalTrigPrimDigiCollection>();
79  if (tcpFormat_)
80  produces<EcalTrigPrimDigiCollection>("formatTCP");
81 }
82 
83 static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue,
84  edm::ProcessHistory const &iHistory) {
85  // get binOfMax
86  // try first in cfg, then in ProcessHistory
87  // =6 is default (1-10 possible values)
88  int binOfMaximum = 0; // starts at 1!
89  if (not iFillFromHistory) {
90  binOfMaximum = iPSetValue;
91  edm::LogInfo("EcalTPG")
92  << "EcalTrigPrimProducer is using binOfMaximum found in cfg file : "
93  << binOfMaximum;
94  }
95 
96  // search backwards in history looking for the particular module
97  const std::string kModuleName{"ecalUnsuppressedDigis"};
98  for (auto it = iHistory.rbegin(), itEnd = iHistory.rend(); it != itEnd;
99  ++it) {
100  auto const &topLevelPSet = getParameterSet(it->parameterSetID());
101  if (topLevelPSet.exists(kModuleName)) {
102  int psetBinOfMax =
103  topLevelPSet.getParameter<edm::ParameterSet>(kModuleName)
104  .getParameter<int>("binOfMaximum");
105 
106  if (not iFillFromHistory) {
107  if (psetBinOfMax != binOfMaximum)
108  edm::LogWarning("EcalTPG")
109  << "binofMaximum given in configuration (=" << binOfMaximum
110  << ") is different from the one found in ProductRegistration(="
111  << psetBinOfMax << ")!!!";
112  } else {
113  binOfMaximum = psetBinOfMax;
114  edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum "
115  "found in ProductRegistry : "
116  << binOfMaximum;
117  }
118  break;
119  }
120  }
121  if (binOfMaximum == 0) {
122  binOfMaximum = 6;
123  edm::LogWarning("EcalTPG")
124  << "Could not find product registry of EBDigiCollection (label "
125  "ecalUnsuppressedDigis), had to set the following parameters by "
126  "Hand: binOfMaximum="
127  << binOfMaximum;
128  }
129  return binOfMaximum;
130 }
131 
133  edm::EventSetup const &setup) {
134  // ProcessHistory is guaranteed to be constant for an entire Run
136  run.processHistory());
137 
140 
141  // get a first version of the records
142  cacheID_ = this->getRecords(setup);
143 }
144 
146  edm::EventSetup const &setup) {
147  algo_.reset();
148 }
149 
150 unsigned long long
152  // get Eventsetup records
153 
154  // for EcalFenixStrip...
155  // get parameter records for xtals
156  edm::ESHandle<EcalTPGLinearizationConst> theEcalTPGLinearization_handle;
157  setup.get<EcalTPGLinearizationConstRcd>().get(theEcalTPGLinearization_handle);
158  const EcalTPGLinearizationConst *ecaltpLin =
159  theEcalTPGLinearization_handle.product();
160  edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle;
161  setup.get<EcalTPGPedestalsRcd>().get(theEcalTPGPedestals_handle);
162  const EcalTPGPedestals *ecaltpPed = theEcalTPGPedestals_handle.product();
163  edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle;
164  setup.get<EcalTPGCrystalStatusRcd>().get(theEcalTPGCrystalStatus_handle);
165  const EcalTPGCrystalStatus *ecaltpgBadX =
166  theEcalTPGCrystalStatus_handle.product();
167 
168  // for strips
169  edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle;
170  setup.get<EcalTPGSlidingWindowRcd>().get(theEcalTPGSlidingWindow_handle);
171  const EcalTPGSlidingWindow *ecaltpgSlidW =
172  theEcalTPGSlidingWindow_handle.product();
173  edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle;
174  setup.get<EcalTPGWeightIdMapRcd>().get(theEcalTPGWEightIdMap_handle);
175  const EcalTPGWeightIdMap *ecaltpgWeightMap =
176  theEcalTPGWEightIdMap_handle.product();
177  edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle;
178  setup.get<EcalTPGWeightGroupRcd>().get(theEcalTPGWEightGroup_handle);
179  const EcalTPGWeightGroup *ecaltpgWeightGroup =
180  theEcalTPGWEightGroup_handle.product();
181  edm::ESHandle<EcalTPGFineGrainStripEE> theEcalTPGFineGrainStripEE_handle;
182  setup.get<EcalTPGFineGrainStripEERcd>().get(
183  theEcalTPGFineGrainStripEE_handle);
184  const EcalTPGFineGrainStripEE *ecaltpgFgStripEE =
185  theEcalTPGFineGrainStripEE_handle.product();
186  edm::ESHandle<EcalTPGStripStatus> theEcalTPGStripStatus_handle;
187  setup.get<EcalTPGStripStatusRcd>().get(theEcalTPGStripStatus_handle);
188  const EcalTPGStripStatus *ecaltpgStripStatus =
189  theEcalTPGStripStatus_handle.product();
190 
191  algo_->setPointers(ecaltpLin, ecaltpPed, ecaltpgSlidW, ecaltpgWeightMap,
192  ecaltpgWeightGroup, ecaltpgFgStripEE, ecaltpgBadX,
193  ecaltpgStripStatus);
194 
195  // .. and for EcalFenixTcp
196  // get parameter records for towers
197  edm::ESHandle<EcalTPGFineGrainEBGroup> theEcalTPGFineGrainEBGroup_handle;
198  setup.get<EcalTPGFineGrainEBGroupRcd>().get(
199  theEcalTPGFineGrainEBGroup_handle);
200  const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup =
201  theEcalTPGFineGrainEBGroup_handle.product();
202 
203  edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle;
204  setup.get<EcalTPGLutGroupRcd>().get(theEcalTPGLutGroup_handle);
205  const EcalTPGLutGroup *ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
206 
207  edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle;
208  setup.get<EcalTPGLutIdMapRcd>().get(theEcalTPGLutIdMap_handle);
209  const EcalTPGLutIdMap *ecaltpgLut = theEcalTPGLutIdMap_handle.product();
210 
211  edm::ESHandle<EcalTPGFineGrainEBIdMap> theEcalTPGFineGrainEBIdMap_handle;
212  setup.get<EcalTPGFineGrainEBIdMapRcd>().get(
213  theEcalTPGFineGrainEBIdMap_handle);
214  const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB =
215  theEcalTPGFineGrainEBIdMap_handle.product();
216 
217  edm::ESHandle<EcalTPGFineGrainTowerEE> theEcalTPGFineGrainTowerEE_handle;
218  setup.get<EcalTPGFineGrainTowerEERcd>().get(
219  theEcalTPGFineGrainTowerEE_handle);
220  const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE =
221  theEcalTPGFineGrainTowerEE_handle.product();
222 
223  edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle;
224  setup.get<EcalTPGTowerStatusRcd>().get(theEcalTPGTowerStatus_handle);
225  const EcalTPGTowerStatus *ecaltpgBadTT =
226  theEcalTPGTowerStatus_handle.product();
227 
228  edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle;
229  setup.get<EcalTPGSpikeRcd>().get(theEcalTPGSpike_handle);
230  const EcalTPGSpike *ecaltpgSpike = theEcalTPGSpike_handle.product();
231 
232  algo_->setPointers2(ecaltpgFgEBGroup, ecaltpgLutGroup, ecaltpgLut,
233  ecaltpgFineGrainEB, ecaltpgFineGrainTowerEE, ecaltpgBadTT,
234  ecaltpgSpike);
235 
236  // we will suppose that everything is to be updated if the
237  // EcalTPGLinearizationConstRcd has changed
238  return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
239 }
240 
242 
243 // ------------ method called to produce the data ------------
245  const edm::EventSetup &iSetup) {
246 
247  // update constants if necessary
249  cacheID_ = this->getRecords(iSetup);
250 
251  // get input collections
252 
255  bool barrel = true;
256  bool endcap = true;
257  if (barrelOnly_)
258  endcap = false;
259 
260  if (!e.getByToken(tokenEB_, ebDigis)) {
261  barrel = false;
263  labelsForToken(tokenEB_, labels);
264  edm::LogWarning("EcalTPG")
265  << " Couldnt find Barrel dataframes with producer " << labels.module
266  << " and label " << labels.productInstance << "!!!";
267  }
268  if (!barrelOnly_) {
269  if (!e.getByToken(tokenEE_, eeDigis)) {
270  endcap = false;
272  labelsForToken(tokenEE_, labels);
273  edm::LogWarning("EcalTPG")
274  << " Couldnt find Endcap dataframes with producer " << labels.module
275  << " and label " << labels.productInstance << "!!!";
276  }
277  }
278  if (!barrel && !endcap) {
280  labelsForToken(tokenEB_, labels);
281  throw cms::Exception(" ProductNotFound")
282  << "No EBDataFrames(EEDataFrames) with producer " << labels.module
283  << " and label " << labels.productInstance << " found in input!!\n";
284  }
285 
286  if (!barrelOnly_)
287  LogDebug("EcalTPG") << " =================> Treating event " << e.id()
288  << ", Number of EBDataFrames "
289  << ebDigis.product()->size()
290  << ", Number of EEDataFrames "
291  << eeDigis.product()->size();
292  else
293  LogDebug("EcalTPG") << " =================> Treating event " << e.id()
294  << ", Number of EBDataFrames "
295  << ebDigis.product()->size();
296 
297  auto pOut = std::make_unique<EcalTrigPrimDigiCollection>();
298  auto pOutTcp = std::make_unique<EcalTrigPrimDigiCollection>();
299 
300  // invoke algorithm
301 
302  const EBDigiCollection *ebdc = nullptr;
303  const EEDigiCollection *eedc = nullptr;
304  if (barrel) {
305  ebdc = ebDigis.product();
306  algo_->run(iSetup, ebdc, *pOut, *pOutTcp);
307  }
308 
309  if (endcap) {
310  eedc = eeDigis.product();
311  algo_->run(iSetup, eedc, *pOut, *pOutTcp);
312  }
313 
314  edm::LogInfo("produce") << "For Barrel + Endcap, " << pOut->size()
315  << " TP Digis were produced";
316 
317  // debug prints if TP >0
318 
319  for (unsigned int i = 0; i < pOut->size(); ++i) {
320  bool print = false;
321  for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
322  if ((*pOut)[i][isam].raw())
323  print = true;
324  }
325  if (print)
326  LogDebug("EcalTPG") << " For tower " << (((*pOut)[i])).id() << ", TP is "
327  << (*pOut)[i];
328  }
329  if (barrelOnly_)
330  LogDebug("EcalTPG") << "\n =================> For Barrel , " << pOut->size()
331  << " TP Digis were produced (including zero ones)";
332  else
333  LogDebug("EcalTPG") << "\n =================> For Barrel + Endcap, "
334  << pOut->size()
335  << " TP Digis were produced (including zero ones)";
336 
337  // put result into the Event
338 
339  e.put(std::move(pOut));
340  if (tcpFormat_)
341  e.put(std::move(pOutTcp), "formatTCP");
342 }
343 
345  edm::ConfigurationDescriptions &descriptions) {
346 
348  desc.add<bool>("BarrelOnly", false);
349  desc.add<bool>("TcpOutput", false);
350  desc.add<bool>("Debug", false);
351  desc.add<bool>("Famos", false);
352  desc.add<std::string>("Label", "simEcalUnsuppressedDigis");
353  desc.add<std::string>("InstanceEB", "");
354  desc.add<std::string>("InstanceEE", "");
355  const std::string kComment(
356  "A value of -1 will make the module lookup the value of 'binOfMaximum' "
357  "from the module 'ecalUnsuppressedDigis' from the process history. "
358  "Allowed values are -1 and from 1-10.");
359  // The code before the existence of fillDescriptions did something special if
360  // 'binOfMaximum' was missing. This replicates that behavior.
361  desc.add<int>("binOfMaximum", -1)->setComment(kComment);
362  descriptions.addDefault(desc);
363 }
#define LogDebug(id)
const_reverse_iterator rbegin() const
unsigned long long cacheIdentifier() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void endRun(const edm::Run &, const edm::EventSetup &) override
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory)
ParameterSet const & getParameterSet(ParameterSetID const &id)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
EcalTrigPrimProducer(const edm::ParameterSet &conf)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
std::unique_ptr< EcalTrigPrimFunctionalAlgo > algo_
void produce(edm::Event &e, const edm::EventSetup &c) override
unsigned long long cacheID_
void addDefault(ParameterSetDescription const &psetDescription)
const_reverse_iterator rend() const
unsigned long long getRecords(edm::EventSetup const &setup)
static const char *const kComment
ProcessHistory const & processHistory() const
Definition: Run.cc:106
ParameterDescriptionBase * add(U const &iLabel, T const &value)
char const * module
Definition: ProductLabels.h:5
edm::EDGetTokenT< EBDigiCollection > tokenEB_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:59
char const * productInstance
Definition: ProductLabels.h:6
HLT enums.
edm::EDGetTokenT< EEDigiCollection > tokenEE_
T get() const
Definition: EventSetup.h:71
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
static std::string topLevelPSet(std::string const &iName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:266
Definition: Run.h:45