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