CMS 3D CMS Logo

DTt0DBValidation.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
15 
18 
19 // Geometry
24 
25 // t0
28 
29 #include "TFile.h"
30 
31 #include <iomanip>
32 #include <sstream>
33 
34 using namespace edm;
35 using namespace std;
36 
38  metname_ = "InterChannelSynchDBValidation";
39  LogVerbatim(metname_) << "[DTt0DBValidation] Constructor called!";
40 
41  // Get the DQM needed services
43  dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
44 
45  // Get dataBase label
46  labelDBRef_ = pset.getParameter<string>("labelDBRef");
47  labelDB_ = pset.getParameter<string>("labelDB");
48 
49  t0TestName_ = "t0DifferenceInRange";
50  if (pset.exists("t0TestName"))
51  t0TestName_ = pset.getParameter<string>("t0TestName");
52 
53  outputMEsInRootFile_ = false;
54  if (pset.exists("OutputFileName")) {
55  outputMEsInRootFile_ = true;
56  outputFileName_ = pset.getParameter<std::string>("OutputFileName");
57  }
58 }
59 
61 
63  metname_ = "InterChannelSynchDBValidation";
64  LogVerbatim(metname_) << "[DTt0DBValidation] Parameters initialization";
65 
66  ESHandle<DTT0> t0_Ref;
67  setup.get<DTT0Rcd>().get(labelDBRef_, t0_Ref);
68  tZeroRefMap_ = &*t0_Ref;
69  LogVerbatim(metname_) << "[DTt0DBValidation] reference T0 version: " << t0_Ref->version();
70 
72  setup.get<DTT0Rcd>().get(labelDB_, t0);
73  tZeroMap_ = &*t0;
74  LogVerbatim(metname_) << "[DTt0DBValidation] T0 to validate version: " << t0->version();
75 
76  // book&reset the summary histos
77  for (int wheel = -2; wheel <= 2; wheel++) {
79  wheelSummary_[wheel]->Reset();
80  }
81 
82  // Get the geometry
83  setup.get<MuonGeometryRecord>().get(dtGeom_);
84 
85  // Loop over Ref DB entries
86  for (DTT0::const_iterator tzero = tZeroRefMap_->begin(); tzero != tZeroRefMap_->end(); tzero++) {
87  // t0s and rms are TDC counts
88  // @@@ NEW DTT0 FORMAT
89  // DTWireId wireId((*tzero).first.wheelId,
90  // (*tzero).first.stationId,
91  // (*tzero).first.sectorId,
92  // (*tzero).first.slId,
93  // (*tzero).first.layerId,
94  // (*tzero).first.cellId);
95  int channelId = tzero->channelId;
96  if (channelId == 0)
97  continue;
98  DTWireId wireId(channelId);
99  // @@@ NEW DTT0 END
100  float t0mean;
101  float t0rms;
102  tZeroRefMap_->get(wireId, t0mean, t0rms, DTTimeUnits::counts);
103  LogTrace(metname_) << "Ref Wire: " << wireId << endl
104  << " T0 mean (TDC counts): " << t0mean << " T0_rms (TDC counts): " << t0rms;
105 
106  t0RefMap_[wireId].push_back(t0mean);
107  t0RefMap_[wireId].push_back(t0rms);
108  }
109 
110  // Loop over Ref DB entries
111  for (DTT0::const_iterator tzero = tZeroMap_->begin(); tzero != tZeroMap_->end(); tzero++) {
112  // t0s and rms are TDC counts
113  // @@@ NEW DTT0 FORMAT
114  // DTWireId wireId((*tzero).first.wheelId,
115  // (*tzero).first.stationId,
116  // (*tzero).first.sectorId,
117  // (*tzero).first.slId,
118  // (*tzero).first.layerId,
119  // (*tzero).first.cellId);
120  int channelId = tzero->channelId;
121  if (channelId == 0)
122  continue;
123  DTWireId wireId(channelId);
124  // @@@ NEW DTT0 END
125  float t0mean;
126  float t0rms;
127  tZeroMap_->get(wireId, t0mean, t0rms, DTTimeUnits::counts);
128  LogTrace(metname_) << "Wire: " << wireId << endl
129  << " T0 mean (TDC counts): " << t0mean << " T0_rms (TDC counts): " << t0rms;
130 
131  t0Map_[wireId].push_back(t0mean);
132  t0Map_[wireId].push_back(t0rms);
133  }
134 
135  double difference = 0;
136  for (map<DTWireId, vector<float>>::const_iterator theMap = t0RefMap_.begin(); theMap != t0RefMap_.end(); theMap++) {
137  if (t0Map_.find((*theMap).first) != t0Map_.end()) {
138  // Compute the difference
139  difference = t0Map_[(*theMap).first][0] - (*theMap).second[0];
140 
141  // book histo
142  DTLayerId layerId = (*theMap).first.layerId();
143  if (t0DiffHistos_.find(layerId) == t0DiffHistos_.end()) {
144  const DTTopology &dtTopo = dtGeom_->layer(layerId)->specificTopology();
145  const int firstWire = dtTopo.firstChannel();
146  const int lastWire = dtTopo.lastChannel();
147  bookHistos(layerId, firstWire, lastWire);
148  }
149 
150  LogTrace(metname_) << "Filling the histo for wire: " << (*theMap).first << " difference: " << difference;
151  t0DiffHistos_[layerId]->Fill((*theMap).first.wire(), difference);
152  }
153  } // Loop over the t0 map reference
154 }
155 
157  // Check the histos
158  string testCriterionName = t0TestName_;
159  for (map<DTLayerId, MonitorElement *>::const_iterator hDiff = t0DiffHistos_.begin(); hDiff != t0DiffHistos_.end();
160  hDiff++) {
161  const QReport *theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
162  if (theDiffQReport) {
163  int xBin = ((*hDiff).first.station() - 1) * 12 + (*hDiff).first.layer() + 4 * ((*hDiff).first.superlayer() - 1);
164  if ((*hDiff).first.station() == 4 && (*hDiff).first.superlayer() == 3)
165  xBin = ((*hDiff).first.station() - 1) * 12 + (*hDiff).first.layer() + 4 * ((*hDiff).first.superlayer() - 2);
166 
167  int qReportStatus = theDiffQReport->getStatus() / 100;
168  wheelSummary_[(*hDiff).first.wheel()]->setBinContent(xBin, (*hDiff).first.sector(), qReportStatus);
169 
170  LogVerbatim(metname_) << "-------- layer: " << (*hDiff).first << " " << theDiffQReport->getMessage()
171  << " ------- " << theDiffQReport->getStatus() << " ------- " << setprecision(3)
172  << theDiffQReport->getQTresult();
173  vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
174  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
175  channel++) {
176  LogVerbatim(metname_) << "layer: " << (*hDiff).first << " Bad channel: " << (*channel).getBin()
177  << " Contents : " << (*channel).getContents();
178 
179  // wheelSummary_[(*hDiff).first.wheel()]->Fill(xBin,(*hDiff).first.sector());
180  }
181  }
182  }
183 }
184 
186  // Write the histos on a file
187  if (outputMEsInRootFile_)
188  dbe_->save(outputFileName_);
189 }
190 
191 // Book a set of histograms for a given Layer
192 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
193  LogTrace(metname_) << " Booking histos for L: " << lId;
194 
195  // Compose the chamber name
196  stringstream wheel;
197  wheel << lId.superlayerId().chamberId().wheel();
198  stringstream station;
199  station << lId.superlayerId().chamberId().station();
200  stringstream sector;
201  sector << lId.superlayerId().chamberId().sector();
202  stringstream superLayer;
203  superLayer << lId.superlayerId().superlayer();
204  stringstream layer;
205  layer << lId.layer();
206 
207  string lHistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str() +
208  "_L" + layer.str();
209 
210  dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation/Wheel" + wheel.str() + "/Station" + station.str() +
211  "/Sector" + sector.str() + "/SuperLayer" + superLayer.str());
212  // Create the monitor elements
213  MonitorElement *hDifference;
214  hDifference = dbe_->book1D("T0Difference" + lHistoName,
215  "difference between the two t0 values",
216  lastWire - firstWire + 1,
217  firstWire - 0.5,
218  lastWire + 0.5);
219 
220  t0DiffHistos_[lId] = hDifference;
221 }
222 
223 // Book the summary histos
225  dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
226  stringstream wh;
227  wh << wheel;
228  wheelSummary_[wheel] = dbe_->book2D(
229  "SummaryWrongT0_W" + wh.str(), "W" + wh.str() + ": summary of wrong t0 differences", 44, 1, 45, 14, 1, 15);
230  wheelSummary_[wheel]->setBinLabel(1, "M1L1", 1);
231  wheelSummary_[wheel]->setBinLabel(2, "M1L2", 1);
232  wheelSummary_[wheel]->setBinLabel(3, "M1L3", 1);
233  wheelSummary_[wheel]->setBinLabel(4, "M1L4", 1);
234  wheelSummary_[wheel]->setBinLabel(5, "M1L5", 1);
235  wheelSummary_[wheel]->setBinLabel(6, "M1L6", 1);
236  wheelSummary_[wheel]->setBinLabel(7, "M1L7", 1);
237  wheelSummary_[wheel]->setBinLabel(8, "M1L8", 1);
238  wheelSummary_[wheel]->setBinLabel(9, "M1L9", 1);
239  wheelSummary_[wheel]->setBinLabel(10, "M1L10", 1);
240  wheelSummary_[wheel]->setBinLabel(11, "M1L11", 1);
241  wheelSummary_[wheel]->setBinLabel(12, "M1L12", 1);
242  wheelSummary_[wheel]->setBinLabel(13, "M2L1", 1);
243  wheelSummary_[wheel]->setBinLabel(14, "M2L2", 1);
244  wheelSummary_[wheel]->setBinLabel(15, "M2L3", 1);
245  wheelSummary_[wheel]->setBinLabel(16, "M2L4", 1);
246  wheelSummary_[wheel]->setBinLabel(17, "M2L5", 1);
247  wheelSummary_[wheel]->setBinLabel(18, "M2L6", 1);
248  wheelSummary_[wheel]->setBinLabel(19, "M2L7", 1);
249  wheelSummary_[wheel]->setBinLabel(20, "M2L8", 1);
250  wheelSummary_[wheel]->setBinLabel(21, "M2L9", 1);
251  wheelSummary_[wheel]->setBinLabel(22, "M2L10", 1);
252  wheelSummary_[wheel]->setBinLabel(23, "M2L11", 1);
253  wheelSummary_[wheel]->setBinLabel(24, "M2L12", 1);
254  wheelSummary_[wheel]->setBinLabel(25, "M3L1", 1);
255  wheelSummary_[wheel]->setBinLabel(26, "M3L2", 1);
256  wheelSummary_[wheel]->setBinLabel(27, "M3L3", 1);
257  wheelSummary_[wheel]->setBinLabel(28, "M3L4", 1);
258  wheelSummary_[wheel]->setBinLabel(29, "M3L5", 1);
259  wheelSummary_[wheel]->setBinLabel(30, "M3L6", 1);
260  wheelSummary_[wheel]->setBinLabel(31, "M3L7", 1);
261  wheelSummary_[wheel]->setBinLabel(32, "M3L8", 1);
262  wheelSummary_[wheel]->setBinLabel(33, "M3L9", 1);
263  wheelSummary_[wheel]->setBinLabel(34, "M3L10", 1);
264  wheelSummary_[wheel]->setBinLabel(35, "M3L11", 1);
265  wheelSummary_[wheel]->setBinLabel(36, "M3L12", 1);
266  wheelSummary_[wheel]->setBinLabel(37, "M4L1", 1);
267  wheelSummary_[wheel]->setBinLabel(38, "M4L2", 1);
268  wheelSummary_[wheel]->setBinLabel(39, "M4L3", 1);
269  wheelSummary_[wheel]->setBinLabel(40, "M4L4", 1);
270  wheelSummary_[wheel]->setBinLabel(41, "M4L5", 1);
271  wheelSummary_[wheel]->setBinLabel(42, "M4L6", 1);
272  wheelSummary_[wheel]->setBinLabel(43, "M4L7", 1);
273  wheelSummary_[wheel]->setBinLabel(44, "M4L8", 1);
274 }
T getParameter(std::string const &) const
void endRun(edm::Run const &, edm::EventSetup const &) override
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1178
const std::vector< DQMChannel > & getBadChannels() const
Definition: QReport.h:37
DTChamberId chamberId() const
Return the corresponding ChamberId.
dqm::legacy::DQMStore * dbe_
bool exists(std::string const &parameterName) const
checks if a parameter exists
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:122
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
void bookHistos()
Definition: Histogram.h:33
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:81
DTt0DBValidation(const edm::ParameterSet &pset)
Constructor.
void endJob() override
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
const std::string & getMessage() const
get message attached to test
Definition: QReport.h:30
#define LogTrace(id)
~DTt0DBValidation() override
Destructor.
int superlayer() const
Return the superlayer number (deprecated method name)
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
Operations.
int getStatus() const
get test status (see Core/interface/QTestStatus.h)
Definition: QReport.h:24
Definition: DTT0Rcd.h:9
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
HLT enums.
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
void bookHistos(DTLayerId lId, int firstWire, int lastWire)
static const double tzero[3]
float getQTresult() const
get test result i.e. prob value
Definition: QReport.h:27
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1121
const std::string & version() const
access version
Definition: DTT0.cc:82
int station() const
Return the station number.
Definition: DTChamberId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2244
Definition: Run.h:45