CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTrigPrimProducer.cc
Go to the documentation of this file.
1 
17 
22 
27 
58 
59 #include "EcalTrigPrimProducer.h"
61 
63  barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
64  tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
65  debug_(iConfig.getParameter<bool>("Debug")),
66  famos_(iConfig.getParameter<bool>("Famos")),
67  label_(iConfig.getParameter<std::string>("Label")),
68  instanceNameEB_(iConfig.getParameter<std::string>("InstanceEB")),
69  instanceNameEE_(iConfig.getParameter<std::string>("InstanceEE")),
70  binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")),
71  fillBinOfMaximumFromHistory_(-1==binOfMaximum_)
72 {
73  //register your products
74  produces <EcalTrigPrimDigiCollection >();
75  if (tcpFormat_) produces <EcalTrigPrimDigiCollection >("formatTCP");
76 }
77 
78 static
79 int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const& iHistory) {
80  // get binOfMax
81  // try first in cfg, then in ProcessHistory
82  // =6 is default (1-10 possible values)
83  int binOfMaximum=0; //starts at 1!
84  if(not iFillFromHistory) {
85  binOfMaximum=iPSetValue;
86  edm::LogInfo("EcalTPG") <<"EcalTrigPrimProducer is using binOfMaximum found in cfg file : "<<binOfMaximum;
87  }
88 
89  //search backwards in history looking for the particular module
90  const std::string kModuleName{ "ecalUnsuppressedDigis" };
91  for(auto it = iHistory.rbegin(), itEnd = iHistory.rend();
92  it != itEnd; ++it) {
93  auto const& topLevelPSet = getParameterSet(it->parameterSetID());
94  if(topLevelPSet.exists(kModuleName)) {
95  int psetBinOfMax = topLevelPSet.getParameter<edm::ParameterSet>(kModuleName).getParameter<int>("binOfMaximum");
96 
97  if (not iFillFromHistory ) {
98  if ( psetBinOfMax!=binOfMaximum)edm:: LogWarning("EcalTPG")<< "binofMaximum given in configuration (="<<binOfMaximum<<") is different from the one found in ProductRegistration(="<<psetBinOfMax<<")!!!";
99  }else {
100  binOfMaximum=psetBinOfMax;
101  edm::LogInfo("EcalTPG") <<"EcalTrigPrimProducer is using binOfMaximum found in ProductRegistry : "<<binOfMaximum;
102  }
103  break;
104  }
105  }
106  if (binOfMaximum==0) {
107  binOfMaximum=6;
108  edm::LogWarning("EcalTPG")<<"Could not find product registry of EBDigiCollection (label ecalUnsuppressedDigis), had to set the following parameters by Hand: binOfMaximum="<<binOfMaximum;
109  }
110  return binOfMaximum;
111 }
112 
113 
115  //ProcessHistory is guaranteed to be constant for an entire Run
117 
119 
120  // get a first version of the records
121  cacheID_=this->getRecords(setup);
122 }
123 
125  algo_.reset();
126 }
127 
129  // get Eventsetup records
130 
131  // for EcalFenixStrip...
132  // get parameter records for xtals
133  edm::ESHandle<EcalTPGLinearizationConst> theEcalTPGLinearization_handle;
134  setup.get<EcalTPGLinearizationConstRcd>().get(theEcalTPGLinearization_handle);
135  const EcalTPGLinearizationConst * ecaltpLin = theEcalTPGLinearization_handle.product();
136  edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle;
137  setup.get<EcalTPGPedestalsRcd>().get(theEcalTPGPedestals_handle);
138  const EcalTPGPedestals * ecaltpPed = theEcalTPGPedestals_handle.product();
139  edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle;
140  setup.get<EcalTPGCrystalStatusRcd>().get(theEcalTPGCrystalStatus_handle);
141  const EcalTPGCrystalStatus * ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
142 
143 
144  //for strips
145  edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle;
146  setup.get<EcalTPGSlidingWindowRcd>().get(theEcalTPGSlidingWindow_handle);
147  const EcalTPGSlidingWindow * ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
148  edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle;
149  setup.get<EcalTPGWeightIdMapRcd>().get(theEcalTPGWEightIdMap_handle);
150  const EcalTPGWeightIdMap * ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
151  edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle;
152  setup.get<EcalTPGWeightGroupRcd>().get(theEcalTPGWEightGroup_handle);
153  const EcalTPGWeightGroup * ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
154  edm::ESHandle<EcalTPGFineGrainStripEE> theEcalTPGFineGrainStripEE_handle;
155  setup.get<EcalTPGFineGrainStripEERcd>().get(theEcalTPGFineGrainStripEE_handle);
156  const EcalTPGFineGrainStripEE * ecaltpgFgStripEE = theEcalTPGFineGrainStripEE_handle.product();
157  edm::ESHandle<EcalTPGStripStatus> theEcalTPGStripStatus_handle;
158  setup.get<EcalTPGStripStatusRcd>().get(theEcalTPGStripStatus_handle);
159  const EcalTPGStripStatus * ecaltpgStripStatus = theEcalTPGStripStatus_handle.product();
160 
161  algo_->setPointers(ecaltpLin,ecaltpPed,ecaltpgSlidW,ecaltpgWeightMap,ecaltpgWeightGroup,ecaltpgFgStripEE,ecaltpgBadX,ecaltpgStripStatus);
162 
163  // .. and for EcalFenixTcp
164  // get parameter records for towers
165  edm::ESHandle<EcalTPGFineGrainEBGroup> theEcalTPGFineGrainEBGroup_handle;
166  setup.get<EcalTPGFineGrainEBGroupRcd>().get(theEcalTPGFineGrainEBGroup_handle);
167  const EcalTPGFineGrainEBGroup * ecaltpgFgEBGroup = theEcalTPGFineGrainEBGroup_handle.product();
168 
169  edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle;
170  setup.get<EcalTPGLutGroupRcd>().get(theEcalTPGLutGroup_handle);
171  const EcalTPGLutGroup * ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
172 
173  edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle;
174  setup.get<EcalTPGLutIdMapRcd>().get(theEcalTPGLutIdMap_handle);
175  const EcalTPGLutIdMap * ecaltpgLut = theEcalTPGLutIdMap_handle.product();
176 
177  edm::ESHandle<EcalTPGFineGrainEBIdMap> theEcalTPGFineGrainEBIdMap_handle;
178  setup.get<EcalTPGFineGrainEBIdMapRcd>().get(theEcalTPGFineGrainEBIdMap_handle);
179  const EcalTPGFineGrainEBIdMap * ecaltpgFineGrainEB = theEcalTPGFineGrainEBIdMap_handle.product();
180 
181  edm::ESHandle<EcalTPGFineGrainTowerEE> theEcalTPGFineGrainTowerEE_handle;
182  setup.get<EcalTPGFineGrainTowerEERcd>().get(theEcalTPGFineGrainTowerEE_handle);
183  const EcalTPGFineGrainTowerEE * ecaltpgFineGrainTowerEE = theEcalTPGFineGrainTowerEE_handle.product();
184 
185  edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle;
186  setup.get<EcalTPGTowerStatusRcd>().get(theEcalTPGTowerStatus_handle);
187  const EcalTPGTowerStatus * ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
188 
189  edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle;
190  setup.get<EcalTPGSpikeRcd>().get(theEcalTPGSpike_handle);
191  const EcalTPGSpike * ecaltpgSpike = theEcalTPGSpike_handle.product();
192 
193  algo_->setPointers2(ecaltpgFgEBGroup,ecaltpgLutGroup,ecaltpgLut,ecaltpgFineGrainEB,ecaltpgFineGrainTowerEE,ecaltpgBadTT,ecaltpgSpike);
194 
195  // we will suppose that everything is to be updated if the EcalTPGLinearizationConstRcd has changed
196  return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
197 }
198 
200 {}
201 
202 
203 // ------------ method called to produce the data ------------
204 void
206 {
207 
208  // update constants if necessary
210 
211  // get input collections
212 
215  bool barrel=true;
216  bool endcap=true;
217  if (barrelOnly_) endcap=false;
218 
219  if (!e.getByLabel(label_,instanceNameEB_,ebDigis)) {
220  barrel=false;
221  edm::LogWarning("EcalTPG") <<" Couldnt find Barrel dataframes with producer "<<label_<<" and label "<<instanceNameEB_<<"!!!";
222  }
223  if (!barrelOnly_) {
224  if (!e.getByLabel(label_,instanceNameEE_,eeDigis)) {
225  endcap=false;
226  edm::LogWarning("EcalTPG") <<" Couldnt find Endcap dataframes with producer "<<label_<<" and label "<<instanceNameEE_<<"!!!";
227  }
228  }
229  if (!barrel && !endcap) {
230  throw cms::Exception(" ProductNotFound") <<"No EBDataFrames(EEDataFrames) with producer "<<label_<<" and label "<<instanceNameEB_<<" found in input!!\n";
231  }
232 
233  if (!barrelOnly_) LogDebug("EcalTPG") <<" =================> Treating event "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size()<<", Number of EEDataFrames "<<eeDigis.product()->size() ;
234  else LogDebug("EcalTPG") <<" =================> Treating event "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size();
235 
236  std::auto_ptr<EcalTrigPrimDigiCollection> pOut(new EcalTrigPrimDigiCollection);
237  std::auto_ptr<EcalTrigPrimDigiCollection> pOutTcp(new EcalTrigPrimDigiCollection);
238 
239 
240  // invoke algorithm
241 
242  const EBDigiCollection *ebdc=NULL;
243  const EEDigiCollection *eedc=NULL;
244  if (barrel) {
245  ebdc=ebDigis.product();
246  algo_->run(iSetup,ebdc,*pOut,*pOutTcp);
247  }
248 
249  if (endcap) {
250  eedc=eeDigis.product();
251  algo_->run(iSetup,eedc,*pOut,*pOutTcp);
252  }
253 
254  edm::LogInfo("produce") <<"For Barrel + Endcap, "<<pOut->size()<<" TP Digis were produced";
255 
256  // debug prints if TP >0
257 
258  for (unsigned int i=0;i<pOut->size();++i) {
259  bool print=false;
260  for (int isam=0;isam<(*pOut)[i].size();++isam) {
261  if ((*pOut)[i][isam].raw()) print=true;
262  }
263  if (print) LogDebug("EcalTPG") <<" For tower "<<(((*pOut)[i])).id()<<", TP is "<<(*pOut)[i];
264  }
265  if (barrelOnly_) LogDebug("EcalTPG") <<"\n =================> For Barrel , "<<pOut->size()<<" TP Digis were produced (including zero ones)";
266  else LogDebug("EcalTPG") <<"\n =================> For Barrel + Endcap, "<<pOut->size()<<" TP Digis were produced (including zero ones)";
267 
268  // put result into the Event
269 
270  e.put(pOut);
271  if (tcpFormat_) e.put(pOutTcp,"formatTCP");
272 }
273 
274 void
276 
278  desc.add<bool>("BarrelOnly",false);
279  desc.add<bool>("TcpOutput",false);
280  desc.add<bool>("Debug",false);
281  desc.add<bool>("Famos",false);
282  desc.add<std::string>("Label","simEcalUnsuppressedDigis");
283  desc.add<std::string>("InstanceEB","");
284  desc.add<std::string>("InstanceEE","");
285  const std::string kComment("A value of -1 will make the module lookup the value of 'binOfMaximum' from the module 'ecalUnsuppressedDigis' from the process history. Allowed values are -1 and from 1-10.");
286  //The code before the existence of fillDescriptions did something special if 'binOfMaximum' was missing. This replicates that behavior.
287  desc.add<int>("binOfMaximum",-1)->setComment(kComment);
288  descriptions.addDefault(desc);
289 }
#define LogDebug(id)
const_reverse_iterator rbegin() const
unsigned long long cacheIdentifier() const
int i
Definition: DBlmapReader.cc:9
void endRun(const edm::Run &, const edm::EventSetup &) override
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
ParameterSet const & getParameterSet(ParameterSetID const &id)
#define NULL
Definition: scimark2.h:8
EcalTrigPrimProducer(const edm::ParameterSet &conf)
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
unsigned long long getRecords(edm::EventSetup const &setup)
static const char *const kComment
ProcessHistory const & processHistory() const
Definition: Run.cc:108
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
edm::EventID id() const
Definition: EventBase.h:56
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
static std::string topLevelPSet(std::string const &iName, edm::ParameterSet const &iProcessConfig, std::string const &iProcessName)
Definition: EdmProvDump.cc:304
Definition: Run.h:41