CMS 3D CMS Logo

SiStripHitEffFromCalibTree.cc
Go to the documentation of this file.
1 //Original Author: Christopher Edelmaier
2 // Created: Feb. 11, 2010
3 #include <memory>
4 #include <string>
5 #include <iostream>
6 #include <fstream>
7 #include <sstream>
8 
17 
43 
54 
57 
62 
63 #include "TFile.h"
64 #include "TCanvas.h"
65 #include "TObjString.h"
66 #include "TString.h"
67 #include "TH1F.h"
68 #include "TH2F.h"
69 #include "TProfile.h"
70 #include "TF1.h"
71 #include "TROOT.h"
72 #include "TTree.h"
73 #include "TStyle.h"
74 #include "TLeaf.h"
75 #include "TGaxis.h"
76 #include "TGraphAsymmErrors.h"
77 #include "TLatex.h"
78 #include "TLegend.h"
79 #include "TEfficiency.h"
80 
81 using namespace edm;
82 using namespace reco;
83 using namespace std;
84 
85 struct hit{
86  double x;
87  double y;
88  double z;
89  unsigned int id;
90 };
91 
92 class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
93  public:
95  ~SiStripHitEffFromCalibTree() override;
96 
97  private:
98  virtual void algoBeginJob();
99  void algoEndJob() override;
100  void algoAnalyze(const edm::Event& e, const edm::EventSetup& c) override;
101  void SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]);
102  void makeTKMap();
103  void makeHotColdMaps();
104  void makeSQLite();
105  void totalStatistics();
106  void makeSummary();
107  void makeSummaryVsBx();
108  void ComputeEff(vector< TH1F* > &vhfound, vector< TH1F* > &vhtotal, string name);
109  void makeSummaryVsLumi();
110  void makeSummaryVsCM();
111  TString GetLayerName(Long_t k);
112  TString GetLayerSideName(Long_t k);
113  float calcPhi(float x, float y);
114 
119  SiStripBadStrip* getNewObject() override;
120 
121  TTree* CalibTree;
122  vector<string> CalibTreeFilenames;
123  float threshold;
124  unsigned int nModsMin;
125  unsigned int doSummary;
128  float _ResXSig;
131  unsigned int _bunchx;
132  unsigned int _spaceBetweenTrains;
133  bool _useCM;
138  float _tkMapMin;
139  float _effPlotMin;
140  TString _title;
141 
142  unsigned int nTEClayers;
143 
144  vector<hit> hits[23];
145  vector<TH2F*> HotColdMaps;
146  map< unsigned int, pair< unsigned int, unsigned int> > modCounter[23];
152  int layerfound[23];
153  int layertotal[23];
154  map< unsigned int, vector<int> > layerfound_perBx;
155  map< unsigned int, vector<int> > layertotal_perBx;
156  vector< TH1F* > layerfound_vsLumi;
157  vector< TH1F* > layertotal_vsLumi;
158  vector< TH1F* > layerfound_vsPU;
159  vector< TH1F* > layertotal_vsPU;
160  vector< TH1F* > layerfound_vsCM;
161  vector< TH1F* > layertotal_vsCM;
162  int goodlayertotal[35];
163  int goodlayerfound[35];
164  int alllayertotal[35];
165  int alllayerfound[35];
166  map< unsigned int, double > BadModules;
167 };
168 
171  FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat")
172 {
173  CalibTreeFilenames = conf.getUntrackedParameter<vector<std::string> >("CalibTreeFilenames");
174  threshold = conf.getParameter<double>("Threshold");
175  nModsMin = conf.getParameter<int>("nModsMin");
176  doSummary = conf.getParameter<int>("doSummary");
177  _badModulesFile = conf.getUntrackedParameter<std::string>("BadModulesFile", "");
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  _bunchx = conf.getUntrackedParameter<int>("BunchCrossing",0);
183  _spaceBetweenTrains = conf.getUntrackedParameter<int>("SpaceBetweenTrains",25);
184  _useCM = conf.getUntrackedParameter<bool>("UseCommonMode",false);
185  _showEndcapSides = conf.getUntrackedParameter<bool>("ShowEndcapSides",true);
186  _showRings = conf.getUntrackedParameter<bool>("ShowRings",false);
187  _showTOB6TEC9 = conf.getUntrackedParameter<bool>("ShowTOB6TEC9",false);
188  _showOnlyGoodModules = conf.getUntrackedParameter<bool>("ShowOnlyGoodModules",false);
189  _tkMapMin = conf.getUntrackedParameter<double>("TkMapMin",0.9);
190  _effPlotMin = conf.getUntrackedParameter<double>("EffPlotMin",0.9);
191  _title = conf.getParameter<std::string>("Title");
193 
194  nTEClayers = 9; // number of wheels
195  if(_showRings) nTEClayers = 7; // number of rings
196 
197  quality_ = new SiStripQuality;
198 }
199 
201 
203  //I have no idea what goes here
204  //fs->make<TTree>("HitEffHistos","Tree of the inefficient hit histograms");
205 }
206 
208  //Still have no idea what goes here
209 
210 }
211 
213 
215  c.get<TrackerDigiGeometryRecord>().get( tracker );
216  const TrackerGeometry * tkgeom=&(* tracker);
217 
218  //Retrieve tracker topology from geometry
219  edm::ESHandle<TrackerTopology> tTopoHandle;
220  c.get<TrackerTopologyRcd>().get(tTopoHandle);
221  const TrackerTopology* const tTopo = tTopoHandle.product();
222 
223  // read bad modules to mask
224  ifstream badModules_file;
225  set<uint32_t> badModules_list;
226  if(_badModulesFile!="") {
227  badModules_file.open(_badModulesFile.c_str());
228  uint32_t badmodule_detid;
229  int mods, fiber1, fiber2, fiber3;
230  if(badModules_file.is_open()) {
231  string line;
232  while ( getline (badModules_file,line) ) {
233  if(badModules_file.eof()) continue;
234  stringstream ss(line);
235  ss >> badmodule_detid >> mods >> fiber1 >> fiber2 >> fiber3;
236  if(badmodule_detid!=0 && mods==1 && (fiber1==1 || fiber2==1 || fiber3==1) )
237  badModules_list.insert(badmodule_detid);
238  }
239  badModules_file.close();
240  }
241  }
242  if(!badModules_list.empty()) cout<<"Remove additionnal bad modules from the analysis: "<<endl;
243  set<uint32_t>::iterator itBadMod;
244  for (itBadMod=badModules_list.begin(); itBadMod!=badModules_list.end(); ++itBadMod)
245  cout<<" "<<*itBadMod<<endl;
246 
247 
248  // initialze counters and histos
249  for(int l=0; l < 35; l++) {
250  goodlayertotal[l] = 0;
251  goodlayerfound[l] = 0;
252  alllayertotal[l] = 0;
253  alllayerfound[l] = 0;
254  }
255 
256  TH1F* resolutionPlots[23];
257  for(Long_t ilayer = 0; ilayer <23; ilayer++) {
258  resolutionPlots[ilayer] = fs->make<TH1F>(Form("resol_layer_%i",(int)(ilayer)),GetLayerName(ilayer),125,-125,125);
259  resolutionPlots[ilayer]->GetXaxis()->SetTitle("trajX-clusX [strip unit]");
260 
261  layerfound_vsLumi.push_back( fs->make<TH1F>(Form("layerfound_vsLumi_layer_%i",(int)(ilayer)),GetLayerName(ilayer),60,0,15000));
262  layertotal_vsLumi.push_back( fs->make<TH1F>(Form("layertotal_vsLumi_layer_%i",(int)(ilayer)),GetLayerName(ilayer),60,0,15000));
263  layerfound_vsPU.push_back( fs->make<TH1F>(Form("layerfound_vsPU_layer_%i",(int)(ilayer)),GetLayerName(ilayer),30,0,60));
264  layertotal_vsPU.push_back( fs->make<TH1F>(Form("layertotal_vsPU_layer_%i",(int)(ilayer)),GetLayerName(ilayer),30,0,60));
265 
266  if(_useCM) {
267  layerfound_vsCM.push_back( fs->make<TH1F>(Form("layerfound_vsCM_layer_%i",(int)(ilayer)),GetLayerName(ilayer),20,0,400));
268  layertotal_vsCM.push_back( fs->make<TH1F>(Form("layertotal_vsCM_layer_%i",(int)(ilayer)),GetLayerName(ilayer),20,0,400));
269  }
270  }
271 
272  cout << "A module is bad if efficiency < " << threshold << " and has at least " << nModsMin << " nModsMin." << endl;
273 
274 
275  //Open the ROOT Calib Tree
276  for( unsigned int ifile=0; ifile < CalibTreeFilenames.size(); ifile++) {
277 
278  cout<<"Loading file: "<<CalibTreeFilenames[ifile]<<endl;
279  TFile* CalibTreeFile = TFile::Open(CalibTreeFilenames[ifile].c_str(),"READ");
280  CalibTreeFile->cd("anEff");
281  CalibTree = (TTree*)(gDirectory->Get("traj"));
282 
283  TLeaf* BadLf = CalibTree->GetLeaf("ModIsBad");
284  TLeaf* sistripLf = CalibTree->GetLeaf("SiStripQualBad");
285  TLeaf* idLf = CalibTree->GetLeaf("Id");
286  TLeaf* acceptLf = CalibTree->GetLeaf("withinAcceptance");
287  TLeaf* layerLf = CalibTree->GetLeaf("layer");
288  TLeaf* nHitsLf = CalibTree->GetLeaf("nHits");
289  TLeaf* xLf = CalibTree->GetLeaf("TrajGlbX");
290  TLeaf* yLf = CalibTree->GetLeaf("TrajGlbY");
291  TLeaf* zLf = CalibTree->GetLeaf("TrajGlbZ");
292  TLeaf* ResXSigLf = CalibTree->GetLeaf("ResXSig");
293  TLeaf* TrajLocXLf = CalibTree->GetLeaf("TrajLocX");
294  TLeaf* TrajLocYLf = CalibTree->GetLeaf("TrajLocY");
295  TLeaf* ClusterLocXLf = CalibTree->GetLeaf("ClusterLocX");
296  TLeaf* BunchLf = CalibTree->GetLeaf("bunchx");
297  TLeaf* InstLumiLf = CalibTree->GetLeaf("instLumi");
298  TLeaf* PULf = CalibTree->GetLeaf("PU");
299  TLeaf* CMLf = nullptr;
300  if(_useCM) CMLf = CalibTree->GetLeaf("commonMode");
301 
302  int nevents = CalibTree->GetEntries();
303  cout << "Successfully loaded analyze function with " << nevents << " events!\n";
304 
305 
306  //Loop through all of the events
307  for(int j =0; j < nevents; j++) {
308  CalibTree->GetEntry(j);
309  unsigned int isBad = (unsigned int)BadLf->GetValue();
310  unsigned int quality = (unsigned int)sistripLf->GetValue();
311  unsigned int id = (unsigned int)idLf->GetValue();
312  unsigned int accept = (unsigned int)acceptLf->GetValue();
313  unsigned int layer_wheel = (unsigned int)layerLf->GetValue();
314  unsigned int layer = layer_wheel;
315  if(_showRings && layer >10) { // use rings instead of wheels
316  if(layer<14) layer = 10 + ((id>>9)&0x3); //TID 3 disks and also 3 rings -> use the same container
317  else layer = 13 + ((id>>5)&0x7); //TEC
318  }
319  unsigned int nHits = (unsigned int)nHitsLf->GetValue();
320  double x = xLf->GetValue();
321  double y = yLf->GetValue();
322  double z = zLf->GetValue();
323  double resxsig = ResXSigLf->GetValue();
324  double TrajLocX = TrajLocXLf->GetValue();
325  double TrajLocY = TrajLocYLf->GetValue();
326  double ClusterLocX = ClusterLocXLf->GetValue();
327  double TrajLocXMid;
328  double stripTrajMid;
329  double stripCluster;
330  bool badquality = false;
331  unsigned int bx = (unsigned int)BunchLf->GetValue();
332  if(_bunchx > 0 && _bunchx != bx) continue;
333  double instLumi = 0;
334  if(InstLumiLf!=nullptr) instLumi = InstLumiLf->GetValue();
335  double PU = 0;
336  if(PULf!=nullptr) PU = PULf->GetValue();
337  int CM = -100;
338  if(_useCM) CM = CMLf->GetValue();
339 
340  //We have two things we want to do, both an XY color plot, and the efficiency measurement
341  //First, ignore anything that isn't in acceptance and isn't good quality
342 
343  //if(quality == 1 || accept != 1 || nHits < 8) continue;
344  if(accept != 1 || nHits < 8) continue;
345  if(quality == 1) badquality = true;
346 
347  // don't compute efficiencies in modules from TOB6 and TEC9
348  if(!_showTOB6TEC9 && (layer_wheel==10 || layer_wheel==22)) continue;
349 
350  // don't use bad modules given in the bad module list
351  itBadMod = badModules_list.find(id);
352  if(itBadMod!=badModules_list.end()) continue;
353 
354 
355  //Now that we have a good event, we need to look at if we expected it or not, and the location
356  //if we didn't
357  //Fill the missing hit information first
358  bool badflag = false;
359 
360  // By default uses the old matching method
361  if(_ResXSig < 0) {
362  if(isBad == 1) badflag = true; // isBad set to false in the tree when resxsig<999.0
363  }
364  else {
365  if(isBad == 1 || resxsig > _ResXSig) badflag = true;
366  }
367 
368  // Conversion of positions in strip unit
369  int nstrips = -9;
370  float Pitch = -9.0;
371 
372  if (resxsig==1000.0) { // special treatment, no GeomDetUnit associated in some cases when no cluster found
373  Pitch = 0.0205; // maximum
374  nstrips = 768; // maximum
375  stripTrajMid = TrajLocX/Pitch + nstrips/2.0 ;
376  stripCluster = ClusterLocX/Pitch + nstrips/2.0 ;
377  }
378  else {
379  DetId ClusterDetId(id);
380  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)tkgeom->idToDetUnit(ClusterDetId);
381  const StripTopology& Topo = stripdet->specificTopology();
382  nstrips = Topo.nstrips();
383  Pitch = stripdet->surface().bounds().width() / Topo.nstrips();
384  stripTrajMid = TrajLocX/Pitch + nstrips/2.0 ; //layer01->10
385  stripCluster = ClusterLocX/Pitch + nstrips/2.0 ;
386 
387  // For trapezoidal modules: extrapolation of x trajectory position to the y middle of the module
388  // for correct comparison with cluster position
389  float hbedge = 0;
390  float htedge = 0;
391  float hapoth = 0;
392  if(layer>=11) {
393  const BoundPlane& plane = stripdet->surface();
394  const TrapezoidalPlaneBounds* trapezoidalBounds( dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
395  std::array<const float, 4> const & parameters = (*trapezoidalBounds).parameters();
396  hbedge = parameters[0];
397  htedge = parameters[1];
398  hapoth = parameters[3];
399  TrajLocXMid = TrajLocX / (1 + (htedge-hbedge)*TrajLocY/(htedge+hbedge)/hapoth) ; // radialy extrapolated x loc position at middle
400  stripTrajMid = TrajLocXMid/Pitch + nstrips/2.0 ;
401  }
402  }
403 
404 
405  if(!badquality && layer<23) {
406  if(resxsig!=1000.0) resolutionPlots[layer]->Fill(stripTrajMid-stripCluster);
407  else resolutionPlots[layer]->Fill(1000);
408  }
409 
410 
411  // New matching methods
412  int tapv = -9;
413  int capv = -9;
414  float stripInAPV = 64.;
415 
416  if ( _clusterMatchingMethod >=1 ) {
417  badflag = false; // reset
418  if(resxsig == 1000.0) { // default value when no cluster found in the module
419  badflag = true; // consider the module inefficient in this case
420  }
421  else{
422  if (_clusterMatchingMethod==2 || _clusterMatchingMethod==4) { // check the distance between cluster and trajectory position
423  if ( abs(stripCluster - stripTrajMid) > _clusterTrajDist ) badflag = true;
424  }
425  if (_clusterMatchingMethod==3 || _clusterMatchingMethod==4) { // cluster and traj have to be in the same APV (don't take edges into accounts)
426  tapv = (int) stripTrajMid/128;
427  capv = (int) stripCluster/128;
428  stripInAPV = stripTrajMid-tapv*128;
429 
430  if(stripInAPV<_stripsApvEdge || stripInAPV>128-_stripsApvEdge) continue;
431  if(tapv != capv) badflag = true;
432  }
433  }
434  }
435 
436 
437 
438  if(badflag && !badquality) {
439  hit temphit;
440  temphit.x = x;
441  temphit.y = y;
442  temphit.z = z;
443  temphit.id = id;
444  hits[layer].push_back(temphit);
445  }
446  pair<unsigned int, unsigned int> newgoodpair (1,1);
447  pair<unsigned int, unsigned int> newbadpair (1,0);
448  //First, figure out if the module already exists in the map of maps
449  map< unsigned int, pair< unsigned int, unsigned int> >::iterator it = modCounter[layer].find(id);
450  if(!badquality) {
451  if(it == modCounter[layer].end()) {
452  if(badflag) modCounter[layer][id] = newbadpair;
453  else modCounter[layer][id] = newgoodpair;
454  }
455  else {
456  ((*it).second.first)++;
457  if(!badflag) ((*it).second.second)++;
458  }
459 
460  if(layerfound_perBx.find(bx)==layerfound_perBx.end()) {
461  layerfound_perBx[bx] = vector<int>(23, 0);
462  layertotal_perBx[bx] = vector<int>(23, 0);
463  }
464  if(!badflag) layerfound_perBx[bx][layer]++;
465  layertotal_perBx[bx][layer]++;
466 
467  if(!badflag) layerfound_vsLumi[layer]->Fill(instLumi);
468  layertotal_vsLumi[layer]->Fill(instLumi);
469  if(!badflag) layerfound_vsPU[layer]->Fill(PU);
470  layertotal_vsPU[layer]->Fill(PU);
471 
472  if(_useCM){
473  if(!badflag) layerfound_vsCM[layer]->Fill(CM);
474  layertotal_vsCM[layer]->Fill(CM);
475  }
476 
477  //Have to do the decoding for which side to go on (ugh)
478  if(layer <= 10) {
479  if(!badflag) goodlayerfound[layer]++;
480  goodlayertotal[layer]++;
481  }
482  else if(layer > 10 && layer < 14) {
483  if( ((id>>13)&0x3) == 1) {
484  if(!badflag) goodlayerfound[layer]++;
485  goodlayertotal[layer]++;
486  }
487  else if( ((id>>13)&0x3) == 2) {
488  if(!badflag) goodlayerfound[layer+3]++;
489  goodlayertotal[layer+3]++;
490  }
491  }
492  else if(layer > 13 && layer <= 22) {
493  if( ((id>>18)&0x3) == 1) {
494  if(!badflag) goodlayerfound[layer+3]++;
495  goodlayertotal[layer+3]++;
496  }
497  else if( ((id>>18)&0x3) == 2) {
498  if(!badflag) goodlayerfound[layer+3+nTEClayers]++;
499  goodlayertotal[layer+3+nTEClayers]++;
500  }
501  }
502  }
503  //Do the one where we don't exclude bad modules!
504  if(layer <= 10) {
505  if(!badflag) alllayerfound[layer]++;
506  alllayertotal[layer]++;
507  }
508  else if(layer > 10 && layer < 14) {
509  if( ((id>>13)&0x3) == 1) {
510  if(!badflag) alllayerfound[layer]++;
511  alllayertotal[layer]++;
512  }
513  else if( ((id>>13)&0x3) == 2) {
514  if(!badflag) alllayerfound[layer+3]++;
515  alllayertotal[layer+3]++;
516  }
517  }
518  else if(layer > 13 && layer <= 22) {
519  if( ((id>>18)&0x3) == 1) {
520  if(!badflag) alllayerfound[layer+3]++;
521  alllayertotal[layer+3]++;
522  }
523  else if( ((id>>18)&0x3) == 2) {
524  if(!badflag) alllayerfound[layer+3+nTEClayers]++;
525  alllayertotal[layer+3+nTEClayers]++;
526  }
527  }
528  //At this point, both of our maps are loaded with the correct information
529  }
530  }// go to next CalibTreeFile
531 
532  makeHotColdMaps();
533  makeTKMap();
534  makeSQLite();
535  totalStatistics();
536  makeSummary();
537  makeSummaryVsBx();
539  if(_useCM) makeSummaryVsCM();
540 
542  //try to write out what's in the quality record
544  int NTkBadComponent[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
545  int NBadComponent[4][19][4];
546  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
547  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
548  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
549  std::stringstream ssV[4][19];
550 
551  for(int i=0;i<4;++i){
552  NTkBadComponent[i]=0;
553  for(int j=0;j<19;++j){
554  ssV[i][j].str("");
555  for(int k=0;k<4;++k)
556  NBadComponent[i][j][k]=0;
557  }
558  }
559 
560 
561  std::vector<SiStripQuality::BadComponent> BC = quality_->getBadComponentList();
562 
563  for (size_t i=0;i<BC.size();++i){
564 
565  //&&&&&&&&&&&&&
566  //Full Tk
567  //&&&&&&&&&&&&&
568 
569  if (BC[i].BadModule)
570  NTkBadComponent[0]++;
571  if (BC[i].BadFibers)
572  NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
573  if (BC[i].BadApvs)
574  NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
575  ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
576 
577  //&&&&&&&&&&&&&&&&&
578  //Single SubSystem
579  //&&&&&&&&&&&&&&&&&
580 
581  int component;
582  SiStripDetId a(BC[i].detid);
583  if ( a.subdetId() == SiStripDetId::TIB ){
584  //&&&&&&&&&&&&&&&&&
585  //TIB
586  //&&&&&&&&&&&&&&&&&
587 
588  component=tTopo->tibLayer(BC[i].detid);
589  SetBadComponents(0, component, BC[i], ssV, NBadComponent);
590 
591  } else if ( a.subdetId() == SiStripDetId::TID ) {
592  //&&&&&&&&&&&&&&&&&
593  //TID
594  //&&&&&&&&&&&&&&&&&
595 
596  component=tTopo->tidSide(BC[i].detid)==2?tTopo->tidWheel(BC[i].detid):tTopo->tidWheel(BC[i].detid)+3;
597  SetBadComponents(1, component, BC[i], ssV, NBadComponent);
598 
599  } else if ( a.subdetId() == SiStripDetId::TOB ) {
600  //&&&&&&&&&&&&&&&&&
601  //TOB
602  //&&&&&&&&&&&&&&&&&
603 
604  component=tTopo->tobLayer(BC[i].detid);
605  SetBadComponents(2, component, BC[i], ssV, NBadComponent);
606 
607  } else if ( a.subdetId() == SiStripDetId::TEC ) {
608  //&&&&&&&&&&&&&&&&&
609  //TEC
610  //&&&&&&&&&&&&&&&&&
611 
612  component=tTopo->tecSide(BC[i].detid)==2?tTopo->tecWheel(BC[i].detid):tTopo->tecWheel(BC[i].detid)+9;
613  SetBadComponents(3, component, BC[i], ssV, NBadComponent);
614 
615  }
616  }
617 
618  //&&&&&&&&&&&&&&&&&&
619  // Single Strip Info
620  //&&&&&&&&&&&&&&&&&&
621  float percentage=0;
622 
625 
626  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
627  unsigned int detid=rp->detid;
628 
629  int subdet=-999; int component=-999;
630  SiStripDetId a(detid);
631  if ( a.subdetId() == 3 ){
632  subdet=0;
633  component=tTopo->tibLayer(detid);
634  } else if ( a.subdetId() == 4 ) {
635  subdet=1;
636  component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
637  } else if ( a.subdetId() == 5 ) {
638  subdet=2;
639  component=tTopo->tobLayer(detid);
640  } else if ( a.subdetId() == 6 ) {
641  subdet=3;
642  component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
643  }
644 
646 
647  percentage=0;
648  for(int it=0;it<sqrange.second-sqrange.first;it++){
649  unsigned int range=quality_->decode( *(sqrange.first+it) ).range;
650  NTkBadComponent[3]+=range;
651  NBadComponent[subdet][0][3]+=range;
652  NBadComponent[subdet][component][3]+=range;
653  percentage+=range;
654  }
655  if(percentage!=0)
656  percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
657  if(percentage>1)
658  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage<< std::endl;
659  }
660  //&&&&&&&&&&&&&&&&&&
661  // printout
662  //&&&&&&&&&&&&&&&&&&
663 
664  cout << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event() << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
665  cout << "\n-----------------\nGlobal Info\n-----------------";
666  cout << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
667  cout << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
668  cout << endl;
669  cout << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
670  cout << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
671  cout << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
672  cout << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
673  cout << "\n";
674 
675  for (int i=1;i<5;++i)
676  cout << "\nTIB Layer " << i << " :\t\t"<<NBadComponent[0][i][0]<<"\t"<<NBadComponent[0][i][1]<<"\t"<<NBadComponent[0][i][2]<<"\t"<<NBadComponent[0][i][3];
677  cout << "\n";
678  for (int i=1;i<4;++i)
679  cout << "\nTID+ Disk " << i << " :\t\t"<<NBadComponent[1][i][0]<<"\t"<<NBadComponent[1][i][1]<<"\t"<<NBadComponent[1][i][2]<<"\t"<<NBadComponent[1][i][3];
680  for (int i=4;i<7;++i)
681  cout << "\nTID- Disk " << i-3 << " :\t\t"<<NBadComponent[1][i][0]<<"\t"<<NBadComponent[1][i][1]<<"\t"<<NBadComponent[1][i][2]<<"\t"<<NBadComponent[1][i][3];
682  cout << "\n";
683  for (int i=1;i<7;++i)
684  cout << "\nTOB Layer " << i << " :\t\t"<<NBadComponent[2][i][0]<<"\t"<<NBadComponent[2][i][1]<<"\t"<<NBadComponent[2][i][2]<<"\t"<<NBadComponent[2][i][3];
685  cout << "\n";
686  for (int i=1;i<10;++i)
687  cout << "\nTEC+ Disk " << i << " :\t\t"<<NBadComponent[3][i][0]<<"\t"<<NBadComponent[3][i][1]<<"\t"<<NBadComponent[3][i][2]<<"\t"<<NBadComponent[3][i][3];
688  for (int i=10;i<19;++i)
689  cout << "\nTEC- Disk " << i-9 << " :\t\t"<<NBadComponent[3][i][0]<<"\t"<<NBadComponent[3][i][1]<<"\t"<<NBadComponent[3][i][2]<<"\t"<<NBadComponent[3][i][3];
690  cout << "\n";
691 
692  cout << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
693  for (int i=1;i<5;++i)
694  cout << "\nTIB Layer " << i << " :" << ssV[0][i].str();
695  cout << "\n";
696  for (int i=1;i<4;++i)
697  cout << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
698  for (int i=4;i<7;++i)
699  cout << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
700  cout << "\n";
701  for (int i=1;i<7;++i)
702  cout << "\nTOB Layer " << i << " :" << ssV[2][i].str();
703  cout << "\n";
704  for (int i=1;i<10;++i)
705  cout << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
706  for (int i=10;i<19;++i)
707  cout << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
708 
709  // store also bad modules in log file
710  ofstream badModules;
711  badModules.open("BadModules.log");
712  badModules << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
713  for (int i=1;i<5;++i)
714  badModules << "\nTIB Layer " << i << " :" << ssV[0][i].str();
715  badModules << "\n";
716  for (int i=1;i<4;++i)
717  badModules << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
718  for (int i=4;i<7;++i)
719  badModules << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
720  badModules << "\n";
721  for (int i=1;i<7;++i)
722  badModules << "\nTOB Layer " << i << " :" << ssV[2][i].str();
723  badModules << "\n";
724  for (int i=1;i<10;++i)
725  badModules << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
726  for (int i=10;i<19;++i)
727  badModules << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
728  badModules.close();
729 
730 }
731 
733  cout << "Entering hot cold map generation!\n";
734  TStyle* gStyle = new TStyle("gStyle","myStyle");
735  gStyle->cd();
736  gStyle->SetPalette(1);
737  gStyle->SetCanvasColor(kWhite);
738  gStyle->SetOptStat(0);
739  //Here we make the hot/cold color maps that we love so very much
740  //Already have access to the data as a private variable
741  //Create all of the histograms in the TFileService
742  TH2F *temph2;
743  for(Long_t maplayer = 1; maplayer <=22; maplayer++) {
744  //Initialize all of the histograms
745  if(maplayer > 0 && maplayer <= 4) {
746  //We are in the TIB
747  temph2 = fs->make<TH2F>(Form("%s%i","TIB",(int)(maplayer)),"TIB",100,-1,361,100,-100,100);
748  temph2->GetXaxis()->SetTitle("Phi");
749  temph2->GetXaxis()->SetBinLabel(1,TString("360"));
750  temph2->GetXaxis()->SetBinLabel(50,TString("180"));
751  temph2->GetXaxis()->SetBinLabel(100,TString("0"));
752  temph2->GetYaxis()->SetTitle("Global Z");
753  temph2->SetOption("colz");
754  HotColdMaps.push_back(temph2);
755  }
756  else if(maplayer > 4 && maplayer <= 10) {
757  //We are in the TOB
758  temph2 = fs->make<TH2F>(Form("%s%i","TOB",(int)(maplayer-4)),"TOB",100,-1,361,100,-120,120);
759  temph2->GetXaxis()->SetTitle("Phi");
760  temph2->GetXaxis()->SetBinLabel(1,TString("360"));
761  temph2->GetXaxis()->SetBinLabel(50,TString("180"));
762  temph2->GetXaxis()->SetBinLabel(100,TString("0"));
763  temph2->GetYaxis()->SetTitle("Global Z");
764  temph2->SetOption("colz");
765  HotColdMaps.push_back(temph2);
766  }
767  else if(maplayer > 10 && maplayer <= 13) {
768  //We are in the TID
769  //Split by +/-
770  temph2 = fs->make<TH2F>(Form("%s%i","TID-",(int)(maplayer-10)),"TID-",100,-100,100,100,-100,100);
771  temph2->GetXaxis()->SetTitle("Global Y");
772  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
773  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
774  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
775  temph2->GetYaxis()->SetTitle("Global X");
776  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
777  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
778  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
779  temph2->SetOption("colz");
780  HotColdMaps.push_back(temph2);
781  temph2 = fs->make<TH2F>(Form("%s%i","TID+",(int)(maplayer-10)),"TID+",100,-100,100,100,-100,100);
782  temph2->GetXaxis()->SetTitle("Global Y");
783  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
784  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
785  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
786  temph2->GetYaxis()->SetTitle("Global X");
787  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
788  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
789  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
790  temph2->SetOption("colz");
791  HotColdMaps.push_back(temph2);
792  }
793  else if(maplayer > 13) {
794  //We are in the TEC
795  //Split by +/-
796  temph2 = fs->make<TH2F>(Form("%s%i","TEC-",(int)(maplayer-13)),"TEC-",100,-120,120,100,-120,120);
797  temph2->GetXaxis()->SetTitle("Global Y");
798  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
799  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
800  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
801  temph2->GetYaxis()->SetTitle("Global X");
802  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
803  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
804  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
805  temph2->SetOption("colz");
806  HotColdMaps.push_back(temph2);
807  temph2 = fs->make<TH2F>(Form("%s%i","TEC+",(int)(maplayer-13)),"TEC+",100,-120,120,100,-120,120);
808  temph2->GetXaxis()->SetTitle("Global Y");
809  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
810  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
811  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
812  temph2->GetYaxis()->SetTitle("Global X");
813  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
814  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
815  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
816  temph2->SetOption("colz");
817  HotColdMaps.push_back(temph2);
818  }
819  }
820  for(Long_t mylayer = 1; mylayer <= 22; mylayer++) {
821  //Determine what kind of plot we want to write out
822  //Loop through the entirety of each layer
823  //Create an array of the histograms
824  vector<hit>::const_iterator iter;
825  for(iter = hits[mylayer].begin(); iter != hits[mylayer].end(); iter++) {
826  //Looping over the particular layer
827  //Fill by 360-x to get the proper location to compare with TKMaps of phi
828  //Also global xy is messed up
829  if(mylayer > 0 && mylayer <= 4) {
830  //We are in the TIB
831  float phi = calcPhi(iter->x, iter->y);
832  HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
833  }
834  else if(mylayer > 4 && mylayer <= 10) {
835  //We are in the TOB
836  float phi = calcPhi(iter->x,iter->y);
837  HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
838  }
839  else if(mylayer > 10 && mylayer <= 13) {
840  //We are in the TID
841  //There are 2 different maps here
842  int side = (((iter->id)>>13) & 0x3);
843  if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(-iter->y,iter->x,1.);
844  else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(-iter->y,iter->x,1.);
845  //if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(iter->x,iter->y,1.);
846  //else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(iter->x,iter->y,1.);
847  }
848  else if(mylayer > 13) {
849  //We are in the TEC
850  //There are 2 different maps here
851  int side = (((iter->id)>>18) & 0x3);
852  if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(-iter->y,iter->x,1.);
853  else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(-iter->y,iter->x,1.);
854  //if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(iter->x,iter->y,1.);
855  //else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(iter->x,iter->y,1.);
856  }
857  }
858  }
859  cout << "Finished HotCold Map Generation\n";
860 }
861 
863  cout << "Entering TKMap generation!\n";
864  tkmap = new TrackerMap(" Detector Inefficiency ");
865  tkmapbad = new TrackerMap(" Inefficient Modules ");
866  tkmapeff = new TrackerMap(_title.Data());
867  tkmapnum = new TrackerMap(" Detector numerator ");
868  tkmapden = new TrackerMap(" Detector denominator ");
869 
870  double myeff, mynum, myden;
871 
872  for(Long_t i = 1; i <= 22; i++) {
873  //Loop over every layer, extracting the information from
874  //the map of the efficiencies
875  layertotal[i] = 0;
876  layerfound[i] = 0;
877  map<unsigned int, pair<unsigned int, unsigned int> >::const_iterator ih;
878  for( ih = modCounter[i].begin(); ih != modCounter[i].end(); ih++) {
879  //We should be in the layer in question, and looping over all of the modules in said layer
880  //Generate the list for the TKmap, and the bad module list
881  mynum = (double)(((*ih).second).second);
882  myden = (double)(((*ih).second).first);
883  if(myden>0) myeff = mynum/myden;
884  else myeff=0;
885  if ( (myden >= nModsMin) && (myeff < threshold) ) {
886  //We have a bad module, put it in the list!
887  BadModules[(*ih).first] = myeff;
888  tkmapbad->fillc((*ih).first,255,0,0);
889  cout << "Layer " << i << " module " << (*ih).first << " efficiency " << myeff << " " << (((*ih).second).second) << "/" << (((*ih).second).first) << endl;
890  }
891  else {
892  //Fill the bad list with empty results for every module
893  tkmapbad->fillc((*ih).first,255,255,255);
894  }
895  if(myden < 50 ) {
896  cout << "Module " << (*ih).first << " layer " << i << " is under occupancy at " << (((*ih).second).first) << endl;
897  }
898  //Put any module into the TKMap
899  //Should call module ID, and then 1- efficiency for that module
900  //if((*ih).first == 369137820) {
901  // cout << "Module 369137820 has 1-eff of " << 1.-myeff << endl;
902  //cout << "Which is " << ((*ih).second).second << "/" << ((*ih).second).first << endl;
903  //}
904  tkmap->fill((*ih).first,1.-myeff);
905  tkmapeff->fill((*ih).first,myeff);
906  tkmapnum->fill((*ih).first,mynum);
907  tkmapden->fill((*ih).first,myden);
908  //Find the total number of hits in the module
909  layertotal[i] += int(myden);
910  layerfound[i] += int(mynum);
911  }
912  }
913  tkmap->save(true, 0, 0, "SiStripHitEffTKMap.png");
914  tkmapbad->save(true, 0, 0, "SiStripHitEffTKMapBad.png");
915  tkmapeff->save(true, _tkMapMin, 1., "SiStripHitEffTKMapEff.png");
916  tkmapnum->save(true, 0, 0, "SiStripHitEffTKMapNum.png");
917  tkmapden->save(true, 0, 0, "SiStripHitEffTKMapDen.png");
918  cout << "Finished TKMap Generation\n";
919 }
920 
922  //Generate the SQLite file for use in the Database of the bad modules!
923  cout << "Entering SQLite file generation!\n";
924  std::vector<unsigned int> BadStripList;
925  unsigned short NStrips;
926  unsigned int id1;
927  SiStripQuality* pQuality = new SiStripQuality;
928  //This is the list of the bad strips, use to mask out entire APVs
929  //Now simply go through the bad hit list and mask out things that
930  //are bad!
931  map< unsigned int, double >::const_iterator it;
932  for(it = BadModules.begin(); it != BadModules.end(); it++) {
933  //We need to figure out how many strips are in this particular module
934  //To Mask correctly!
935  NStrips=reader->getNumberOfApvsAndStripLength((*it).first).first*128;
936  cout << "Number of strips module " << (*it).first << " is " << NStrips << endl;
937  BadStripList.push_back(pQuality->encode(0,NStrips,0));
938  //Now compact into a single bad module
939  id1=(unsigned int)(*it).first;
940  cout << "ID1 shoudl match list of modules above " << id1 << endl;
941  quality_->compact(id1,BadStripList);
942  SiStripQuality::Range range(BadStripList.begin(),BadStripList.end());
943  quality_->put(id1,range);
944  BadStripList.clear();
945  }
946  //Fill all the bad components now
948 }
949 
951  //Calculate the statistics by layer
952  int totalfound = 0;
953  int totaltotal = 0;
954  double layereff;
955  int subdetfound[5];
956  int subdettotal[5];
957 
958  for(Long_t i=1; i<5; i++) {subdetfound[i]=0; subdettotal[i]=0;}
959 
960  for(Long_t i=1; i<=22; i++) {
961  layereff = double(layerfound[i])/double(layertotal[i]);
962  cout << "Layer " << i << " has total efficiency " << layereff << " " << layerfound[i] << "/" << layertotal[i] << endl;
963  totalfound += layerfound[i];
964  totaltotal += layertotal[i];
965  if(i<5) {subdetfound[1]+=layerfound[i]; subdettotal[1]+=layertotal[i];}
966  if(i>=5 && i<11) {subdetfound[2]+=layerfound[i]; subdettotal[2]+=layertotal[i];}
967  if(i>=11 && i<14) {subdetfound[3]+=layerfound[i]; subdettotal[3]+=layertotal[i];}
968  if(i>=14) {subdetfound[4]+=layerfound[i]; subdettotal[4]+=layertotal[i];}
969 
970  }
971 
972  cout << "The total efficiency is " << double(totalfound)/double(totaltotal) << endl;
973  cout << " TIB: " << double(subdetfound[1])/subdettotal[1] << endl;
974  cout << " TOB: " << double(subdetfound[2])/subdettotal[2] << endl;
975  cout << " TID: " << double(subdetfound[3])/subdettotal[3] << endl;
976  cout << " TEC: " << double(subdetfound[4])/subdettotal[4] << endl;
977 }
978 
980  //setTDRStyle();
981 
982  int nLayers = 34;
983  if(_showRings) nLayers = 30;
984  if(!_showEndcapSides) {
985  if(!_showRings) nLayers=22;
986  else nLayers=20;
987  }
988 
989  TH1F *found = fs->make<TH1F>("found","found",nLayers+1,0,nLayers+1);
990  TH1F *all = fs->make<TH1F>("all","all",nLayers+1,0,nLayers+1);
991  TH1F *found2 = fs->make<TH1F>("found2","found2",nLayers+1,0,nLayers+1);
992  TH1F *all2 = fs->make<TH1F>("all2","all2",nLayers+1,0,nLayers+1);
993  // first bin only to keep real data off the y axis so set to -1
994  found->SetBinContent(0,-1);
995  all->SetBinContent(0,1);
996 
997  // new ROOT version: TGraph::Divide don't handle null or negative values
998  for (Long_t i=1; i< nLayers+2; ++i) {
999  found->SetBinContent(i,1e-6);
1000  all->SetBinContent(i,1);
1001  found2->SetBinContent(i,1e-6);
1002  all2->SetBinContent(i,1);
1003  }
1004 
1005  TCanvas *c7 =new TCanvas("c7"," test ",10,10,800,600);
1006  c7->SetFillColor(0);
1007  c7->SetGrid();
1008 
1009  int nLayers_max=nLayers+1; // barrel+endcap
1010  if(!_showEndcapSides) nLayers_max=11; // barrel
1011  for (Long_t i=1; i< nLayers_max; ++i) {
1012  cout << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] << " B = " << goodlayertotal[i] << endl;
1013  if (goodlayertotal[i] > 5) {
1014  found->SetBinContent(i,goodlayerfound[i]);
1015  all->SetBinContent(i,goodlayertotal[i]);
1016  }
1017 
1018  cout << "Filling all modules layer " << i << ": S = " << alllayerfound[i] << " B = " << alllayertotal[i] << endl;
1019  if (alllayertotal[i] > 5) {
1020  found2->SetBinContent(i,alllayerfound[i]);
1021  all2->SetBinContent(i,alllayertotal[i]);
1022  }
1023 
1024  }
1025 
1026  // endcap - merging sides
1027  if(!_showEndcapSides) {
1028  for (Long_t i=11; i< 14; ++i) { // TID disks
1029  cout << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i]+goodlayerfound[i+3] << " B = " << goodlayertotal[i]+goodlayertotal[i+3] << endl;
1030  if (goodlayertotal[i]+goodlayertotal[i+3] > 5) {
1031  found->SetBinContent(i,goodlayerfound[i]+goodlayerfound[i+3]);
1032  all->SetBinContent(i,goodlayertotal[i]+goodlayertotal[i+3]);
1033  }
1034  cout << "Filling all modules layer " << i << ": S = " << alllayerfound[i]+alllayerfound[i+3] << " B = " << alllayertotal[i]+alllayertotal[i+3] << endl;
1035  if (alllayertotal[i]+alllayertotal[i+3] > 5) {
1036  found2->SetBinContent(i,alllayerfound[i]+alllayerfound[i+3]);
1037  all2->SetBinContent(i,alllayertotal[i]+alllayertotal[i+3]);
1038  }
1039  }
1040  for (Long_t i=17; i< 17+nTEClayers; ++i) { // TEC disks
1041  cout << "Fill only good modules layer " << i-3 << ": S = " << goodlayerfound[i]+goodlayerfound[i+nTEClayers] << " B = " << goodlayertotal[i]+goodlayertotal[i+nTEClayers] << endl;
1042  if (goodlayertotal[i]+goodlayertotal[i+nTEClayers] > 5) {
1043  found->SetBinContent(i-3,goodlayerfound[i]+goodlayerfound[i+nTEClayers]);
1044  all->SetBinContent(i-3,goodlayertotal[i]+goodlayertotal[i+nTEClayers]);
1045  }
1046  cout << "Filling all modules layer " << i-3 << ": S = " << alllayerfound[i]+alllayerfound[i+nTEClayers] << " B = " << alllayertotal[i]+alllayertotal[i+nTEClayers] << endl;
1047  if (alllayertotal[i]+alllayertotal[i+nTEClayers] > 5) {
1048  found2->SetBinContent(i-3,alllayerfound[i]+alllayerfound[i+nTEClayers]);
1049  all2->SetBinContent(i-3,alllayertotal[i]+alllayertotal[i+nTEClayers]);
1050  }
1051  }
1052  }
1053 
1054  found->Sumw2();
1055  all->Sumw2();
1056 
1057  found2->Sumw2();
1058  all2->Sumw2();
1059 
1060  TGraphAsymmErrors *gr = fs->make<TGraphAsymmErrors>(nLayers+1);
1061  gr->SetName("eff_good");
1062  gr->BayesDivide(found,all);
1063 
1064  TGraphAsymmErrors *gr2 = fs->make<TGraphAsymmErrors>(nLayers+1);
1065  gr2->SetName("eff_all");
1066  gr2->BayesDivide(found2,all2);
1067 
1068  for(int j = 0; j<nLayers+1; j++){
1069  gr->SetPointError(j, 0., 0., gr->GetErrorYlow(j),gr->GetErrorYhigh(j) );
1070  gr2->SetPointError(j, 0., 0., gr2->GetErrorYlow(j),gr2->GetErrorYhigh(j) );
1071  }
1072 
1073  gr->GetXaxis()->SetLimits(0,nLayers);
1074  gr->SetMarkerColor(2);
1075  gr->SetMarkerSize(1.2);
1076  gr->SetLineColor(2);
1077  gr->SetLineWidth(4);
1078  gr->SetMarkerStyle(20);
1079  gr->SetMinimum(_effPlotMin);
1080  gr->SetMaximum(1.001);
1081  gr->GetYaxis()->SetTitle("Efficiency");
1082  gStyle->SetTitleFillColor(0);
1083  gStyle->SetTitleBorderSize(0);
1084  gr->SetTitle(_title);
1085 
1086  gr2->GetXaxis()->SetLimits(0,nLayers);
1087  gr2->SetMarkerColor(1);
1088  gr2->SetMarkerSize(1.2);
1089  gr2->SetLineColor(1);
1090  gr2->SetLineWidth(4);
1091  gr2->SetMarkerStyle(21);
1092  gr2->SetMinimum(_effPlotMin);
1093  gr2->SetMaximum(1.001);
1094  gr2->GetYaxis()->SetTitle("Efficiency");
1095  gr2->SetTitle(_title);
1096 
1097  for ( Long_t k=1; k<nLayers+1; k++) {
1098  TString label;
1099  if(_showEndcapSides) label = GetLayerSideName(k);
1100  else label = GetLayerName(k);
1101  if(!_showTOB6TEC9) {
1102  if(k==10) label="";
1103  if(!_showRings && k==nLayers) label="";
1104  if(!_showRings && _showEndcapSides && k==25) label="";
1105  }
1106  if(!_showRings) {
1107  if(_showEndcapSides) {
1108  gr->GetXaxis()->SetBinLabel(((k+1)*100+2)/(nLayers)-4,label);
1109  gr2->GetXaxis()->SetBinLabel(((k+1)*100+2)/(nLayers)-4,label);
1110  }
1111  else {
1112  gr->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-6,label);
1113  gr2->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-6,label);
1114  }
1115  }
1116  else {
1117  if(_showEndcapSides) {
1118  gr->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-4,label);
1119  gr2->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-4,label);
1120  }
1121  else {
1122  gr->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-7,label);
1123  gr2->GetXaxis()->SetBinLabel((k+1)*100/(nLayers)-7,label);
1124  }
1125  }
1126  }
1127 
1128  gr->Draw("AP");
1129  gr->GetXaxis()->SetNdivisions(36);
1130 
1131  c7->cd();
1132  TPad *overlay = new TPad("overlay","",0,0,1,1);
1133  overlay->SetFillStyle(4000);
1134  overlay->SetFillColor(0);
1135  overlay->SetFrameFillStyle(4000);
1136  overlay->Draw("same");
1137  overlay->cd();
1138  if(!_showOnlyGoodModules) gr2->Draw("AP");
1139 
1140  TLegend *leg = new TLegend(0.70,0.27,0.88,0.40);
1141  leg->AddEntry(gr,"Good Modules","p");
1142  if(!_showOnlyGoodModules) leg->AddEntry(gr2,"All Modules","p");
1143  leg->SetTextSize(0.020);
1144  leg->SetFillColor(0);
1145  leg->Draw("same");
1146 
1147  c7->SaveAs("Summary.png");
1148 }
1149 
1150 
1152  cout<<"Computing efficiency vs bx"<<endl;
1153 
1154  unsigned int nLayers = 22;
1155  if(_showRings) nLayers = 20;
1156 
1157  for(unsigned int ilayer=1; ilayer<nLayers; ilayer++) {
1158  TH1F *hfound = fs->make<TH1F>(Form("foundVsBx_layer%i", ilayer),Form("layer %i", ilayer),3565,0,3565);
1159  TH1F *htotal = fs->make<TH1F>(Form("totalVsBx_layer%i", ilayer),Form("layer %i", ilayer),3565,0,3565);
1160 
1161  for(unsigned int ibx=0; ibx<3566; ibx++){
1162  hfound->SetBinContent(ibx, 1e-6);
1163  htotal->SetBinContent(ibx, 1);
1164  }
1165  map<unsigned int, vector<int> >::iterator iterMapvsBx;
1166  for(iterMapvsBx=layerfound_perBx.begin(); iterMapvsBx!=layerfound_perBx.end(); ++iterMapvsBx)
1167  hfound->SetBinContent( iterMapvsBx->first, iterMapvsBx->second[ilayer]);
1168  for(iterMapvsBx=layertotal_perBx.begin(); iterMapvsBx!=layertotal_perBx.end(); ++iterMapvsBx)
1169  if(iterMapvsBx->second[ilayer]>0) htotal->SetBinContent( iterMapvsBx->first, iterMapvsBx->second[ilayer]);
1170 
1171  hfound->Sumw2();
1172  htotal->Sumw2();
1173 
1174  TGraphAsymmErrors *geff = fs->make<TGraphAsymmErrors>(3564);
1175  geff->SetName(Form("effVsBx_layer%i", ilayer));
1176  geff->SetTitle("Hit Efficiency vs bx - "+GetLayerName(ilayer));
1177  geff->BayesDivide(hfound,htotal);
1178 
1179  //Average over trains
1180  TGraphAsymmErrors *geff_avg = fs->make<TGraphAsymmErrors>();
1181  geff_avg->SetName(Form("effVsBxAvg_layer%i", ilayer));
1182  geff_avg->SetTitle("Hit Efficiency vs bx - "+GetLayerName(ilayer));
1183  geff_avg->SetMarkerStyle(20);
1184  int ibx=0;
1185  int previous_bx=-80;
1186  int delta_bx=0;
1187  int nbx=0;
1188  int found=0;
1189  int total=0;
1190  double sum_bx=0;
1191  int ipt=0;
1192  float low, up, eff;
1193  int firstbx=0;
1194  for(iterMapvsBx=layertotal_perBx.begin(); iterMapvsBx!=layertotal_perBx.end(); ++iterMapvsBx){
1195  ibx=iterMapvsBx->first;
1196  delta_bx=ibx-previous_bx;
1197  // consider a new train
1198  if(delta_bx>(int)_spaceBetweenTrains && nbx>0 && total>0){
1199  eff=found/(float)total;
1200  //cout<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
1201  geff_avg->SetPoint(ipt, sum_bx/nbx, eff);
1202  low = TEfficiency::Bayesian(total, found, .683, 1, 1, false);
1203  up = TEfficiency::Bayesian(total, found, .683, 1, 1, true);
1204  geff_avg->SetPointError(ipt, sum_bx/nbx-firstbx, previous_bx-sum_bx/nbx, eff-low, up-eff);
1205  ipt++;
1206  sum_bx=0;
1207  found=0;
1208  total=0;
1209  nbx=0;
1210  firstbx=ibx;
1211  }
1212  sum_bx+=ibx;
1213  found+=hfound->GetBinContent(ibx);
1214  total+=htotal->GetBinContent(ibx);
1215  nbx++;
1216 
1217  previous_bx=ibx;
1218  }
1219  //last train
1220  eff=found/(float)total;
1221  //cout<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
1222  geff_avg->SetPoint(ipt, sum_bx/nbx, eff);
1223  low = TEfficiency::Bayesian(total, found, .683, 1, 1, false);
1224  up = TEfficiency::Bayesian(total, found, .683, 1, 1, true);
1225  geff_avg->SetPointError(ipt, sum_bx/nbx-firstbx, previous_bx-sum_bx/nbx, eff-low, up-eff);
1226  }
1227 }
1228 
1229 
1231 
1232  TString layername="";
1233  TString ringlabel="D";
1234  if(_showRings) ringlabel="R";
1235  if (k>0 && k<5) {
1236  layername = TString("TIB L") + k;
1237  } else if (k>4 && k<11) {
1238  layername = TString("TOB L")+(k-4);
1239  } else if (k>10 && k<14) {
1240  layername = TString("TID ")+ringlabel+(k-10);
1241  } else if (k>13 && k<14+nTEClayers) {
1242  layername = TString("TEC ")+ringlabel+(k-13);
1243  }
1244 
1245  return layername;
1246 }
1247 
1248 void SiStripHitEffFromCalibTree::ComputeEff(vector< TH1F* > &vhfound, vector< TH1F* > &vhtotal, string name) {
1249 
1250  unsigned int nLayers = 22;
1251  if(_showRings) nLayers = 20;
1252 
1253  TH1F* hfound;
1254  TH1F* htotal;
1255 
1256  for(unsigned int ilayer=1; ilayer<nLayers; ilayer++) {
1257 
1258  hfound = vhfound[ilayer];
1259  htotal = vhtotal[ilayer];
1260 
1261  hfound->Sumw2();
1262  htotal->Sumw2();
1263 
1264  // new ROOT version: TGraph::Divide don't handle null or negative values
1265  for (Long_t i=0; i< hfound->GetNbinsX()+1; ++i) {
1266  if( hfound->GetBinContent(i)==0) hfound->SetBinContent(i,1e-6);
1267  if( htotal->GetBinContent(i)==0) htotal->SetBinContent(i,1);
1268  }
1269 
1270  TGraphAsymmErrors *geff = fs->make<TGraphAsymmErrors>(hfound->GetNbinsX());
1271  geff->SetName(Form("%s_layer%i", name.c_str(), ilayer));
1272  geff->BayesDivide(hfound, htotal);
1273  if(name=="effVsLumi") geff->SetTitle("Hit Efficiency vs inst. lumi. - "+GetLayerName(ilayer));
1274  if(name=="effVsPU") geff->SetTitle("Hit Efficiency vs pileup - "+GetLayerName(ilayer));
1275  if(name=="effVsCM") geff->SetTitle("Hit Efficiency vs common Mode - "+GetLayerName(ilayer));
1276  geff->SetMarkerStyle(20);
1277 
1278  }
1279 
1280 }
1281 
1283  cout<<"Computing efficiency vs lumi"<<endl;
1284 
1285  unsigned int nLayers = 22;
1286  if(_showRings) nLayers = 20;
1287  unsigned int nLayersForAvg = 0;
1288  float layerLumi = 0;
1289  float layerPU = 0;
1290  float avgLumi = 0;
1291  float avgPU = 0;
1292 
1293  cout<<"Lumi summary: (avg over trajectory measurements)"<<endl;
1294  for(unsigned int ilayer=1; ilayer<nLayers; ilayer++) {
1295  layerLumi=layertotal_vsLumi[ilayer]->GetMean();
1296  layerPU=layertotal_vsPU[ilayer]->GetMean();
1297  //cout<<" layer "<<ilayer<<" lumi: "<<layerLumi<<" pu: "<<layerPU<<endl;
1298  if(layerLumi!=0 && layerPU!=0) {
1299  avgLumi+=layerLumi;
1300  avgPU+=layerPU;
1301  nLayersForAvg++;
1302  }
1303  }
1304  avgLumi/=nLayersForAvg;
1305  avgPU/=nLayersForAvg;
1306  cout<<"Avg conditions: lumi :"<<avgLumi<<" pu: "<<avgPU<<endl;
1307 
1310 
1311 }
1312 
1314  cout<<"Computing efficiency vs CM"<<endl;
1316 }
1317 
1319 
1320  TString layername="";
1321  TString ringlabel="D";
1322  if(_showRings) ringlabel="R";
1323  if (k>0 && k<5) {
1324  layername = TString("TIB L") + k;
1325  } else if (k>4&&k<11) {
1326  layername = TString("TOB L")+(k-4);
1327  } else if (k>10&&k<14) {
1328  layername = TString("TID- ")+ringlabel+(k-10);
1329  } else if (k>13&&k<17) {
1330  layername = TString("TID+ ")+ringlabel+(k-13);
1331  } else if (k>16&&k<17+nTEClayers) {
1332  layername = TString("TEC- ")+ringlabel+(k-16);
1333  } else if (k>16+nTEClayers) {
1334  layername = TString("TEC+ ")+ringlabel+(k-16-nTEClayers);
1335  }
1336 
1337  return layername;
1338 }
1339 
1341  //Need this for a Condition DB Writer
1342  //Initialize a return variable
1344 
1347 
1348  for(;rIter!=rIterEnd;++rIter){
1349  SiStripBadStrip::Range range(quality_->getDataVectorBegin()+rIter->ibegin,quality_->getDataVectorBegin()+rIter->iend);
1350  if ( ! obj->put(rIter->detid,range) )
1351  edm::LogError("SiStripHitEffFromCalibTree")<<"[SiStripHitEffFromCalibTree::getNewObject] detid already exists"<<std::endl;
1352  }
1353 
1354  return obj;
1355 }
1356 
1358  float phi = 0;
1359  float Pi = 3.14159;
1360  if((x>=0)&&(y>=0)) phi = atan(y/x);
1361  else if((x>=0)&&(y<=0)) phi = atan(y/x) + 2*Pi;
1362  else if((x<=0)&&(y>=0)) phi = atan(y/x) + Pi;
1363  else phi = atan(y/x) + Pi;
1364  phi = phi*180.0/Pi;
1365 
1366  return phi;
1367 }
1368 
1369 void SiStripHitEffFromCalibTree::SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]){
1370 
1371  int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
1372 
1373  ssV[i][component] << "\n\t\t "
1374  << BC.detid
1375  << " \t " << BC.BadModule << " \t "
1376  << ( (BC.BadFibers)&0x1 ) << " ";
1377  if (napv==4)
1378  ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
1379 
1380  if (napv==6)
1381  ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
1382  << ( (BC.BadFibers>>2)&0x1 );
1383  ssV[i][component] << " \t "
1384  << ( (BC.BadApvs)&0x1 ) << " "
1385  << ( (BC.BadApvs>>1)&0x1 ) << " ";
1386  if (napv==4)
1387  ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
1388  << ( (BC.BadApvs>>3)&0x1 );
1389  if (napv==6)
1390  ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
1391  << ( (BC.BadApvs>>3)&0x1 ) << " "
1392  << ( (BC.BadApvs>>4)&0x1 ) << " "
1393  << ( (BC.BadApvs>>5)&0x1 ) << " ";
1394 
1395  if (BC.BadApvs){
1396  NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
1397  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
1398  NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
1399  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
1400  }
1401  if (BC.BadFibers){
1402  NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
1403  NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
1404  }
1405  if (BC.BadModule){
1406  NBadComponent[i][0][0]++;
1407  NBadComponent[i][component][0]++;
1408  }
1409 }
1410 
unsigned short range
RunNumber_t run() const
Definition: EventID.h:39
Definition: BitonicSort.h:8
const double Pi
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< BadComponent > & getBadComponentList() const
unsigned int tibLayer(const DetId &id) const
virtual const std::array< const float, 4 > parameters() const
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
const Bounds & bounds() const
Definition: Surface.h:120
unsigned int tidWheel(const DetId &id) const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void SetBadComponents(int i, int component, SiStripQuality::BadComponent &BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4])
Registry::const_iterator RegistryIterator
SiStripDetInfoFileReader * reader
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
U second(std::pair< T, U > const &p)
virtual float width() const =0
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
def overlay(hists, ytitle, header, addon)
Definition: compare.py:119
RegistryIterator getRegistryVectorEnd() const
edm::Service< TFileService > fs
map< unsigned int, vector< int > > layerfound_perBx
unsigned int tidSide(const DetId &id) const
void ComputeEff(vector< TH1F * > &vhfound, vector< TH1F * > &vhtotal, string name)
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:699
void compact(unsigned int &, std::vector< unsigned int > &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:39
SiStripBadStrip * getNewObject() override
void fillBadComponents()
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
map< unsigned int, pair< unsigned int, unsigned int > > modCounter[23]
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:109
int k[5][pyjets_maxn]
unsigned int id
ContainerIterator getDataVectorBegin() const
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:18
virtual int nstrips() const =0
const T & get() const
Definition: EventSetup.h:58
RegistryIterator getRegistryVectorBegin() const
edm::EventID id() const
Definition: EventBase.h:60
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
map< unsigned int, vector< int > > layertotal_perBx
void algoAnalyze(const edm::Event &e, const edm::EventSetup &c) override
double a
Definition: hdecay.h:121
std::pair< ContainerIterator, ContainerIterator > Range
std::string fullPath() const
Definition: FileInPath.cc:197
map< unsigned int, double > BadModules
bool put(const uint32_t &detID, const InputVector &vect)
unsigned int tecWheel(const DetId &id) const
T const * product() const
Definition: ESHandle.h:86
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
TimeValue_t value() const
Definition: Timestamp.h:56
SiStripHitEffFromCalibTree(const edm::ParameterSet &)
edm::Timestamp time() const
Definition: EventBase.h:61
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2786
data decode(const unsigned int &value) const
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const