CMS 3D CMS Logo

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