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
17 #include <iostream>
18 #include <string>
19 
21  currentPedestals_(0),channelStatus_(0){
22 
23  chStatusToExclude_= StringToEnumValue<EcalChannelStatusCode::Code>(ps.getParameter<std::vector<std::string> >("ChannelStatusToExclude"));
24  minEntries_=ps.getParameter<int>("MinEntries");
25  checkAnomalies_ = ps.getParameter<bool>("checkAnomalies");
26  nSigma_ = ps.getParameter<double>("nSigma");
27  thresholdAnomalies_ = ps.getParameter<double>("thresholdAnomalies");
28  dqmDir_ = ps.getParameter<std::string>("dqmDir");
29 }
30 
32 
33 
34  // calculate pedestals and fill db record
35  EcalPedestals pedestals;
36 
37 
38  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
39  std::string hname = dqmDir_+"/EB/"+std::to_string(int(i/100))+"/eb_" + std::to_string(i);
40  MonitorElement* ch= igetter_.get(hname);
41  double mean = ch->getMean();
42  double rms = ch->getRMS();
43 
45  EcalPedestal ped;
46  EcalPedestal oldped=* currentPedestals_->find(id.rawId());
47 
48  ped.mean_x12=mean;
49  ped.rms_x12=rms;
50 
51  // if bad channel or low stat skip
52  if(ch->getEntries()< minEntries_ || !checkStatusCode(id)){
53 
54  ped.mean_x12=oldped.mean_x12;
55  ped.rms_x12=oldped.rms_x12;
56 
57  }
58 
59  ped.mean_x6=oldped.mean_x6;
60  ped.rms_x6=oldped.rms_x6;
61  ped.mean_x1=oldped.mean_x1;
62  ped.rms_x1=oldped.rms_x1;
63 
64  pedestals.setValue(id.rawId(),ped);
65  }
66 
67 
68  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
69 
70  std::string hname = dqmDir_+"/EE/"+std::to_string(int(i/100))+"/ee_" + std::to_string(i);
71 
72  MonitorElement* ch= igetter_.get(hname);
73  double mean = ch->getMean();
74  double rms = ch->getRMS();
75 
77  EcalPedestal ped;
78  EcalPedestal oldped= *currentPedestals_->find(id.rawId());
79 
80  ped.mean_x12=mean;
81  ped.rms_x12=rms;
82 
83  // if bad channel or low stat skip
84  if(ch->getEntries()< minEntries_ || !checkStatusCode(id)){
85  ped.mean_x12=oldped.mean_x12;
86  ped.rms_x12=oldped.rms_x12;
87  }
88 
89  ped.mean_x6=oldped.mean_x6;
90  ped.rms_x6=oldped.rms_x6;
91  ped.mean_x1=oldped.mean_x1;
92  ped.rms_x1=oldped.rms_x1;
93 
94  pedestals.setValue(id.rawId(),ped);
95  }
96 
97 
98 
99  dqmPlots(pedestals, ibooker_);
100 
101  // check if there are large variations wrt exisiting pedstals
102 
103  if (checkAnomalies_){
104  if (checkVariation(*currentPedestals_, pedestals)) {
105  edm::LogError("Large Variations found wrt to old pedestals, no file created");
106  return;
107  }
108  }
109 
110  // write out pedestal record
112 
113  if( poolDbService.isAvailable() )
114  poolDbService->writeOne( &pedestals, poolDbService->currentTime(),
115  "EcalPedestalsRcd" );
116  else
117  throw std::runtime_error("PoolDBService required.");
118 }
119 
120 
121 
122 
123 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
124 void
126 
128  desc.setUnknown();
129  descriptions.addDefault(desc);
130 }
131 
132 
134 
135 
137  isetup.get<EcalChannelStatusRcd>().get(chStatus);
138  channelStatus_=chStatus.product();
139 
141  isetup.get<EcalPedestalsRcd>().get(peds);
142  currentPedestals_=peds.product();
143 
144 }
145 
147 
149  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
150  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
151 
152  std::vector<int>::const_iterator res =
153  std::find( chStatusToExclude_.begin(), chStatusToExclude_.end(), dbstatus );
154  if ( res != chStatusToExclude_.end() ) return false;
155 
156  return true;
157 }
158 
159 
161  const EcalPedestalsMap& newPedestals) {
162 
163  uint32_t nAnomaliesEB =0;
164  uint32_t nAnomaliesEE =0;
165 
166  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
167 
169  const EcalPedestal& newped=* newPedestals.find(id.rawId());
170  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
171 
172  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++;
173 
174  }
175 
176  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
177 
179  const EcalPedestal& newped=* newPedestals.find(id.rawId());
180  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
181 
182  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++;
183 
184  }
185 
186  if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing ||
187  nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing)
188  return true;
189 
190  return false;
191 
192 
193 }
194 
195 
196 
197 
199 
200  ibooker.cd();
201  ibooker.setCurrentFolder(dqmDir_+"/Summary");
202 
203  MonitorElement * pmeb = ibooker.book2D("meaneb","Pedestal Means",360, 1., 361., 171, -85., 86.);
204  MonitorElement * preb = ibooker.book2D("rmseb","Pedestal RMS",360, 1., 361., 171, -85., 86.);
205 
206  MonitorElement * pmeep = ibooker.book2D("meaneep","Pedestal Means",100,1,101,100,1,101);
207  MonitorElement * preep = ibooker.book2D("rmseep","Pedestal RMS",100,1,101,100,1,101);
208 
209  MonitorElement * pmeem = ibooker.book2D("meaneem","Pedestal Means",100,1,101,100,1,101);
210  MonitorElement * preem = ibooker.book2D("rmseem","Pedestal RMS",100,1,101,100,1,101);
211 
212  MonitorElement * pmebd = ibooker.book2D("meanebdiff","Pedestal Means Diff",360, 1., 361., 171, -85., 86.);
213  MonitorElement * prebd = ibooker.book2D("rmsebdiff","Pedestal RMS Diff",360, 1., 361., 171, -85., 86.);
214 
215  MonitorElement * pmeepd = ibooker.book2D("meaneepdiff","Pedestal Means Diff",100,1,101,100,1,101);
216  MonitorElement * preepd = ibooker.book2D("rmseepdiff","Pedestal RMS Diff",100,1,101,100,1,101);
217 
218  MonitorElement * pmeemd = ibooker.book2D("meaneemdiff","Pedestal Means Diff",100,1,101,100,1,101);
219  MonitorElement * preemd = ibooker.book2D("rmseemdiff","Pedestal RMS Diff",100,1,101,100,1,101);
220 
221 
223 
225  float mean= newpeds[di].mean_x12;
226  float rms = newpeds[di].rms_x12;
227 
228  float cmean = (*currentPedestals_)[di].mean_x12;
229  float crms = (*currentPedestals_)[di].rms_x12;
230 
231  pmeb->Fill(di.iphi(),di.ieta(),mean);
232  preb->Fill(di.iphi(),di.ieta(),rms);
233  pmebd->Fill(di.iphi(),di.ieta(),(mean-cmean)/cmean);
234  prebd->Fill(di.iphi(),di.ieta(),(rms-crms)/crms);
235 
236  }
237 
238 
240 
242  float mean= newpeds[di].mean_x12;
243  float rms = newpeds[di].rms_x12;
244  float cmean = (*currentPedestals_)[di].mean_x12;
245  float crms = (*currentPedestals_)[di].rms_x12;
246 
247  if (di.zside() >0){
248  pmeep->Fill(di.ix(),di.iy(),mean);
249  preep->Fill(di.ix(),di.iy(),rms);
250  pmeepd->Fill(di.ix(),di.iy(),(mean-cmean)/cmean);
251  preepd->Fill(di.ix(),di.iy(),(rms-crms)/crms);
252  } else{
253  pmeem->Fill(di.ix(),di.iy(),mean);
254  preem->Fill(di.ix(),di.iy(),rms);
255  pmeemd->Fill(di.ix(),di.iy(),(mean-cmean)/cmean);
256  preemd->Fill(di.ix(),di.iy(),(rms-crms)/crms);
257  }
258 
259  }
260 
261 
262 
263 }
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
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)
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
Definition: Electron.h:4
void Fill(long long x)
virtual void endRun(edm::Run const &run, edm::EventSetup const &isetup)
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)
std::vector< int > chStatusToExclude_
bool isAvailable() const
Definition: Service.h:46
int zside() const
Definition: EEDetId.h:70
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:56
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
T const * product() const
Definition: ESHandle.h:86
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:42
virtual void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)