CMS 3D CMS Logo

ECALpedestalPCLHarvester.cc
Go to the documentation of this file.
1 
2 // system include files
3 #include <memory>
4 
5 // user include files
15 #include <iostream>
16 #include <string>
17 
19  currentPedestals_(nullptr),channelStatus_(nullptr){
20 
21  chStatusToExclude_= StringToEnumValue<EcalChannelStatusCode::Code>(ps.getParameter<std::vector<std::string> >("ChannelStatusToExclude"));
22  minEntries_=ps.getParameter<int>("MinEntries");
23  checkAnomalies_ = ps.getParameter<bool>("checkAnomalies");
24  nSigma_ = ps.getParameter<double>("nSigma");
25  thresholdAnomalies_ = ps.getParameter<double>("thresholdAnomalies");
26  dqmDir_ = ps.getParameter<std::string>("dqmDir");
27  labelG6G1_ = ps.getParameter<std::string>("labelG6G1");
28  threshDiffEB_ = ps.getParameter<double>("threshDiffEB");
29  threshDiffEE_ = ps.getParameter<double>("threshDiffEE");
30  threshChannelsAnalyzed_ = ps.getParameter<double>("threshChannelsAnalyzed");
31 }
32 
34 
35 
36  // calculate pedestals and fill db record
37  EcalPedestals pedestals;
38  int kBarrelSize = 61200;
39  int kEndcapSize = 2*7324;
40  int skipped_channels_EB = 0;
41  int skipped_channels_EE = 0;
42 
43 
44  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
45  std::string hname = dqmDir_+"/EB/"+std::to_string(int(i/100))+"/eb_" + std::to_string(i);
46  MonitorElement* ch= igetter_.get(hname);
47  double mean = ch->getMean();
48  double rms = ch->getRMS();
49  entriesEB_[i] = ch->getEntries();
50 
52  EcalPedestal ped;
53  EcalPedestal oldped =* currentPedestals_->find(id.rawId());
54  EcalPedestal g6g1ped=* g6g1Pedestals_->find(id.rawId());
55 
56  ped.mean_x12=mean;
57  ped.rms_x12=rms;
58 
59  float diff = std::abs(mean-oldped.mean_x12);
60 
61  // if bad channel or low stat skip or the difference is too large wrt to previous record
62  if(ch->getEntries()< minEntries_ || !checkStatusCode(id) || diff>threshDiffEB_){
63 
64  ped.mean_x12=oldped.mean_x12;
65  ped.rms_x12=oldped.rms_x12;
66 
67  skipped_channels_EB++;
68 
69  }
70 
71  // copy g6 and g1 from the corressponding record
72  ped.mean_x6= g6g1ped.mean_x6;
73  ped.rms_x6 = g6g1ped.rms_x6;
74  ped.mean_x1= g6g1ped.mean_x1;
75  ped.rms_x1 = g6g1ped.rms_x1;
76 
77  pedestals.setValue(id.rawId(),ped);
78  }
79 
80 
81  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
82 
83  std::string hname = dqmDir_+"/EE/"+std::to_string(int(i/100))+"/ee_" + std::to_string(i);
84 
85  MonitorElement* ch= igetter_.get(hname);
86  double mean = ch->getMean();
87  double rms = ch->getRMS();
88  entriesEE_[i] = ch->getEntries();
89 
91  EcalPedestal ped;
92  EcalPedestal oldped = *currentPedestals_->find(id.rawId());
93  EcalPedestal g6g1ped= *g6g1Pedestals_->find(id.rawId());
94 
95  ped.mean_x12=mean;
96  ped.rms_x12=rms;
97 
98  float diff = std::abs(mean-oldped.mean_x12);
99 
100  // if bad channel or low stat skip or the difference is too large wrt to previous record
101  if(ch->getEntries()< minEntries_ || !checkStatusCode(id)|| diff>threshDiffEE_){
102 
103  ped.mean_x12=oldped.mean_x12;
104  ped.rms_x12=oldped.rms_x12;
105 
106  skipped_channels_EE++;
107  }
108 
109  // copy g6 and g1 pedestals from corresponding record
110  ped.mean_x6= g6g1ped.mean_x6;
111  ped.rms_x6 = g6g1ped.rms_x6;
112  ped.mean_x1= g6g1ped.mean_x1;
113  ped.rms_x1 = g6g1ped.rms_x1;
114 
115  pedestals.setValue(id.rawId(),ped);
116  }
117 
118 
119  bool enough_stat = false;
120  if ((kBarrelSize-skipped_channels_EB)/kBarrelSize > threshChannelsAnalyzed_ &&
121  (kEndcapSize-skipped_channels_EE)/kEndcapSize > threshChannelsAnalyzed_ ){
122 
123  enough_stat=true;
124  }
125 
126 
127  dqmPlots(pedestals, ibooker_);
128 
129 
130  // check if there are large variations wrt exisiting pedstals
131 
132  if (checkAnomalies_){
133  if (checkVariation(*currentPedestals_, pedestals)) {
134  edm::LogError("Large Variations found wrt to old pedestals, no file created");
135  return;
136  }
137  }
138 
139  // write out pedestal record
141 
142  if ( !poolDbService.isAvailable() ) {
143  throw std::runtime_error("PoolDBService required.");
144  }
145  if (enough_stat)
146  poolDbService->writeOne( &pedestals, poolDbService->currentTime(),"EcalPedestalsRcd" );
147 
148 }
149 
150 
151 
152 
153 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
154 void
156 
158  desc.setUnknown();
159  descriptions.addDefault(desc);
160 }
161 
162 
164 
165 
167  isetup.get<EcalChannelStatusRcd>().get(chStatus);
168  channelStatus_=chStatus.product();
169 
171  isetup.get<EcalPedestalsRcd>().get(peds);
172  currentPedestals_=peds.product();
173 
175  isetup.get<EcalPedestalsRcd>().get(labelG6G1_,g6g1peds);
176  g6g1Pedestals_=g6g1peds.product();
177 
178 }
179 
181 
183  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
184  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
185 
186  std::vector<int>::const_iterator res =
187  std::find( chStatusToExclude_.begin(), chStatusToExclude_.end(), dbstatus );
188  if ( res != chStatusToExclude_.end() ) return false;
189 
190  return true;
191 }
192 
194 
196  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
197  if (dbstatusPtr == channelStatus_->getMap().end())
198  edm::LogError("Invalid DetId supplied");
199  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
200  if (dbstatus ==0 ) return true;
201  return false;
202 }
203 
204 
206  const EcalPedestalsMap& newPedestals) {
207 
208  uint32_t nAnomaliesEB =0;
209  uint32_t nAnomaliesEE =0;
210 
211  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
212 
214  const EcalPedestal& newped=* newPedestals.find(id.rawId());
215  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
216 
217  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++;
218 
219  }
220 
221  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
222 
224  const EcalPedestal& newped=* newPedestals.find(id.rawId());
225  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
226 
227  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++;
228 
229  }
230 
231  if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing ||
232  nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing)
233  return true;
234 
235  return false;
236 
237 
238 }
239 
240 
241 
242 
244 
245  ibooker.cd();
246  ibooker.setCurrentFolder(dqmDir_+"/Summary");
247 
248  MonitorElement * pmeb = ibooker.book2D("meaneb","Pedestal Means EB",360, 1., 361., 171, -85., 86.);
249  MonitorElement * preb = ibooker.book2D("rmseb","Pedestal RMS EB ",360, 1., 361., 171, -85., 86.);
250 
251  MonitorElement * pmeep = ibooker.book2D("meaneep","Pedestal Means EEP",100,1,101,100,1,101);
252  MonitorElement * preep = ibooker.book2D("rmseep","Pedestal RMS EEP",100,1,101,100,1,101);
253 
254  MonitorElement * pmeem = ibooker.book2D("meaneem","Pedestal Means EEM",100,1,101,100,1,101);
255  MonitorElement * preem = ibooker.book2D("rmseem","Pedestal RMS EEM",100,1,101,100,1,101);
256 
257  MonitorElement * pmebd = ibooker.book2D("meanebdiff","Abs Rel Pedestal Means Diff EB",360,1., 361., 171, -85., 86.);
258  MonitorElement * prebd = ibooker.book2D("rmsebdiff","Abs Rel Pedestal RMS Diff E ",360, 1., 361., 171, -85., 86.);
259 
260  MonitorElement * pmeepd = ibooker.book2D("meaneepdiff","Abs Rel Pedestal Means Diff EEP",100,1,101,100,1,101);
261  MonitorElement * preepd = ibooker.book2D("rmseepdiff","Abs Rel Pedestal RMS Diff EEP",100,1,101,100,1,101);
262 
263  MonitorElement * pmeemd = ibooker.book2D("meaneemdiff","Abs Rel Pedestal Means Diff EEM",100,1,101,100,1,101);
264  MonitorElement * preemd = ibooker.book2D("rmseemdiff","Abs RelPedestal RMS Diff EEM",100,1,101,100,1,101);
265 
266  MonitorElement * poeb = ibooker.book2D("occeb","Occupancy EB",360, 1., 361., 171, -85., 86.);
267  MonitorElement * poeep = ibooker.book2D("occeep","Occupancy EEP",100,1,101,100,1,101);
268  MonitorElement * poeem = ibooker.book2D("occeem","Occupancy EEM",100,1,101,100,1,101);
269 
270 
271  MonitorElement * hdiffeb = ibooker.book1D("diffeb","Pedestal Differences EB",100,-2.5,2.5);
272  MonitorElement * hdiffee = ibooker.book1D("diffee","Pedestal Differences EE",100,-2.5,2.5);
273 
275 
277  float mean= newpeds[di].mean_x12;
278  float rms = newpeds[di].rms_x12;
279 
280  float cmean = (*currentPedestals_)[di].mean_x12;
281  float crms = (*currentPedestals_)[di].rms_x12;
282 
283  if (!isGood(di) ) continue; // only good channels are plotted
284 
285  pmeb->Fill(di.iphi(),di.ieta(),mean);
286  preb->Fill(di.iphi(),di.ieta(),rms);
287  if (cmean) pmebd->Fill(di.iphi(),di.ieta(),std::abs(mean-cmean)/cmean);
288  if (crms) prebd->Fill(di.iphi(),di.ieta(),std::abs(rms-crms)/crms);
289  poeb->Fill(di.iphi(),di.ieta(),entriesEB_[hash]);
290  hdiffeb->Fill(mean-cmean);
291  }
292 
293 
295 
297  float mean= newpeds[di].mean_x12;
298  float rms = newpeds[di].rms_x12;
299  float cmean = (*currentPedestals_)[di].mean_x12;
300  float crms = (*currentPedestals_)[di].rms_x12;
301 
302  if (!isGood(di) ) continue; // only good channels are plotted
303 
304  if (di.zside() >0){
305  pmeep->Fill(di.ix(),di.iy(),mean);
306  preep->Fill(di.ix(),di.iy(),rms);
307  poeep->Fill(di.ix(),di.iy(),entriesEE_[hash]);
308  if (cmean) pmeepd->Fill(di.ix(),di.iy(),std::abs(mean-cmean)/cmean);
309  if (crms) preepd->Fill(di.ix(),di.iy(),std::abs(rms-crms)/crms);
310  } else{
311  pmeem->Fill(di.ix(),di.iy(),mean);
312  preem->Fill(di.ix(),di.iy(),rms);
313  if (cmean) pmeemd->Fill(di.ix(),di.iy(),std::abs(mean-cmean)/cmean);
314  poeem->Fill(di.ix(),di.iy(),entriesEE_[hash]);
315  if (crms)preemd->Fill(di.ix(),di.iy(),std::abs(rms-crms)/crms);
316  }
317  hdiffee->Fill(mean-cmean);
318 
319  }
320 
321 
322 
323 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
T getParameter(std::string const &) const
int ix() const
Definition: EEDetId.h:76
const self & getMap() const
int entriesEE_[EEDetId::kSizeForDenseIndexing]
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:307
bool checkVariation(const EcalPedestalsMap &oldPedestals, const EcalPedestalsMap &newPedestals)
#define nullptr
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_) override
Definition: Electron.h:6
void Fill(long long x)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:111
void setValue(const uint32_t id, const Item &item)
ECALpedestalPCLHarvester(const edm::ParameterSet &ps)
void addDefault(ParameterSetDescription const &psetDescription)
const EcalPedestals * g6g1Pedestals_
std::vector< int > chStatusToExclude_
bool isAvailable() const
Definition: Service.h:46
int zside() const
Definition: EEDetId.h:70
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
int iy() const
Definition: EEDetId.h:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
void dqmPlots(const EcalPedestals &newpeds, DQMStore::IBooker &ibooker)
Definition: DetId.h:18
double getEntries() const
get # of entries
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
const EcalChannelStatus * channelStatus_
const T & get() const
Definition: EventSetup.h:59
std::vector< Item >::const_iterator const_iterator
bool checkStatusCode(const DetId &id)
const EcalPedestals * currentPedestals_
double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
const_iterator find(uint32_t rawId) const
const_iterator end() const
void endRun(edm::Run const &run, edm::EventSetup const &isetup) override
int entriesEB_[EBDetId::kSizeForDenseIndexing]
T const * product() const
Definition: ESHandle.h:86
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:43