CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
14 
19 
20 #include "CLHEP/Matrix/Matrix.h"
21 
22 using namespace std;
23 
25  : pedestalsToken_(esConsumes()),
26  adcToGevConstantToken_(esConsumes()),
27  weightXtalGroupsToken_(esConsumes()),
28  gainRatiosToken_(esConsumes()),
29  intercalibConstantsToken_(esConsumes()),
30  intercalibErrorsToken_(esConsumes()),
31  timeCalibConstantsToken_(esConsumes()),
32  timeCalibErrorsToken_(esConsumes()),
33  timeOffsetConstantToken_(esConsumes()),
34  tbWeightsToken_(esConsumes()),
35  clusterLocalContCorrToken_(esConsumes()),
36  clusterCrackCorrToken_(esConsumes()),
37  clusterEnergyCorrectionToken_(esConsumes()),
38  clusterEnergyUncertaintyToken_(esConsumes()),
39  clusterEnergyCorrectionObjectSpecificToken_(esConsumes()),
40  laserAlphasToken_(esConsumes()),
41  laserAPDPNRatiosRefToken_(esConsumes()),
42  laserAPDPNRatiosToken_(esConsumes()),
43  channelStatusToken_(esConsumes()),
44  sampleMaskToken_(esConsumes()) {}
45 
47  using namespace edm::eventsetup;
48  // Context is not used.
49  edm::LogInfo(">>> EcalTrivialObjectAnalyzer: processing run ") << e.id().run() << " event: " << e.id().event();
50 
51  // ADC -> GeV Scale
52  const auto& agc = context.getData(adcToGevConstantToken_);
53  edm::LogInfo("Global ADC->GeV scale: EB ") << std::setprecision(6) << agc.getEBValue()
54  << " GeV/ADC count"
55  " EE "
56  << std::setprecision(6) << agc.getEEValue() << " GeV/ADC count";
57 
58  // use a channel to fetch values from DB
59  double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
60  int ieta = int(1 + r1 * 85);
61  r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
62  int iphi = int(1 + r1 * 20);
63 
64  EBDetId ebid(ieta, iphi); //eta,phi
65  edm::LogInfo("EcalTrivialObjectAnalyzer: using EBDetId: ") << ebid;
66 
67  const auto& myped = context.getData(pedestalsToken_);
68  EcalPedestals::const_iterator it = myped.find(ebid.rawId());
69  if (it != myped.end()) {
70  edm::LogInfo("EcalPedestal: ") << " mean_x1: " << std::setprecision(8) << (*it).mean_x1
71  << " rms_x1: " << (*it).rms_x1 << " mean_x6: " << (*it).mean_x6
72  << " rms_x6: " << (*it).rms_x6 << " mean_x12: " << (*it).mean_x12
73  << " rms_x12: " << (*it).rms_x12;
74  } else {
75  edm::LogInfo("No pedestal found for this xtal! something wrong with EcalPedestals in your DB? ");
76  }
77 
78  // fetch map of groups of xtals
79  const auto& grp = context.getData(weightXtalGroupsToken_);
80 
81  EcalXtalGroupsMap::const_iterator git = grp.getMap().find(ebid.rawId());
82  EcalXtalGroupId gid;
83  if (git != grp.getMap().end()) {
84  edm::LogInfo("XtalGroupId.id() = ") << std::setprecision(3) << (*git).id();
85  gid = (*git);
86  } else {
87  edm::LogInfo("No group id found for this crystal. something wrong with EcalWeightXtalGroups in your DB?");
88  }
89 
90  // Gain Ratios
91  const auto& gr = context.getData(gainRatiosToken_);
92 
93  EcalGainRatioMap::const_iterator grit = gr.getMap().find(ebid.rawId());
94  EcalMGPAGainRatio mgpa;
95  if (grit != gr.getMap().end()) {
96  mgpa = (*grit);
97 
98  edm::LogInfo("EcalMGPAGainRatio: ") << "gain 12/6 : " << std::setprecision(4) << mgpa.gain12Over6()
99  << " gain 6/1: " << mgpa.gain6Over1();
100  } else {
101  edm::LogInfo("No MGPA Gain Ratio found for this xtal! something wrong with EcalGainRatios in your DB? ");
102  }
103 
104  // Intercalib constants
105  const auto& ical = context.getData(intercalibConstantsToken_);
106 
107  EcalIntercalibConstantMap::const_iterator icalit = ical.getMap().find(ebid.rawId());
108  EcalIntercalibConstant icalconst;
109  if (icalit != ical.getMap().end()) {
110  icalconst = (*icalit);
111 
112  edm::LogInfo("EcalIntercalibConstant: ") << std::setprecision(6) << icalconst;
113  } else {
114  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalIntercalibConstants in your DB? ");
115  }
116 
117  // Intercalib errors
118  const auto& icalErr = context.getData(intercalibErrorsToken_);
119 
120  EcalIntercalibErrorMap::const_iterator icalitErr = icalErr.getMap().find(ebid.rawId());
121  EcalIntercalibError icalconstErr;
122  if (icalitErr != icalErr.getMap().end()) {
123  icalconstErr = (*icalitErr);
124 
125  edm::LogInfo("EcalIntercalibError: ") << std::setprecision(6) << icalconstErr;
126  } else {
127  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalIntercalibErrors in your DB? ");
128  }
129 
130  { // quick and dirty for cut and paste ;) it is a test program...
131  // TimeCalib constants
132  const auto& ical = context.getData(timeCalibConstantsToken_);
133 
134  EcalTimeCalibConstantMap::const_iterator icalit = ical.getMap().find(ebid.rawId());
135  EcalTimeCalibConstant icalconst;
136  if (icalit != ical.getMap().end()) {
137  icalconst = (*icalit);
138 
139  edm::LogInfo("EcalTimeCalibConstant: ") << std::setprecision(6) << icalconst;
140  } else {
141  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalTimeCalibConstants in your DB? ");
142  }
143 
144  // TimeCalib errors
145  const auto& icalErr = context.getData(timeCalibErrorsToken_);
146 
147  EcalTimeCalibErrorMap::const_iterator icalitErr = icalErr.getMap().find(ebid.rawId());
148  EcalTimeCalibError icalconstErr;
149  if (icalitErr != icalErr.getMap().end()) {
150  icalconstErr = (*icalitErr);
151 
152  edm::LogInfo("EcalTimeCalibError: ") << std::setprecision(6) << icalconstErr;
153  } else {
154  edm::LogInfo("No intercalib const found for this xtal! something wrong with EcalTimeCalibErrors in your DB? ");
155  }
156  }
157 
158  // fetch Time Offset
159  //std::cout <<"Fetching TimeOffsetConstant from DB " << std::endl;
160 
161  // Time Offset constants
162  const auto& TOff = context.getData(timeOffsetConstantToken_);
163 
164  edm::LogInfo("EcalTimeOffsetConstant: ") << " EB " << TOff.getEBValue() << " EE " << TOff.getEEValue();
165 
166  // fetch TB weights
167  edm::LogInfo("Fetching EcalTBWeights from DB ");
168  const auto& wgts = context.getData(tbWeightsToken_);
169  edm::LogInfo("EcalTBWeightMap.size(): ") << std::setprecision(3) << wgts.getMap().size();
170 
171  // look up the correct weights for this xtal
172  //EcalXtalGroupId gid( (*git) );
173  EcalTBWeights::EcalTDCId tdcid(1);
174 
175  edm::LogInfo("Lookup EcalWeightSet for groupid: ") << std::setprecision(3) << gid.id() << " and TDC id " << tdcid;
176  EcalTBWeights::EcalTBWeightMap::const_iterator wit = wgts.getMap().find(std::make_pair(gid, tdcid));
177  EcalWeightSet wset;
178  if (wit != wgts.getMap().end()) {
179  wset = wit->second;
180  edm::LogInfo("check size of data members in EcalWeightSet");
181  //wit->second.print(std::cout);
182 
183  //typedef std::vector< std::vector<EcalWeight> > EcalWeightMatrix;
184  const EcalWeightSet::EcalWeightMatrix& mat1 = wit->second.getWeightsBeforeGainSwitch();
185  const EcalWeightSet::EcalWeightMatrix& mat2 = wit->second.getWeightsAfterGainSwitch();
186 
187  // std::cout << "WeightsBeforeGainSwitch.size: " << mat1.size()
188  // << ", WeightsAfterGainSwitch.size: " << mat2.size() << std::endl;
189 
190  CLHEP::HepMatrix clmat1(3, 10, 0);
191  CLHEP::HepMatrix clmat2(3, 10, 0);
192  for (int irow = 0; irow < 3; irow++) {
193  for (int icol = 0; icol < 10; icol++) {
194  clmat1[irow][icol] = mat1(irow, icol);
195  clmat2[irow][icol] = mat2(irow, icol);
196  }
197  }
198  edm::LogInfo("weight matrix before gain switch:") << clmat1;
199  edm::LogInfo("weight matrix after gain switch:") << clmat2;
200 
201  } else {
202  edm::LogInfo("No weights found for EcalGroupId: ") << gid.id() << " and EcalTDCId: " << tdcid;
203  }
204 
205  // cluster functions/corrections
206  const auto& paramLocalCont = context.getData(clusterLocalContCorrToken_);
207  edm::LogInfo("LocalContCorrParameters:");
208  for (EcalFunctionParameters::const_iterator it = paramLocalCont.params().begin(); it != paramLocalCont.params().end();
209  ++it) {
210  // edm::LogInfo(" ") << *it;
211  }
212  // std::cout << "\n";
213  const auto& paramCrack = context.getData(clusterCrackCorrToken_);
214  edm::LogInfo("CrackCorrParameters:");
215  for (EcalFunctionParameters::const_iterator it = paramCrack.params().begin(); it != paramCrack.params().end(); ++it) {
216  // edm::LogInfo(" ") << *it;
217  }
218  // std::cout << "\n";
219  const auto& paramEnergyCorrection = context.getData(clusterEnergyCorrectionToken_);
220  edm::LogInfo("EnergyCorrectionParameters:");
221  for (EcalFunctionParameters::const_iterator it = paramEnergyCorrection.params().begin();
222  it != paramEnergyCorrection.params().end();
223  ++it) {
224  // edm::LogInfo(" ") << *it;
225  }
226  // std::cout << "\n";
227  const auto& paramEnergyUncertainty = context.getData(clusterEnergyUncertaintyToken_);
228  edm::LogInfo("EnergyCorrectionParameters:");
229  for (EcalFunctionParameters::const_iterator it = paramEnergyUncertainty.params().begin();
230  it != paramEnergyUncertainty.params().end();
231  ++it) {
232  // edm::LogInfo(" ") << *it;
233  }
234  // std::cout << "\n";
235  const auto& paramEnergyCorrectionObjectSpecific = context.getData(clusterEnergyCorrectionObjectSpecificToken_);
236  edm::LogInfo("EnergyCorrectionObjectSpecificParameters:");
237  for (EcalFunctionParameters::const_iterator it = paramEnergyCorrectionObjectSpecific.params().begin();
238  it != paramEnergyCorrectionObjectSpecific.params().end();
239  ++it) {
240  // edm::LogInfo(" ") << *it;
241  }
242  // std::cout << "\n";
243 
244  // laser correction
245 
246  // laser alphas
247  const auto& lalpha = context.getData(laserAlphasToken_);
248 
250  lalphait = lalpha.getMap().find(ebid.rawId());
251  if (lalphait != lalpha.getMap().end()) {
252  edm::LogInfo("EcalLaserAlpha: ") << std::setprecision(6) << (*lalphait);
253  } else {
254  edm::LogInfo("No laser alpha found for this xtal! something wrong with EcalLaserAlphas in your DB? ");
255  }
256 
257  // laser apdpnref
258  const auto& lref = context.getData(laserAPDPNRatiosRefToken_);
259 
261  lrefit = lref.getMap().find(ebid.rawId());
262  if (lrefit != lref.getMap().end()) {
263  // edm::LogInfo("EcalLaserAPDPNRatiosRef: ")
264  // <<std::setprecision(6)
265  // << (*lrefit)
266  ;
267  } else {
268  edm::LogInfo("No laser apd/pn ref found for this xtal! something wrong with EcalLaserAPDPNRatiosRef in your DB? ");
269  }
270 
271  // laser apdpn ratios
272  const auto& lratio = context.getData(laserAPDPNRatiosToken_);
273 
275  lratioit = lratio.getLaserMap().find(ebid.rawId());
277 
278  if (lratioit != lratio.getLaserMap().end()) {
279  lratioconst = (*lratioit);
280 
281  // edm::LogInfo("EcalLaserAPDPNRatios: ")
282  // <<e.id().run() << " " << e.id().event() << " "
283  // << std::setprecision(6)
284  // << lratioconst.p1 << " " << lratioconst.p2
285  ;
286  } else {
287  edm::LogInfo("No laser apd/pn ratio found for this xtal! something wrong with EcalLaserAPDPNRatios in your DB? ");
288  }
289 
290  // laser timestamps
292  // EcalLaserAPDPNRatios::EcalLaserTimeStampMap::const_iterator ltimeit;
293  for (int i = 1; i <= 92; i++) {
294  ltimestamp = lratio.getTimeMap()[i];
295  // edm::LogInfo("i = ") << std::setprecision(6) << i
296  // << ltimestamp.t1.value() << " " << ltimestamp.t2.value() << " : " ;
297  }
298  // edm::LogInfo("Tests finished.");
299 
300  // channel status
301  const auto& ch_status = context.getData(channelStatusToken_);
302 
304  chit = ch_status.getMap().find(ebid.rawId());
305  if (chit != ch_status.getMap().end()) {
306  EcalChannelStatusCode ch_code = (*chit);
307  edm::LogInfo("EcalChannelStatus: ") << std::setprecision(6) << ch_code.getStatusCode();
308  } else {
309  edm::LogInfo("No channel status found for this xtal! something wrong with EcalChannelStatus in your DB? ");
310  }
311 
312  // laser transparency correction
313 
314  // Mask to ignore sample
315  const auto& smask = context.getData(sampleMaskToken_);
316  edm::LogInfo("Sample Mask EB ") << std::hex << smask.getEcalSampleMaskRecordEB() << " EE " << std::hex
317  << smask.getEcalSampleMaskRecordEE();
318 
319  /*
320  std::cout << "make CLHEP matrices from vector<vector<Ecalweight>>" << std::endl;
321  CLHEP::HepMatrix clmat1(3,8,0);
322  CLHEP::HepMatrix clmat2(3,8,0);
323  for(int irow=0; irow<3; irow++) {
324  for(int icol=0; icol<8; icol++) {
325  clmat1[irow][icol] = (mat1[irow])[icol]();
326  clmat2[irow][icol] = (mat2[irow])[icol]();
327  }
328  }
329  std::cout << clmat1 << std::endl;
330  std::cout << clmat2 << std::endl;
331 */
332 
333 } //end of ::Analyze()
334 //DEFINE_FWK_MODULE(EcalTrivialObjectAnalyzer);
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
const edm::ESGetToken< EcalClusterEnergyUncertaintyParameters, EcalClusterEnergyUncertaintyParametersRcd > clusterEnergyUncertaintyToken_
const edm::ESGetToken< EcalLaserAlphas, EcalLaserAlphasRcd > laserAlphasToken_
const edm::ESGetToken< EcalClusterLocalContCorrParameters, EcalClusterLocalContCorrParametersRcd > clusterLocalContCorrToken_
const edm::ESGetToken< EcalIntercalibErrors, EcalIntercalibErrorsRcd > intercalibErrorsToken_
const edm::ESGetToken< EcalClusterCrackCorrParameters, EcalClusterCrackCorrParametersRcd > clusterCrackCorrToken_
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:19
float EcalTimeCalibError
bool getData(T &iHolder) const
Definition: EventSetup.h:128
const edm::ESGetToken< EcalClusterEnergyCorrectionParameters, EcalClusterEnergyCorrectionParametersRcd > clusterEnergyCorrectionToken_
const edm::ESGetToken< EcalClusterEnergyCorrectionObjectSpecificParameters, EcalClusterEnergyCorrectionObjectSpecificParametersRcd > clusterEnergyCorrectionObjectSpecificToken_
const edm::ESGetToken< EcalSampleMask, EcalSampleMaskRcd > sampleMaskToken_
const edm::ESGetToken< EcalTimeCalibConstants, EcalTimeCalibConstantsRcd > timeCalibConstantsToken_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > channelStatusToken_
const edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedestalsToken_
EcalTrivialObjectAnalyzer(edm::ParameterSet const &p)
const edm::ESGetToken< EcalTimeCalibErrors, EcalTimeCalibErrorsRcd > timeCalibErrorsToken_
float EcalIntercalibError
const edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > laserAPDPNRatiosToken_
const edm::ESGetToken< EcalLaserAPDPNRatiosRef, EcalLaserAPDPNRatiosRefRcd > laserAPDPNRatiosRefToken_
Log< level::Info, false > LogInfo
const edm::ESGetToken< EcalWeightXtalGroups, EcalWeightXtalGroupsRcd > weightXtalGroupsToken_
const edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > intercalibConstantsToken_
const edm::ESGetToken< EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd > timeOffsetConstantToken_
std::vector< Item >::const_iterator const_iterator
const edm::ESGetToken< EcalTBWeights, EcalTBWeightsRcd > tbWeightsToken_
edm::EventID id() const
Definition: EventBase.h:59
float EcalTimeCalibConstant
const edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > gainRatiosToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > adcToGevConstantToken_
float EcalIntercalibConstant