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 
23 
28 
59 
60 #include "EcalTrigPrimProducer.h"
62 
64  barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
65  tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
66  debug_(iConfig.getParameter<bool>("Debug")),
67  famos_(iConfig.getParameter<bool>("Famos")),
68  tokenEB_(consumes <EBDigiCollection>(edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEB")))),
69  tokenEE_(consumes <EEDigiCollection>(edm::InputTag(iConfig.getParameter<std::string>("Label"), 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.getByToken(tokenEB_,ebDigis)) {
220  barrel=false;
222  labelsForToken(tokenEB_, labels);
223  edm::LogWarning("EcalTPG") <<" Couldnt find Barrel dataframes with producer "<<labels.module<<" and label "<<labels.productInstance<<"!!!";
224  }
225  if (!barrelOnly_) {
226  if (!e.getByToken(tokenEE_,eeDigis)) {
227  endcap=false;
229  labelsForToken(tokenEE_, labels);
230  edm::LogWarning("EcalTPG") <<" Couldnt find Endcap dataframes with producer "<<labels.module<<" and label "<<labels.productInstance<<"!!!";
231  }
232  }
233  if (!barrel && !endcap) {
235  labelsForToken(tokenEB_, labels);
236  throw cms::Exception(" ProductNotFound") <<"No EBDataFrames(EEDataFrames) with producer "<<labels.module<<" and label "<<labels.productInstance<<" found in input!!\n";
237  }
238 
239  if (!barrelOnly_) LogDebug("EcalTPG") <<" =================> Treating event "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size()<<", Number of EEDataFrames "<<eeDigis.product()->size() ;
240  else LogDebug("EcalTPG") <<" =================> Treating event "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size();
241 
242  std::auto_ptr<EcalTrigPrimDigiCollection> pOut(new EcalTrigPrimDigiCollection);
243  std::auto_ptr<EcalTrigPrimDigiCollection> pOutTcp(new EcalTrigPrimDigiCollection);
244 
245 
246  // invoke algorithm
247 
248  const EBDigiCollection *ebdc=NULL;
249  const EEDigiCollection *eedc=NULL;
250  if (barrel) {
251  ebdc=ebDigis.product();
252  algo_->run(iSetup,ebdc,*pOut,*pOutTcp);
253  }
254 
255  if (endcap) {
256  eedc=eeDigis.product();
257  algo_->run(iSetup,eedc,*pOut,*pOutTcp);
258  }
259 
260  edm::LogInfo("produce") <<"For Barrel + Endcap, "<<pOut->size()<<" TP Digis were produced";
261 
262  // debug prints if TP >0
263 
264  for (unsigned int i=0;i<pOut->size();++i) {
265  bool print=false;
266  for (int isam=0;isam<(*pOut)[i].size();++isam) {
267  if ((*pOut)[i][isam].raw()) print=true;
268  }
269  if (print) LogDebug("EcalTPG") <<" For tower "<<(((*pOut)[i])).id()<<", TP is "<<(*pOut)[i];
270  }
271  if (barrelOnly_) LogDebug("EcalTPG") <<"\n =================> For Barrel , "<<pOut->size()<<" TP Digis were produced (including zero ones)";
272  else LogDebug("EcalTPG") <<"\n =================> For Barrel + Endcap, "<<pOut->size()<<" TP Digis were produced (including zero ones)";
273 
274  // put result into the Event
275 
276  e.put(pOut);
277  if (tcpFormat_) e.put(pOutTcp,"formatTCP");
278 }
279 
280 void
282 
284  desc.add<bool>("BarrelOnly",false);
285  desc.add<bool>("TcpOutput",false);
286  desc.add<bool>("Debug",false);
287  desc.add<bool>("Famos",false);
288  desc.add<std::string>("Label","simEcalUnsuppressedDigis");
289  desc.add<std::string>("InstanceEB","");
290  desc.add<std::string>("InstanceEE","");
291  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.");
292  //The code before the existence of fillDescriptions did something special if 'binOfMaximum' was missing. This replicates that behavior.
293  desc.add<int>("binOfMaximum",-1)->setComment(kComment);
294  descriptions.addDefault(desc);
295 }
#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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
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:10
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:120
unsigned long long getRecords(edm::EventSetup const &setup)
static const char *const kComment
ProcessHistory const & processHistory() const
Definition: Run.cc:103
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:81
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
edm::EventID id() const
Definition: EventBase.h:60
char const * productInstance
Definition: ProductLabels.h:6
edm::EDGetTokenT< EEDigiCollection > tokenEE_
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:303
Definition: Run.h:43