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: 2009/02/16 15:57:24 $
6  * $Revision: 1.6 $
7  * \author G. Mila - INFN Torino
8  */
9 
11 
12 // Framework
17 
21 
22 // Geometry
27 
28 // t0
31 
32 #include <stdio.h>
33 #include <sstream>
34 #include <math.h>
35 #include "TFile.h"
36 
37 using namespace edm;
38 using namespace std;
39 
40 
41 
42 
44 
45  cout << "[DTt0DBValidation] Constructor called!" << endl;
46 
47  // Get the DQM needed services
48  dbe = edm::Service<DQMStore>().operator->();
49  dbe->setCurrentFolder("DT/DTDBValidation");
50 
51  // Get dataBase label
52  labelDBRef = pset.getUntrackedParameter<string>("labelDBRef");
53  labelDB = pset.getUntrackedParameter<string>("labelDB");
54 
55  parameters = pset;
56 }
57 
58 
60 
61 
62 void DTt0DBValidation::beginRun(const edm::Run& run, const EventSetup& setup) {
63 
64  metname = "t0dbValidation";
65  LogTrace(metname)<<"[DTt0DBValidation] Parameters initialization";
66 
67  outputFileName = parameters.getUntrackedParameter<std::string>("OutputFileName");
68 
69  ESHandle<DTT0> t0_Ref;
70  setup.get<DTT0Rcd>().get(labelDBRef, t0_Ref);
71  tZeroRefMap = &*t0_Ref;
72  LogTrace(metname)<<"[DTt0DBValidation] reference T0 version: " << t0_Ref->version();
73 
74  ESHandle<DTT0> t0;
75  setup.get<DTT0Rcd>().get(labelDB, t0);
76  tZeroMap = &*t0;
77  LogTrace(metname)<<"[DTt0DBValidation] T0 to validate version: " << t0->version();
78 
79  //book&reset the summary histos
80  for(int wheel=-2; wheel<=2; wheel++){
81  bookHistos(wheel);
82  wheelSummary[wheel]->Reset();
83  }
84 
85  // Get the geometry
86  setup.get<MuonGeometryRecord>().get(dtGeom);
87 
88  // Loop over Ref DB entries
89  for(DTT0::const_iterator tzero = tZeroRefMap->begin();
90  tzero != tZeroRefMap->end(); tzero++) {
91  // t0s and rms are TDC counts
92  DTWireId wireId((*tzero).first.wheelId,
93  (*tzero).first.stationId,
94  (*tzero).first.sectorId,
95  (*tzero).first.slId,
96  (*tzero).first.layerId,
97  (*tzero).first.cellId);
98  float t0mean;
99  float t0rms;
100  tZeroRefMap->get( wireId, t0mean, t0rms, DTTimeUnits::counts );
101  LogTrace(metname)<< "Ref Wire: " << wireId <<endl
102  << " T0 mean (TDC counts): " << t0mean
103  << " T0_rms (TDC counts): " << t0rms;
104 
105  t0RefMap[wireId].push_back(t0mean);
106  t0RefMap[wireId].push_back(t0rms);
107  }
108 
109  // Loop over Ref DB entries
110  for(DTT0::const_iterator tzero = tZeroMap->begin();
111  tzero != tZeroMap->end(); tzero++) {
112  // t0s and rms are TDC counts
113  DTWireId wireId((*tzero).first.wheelId,
114  (*tzero).first.stationId,
115  (*tzero).first.sectorId,
116  (*tzero).first.slId,
117  (*tzero).first.layerId,
118  (*tzero).first.cellId);
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
124  << " 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();
132  theMap != t0RefMap.end();
133  theMap++) {
134  if(t0Map.find((*theMap).first) != t0Map.end()) {
135 
136  // compute the difference
137  difference = t0Map[(*theMap).first][0]-(*theMap).second[0];
138 
139  //book histo
140  DTLayerId layerId = (*theMap).first.layerId();
141  if(t0DiffHistos.find(layerId) == t0DiffHistos.end()) {
142  const DTTopology& dtTopo = dtGeom->layer(layerId)->specificTopology();
143  const int firstWire = dtTopo.firstChannel();
144  const int lastWire = dtTopo.lastChannel();
145  bookHistos(layerId, firstWire, lastWire);
146  }
147 
148  cout<< "Filling the histo for wire: "<<(*theMap).first
149  <<" difference: "<<difference<<endl;
150  t0DiffHistos[layerId]->Fill((*theMap).first.wire(),difference);
151 
152  }
153  } // Loop over the t0 map reference
154 
155 }
156 
157 
159 
160  //check the histos
161  string testCriterionName = parameters.getUntrackedParameter<string>("t0TestName","t0DifferenceInRange");
162  for(map<DTLayerId, MonitorElement*>::const_iterator hDiff = t0DiffHistos.begin();
163  hDiff != t0DiffHistos.end();
164  hDiff++) {
165  const QReport * theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
166  if(theDiffQReport) {
167  vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
168  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
169  channel != badChannels.end(); channel++) {
170  cout << "layer:"<<(*hDiff).first<<" Bad mean channels: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents()<<endl;
171 
172  int xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-1);
173  if((*hDiff).first.station()==4 && (*hDiff).first.superlayer()==3)
174  xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-2);
175  wheelSummary[(*hDiff).first.wheel()]->Fill(xBin,(*hDiff).first.sector());
176 
177  }
178  cout << "-------- layer: "<<(*hDiff).first<<" "<<theDiffQReport->getMessage()<<" ------- "<<theDiffQReport->getStatus()<<endl;
179  }
180  }
181 
182  // write the histos on a file
183  dbe->save(outputFileName);
184 
185 }
186 
187  // Book a set of histograms for a given Layer
188 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
189 
190  LogTrace(metname)<< " Booking histos for L: " << lId;
191 
192  // Compose the chamber name
193  stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();
194  stringstream station; station << lId.superlayerId().chamberId().station();
195  stringstream sector; sector << lId.superlayerId().chamberId().sector();
196  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
197  stringstream layer; layer << lId.layer();
198 
199  string lHistoName =
200  "_W" + wheel.str() +
201  "_St" + station.str() +
202  "_Sec" + sector.str() +
203  "_SL" + superLayer.str()+
204  "_L" + layer.str();
205 
206  dbe->setCurrentFolder("DT/t0Validation/Wheel" + wheel.str() +
207  "/Station" + station.str() +
208  "/Sector" + sector.str() +
209  "/SuperLayer" +superLayer.str());
210  // Create the monitor elements
211  MonitorElement * hDifference;
212  hDifference = dbe->book1D("hDifference"+lHistoName, "difference between the two t0 values",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5);
213 
214  t0DiffHistos[lId] = hDifference;
215 }
216 
217 // Book the summary histos
219  dbe->setCurrentFolder("DT/t0Validation/Summary");
220  stringstream wh; wh << wheel;
221  wheelSummary[wheel]= dbe->book2D("summaryWrongT0_W"+wh.str(), "W"+wh.str()+": summary of wrong t0 differences",44,1,45,14,1,15);
222  wheelSummary[wheel]->setBinLabel(1,"M1L1",1);
223  wheelSummary[wheel]->setBinLabel(2,"M1L2",1);
224  wheelSummary[wheel]->setBinLabel(3,"M1L3",1);
225  wheelSummary[wheel]->setBinLabel(4,"M1L4",1);
226  wheelSummary[wheel]->setBinLabel(5,"M1L5",1);
227  wheelSummary[wheel]->setBinLabel(6,"M1L6",1);
228  wheelSummary[wheel]->setBinLabel(7,"M1L7",1);
229  wheelSummary[wheel]->setBinLabel(8,"M1L8",1);
230  wheelSummary[wheel]->setBinLabel(9,"M1L9",1);
231  wheelSummary[wheel]->setBinLabel(10,"M1L10",1);
232  wheelSummary[wheel]->setBinLabel(11,"M1L11",1);
233  wheelSummary[wheel]->setBinLabel(12,"M1L12",1);
234  wheelSummary[wheel]->setBinLabel(13,"M2L1",1);
235  wheelSummary[wheel]->setBinLabel(14,"M2L2",1);
236  wheelSummary[wheel]->setBinLabel(15,"M2L3",1);
237  wheelSummary[wheel]->setBinLabel(16,"M2L4",1);
238  wheelSummary[wheel]->setBinLabel(17,"M2L5",1);
239  wheelSummary[wheel]->setBinLabel(18,"M2L6",1);
240  wheelSummary[wheel]->setBinLabel(19,"M2L7",1);
241  wheelSummary[wheel]->setBinLabel(20,"M2L8",1);
242  wheelSummary[wheel]->setBinLabel(21,"M2L9",1);
243  wheelSummary[wheel]->setBinLabel(22,"M2L10",1);
244  wheelSummary[wheel]->setBinLabel(23,"M2L11",1);
245  wheelSummary[wheel]->setBinLabel(24,"M2L12",1);
246  wheelSummary[wheel]->setBinLabel(25,"M3L1",1);
247  wheelSummary[wheel]->setBinLabel(26,"M3L2",1);
248  wheelSummary[wheel]->setBinLabel(27,"M3L3",1);
249  wheelSummary[wheel]->setBinLabel(28,"M3L4",1);
250  wheelSummary[wheel]->setBinLabel(29,"M3L5",1);
251  wheelSummary[wheel]->setBinLabel(30,"M3L6",1);
252  wheelSummary[wheel]->setBinLabel(31,"M3L7",1);
253  wheelSummary[wheel]->setBinLabel(32,"M3L8",1);
254  wheelSummary[wheel]->setBinLabel(33,"M3L9",1);
255  wheelSummary[wheel]->setBinLabel(34,"M3L10",1);
256  wheelSummary[wheel]->setBinLabel(35,"M3L11",1);
257  wheelSummary[wheel]->setBinLabel(36,"M3L12",1);
258  wheelSummary[wheel]->setBinLabel(37,"M4L1",1);
259  wheelSummary[wheel]->setBinLabel(38,"M4L2",1);
260  wheelSummary[wheel]->setBinLabel(39,"M4L3",1);
261  wheelSummary[wheel]->setBinLabel(40,"M4L4",1);
262  wheelSummary[wheel]->setBinLabel(41,"M4L5",1);
263  wheelSummary[wheel]->setBinLabel(42,"M4L6",1);
264  wheelSummary[wheel]->setBinLabel(43,"M4L7",1);
265  wheelSummary[wheel]->setBinLabel(44,"M4L8",1);
266 }
const int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:82
T getUntrackedParameter(std::string const &, T const &) const
const std::string metname
DTChamberId chamberId() const
Return the corresponding ChamberId.
virtual ~DTt0DBValidation()
Destructor.
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
const int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:80
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
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:160
void bookHistos()
Definition: Histogram.h:33
DTt0DBValidation(const edm::ParameterSet &pset)
Constructor.
int getStatus(void) const
get test status (see Core/interface/QTestStatus.h)
Definition: QReport.h:16
tuple pset
Definition: CrabTask.py:85
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
#define LogTrace(id)
int superlayer() const
Return the superlayer number (deprecated method name)
const T & get() const
Definition: EventSetup.h:55
std::vector< std::pair< DTT0Id, DTT0Data > >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:158
Definition: DTT0Rcd.h:9
int sector() const
Definition: DTChamberId.h:63
void bookHistos(DTLayerId lId, int firstWire, int lastWire)
static const double tzero[3]
tuple cout
Definition: gather_cfg.py:41
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
Definition: Run.h:31