CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTLocalTriggerLutTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana S. Marcellini - INFN Bologna
5  */
6 
7 
8 // This class header
10 
11 // Framework headers
16 
17 // Geometry
20 
21 // Root
22 #include "TF1.h"
23 #include "TProfile.h"
24 
25 
26 //C++ headers
27 #include <iostream>
28 #include <sstream>
29 
30 using namespace edm;
31 using namespace std;
32 
33 
35 
36  setConfig(ps,"DTLocalTriggerLut");
37  baseFolderDCC = "DT/03-LocalTrigger-DCC/";
38  baseFolderDDU = "DT/04-LocalTrigger-DDU/";
39  thresholdPhiMean = ps.getUntrackedParameter<double>("thresholdPhiMean",1.5);
40  thresholdPhiRMS = ps.getUntrackedParameter<double>("thresholdPhiRMS",.5);
41  thresholdPhibMean = ps.getUntrackedParameter<double>("thresholdPhibMean",1.5);
42  thresholdPhibRMS = ps.getUntrackedParameter<double>("thresholdPhibRMS",.8);
43  doCorrStudy = ps.getUntrackedParameter<bool>("doCorrelationStudy",false);
44 
45 
46 }
47 
48 
50 
51 }
52 
53 
55 
57 
58  vector<string>::const_iterator iTr = trigSources.begin();
59  vector<string>::const_iterator trEnd = trigSources.end();
60  vector<string>::const_iterator iHw = hwSources.begin();
61  vector<string>::const_iterator hwEnd = hwSources.end();
62 
63  //Booking
64  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
65  for (; iTr != trEnd; ++iTr){
66  trigSource = (*iTr);
67  for (; iHw != hwEnd; ++iHw){
68  hwSource = (*iHw);
69  // Loop over the TriggerUnits
70  for (int wh=-2; wh<=2; ++wh){
71  bookWheelHistos(wh,"PhiResidualMean");
72  bookWheelHistos(wh,"PhiResidualRMS");
73  bookWheelHistos(wh,"PhibResidualMean");
74  bookWheelHistos(wh,"PhibResidualRMS");
75  if (doCorrStudy) {
76  bookWheelHistos(wh,"PhiTkvsTrigSlope");
77  bookWheelHistos(wh,"PhiTkvsTrigIntercept");
78  bookWheelHistos(wh,"PhiTkvsTrigCorr");
79  bookWheelHistos(wh,"PhibTkvsTrigSlope");
80  bookWheelHistos(wh,"PhibTkvsTrigIntercept");
81  bookWheelHistos(wh,"PhibTkvsTrigCorr");
82  }
83  }
84  }
85  }
86  }
87 
88  // Summary test histo booking (only static)
89  for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
90  trigSource = (*iTr);
91  for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
92  hwSource = (*iHw);
93  // Loop over the TriggerUnits
94  for (int wh=-2; wh<=2; ++wh){
95  bookWheelHistos(wh,"PhiLutSummary");
96  bookWheelHistos(wh,"PhibLutSummary");
97  }
98  bookCmsHistos("PhiLutSummary");
99  bookCmsHistos("PhibLutSummary");
100  }
101  }
102 
103 }
104 
105 
107 
109 
110 }
111 
112 
114 
115  // Loop over Trig & Hw sources
116  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
117  trigSource = (*iTr);
118  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
119  hwSource = (*iHw);
120  vector<const DTChamber*>::const_iterator chIt = muonGeom->chambers().begin();
121  vector<const DTChamber*>::const_iterator chEnd = muonGeom->chambers().end();
122  for (; chIt != chEnd; ++chIt) {
123  DTChamberId chId((*chIt)->id());
124  int wh = chId.wheel();
125  int sect = chId.sector();
126  int stat = chId.station();
127 
128 
129  if (doCorrStudy) {
130  // Perform Correlation Plots analysis (DCC + segment Phi)
131  TH2F * TrackPhitkvsPhitrig = getHisto<TH2F>(dbe->get(getMEName("PhitkvsPhitrig","Segment", chId)));
132 
133  if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries()>10) {
134 
135  // Fill client histos
136  if( whME[wh].find(fullName("PhiTkvsTrigCorr")) == whME[wh].end() ){
137  bookWheelHistos(wh,"PhiTkvsTrigSlope");
138  bookWheelHistos(wh,"PhiTkvsTrigIntercept");
139  bookWheelHistos(wh,"PhiTkvsTrigCorr");
140  }
141 
142  TProfile* PhitkvsPhitrigProf = TrackPhitkvsPhitrig->ProfileX();
143  double phiInt = 0;
144  double phiSlope = 0;
145  double phiCorr = 0;
146  try {
147  TF1 ffPhi("mypol1","pol1");
148  PhitkvsPhitrigProf->Fit(&ffPhi,"CQO");
149  phiInt = ffPhi.GetParameter(0);
150  phiSlope = ffPhi.GetParameter(1);
151  phiCorr = TrackPhitkvsPhitrig->GetCorrelationFactor();
152  } catch (cms::Exception& iException) {
153  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhitkvsPhitrig for Wheel " << wh
154  <<" Sector " << sect << " Station " << stat;
155  }
156 
157  std::map<std::string,MonitorElement*> &innerME = whME[wh];
158  fillWhPlot(innerME.find(fullName("PhiTkvsTrigSlope"))->second,sect,stat,phiSlope-1);
159  fillWhPlot(innerME.find(fullName("PhiTkvsTrigIntercept"))->second,sect,stat,phiInt);
160  fillWhPlot(innerME.find(fullName("PhiTkvsTrigCorr"))->second,sect,stat,phiCorr,false);
161 
162  }
163 
164  // Perform Correlation Plots analysis (DCC + segment Phib)
165  TH2F * TrackPhibtkvsPhibtrig = getHisto<TH2F>(dbe->get(getMEName("PhibtkvsPhibtrig","Segment", chId)));
166 
167  if (stat != 3 && TrackPhibtkvsPhibtrig && TrackPhibtkvsPhibtrig->GetEntries()>10) {// station 3 has no meaningful MB3 phi bending information
168 
169  // Fill client histos
170  if( whME[wh].find(fullName("PhibTkvsTrigCorr")) == whME[wh].end() ){
171  bookWheelHistos(wh,"PhibTkvsTrigSlope");
172  bookWheelHistos(wh,"PhibTkvsTrigIntercept");
173  bookWheelHistos(wh,"PhibTkvsTrigCorr");
174  }
175 
176  TProfile* PhibtkvsPhibtrigProf = TrackPhibtkvsPhibtrig->ProfileX();
177  double phibInt = 0;
178  double phibSlope = 0;
179  double phibCorr = 0;
180  try {
181  TF1 ffPhib("ffPhib","pol1");
182  PhibtkvsPhibtrigProf->Fit(&ffPhib,"CQO");
183  phibInt = ffPhib.GetParameter(0);
184  phibSlope = ffPhib.GetParameter(1);
185  phibCorr = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
186  } catch (cms::Exception& iException) {
187  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibtkvsPhibtrig for Wheel " << wh
188  <<" Sector " << sect << " Station " << stat;
189  }
190 
191  std::map<std::string,MonitorElement*> &innerME = whME[wh];
192  fillWhPlot(innerME.find(fullName("PhibTkvsTrigSlope"))->second,sect,stat,phibSlope-1);
193  fillWhPlot(innerME.find(fullName("PhibTkvsTrigIntercept"))->second,sect,stat,phibInt);
194  fillWhPlot(innerME.find(fullName("PhibTkvsTrigCorr"))->second,sect,stat,phibCorr,false);
195 
196  }
197 
198  }
199 
200  // Make Phi Residual Summary
201  TH1F * PhiResidual = getHisto<TH1F>(dbe->get(getMEName("PhiResidual","Segment", chId)));
202  int phiSummary = 1;
203 
204  if (PhiResidual && PhiResidual->GetEffectiveEntries()>10) {
205 
206  // Fill client histos
207  if( whME[wh].find(fullName("PhiResidualMean")) == whME[wh].end() ){
208  bookWheelHistos(wh,"PhiResidualMean");
209  bookWheelHistos(wh,"PhiResidualRMS");
210  }
211 
212  double peak = PhiResidual->GetBinCenter(PhiResidual->GetMaximumBin());
213  double phiMean = 0;
214  double phiRMS = 0;
215  try {
216  TF1 ffPhi("ffPhi","gaus");
217  PhiResidual->Fit(&ffPhi,"CQO","",peak-5,peak+5);
218  phiMean = ffPhi.GetParameter(1);
219  phiRMS = ffPhi.GetParameter(2);
220  } catch (cms::Exception& iException) {
221  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhiResidual for Wheel " << wh
222  <<" Sector " << sect << " Station " << stat;
223  }
224 
225  std::map<std::string,MonitorElement*> &innerME = whME[wh];
226  fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second,sect,stat,phiMean);
227  fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second,sect,stat,phiRMS);
228 
229  phiSummary = performLutTest(phiMean,phiRMS,thresholdPhiMean,thresholdPhiRMS);
230 
231  }
232  fillWhPlot(whME[wh].find(fullName("PhiLutSummary"))->second,sect,stat,phiSummary);
233 
234  // Make Phib Residual Summary
235  TH1F * PhibResidual = getHisto<TH1F>(dbe->get(getMEName("PhibResidual","Segment", chId)));
236  int phibSummary = stat==3 ? 0 : 1; // station 3 has no meaningful MB3 phi bending information
237 
238  if (stat != 3 && PhibResidual && PhibResidual->GetEffectiveEntries()>10) {// station 3 has no meaningful MB3 phi bending information
239 
240  // Fill client histos
241  if( whME[wh].find(fullName("PhibResidualMean")) == whME[wh].end() ){
242  bookWheelHistos(wh,"PhibResidualMean");
243  bookWheelHistos(wh,"PhibResidualRMS");
244  }
245 
246  double peak = PhibResidual->GetBinCenter(PhibResidual->GetMaximumBin());
247  double phibMean = 0;
248  double phibRMS = 0;
249  try {
250  TF1 ffPhib("ffPhib","gaus");
251  PhibResidual->Fit(&ffPhib,"CQO","",peak-5,peak+5);
252  phibMean = ffPhib.GetParameter(1);
253  phibRMS = ffPhib.GetParameter(2);
254  } catch (cms::Exception& iException) {
255  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibResidual for Wheel " << wh
256  <<" Sector " << sect << " Station " << stat;
257  }
258 
259  std::map<std::string,MonitorElement*> &innerME = whME[wh];
260  fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second,sect,stat,phibMean);
261  fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second,sect,stat,phibRMS);
262 
263  phibSummary = performLutTest(phibMean,phibRMS,thresholdPhibMean,thresholdPhibRMS);
264 
265  }
266  fillWhPlot(whME[wh].find(fullName("PhibLutSummary"))->second,sect,stat,phibSummary);
267 
268  }
269  }
270  }
271 
272  // Barrel Summary Plots
273  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
274  trigSource = (*iTr);
275  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
276  hwSource = (*iHw);
277  for (int wh=-2; wh<=2; ++wh){
278  std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
279 
280  TH2F* phiWhSummary = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
281  TH2F* phibWhSummary = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
282  for (int sect=1; sect<=12; ++sect){
283  int phiErr = 0;
284  int phibErr = 0;
285  int phiNoData = 0;
286  int phibNoData = 0;
287  for (int stat=1; stat<=4; ++stat){
288  switch (static_cast<int>(phiWhSummary->GetBinContent(sect,stat))) {
289  case 1:
290  phiNoData++;
291  case 2:
292  case 3:
293  phiErr++;
294  }
295  switch (static_cast<int>(phibWhSummary->GetBinContent(sect,stat))) {
296  case 1:
297  phibNoData++;
298  case 2:
299  case 3:
300  phibErr++;
301  }
302  }
303  if (phiNoData == 4) phiErr = 5;
304  if (phibNoData == 3) phibErr = 5; // MB3 has no phib information
305  cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect,wh+3,phiErr);
306  cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect,wh+3,phibErr);
307  }
308  }
309  }
310  }
311 
312 }
313 
314 int DTLocalTriggerLutTest::performLutTest(double mean,double RMS,double thresholdMean,double thresholdRMS) {
315 
316  bool meanErr = fabs(mean)>thresholdMean;
317  bool rmsErr = RMS>thresholdRMS;
318 
319  return (meanErr || rmsErr) ? 2+(meanErr!=rmsErr) : 0 ;
320 
321 }
322 
323 void DTLocalTriggerLutTest::fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest) {
324 
325  if (sect>12) {
326  int scsect = sect==13 ? 4 : 10;
327  if ( (fabs(value)>fabs(plot->getBinContent(scsect,stat)))==lessIsBest) {
328  plot->setBinContent(scsect,stat,value);
329  }
330  }
331  else {
332  plot->setBinContent(sect,stat,value);
333  }
334 
335  return;
336 
337 }
338 
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
void setBinContent(int binx, double content)
set content of bin (1-D)
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
int performLutTest(double mean, double RMS, double thresholdMean, double thresholdRMS)
Perform Lut Test logical operations.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest=true)
Fill summary plots managing double MB4 chambers.
U second(std::pair< T, U > const &p)
void runClientDiagnostic()
Run client analysis.
string fullName
double getBinContent(int binx) const
get content of bin (1-D)
DTLocalTriggerLutTest(const edm::ParameterSet &ps)
Constructor.
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
virtual ~DTLocalTriggerLutTest()
Destructor.
Definition: Run.h:41