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