CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTtTrigCalibrationTest.cc
Go to the documentation of this file.
1 /*
2  * \file DTtTrigCalibrationTest.cc
3  *
4  * \author M. Zanetti - CERN
5  * Modified by G. Mila - INFN Torino
6  *
7  */
8 
9 
11 
12 // Framework
14 
15 
16 // Geometry
19 
22 
26 
27 // the Timebox fitter
29 
30 #include <stdio.h>
31 #include <sstream>
32 #include <math.h>
33 
34 using namespace edm;
35 using namespace std;
36 
38 
39  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: Constructor";
40 
41  parameters = ps;
42 
43  dbe = edm::Service<DQMStore>().operator->();
44 
45  theFitter = new DTTimeBoxFitter();
46 
47  prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 3);
48 
49  percentual = parameters.getUntrackedParameter<int>("BadSLpercentual", 10);
50 
51 }
52 
53 
55 
56  edm::LogVerbatim ("tTrigCalibration") <<"DTtTrigCalibrationTest: analyzed " << nevents << " events";
57 
58  delete theFitter;
59 
60 }
61 
62 
64 
65  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: BeginJob";
66 
67  nevents = 0;
68 
69 }
70 
71 
72 void DTtTrigCalibrationTest::beginRun(Run const& run, EventSetup const& context) {
73 
74  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: BeginRun";
75 
76  // Get the geometry
77  context.get<MuonGeometryRecord>().get(muonGeom);
78 
79 }
80 
82 
83  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: Begin of LS transition";
84 
85  // Get the run number
86  run = lumiSeg.run();
87 
88 }
89 
90 
92 
93  nevents++;
94  edm::LogVerbatim ("tTrigCalibration") << "[DTtTrigCalibrationTest]: "<<nevents<<" events";
95 
96 }
97 
98 
100 
101 
102  // counts number of updats (online mode) or number of events (standalone mode)
103  //nevents++;
104  // if running in standalone perform diagnostic only after a reasonalbe amount of events
105  //if ( parameters.getUntrackedParameter<bool>("runningStandalone", false) &&
106  // nevents%parameters.getUntrackedParameter<int>("diagnosticPrescale", 1000) != 0 ) return;
107  //edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: "<<nevents<<" updates";
108 
109 
110  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: End of LS transition, performing the DQM client operation";
111 
112  // counts number of lumiSegs
113  nLumiSegs = lumiSeg.id().luminosityBlock();
114 
115  // prescale factor
116  if ( nLumiSegs%prescaleFactor != 0 ) return;
117 
118  for(map<int, MonitorElement*> ::const_iterator histo = wheelHistos.begin();
119  histo != wheelHistos.end();
120  histo++) {
121  (*histo).second->Reset();
122  }
123 
124  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: "<<nLumiSegs<<" updates";
125 
126  context.get<DTTtrigRcd>().get(tTrigMap);
127  float tTrig, tTrigRMS,kFactor;
128 
129  map <pair<int,int>, int> cmsHistos;
130  cmsHistos.clear();
131  map <pair<int,int>, bool> filled;
132  for(int i=-2; i<3; i++){
133  for(int j=1; j<15; j++){
134  filled[make_pair(i,j)]=false;
135  }
136  }
137 
138  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
139  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
140  for (; ch_it != ch_end; ++ch_it) {
141 
142  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
143  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
144  for(; sl_it != sl_end; ++sl_it) {
145 
146  DTSuperLayerId slID = (*sl_it)->id();
147 
148  MonitorElement * tb_histo = dbe->get(getMEName(slID));
149  if (tb_histo) {
150 
151  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: I've got the histo!!";
152 
153  TH1F * tb_histo_root = tb_histo->getTH1F();
154 
155  pair<double, double> meanAndSigma = theFitter->fitTimeBox(tb_histo_root);
156 
157  // ttrig and rms are counts
158  tTrigMap->get(slID, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
159 
160  if (histos.find((*ch_it)->id().rawId()) == histos.end()) bookHistos((*ch_it)->id());
161  histos.find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(), meanAndSigma.first-tTrig);
162 
163  }
164  }
165 
166  if (histos.find((*ch_it)->id().rawId()) != histos.end()) {
167  string criterionName = parameters.getUntrackedParameter<string>("tTrigTestName","tTrigOffSet");
168  const QReport * theQReport = histos.find((*ch_it)->id().rawId())->second->getQReport(criterionName);
169  if(theQReport) {
170  vector<dqm::me_util::Channel> badChannels = theQReport->getBadChannels();
171  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
172  channel != badChannels.end(); channel++) {
173  edm::LogError ("tTrigCalibration") <<"Chamber ID : "<<(*ch_it)->id()<<" Bad channels: "<<(*channel).getBin()<<" "<<(*channel).getContents();
174  if(wheelHistos.find((*ch_it)->id().wheel()) == wheelHistos.end()) bookHistos((*ch_it)->id(), (*ch_it)->id().wheel());
175  // fill the wheel summary histos if the SL has not passed the test
176  if(!((*ch_it)->id().station() == 4 && (*channel).getBin() == 3))
177  wheelHistos[(*ch_it)->id().wheel()]->Fill((*ch_it)->id().sector()-1,((*channel).getBin()-1)+3*((*ch_it)->id().station()-1));
178  else
179  wheelHistos[(*ch_it)->id().wheel()]->Fill((*ch_it)->id().sector()-1,10);
180  // fill the cms summary histo if the percentual of SL which have not passed the test
181  // is more than a predefined treshold
182  cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]++;
183  if(((*ch_it)->id().sector()<13 &&
184  double(cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())])/11>double(percentual)/100 &&
185  filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]==false) ||
186  ((*ch_it)->id().sector()>=13 &&
187  double(cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())])/2>double(percentual)/100 &&
188  filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]==false)){
189  filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]=true;
190  wheelHistos[3]->Fill((*ch_it)->id().sector()-1,(*ch_it)->id().wheel());
191  }
192  }
193  // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
194  // edm::LogWarning ("tTrigCalibration") <<"-------- "<<theQReport->getMessage()<<" ------- "<<theQReport->getStatus();
195  }
196  }
197 
198  }
199 
200 }
201 
202 
204 
205  edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest] endjob called!";
206 
207  dbe->rmdir("DT/Tests/DTtTrigCalibration");
208 }
209 
210 
211 
212 
214 
215  stringstream wheel; wheel << slID.wheel();
216  stringstream station; station << slID.station();
217  stringstream sector; sector << slID.sector();
218  stringstream superLayer; superLayer << slID.superlayer();
219 
220  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
221  string folderTag = parameters.getUntrackedParameter<string>("folderTag", "TimeBoxes");
222  string folderName =
223  folderRoot + "DT/DTDigiTask/Wheel" + wheel.str() +
224  "/Station" + station.str() +
225  "/Sector" + sector.str() + "/" + folderTag + "/";
226 
227  string histoTag = parameters.getUntrackedParameter<string>("histoTag", "TimeBox");
228  string histoname = folderName + histoTag
229  + "_W" + wheel.str()
230  + "_St" + station.str()
231  + "_Sec" + sector.str()
232  + "_SL" + superLayer.str();
233 
234  return histoname;
235 
236 }
237 
238 
239 
241 
242  stringstream wheel; wheel << ch.wheel();
243  stringstream station; station << ch.station();
244  stringstream sector; sector << ch.sector();
245 
246  string histoName = "tTrigTest_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
247 
248  dbe->setCurrentFolder("DT/Tests/DTtTrigCalibration");
249 
250  histos[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,2);
251 
252 }
253 
255 
256  dbe->setCurrentFolder("DT/Tests/DTtTrigCalibration/SummaryPlot");
257 
258  if(wheelHistos.find(3) == wheelHistos.end()){
259  string histoName = "t_TrigSummary_testFailedByAtLeastBadSL";
260  wheelHistos[3] = dbe->book2D(histoName.c_str(),histoName.c_str(),14,0,14,5,-2,2);
261  wheelHistos[3]->setBinLabel(1,"Sector1",1);
262  wheelHistos[3]->setBinLabel(1,"Sector1",1);
263  wheelHistos[3]->setBinLabel(2,"Sector2",1);
264  wheelHistos[3]->setBinLabel(3,"Sector3",1);
265  wheelHistos[3]->setBinLabel(4,"Sector4",1);
266  wheelHistos[3]->setBinLabel(5,"Sector5",1);
267  wheelHistos[3]->setBinLabel(6,"Sector6",1);
268  wheelHistos[3]->setBinLabel(7,"Sector7",1);
269  wheelHistos[3]->setBinLabel(8,"Sector8",1);
270  wheelHistos[3]->setBinLabel(9,"Sector9",1);
271  wheelHistos[3]->setBinLabel(10,"Sector10",1);
272  wheelHistos[3]->setBinLabel(11,"Sector11",1);
273  wheelHistos[3]->setBinLabel(12,"Sector12",1);
274  wheelHistos[3]->setBinLabel(13,"Sector13",1);
275  wheelHistos[3]->setBinLabel(14,"Sector14",1);
276  wheelHistos[3]->setBinLabel(1,"Wheel-2",2);
277  wheelHistos[3]->setBinLabel(2,"Wheel-1",2);
278  wheelHistos[3]->setBinLabel(3,"Wheel0",2);
279  wheelHistos[3]->setBinLabel(4,"Wheel+1",2);
280  wheelHistos[3]->setBinLabel(5,"Wheel+2",2);
281  }
282 
283  stringstream wheel; wheel <<wh;
284  string histoName = "t_TrigSummary_testFailed_W" + wheel.str();
285  wheelHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),14,0,14,11,0,11);
286  wheelHistos[wh]->setBinLabel(1,"Sector1",1);
287  wheelHistos[wh]->setBinLabel(2,"Sector2",1);
288  wheelHistos[wh]->setBinLabel(3,"Sector3",1);
289  wheelHistos[wh]->setBinLabel(4,"Sector4",1);
290  wheelHistos[wh]->setBinLabel(5,"Sector5",1);
291  wheelHistos[wh]->setBinLabel(6,"Sector6",1);
292  wheelHistos[wh]->setBinLabel(7,"Sector7",1);
293  wheelHistos[wh]->setBinLabel(8,"Sector8",1);
294  wheelHistos[wh]->setBinLabel(9,"Sector9",1);
295  wheelHistos[wh]->setBinLabel(10,"Sector10",1);
296  wheelHistos[wh]->setBinLabel(11,"Sector11",1);
297  wheelHistos[wh]->setBinLabel(12,"Sector12",1);
298  wheelHistos[wh]->setBinLabel(13,"Sector13",1);
299  wheelHistos[wh]->setBinLabel(14,"Sector14",1);
300  wheelHistos[wh]->setBinLabel(1,"MB1_SL1",2);
301  wheelHistos[wh]->setBinLabel(2,"MB1_SL2",2);
302  wheelHistos[wh]->setBinLabel(3,"MB1_SL3",2);
303  wheelHistos[wh]->setBinLabel(4,"MB2_SL1",2);
304  wheelHistos[wh]->setBinLabel(5,"MB2_SL2",2);
305  wheelHistos[wh]->setBinLabel(6,"MB2_SL3",2);
306  wheelHistos[wh]->setBinLabel(7,"MB3_SL1",2);
307  wheelHistos[wh]->setBinLabel(8,"MB3_SL2",2);
308  wheelHistos[wh]->setBinLabel(9,"MB3_SL3",2);
309  wheelHistos[wh]->setBinLabel(10,"MB4_SL1",2);
310  wheelHistos[wh]->setBinLabel(11,"MB4_SL3",2);
311 
312 }
313 
LuminosityBlockID id() const
std::string getMEName(const DTSuperLayerId &slID)
Get the ME name.
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
void bookHistos(const DTChamberId &ch)
book the new ME
void bookHistos()
Definition: Histogram.h:33
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
int superLayer() const
Return the superlayer number.
int j
Definition: DBlmapReader.cc:9
DTtTrigCalibrationTest(const edm::ParameterSet &ps)
Constructor.
RunNumber_t run() const
int nevents
virtual ~DTtTrigCalibrationTest()
Destructor.
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
int superlayer() const
Return the superlayer number (deprecated method name)
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic.
const T & get() const
Definition: EventSetup.h:55
TH1F * getTH1F(void) const
LuminosityBlockNumber_t luminosityBlock() const
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
Definition: Run.h:41