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