CMS 3D CMS Logo

SiStripHitResolFromCalibTree.cc
Go to the documentation of this file.
1 //Original Author: Christopher Edelmaier
2 // Created: Feb. 11, 2010
3 
4 // system include files
5 #include <fstream>
6 #include <iostream>
7 #include <memory>
8 #include <sstream>
9 #include <string>
10 
11 // user includes
42 
43 // ROOT includes
44 #include "TCanvas.h"
45 #include "TEfficiency.h"
46 #include "TF1.h"
47 #include "TFile.h"
48 #include "TGaxis.h"
49 #include "TGraphAsymmErrors.h"
50 #include "TH1F.h"
51 #include "TH2F.h"
52 #include "TLatex.h"
53 #include "TLeaf.h"
54 #include "TLegend.h"
55 #include "TObjString.h"
56 #include "TProfile.h"
57 #include "TROOT.h"
58 #include "TString.h"
59 #include "TStyle.h"
60 #include "TTree.h"
61 
62 using namespace edm;
63 using namespace reco;
64 using namespace std;
65 
66 struct hit {
67  double x;
68  double y;
69  double z;
70  unsigned int id;
71 };
72 
73 class SiStripHitResolFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
74 public:
76  ~SiStripHitResolFromCalibTree() override = default;
77 
78 private:
79  void algoBeginJob(const edm::EventSetup&) override;
80  void algoEndJob() override;
81  void algoAnalyze(const edm::Event& e, const edm::EventSetup& c) override;
82  void SetBadComponents(int i,
83  int component,
85  std::stringstream ssV[4][19],
86  int NBadComponent[4][19][4]);
87  void makeTKMap(const edm::Service<TFileService>& fs, bool autoTagging);
88  void makeHotColdMaps(const edm::Service<TFileService>& fs);
89  void makeSQLite();
90  void totalStatistics();
91  void makeSummary(const edm::Service<TFileService>& fs);
92  void makeSummaryVsBx(const edm::Service<TFileService>& fs);
93  void ComputeEff(const edm::Service<TFileService>& fs, vector<TH1F*>& vhfound, vector<TH1F*>& vhtotal, string name);
94  void makeSummaryVsLumi(const edm::Service<TFileService>& fs);
95  void makeSummaryVsCM(const edm::Service<TFileService>& fs);
96  TString GetLayerName(Long_t k);
97  TString GetLayerSideName(Long_t k);
98  float calcPhi(float x, float y);
99 
100  static constexpr double nBxInAnOrbit = 3565;
101 
105  std::unique_ptr<SiStripBadStrip> getNewObject() override;
106 
107  TTree* CalibTree;
108  vector<string> calibTreeFileNames_;
109  float threshold_;
110  unsigned int nModsMin_;
111  unsigned int doSummary_;
115  float resXSig_;
119  unsigned int bunchx_;
120  unsigned int spaceBetweenTrains_;
121  bool useCM_;
126  float tkMapMin_;
127  float effPlotMin_;
128  TString title_;
129 
132 
133  unsigned int nTEClayers_;
134 
135  TH1F* bxHisto;
137  TH1F* PUHisto;
138 
139  // for association of informations of the hitEff tree and the event infos tree
140  map<pair<unsigned int, unsigned int>, array<double, 3> > eventInfos;
141 
142  vector<hit> hits[::k_END_OF_LAYERS];
143  vector<TH2F*> HotColdMaps;
144  map<unsigned int, pair<unsigned int, unsigned int> > modCounter[::k_END_OF_LAYERS];
150  long layerfound[::k_END_OF_LAYERS];
151  long layertotal[::k_END_OF_LAYERS];
152  map<unsigned int, vector<int> > layerfound_perBx;
153  map<unsigned int, vector<int> > layertotal_perBx;
154  vector<TH1F*> layerfound_vsLumi;
155  vector<TH1F*> layertotal_vsLumi;
156  vector<TH1F*> layerfound_vsPU;
157  vector<TH1F*> layertotal_vsPU;
158  vector<TH1F*> layerfound_vsCM;
159  vector<TH1F*> layertotal_vsCM;
160  vector<TH1F*> layerfound_vsBX;
161  vector<TH1F*> layertotal_vsBX;
162  int goodlayertotal[::k_END_OF_LAYS_AND_RINGS];
163  int goodlayerfound[::k_END_OF_LAYS_AND_RINGS];
164  int alllayertotal[::k_END_OF_LAYS_AND_RINGS];
165  int alllayerfound[::k_END_OF_LAYS_AND_RINGS];
166  map<unsigned int, double> BadModules;
167 };
168 
170  : ConditionDBWriter<SiStripBadStrip>(conf), FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat") {
171  usesResource(TFileService::kSharedResource);
172  calibTreeFileNames_ = conf.getUntrackedParameter<vector<std::string> >("CalibTreeFilenames");
173  threshold_ = conf.getParameter<double>("Threshold");
174  nModsMin_ = conf.getParameter<int>("nModsMin");
175  doSummary_ = conf.getParameter<int>("doSummary");
176  badModulesFile_ = conf.getUntrackedParameter<std::string>("BadModulesFile", "");
177  autoIneffModTagging_ = conf.getUntrackedParameter<bool>("AutoIneffModTagging", false);
178  clusterMatchingMethod_ = conf.getUntrackedParameter<int>("ClusterMatchingMethod", 0);
179  resXSig_ = conf.getUntrackedParameter<double>("ResXSig", -1);
180  clusterTrajDist_ = conf.getUntrackedParameter<double>("ClusterTrajDist", 64.0);
181  stripsApvEdge_ = conf.getUntrackedParameter<double>("StripsApvEdge", 10.0);
182  useOnlyHighPurityTracks_ = conf.getUntrackedParameter<bool>("UseOnlyHighPurityTracks", true);
183  bunchx_ = conf.getUntrackedParameter<int>("BunchCrossing", 0);
184  spaceBetweenTrains_ = conf.getUntrackedParameter<int>("SpaceBetweenTrains", 25);
185  useCM_ = conf.getUntrackedParameter<bool>("UseCommonMode", false);
186  showEndcapSides_ = conf.getUntrackedParameter<bool>("ShowEndcapSides", true);
187  showRings_ = conf.getUntrackedParameter<bool>("ShowRings", false);
188  showTOB6TEC9_ = conf.getUntrackedParameter<bool>("ShowTOB6TEC9", false);
189  showOnlyGoodModules_ = conf.getUntrackedParameter<bool>("ShowOnlyGoodModules", false);
190  tkMapMin_ = conf.getUntrackedParameter<double>("TkMapMin", 0.9);
191  effPlotMin_ = conf.getUntrackedParameter<double>("EffPlotMin", 0.9);
192  title_ = conf.getParameter<std::string>("Title");
196 
197  nTEClayers_ = 9; // number of wheels
198  if (showRings_)
199  nTEClayers_ = 7; // number of rings
200 
202 }
203 
205 
207 
210 
211  const auto& tkgeom = c.getData(tkGeomToken_);
212  const auto& tTopo = c.getData(tTopoToken_);
213 
214  // read bad modules to mask
215  ifstream badModules_file;
216  set<uint32_t> badModules_list;
217  if (!badModulesFile_.empty()) {
218  badModules_file.open(badModulesFile_.c_str());
219  uint32_t badmodule_detid;
220  int mods, fiber1, fiber2, fiber3;
221  if (badModules_file.is_open()) {
222  string line;
223  while (getline(badModules_file, line)) {
224  if (badModules_file.eof())
225  continue;
226  stringstream ss(line);
227  ss >> badmodule_detid >> mods >> fiber1 >> fiber2 >> fiber3;
228  if (badmodule_detid != 0 && mods == 1 && (fiber1 == 1 || fiber2 == 1 || fiber3 == 1))
229  badModules_list.insert(badmodule_detid);
230  }
231  badModules_file.close();
232  }
233  }
234  if (!badModules_list.empty())
235  edm::LogInfo("SiStripHitResolFromCalibTree") << "Remove additionnal bad modules from the analysis: " << endl;
236  set<uint32_t>::iterator itBadMod;
237  for (itBadMod = badModules_list.begin(); itBadMod != badModules_list.end(); ++itBadMod)
238  edm::LogInfo("SiStripHitResolFromCalibTree") << " " << *itBadMod << endl;
239 
240  // initialze counters and histos
241 
242  bxHisto = fs->make<TH1F>("bx", "bx", 3600, 0, 3600);
243  instLumiHisto = fs->make<TH1F>("instLumi", "inst. lumi.", 250, 0, 25000);
244  PUHisto = fs->make<TH1F>("PU", "PU", 200, 0, 200);
245 
246  for (int l = 0; l < ::k_END_OF_LAYS_AND_RINGS; l++) {
247  goodlayertotal[l] = 0;
248  goodlayerfound[l] = 0;
249  alllayertotal[l] = 0;
250  alllayerfound[l] = 0;
251  }
252 
253  TH1F* PredPlots_m[::k_END_OF_LAYERS];
254  TH1F* PredPlots_p[::k_END_OF_LAYERS];
255  TH1F* MeasPlots_m[::k_END_OF_LAYERS];
256  TH1F* MeasPlots_p[::k_END_OF_LAYERS];
257  TH1F* ResidPlots_m[::k_END_OF_LAYERS];
258  TH1F* ResidPlots_p[::k_END_OF_LAYERS];
259 
260  //std::string UnitString = "cm";
261  std::string UnitString = "strip unit";
262  std::string PlotTitleClusX;
263  std::string PlotTitleTrajX;
264  std::string FileNameEnding;
265 
266  if (UnitString == "cm") {
267  PlotTitleClusX = "clusX [cm]";
268  PlotTitleTrajX = "trajX [cm]";
269  FileNameEnding = "CM";
270  } else if (UnitString == "strip unit") {
271  PlotTitleClusX = "clusX [strip unit]";
272  PlotTitleTrajX = "trajX [strip unit]";
273  FileNameEnding = "StripUnit";
274  } else {
275  edm::LogInfo("SiStripHitResolFromCalibTree") << "ERROR: Unit must either be cm or strip unit." << std::endl;
276  }
277 
278  for (Long_t ilayer = 0; ilayer < ::k_END_OF_LAYERS; ilayer++) {
279  MeasPlots_m[ilayer] =
280  fs->make<TH1F>(Form("MeasPlots_m_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 1000, -5., 5.);
281  MeasPlots_m[ilayer]->GetXaxis()->SetTitle("clusX [cm]");
282  MeasPlots_p[ilayer] =
283  fs->make<TH1F>(Form("MeasPlots_p_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 1000, -400, 400);
284  MeasPlots_p[ilayer]->GetXaxis()->SetTitle("clusX [strip]");
285 
286  PredPlots_m[ilayer] =
287  fs->make<TH1F>(Form("PredPlots_m_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 1000, -5., 5.);
288  PredPlots_m[ilayer]->GetXaxis()->SetTitle("trajX [cm]");
289  PredPlots_p[ilayer] =
290  fs->make<TH1F>(Form("PredPlots_p_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 1000, -400, 400);
291  PredPlots_p[ilayer]->GetXaxis()->SetTitle("trajX [strip]");
292 
293  ResidPlots_m[ilayer] =
294  fs->make<TH1F>(Form("ResidPlots_m_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 250, -.125, .125);
295  ResidPlots_m[ilayer]->GetXaxis()->SetTitle("trajX [cm]");
296  ResidPlots_p[ilayer] =
297  fs->make<TH1F>(Form("ResidPlots_p_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 200, -10., 10);
298  ResidPlots_p[ilayer]->GetXaxis()->SetTitle("trajX [strip]");
299 
300  layerfound_vsLumi.push_back(
301  fs->make<TH1F>(Form("layerfound_vsLumi_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 100, 0, 25000));
302  layertotal_vsLumi.push_back(
303  fs->make<TH1F>(Form("layertotal_vsLumi_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 100, 0, 25000));
304  layerfound_vsPU.push_back(
305  fs->make<TH1F>(Form("layerfound_vsPU_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 45, 0, 90));
306  layertotal_vsPU.push_back(
307  fs->make<TH1F>(Form("layertotal_vsPU_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 45, 0, 90));
308 
309  layerfound_vsBX.push_back(fs->make<TH1F>(
310  Form("foundVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));
311  layertotal_vsBX.push_back(fs->make<TH1F>(
312  Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));
313 
314  if (useCM_) {
315  layerfound_vsCM.push_back(
316  fs->make<TH1F>(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400));
317  layertotal_vsCM.push_back(
318  fs->make<TH1F>(Form("layertotal_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400));
319  }
320  layertotal[ilayer] = 0;
321  layerfound[ilayer] = 0;
322  }
323 
325  edm::LogInfo("SiStripHitResolFromCalibTree") << "A module is bad if efficiency < " << threshold_
326  << " and has at least " << nModsMin_ << " nModsMin." << endl;
327  else
328  edm::LogInfo("SiStripHitResolFromCalibTree") << "A module is bad if efficiency < the avg in layer - " << threshold_
329  << " and has at least " << nModsMin_ << " nModsMin." << endl;
330 
331  unsigned int run, evt, bx;
332  double instLumi, PU;
333 
334  //Open the ROOT Calib Tree
335  for (unsigned int ifile = 0; ifile < calibTreeFileNames_.size(); ifile++) {
336  edm::LogInfo("SiStripHitResolFromCalibTree") << "Loading file: " << calibTreeFileNames_[ifile] << endl;
337  TFile* CalibTreeFile = TFile::Open(calibTreeFileNames_[ifile].c_str(), "READ");
338 
339  // Get event infos
340  bool foundEventInfos = false;
341  try {
342  CalibTreeFile->cd("eventInfo");
343  } catch (exception& e) {
344  edm::LogInfo("SiStripHitResolFromCalibTree") << "No event infos tree" << endl;
345  }
346  TTree* EventTree = (TTree*)(gDirectory->Get("tree"));
347 
348  TLeaf* runLf;
349  TLeaf* evtLf;
350  TLeaf* BunchLf;
351  TLeaf* InstLumiLf;
352  TLeaf* PULf;
353  if (EventTree) {
354  edm::LogInfo("SiStripHitResolFromCalibTree") << "Found event infos tree" << endl;
355 
356  runLf = EventTree->GetLeaf("run");
357  evtLf = EventTree->GetLeaf("event");
358 
359  BunchLf = EventTree->GetLeaf("bx");
360  InstLumiLf = EventTree->GetLeaf("instLumi");
361  PULf = EventTree->GetLeaf("PU");
362 
363  int nevt = EventTree->GetEntries();
364  if (nevt)
365  foundEventInfos = true;
366 
367  for (int j = 0; j < nevt; j++) {
368  EventTree->GetEntry(j);
369  run = runLf->GetValue();
370  evt = evtLf->GetValue();
371  bx = BunchLf->GetValue();
372  instLumi = InstLumiLf->GetValue();
373  PU = PULf->GetValue();
374 
375  bxHisto->Fill(bx);
376  instLumiHisto->Fill(instLumi);
377  PUHisto->Fill(PU);
378 
379  eventInfos[make_pair(run, evt)] = array<double, 3>{{(double)bx, instLumi, PU}};
380  }
381  }
382 
383  // Get hit infos
384  CalibTreeFile->cd("anEff");
385  CalibTree = (TTree*)(gDirectory->Get("traj"));
386 
387  runLf = CalibTree->GetLeaf("run");
388  evtLf = CalibTree->GetLeaf("event");
389  TLeaf* BadLf = CalibTree->GetLeaf("ModIsBad");
390  TLeaf* sistripLf = CalibTree->GetLeaf("SiStripQualBad");
391  TLeaf* idLf = CalibTree->GetLeaf("Id");
392  TLeaf* acceptLf = CalibTree->GetLeaf("withinAcceptance");
393  TLeaf* layerLf = CalibTree->GetLeaf("layer");
394  //TLeaf* nHitsLf = CalibTree->GetLeaf("nHits");
395  TLeaf* highPurityLf = CalibTree->GetLeaf("highPurity");
396  TLeaf* xLf = CalibTree->GetLeaf("TrajGlbX");
397  TLeaf* yLf = CalibTree->GetLeaf("TrajGlbY");
398  TLeaf* zLf = CalibTree->GetLeaf("TrajGlbZ");
399  TLeaf* ResXSigLf = CalibTree->GetLeaf("ResXSig");
400  TLeaf* TrajLocXLf = CalibTree->GetLeaf("TrajLocX");
401  TLeaf* TrajLocYLf = CalibTree->GetLeaf("TrajLocY");
402  TLeaf* ClusterLocXLf = CalibTree->GetLeaf("ClusterLocX");
403  BunchLf = CalibTree->GetLeaf("bunchx");
404  InstLumiLf = CalibTree->GetLeaf("instLumi");
405  PULf = CalibTree->GetLeaf("PU");
406  TLeaf* CMLf = nullptr;
407  if (useCM_)
408  CMLf = CalibTree->GetLeaf("commonMode");
409 
410  int nevents = CalibTree->GetEntries();
411  edm::LogInfo("SiStripHitResolFromCalibTree")
412  << "Successfully loaded analyze function with " << nevents << " events!\n";
413 
414  map<pair<unsigned int, unsigned int>, array<double, 3> >::iterator itEventInfos;
415 
416  //Loop through all of the events
417  for (int j = 0; j < nevents; j++) {
418  CalibTree->GetEntry(j);
419  run = (unsigned int)runLf->GetValue();
420  evt = (unsigned int)evtLf->GetValue();
421  unsigned int isBad = (unsigned int)BadLf->GetValue();
422  unsigned int quality = (unsigned int)sistripLf->GetValue();
423  unsigned int id = (unsigned int)idLf->GetValue();
424  unsigned int accept = (unsigned int)acceptLf->GetValue();
425  unsigned int layer_wheel = (unsigned int)layerLf->GetValue();
426  unsigned int layer = layer_wheel;
427  if (showRings_ && layer > 10) { // use rings instead of wheels
428  if (layer < 14)
429  layer = 10 + ((id >> 9) & 0x3); //TID 3 disks and also 3 rings -> use the same container
430  else
431  layer = 13 + ((id >> 5) & 0x7); //TEC
432  }
433  //unsigned int nHits = (unsigned int)nHitsLf->GetValue();
434  bool highPurity = (bool)highPurityLf->GetValue();
435  double x = xLf->GetValue();
436  double y = yLf->GetValue();
437  double z = zLf->GetValue();
438  double resxsig = ResXSigLf->GetValue();
439  double TrajLocX = TrajLocXLf->GetValue();
440  double TrajLocY = TrajLocYLf->GetValue();
441  double ClusterLocX = ClusterLocXLf->GetValue();
442  double TrajLocXMid;
443  double stripTrajMid;
444  double stripCluster;
445  bool badquality = false;
446 
447  instLumi = 0;
448  PU = 0;
449 
450  // if no special tree with event infos, they may be stored in the hit eff tree
451  if (!foundEventInfos) {
452  bx = (unsigned int)BunchLf->GetValue();
453  if (InstLumiLf != nullptr)
454  instLumi = InstLumiLf->GetValue(); // branch not filled by default
455  if (PULf != nullptr)
456  PU = PULf->GetValue(); // branch not filled by default
457  }
458  int CM = -100;
459  if (useCM_)
460  CM = CMLf->GetValue();
461 
462  // Get infos from eventInfos if they exist
463  if (foundEventInfos) {
464  itEventInfos = eventInfos.find(make_pair(run, evt));
465  if (itEventInfos != eventInfos.end()) {
466  bx = itEventInfos->second[0];
467  instLumi = itEventInfos->second[1];
468  PU = itEventInfos->second[2];
469  }
470  }
471 
472  //We have two things we want to do, both an XY color plot, and the efficiency measurement
473  //First, ignore anything that isn't in acceptance and isn't good quality
474 
475  if (bunchx_ > 0 && bunchx_ != bx)
476  continue;
477 
478  //if(quality == 1 || accept != 1 || nHits < 8) continue;
479  if (accept != 1)
480  continue;
482  continue;
483  if (quality == 1)
484  badquality = true;
485 
486  // don't compute efficiencies in modules from TOB6 and TEC9
487  if (!showTOB6TEC9_ && (layer_wheel == 10 || layer_wheel == 22))
488  continue;
489 
490  // don't use bad modules given in the bad module list
491  itBadMod = badModules_list.find(id);
492  if (itBadMod != badModules_list.end())
493  continue;
494 
495  //Now that we have a good event, we need to look at if we expected it or not, and the location
496  //if we didn't
497  //Fill the missing hit information first
498  bool badflag = false;
499 
500  // By default uses the old matching method
501  if (resXSig_ < 0) {
502  if (isBad == 1)
503  badflag = true; // isBad set to false in the tree when resxsig<999.0
504  } else {
505  if (isBad == 1 || resxsig > resXSig_)
506  badflag = true;
507  }
508 
509  // Conversion of positions in strip unit
510  int nstrips = -9;
511  float Pitch = -9.0;
512 
513  //For converting from pitch units into micrometres
514  //const StripGeomDetUnit * conversion = dynamic_cast<const StripGeomDetUnit*>(tkgeom->idToDetUnit(DetId));
515  //auto SpecTopo = conversion->specificTopology();
516 
517  //const StripGeomDetUnit * conversion=(const StripGeomDetUnit*)tkgeom->idToDetUnit(DetId);
518  //auto SpecTopo = conversion->specificTopology();
519 
520  //edm::LogInfo("SiStripHitResolFromCalibTree") << '\n' << std::endl;
521  //edm::LogInfo("SiStripHitResolFromCalibTree") << "SpecTopo = " << SpecTopo << std::endl;
522  //edm::LogInfo("SiStripHitResolFromCalibTree") << '\n' << std::endl;
523 
524  if (resxsig == 1000.0) { // special treatment, no GeomDetUnit associated in some cases when no cluster found
525  Pitch = 0.0205; // maximum
526  nstrips = 768; // maximum
527  stripTrajMid = TrajLocX / Pitch + nstrips / 2.0;
528  stripCluster = ClusterLocX / Pitch + nstrips / 2.0;
529  } else {
530  DetId ClusterDetId(id);
531  const StripGeomDetUnit* stripdet = (const StripGeomDetUnit*)tkgeom.idToDetUnit(ClusterDetId);
532  const StripTopology& Topo = stripdet->specificTopology();
533  nstrips = Topo.nstrips();
534  Pitch = stripdet->surface().bounds().width() / Topo.nstrips();
535  stripTrajMid = TrajLocX / Pitch + nstrips / 2.0; //layer01->10
536  stripCluster = ClusterLocX / Pitch + nstrips / 2.0;
537 
538  // For trapezoidal modules: extrapolation of x trajectory position to the y middle of the module
539  // for correct comparison with cluster position
540  float hbedge = 0;
541  float htedge = 0;
542  float hapoth = 0;
543  if (layer >= 11) {
544  const BoundPlane& plane = stripdet->surface();
545  const TrapezoidalPlaneBounds* trapezoidalBounds(
546  dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
547  std::array<const float, 4> const& parameters = (*trapezoidalBounds).parameters();
548  hbedge = parameters[0];
549  htedge = parameters[1];
550  hapoth = parameters[3];
551  TrajLocXMid = TrajLocX / (1 + (htedge - hbedge) * TrajLocY / (htedge + hbedge) /
552  hapoth); // radialy extrapolated x loc position at middle
553  stripTrajMid = TrajLocXMid / Pitch + nstrips / 2.0;
554  }
555  }
556 
557  /*
558  double MeasPlotsVariable;
559  double PredPlotsVariable;
560 
561  if(UnitString == "cm"){MeasPlotsVariable = ClusterLocX; PredPlotsVariable = TrajLocX;}
562  else if(UnitString == "strip unit"){MeasPlotsVariable = ClusterLocX/Pitch; PredPlotsVariable = TrajLocX/Pitch;}
563  else{edm::LogInfo("SiStripHitResolFromCalibTree") << "ERROR: Unit must be cm or strip unit" << std::endl;}
564  */
565 
566  if (!badquality && layer < ::k_END_OF_LAYERS) {
567  if (resxsig != 1000.0) {
568  MeasPlots_m[layer]->Fill(ClusterLocX);
569  MeasPlots_p[layer]->Fill(ClusterLocX / Pitch);
570  PredPlots_m[layer]->Fill(TrajLocX);
571  PredPlots_p[layer]->Fill(TrajLocX / Pitch);
572  ResidPlots_m[layer]->Fill(ClusterLocX - TrajLocX);
573  ResidPlots_p[layer]->Fill((ClusterLocX - TrajLocX) / Pitch);
574  } else {
575  MeasPlots_m[layer]->Fill(1000);
576  MeasPlots_p[layer]->Fill(1000);
577  PredPlots_m[layer]->Fill(1000);
578  PredPlots_p[layer]->Fill(1000);
579  }
580  }
581 
582  // New matching methods
583  int tapv = -9;
584  int capv = -9;
585  float stripInAPV = 64.;
586 
587  if (clusterMatchingMethod_ >= 1) {
588  badflag = false; // reset
589  if (resxsig == 1000.0) { // default value when no cluster found in the module
590  badflag = true; // consider the module inefficient in this case
591  } else {
592  if (clusterMatchingMethod_ == 2 ||
593  clusterMatchingMethod_ == 4) { // check the distance between cluster and trajectory position
594  if (abs(stripCluster - stripTrajMid) > clusterTrajDist_)
595  badflag = true;
596  }
597  if (clusterMatchingMethod_ == 3 ||
599  4) { // cluster and traj have to be in the same APV (don't take edges into accounts)
600  tapv = (int)stripTrajMid / 128;
601  capv = (int)stripCluster / 128;
602  stripInAPV = stripTrajMid - tapv * 128;
603 
604  if (stripInAPV < stripsApvEdge_ || stripInAPV > 128 - stripsApvEdge_)
605  continue;
606  if (tapv != capv)
607  badflag = true;
608  }
609  }
610  }
611 
612  if (badflag && !badquality) {
613  hit temphit;
614  temphit.x = x;
615  temphit.y = y;
616  temphit.z = z;
617  temphit.id = id;
618  hits[layer].push_back(temphit);
619  }
620  pair<unsigned int, unsigned int> newgoodpair(1, 1);
621  pair<unsigned int, unsigned int> newbadpair(1, 0);
622  //First, figure out if the module already exists in the map of maps
623  map<unsigned int, pair<unsigned int, unsigned int> >::iterator it = modCounter[layer].find(id);
624  if (!badquality) {
625  if (it == modCounter[layer].end()) {
626  if (badflag)
627  modCounter[layer][id] = newbadpair;
628  else
629  modCounter[layer][id] = newgoodpair;
630  } else {
631  ((*it).second.first)++;
632  if (!badflag)
633  ((*it).second.second)++;
634  }
635 
636  if (layerfound_perBx.find(bx) == layerfound_perBx.end()) {
637  layerfound_perBx[bx] = vector<int>(::k_END_OF_LAYERS, 0);
638  layertotal_perBx[bx] = vector<int>(::k_END_OF_LAYERS, 0);
639  }
640  if (!badflag)
643 
644  if (!badflag)
647  if (!badflag)
648  layerfound_vsPU[layer]->Fill(PU);
649  layertotal_vsPU[layer]->Fill(PU);
650 
651  if (useCM_) {
652  if (!badflag)
653  layerfound_vsCM[layer]->Fill(CM);
654  layertotal_vsCM[layer]->Fill(CM);
655  }
656 
657  //Have to do the decoding for which side to go on (ugh)
658  if (layer <= 10) {
659  if (!badflag)
662  } else if (layer > 10 && layer < 14) {
663  if (((id >> 13) & 0x3) == 1) {
664  if (!badflag)
667  } else if (((id >> 13) & 0x3) == 2) {
668  if (!badflag)
669  goodlayerfound[layer + 3]++;
670  goodlayertotal[layer + 3]++;
671  }
672  } else if (layer > 13 && layer <= 22) {
673  if (((id >> 18) & 0x3) == 1) {
674  if (!badflag)
675  goodlayerfound[layer + 3]++;
676  goodlayertotal[layer + 3]++;
677  } else if (((id >> 18) & 0x3) == 2) {
678  if (!badflag)
681  }
682  }
683  }
684  //Do the one where we don't exclude bad modules!
685  if (layer <= 10) {
686  if (!badflag)
687  alllayerfound[layer]++;
688  alllayertotal[layer]++;
689  } else if (layer > 10 && layer < 14) {
690  if (((id >> 13) & 0x3) == 1) {
691  if (!badflag)
692  alllayerfound[layer]++;
693  alllayertotal[layer]++;
694  } else if (((id >> 13) & 0x3) == 2) {
695  if (!badflag)
696  alllayerfound[layer + 3]++;
697  alllayertotal[layer + 3]++;
698  }
699  } else if (layer > 13 && layer <= 22) {
700  if (((id >> 18) & 0x3) == 1) {
701  if (!badflag)
702  alllayerfound[layer + 3]++;
703  alllayertotal[layer + 3]++;
704  } else if (((id >> 18) & 0x3) == 2) {
705  if (!badflag)
708  }
709  }
710  //At this point, both of our maps are loaded with the correct information
711  }
712  } // go to next CalibTreeFile
713 
716  makeSQLite();
717  totalStatistics();
718  makeSummary(fs);
721  if (useCM_)
723 
725  //try to write out what's in the quality record
727  int NTkBadComponent[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
728  int NBadComponent[4][19][4];
729  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
730  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
731  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
732  std::stringstream ssV[4][19];
733 
734  for (int i = 0; i < 4; ++i) {
735  NTkBadComponent[i] = 0;
736  for (int j = 0; j < 19; ++j) {
737  ssV[i][j].str("");
738  for (int k = 0; k < 4; ++k)
739  NBadComponent[i][j][k] = 0;
740  }
741  }
742 
743  std::vector<SiStripQuality::BadComponent> BC = quality_->getBadComponentList();
744 
745  for (size_t i = 0; i < BC.size(); ++i) {
746  //&&&&&&&&&&&&&
747  //Full Tk
748  //&&&&&&&&&&&&&
749 
750  if (BC[i].BadModule)
751  NTkBadComponent[0]++;
752  if (BC[i].BadFibers)
753  NTkBadComponent[1] += ((BC[i].BadFibers >> 2) & 0x1) + ((BC[i].BadFibers >> 1) & 0x1) + ((BC[i].BadFibers) & 0x1);
754  if (BC[i].BadApvs)
755  NTkBadComponent[2] += ((BC[i].BadApvs >> 5) & 0x1) + ((BC[i].BadApvs >> 4) & 0x1) + ((BC[i].BadApvs >> 3) & 0x1) +
756  ((BC[i].BadApvs >> 2) & 0x1) + ((BC[i].BadApvs >> 1) & 0x1) + ((BC[i].BadApvs) & 0x1);
757 
758  //&&&&&&&&&&&&&&&&&
759  //Single SubSystem
760  //&&&&&&&&&&&&&&&&&
761 
762  int component;
763  DetId a(BC[i].detid);
764  if (a.subdetId() == StripSubdetector::TIB) {
765  //&&&&&&&&&&&&&&&&&
766  //TIB
767  //&&&&&&&&&&&&&&&&&
768 
769  component = tTopo.tibLayer(BC[i].detid);
770  SetBadComponents(0, component, BC[i], ssV, NBadComponent);
771 
772  } else if (a.subdetId() == StripSubdetector::TID) {
773  //&&&&&&&&&&&&&&&&&
774  //TID
775  //&&&&&&&&&&&&&&&&&
776 
777  component = tTopo.tidSide(BC[i].detid) == 2 ? tTopo.tidWheel(BC[i].detid) : tTopo.tidWheel(BC[i].detid) + 3;
778  SetBadComponents(1, component, BC[i], ssV, NBadComponent);
779 
780  } else if (a.subdetId() == StripSubdetector::TOB) {
781  //&&&&&&&&&&&&&&&&&
782  //TOB
783  //&&&&&&&&&&&&&&&&&
784 
785  component = tTopo.tobLayer(BC[i].detid);
786  SetBadComponents(2, component, BC[i], ssV, NBadComponent);
787 
788  } else if (a.subdetId() == StripSubdetector::TEC) {
789  //&&&&&&&&&&&&&&&&&
790  //TEC
791  //&&&&&&&&&&&&&&&&&
792 
793  component = tTopo.tecSide(BC[i].detid) == 2 ? tTopo.tecWheel(BC[i].detid) : tTopo.tecWheel(BC[i].detid) + 9;
794  SetBadComponents(3, component, BC[i], ssV, NBadComponent);
795  }
796  }
797 
798  //&&&&&&&&&&&&&&&&&&
799  // Single Strip Info
800  //&&&&&&&&&&&&&&&&&&
801  float percentage = 0;
802 
805 
806  for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
807  unsigned int detid = rp->detid;
808 
809  int subdet = -999;
810  int component = -999;
811  DetId a(detid);
812  if (a.subdetId() == 3) {
813  subdet = 0;
814  component = tTopo.tibLayer(detid);
815  } else if (a.subdetId() == 4) {
816  subdet = 1;
817  component = tTopo.tidSide(detid) == 2 ? tTopo.tidWheel(detid) : tTopo.tidWheel(detid) + 3;
818  } else if (a.subdetId() == 5) {
819  subdet = 2;
820  component = tTopo.tobLayer(detid);
821  } else if (a.subdetId() == 6) {
822  subdet = 3;
823  component = tTopo.tecSide(detid) == 2 ? tTopo.tecWheel(detid) : tTopo.tecWheel(detid) + 9;
824  }
825 
826  SiStripQuality::Range sqrange =
828 
829  percentage = 0;
830  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
831  unsigned int range = quality_->decode(*(sqrange.first + it)).range;
832  NTkBadComponent[3] += range;
833  NBadComponent[subdet][0][3] += range;
834  NBadComponent[subdet][component][3] += range;
835  percentage += range;
836  }
837  if (percentage != 0)
838  percentage /= 128. * detInfo_.getNumberOfApvsAndStripLength(detid).first;
839  if (percentage > 1)
840  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage << std::endl;
841  }
842  //&&&&&&&&&&&&&&&&&&
843  // printout
844  //&&&&&&&&&&&&&&&&&&
845 
846  std::ofstream ResolutionValues;
847  int RunNumInt = e.id().run();
848  std::string RunNumString = std::to_string(RunNumInt);
849  edm::LogInfo("SiStripHitResolFromCalibTree") << "RunNumString" << RunNumString << std::endl;
850  std::string ResolutionTextFileString = "ResolutionValues_" + RunNumString + "_" + FileNameEnding + ".txt";
851 
852  ResolutionValues.open(ResolutionTextFileString.c_str());
853 
854  for (Long_t ilayer = 0; ilayer < ::k_END_OF_LAYERS; ilayer++) {
855  //Calculating and printing out the resolution values
856 
857  float Meas = MeasPlots_p[ilayer]->GetStdDev();
858  float Pred = PredPlots_p[ilayer]->GetStdDev();
859 
860  float PredMinusMeas = pow(Meas, 2) + pow(Pred, 2); //width^2= sigma(deltaX_pred)^2 + sigma(deltaX_hit)^2
861 
862  float Resolution = sqrt(Pred / 2);
863 
864  //Saving the resolution values to a text file
865  ResolutionValues << '\n'
866  << "Resolution for layer number " << ilayer << " (" << GetLayerName(ilayer) << ")"
867  << " is: " << Resolution << '\n'
868  << "Double difference of the measured and predicted position between the two sensors under "
869  "consideration for layer number "
870  << ilayer << " (" << GetLayerName(ilayer) << ")"
871  << " is: " << PredMinusMeas << '\n'
872  << "The difference between the two positions of the hit measurements for layer number " << ilayer
873  << " (" << GetLayerName(ilayer) << ")"
874  << " is: " << Meas << '\n'
875  << std::endl;
876  }
877 
878  edm::LogInfo("SiStripHitResolFromCalibTree")
879  << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event()
880  << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
881  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n-----------------\nGlobal Info\n-----------------";
882  edm::LogInfo("SiStripHitResolFromCalibTree")
883  << "\nBadComponent \t Modules \tFibers "
884  "\tApvs\tStrips\n----------------------------------------------------------------";
885  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1]
886  << "\t" << NTkBadComponent[2] << "\t" << NTkBadComponent[3];
887  edm::LogInfo("SiStripHitResolFromCalibTree") << endl;
888  edm::LogInfo("SiStripHitResolFromCalibTree")
889  << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
890  << "\t" << NBadComponent[0][0][3];
891  edm::LogInfo("SiStripHitResolFromCalibTree")
892  << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
893  << "\t" << NBadComponent[1][0][3];
894  edm::LogInfo("SiStripHitResolFromCalibTree")
895  << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
896  << "\t" << NBadComponent[2][0][3];
897  edm::LogInfo("SiStripHitResolFromCalibTree")
898  << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
899  << "\t" << NBadComponent[3][0][3];
900  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
901 
902  for (int i = 1; i < 5; ++i)
903  edm::LogInfo("SiStripHitResolFromCalibTree")
904  << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
905  << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
906  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
907  for (int i = 1; i < 4; ++i)
908  edm::LogInfo("SiStripHitResolFromCalibTree")
909  << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
910  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
911  for (int i = 4; i < 7; ++i)
912  edm::LogInfo("SiStripHitResolFromCalibTree")
913  << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
914  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
915  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
916  for (int i = 1; i < 7; ++i)
917  edm::LogInfo("SiStripHitResolFromCalibTree")
918  << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
919  << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
920  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
921  for (int i = 1; i < 10; ++i)
922  edm::LogInfo("SiStripHitResolFromCalibTree")
923  << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
924  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
925  for (int i = 10; i < 19; ++i)
926  edm::LogInfo("SiStripHitResolFromCalibTree")
927  << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
928  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
929  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
930 
931  edm::LogInfo("SiStripHitResolFromCalibTree")
932  << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
933  "Apvs\n----------------------------------------------------------------";
934  for (int i = 1; i < 5; ++i)
935  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTIB Layer " << i << " :" << ssV[0][i].str();
936  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
937  for (int i = 1; i < 4; ++i)
938  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
939  for (int i = 4; i < 7; ++i)
940  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
941  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
942  for (int i = 1; i < 7; ++i)
943  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTOB Layer " << i << " :" << ssV[2][i].str();
944  edm::LogInfo("SiStripHitResolFromCalibTree") << "\n";
945  for (int i = 1; i < 10; ++i)
946  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
947  for (int i = 10; i < 19; ++i)
948  edm::LogInfo("SiStripHitResolFromCalibTree") << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
949 
950  // store also bad modules in log file
951  ofstream badModules;
952  badModules.open("BadModules.log");
953  badModules << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
954  "Apvs\n----------------------------------------------------------------";
955  for (int i = 1; i < 5; ++i)
956  badModules << "\nTIB Layer " << i << " :" << ssV[0][i].str();
957  badModules << "\n";
958  for (int i = 1; i < 4; ++i)
959  badModules << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
960  for (int i = 4; i < 7; ++i)
961  badModules << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
962  badModules << "\n";
963  for (int i = 1; i < 7; ++i)
964  badModules << "\nTOB Layer " << i << " :" << ssV[2][i].str();
965  badModules << "\n";
966  for (int i = 1; i < 10; ++i)
967  badModules << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
968  for (int i = 10; i < 19; ++i)
969  badModules << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
970  badModules.close();
971 }
972 
974  edm::LogInfo("SiStripHitResolFromCalibTree") << "Entering hot cold map generation!\n";
975  TStyle* gStyle = new TStyle("gStyle", "myStyle");
976  gStyle->cd();
977  gStyle->SetPalette(1);
978  gStyle->SetCanvasColor(kWhite);
979  gStyle->SetOptStat(0);
980  //Here we make the hot/cold color maps that we love so very much
981  //Already have access to the data as a private variable
982  //Create all of the histograms in the TFileService
983  TH2F* temph2;
984  for (Long_t maplayer = 1; maplayer <= 22; maplayer++) {
985  //Initialize all of the histograms
986  if (maplayer > 0 && maplayer <= 4) {
987  //We are in the TIB
988  temph2 = fs->make<TH2F>(Form("%s%i", "TIB", (int)(maplayer)), "TIB", 100, -1, 361, 100, -100, 100);
989  temph2->GetXaxis()->SetTitle("Phi");
990  temph2->GetXaxis()->SetBinLabel(1, TString("360"));
991  temph2->GetXaxis()->SetBinLabel(50, TString("180"));
992  temph2->GetXaxis()->SetBinLabel(100, TString("0"));
993  temph2->GetYaxis()->SetTitle("Global Z");
994  temph2->SetOption("colz");
995  HotColdMaps.push_back(temph2);
996  } else if (maplayer > 4 && maplayer <= 10) {
997  //We are in the TOB
998  temph2 = fs->make<TH2F>(Form("%s%i", "TOB", (int)(maplayer - 4)), "TOB", 100, -1, 361, 100, -120, 120);
999  temph2->GetXaxis()->SetTitle("Phi");
1000  temph2->GetXaxis()->SetBinLabel(1, TString("360"));
1001  temph2->GetXaxis()->SetBinLabel(50, TString("180"));
1002  temph2->GetXaxis()->SetBinLabel(100, TString("0"));
1003  temph2->GetYaxis()->SetTitle("Global Z");
1004  temph2->SetOption("colz");
1005  HotColdMaps.push_back(temph2);
1006  } else if (maplayer > 10 && maplayer <= 13) {
1007  //We are in the TID
1008  //Split by +/-
1009  temph2 = fs->make<TH2F>(Form("%s%i", "TID-", (int)(maplayer - 10)), "TID-", 100, -100, 100, 100, -100, 100);
1010  temph2->GetXaxis()->SetTitle("Global Y");
1011  temph2->GetXaxis()->SetBinLabel(1, TString("+Y"));
1012  temph2->GetXaxis()->SetBinLabel(50, TString("0"));
1013  temph2->GetXaxis()->SetBinLabel(100, TString("-Y"));
1014  temph2->GetYaxis()->SetTitle("Global X");
1015  temph2->GetYaxis()->SetBinLabel(1, TString("-X"));
1016  temph2->GetYaxis()->SetBinLabel(50, TString("0"));
1017  temph2->GetYaxis()->SetBinLabel(100, TString("+X"));
1018  temph2->SetOption("colz");
1019  HotColdMaps.push_back(temph2);
1020  temph2 = fs->make<TH2F>(Form("%s%i", "TID+", (int)(maplayer - 10)), "TID+", 100, -100, 100, 100, -100, 100);
1021  temph2->GetXaxis()->SetTitle("Global Y");
1022  temph2->GetXaxis()->SetBinLabel(1, TString("+Y"));
1023  temph2->GetXaxis()->SetBinLabel(50, TString("0"));
1024  temph2->GetXaxis()->SetBinLabel(100, TString("-Y"));
1025  temph2->GetYaxis()->SetTitle("Global X");
1026  temph2->GetYaxis()->SetBinLabel(1, TString("-X"));
1027  temph2->GetYaxis()->SetBinLabel(50, TString("0"));
1028  temph2->GetYaxis()->SetBinLabel(100, TString("+X"));
1029  temph2->SetOption("colz");
1030  HotColdMaps.push_back(temph2);
1031  } else if (maplayer > 13) {
1032  //We are in the TEC
1033  //Split by +/-
1034  temph2 = fs->make<TH2F>(Form("%s%i", "TEC-", (int)(maplayer - 13)), "TEC-", 100, -120, 120, 100, -120, 120);
1035  temph2->GetXaxis()->SetTitle("Global Y");
1036  temph2->GetXaxis()->SetBinLabel(1, TString("+Y"));
1037  temph2->GetXaxis()->SetBinLabel(50, TString("0"));
1038  temph2->GetXaxis()->SetBinLabel(100, TString("-Y"));
1039  temph2->GetYaxis()->SetTitle("Global X");
1040  temph2->GetYaxis()->SetBinLabel(1, TString("-X"));
1041  temph2->GetYaxis()->SetBinLabel(50, TString("0"));
1042  temph2->GetYaxis()->SetBinLabel(100, TString("+X"));
1043  temph2->SetOption("colz");
1044  HotColdMaps.push_back(temph2);
1045  temph2 = fs->make<TH2F>(Form("%s%i", "TEC+", (int)(maplayer - 13)), "TEC+", 100, -120, 120, 100, -120, 120);
1046  temph2->GetXaxis()->SetTitle("Global Y");
1047  temph2->GetXaxis()->SetBinLabel(1, TString("+Y"));
1048  temph2->GetXaxis()->SetBinLabel(50, TString("0"));
1049  temph2->GetXaxis()->SetBinLabel(100, TString("-Y"));
1050  temph2->GetYaxis()->SetTitle("Global X");
1051  temph2->GetYaxis()->SetBinLabel(1, TString("-X"));
1052  temph2->GetYaxis()->SetBinLabel(50, TString("0"));
1053  temph2->GetYaxis()->SetBinLabel(100, TString("+X"));
1054  temph2->SetOption("colz");
1055  HotColdMaps.push_back(temph2);
1056  }
1057  }
1058  for (Long_t mylayer = 1; mylayer <= 22; mylayer++) {
1059  //Determine what kind of plot we want to write out
1060  //Loop through the entirety of each layer
1061  //Create an array of the histograms
1062  vector<hit>::const_iterator iter;
1063  for (iter = hits[mylayer].begin(); iter != hits[mylayer].end(); iter++) {
1064  //Looping over the particular layer
1065  //Fill by 360-x to get the proper location to compare with TKMaps of phi
1066  //Also global xy is messed up
1067  if (mylayer > 0 && mylayer <= 4) {
1068  //We are in the TIB
1069  float phi = calcPhi(iter->x, iter->y);
1070  HotColdMaps[mylayer - 1]->Fill(360. - phi, iter->z, 1.);
1071  } else if (mylayer > 4 && mylayer <= 10) {
1072  //We are in the TOB
1073  float phi = calcPhi(iter->x, iter->y);
1074  HotColdMaps[mylayer - 1]->Fill(360. - phi, iter->z, 1.);
1075  } else if (mylayer > 10 && mylayer <= 13) {
1076  //We are in the TID
1077  //There are 2 different maps here
1078  int side = (((iter->id) >> 13) & 0x3);
1079  if (side == 1)
1080  HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(-iter->y, iter->x, 1.);
1081  else if (side == 2)
1082  HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(-iter->y, iter->x, 1.);
1083  //if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(iter->x,iter->y,1.);
1084  //else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(iter->x,iter->y,1.);
1085  } else if (mylayer > 13) {
1086  //We are in the TEC
1087  //There are 2 different maps here
1088  int side = (((iter->id) >> 18) & 0x3);
1089  if (side == 1)
1090  HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(-iter->y, iter->x, 1.);
1091  else if (side == 2)
1092  HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(-iter->y, iter->x, 1.);
1093  //if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(iter->x,iter->y,1.);
1094  //else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(iter->x,iter->y,1.);
1095  }
1096  }
1097  }
1098  edm::LogInfo("SiStripHitResolFromCalibTree") << "Finished HotCold Map Generation\n";
1099 }
1100 
1102  edm::LogInfo("SiStripHitResolFromCalibTree") << "Entering TKMap generation!\n";
1103  tkmap = new TrackerMap(" Detector Inefficiency ");
1104  tkmapbad = new TrackerMap(" Inefficient Modules ");
1105  tkmapeff = new TrackerMap(title_.Data());
1106  tkmapnum = new TrackerMap(" Detector numerator ");
1107  tkmapden = new TrackerMap(" Detector denominator ");
1108 
1109  double myeff, mynum, myden;
1110  double eff_limit = 0;
1111 
1112  for (Long_t i = 1; i <= 22; i++) {
1113  //Loop over every layer, extracting the information from
1114  //the map of the efficiencies
1115  layertotal[i] = 0;
1116  layerfound[i] = 0;
1117  TH1F* hEffInLayer =
1118  fs->make<TH1F>(Form("eff_layer%i", int(i)), Form("Module efficiency in layer %i", int(i)), 201, 0, 1.005);
1119 
1120  map<unsigned int, pair<unsigned int, unsigned int> >::const_iterator ih;
1121  for (ih = modCounter[i].begin(); ih != modCounter[i].end(); ih++) {
1122  //We should be in the layer in question, and looping over all of the modules in said layer
1123  //Generate the list for the TKmap, and the bad module list
1124  mynum = (double)(((*ih).second).second);
1125  myden = (double)(((*ih).second).first);
1126  if (myden > 0)
1127  myeff = mynum / myden;
1128  else
1129  myeff = 0;
1130  hEffInLayer->Fill(myeff);
1131 
1132  if (!autoTagging) {
1133  if ((myden >= nModsMin_) && (myeff < threshold_)) {
1134  //We have a bad module, put it in the list!
1135  BadModules[(*ih).first] = myeff;
1136  tkmapbad->fillc((*ih).first, 255, 0, 0);
1137  edm::LogInfo("SiStripHitResolFromCalibTree")
1138  << "Layer " << i << " (" << GetLayerName(i) << ") module " << (*ih).first << " efficiency: " << myeff
1139  << " , " << mynum << "/" << myden << endl;
1140  } else {
1141  //Fill the bad list with empty results for every module
1142  tkmapbad->fillc((*ih).first, 255, 255, 255);
1143  }
1144  if (myden < nModsMin_) {
1145  edm::LogInfo("SiStripHitResolFromCalibTree") << "Layer " << i << " (" << GetLayerName(i) << ") module "
1146  << (*ih).first << " is under occupancy at " << myden << endl;
1147  }
1148  }
1149 
1150  //Put any module into the TKMap
1151  tkmap->fill((*ih).first, 1. - myeff);
1152  tkmapeff->fill((*ih).first, myeff);
1153  tkmapnum->fill((*ih).first, mynum);
1154  tkmapden->fill((*ih).first, myden);
1155 
1156  //Add the number of hits in the layer
1157  layertotal[i] += long(myden);
1158  layerfound[i] += long(mynum);
1159  }
1160 
1161  if (autoTagging) {
1162  //Compute threshold to use for each layer
1163  hEffInLayer->GetXaxis()->SetRange(3, hEffInLayer->GetNbinsX() + 1); // Remove from the avg modules below 1%
1164  eff_limit = hEffInLayer->GetMean() - threshold_;
1165  edm::LogInfo("SiStripHitResolFromCalibTree")
1166  << "Layer " << i << " threshold for bad modules: " << eff_limit << endl;
1167  hEffInLayer->GetXaxis()->SetRange(1, hEffInLayer->GetNbinsX() + 1);
1168 
1169  for (ih = modCounter[i].begin(); ih != modCounter[i].end(); ih++) {
1170  // Second loop over modules to tag inefficient ones
1171  mynum = (double)(((*ih).second).second);
1172  myden = (double)(((*ih).second).first);
1173  if (myden > 0)
1174  myeff = mynum / myden;
1175  else
1176  myeff = 0;
1177  if ((myden >= nModsMin_) && (myeff < eff_limit)) {
1178  //We have a bad module, put it in the list!
1179  BadModules[(*ih).first] = myeff;
1180  tkmapbad->fillc((*ih).first, 255, 0, 0);
1181  edm::LogInfo("SiStripHitResolFromCalibTree")
1182  << "Layer " << i << " (" << GetLayerName(i) << ") module " << (*ih).first << " efficiency: " << myeff
1183  << " , " << mynum << "/" << myden << endl;
1184  } else {
1185  //Fill the bad list with empty results for every module
1186  tkmapbad->fillc((*ih).first, 255, 255, 255);
1187  }
1188  if (myden < nModsMin_) {
1189  edm::LogInfo("SiStripHitResolFromCalibTree")
1190  << "Layer " << i << " (" << GetLayerName(i) << ") module " << (*ih).first << " layer " << i
1191  << " is under occupancy at " << myden << endl;
1192  }
1193  }
1194  }
1195  }
1196  tkmap->save(true, 0, 0, "SiStripHitResolTKMap.png");
1197  tkmapbad->save(true, 0, 0, "SiStripHitResolTKMapBad.png");
1198  tkmapeff->save(true, tkMapMin_, 1., "SiStripHitResolTKMapEff.png");
1199  tkmapnum->save(true, 0, 0, "SiStripHitResolTKMapNum.png");
1200  tkmapden->save(true, 0, 0, "SiStripHitResolTKMapDen.png");
1201  edm::LogInfo("SiStripHitResolFromCalibTree") << "Finished TKMap Generation\n";
1202 }
1203 
1205  //Generate the SQLite file for use in the Database of the bad modules!
1206  edm::LogInfo("SiStripHitResolFromCalibTree") << "Entering SQLite file generation!\n";
1207  std::vector<unsigned int> BadStripList;
1208  unsigned short NStrips;
1209  unsigned int id1;
1210  std::unique_ptr<SiStripQuality> pQuality = std::make_unique<SiStripQuality>(detInfo_);
1211  //This is the list of the bad strips, use to mask out entire APVs
1212  //Now simply go through the bad hit list and mask out things that
1213  //are bad!
1214  map<unsigned int, double>::const_iterator it;
1215  for (it = BadModules.begin(); it != BadModules.end(); it++) {
1216  //We need to figure out how many strips are in this particular module
1217  //To Mask correctly!
1218  NStrips = detInfo_.getNumberOfApvsAndStripLength((*it).first).first * 128;
1219  edm::LogInfo("SiStripHitResolFromCalibTree")
1220  << "Number of strips module " << (*it).first << " is " << NStrips << endl;
1221  BadStripList.push_back(pQuality->encode(0, NStrips, 0));
1222  //Now compact into a single bad module
1223  id1 = (unsigned int)(*it).first;
1224  edm::LogInfo("SiStripHitResolFromCalibTree") << "ID1 shoudl match list of modules above " << id1 << endl;
1225  quality_->compact(id1, BadStripList);
1226  SiStripQuality::Range range(BadStripList.begin(), BadStripList.end());
1227  quality_->put(id1, range);
1228  BadStripList.clear();
1229  }
1230  //Fill all the bad components now
1232 }
1233 
1235  //Calculate the statistics by layer
1236  int totalfound = 0;
1237  int totaltotal = 0;
1238  double layereff;
1239  int subdetfound[5];
1240  int subdettotal[5];
1241 
1242  for (Long_t i = 1; i < 5; i++) {
1243  subdetfound[i] = 0;
1244  subdettotal[i] = 0;
1245  }
1246 
1247  for (Long_t i = 1; i <= 22; i++) {
1248  layereff = double(layerfound[i]) / double(layertotal[i]);
1249  edm::LogInfo("SiStripHitResolFromCalibTree")
1250  << "Layer " << i << " (" << GetLayerName(i) << ") has total efficiency " << layereff << " " << layerfound[i]
1251  << "/" << layertotal[i] << endl;
1252  totalfound += layerfound[i];
1253  totaltotal += layertotal[i];
1254  if (i < 5) {
1255  subdetfound[1] += layerfound[i];
1256  subdettotal[1] += layertotal[i];
1257  }
1258  if (i >= 5 && i < 11) {
1259  subdetfound[2] += layerfound[i];
1260  subdettotal[2] += layertotal[i];
1261  }
1262  if (i >= 11 && i < 14) {
1263  subdetfound[3] += layerfound[i];
1264  subdettotal[3] += layertotal[i];
1265  }
1266  if (i >= 14) {
1267  subdetfound[4] += layerfound[i];
1268  subdettotal[4] += layertotal[i];
1269  }
1270  }
1271 
1272  edm::LogInfo("SiStripHitResolFromCalibTree")
1273  << "The total efficiency is " << double(totalfound) / double(totaltotal) << endl;
1274  edm::LogInfo("SiStripHitResolFromCalibTree") << " TIB: " << double(subdetfound[1]) / subdettotal[1] << " "
1275  << subdetfound[1] << "/" << subdettotal[1] << endl;
1276  edm::LogInfo("SiStripHitResolFromCalibTree") << " TOB: " << double(subdetfound[2]) / subdettotal[2] << " "
1277  << subdetfound[2] << "/" << subdettotal[2] << endl;
1278  edm::LogInfo("SiStripHitResolFromCalibTree") << " TID: " << double(subdetfound[3]) / subdettotal[3] << " "
1279  << subdetfound[3] << "/" << subdettotal[3] << endl;
1280  edm::LogInfo("SiStripHitResolFromCalibTree") << " TEC: " << double(subdetfound[4]) / subdettotal[4] << " "
1281  << subdetfound[4] << "/" << subdettotal[4] << endl;
1282 }
1283 
1285  //setTDRStyle();
1286 
1287  int nLayers = 34;
1288  if (showRings_)
1289  nLayers = 30;
1290  if (!showEndcapSides_) {
1291  if (!showRings_)
1292  nLayers = 22;
1293  else
1294  nLayers = 20;
1295  }
1296 
1297  TH1F* found = fs->make<TH1F>("found", "found", nLayers + 1, 0, nLayers + 1);
1298  TH1F* all = fs->make<TH1F>("all", "all", nLayers + 1, 0, nLayers + 1);
1299  TH1F* found2 = fs->make<TH1F>("found2", "found2", nLayers + 1, 0, nLayers + 1);
1300  TH1F* all2 = fs->make<TH1F>("all2", "all2", nLayers + 1, 0, nLayers + 1);
1301  // first bin only to keep real data off the y axis so set to -1
1302  found->SetBinContent(0, -1);
1303  all->SetBinContent(0, 1);
1304 
1305  // new ROOT version: TGraph::Divide don't handle null or negative values
1306  for (Long_t i = 1; i < nLayers + 2; ++i) {
1307  found->SetBinContent(i, 1e-6);
1308  all->SetBinContent(i, 1);
1309  found2->SetBinContent(i, 1e-6);
1310  all2->SetBinContent(i, 1);
1311  }
1312 
1313  TCanvas* c7 = new TCanvas("c7", " test ", 10, 10, 800, 600);
1314  c7->SetFillColor(0);
1315  c7->SetGrid();
1316 
1317  int nLayers_max = nLayers + 1; // barrel+endcap
1318  if (!showEndcapSides_)
1319  nLayers_max = 11; // barrel
1320  for (Long_t i = 1; i < nLayers_max; ++i) {
1321  edm::LogInfo("SiStripHitResolFromCalibTree")
1322  << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] << " B = " << goodlayertotal[i]
1323  << endl;
1324  if (goodlayertotal[i] > 5) {
1325  found->SetBinContent(i, goodlayerfound[i]);
1326  all->SetBinContent(i, goodlayertotal[i]);
1327  }
1328 
1329  edm::LogInfo("SiStripHitResolFromCalibTree")
1330  << "Filling all modules layer " << i << ": S = " << alllayerfound[i] << " B = " << alllayertotal[i] << endl;
1331  if (alllayertotal[i] > 5) {
1332  found2->SetBinContent(i, alllayerfound[i]);
1333  all2->SetBinContent(i, alllayertotal[i]);
1334  }
1335  }
1336 
1337  // endcap - merging sides
1338  if (!showEndcapSides_) {
1339  for (Long_t i = 11; i < 14; ++i) { // TID disks
1340  edm::LogInfo("SiStripHitResolFromCalibTree")
1341  << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] + goodlayerfound[i + 3]
1342  << " B = " << goodlayertotal[i] + goodlayertotal[i + 3] << endl;
1343  if (goodlayertotal[i] + goodlayertotal[i + 3] > 5) {
1344  found->SetBinContent(i, goodlayerfound[i] + goodlayerfound[i + 3]);
1345  all->SetBinContent(i, goodlayertotal[i] + goodlayertotal[i + 3]);
1346  }
1347  edm::LogInfo("SiStripHitResolFromCalibTree")
1348  << "Filling all modules layer " << i << ": S = " << alllayerfound[i] + alllayerfound[i + 3]
1349  << " B = " << alllayertotal[i] + alllayertotal[i + 3] << endl;
1350  if (alllayertotal[i] + alllayertotal[i + 3] > 5) {
1351  found2->SetBinContent(i, alllayerfound[i] + alllayerfound[i + 3]);
1352  all2->SetBinContent(i, alllayertotal[i] + alllayertotal[i + 3]);
1353  }
1354  }
1355  for (Long_t i = 17; i < 17 + nTEClayers_; ++i) { // TEC disks
1356  edm::LogInfo("SiStripHitResolFromCalibTree")
1357  << "Fill only good modules layer " << i - 3
1358  << ": S = " << goodlayerfound[i] + goodlayerfound[i + nTEClayers_]
1359  << " B = " << goodlayertotal[i] + goodlayertotal[i + nTEClayers_] << endl;
1360  if (goodlayertotal[i] + goodlayertotal[i + nTEClayers_] > 5) {
1361  found->SetBinContent(i - 3, goodlayerfound[i] + goodlayerfound[i + nTEClayers_]);
1362  all->SetBinContent(i - 3, goodlayertotal[i] + goodlayertotal[i + nTEClayers_]);
1363  }
1364  edm::LogInfo("SiStripHitResolFromCalibTree")
1365  << "Filling all modules layer " << i - 3 << ": S = " << alllayerfound[i] + alllayerfound[i + nTEClayers_]
1366  << " B = " << alllayertotal[i] + alllayertotal[i + nTEClayers_] << endl;
1367  if (alllayertotal[i] + alllayertotal[i + nTEClayers_] > 5) {
1368  found2->SetBinContent(i - 3, alllayerfound[i] + alllayerfound[i + nTEClayers_]);
1369  all2->SetBinContent(i - 3, alllayertotal[i] + alllayertotal[i + nTEClayers_]);
1370  }
1371  }
1372  }
1373 
1374  found->Sumw2();
1375  all->Sumw2();
1376 
1377  found2->Sumw2();
1378  all2->Sumw2();
1379 
1380  TGraphAsymmErrors* gr = fs->make<TGraphAsymmErrors>(nLayers + 1);
1381  gr->SetName("eff_good");
1382  gr->BayesDivide(found, all);
1383 
1384  TGraphAsymmErrors* gr2 = fs->make<TGraphAsymmErrors>(nLayers + 1);
1385  gr2->SetName("eff_all");
1386  gr2->BayesDivide(found2, all2);
1387 
1388  for (int j = 0; j < nLayers + 1; j++) {
1389  gr->SetPointError(j, 0., 0., gr->GetErrorYlow(j), gr->GetErrorYhigh(j));
1390  gr2->SetPointError(j, 0., 0., gr2->GetErrorYlow(j), gr2->GetErrorYhigh(j));
1391  }
1392 
1393  gr->GetXaxis()->SetLimits(0, nLayers);
1394  gr->SetMarkerColor(2);
1395  gr->SetMarkerSize(1.2);
1396  gr->SetLineColor(2);
1397  gr->SetLineWidth(4);
1398  gr->SetMarkerStyle(20);
1399  gr->SetMinimum(effPlotMin_);
1400  gr->SetMaximum(1.001);
1401  gr->GetYaxis()->SetTitle("Efficiency");
1402  gStyle->SetTitleFillColor(0);
1403  gStyle->SetTitleBorderSize(0);
1404  gr->SetTitle(title_);
1405 
1406  gr2->GetXaxis()->SetLimits(0, nLayers);
1407  gr2->SetMarkerColor(1);
1408  gr2->SetMarkerSize(1.2);
1409  gr2->SetLineColor(1);
1410  gr2->SetLineWidth(4);
1411  gr2->SetMarkerStyle(21);
1412  gr2->SetMinimum(effPlotMin_);
1413  gr2->SetMaximum(1.001);
1414  gr2->GetYaxis()->SetTitle("Efficiency");
1415  gr2->SetTitle(title_);
1416 
1417  for (Long_t k = 1; k < nLayers + 1; k++) {
1418  TString label;
1419  if (showEndcapSides_)
1421  else
1422  label = GetLayerName(k);
1423  if (!showTOB6TEC9_) {
1424  if (k == 10)
1425  label = "";
1426  if (!showRings_ && k == nLayers)
1427  label = "";
1428  if (!showRings_ && showEndcapSides_ && k == 25)
1429  label = "";
1430  }
1431  if (!showRings_) {
1432  if (showEndcapSides_) {
1433  gr->GetXaxis()->SetBinLabel(((k + 1) * 100 + 2) / (nLayers)-4, label);
1434  gr2->GetXaxis()->SetBinLabel(((k + 1) * 100 + 2) / (nLayers)-4, label);
1435  } else {
1436  gr->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-6, label);
1437  gr2->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-6, label);
1438  }
1439  } else {
1440  if (showEndcapSides_) {
1441  gr->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-4, label);
1442  gr2->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-4, label);
1443  } else {
1444  gr->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-7, label);
1445  gr2->GetXaxis()->SetBinLabel((k + 1) * 100 / (nLayers)-7, label);
1446  }
1447  }
1448  }
1449 
1450  gr->Draw("AP");
1451  gr->GetXaxis()->SetNdivisions(36);
1452 
1453  c7->cd();
1454  TPad* overlay = new TPad("overlay", "", 0, 0, 1, 1);
1455  overlay->SetFillStyle(4000);
1456  overlay->SetFillColor(0);
1457  overlay->SetFrameFillStyle(4000);
1458  overlay->Draw("same");
1459  overlay->cd();
1460  if (!showOnlyGoodModules_)
1461  gr2->Draw("AP");
1462 
1463  TLegend* leg = new TLegend(0.70, 0.27, 0.88, 0.40);
1464  leg->AddEntry(gr, "Good Modules", "p");
1465  if (!showOnlyGoodModules_)
1466  leg->AddEntry(gr2, "All Modules", "p");
1467  leg->SetTextSize(0.020);
1468  leg->SetFillColor(0);
1469  leg->Draw("same");
1470 
1471  c7->SaveAs("Summary.png");
1472 }
1473 
1475  edm::LogInfo("SiStripHitResolFromCalibTree") << "Computing efficiency vs bx" << endl;
1476 
1477  unsigned int nLayers = 22;
1478  if (showRings_)
1479  nLayers = 20;
1480 
1481  for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) {
1482  for (unsigned int ibx = 0; ibx <= nBxInAnOrbit; ibx++) {
1483  layerfound_vsBX[ilayer]->SetBinContent(ibx, 1e-6);
1484  layertotal_vsBX[ilayer]->SetBinContent(ibx, 1);
1485  }
1486 
1487  map<unsigned int, vector<int> >::iterator iterMapvsBx;
1488  for (iterMapvsBx = layerfound_perBx.begin(); iterMapvsBx != layerfound_perBx.end(); ++iterMapvsBx)
1489  layerfound_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]);
1490  for (iterMapvsBx = layertotal_perBx.begin(); iterMapvsBx != layertotal_perBx.end(); ++iterMapvsBx)
1491  if (iterMapvsBx->second[ilayer] > 0)
1492  layertotal_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]);
1493 
1494  layerfound_vsBX[ilayer]->Sumw2();
1495  layertotal_vsBX[ilayer]->Sumw2();
1496 
1497  TGraphAsymmErrors* geff = fs->make<TGraphAsymmErrors>(nBxInAnOrbit - 1);
1498  geff->SetName(Form("effVsBx_layer%i", ilayer));
1499  geff->SetTitle("Hit Efficiency vs bx - " + GetLayerName(ilayer));
1500  geff->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]);
1501 
1502  //Average over trains
1503  TGraphAsymmErrors* geff_avg = fs->make<TGraphAsymmErrors>();
1504  geff_avg->SetName(Form("effVsBxAvg_layer%i", ilayer));
1505  geff_avg->SetTitle("Hit Efficiency vs bx - " + GetLayerName(ilayer));
1506  geff_avg->SetMarkerStyle(20);
1507  int ibx = 0;
1508  int previous_bx = -80;
1509  int delta_bx = 0;
1510  int nbx = 0;
1511  int found = 0;
1512  int total = 0;
1513  double sum_bx = 0;
1514  int ipt = 0;
1515  float low, up, eff;
1516  int firstbx = 0;
1517  for (iterMapvsBx = layertotal_perBx.begin(); iterMapvsBx != layertotal_perBx.end(); ++iterMapvsBx) {
1518  ibx = iterMapvsBx->first;
1519  delta_bx = ibx - previous_bx;
1520  // consider a new train
1521  if (delta_bx > (int)spaceBetweenTrains_ && nbx > 0 && total > 0) {
1522  eff = found / (float)total;
1523  //edm::LogInfo("SiStripHitResolFromCalibTree")<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
1524  geff_avg->SetPoint(ipt, sum_bx / nbx, eff);
1525  low = TEfficiency::Bayesian(total, found, .683, 1, 1, false);
1526  up = TEfficiency::Bayesian(total, found, .683, 1, 1, true);
1527  geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff);
1528  ipt++;
1529  sum_bx = 0;
1530  found = 0;
1531  total = 0;
1532  nbx = 0;
1533  firstbx = ibx;
1534  }
1535  sum_bx += ibx;
1536  found += layerfound_vsBX[ilayer]->GetBinContent(ibx);
1537  total += layertotal_vsBX[ilayer]->GetBinContent(ibx);
1538  nbx++;
1539 
1540  previous_bx = ibx;
1541  }
1542  //last train
1543  eff = found / (float)total;
1544  //edm::LogInfo("SiStripHitResolFromCalibTree")<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
1545  geff_avg->SetPoint(ipt, sum_bx / nbx, eff);
1546  low = TEfficiency::Bayesian(total, found, .683, 1, 1, false);
1547  up = TEfficiency::Bayesian(total, found, .683, 1, 1, true);
1548  geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff);
1549  }
1550 }
1551 
1553  TString layername = "";
1554  TString ringlabel = "D";
1555  if (showRings_)
1556  ringlabel = "R";
1557  if (k > 0 && k < 5) {
1558  layername = TString("TIB L") + k;
1559  } else if (k > 4 && k < 11) {
1560  layername = TString("TOB L") + (k - 4);
1561  } else if (k > 10 && k < 14) {
1562  layername = TString("TID ") + ringlabel + (k - 10);
1563  } else if (k > 13 && k < 14 + nTEClayers_) {
1564  layername = TString("TEC ") + ringlabel + (k - 13);
1565  }
1566 
1567  return layername;
1568 }
1569 
1571  vector<TH1F*>& vhfound,
1572  vector<TH1F*>& vhtotal,
1573  string name) {
1574  unsigned int nLayers = 22;
1575  if (showRings_)
1576  nLayers = 20;
1577 
1578  TH1F* hfound;
1579  TH1F* htotal;
1580 
1581  for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) {
1582  hfound = vhfound[ilayer];
1583  htotal = vhtotal[ilayer];
1584 
1585  hfound->Sumw2();
1586  htotal->Sumw2();
1587 
1588  // new ROOT version: TGraph::Divide don't handle null or negative values
1589  for (Long_t i = 0; i < hfound->GetNbinsX() + 1; ++i) {
1590  if (hfound->GetBinContent(i) == 0)
1591  hfound->SetBinContent(i, 1e-6);
1592  if (htotal->GetBinContent(i) == 0)
1593  htotal->SetBinContent(i, 1);
1594  }
1595 
1596  TGraphAsymmErrors* geff = fs->make<TGraphAsymmErrors>(hfound->GetNbinsX());
1597  geff->SetName(Form("%s_layer%i", name.c_str(), ilayer));
1598  geff->BayesDivide(hfound, htotal);
1599  if (name == "effVsLumi")
1600  geff->SetTitle("Hit Efficiency vs inst. lumi. - " + GetLayerName(ilayer));
1601  if (name == "effVsPU")
1602  geff->SetTitle("Hit Efficiency vs pileup - " + GetLayerName(ilayer));
1603  if (name == "effVsCM")
1604  geff->SetTitle("Hit Efficiency vs common Mode - " + GetLayerName(ilayer));
1605  geff->SetMarkerStyle(20);
1606  }
1607 }
1608 
1610  edm::LogInfo("SiStripHitResolFromCalibTree") << "Computing efficiency vs lumi" << endl;
1611 
1612  if (instLumiHisto->GetEntries()) // from infos per event
1613  edm::LogInfo("SiStripHitResolFromCalibTree")
1614  << "Avg conditions (avg+/-rms): lumi :" << instLumiHisto->GetMean() << "+/-" << instLumiHisto->GetRMS()
1615  << " pu: " << PUHisto->GetMean() << "+/-" << PUHisto->GetRMS() << endl;
1616 
1617  else { // from infos per hit
1618 
1619  unsigned int nLayers = 22;
1620  if (showRings_)
1621  nLayers = 20;
1622  unsigned int nLayersForAvg = 0;
1623  float layerLumi = 0;
1624  float layerPU = 0;
1625  float avgLumi = 0;
1626  float avgPU = 0;
1627 
1628  edm::LogInfo("SiStripHitResolFromCalibTree") << "Lumi summary: (avg over trajectory measurements)" << endl;
1629  for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) {
1630  layerLumi = layertotal_vsLumi[ilayer]->GetMean();
1631  layerPU = layertotal_vsPU[ilayer]->GetMean();
1632  //edm::LogInfo("SiStripHitResolFromCalibTree")<<" layer "<<ilayer<<" lumi: "<<layerLumi<<" pu: "<<layerPU<<endl;
1633  if (layerLumi != 0 && layerPU != 0) {
1634  avgLumi += layerLumi;
1635  avgPU += layerPU;
1636  nLayersForAvg++;
1637  }
1638  }
1639  avgLumi /= nLayersForAvg;
1640  avgPU /= nLayersForAvg;
1641  edm::LogInfo("SiStripHitResolFromCalibTree") << "Avg conditions: lumi :" << avgLumi << " pu: " << avgPU << endl;
1642  }
1643 
1646 }
1647 
1649  edm::LogInfo("SiStripHitResolFromCalibTree") << "Computing efficiency vs CM" << endl;
1651 }
1652 
1654  TString layername = "";
1655  TString ringlabel = "D";
1656  if (showRings_)
1657  ringlabel = "R";
1658  if (k > 0 && k < 5) {
1659  layername = TString("TIB L") + k;
1660  } else if (k > 4 && k < 11) {
1661  layername = TString("TOB L") + (k - 4);
1662  } else if (k > 10 && k < 14) {
1663  layername = TString("TID- ") + ringlabel + (k - 10);
1664  } else if (k > 13 && k < 17) {
1665  layername = TString("TID+ ") + ringlabel + (k - 13);
1666  } else if (k > 16 && k < 17 + nTEClayers_) {
1667  layername = TString("TEC- ") + ringlabel + (k - 16);
1668  } else if (k > 16 + nTEClayers_) {
1669  layername = TString("TEC+ ") + ringlabel + (k - 16 - nTEClayers_);
1670  }
1671 
1672  return layername;
1673 }
1674 
1675 std::unique_ptr<SiStripBadStrip> SiStripHitResolFromCalibTree::getNewObject() {
1676  //Need this for a Condition DB Writer
1677  //Initialize a return variable
1678  auto obj = std::make_unique<SiStripBadStrip>();
1679 
1682 
1683  for (; rIter != rIterEnd; ++rIter) {
1685  quality_->getDataVectorBegin() + rIter->iend);
1686  if (!obj->put(rIter->detid, range))
1687  edm::LogError("SiStripHitResolFromCalibTree")
1688  << "[SiStripHitResolFromCalibTree::getNewObject] detid already exists" << std::endl;
1689  }
1690 
1691  return obj;
1692 }
1693 
1695  float phi = 0;
1696  float Pi = 3.14159;
1697  if ((x >= 0) && (y >= 0))
1698  phi = atan(y / x);
1699  else if ((x >= 0) && (y <= 0))
1700  phi = atan(y / x) + 2 * Pi;
1701  else if ((x <= 0) && (y >= 0))
1702  phi = atan(y / x) + Pi;
1703  else
1704  phi = atan(y / x) + Pi;
1705  phi = phi * 180.0 / Pi;
1706 
1707  return phi;
1708 }
1709 
1711  int i, int component, SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]) {
1712  int napv = detInfo_.getNumberOfApvsAndStripLength(BC.detid).first;
1713 
1714  ssV[i][component] << "\n\t\t " << BC.detid << " \t " << BC.BadModule << " \t " << ((BC.BadFibers) & 0x1) << " ";
1715  if (napv == 4)
1716  ssV[i][component] << "x " << ((BC.BadFibers >> 1) & 0x1);
1717 
1718  if (napv == 6)
1719  ssV[i][component] << ((BC.BadFibers >> 1) & 0x1) << " " << ((BC.BadFibers >> 2) & 0x1);
1720  ssV[i][component] << " \t " << ((BC.BadApvs) & 0x1) << " " << ((BC.BadApvs >> 1) & 0x1) << " ";
1721  if (napv == 4)
1722  ssV[i][component] << "x x " << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1);
1723  if (napv == 6)
1724  ssV[i][component] << ((BC.BadApvs >> 2) & 0x1) << " " << ((BC.BadApvs >> 3) & 0x1) << " "
1725  << ((BC.BadApvs >> 4) & 0x1) << " " << ((BC.BadApvs >> 5) & 0x1) << " ";
1726 
1727  if (BC.BadApvs) {
1728  NBadComponent[i][0][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) + ((BC.BadApvs >> 3) & 0x1) +
1729  ((BC.BadApvs >> 2) & 0x1) + ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
1730  NBadComponent[i][component][2] += ((BC.BadApvs >> 5) & 0x1) + ((BC.BadApvs >> 4) & 0x1) +
1731  ((BC.BadApvs >> 3) & 0x1) + ((BC.BadApvs >> 2) & 0x1) +
1732  ((BC.BadApvs >> 1) & 0x1) + ((BC.BadApvs) & 0x1);
1733  }
1734  if (BC.BadFibers) {
1735  NBadComponent[i][0][1] += ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
1736  NBadComponent[i][component][1] +=
1737  ((BC.BadFibers >> 2) & 0x1) + ((BC.BadFibers >> 1) & 0x1) + ((BC.BadFibers) & 0x1);
1738  }
1739  if (BC.BadModule) {
1740  NBadComponent[i][0][0]++;
1741  NBadComponent[i][component][0]++;
1742  }
1743 }
1744 
unsigned short range
static const std::string kSharedResource
Definition: TFileService.h:76
Definition: BitonicSort.h:7
const double Pi
static constexpr auto TEC
virtual int nstrips() const =0
ContainerIterator getDataVectorBegin() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< SiStripBadStrip > getNewObject() override
map< unsigned int, vector< int > > layertotal_perBx
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
std::string fullPath() const
Definition: FileInPath.cc:161
map< unsigned int, vector< int > > layerfound_perBx
int goodlayertotal[::k_END_OF_LAYS_AND_RINGS]
void makeSummaryVsBx(const edm::Service< TFileService > &fs)
constexpr int pow(int x)
Definition: conifer.h:24
Registry::const_iterator RegistryIterator
Log< level::Error, false > LogError
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
float float float z
static std::string to_string(const XMLCh *ch)
const std::vector< BadComponent > & getBadComponentList() const
void makeSummary(const edm::Service< TFileService > &fs)
T getUntrackedParameter(std::string const &, T const &) const
char const * label
string quality
def overlay(hists, ytitle, header, addon)
Definition: compare.py:122
map< unsigned int, double > BadModules
T sqrt(T t)
Definition: SSEVec.h:19
map< pair< unsigned int, unsigned int >, array< double, 3 > > eventInfos
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:844
void compact(uint32_t detid, std::vector< unsigned int > &)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
RegistryIterator getRegistryVectorEnd() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripDetInfo read(std::string filePath)
static constexpr auto TOB
map< unsigned int, pair< unsigned int, unsigned int > > modCounter[::k_END_OF_LAYERS]
void fillBadComponents()
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:135
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
vector< hit > hits[::k_END_OF_LAYERS]
unsigned int id
Log< level::Info, false > LogInfo
int alllayerfound[::k_END_OF_LAYS_AND_RINGS]
Definition: DetId.h:17
static constexpr auto TIB
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
void ComputeEff(const edm::Service< TFileService > &fs, vector< TH1F *> &vhfound, vector< TH1F *> &vhtotal, string name)
void makeTKMap(const edm::Service< TFileService > &fs, bool autoTagging)
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:121
std::pair< ContainerIterator, ContainerIterator > Range
void algoAnalyze(const edm::Event &e, const edm::EventSetup &c) override
void makeSummaryVsCM(const edm::Service< TFileService > &fs)
int goodlayerfound[::k_END_OF_LAYS_AND_RINGS]
int alllayertotal[::k_END_OF_LAYS_AND_RINGS]
float x
data decode(const unsigned int &value) const
void makeSummaryVsLumi(const edm::Service< TFileService > &fs)
bool put(const uint32_t &detID, const InputVector &vect)
#define str(s)
void SetBadComponents(int i, int component, SiStripQuality::BadComponent &BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4])
virtual float width() const =0
static constexpr auto TID
SiStripHitResolFromCalibTree(const edm::ParameterSet &)
RegistryIterator getRegistryVectorBegin() const
void makeHotColdMaps(const edm::Service< TFileService > &fs)
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:3443
void algoBeginJob(const edm::EventSetup &) override
const Bounds & bounds() const
Definition: Surface.h:87