test
CMS 3D CMS Logo

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