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