CMS 3D CMS Logo

EcalTrivialObjectAnalyzer.cc
Go to the documentation of this file.
1 //
2 // Created: 2 Mar 2006
3 // Shahram Rahatlou, University of Rome & INFN
4 //
6 
7 #include <stdexcept>
8 #include <string>
9 #include <iostream>
10 #include <iomanip>
11 #include <map>
12 #include <vector>
15 
17 
20 
24 
28 
31 
34 
37 
40 
43 
47 
50 
53 
56 
59 
70 
73 
76 
77 #include "CLHEP/Matrix/Matrix.h"
78 
79 using namespace std;
80 
82  using namespace edm::eventsetup;
83  // Context is not used.
84  edm::LogInfo(">>> EcalTrivialObjectAnalyzer: processing run ") << e.id().run() << " event: " << e.id().event();
85 
87  context.get<EcalPedestalsRcd>().get(pPeds);
88 
89  // ADC -> GeV Scale
91  context.get<EcalADCToGeVConstantRcd>().get(pAgc);
92  const EcalADCToGeVConstant* agc = pAgc.product();
93  edm::LogInfo("Global ADC->GeV scale: EB ") << std::setprecision(6) << agc->getEBValue()
94  << " GeV/ADC count"
95  " EE "
96  << std::setprecision(6) << agc->getEEValue() << " GeV/ADC count";
97 
98  // use a channel to fetch values from DB
99  double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
100  int ieta = int(1 + r1 * 85);
101  r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
102  int iphi = int(1 + r1 * 20);
103 
104  EBDetId ebid(ieta, iphi); //eta,phi
105  edm::LogInfo("EcalTrivialObjectAnalyzer: using EBDetId: ") << ebid;
106 
107  const EcalPedestals* myped = pPeds.product();
108  EcalPedestals::const_iterator it = myped->find(ebid.rawId());
109  if (it != myped->end()) {
110  edm::LogInfo("EcalPedestal: ") << " mean_x1: " << std::setprecision(8) << (*it).mean_x1
111  << " rms_x1: " << (*it).rms_x1 << " mean_x6: " << (*it).mean_x6
112  << " rms_x6: " << (*it).rms_x6 << " mean_x12: " << (*it).mean_x12
113  << " rms_x12: " << (*it).rms_x12;
114  } else {
115  edm::LogInfo("No pedestal found for this xtal! something wrong with EcalPedestals in your DB? ");
116  }
117 
118  // fetch map of groups of xtals
120  context.get<EcalWeightXtalGroupsRcd>().get(pGrp);
121  const EcalWeightXtalGroups* grp = pGrp.product();
122 
123  EcalXtalGroupsMap::const_iterator git = grp->getMap().find(ebid.rawId());
124  EcalXtalGroupId gid;
125  if (git != grp->getMap().end()) {
126  edm::LogInfo("XtalGroupId.id() = ") << std::setprecision(3) << (*git).id();
127  gid = (*git);
128  } else {
129  edm::LogInfo("No group id found for this crystal. something wrong with EcalWeightXtalGroups in your DB?");
130  }
131 
132  // Gain Ratios
134  context.get<EcalGainRatiosRcd>().get(pRatio);
135  const EcalGainRatios* gr = pRatio.product();
136 
137  EcalGainRatioMap::const_iterator grit = gr->getMap().find(ebid.rawId());
138  EcalMGPAGainRatio mgpa;
139  if (grit != gr->getMap().end()) {
140  mgpa = (*grit);
141 
142  edm::LogInfo("EcalMGPAGainRatio: ") << "gain 12/6 : " << std::setprecision(4) << mgpa.gain12Over6()
143  << " gain 6/1: " << mgpa.gain6Over1();
144  } else {
145  edm::LogInfo("No MGPA Gain Ratio found for this xtal! something wrong with EcalGainRatios in your DB? ");
146  }
147 
148  // Intercalib constants
150  context.get<EcalIntercalibConstantsRcd>().get(pIcal);
151  const EcalIntercalibConstants* ical = pIcal.product();
152 
154  EcalIntercalibConstant icalconst;
155  if (icalit != ical->getMap().end()) {
156  icalconst = (*icalit);
157 
158  edm::LogInfo("EcalIntercalibConstant: ") << std::setprecision(6) << icalconst;
159  } else {
160  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalIntercalibConstants in your DB? ");
161  }
162 
163  // Intercalib errors
165  context.get<EcalIntercalibErrorsRcd>().get(pIcalErr);
166  const EcalIntercalibErrors* icalErr = pIcalErr.product();
167 
168  EcalIntercalibErrorMap::const_iterator icalitErr = icalErr->getMap().find(ebid.rawId());
169  EcalIntercalibError icalconstErr;
170  if (icalitErr != icalErr->getMap().end()) {
171  icalconstErr = (*icalitErr);
172 
173  edm::LogInfo("EcalIntercalibError: ") << std::setprecision(6) << icalconstErr;
174  } else {
175  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalIntercalibErrors in your DB? ");
176  }
177 
178  { // quick and dirty for cut and paste ;) it is a test program...
179  // TimeCalib constants
181  context.get<EcalTimeCalibConstantsRcd>().get(pIcal);
182  const EcalTimeCalibConstants* ical = pIcal.product();
183 
185  EcalTimeCalibConstant icalconst;
186  if (icalit != ical->getMap().end()) {
187  icalconst = (*icalit);
188 
189  edm::LogInfo("EcalTimeCalibConstant: ") << std::setprecision(6) << icalconst;
190  } else {
191  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalTimeCalibConstants in your DB? ");
192  }
193 
194  // TimeCalib errors
196  context.get<EcalTimeCalibErrorsRcd>().get(pIcalErr);
197  const EcalTimeCalibErrors* icalErr = pIcalErr.product();
198 
199  EcalTimeCalibErrorMap::const_iterator icalitErr = icalErr->getMap().find(ebid.rawId());
200  EcalTimeCalibError icalconstErr;
201  if (icalitErr != icalErr->getMap().end()) {
202  icalconstErr = (*icalitErr);
203 
204  edm::LogInfo("EcalTimeCalibError: ") << std::setprecision(6) << icalconstErr;
205  } else {
206  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalTimeCalibErrors in your DB? ");
207  }
208  }
209 
210  // fetch Time Offset
211  //std::cout <<"Fetching TimeOffsetConstant from DB " << std::endl;
212 
213  // Time Offset constants
215  context.get<EcalTimeOffsetConstantRcd>().get(pTOff);
216  const EcalTimeOffsetConstant* TOff = pTOff.product();
217 
218  edm::LogInfo("EcalTimeOffsetConstant: ") << " EB " << TOff->getEBValue() << " EE " << TOff->getEEValue();
219 
220  // fetch TB weights
221  edm::LogInfo("Fetching EcalTBWeights from DB ");
223  context.get<EcalTBWeightsRcd>().get(pWgts);
224  const EcalTBWeights* wgts = pWgts.product();
225  edm::LogInfo("EcalTBWeightMap.size(): ") << std::setprecision(3) << wgts->getMap().size();
226 
227  // look up the correct weights for this xtal
228  //EcalXtalGroupId gid( (*git) );
229  EcalTBWeights::EcalTDCId tdcid(1);
230 
231  edm::LogInfo("Lookup EcalWeightSet for groupid: ") << std::setprecision(3) << gid.id() << " and TDC id " << tdcid;
232  EcalTBWeights::EcalTBWeightMap::const_iterator wit = wgts->getMap().find(std::make_pair(gid, tdcid));
233  EcalWeightSet wset;
234  if (wit != wgts->getMap().end()) {
235  wset = wit->second;
236  edm::LogInfo("check size of data members in EcalWeightSet");
237  //wit->second.print(std::cout);
238 
239  //typedef std::vector< std::vector<EcalWeight> > EcalWeightMatrix;
240  const EcalWeightSet::EcalWeightMatrix& mat1 = wit->second.getWeightsBeforeGainSwitch();
241  const EcalWeightSet::EcalWeightMatrix& mat2 = wit->second.getWeightsAfterGainSwitch();
242 
243  // std::cout << "WeightsBeforeGainSwitch.size: " << mat1.size()
244  // << ", WeightsAfterGainSwitch.size: " << mat2.size() << std::endl;
245 
246  CLHEP::HepMatrix clmat1(3, 10, 0);
247  CLHEP::HepMatrix clmat2(3, 10, 0);
248  for (int irow = 0; irow < 3; irow++) {
249  for (int icol = 0; icol < 10; icol++) {
250  clmat1[irow][icol] = mat1(irow, icol);
251  clmat2[irow][icol] = mat2(irow, icol);
252  }
253  }
254  edm::LogInfo("weight matrix before gain switch:") << clmat1;
255  edm::LogInfo("weight matrix after gain switch:") << clmat2;
256 
257  } else {
258  edm::LogInfo("No weights found for EcalGroupId: ") << gid.id() << " and EcalTDCId: " << tdcid;
259  }
260 
261  // cluster functions/corrections
263  context.get<EcalClusterLocalContCorrParametersRcd>().get(pLocalCont);
264  const EcalClusterLocalContCorrParameters* paramLocalCont = pLocalCont.product();
265  edm::LogInfo("LocalContCorrParameters:");
266  for (EcalFunctionParameters::const_iterator it = paramLocalCont->params().begin();
267  it != paramLocalCont->params().end();
268  ++it) {
269  // edm::LogInfo(" ") << *it;
270  }
271  // std::cout << "\n";
273  context.get<EcalClusterCrackCorrParametersRcd>().get(pCrack);
274  const EcalClusterCrackCorrParameters* paramCrack = pCrack.product();
275  edm::LogInfo("CrackCorrParameters:");
276  for (EcalFunctionParameters::const_iterator it = paramCrack->params().begin(); it != paramCrack->params().end();
277  ++it) {
278  // edm::LogInfo(" ") << *it;
279  }
280  // std::cout << "\n";
282  context.get<EcalClusterEnergyCorrectionParametersRcd>().get(pEnergyCorrection);
283  const EcalClusterEnergyCorrectionParameters* paramEnergyCorrection = pEnergyCorrection.product();
284  edm::LogInfo("EnergyCorrectionParameters:");
285  for (EcalFunctionParameters::const_iterator it = paramEnergyCorrection->params().begin();
286  it != paramEnergyCorrection->params().end();
287  ++it) {
288  // edm::LogInfo(" ") << *it;
289  }
290  // std::cout << "\n";
292  context.get<EcalClusterEnergyUncertaintyParametersRcd>().get(pEnergyUncertainty);
293  const EcalClusterEnergyUncertaintyParameters* paramEnergyUncertainty = pEnergyUncertainty.product();
294  edm::LogInfo("EnergyCorrectionParameters:");
295  for (EcalFunctionParameters::const_iterator it = paramEnergyUncertainty->params().begin();
296  it != paramEnergyUncertainty->params().end();
297  ++it) {
298  // edm::LogInfo(" ") << *it;
299  }
300  // std::cout << "\n";
302  context.get<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>().get(pEnergyCorrectionObjectSpecific);
303  const EcalClusterEnergyCorrectionObjectSpecificParameters* paramEnergyCorrectionObjectSpecific =
304  pEnergyCorrectionObjectSpecific.product();
305  edm::LogInfo("EnergyCorrectionObjectSpecificParameters:");
306  for (EcalFunctionParameters::const_iterator it = paramEnergyCorrectionObjectSpecific->params().begin();
307  it != paramEnergyCorrectionObjectSpecific->params().end();
308  ++it) {
309  // edm::LogInfo(" ") << *it;
310  }
311  // std::cout << "\n";
312 
313  // laser correction
314 
315  // laser alphas
317  context.get<EcalLaserAlphasRcd>().get(pAlpha);
318  const EcalLaserAlphas* lalpha = pAlpha.product();
319 
321  lalphait = lalpha->getMap().find(ebid.rawId());
322  if (lalphait != lalpha->getMap().end()) {
323  edm::LogInfo("EcalLaserAlpha: ") << std::setprecision(6) << (*lalphait);
324  } else {
325  edm::LogInfo("No laser alpha found for this xtal! something wrong with EcalLaserAlphas in your DB? ");
326  }
327 
328  // laser apdpnref
330  context.get<EcalLaserAPDPNRatiosRefRcd>().get(pAPDPNRatiosRef);
331  const EcalLaserAPDPNRatiosRef* lref = pAPDPNRatiosRef.product();
332 
334  lrefit = lref->getMap().find(ebid.rawId());
335  if (lrefit != lref->getMap().end()) {
336  // edm::LogInfo("EcalLaserAPDPNRatiosRef: ")
337  // <<std::setprecision(6)
338  // << (*lrefit)
339  ;
340  } else {
341  edm::LogInfo("No laser apd/pn ref found for this xtal! something wrong with EcalLaserAPDPNRatiosRef in your DB? ");
342  }
343 
344  // laser apdpn ratios
346  context.get<EcalLaserAPDPNRatiosRcd>().get(pAPDPNRatios);
347  const EcalLaserAPDPNRatios* lratio = pAPDPNRatios.product();
348 
350  lratioit = lratio->getLaserMap().find(ebid.rawId());
352 
353  if (lratioit != lratio->getLaserMap().end()) {
354  lratioconst = (*lratioit);
355 
356  // edm::LogInfo("EcalLaserAPDPNRatios: ")
357  // <<e.id().run() << " " << e.id().event() << " "
358  // << std::setprecision(6)
359  // << lratioconst.p1 << " " << lratioconst.p2
360  ;
361  } else {
362  edm::LogInfo("No laser apd/pn ratio found for this xtal! something wrong with EcalLaserAPDPNRatios in your DB? ");
363  }
364 
365  // laser timestamps
367  // EcalLaserAPDPNRatios::EcalLaserTimeStampMap::const_iterator ltimeit;
368  for (int i = 1; i <= 92; i++) {
369  ltimestamp = lratio->getTimeMap()[i];
370  // edm::LogInfo("i = ") << std::setprecision(6) << i
371  // << ltimestamp.t1.value() << " " << ltimestamp.t2.value() << " : " ;
372  }
373  // edm::LogInfo("Tests finished.");
374 
375  // channel status
376  edm::ESHandle<EcalChannelStatus> pChannelStatus;
377  context.get<EcalChannelStatusRcd>().get(pChannelStatus);
378  const EcalChannelStatus* ch_status = pChannelStatus.product();
379 
381  chit = ch_status->getMap().find(ebid.rawId());
382  if (chit != ch_status->getMap().end()) {
383  EcalChannelStatusCode ch_code = (*chit);
384  edm::LogInfo("EcalChannelStatus: ") << std::setprecision(6) << ch_code.getStatusCode();
385  } else {
386  edm::LogInfo("No channel status found for this xtal! something wrong with EcalChannelStatus in your DB? ");
387  }
388 
389  // laser transparency correction
390 
391  // Mask to ignore sample
393  context.get<EcalSampleMaskRcd>().get(pSMask);
394  const EcalSampleMask* smask = pSMask.product();
395  edm::LogInfo("Sample Mask EB ") << std::hex << smask->getEcalSampleMaskRecordEB() << " EE " << std::hex
396  << smask->getEcalSampleMaskRecordEE();
397 
398  /*
399  std::cout << "make CLHEP matrices from vector<vector<Ecalweight>>" << std::endl;
400  CLHEP::HepMatrix clmat1(3,8,0);
401  CLHEP::HepMatrix clmat2(3,8,0);
402  for(int irow=0; irow<3; irow++) {
403  for(int icol=0; icol<8; icol++) {
404  clmat1[irow][icol] = (mat1[irow])[icol]();
405  clmat2[irow][icol] = (mat2[irow])[icol]();
406  }
407  }
408  std::cout << clmat1 << std::endl;
409  std::cout << clmat2 << std::endl;
410 */
411 
412 } //end of ::Analyze()
413 //DEFINE_FWK_MODULE(EcalTrivialObjectAnalyzer);
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
const self & getMap() const
Code getStatusCode() const
return decoded status
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:20
float EcalTimeCalibError
const unsigned int id() const
const EcalLaserAPDPNRatiosMap & getLaserMap() const
EcalFunctionParameters & params()
void analyze(const edm::Event &e, const edm::EventSetup &c) override
float getEcalSampleMaskRecordEE() const
float gain6Over1() const
float EcalIntercalibError
const EcalLaserTimeStampMap & getTimeMap() const
std::vector< Item >::const_iterator const_iterator
float gain12Over6() const
edm::EventID id() const
Definition: EventBase.h:59
float EcalTimeCalibConstant
float getEcalSampleMaskRecordEB() const
T get() const
Definition: EventSetup.h:73
Signal rand(Signal arg)
Definition: vlib.cc:379
const_iterator find(uint32_t rawId) const
const EcalTBWeightMap & getMap() const
Definition: EcalTBWeights.h:28
const_iterator end() const
T const * product() const
Definition: ESHandle.h:86
float EcalIntercalibConstant