CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelHistoricInfoEDAClient.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <math.h>
3 #include <iostream>
4 #include <string>
5 #include <stdio.h>
6 #include <sys/time.h>
7 
10 
11 
12 using namespace std;
13 using namespace edm;
14 // using namespace cgicc;
15 // using namespace xcept;
16 
17 
20 
21  parameterSet_ = parameterSet;
22 
23  printDebug_ = parameterSet_.getUntrackedParameter<bool>("printDebug", false);
24  writeHisto_ = parameterSet_.getUntrackedParameter<bool>("writeHisto", false);
25 
26  outputDir_ = parameterSet_.getUntrackedParameter<string>("outputDir", ".");
27 }
28 
29 
31 
32 
34 
35 
36 void SiPixelHistoricInfoEDAClient::beginRun(const Run& run, const EventSetup& eventSetup) {
37  performanceSummary = new SiPixelPerformanceSummary();
38  performanceSummary->setRunNumber(run.run());
39 
40  nEventsInRun = 0;
41  firstEventInRun = true;
42 }
43 
44 
46  const edm::EventSetup& eventSetup) {
47  performanceSummary->setLuminosityBlock(luminosityBlock.luminosityBlock());
48 }
49 
50 
52  nEventsInRun++;
53  if (firstEventInRun) {
54  firstEventInRun = false;
55 
56  performanceSummary->setTimeStamp(event.time().value());
57  }
58 }
59 
60 
62  const edm::EventSetup& eventSetup) {}
63 
64 
65 void SiPixelHistoricInfoEDAClient::endRun(const Run& run, const EventSetup& eventSetup) {
66  performanceSummary->setNumberOfEvents(nEventsInRun);
67 
68  retrieveMEs();
69  fillPerformanceSummary();
70  writeDB();
71 
72  if (writeHisto_) {
73  ostringstream endRunOutputFile;
74  endRunOutputFile << outputDir_ << "/SiPixelHistoricInfoEDAClient_" << run.run() <<".root";
75  dbe_->save(endRunOutputFile.str());
76  }
77 }
78 
79 
81  if (writeHisto_) {
82  ostringstream endJobOutputFile;
83  endJobOutputFile << outputDir_ << "/SiPixelHistoricInfoEDAClient_endJob.root";
84  dbe_->save(endJobOutputFile.str());
85  }
86 }
87 
88 
90  mapOfdetIDtoMEs.clear();
91 
92  vector<string> listOfMEswithFullPath;
93  dbe_->getContents(listOfMEswithFullPath);
94 
95  for (vector<string>::const_iterator iMEstr = listOfMEswithFullPath.begin();
96  iMEstr!=listOfMEswithFullPath.end(); iMEstr++) {
97  if (printDebug_) cout << iMEstr->data() << endl;
98 
99  size_t pathLength = iMEstr->find(":",0);
100  string thePath = iMEstr->substr(0, pathLength);
101  string allHists = iMEstr->substr(pathLength+1);
102 
103  if (thePath.find("Pixel",0)!=string::npos) {
104  if (thePath.find("Track",0)!=string::npos) { // for Pixel/Tracks, Pixel/Clusters/On,OffTrack
105  uint32_t newMEdetID = 77;
106  if (thePath.find("On", 0)!=string::npos) newMEdetID = 78;
107  if (thePath.find("Off",0)!=string::npos) newMEdetID = 79;
108 
109  size_t histnameLength;
110  do {
111  histnameLength = allHists.find(",",0);
112  string theHist;
113  if (histnameLength!=string::npos) {
114  theHist = allHists.substr(0, histnameLength);
115  allHists.erase(0, histnameLength+1);
116  }
117  else theHist = allHists;
118 
119  string fullPathHist = thePath + "/" + theHist;
120  MonitorElement* newME = dbe_->get(fullPathHist);
121  if (newME) {
122  if (mapOfdetIDtoMEs.find(newMEdetID)==mapOfdetIDtoMEs.end()) {
123  vector<MonitorElement*> newMEvector;
124  newMEvector.push_back(newME);
125  mapOfdetIDtoMEs.insert(make_pair(newMEdetID, newMEvector));
126  }
127  else (mapOfdetIDtoMEs.find(newMEdetID)->second).push_back(newME);
128  }
129  }
130  while (histnameLength!=string::npos);
131  }
132  else {
133  size_t histnameLength;
134  do {
135  histnameLength = allHists.find(",",0);
136  string theHist;
137  if (histnameLength!=string::npos) {
138  theHist = allHists.substr(0, histnameLength);
139  allHists.erase(0, histnameLength+1);
140  }
141  else theHist = allHists;
142 
143  string fullPathHist = thePath + "/" + theHist;
144  MonitorElement* newME = dbe_->get(fullPathHist);
145  if (newME) {
146  uint32_t newMEdetID = histogramManager.getRawId(newME->getName());
147 
148  if (mapOfdetIDtoMEs.find(newMEdetID)==mapOfdetIDtoMEs.end()) {
149  vector<MonitorElement*> newMEvector;
150  newMEvector.push_back(newME);
151  mapOfdetIDtoMEs.insert(make_pair(newMEdetID, newMEvector));
152  }
153  else ((mapOfdetIDtoMEs.find(newMEdetID))->second).push_back(newME);
154  }
155  }
156  while (histnameLength!=string::npos);
157  }
158  }
159  }
160 }
161 
162 
164  for (map< uint32_t, vector<MonitorElement*> >::const_iterator iMEvec=mapOfdetIDtoMEs.begin();
165  iMEvec!=mapOfdetIDtoMEs.end(); iMEvec++) {
166  uint32_t theMEdetID = iMEvec->first;
167  vector<MonitorElement*> theMEvector = iMEvec->second;
168 
169  if (printDebug_) {
170  cout << theMEdetID << ":"; for (vector<MonitorElement*>::const_iterator iME = theMEvector.begin();
171  iME!=theMEvector.end(); iME++) cout << (*iME)->getName() << ","; cout << endl;
172  }
173  for (vector<MonitorElement*>::const_iterator iME = theMEvector.begin(); iME!=theMEvector.end(); iME++) {
174  string theMEname = (*iME)->getName();
175 
176 
177  if (theMEdetID<50) {
178  // from SiPixelMonitorRawData
179  if (theMEname.find("errorType_siPixelDigis")!=string::npos) {
180  for (int v=25; v<40; v++) {
181  int b = (*iME)->getTH1()->GetXaxis()->FindBin(v);
182  performanceSummary->setRawDataErrorType(theMEdetID, v-25, (*iME)->getBinContent(b));
183  }
184  }
185  }
186  // from SiPixelMonitorTrack
187  else if (theMEdetID==77) {
188  if (theMEname.find("ntracks")!=string::npos && theMEname.find("InPixVol")==string::npos) {
189  float trkMean=0.0, trkRMS=0.0;
190  if ((*iME)->getBinContent(1)>0.0) {
191  trkMean = float((*iME)->getBinContent(3))/(*iME)->getBinContent(1); // Barrel regionID: 80
192  trkRMS = sqrt(trkMean*(trkMean+1.0)/(*iME)->getBinContent(1));
193  performanceSummary->setFractionOfTracks(80, trkMean, trkRMS);
194 
195  trkMean = float((*iME)->getBinContent(4))/(*iME)->getBinContent(1); // Endcap regionID: 81
196  trkRMS = sqrt(trkMean*(trkMean+1.0)/(*iME)->getBinContent(1));
197  performanceSummary->setFractionOfTracks(81, trkMean, trkRMS);
198  }
199  }
200  }
201  else if (theMEdetID==78) { // OnTrack
202  if (theMEname.find("nclusters_siPixelClusters")!=string::npos) {
203  performanceSummary->setNumberOfOnTrackClusters(80, (*iME)->getBinContent(2));
204  performanceSummary->setNumberOfOnTrackClusters(81, (*iME)->getBinContent(3));
205  }
206  if (theMEname.find("charge_siPixelClusters_Barrel")!=string::npos) {
207  performanceSummary->setClusterChargeOnTrack(80, (*iME)->getMean(), (*iME)->getRMS());
208  }
209  if (theMEname.find("charge_siPixelClusters_Endcap")!=string::npos) {
210  performanceSummary->setClusterChargeOnTrack(81, (*iME)->getMean(), (*iME)->getRMS());
211  }
212  if (theMEname.find("size_siPixelClusters_Barrel")!=string::npos) {
213  performanceSummary->setClusterSizeOnTrack(80, (*iME)->getMean(), (*iME)->getRMS());
214  }
215  if (theMEname.find("size_siPixelClusters_Endcap")!=string::npos) {
216  performanceSummary->setClusterSizeOnTrack(81, (*iME)->getMean(), (*iME)->getRMS());
217  }
218  }
219  else if (theMEdetID==79) { // OffTrack
220  if (theMEname.find("nclusters_siPixelClusters")!=string::npos) {
221  performanceSummary->setNumberOfOffTrackClusters(80, (*iME)->getBinContent(2));
222  performanceSummary->setNumberOfOffTrackClusters(81, (*iME)->getBinContent(3));
223  }
224  if (theMEname.find("charge_siPixelClusters_Barrel")!=string::npos) {
225  performanceSummary->setClusterChargeOffTrack(80, (*iME)->getMean(), (*iME)->getRMS());
226  }
227  if (theMEname.find("charge_siPixelClusters_Endcap")!=string::npos) {
228  performanceSummary->setClusterChargeOffTrack(81, (*iME)->getMean(), (*iME)->getRMS());
229  }
230  if (theMEname.find("size_siPixelClusters_Barrel")!=string::npos) {
231  performanceSummary->setClusterSizeOffTrack(80, (*iME)->getMean(), (*iME)->getRMS());
232  }
233  if (theMEname.find("size_siPixelClusters_Endcap")!=string::npos) {
234  performanceSummary->setClusterSizeOffTrack(81, (*iME)->getMean(), (*iME)->getRMS());
235  }
236  }
237  else {
238  // from SiPixelMonitorDigi
239  if (theMEname.find("ndigis_siPixelDigis")!=string::npos) {
240  performanceSummary->setNumberOfDigis(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
241  }
242  if (theMEname.find("adc_siPixelDigis")!=string::npos) {
243  performanceSummary->setADC(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
244  }
245  // from SiPixelMonitorCluster
246  if (theMEname.find("nclusters_siPixelClusters")!=string::npos) {
247  performanceSummary->setNumberOfClusters(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
248  }
249  if (theMEname.find("charge_siPixelClusters")!=string::npos) {
250  performanceSummary->setClusterCharge(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
251  }
252  if (theMEname.find("size_siPixelClusters")!=string::npos) {
253  performanceSummary->setClusterSize(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
254  }
255  if (theMEname.find("sizeX_siPixelClusters")!=string::npos) {
256  performanceSummary->setClusterSizeX(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
257  }
258  if (theMEname.find("sizeY_siPixelClusters")!=string::npos) {
259  performanceSummary->setClusterSizeY(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
260  }
261  // from SiPixelMonitorRecHit
262  if (theMEname.find("nRecHits_siPixelRecHits")!=string::npos) {
263  performanceSummary->setNumberOfRecHits(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
264  }
265  // from SiPixelMonitorTrack
266  if (theMEname.find("residualX_siPixelTrackResiduals")!=string::npos) {
267  performanceSummary->setResidualX(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
268  }
269  if (theMEname.find("residualY_siPixelTrackResiduals")!=string::npos) {
270  performanceSummary->setResidualY(theMEdetID, (*iME)->getMean(), (*iME)->getRMS(), (*iME)->getEntries()==0.0);
271  }
272  // temporary solutions
273  if (theMEname.find("hitmap_siPixelClusters")!=std::string::npos ||
274  theMEname.find("hitmap_siPixelDigis")!=std::string::npos) { // if digi map exists, use it; else use cluster map
275  int nNoisyCells=0, nEmptyCells=0; // not use xypos_siPixelRecHits
276  for (int xBin=0; xBin<(*iME)->getNbinsX(); xBin++) { // 4-1 pixel per bin
277  for (int yBin=0; yBin<(*iME)->getNbinsY(); yBin++) {
278  if ((*iME)->getBinContent(xBin+1, yBin+1)>0.01*(*iME)->getEntries()) nNoisyCells++;
279  if ((*iME)->getBinContent(xBin+1, yBin+1)==.0 && (*iME)->getBinError(xBin+1, yBin+1)==0.0) nEmptyCells++;
280  }
281  }
282  performanceSummary->setNumberOfNoisCells(theMEdetID, float(nNoisyCells));
283  performanceSummary->setNumberOfDeadCells(theMEdetID, float(nEmptyCells));
284  }
285  // performanceSummary->setNumberOfPixelHitsInTrackFit(theMEdetId, float(nPixelHits));
286  }
287  }
288  }
289 }
290 
291 
293  if (printDebug_) performanceSummary->printAll();
294  else performanceSummary->print();
295  cout << "SiPixelHistoricInfoEDAClient::writeDB()" << endl;
296 
298  if (mydbservice.isAvailable()) {
299  if (mydbservice->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
300  mydbservice->createNewIOV<SiPixelPerformanceSummary>(performanceSummary,
301  mydbservice->beginOfTime(),
302  mydbservice->endOfTime(),
303  "SiPixelPerformanceSummaryRcd");
304  }
305  else {
306  mydbservice->appendSinceTime<SiPixelPerformanceSummary>(performanceSummary,
307  mydbservice->currentTime(),
308  "SiPixelPerformanceSummaryRcd");
309  }
310  }
311  else LogError("writeDB") << "service unavailable" << endl;
312 }
virtual void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
virtual void analyze(const edm::Event &, const edm::EventSetup &)
SiPixelHistoricInfoEDAClient(const edm::ParameterSet &)
RunNumber_t run() const
Definition: RunBase.h:42
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:2113
dictionary map
Definition: Association.py:205
LuminosityBlockNumber_t luminosityBlock() const
U second(std::pair< T, U > const &p)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
T sqrt(T t)
Definition: SSEVec.h:46
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
bool isAvailable() const
Definition: Service.h:47
virtual void endRun(const edm::Run &, const edm::EventSetup &)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1468
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1497
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
DQMStore * dbe_
TimeValue_t value() const
Definition: Timestamp.cc:72
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
double b
Definition: hdecay.h:120
tuple cout
Definition: gather_cfg.py:121
mathSSE::Vec4< T > v
edm::Timestamp time() const
Definition: EventBase.h:57
Definition: Run.h:33