CMS 3D CMS Logo

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