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  float kBarrelSize = 61200;
39  float kEndcapSize = 2*7324;
40  float skipped_channels_EB = 0;
41  float 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  if(ch == nullptr) {
48  edm::LogWarning("MissingMonitorElement")<<"failed to find MonitorElement "<<hname;
49  entriesEB_[i] = 0;
50  continue;
51  }
52  double mean = ch->getMean();
53  double rms = ch->getRMS();
54  entriesEB_[i] = ch->getEntries();
55 
57  EcalPedestal ped;
58  EcalPedestal oldped =* currentPedestals_->find(id.rawId());
59  EcalPedestal g6g1ped=* g6g1Pedestals_->find(id.rawId());
60 
61  ped.mean_x12=mean;
62  ped.rms_x12=rms;
63 
64  float diff = std::abs(mean-oldped.mean_x12);
65 
66  // if bad channel or low stat skip or the difference is too large wrt to previous record
67  if(ch->getEntries()< minEntries_ || !checkStatusCode(id) || diff>threshDiffEB_){
68 
69  ped.mean_x12=oldped.mean_x12;
70  ped.rms_x12=oldped.rms_x12;
71 
72  skipped_channels_EB++;
73 
74  }
75 
76  // copy g6 and g1 from the corressponding record
77  ped.mean_x6= g6g1ped.mean_x6;
78  ped.rms_x6 = g6g1ped.rms_x6;
79  ped.mean_x1= g6g1ped.mean_x1;
80  ped.rms_x1 = g6g1ped.rms_x1;
81 
82  pedestals.setValue(id.rawId(),ped);
83  }
84 
85 
86  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
87 
88  std::string hname = dqmDir_+"/EE/"+std::to_string(int(i/100))+"/ee_" + std::to_string(i);
89 
90  MonitorElement* ch= igetter_.get(hname);
91  if(ch == nullptr) {
92  edm::LogWarning("MissingMonitorElement")<<"failed to find MonitorElement "<<hname;
93  entriesEE_[i] = 0;
94  continue;
95  }
96  double mean = ch->getMean();
97  double rms = ch->getRMS();
98  entriesEE_[i] = ch->getEntries();
99 
101  EcalPedestal ped;
102  EcalPedestal oldped = *currentPedestals_->find(id.rawId());
103  EcalPedestal g6g1ped= *g6g1Pedestals_->find(id.rawId());
104 
105  ped.mean_x12=mean;
106  ped.rms_x12=rms;
107 
108  float diff = std::abs(mean-oldped.mean_x12);
109 
110  // if bad channel or low stat skip or the difference is too large wrt to previous record
111  if(ch->getEntries()< minEntries_ || !checkStatusCode(id)|| diff>threshDiffEE_){
112 
113  ped.mean_x12=oldped.mean_x12;
114  ped.rms_x12=oldped.rms_x12;
115 
116  skipped_channels_EE++;
117  }
118 
119  // copy g6 and g1 pedestals from corresponding record
120  ped.mean_x6= g6g1ped.mean_x6;
121  ped.rms_x6 = g6g1ped.rms_x6;
122  ped.mean_x1= g6g1ped.mean_x1;
123  ped.rms_x1 = g6g1ped.rms_x1;
124 
125  pedestals.setValue(id.rawId(),ped);
126  }
127 
128 
129  bool enough_stat = false;
130  if ((kBarrelSize-skipped_channels_EB)/kBarrelSize > threshChannelsAnalyzed_ &&
131  (kEndcapSize-skipped_channels_EE)/kEndcapSize > threshChannelsAnalyzed_ ){
132 
133  enough_stat=true;
134  }
135 
136 
137  dqmPlots(pedestals, ibooker_);
138 
139 
140  // check if there are large variations wrt exisiting pedstals
141 
142  if (checkAnomalies_){
143  if (checkVariation(*currentPedestals_, pedestals)) {
144  edm::LogError("Large Variations found wrt to old pedestals, no file created");
145  return;
146  }
147  }
148 
149  if (!enough_stat) return;
150 
151  // write out pedestal record
153 
154  if ( !poolDbService.isAvailable() ) {
155  throw std::runtime_error("PoolDBService required.");
156  }
157 
158  poolDbService->writeOne( &pedestals, poolDbService->currentTime(),"EcalPedestalsRcd" );
159 
160 }
161 
162 
163 
164 
165 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
166 void
168 
170  desc.setUnknown();
171  descriptions.addDefault(desc);
172 }
173 
174 
176 
177 
179  isetup.get<EcalChannelStatusRcd>().get(chStatus);
180  channelStatus_=chStatus.product();
181 
183  isetup.get<EcalPedestalsRcd>().get(peds);
184  currentPedestals_=peds.product();
185 
187  isetup.get<EcalPedestalsRcd>().get(labelG6G1_,g6g1peds);
188  g6g1Pedestals_=g6g1peds.product();
189 
190 }
191 
193 
195  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
196  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
197 
198  std::vector<int>::const_iterator res =
199  std::find( chStatusToExclude_.begin(), chStatusToExclude_.end(), dbstatus );
200  if ( res != chStatusToExclude_.end() ) return false;
201 
202  return true;
203 }
204 
206 
208  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
209  if (dbstatusPtr == channelStatus_->getMap().end())
210  edm::LogError("Invalid DetId supplied");
211  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
212  if (dbstatus ==0 ) return true;
213  return false;
214 }
215 
216 
218  const EcalPedestalsMap& newPedestals) {
219 
220  uint32_t nAnomaliesEB =0;
221  uint32_t nAnomaliesEE =0;
222 
223  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
224 
226  const EcalPedestal& newped=* newPedestals.find(id.rawId());
227  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
228 
229  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++;
230 
231  }
232 
233  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
234 
236  const EcalPedestal& newped=* newPedestals.find(id.rawId());
237  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
238 
239  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++;
240 
241  }
242 
243  if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing ||
244  nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing)
245  return true;
246 
247  return false;
248 
249 
250 }
251 
252 
253 
254 
256 
257  ibooker.cd();
258  ibooker.setCurrentFolder(dqmDir_+"/Summary");
259 
260  MonitorElement * pmeb = ibooker.book2D("meaneb","Pedestal Means EB",360, 1., 361., 171, -85., 86.);
261  MonitorElement * preb = ibooker.book2D("rmseb","Pedestal RMS EB ",360, 1., 361., 171, -85., 86.);
262 
263  MonitorElement * pmeep = ibooker.book2D("meaneep","Pedestal Means EEP",100,1,101,100,1,101);
264  MonitorElement * preep = ibooker.book2D("rmseep","Pedestal RMS EEP",100,1,101,100,1,101);
265 
266  MonitorElement * pmeem = ibooker.book2D("meaneem","Pedestal Means EEM",100,1,101,100,1,101);
267  MonitorElement * preem = ibooker.book2D("rmseem","Pedestal RMS EEM",100,1,101,100,1,101);
268 
269  MonitorElement * pmebd = ibooker.book2D("meanebdiff","Abs Rel Pedestal Means Diff EB",360,1., 361., 171, -85., 86.);
270  MonitorElement * prebd = ibooker.book2D("rmsebdiff","Abs Rel Pedestal RMS Diff E ",360, 1., 361., 171, -85., 86.);
271 
272  MonitorElement * pmeepd = ibooker.book2D("meaneepdiff","Abs Rel Pedestal Means Diff EEP",100,1,101,100,1,101);
273  MonitorElement * preepd = ibooker.book2D("rmseepdiff","Abs Rel Pedestal RMS Diff EEP",100,1,101,100,1,101);
274 
275  MonitorElement * pmeemd = ibooker.book2D("meaneemdiff","Abs Rel Pedestal Means Diff EEM",100,1,101,100,1,101);
276  MonitorElement * preemd = ibooker.book2D("rmseemdiff","Abs RelPedestal RMS Diff EEM",100,1,101,100,1,101);
277 
278  MonitorElement * poeb = ibooker.book2D("occeb","Occupancy EB",360, 1., 361., 171, -85., 86.);
279  MonitorElement * poeep = ibooker.book2D("occeep","Occupancy EEP",100,1,101,100,1,101);
280  MonitorElement * poeem = ibooker.book2D("occeem","Occupancy EEM",100,1,101,100,1,101);
281 
282 
283  MonitorElement * hdiffeb = ibooker.book1D("diffeb","Pedestal Differences EB",100,-2.5,2.5);
284  MonitorElement * hdiffee = ibooker.book1D("diffee","Pedestal Differences EE",100,-2.5,2.5);
285 
287 
289  float mean= newpeds[di].mean_x12;
290  float rms = newpeds[di].rms_x12;
291 
292  float cmean = (*currentPedestals_)[di].mean_x12;
293  float crms = (*currentPedestals_)[di].rms_x12;
294 
295  if (!isGood(di) ) continue; // only good channels are plotted
296 
297  pmeb->Fill(di.iphi(),di.ieta(),mean);
298  preb->Fill(di.iphi(),di.ieta(),rms);
299  if (cmean) pmebd->Fill(di.iphi(),di.ieta(),std::abs(mean-cmean)/cmean);
300  if (crms) prebd->Fill(di.iphi(),di.ieta(),std::abs(rms-crms)/crms);
301  poeb->Fill(di.iphi(),di.ieta(),entriesEB_[hash]);
302  hdiffeb->Fill(mean-cmean);
303  }
304 
305 
307 
309  float mean= newpeds[di].mean_x12;
310  float rms = newpeds[di].rms_x12;
311  float cmean = (*currentPedestals_)[di].mean_x12;
312  float crms = (*currentPedestals_)[di].rms_x12;
313 
314  if (!isGood(di) ) continue; // only good channels are plotted
315 
316  if (di.zside() >0){
317  pmeep->Fill(di.ix(),di.iy(),mean);
318  preep->Fill(di.ix(),di.iy(),rms);
319  poeep->Fill(di.ix(),di.iy(),entriesEE_[hash]);
320  if (cmean) pmeepd->Fill(di.ix(),di.iy(),std::abs(mean-cmean)/cmean);
321  if (crms) preepd->Fill(di.ix(),di.iy(),std::abs(rms-crms)/crms);
322  } else{
323  pmeem->Fill(di.ix(),di.iy(),mean);
324  preem->Fill(di.ix(),di.iy(),rms);
325  if (cmean) pmeemd->Fill(di.ix(),di.iy(),std::abs(mean-cmean)/cmean);
326  poeem->Fill(di.ix(),di.iy(),entriesEE_[hash]);
327  if (crms)preemd->Fill(di.ix(),di.iy(),std::abs(rms-crms)/crms);
328  }
329  hdiffee->Fill(mean-cmean);
330 
331  }
332 
333 
334 
335 }
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:302
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:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
const EcalChannelStatus * channelStatus_
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)
T get() const
Definition: EventSetup.h:63
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:44