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