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(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(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  // check if there are large variations wrt exisiting pedstals
99 
100  if (checkAnomalies_){
101  if (checkVariation(*currentPedestals_, pedestals)) {
102  edm::LogError("Large Variations found wrt to old pedestals, no file created");
103  return;
104  }
105  }
106 
107  // write out pedestal record
109 
110  if( poolDbService.isAvailable() )
111  poolDbService->writeOne( &pedestals, poolDbService->currentTime(),
112  "EcalPedestalsRcd" );
113  else
114  throw std::runtime_error("PoolDBService required.");
115 }
116 
117 
118 
119 
120 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
121 void
123 
125  desc.setUnknown();
126  descriptions.addDefault(desc);
127 }
128 
129 
131 
132 
134  isetup.get<EcalChannelStatusRcd>().get(chStatus);
135  channelStatus_=chStatus.product();
136 
138  isetup.get<EcalPedestalsRcd>().get(peds);
139  currentPedestals_=peds.product();
140 
141 }
142 
144 
146  dbstatusPtr = channelStatus_->getMap().find(id.rawId());
147  EcalChannelStatusCode::Code dbstatus = dbstatusPtr->getStatusCode();
148 
149  std::vector<int>::const_iterator res =
150  std::find( chStatusToExclude_.begin(), chStatusToExclude_.end(), dbstatus );
151  if ( res != chStatusToExclude_.end() ) return false;
152 
153  return true;
154 }
155 
156 
158  const EcalPedestalsMap& newPedestals) {
159 
160  uint32_t nAnomaliesEB =0;
161  uint32_t nAnomaliesEE =0;
162 
163  for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) {
164 
166  const EcalPedestal& newped=* newPedestals.find(id.rawId());
167  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
168 
169  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++;
170 
171  }
172 
173  for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) {
174 
176  const EcalPedestal& newped=* newPedestals.find(id.rawId());
177  const EcalPedestal& oldped=* oldPedestals.find(id.rawId());
178 
179  if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++;
180 
181  }
182 
183  if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing ||
184  nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing)
185  return true;
186 
187  return false;
188 
189 
190 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
T getParameter(std::string const &) const
const self & getMap() const
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
virtual void endRun(edm::Run const &run, edm::EventSetup const &isetup)
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
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)
Definition: DetId.h:18
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_)