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