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"), iConfig.getParameter<std::string>("InstanceEB")))),
71  tokenEE_(consumes<EEDigiCollection>(
72  edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEE")))),
73  binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")),
74  fillBinOfMaximumFromHistory_(-1 == binOfMaximum_) {
75  // register your products
76  produces<EcalTrigPrimDigiCollection>();
77  if (tcpFormat_)
78  produces<EcalTrigPrimDigiCollection>("formatTCP");
79 }
80 
81 static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory) {
82  // get binOfMax
83  // try first in cfg, then in ProcessHistory
84  // =6 is default (1-10 possible values)
85  int binOfMaximum = 0; // starts at 1!
86  if (not iFillFromHistory) {
87  binOfMaximum = iPSetValue;
88  edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum found in cfg file : " << binOfMaximum;
89  }
90 
91  // search backwards in history looking for the particular module
92  const std::string kModuleName{"ecalUnsuppressedDigis"};
93  for (auto it = iHistory.rbegin(), itEnd = iHistory.rend(); it != itEnd; ++it) {
94  auto const &topLevelPSet = getParameterSet(it->parameterSetID());
95  if (topLevelPSet.exists(kModuleName)) {
96  int psetBinOfMax = topLevelPSet.getParameter<edm::ParameterSet>(kModuleName).getParameter<int>("binOfMaximum");
97 
98  if (not iFillFromHistory) {
99  if (psetBinOfMax != binOfMaximum)
100  edm::LogWarning("EcalTPG") << "binofMaximum given in configuration (=" << binOfMaximum
101  << ") is different from the one found in ProductRegistration(=" << psetBinOfMax
102  << ")!!!";
103  } else {
104  binOfMaximum = psetBinOfMax;
105  edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum "
106  "found in ProductRegistry : "
107  << binOfMaximum;
108  }
109  break;
110  }
111  }
112  if (binOfMaximum == 0) {
113  binOfMaximum = 6;
114  edm::LogWarning("EcalTPG") << "Could not find product registry of EBDigiCollection (label "
115  "ecalUnsuppressedDigis), had to set the following parameters by "
116  "Hand: binOfMaximum="
117  << binOfMaximum;
118  }
119  return binOfMaximum;
120 }
121 
123  // ProcessHistory is guaranteed to be constant for an entire Run
125 
127 
128  // get a first version of the records
129  cacheID_ = this->getRecords(setup);
130 }
131 
133 
135  // get Eventsetup records
136 
137  // for EcalFenixStrip...
138  // get parameter records for xtals
139  edm::ESHandle<EcalTPGLinearizationConst> theEcalTPGLinearization_handle;
140  setup.get<EcalTPGLinearizationConstRcd>().get(theEcalTPGLinearization_handle);
141  const EcalTPGLinearizationConst *ecaltpLin = theEcalTPGLinearization_handle.product();
142  edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle;
143  setup.get<EcalTPGPedestalsRcd>().get(theEcalTPGPedestals_handle);
144  const EcalTPGPedestals *ecaltpPed = theEcalTPGPedestals_handle.product();
145  edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle;
146  setup.get<EcalTPGCrystalStatusRcd>().get(theEcalTPGCrystalStatus_handle);
147  const EcalTPGCrystalStatus *ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
148 
149  // for strips
150  edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle;
151  setup.get<EcalTPGSlidingWindowRcd>().get(theEcalTPGSlidingWindow_handle);
152  const EcalTPGSlidingWindow *ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
153  edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle;
154  setup.get<EcalTPGWeightIdMapRcd>().get(theEcalTPGWEightIdMap_handle);
155  const EcalTPGWeightIdMap *ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
156  edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle;
157  setup.get<EcalTPGWeightGroupRcd>().get(theEcalTPGWEightGroup_handle);
158  const EcalTPGWeightGroup *ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
159  edm::ESHandle<EcalTPGFineGrainStripEE> theEcalTPGFineGrainStripEE_handle;
160  setup.get<EcalTPGFineGrainStripEERcd>().get(theEcalTPGFineGrainStripEE_handle);
161  const EcalTPGFineGrainStripEE *ecaltpgFgStripEE = theEcalTPGFineGrainStripEE_handle.product();
162  edm::ESHandle<EcalTPGStripStatus> theEcalTPGStripStatus_handle;
163  setup.get<EcalTPGStripStatusRcd>().get(theEcalTPGStripStatus_handle);
164  const EcalTPGStripStatus *ecaltpgStripStatus = theEcalTPGStripStatus_handle.product();
165 
166  algo_->setPointers(ecaltpLin,
167  ecaltpPed,
168  ecaltpgSlidW,
169  ecaltpgWeightMap,
170  ecaltpgWeightGroup,
171  ecaltpgFgStripEE,
172  ecaltpgBadX,
173  ecaltpgStripStatus);
174 
175  // .. and for EcalFenixTcp
176  // get parameter records for towers
177  edm::ESHandle<EcalTPGFineGrainEBGroup> theEcalTPGFineGrainEBGroup_handle;
178  setup.get<EcalTPGFineGrainEBGroupRcd>().get(theEcalTPGFineGrainEBGroup_handle);
179  const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup = theEcalTPGFineGrainEBGroup_handle.product();
180 
181  edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle;
182  setup.get<EcalTPGLutGroupRcd>().get(theEcalTPGLutGroup_handle);
183  const EcalTPGLutGroup *ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
184 
185  edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle;
186  setup.get<EcalTPGLutIdMapRcd>().get(theEcalTPGLutIdMap_handle);
187  const EcalTPGLutIdMap *ecaltpgLut = theEcalTPGLutIdMap_handle.product();
188 
189  edm::ESHandle<EcalTPGFineGrainEBIdMap> theEcalTPGFineGrainEBIdMap_handle;
190  setup.get<EcalTPGFineGrainEBIdMapRcd>().get(theEcalTPGFineGrainEBIdMap_handle);
191  const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB = theEcalTPGFineGrainEBIdMap_handle.product();
192 
193  edm::ESHandle<EcalTPGFineGrainTowerEE> theEcalTPGFineGrainTowerEE_handle;
194  setup.get<EcalTPGFineGrainTowerEERcd>().get(theEcalTPGFineGrainTowerEE_handle);
195  const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE = theEcalTPGFineGrainTowerEE_handle.product();
196 
197  edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle;
198  setup.get<EcalTPGTowerStatusRcd>().get(theEcalTPGTowerStatus_handle);
199  const EcalTPGTowerStatus *ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
200 
201  edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle;
202  setup.get<EcalTPGSpikeRcd>().get(theEcalTPGSpike_handle);
203  const EcalTPGSpike *ecaltpgSpike = theEcalTPGSpike_handle.product();
204 
205  algo_->setPointers2(ecaltpgFgEBGroup,
206  ecaltpgLutGroup,
207  ecaltpgLut,
208  ecaltpgFineGrainEB,
209  ecaltpgFineGrainTowerEE,
210  ecaltpgBadTT,
211  ecaltpgSpike);
212 
213  // we will suppose that everything is to be updated if the
214  // EcalTPGLinearizationConstRcd has changed
215  return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
216 }
217 
219 
220 // ------------ method called to produce the data ------------
222  // update constants if necessary
224  cacheID_ = this->getRecords(iSetup);
225 
226  // get input collections
227 
230  bool barrel = true;
231  bool endcap = true;
232  if (barrelOnly_)
233  endcap = false;
234 
235  if (!e.getByToken(tokenEB_, ebDigis)) {
236  barrel = false;
238  labelsForToken(tokenEB_, labels);
239  edm::LogWarning("EcalTPG") << " Couldnt find Barrel dataframes with producer " << labels.module << " and label "
240  << labels.productInstance << "!!!";
241  }
242  if (!barrelOnly_) {
243  if (!e.getByToken(tokenEE_, eeDigis)) {
244  endcap = false;
246  labelsForToken(tokenEE_, labels);
247  edm::LogWarning("EcalTPG") << " Couldnt find Endcap dataframes with producer " << labels.module << " and label "
248  << labels.productInstance << "!!!";
249  }
250  }
251  if (!barrel && !endcap) {
253  labelsForToken(tokenEB_, labels);
254  throw cms::Exception(" ProductNotFound") << "No EBDataFrames(EEDataFrames) with producer " << labels.module
255  << " and label " << labels.productInstance << " found in input!!\n";
256  }
257 
258  if (!barrelOnly_)
259  LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
260  << ebDigis.product()->size() << ", Number of EEDataFrames " << eeDigis.product()->size();
261  else
262  LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
263  << ebDigis.product()->size();
264 
265  auto pOut = std::make_unique<EcalTrigPrimDigiCollection>();
266  auto pOutTcp = std::make_unique<EcalTrigPrimDigiCollection>();
267 
268  // invoke algorithm
269 
270  const EBDigiCollection *ebdc = nullptr;
271  const EEDigiCollection *eedc = nullptr;
272  if (barrel) {
273  ebdc = ebDigis.product();
274  algo_->run(iSetup, ebdc, *pOut, *pOutTcp);
275  }
276 
277  if (endcap) {
278  eedc = eeDigis.product();
279  algo_->run(iSetup, eedc, *pOut, *pOutTcp);
280  }
281 
282  edm::LogInfo("produce") << "For Barrel + Endcap, " << pOut->size() << " TP Digis were produced";
283 
284  // debug prints if TP >0
285 
286  for (unsigned int i = 0; i < pOut->size(); ++i) {
287  bool print = false;
288  for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
289  if ((*pOut)[i][isam].raw())
290  print = true;
291  }
292  if (print)
293  LogDebug("EcalTPG") << " For tower " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i];
294  }
295  if (barrelOnly_)
296  LogDebug("EcalTPG") << "\n =================> For Barrel , " << pOut->size()
297  << " TP Digis were produced (including zero ones)";
298  else
299  LogDebug("EcalTPG") << "\n =================> For Barrel + Endcap, " << pOut->size()
300  << " TP Digis were produced (including zero ones)";
301 
302  // put result into the Event
303 
304  e.put(std::move(pOut));
305  if (tcpFormat_)
306  e.put(std::move(pOutTcp), "formatTCP");
307 }
308 
311  desc.add<bool>("BarrelOnly", false);
312  desc.add<bool>("TcpOutput", false);
313  desc.add<bool>("Debug", false);
314  desc.add<bool>("Famos", false);
315  desc.add<std::string>("Label", "simEcalUnsuppressedDigis");
316  desc.add<std::string>("InstanceEB", "");
317  desc.add<std::string>("InstanceEE", "");
318  const std::string kComment(
319  "A value of -1 will make the module lookup the value of 'binOfMaximum' "
320  "from the module 'ecalUnsuppressedDigis' from the process history. "
321  "Allowed values are -1 and from 1-10.");
322  // The code before the existence of fillDescriptions did something special if
323  // 'binOfMaximum' was missing. This replicates that behavior.
324  desc.add<int>("binOfMaximum", -1)->setComment(kComment);
325  descriptions.addDefault(desc);
326 }
#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:131
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:525
static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory)
ParameterSet const & getParameterSet(ParameterSetID const &id)
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:69
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:73
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