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 
15 
36 
48 
51 
56 
57 #include "TFile.h"
58 #include "TCanvas.h"
59 #include "TObjString.h"
60 #include "TString.h"
61 #include "TH1F.h"
62 #include "TH2F.h"
63 #include "TProfile.h"
64 #include "TF1.h"
65 #include "TROOT.h"
66 #include "TTree.h"
67 #include "TChain.h"
68 #include "TStyle.h"
69 #include "TLeaf.h"
70 #include "TGaxis.h"
71 #include "TGraphAsymmErrors.h"
72 #include "TLatex.h"
73 #include "TLegend.h"
74 
75 using namespace edm;
76 using namespace reco;
77 using namespace std;
78 
79 struct hit{
80  double x;
81  double y;
82  double z;
83  unsigned int id;
84 };
85 
86 class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
87  public:
90 
91  private:
92  virtual void algoBeginJob();
93  virtual void algoEndJob() override;
94  virtual void algoAnalyze(const edm::Event& e, const edm::EventSetup& c) override;
95  void SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]);
96  void makeTKMap();
97  void makeHotColdMaps();
98  void makeSQLite();
99  void totalStatistics();
100  void makeSummary();
101  float calcPhi(float x, float y);
102 
107  SiStripBadStrip* getNewObject() override;
108 
110  TTree* CalibTree;
112  float threshold;
113  unsigned int nModsMin;
114  unsigned int doSummary;
115  float _ResXSig;
116  unsigned int _bunchx;
117  vector<hit> hits[23];
118  vector<TH2F*> HotColdMaps;
119  map< unsigned int, pair< unsigned int, unsigned int> > modCounter[23];
122  int layerfound[23];
123  int layertotal[23];
124  int goodlayertotal[35];
125  int goodlayerfound[35];
126  int alllayertotal[35];
127  int alllayerfound[35];
128  map< unsigned int, double > BadModules;
129 };
130 
133  FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat")
134 {
135  CalibTreeFilename = conf.getParameter<std::string>("CalibTreeFilename");
136  threshold = conf.getParameter<double>("Threshold");
137  nModsMin = conf.getParameter<int>("nModsMin");
138  doSummary = conf.getParameter<int>("doSummary");
139  _ResXSig = conf.getUntrackedParameter<double>("ResXSig",-1);
140  _bunchx = conf.getUntrackedParameter<int>("BunchCrossing",0);
142 
143  quality_ = new SiStripQuality;
144 }
145 
147 
149  //I have no idea what goes here
150  //fs->make<TTree>("HitEffHistos","Tree of the inefficient hit histograms");
151 }
152 
154  //Still have no idea what goes here
155 
156 }
157 
159  //Retrieve tracker topology from geometry
160  edm::ESHandle<TrackerTopology> tTopoHandle;
161  c.get<TrackerTopologyRcd>().get(tTopoHandle);
162  const TrackerTopology* const tTopo = tTopoHandle.product();
163 
164  //Open the ROOT Calib Tree
165  CalibTreeFile = TFile::Open(CalibTreeFilename,"READ");
166  CalibTreeFile->cd("anEff");
167  CalibTree = (TTree*)(gDirectory->Get("traj")) ;
168  TLeaf* BadLf = CalibTree->GetLeaf("ModIsBad");
169  TLeaf* sistripLf = CalibTree->GetLeaf("SiStripQualBad");
170  TLeaf* idLf = CalibTree->GetLeaf("Id");
171  TLeaf* acceptLf = CalibTree->GetLeaf("withinAcceptance");
172  TLeaf* layerLf = CalibTree->GetLeaf("layer");
173  TLeaf* nHitsLf = CalibTree->GetLeaf("nHits");
174  TLeaf* xLf = CalibTree->GetLeaf("TrajGlbX");
175  TLeaf* yLf = CalibTree->GetLeaf("TrajGlbY");
176  TLeaf* zLf = CalibTree->GetLeaf("TrajGlbZ");
177  TLeaf* ResXSigLf = CalibTree->GetLeaf("ResXSig");
178  TLeaf* BunchLf(0);
179  for(int l=0; l < 35; l++) {
180  goodlayertotal[l] = 0;
181  goodlayerfound[l] = 0;
182  alllayertotal[l] = 0;
183  alllayerfound[l] = 0;
184  }
185  if(_bunchx != 0) {
186  BunchLf = CalibTree->GetLeaf("bunchx");
187  }
188  int nevents = CalibTree->GetEntries();
189  cout << "Successfully loaded analyze function with " << nevents << " events!\n";
190  cout << "A module is bad if efficiency < " << threshold << " and has at least " << nModsMin << " nModsMin." << endl;
191 
192  //Loop through all of the events
193  for(int j =0; j < nevents; j++) {
194  CalibTree->GetEvent(j);
195  unsigned int isBad = (unsigned int)BadLf->GetValue();
196  unsigned int quality = (unsigned int)sistripLf->GetValue();
197  unsigned int id = (unsigned int)idLf->GetValue();
198  unsigned int accept = (unsigned int)acceptLf->GetValue();
199  unsigned int layer = (unsigned int)layerLf->GetValue();
200  unsigned int nHits = (unsigned int)nHitsLf->GetValue();
201  double x = xLf->GetValue();
202  double y = yLf->GetValue();
203  double z = zLf->GetValue();
204  double resxsig = ResXSigLf->GetValue();
205  bool badquality = false;
206  if(_bunchx != 0) {
207  if(_bunchx != BunchLf->GetValue()) continue;
208  }
209  //We have two things we want to do, both an XY color plot, and the efficiency measurement
210  //First, ignore anything that isn't in acceptance and isn't good quality
211 
212  //if(quality == 1 || accept != 1 || nHits < 8) continue;
213  if(accept != 1 || nHits < 8) continue;
214  if(quality == 1) badquality = true;
215 
216  //Now that we have a good event, we need to look at if we expected it or not, and the location
217  //if we didn't
218  //Fill the missing hit information first
219  bool badflag = false;
220  if(_ResXSig < 0) {
221  if(isBad == 1) badflag = true;
222  }
223  else {
224  if(isBad == 1 || resxsig > _ResXSig) badflag = true;
225  }
226  if(badflag && !badquality) {
227  hit temphit;
228  temphit.x = x;
229  temphit.y = y;
230  temphit.z = z;
231  temphit.id = id;
232  hits[layer].push_back(temphit);
233  }
234  pair<unsigned int, unsigned int> newgoodpair (1,1);
235  pair<unsigned int, unsigned int> newbadpair (1,0);
236  //First, figure out if the module already exists in the map of maps
237  map< unsigned int, pair< unsigned int, unsigned int> >::iterator it = modCounter[layer].find(id);
238  if(!badquality) {
239  if(it == modCounter[layer].end()) {
240  if(badflag) modCounter[layer][id] = newbadpair;
241  else modCounter[layer][id] = newgoodpair;
242  }
243  else {
244  ((*it).second.first)++;
245  if(!badflag) ((*it).second.second)++;
246  }
247  //Have to do the decoding for which side to go on (ugh)
248  if(layer <= 10) {
249  if(!badflag) goodlayerfound[layer]++;
250  goodlayertotal[layer]++;
251  }
252  else if(layer > 10 && layer < 14) {
253  if( ((id>>13)&0x3) == 1) {
254  if(!badflag) goodlayerfound[layer]++;
255  goodlayertotal[layer]++;
256  }
257  else if( ((id>>13)&0x3) == 2) {
258  if(!badflag) goodlayerfound[layer+3]++;
259  goodlayertotal[layer+3]++;
260  }
261  }
262  else if(layer > 13 && layer <= 22) {
263  if( ((id>>18)&0x3) == 1) {
264  if(!badflag) goodlayerfound[layer+3]++;
265  goodlayertotal[layer+3]++;
266  }
267  else if( ((id>>18)&0x3) == 2) {
268  if(!badflag) goodlayerfound[layer+12]++;
269  goodlayertotal[layer+12]++;
270  }
271  }
272  }
273  //Do the one where we don't exclude bad modules!
274  if(layer <= 10) {
275  if(!badflag) alllayerfound[layer]++;
276  alllayertotal[layer]++;
277  }
278  else if(layer > 10 && layer < 14) {
279  if( ((id>>13)&0x3) == 1) {
280  if(!badflag) alllayerfound[layer]++;
281  alllayertotal[layer]++;
282  }
283  else if( ((id>>13)&0x3) == 2) {
284  if(!badflag) alllayerfound[layer+3]++;
285  alllayertotal[layer+3]++;
286  }
287  }
288  else if(layer > 13 && layer <= 22) {
289  if( ((id>>18)&0x3) == 1) {
290  if(!badflag) alllayerfound[layer+3]++;
291  alllayertotal[layer+3]++;
292  }
293  else if( ((id>>18)&0x3) == 2) {
294  if(!badflag) alllayerfound[layer+12]++;
295  alllayertotal[layer+12]++;
296  }
297  }
298  //At this point, both of our maps are loaded with the correct information
299  }
300  //CalibTreeFile->Close();
301  makeHotColdMaps();
302  makeTKMap();
303  makeSQLite();
304  totalStatistics();
305  makeSummary();
306 
308  //try to write out what's in the quality record
310  int NTkBadComponent[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
311  int NBadComponent[4][19][4];
312  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
313  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
314  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
315  std::stringstream ssV[4][19];
316 
317  for(int i=0;i<4;++i){
318  NTkBadComponent[i]=0;
319  for(int j=0;j<19;++j){
320  ssV[i][j].str("");
321  for(int k=0;k<4;++k)
322  NBadComponent[i][j][k]=0;
323  }
324  }
325 
326 
327  std::vector<SiStripQuality::BadComponent> BC = quality_->getBadComponentList();
328 
329  for (size_t i=0;i<BC.size();++i){
330 
331  //&&&&&&&&&&&&&
332  //Full Tk
333  //&&&&&&&&&&&&&
334 
335  if (BC[i].BadModule)
336  NTkBadComponent[0]++;
337  if (BC[i].BadFibers)
338  NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
339  if (BC[i].BadApvs)
340  NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
341  ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
342 
343  //&&&&&&&&&&&&&&&&&
344  //Single SubSystem
345  //&&&&&&&&&&&&&&&&&
346 
347  int component;
348  SiStripDetId a(BC[i].detid);
349  if ( a.subdetId() == SiStripDetId::TIB ){
350  //&&&&&&&&&&&&&&&&&
351  //TIB
352  //&&&&&&&&&&&&&&&&&
353 
354  component=tTopo->tibLayer(BC[i].detid);
355  SetBadComponents(0, component, BC[i], ssV, NBadComponent);
356 
357  } else if ( a.subdetId() == SiStripDetId::TID ) {
358  //&&&&&&&&&&&&&&&&&
359  //TID
360  //&&&&&&&&&&&&&&&&&
361 
362  component=tTopo->tidSide(BC[i].detid)==2?tTopo->tidWheel(BC[i].detid):tTopo->tidWheel(BC[i].detid)+3;
363  SetBadComponents(1, component, BC[i], ssV, NBadComponent);
364 
365  } else if ( a.subdetId() == SiStripDetId::TOB ) {
366  //&&&&&&&&&&&&&&&&&
367  //TOB
368  //&&&&&&&&&&&&&&&&&
369 
370  component=tTopo->tobLayer(BC[i].detid);
371  SetBadComponents(2, component, BC[i], ssV, NBadComponent);
372 
373  } else if ( a.subdetId() == SiStripDetId::TEC ) {
374  //&&&&&&&&&&&&&&&&&
375  //TEC
376  //&&&&&&&&&&&&&&&&&
377 
378  component=tTopo->tecSide(BC[i].detid)==2?tTopo->tecWheel(BC[i].detid):tTopo->tecWheel(BC[i].detid)+9;
379  SetBadComponents(3, component, BC[i], ssV, NBadComponent);
380 
381  }
382  }
383 
384  //&&&&&&&&&&&&&&&&&&
385  // Single Strip Info
386  //&&&&&&&&&&&&&&&&&&
387  float percentage=0;
388 
391 
392  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
393  unsigned int detid=rp->detid;
394 
395  int subdet=-999; int component=-999;
396  SiStripDetId a(detid);
397  if ( a.subdetId() == 3 ){
398  subdet=0;
399  component=tTopo->tibLayer(detid);
400  } else if ( a.subdetId() == 4 ) {
401  subdet=1;
402  component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
403  } else if ( a.subdetId() == 5 ) {
404  subdet=2;
405  component=tTopo->tobLayer(detid);
406  } else if ( a.subdetId() == 6 ) {
407  subdet=3;
408  component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
409  }
410 
412 
413  percentage=0;
414  for(int it=0;it<sqrange.second-sqrange.first;it++){
415  unsigned int range=quality_->decode( *(sqrange.first+it) ).range;
416  NTkBadComponent[3]+=range;
417  NBadComponent[subdet][0][3]+=range;
418  NBadComponent[subdet][component][3]+=range;
419  percentage+=range;
420  }
421  if(percentage!=0)
422  percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
423  if(percentage>1)
424  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage<< std::endl;
425  }
426  //&&&&&&&&&&&&&&&&&&
427  // printout
428  //&&&&&&&&&&&&&&&&&&
429 
430  cout << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event() << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
431  cout << "\n-----------------\nGlobal Info\n-----------------";
432  cout << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
433  cout << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
434  cout << endl;
435  cout << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
436  cout << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
437  cout << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
438  cout << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
439  cout << "\n";
440 
441  for (int i=1;i<5;++i)
442  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];
443  cout << "\n";
444  for (int i=1;i<4;++i)
445  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];
446  for (int i=4;i<7;++i)
447  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];
448  cout << "\n";
449  for (int i=1;i<7;++i)
450  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];
451  cout << "\n";
452  for (int i=1;i<10;++i)
453  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];
454  for (int i=10;i<19;++i)
455  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];
456  cout << "\n";
457 
458  cout << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
459  for (int i=1;i<5;++i)
460  cout << "\nTIB Layer " << i << " :" << ssV[0][i].str();
461  cout << "\n";
462  for (int i=1;i<4;++i)
463  cout << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
464  for (int i=4;i<7;++i)
465  cout << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
466  cout << "\n";
467  for (int i=1;i<7;++i)
468  cout << "\nTOB Layer " << i << " :" << ssV[2][i].str();
469  cout << "\n";
470  for (int i=1;i<10;++i)
471  cout << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
472  for (int i=10;i<19;++i)
473  cout << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
474 
475 }
476 
478  cout << "Entering hot cold map generation!\n";
479  TStyle* gStyle = new TStyle("gStyle","myStyle");
480  gStyle->cd();
481  gStyle->SetPalette(1);
482  gStyle->SetCanvasColor(kWhite);
483  gStyle->SetOptStat(0);
484  //Here we make the hot/cold color maps that we love so very much
485  //Already have access to the data as a private variable
486  //Create all of the histograms in the TFileService
487  TH2F *temph2;
488  for(Long_t maplayer = 1; maplayer <=22; maplayer++) {
489  //Initialize all of the histograms
490  if(maplayer > 0 && maplayer <= 4) {
491  //We are in the TIB
492  temph2 = fs->make<TH2F>(Form("%s%i","TIB",(int)(maplayer)),"TIB",100,-1,361,100,-100,100);
493  temph2->GetXaxis()->SetTitle("Phi");
494  temph2->GetXaxis()->SetBinLabel(1,TString("360"));
495  temph2->GetXaxis()->SetBinLabel(50,TString("180"));
496  temph2->GetXaxis()->SetBinLabel(100,TString("0"));
497  temph2->GetYaxis()->SetTitle("Global Z");
498  temph2->SetOption("colz");
499  HotColdMaps.push_back(temph2);
500  }
501  else if(maplayer > 4 && maplayer <= 10) {
502  //We are in the TOB
503  temph2 = fs->make<TH2F>(Form("%s%i","TOB",(int)(maplayer-4)),"TOB",100,-1,361,100,-120,120);
504  temph2->GetXaxis()->SetTitle("Phi");
505  temph2->GetXaxis()->SetBinLabel(1,TString("360"));
506  temph2->GetXaxis()->SetBinLabel(50,TString("180"));
507  temph2->GetXaxis()->SetBinLabel(100,TString("0"));
508  temph2->GetYaxis()->SetTitle("Global Z");
509  temph2->SetOption("colz");
510  HotColdMaps.push_back(temph2);
511  }
512  else if(maplayer > 10 && maplayer <= 13) {
513  //We are in the TID
514  //Split by +/-
515  temph2 = fs->make<TH2F>(Form("%s%i","TID-",(int)(maplayer-10)),"TID-",100,-100,100,100,-100,100);
516  temph2->GetXaxis()->SetTitle("Global Y");
517  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
518  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
519  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
520  temph2->GetYaxis()->SetTitle("Global X");
521  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
522  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
523  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
524  temph2->SetOption("colz");
525  HotColdMaps.push_back(temph2);
526  temph2 = fs->make<TH2F>(Form("%s%i","TID+",(int)(maplayer-10)),"TID+",100,-100,100,100,-100,100);
527  temph2->GetXaxis()->SetTitle("Global Y");
528  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
529  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
530  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
531  temph2->GetYaxis()->SetTitle("Global X");
532  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
533  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
534  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
535  temph2->SetOption("colz");
536  HotColdMaps.push_back(temph2);
537  }
538  else if(maplayer > 13) {
539  //We are in the TEC
540  //Split by +/-
541  temph2 = fs->make<TH2F>(Form("%s%i","TEC-",(int)(maplayer-13)),"TEC-",100,-120,120,100,-120,120);
542  temph2->GetXaxis()->SetTitle("Global Y");
543  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
544  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
545  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
546  temph2->GetYaxis()->SetTitle("Global X");
547  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
548  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
549  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
550  temph2->SetOption("colz");
551  HotColdMaps.push_back(temph2);
552  temph2 = fs->make<TH2F>(Form("%s%i","TEC+",(int)(maplayer-13)),"TEC+",100,-120,120,100,-120,120);
553  temph2->GetXaxis()->SetTitle("Global Y");
554  temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
555  temph2->GetXaxis()->SetBinLabel(50,TString("0"));
556  temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
557  temph2->GetYaxis()->SetTitle("Global X");
558  temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
559  temph2->GetYaxis()->SetBinLabel(50,TString("0"));
560  temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
561  temph2->SetOption("colz");
562  HotColdMaps.push_back(temph2);
563  }
564  }
565  for(Long_t mylayer = 1; mylayer <= 22; mylayer++) {
566  //Determine what kind of plot we want to write out
567  //Loop through the entirety of each layer
568  //Create an array of the histograms
569  vector<hit>::const_iterator iter;
570  for(iter = hits[mylayer].begin(); iter != hits[mylayer].end(); iter++) {
571  //Looping over the particular layer
572  //Fill by 360-x to get the proper location to compare with TKMaps of phi
573  //Also global xy is messed up
574  if(mylayer > 0 && mylayer <= 4) {
575  //We are in the TIB
576  float phi = calcPhi(iter->x, iter->y);
577  HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
578  }
579  else if(mylayer > 4 && mylayer <= 10) {
580  //We are in the TOB
581  float phi = calcPhi(iter->x,iter->y);
582  HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
583  }
584  else if(mylayer > 10 && mylayer <= 13) {
585  //We are in the TID
586  //There are 2 different maps here
587  int side = (((iter->id)>>13) & 0x3);
588  if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(-iter->y,iter->x,1.);
589  else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(-iter->y,iter->x,1.);
590  //if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(iter->x,iter->y,1.);
591  //else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(iter->x,iter->y,1.);
592  }
593  else if(mylayer > 13) {
594  //We are in the TEC
595  //There are 2 different maps here
596  int side = (((iter->id)>>18) & 0x3);
597  if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(-iter->y,iter->x,1.);
598  else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(-iter->y,iter->x,1.);
599  //if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(iter->x,iter->y,1.);
600  //else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(iter->x,iter->y,1.);
601  }
602  }
603  }
604  cout << "Finished HotCold Map Generation\n";
605 }
606 
608  cout << "Entering TKMap generation!\n";
609  tkmap = new TrackerMap(" Detector Inefficiency ");
610  tkmapbad = new TrackerMap(" Inefficient Modules ");
611  for(Long_t i = 1; i <= 22; i++) {
612  layertotal[i] = 0;
613  layerfound[i] = 0;
614  //Loop over every layer, extracting the information from
615  //the map of the efficiencies
616  map<unsigned int, pair<unsigned int, unsigned int> >::const_iterator ih;
617  for( ih = modCounter[i].begin(); ih != modCounter[i].end(); ih++) {
618  //We should be in the layer in question, and looping over all of the modules in said layer
619  //Generate the list for the TKmap, and the bad module list
620  double myeff = (double)(((*ih).second).second)/(((*ih).second).first);
621  if ( ((((*ih).second).first) >= nModsMin) && (myeff < threshold) ) {
622  //We have a bad module, put it in the list!
623  BadModules[(*ih).first] = myeff;
624  tkmapbad->fillc((*ih).first,255,0,0);
625  cout << "Layer " << i << " module " << (*ih).first << " efficiency " << myeff << " " << (((*ih).second).second) << "/" << (((*ih).second).first) << endl;
626  }
627  else {
628  //Fill the bad list with empty results for every module
629  tkmapbad->fillc((*ih).first,255,255,255);
630  }
631  if((((*ih).second).first) < 100 ) {
632  cout << "Module " << (*ih).first << " layer " << i << " is under occupancy at " << (((*ih).second).first) << endl;
633  }
634  //Put any module into the TKMap
635  //Should call module ID, and then 1- efficiency for that module
636  //if((*ih).first == 369137820) {
637  // cout << "Module 369137820 has 1-eff of " << 1.-myeff << endl;
638  //cout << "Which is " << ((*ih).second).second << "/" << ((*ih).second).first << endl;
639  //}
640  tkmap->fill((*ih).first,1.-myeff);
641  //Find the total number of hits in the module
642  layertotal[i] += int(((*ih).second).first);
643  layerfound[i] += int(((*ih).second).second);
644  }
645  }
646  tkmap->save(true, 0, 0, "SiStripHitEffTKMap.png");
647  tkmapbad->save(true, 0, 0, "SiStripHitEffTKMapBad.png");
648  cout << "Finished TKMap Generation\n";
649 }
650 
652  //Generate the SQLite file for use in the Database of the bad modules!
653  cout << "Entering SQLite file generation!\n";
654  std::vector<unsigned int> BadStripList;
655  unsigned short NStrips;
656  unsigned int id1;
657  SiStripQuality* pQuality = new SiStripQuality;
658  //This is the list of the bad strips, use to mask out entire APVs
659  //Now simply go through the bad hit list and mask out things that
660  //are bad!
661  map< unsigned int, double >::const_iterator it;
662  for(it = BadModules.begin(); it != BadModules.end(); it++) {
663  //We need to figure out how many strips are in this particular module
664  //To Mask correctly!
665  NStrips=reader->getNumberOfApvsAndStripLength((*it).first).first*128;
666  cout << "Number of strips module " << (*it).first << " is " << NStrips << endl;
667  BadStripList.push_back(pQuality->encode(0,NStrips,0));
668  //Now compact into a single bad module
669  id1=(unsigned int)(*it).first;
670  cout << "ID1 shoudl match list of modules above " << id1 << endl;
671  quality_->compact(id1,BadStripList);
672  SiStripQuality::Range range(BadStripList.begin(),BadStripList.end());
673  quality_->put(id1,range);
674  BadStripList.clear();
675  }
676  //Fill all the bad components now
678 }
679 
681  //Calculate the statistics by layer
682  int totalfound = 0;
683  int totaltotal = 0;
684  double layereff;
685  for(Long_t i=1; i<=22; i++) {
686  layereff = double(layerfound[i])/double(layertotal[i]);
687  cout << "Layer " << i << " has total efficiency " << layereff << " " << layerfound[i] << "/" << layertotal[i] << endl;
688  totalfound += layerfound[i];
689  totaltotal += layertotal[i];
690  }
691  cout << "The total efficiency is " << double(totalfound)/double(totaltotal) << endl;
692 }
693 
695  //setTDRStyle();
696 
697  int nLayers = 34;
698 
699  TH1F *found = fs->make<TH1F>("found","found",nLayers+1,0,nLayers+1);
700  TH1F *all = fs->make<TH1F>("all","all",nLayers+1,0,nLayers+1);
701  TH1F *found2 = fs->make<TH1F>("found2","found2",nLayers+1,0,nLayers+1);
702  TH1F *all2 = fs->make<TH1F>("all2","all2",nLayers+1,0,nLayers+1);
703  // first bin only to keep real data off the y axis so set to -1
704  found->SetBinContent(0,-1);
705  all->SetBinContent(0,1);
706 
707  TCanvas *c7 =new TCanvas("c7"," test ",10,10,800,600);
708  c7->SetFillColor(0);
709  c7->SetGrid();
710 
711  for (Long_t i=1; i< nLayers+1; ++i) {
712  if (i==10) i++;
713  if (i==25) i++;
714  if (i==34) break;
715 
716  cout << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] << " B = " << goodlayertotal[i] << endl;
717  if (goodlayertotal[i] > 5) {
718  found->SetBinContent(i,goodlayerfound[i]);
719  all->SetBinContent(i,goodlayertotal[i]);
720  } else {
721  found->SetBinContent(i,0);
722  all->SetBinContent(i,10);
723  }
724 
725  cout << "Filling all modules layer " << i << ": S = " << alllayerfound[i] << " B = " << alllayertotal[i] << endl;
726  if (alllayertotal[i] > 5) {
727  found2->SetBinContent(i,alllayerfound[i]);
728  all2->SetBinContent(i,alllayertotal[i]);
729  } else {
730  found2->SetBinContent(i,0);
731  all2->SetBinContent(i,10);
732  }
733 
734  }
735 
736  found->Sumw2();
737  all->Sumw2();
738 
739  found2->Sumw2();
740  all2->Sumw2();
741 
742  TGraphAsymmErrors *gr = new TGraphAsymmErrors(nLayers+1);
743  gr->BayesDivide(found,all);
744 
745  TGraphAsymmErrors *gr2 = new TGraphAsymmErrors(nLayers+1);
746  gr2->BayesDivide(found2,all2);
747 
748  for(int j = 0; j<nLayers+1; j++){
749  gr->SetPointError(j, 0., 0., gr->GetErrorYlow(j),gr->GetErrorYhigh(j) );
750  gr2->SetPointError(j, 0., 0., gr2->GetErrorYlow(j),gr2->GetErrorYhigh(j) );
751  }
752 
753  gr->GetXaxis()->SetLimits(0,nLayers);
754  gr->SetMarkerColor(2);
755  gr->SetMarkerSize(1.2);
756  gr->SetLineColor(2);
757  gr->SetLineWidth(4);
758  gr->SetMarkerStyle(20);
759  gr->SetMinimum(0.90);
760  gr->SetMaximum(1.001);
761  gr->GetYaxis()->SetTitle("Efficiency");
762 
763  gr2->GetXaxis()->SetLimits(0,nLayers);
764  gr2->SetMarkerColor(1);
765  gr2->SetMarkerSize(1.2);
766  gr2->SetLineColor(1);
767  gr2->SetLineWidth(4);
768  gr2->SetMarkerStyle(21);
769  gr2->SetMinimum(0.90);
770  gr2->SetMaximum(1.001);
771  gr2->GetYaxis()->SetTitle("Efficiency");
772  //cout << "starting labels" << endl;
773  //for ( int k=1; k<nLayers+1; k++) {
774  for ( Long_t k=1; k<nLayers+1; k++) {
775  if (k==10) k++;
776  if (k==25) k++;
777  if (k==34) break;
778  TString label;
779  if (k<5) {
780  label = TString("TIB ") + k;
781  } else if (k>4&&k<11) {
782  label = TString("TOB ")+(k-4);
783  } else if (k>10&&k<14) {
784  label = TString("TID- ")+(k-10);
785  } else if (k>13&&k<17) {
786  label = TString("TID+ ")+(k-13);
787  } else if (k>16&&k<26) {
788  label = TString("TEC- ")+(k-16);
789  } else if (k>25) {
790  label = TString("TEC+ ")+(k-25);
791  }
792  gr->GetXaxis()->SetBinLabel(((k+1)*100)/(nLayers)-2,label);
793  gr2->GetXaxis()->SetBinLabel(((k+1)*100)/(nLayers)-2,label);
794  }
795 
796  gr->Draw("AP");
797  gr->GetXaxis()->SetNdivisions(36);
798 
799  c7->cd();
800  TPad *overlay = new TPad("overlay","",0,0,1,1);
801  overlay->SetFillStyle(4000);
802  overlay->SetFillColor(0);
803  overlay->SetFrameFillStyle(4000);
804  overlay->Draw("same");
805  overlay->cd();
806  gr2->Draw("AP");
807 
808  TLegend *leg = new TLegend(0.70,0.20,0.92,0.39);
809  leg->AddEntry(gr,"Good Modules","p");
810  leg->AddEntry(gr2,"All Modules","p");
811  leg->SetTextSize(0.020);
812  leg->SetFillColor(0);
813  leg->Draw("same");
814 
815  c7->SaveAs("Summary.png");
816 }
817 
819  //Need this for a Condition DB Writer
820  //Initialize a return variable
822 
825 
826  for(;rIter!=rIterEnd;++rIter){
827  SiStripBadStrip::Range range(quality_->getDataVectorBegin()+rIter->ibegin,quality_->getDataVectorBegin()+rIter->iend);
828  if ( ! obj->put(rIter->detid,range) )
829  edm::LogError("SiStripHitEffFromCalibTree")<<"[SiStripHitEffFromCalibTree::getNewObject] detid already exists"<<std::endl;
830  }
831 
832  return obj;
833 }
834 
836  float phi = 0;
837  float Pi = 3.14159;
838  if((x>=0)&&(y>=0)) phi = atan(y/x);
839  else if((x>=0)&&(y<=0)) phi = atan(y/x) + 2*Pi;
840  else if((x<=0)&&(y>=0)) phi = atan(y/x) + Pi;
841  else phi = atan(y/x) + Pi;
842  phi = phi*180.0/Pi;
843 
844  return phi;
845 }
846 
847 void SiStripHitEffFromCalibTree::SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]){
848 
849  int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
850 
851  ssV[i][component] << "\n\t\t "
852  << BC.detid
853  << " \t " << BC.BadModule << " \t "
854  << ( (BC.BadFibers)&0x1 ) << " ";
855  if (napv==4)
856  ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
857 
858  if (napv==6)
859  ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
860  << ( (BC.BadFibers>>2)&0x1 );
861  ssV[i][component] << " \t "
862  << ( (BC.BadApvs)&0x1 ) << " "
863  << ( (BC.BadApvs>>1)&0x1 ) << " ";
864  if (napv==4)
865  ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
866  << ( (BC.BadApvs>>3)&0x1 );
867  if (napv==6)
868  ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
869  << ( (BC.BadApvs>>3)&0x1 ) << " "
870  << ( (BC.BadApvs>>4)&0x1 ) << " "
871  << ( (BC.BadApvs>>5)&0x1 ) << " ";
872 
873  if (BC.BadApvs){
874  NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
875  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
876  NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
877  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
878  }
879  if (BC.BadFibers){
880  NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
881  NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
882  }
883  if (BC.BadModule){
884  NBadComponent[i][0][0]++;
885  NBadComponent[i][component][0]++;
886  }
887 }
888 
unsigned short range
RunNumber_t run() const
Definition: EventID.h:39
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
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:63
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:25
U second(std::pair< T, U > const &p)
T x() const
Cartesian x coordinate.
RegistryIterator getRegistryVectorEnd() const
edm::Service< TFileService > fs
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 > &)
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]
tuple conf
Definition: dbtoconf.py:185
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:104
unsigned int id
ContainerIterator getDataVectorBegin() const
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
RegistryIterator getRegistryVectorBegin() const
edm::EventID id() const
Definition: EventBase.h:60
#define begin
Definition: vmac.h:30
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:121
map< unsigned int, double > BadModules
std::string fullPath() const
Definition: FileInPath.cc:165
bool put(const uint32_t &detID, const InputVector &vect)
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:61
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