CMS 3D CMS Logo

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