CMS 3D CMS Logo

TimingClient.cc
Go to the documentation of this file.
2 
4 
7 
9 
10 #include <cmath>
11 
12 namespace ecaldqm {
14  : DQWorkerClient(),
15  ebtoleranceMean_(0.),
16  eetoleranceMean_(0.),
17  toleranceMeanFwd_(0.),
18  toleranceRMS_(0.),
19  toleranceRMSFwd_(0.),
20  minChannelEntries_(0),
21  minChannelEntriesFwd_(0),
22  minTowerEntries_(0),
23  minTowerEntriesFwd_(0),
24  tailPopulThreshold_(0.) {
25  qualitySummaries_.insert("Quality");
26  qualitySummaries_.insert("QualitySummary");
27  }
28 
30  ebtoleranceMean_ = _params.getUntrackedParameter<double>("ebtoleranceMean");
31  eetoleranceMean_ = _params.getUntrackedParameter<double>("eetoleranceMean");
32  toleranceMeanFwd_ = _params.getUntrackedParameter<double>("toleranceMeanFwd");
33  toleranceRMS_ = _params.getUntrackedParameter<double>("toleranceRMS");
34  toleranceRMSFwd_ = _params.getUntrackedParameter<double>("toleranceRMSFwd");
35  minChannelEntries_ = _params.getUntrackedParameter<int>("minChannelEntries");
36  minChannelEntriesFwd_ = _params.getUntrackedParameter<int>("minChannelEntriesFwd");
37  minTowerEntries_ = _params.getUntrackedParameter<int>("minTowerEntries");
38  minTowerEntriesFwd_ = _params.getUntrackedParameter<int>("minChannelEntriesFwd");
39  tailPopulThreshold_ = _params.getUntrackedParameter<double>("tailPopulThreshold");
40  }
41 
43  MESet& meQuality(MEs_.at("Quality"));
44  MESet& meMeanSM(MEs_.at("MeanSM"));
45  MESet& meMeanAll(MEs_.at("MeanAll"));
46  MESet& meFwdBkwdDiff(MEs_.at("FwdBkwdDiff"));
47  MESet& meFwdvBkwd(MEs_.at("FwdvBkwd"));
48  MESet& meRMSMap(MEs_.at("RMSMap"));
49  MESet& meRMSAll(MEs_.at("RMSAll"));
50  MESet& meProjEta(MEs_.at("ProjEta"));
51  MESet& meProjPhi(MEs_.at("ProjPhi"));
52  MESet& meQualitySummary(MEs_.at("QualitySummary"));
53 
54  MESet const& sTimeAllMap(sources_.at("TimeAllMap"));
55  MESet const& sTimeMap(sources_.at("TimeMap"));
56  MESet const& sTimeMapByLS(sources_.at("TimeMapByLS"));
57  MESet const& sChStatus(sources_.at("ChStatus"));
58 
60 
61  MESet::iterator qEnd(meQuality.end(GetElectronicsMap()));
62 
63  MESet::iterator rItr(GetElectronicsMap(), meRMSMap);
64  MESet::const_iterator tItr(GetElectronicsMap(), sTimeMap);
65  MESet::const_iterator tLSItr(GetElectronicsMap(), sTimeMapByLS);
66 
67  float EBentries(0.), EEentries(0.);
68  float EBmean(0.), EEmean(0.);
69  float EBrms(0.), EErms(0.);
70  for (MESet::iterator qItr(meQuality.beginChannel(GetElectronicsMap())); qItr != qEnd;
72  tItr = qItr;
73  rItr = qItr;
74 
75  DetId id(qItr->getId());
76 
78  float meanThresh;
79  float rmsThresh(toleranceRMS_);
80 
81  if (id.subdetId() == EcalBarrel)
82  meanThresh = ebtoleranceMean_;
83  else
84  meanThresh = eetoleranceMean_;
85 
86  if (isForward(id)) {
88  meanThresh = toleranceMeanFwd_;
89  rmsThresh = toleranceRMSFwd_;
90  }
91 
92  bool doMask(meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
93 
94  float entries(tItr->getBinEntries());
95 
96  if (entries < minChannelEntries) {
97  qItr->setBinContent(doMask ? kMUnknown : kUnknown);
98  rItr->setBinContent(-1.);
99  continue;
100  }
101 
102  float mean(tItr->getBinContent());
103  float rms(tItr->getBinError() * sqrt(entries));
104 
105  meMeanSM.fill(getEcalDQMSetupObjects(), id, mean);
106  meMeanAll.fill(getEcalDQMSetupObjects(), id, mean);
107  meProjEta.fill(getEcalDQMSetupObjects(), id, mean);
108  meProjPhi.fill(getEcalDQMSetupObjects(), id, mean);
109  meRMSAll.fill(getEcalDQMSetupObjects(), id, rms);
110  rItr->setBinContent(rms);
111 
112  bool negative(false);
113  float posTime(0.);
114 
115  if (id.subdetId() == EcalBarrel) {
116  EBDetId ebid(id);
117  if (ebid.zside() < 0) {
118  negative = true;
119  EBDetId posId(EBDetId::switchZSide(ebid));
120  posTime = sTimeMap.getBinContent(getEcalDQMSetupObjects(), posId);
121  }
122  } else {
123  EEDetId eeid(id);
124  if (eeid.zside() < 0) {
125  negative = true;
126  EEDetId posId(EEDetId::switchZSide(eeid));
127  posTime = sTimeMap.getBinContent(getEcalDQMSetupObjects(), posId);
128  }
129  }
130  if (negative) {
131  meFwdBkwdDiff.fill(getEcalDQMSetupObjects(), id, posTime - mean);
132  meFwdvBkwd.fill(getEcalDQMSetupObjects(), id, mean, posTime);
133  }
134 
135  if (std::abs(mean) > meanThresh || rms > rmsThresh)
136  qItr->setBinContent(doMask ? kMBad : kBad);
137  else
138  qItr->setBinContent(doMask ? kMGood : kGood);
139 
140  // For Trend plots:
141  tLSItr = qItr;
142  float entriesLS(tLSItr->getBinEntries());
143  float meanLS(tLSItr->getBinContent());
144  float rmsLS(tLSItr->getBinError() * sqrt(entriesLS));
145  float chStatus(sChStatus.getBinContent(getEcalDQMSetupObjects(), id));
146 
147  if (entriesLS < minChannelEntries)
148  continue;
149  if (chStatus != EcalChannelStatusCode::kOk)
150  continue; // exclude problematic channels
151 
152  // Keep running count of timing mean, rms, and N_hits
153  if (id.subdetId() == EcalBarrel) {
154  EBmean += meanLS;
155  EBrms += rmsLS;
156  EBentries += entriesLS;
157  } else {
158  EEmean += meanLS;
159  EErms += rmsLS;
160  EEentries += entriesLS;
161  }
162 
163  } // channel loop
164 
165  // Fill Timing Trend plots at each LS
166  MESet& meTrendMean(MEs_.at("TrendMean"));
167  MESet& meTrendRMS(MEs_.at("TrendRMS"));
168  if (EBentries > 0.) {
169  if (std::abs(EBmean) > 0.)
170  meTrendMean.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), EBmean / EBentries);
171  if (std::abs(EBrms) > 0.)
172  meTrendRMS.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), EBrms / EBentries);
173  }
174  if (EEentries > 0.) {
175  if (std::abs(EEmean) > 0.)
176  meTrendMean.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), EEmean / EEentries);
177  if (std::abs(EErms) > 0.)
178  meTrendRMS.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), EErms / EEentries);
179  }
180 
181  MESet::iterator qsEnd(meQualitySummary.end(GetElectronicsMap()));
182 
183  for (MESet::iterator qsItr(meQualitySummary.beginChannel(GetElectronicsMap())); qsItr != qsEnd;
184  qsItr.toNextChannel(GetElectronicsMap())) {
185  DetId tId(qsItr->getId());
186 
187  std::vector<DetId> ids;
188 
189  if (tId.subdetId() == EcalTriggerTower)
191  else
192  ids = scConstituents(EcalScDetId(tId));
193 
195  float meanThresh;
196  float rmsThresh(toleranceRMS_);
197 
198  if (tId.subdetId() == EcalBarrel)
199  meanThresh = ebtoleranceMean_;
200  else
201  meanThresh = eetoleranceMean_;
202 
203  if (isForward(tId)) {
205  meanThresh = toleranceMeanFwd_;
206  rmsThresh = toleranceRMSFwd_;
207  }
208 
209  // tower entries != sum(channel entries) because of the difference in timing cut at the source
210  float summaryEntries(sTimeAllMap.getBinEntries(getEcalDQMSetupObjects(), tId));
211 
212  float towerEntries(0.);
213  float towerMean(0.);
214  float towerMean2(0.);
215 
216  bool doMask(false);
217 
218  for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr) {
219  DetId& id(*idItr);
220 
221  doMask |= meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap());
222 
223  MESet::const_iterator tmItr(GetElectronicsMap(), sTimeMap, id);
224 
225  float entries(tmItr->getBinEntries());
226  if (entries < 0.)
227  continue;
228  towerEntries += entries;
229  float mean(tmItr->getBinContent());
230  towerMean += mean * entries;
231  float rms(tmItr->getBinError() * sqrt(entries));
232  towerMean2 += (rms * rms + mean * mean) * entries;
233  }
234 
235  double quality(doMask ? kMUnknown : kUnknown);
236  if (towerEntries / ids.size() > minTowerEntries / 25.) {
237  if (summaryEntries < towerEntries * (1. - tailPopulThreshold_)) // large timing deviation
238  quality = doMask ? kMBad : kBad;
239  else {
240  towerMean /= towerEntries;
241  towerMean2 /= towerEntries;
242 
243  float towerRMS(sqrt(towerMean2 - towerMean * towerMean));
244 
245  if (std::abs(towerMean) > meanThresh || towerRMS > rmsThresh)
246  quality = doMask ? kMBad : kBad;
247  else
248  quality = doMask ? kMGood : kGood;
249  }
250  }
251  qsItr->setBinContent(quality);
252  }
253  }
254 
256 } // namespace ecaldqm
double getBinContent() const
Definition: MESet.h:192
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
edm::LuminosityBlockNumber_t iLumi
Definition: DQWorker.h:48
static const int PHYSICS_BAD_CHANNEL_WARNING
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
MESet & at(const std::string &key)
Definition: MESet.h:399
const_iterator & toNextChannel(EcalElectronicsMapping const *electronicsMap)
Definition: MESet.h:320
bool isForward(DetId const &)
EEDetId switchZSide() const
Definition: EEDetId.cc:402
string quality
std::set< std::string > qualitySummaries_
void setParams(edm::ParameterSet const &) override
Definition: TimingClient.cc:29
T sqrt(T t)
Definition: SSEVec.h:19
double getBinEntries() const
Definition: MESet.h:204
StatusManager const * statusManager_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual void fill(EcalDQMSetupObjects const, DetId const &, double=1., double=1., double=1.)
Definition: MESet.h:74
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
EBDetId switchZSide() const
Definition: EBDetId.cc:72
MESetCollection sources_
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
Definition: DetId.h:17
Timestamp timestamp_
Definition: DQWorker.h:134
int zside() const
Definition: EEDetId.h:71
MESetCollection MEs_
Definition: DQWorker.h:131
std::vector< DetId > scConstituents(EcalScDetId const &)
EcalTrigTowerConstituentsMap const * GetTrigTowerMap()
Definition: DQWorker.cc:155
void producePlots(ProcessType) override
Definition: TimingClient.cc:42
double getBinError() const
Definition: MESet.h:198