00001
00002
00003 #include <memory>
00004 #include <string>
00005 #include <iostream>
00006
00007 #include "FWCore/Framework/interface/Frameworkfwd.h"
00008 #include "FWCore/Framework/interface/EDAnalyzer.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/MakerMacros.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/ParameterSet/interface/FileInPath.h"
00015
00016 #include "CalibTracker/SiStripHitEfficiency/interface/HitEff.h"
00017 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00018 #include "DataFormats/Common/interface/Handle.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00021 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00022 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00023 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00024 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00025 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00026 #include "DataFormats/TrackReco/interface/Track.h"
00027 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00028 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00029 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00030 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00031 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00032 #include "CalibTracker/SiStripHitEfficiency/interface/TrajectoryAtInvalidHit.h"
00033 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00034 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00035 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
00036 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00037 #include "DataFormats/TrackReco/interface/DeDxData.h"
00038 #include "DataFormats/DetId/interface/DetIdCollection.h"
00039 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00040 #include "RecoTracker/MeasurementDet/interface/MeasurementTracker.h"
00041
00042 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00043 #include "AnalysisDataFormats/SiStripClusterInfo/interface/SiStripClusterInfo.h"
00044 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00045 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00046 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00047 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00048 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00049 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00050 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00051 #include "DataFormats/Common/interface/DetSetVector.h"
00052 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00053 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00054
00055 #include "DataFormats/MuonReco/interface/Muon.h"
00056 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00057
00058 #include "FWCore/ServiceRegistry/interface/Service.h"
00059 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00060 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00061 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
00062
00063 #include "TFile.h"
00064 #include "TCanvas.h"
00065 #include "TObjString.h"
00066 #include "TString.h"
00067 #include "TH1F.h"
00068 #include "TH2F.h"
00069 #include "TProfile.h"
00070 #include "TF1.h"
00071 #include "TROOT.h"
00072 #include "TTree.h"
00073 #include "TChain.h"
00074 #include "TStyle.h"
00075 #include "TLeaf.h"
00076 #include "TGaxis.h"
00077 #include "TGraphAsymmErrors.h"
00078 #include "TLatex.h"
00079 #include "TLegend.h"
00080
00081 using namespace edm;
00082 using namespace reco;
00083 using namespace std;
00084
00085 struct hit{
00086 double x;
00087 double y;
00088 double z;
00089 unsigned int id;
00090 };
00091
00092 class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
00093 public:
00094 explicit SiStripHitEffFromCalibTree(const edm::ParameterSet&);
00095 ~SiStripHitEffFromCalibTree();
00096
00097 private:
00098 virtual void algoBeginJob();
00099 virtual void algoEndJob();
00100 virtual void algoAnalyze(const edm::Event& e, const edm::EventSetup& c);
00101 void SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]);
00102 void makeTKMap();
00103 void makeHotColdMaps();
00104 void makeSQLite();
00105 void totalStatistics();
00106 void makeSummary();
00107 float calcPhi(float x, float y);
00108
00109 edm::Service<TFileService> fs;
00110 SiStripDetInfoFileReader* reader;
00111 edm::FileInPath FileInPath_;
00112 SiStripQuality* quality_;
00113 SiStripBadStrip* getNewObject();
00114
00115 TFile* CalibTreeFile;
00116 TTree* CalibTree;
00117 TString CalibTreeFilename;
00118 float threshold;
00119 unsigned int nModsMin;
00120 unsigned int doSummary;
00121 float _ResXSig;
00122 unsigned int _bunchx;
00123 vector<hit> hits[23];
00124 vector<TH2F*> HotColdMaps;
00125 map< unsigned int, pair< unsigned int, unsigned int> > modCounter[23];
00126 TrackerMap *tkmap;
00127 TrackerMap *tkmapbad;
00128 int layerfound[23];
00129 int layertotal[23];
00130 int goodlayertotal[35];
00131 int goodlayerfound[35];
00132 int alllayertotal[35];
00133 int alllayerfound[35];
00134 map< unsigned int, double > BadModules;
00135 };
00136
00137 SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(const edm::ParameterSet& conf) :
00138 ConditionDBWriter<SiStripBadStrip>(conf),
00139 FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat")
00140 {
00141 CalibTreeFilename = conf.getParameter<std::string>("CalibTreeFilename");
00142 threshold = conf.getParameter<double>("Threshold");
00143 nModsMin = conf.getParameter<int>("nModsMin");
00144 doSummary = conf.getParameter<int>("doSummary");
00145 _ResXSig = conf.getUntrackedParameter<double>("ResXSig",-1);
00146 _bunchx = conf.getUntrackedParameter<int>("BunchCrossing",0);
00147 reader = new SiStripDetInfoFileReader(FileInPath_.fullPath());
00148
00149 quality_ = new SiStripQuality;
00150 }
00151
00152 SiStripHitEffFromCalibTree::~SiStripHitEffFromCalibTree() { }
00153
00154 void SiStripHitEffFromCalibTree::algoBeginJob() {
00155
00156
00157 }
00158
00159 void SiStripHitEffFromCalibTree::algoEndJob() {
00160
00161
00162 }
00163
00164 void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::EventSetup& c) {
00165
00166 edm::ESHandle<TrackerTopology> tTopoHandle;
00167 c.get<IdealGeometryRecord>().get(tTopoHandle);
00168 const TrackerTopology* const tTopo = tTopoHandle.product();
00169
00170
00171 CalibTreeFile = TFile::Open(CalibTreeFilename,"READ");
00172 CalibTreeFile->cd("anEff");
00173 CalibTree = (TTree*)(gDirectory->Get("traj")) ;
00174 TLeaf* BadLf = CalibTree->GetLeaf("ModIsBad");
00175 TLeaf* sistripLf = CalibTree->GetLeaf("SiStripQualBad");
00176 TLeaf* idLf = CalibTree->GetLeaf("Id");
00177 TLeaf* acceptLf = CalibTree->GetLeaf("withinAcceptance");
00178 TLeaf* layerLf = CalibTree->GetLeaf("layer");
00179 TLeaf* nHitsLf = CalibTree->GetLeaf("nHits");
00180 TLeaf* xLf = CalibTree->GetLeaf("TrajGlbX");
00181 TLeaf* yLf = CalibTree->GetLeaf("TrajGlbY");
00182 TLeaf* zLf = CalibTree->GetLeaf("TrajGlbZ");
00183 TLeaf* ResXSigLf = CalibTree->GetLeaf("ResXSig");
00184 TLeaf* BunchLf(0);
00185 for(int l=0; l < 35; l++) {
00186 goodlayertotal[l] = 0;
00187 goodlayerfound[l] = 0;
00188 alllayertotal[l] = 0;
00189 alllayerfound[l] = 0;
00190 }
00191 if(_bunchx != 0) {
00192 BunchLf = CalibTree->GetLeaf("bunchx");
00193 }
00194 int nevents = CalibTree->GetEntries();
00195 cout << "Successfully loaded analyze function with " << nevents << " events!\n";
00196 cout << "A module is bad if efficiency < " << threshold << " and has at least " << nModsMin << " nModsMin." << endl;
00197
00198
00199 for(int j =0; j < nevents; j++) {
00200 CalibTree->GetEvent(j);
00201 unsigned int isBad = (unsigned int)BadLf->GetValue();
00202 unsigned int quality = (unsigned int)sistripLf->GetValue();
00203 unsigned int id = (unsigned int)idLf->GetValue();
00204 unsigned int accept = (unsigned int)acceptLf->GetValue();
00205 unsigned int layer = (unsigned int)layerLf->GetValue();
00206 unsigned int nHits = (unsigned int)nHitsLf->GetValue();
00207 double x = xLf->GetValue();
00208 double y = yLf->GetValue();
00209 double z = zLf->GetValue();
00210 double resxsig = ResXSigLf->GetValue();
00211 bool badquality = false;
00212 if(_bunchx != 0) {
00213 if(_bunchx != BunchLf->GetValue()) continue;
00214 }
00215
00216
00217
00218
00219 if(accept != 1 || nHits < 8) continue;
00220 if(quality == 1) badquality = true;
00221
00222
00223
00224
00225 bool badflag = false;
00226 if(_ResXSig < 0) {
00227 if(isBad == 1) badflag = true;
00228 }
00229 else {
00230 if(isBad == 1 || resxsig > _ResXSig) badflag = true;
00231 }
00232 if(badflag && !badquality) {
00233 hit temphit;
00234 temphit.x = x;
00235 temphit.y = y;
00236 temphit.z = z;
00237 temphit.id = id;
00238 hits[layer].push_back(temphit);
00239 }
00240 pair<unsigned int, unsigned int> newgoodpair (1,1);
00241 pair<unsigned int, unsigned int> newbadpair (1,0);
00242
00243 map< unsigned int, pair< unsigned int, unsigned int> >::iterator it = modCounter[layer].find(id);
00244 if(!badquality) {
00245 if(it == modCounter[layer].end()) {
00246 if(badflag) modCounter[layer][id] = newbadpair;
00247 else modCounter[layer][id] = newgoodpair;
00248 }
00249 else {
00250 ((*it).second.first)++;
00251 if(!badflag) ((*it).second.second)++;
00252 }
00253
00254 if(layer <= 10) {
00255 if(!badflag) goodlayerfound[layer]++;
00256 goodlayertotal[layer]++;
00257 }
00258 else if(layer > 10 && layer < 14) {
00259 if( ((id>>13)&0x3) == 1) {
00260 if(!badflag) goodlayerfound[layer]++;
00261 goodlayertotal[layer]++;
00262 }
00263 else if( ((id>>13)&0x3) == 2) {
00264 if(!badflag) goodlayerfound[layer+3]++;
00265 goodlayertotal[layer+3]++;
00266 }
00267 }
00268 else if(layer > 13 && layer <= 22) {
00269 if( ((id>>18)&0x3) == 1) {
00270 if(!badflag) goodlayerfound[layer+3]++;
00271 goodlayertotal[layer+3]++;
00272 }
00273 else if( ((id>>18)&0x3) == 2) {
00274 if(!badflag) goodlayerfound[layer+12]++;
00275 goodlayertotal[layer+12]++;
00276 }
00277 }
00278 }
00279
00280 if(layer <= 10) {
00281 if(!badflag) alllayerfound[layer]++;
00282 alllayertotal[layer]++;
00283 }
00284 else if(layer > 10 && layer < 14) {
00285 if( ((id>>13)&0x3) == 1) {
00286 if(!badflag) alllayerfound[layer]++;
00287 alllayertotal[layer]++;
00288 }
00289 else if( ((id>>13)&0x3) == 2) {
00290 if(!badflag) alllayerfound[layer+3]++;
00291 alllayertotal[layer+3]++;
00292 }
00293 }
00294 else if(layer > 13 && layer <= 22) {
00295 if( ((id>>18)&0x3) == 1) {
00296 if(!badflag) alllayerfound[layer+3]++;
00297 alllayertotal[layer+3]++;
00298 }
00299 else if( ((id>>18)&0x3) == 2) {
00300 if(!badflag) alllayerfound[layer+12]++;
00301 alllayertotal[layer+12]++;
00302 }
00303 }
00304
00305 }
00306
00307 makeHotColdMaps();
00308 makeTKMap();
00309 makeSQLite();
00310 totalStatistics();
00311 makeSummary();
00312
00314
00316 int NTkBadComponent[4];
00317 int NBadComponent[4][19][4];
00318
00319
00320
00321 std::stringstream ssV[4][19];
00322
00323 for(int i=0;i<4;++i){
00324 NTkBadComponent[i]=0;
00325 for(int j=0;j<19;++j){
00326 ssV[i][j].str("");
00327 for(int k=0;k<4;++k)
00328 NBadComponent[i][j][k]=0;
00329 }
00330 }
00331
00332
00333 std::vector<SiStripQuality::BadComponent> BC = quality_->getBadComponentList();
00334
00335 for (size_t i=0;i<BC.size();++i){
00336
00337
00338
00339
00340
00341 if (BC[i].BadModule)
00342 NTkBadComponent[0]++;
00343 if (BC[i].BadFibers)
00344 NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
00345 if (BC[i].BadApvs)
00346 NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
00347 ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
00348
00349
00350
00351
00352
00353 int component;
00354 SiStripDetId a(BC[i].detid);
00355 if ( a.subdetId() == SiStripDetId::TIB ){
00356
00357
00358
00359
00360 component=tTopo->tibLayer(BC[i].detid);
00361 SetBadComponents(0, component, BC[i], ssV, NBadComponent);
00362
00363 } else if ( a.subdetId() == SiStripDetId::TID ) {
00364
00365
00366
00367
00368 component=tTopo->tidSide(BC[i].detid)==2?tTopo->tidWheel(BC[i].detid):tTopo->tidWheel(BC[i].detid)+3;
00369 SetBadComponents(1, component, BC[i], ssV, NBadComponent);
00370
00371 } else if ( a.subdetId() == SiStripDetId::TOB ) {
00372
00373
00374
00375
00376 component=tTopo->tobLayer(BC[i].detid);
00377 SetBadComponents(2, component, BC[i], ssV, NBadComponent);
00378
00379 } else if ( a.subdetId() == SiStripDetId::TEC ) {
00380
00381
00382
00383
00384 component=tTopo->tecSide(BC[i].detid)==2?tTopo->tecWheel(BC[i].detid):tTopo->tecWheel(BC[i].detid)+9;
00385 SetBadComponents(3, component, BC[i], ssV, NBadComponent);
00386
00387 }
00388 }
00389
00390
00391
00392
00393 float percentage=0;
00394
00395 SiStripQuality::RegistryIterator rbegin = quality_->getRegistryVectorBegin();
00396 SiStripQuality::RegistryIterator rend = quality_->getRegistryVectorEnd();
00397
00398 for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
00399 unsigned int detid=rp->detid;
00400
00401 int subdet=-999; int component=-999;
00402 SiStripDetId a(detid);
00403 if ( a.subdetId() == 3 ){
00404 subdet=0;
00405 component=tTopo->tibLayer(detid);
00406 } else if ( a.subdetId() == 4 ) {
00407 subdet=1;
00408 component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
00409 } else if ( a.subdetId() == 5 ) {
00410 subdet=2;
00411 component=tTopo->tobLayer(detid);
00412 } else if ( a.subdetId() == 6 ) {
00413 subdet=3;
00414 component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
00415 }
00416
00417 SiStripQuality::Range sqrange = SiStripQuality::Range( quality_->getDataVectorBegin()+rp->ibegin , quality_->getDataVectorBegin()+rp->iend );
00418
00419 percentage=0;
00420 for(int it=0;it<sqrange.second-sqrange.first;it++){
00421 unsigned int range=quality_->decode( *(sqrange.first+it) ).range;
00422 NTkBadComponent[3]+=range;
00423 NBadComponent[subdet][0][3]+=range;
00424 NBadComponent[subdet][component][3]+=range;
00425 percentage+=range;
00426 }
00427 if(percentage!=0)
00428 percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
00429 if(percentage>1)
00430 edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage<< std::endl;
00431 }
00432
00433
00434
00435
00436 cout << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event() << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
00437 cout << "\n-----------------\nGlobal Info\n-----------------";
00438 cout << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
00439 cout << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
00440 cout << endl;
00441 cout << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
00442 cout << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
00443 cout << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
00444 cout << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
00445 cout << "\n";
00446
00447 for (int i=1;i<5;++i)
00448 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];
00449 cout << "\n";
00450 for (int i=1;i<4;++i)
00451 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];
00452 for (int i=4;i<7;++i)
00453 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];
00454 cout << "\n";
00455 for (int i=1;i<7;++i)
00456 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];
00457 cout << "\n";
00458 for (int i=1;i<10;++i)
00459 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];
00460 for (int i=10;i<19;++i)
00461 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];
00462 cout << "\n";
00463
00464 cout << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
00465 for (int i=1;i<5;++i)
00466 cout << "\nTIB Layer " << i << " :" << ssV[0][i].str();
00467 cout << "\n";
00468 for (int i=1;i<4;++i)
00469 cout << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
00470 for (int i=4;i<7;++i)
00471 cout << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
00472 cout << "\n";
00473 for (int i=1;i<7;++i)
00474 cout << "\nTOB Layer " << i << " :" << ssV[2][i].str();
00475 cout << "\n";
00476 for (int i=1;i<10;++i)
00477 cout << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
00478 for (int i=10;i<19;++i)
00479 cout << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
00480
00481 }
00482
00483 void SiStripHitEffFromCalibTree::makeHotColdMaps() {
00484 cout << "Entering hot cold map generation!\n";
00485 TStyle* gStyle = new TStyle("gStyle","myStyle");
00486 gStyle->cd();
00487 gStyle->SetPalette(1);
00488 gStyle->SetCanvasColor(kWhite);
00489 gStyle->SetOptStat(0);
00490
00491
00492
00493 TH2F *temph2;
00494 for(Long_t maplayer = 1; maplayer <=22; maplayer++) {
00495
00496 if(maplayer > 0 && maplayer <= 4) {
00497
00498 temph2 = fs->make<TH2F>(Form("%s%i","TIB",(int)(maplayer)),"TIB",100,-1,361,100,-100,100);
00499 temph2->GetXaxis()->SetTitle("Phi");
00500 temph2->GetXaxis()->SetBinLabel(1,TString("360"));
00501 temph2->GetXaxis()->SetBinLabel(50,TString("180"));
00502 temph2->GetXaxis()->SetBinLabel(100,TString("0"));
00503 temph2->GetYaxis()->SetTitle("Global Z");
00504 temph2->SetOption("colz");
00505 HotColdMaps.push_back(temph2);
00506 }
00507 else if(maplayer > 4 && maplayer <= 10) {
00508
00509 temph2 = fs->make<TH2F>(Form("%s%i","TOB",(int)(maplayer-4)),"TOB",100,-1,361,100,-120,120);
00510 temph2->GetXaxis()->SetTitle("Phi");
00511 temph2->GetXaxis()->SetBinLabel(1,TString("360"));
00512 temph2->GetXaxis()->SetBinLabel(50,TString("180"));
00513 temph2->GetXaxis()->SetBinLabel(100,TString("0"));
00514 temph2->GetYaxis()->SetTitle("Global Z");
00515 temph2->SetOption("colz");
00516 HotColdMaps.push_back(temph2);
00517 }
00518 else if(maplayer > 10 && maplayer <= 13) {
00519
00520
00521 temph2 = fs->make<TH2F>(Form("%s%i","TID-",(int)(maplayer-10)),"TID-",100,-100,100,100,-100,100);
00522 temph2->GetXaxis()->SetTitle("Global Y");
00523 temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
00524 temph2->GetXaxis()->SetBinLabel(50,TString("0"));
00525 temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
00526 temph2->GetYaxis()->SetTitle("Global X");
00527 temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
00528 temph2->GetYaxis()->SetBinLabel(50,TString("0"));
00529 temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
00530 temph2->SetOption("colz");
00531 HotColdMaps.push_back(temph2);
00532 temph2 = fs->make<TH2F>(Form("%s%i","TID+",(int)(maplayer-10)),"TID+",100,-100,100,100,-100,100);
00533 temph2->GetXaxis()->SetTitle("Global Y");
00534 temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
00535 temph2->GetXaxis()->SetBinLabel(50,TString("0"));
00536 temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
00537 temph2->GetYaxis()->SetTitle("Global X");
00538 temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
00539 temph2->GetYaxis()->SetBinLabel(50,TString("0"));
00540 temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
00541 temph2->SetOption("colz");
00542 HotColdMaps.push_back(temph2);
00543 }
00544 else if(maplayer > 13) {
00545
00546
00547 temph2 = fs->make<TH2F>(Form("%s%i","TEC-",(int)(maplayer-13)),"TEC-",100,-120,120,100,-120,120);
00548 temph2->GetXaxis()->SetTitle("Global Y");
00549 temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
00550 temph2->GetXaxis()->SetBinLabel(50,TString("0"));
00551 temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
00552 temph2->GetYaxis()->SetTitle("Global X");
00553 temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
00554 temph2->GetYaxis()->SetBinLabel(50,TString("0"));
00555 temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
00556 temph2->SetOption("colz");
00557 HotColdMaps.push_back(temph2);
00558 temph2 = fs->make<TH2F>(Form("%s%i","TEC+",(int)(maplayer-13)),"TEC+",100,-120,120,100,-120,120);
00559 temph2->GetXaxis()->SetTitle("Global Y");
00560 temph2->GetXaxis()->SetBinLabel(1,TString("+Y"));
00561 temph2->GetXaxis()->SetBinLabel(50,TString("0"));
00562 temph2->GetXaxis()->SetBinLabel(100,TString("-Y"));
00563 temph2->GetYaxis()->SetTitle("Global X");
00564 temph2->GetYaxis()->SetBinLabel(1,TString("-X"));
00565 temph2->GetYaxis()->SetBinLabel(50,TString("0"));
00566 temph2->GetYaxis()->SetBinLabel(100,TString("+X"));
00567 temph2->SetOption("colz");
00568 HotColdMaps.push_back(temph2);
00569 }
00570 }
00571 for(Long_t mylayer = 1; mylayer <= 22; mylayer++) {
00572
00573
00574
00575 vector<hit>::const_iterator iter;
00576 for(iter = hits[mylayer].begin(); iter != hits[mylayer].end(); iter++) {
00577
00578
00579
00580 if(mylayer > 0 && mylayer <= 4) {
00581
00582 float phi = calcPhi(iter->x, iter->y);
00583 HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
00584 }
00585 else if(mylayer > 4 && mylayer <= 10) {
00586
00587 float phi = calcPhi(iter->x,iter->y);
00588 HotColdMaps[mylayer - 1]->Fill(360.-phi,iter->z,1.);
00589 }
00590 else if(mylayer > 10 && mylayer <= 13) {
00591
00592
00593 int side = (((iter->id)>>13) & 0x3);
00594 if(side == 1) HotColdMaps[(mylayer - 1) + (mylayer - 11)]->Fill(-iter->y,iter->x,1.);
00595 else if(side == 2) HotColdMaps[(mylayer - 1) + (mylayer - 10)]->Fill(-iter->y,iter->x,1.);
00596
00597
00598 }
00599 else if(mylayer > 13) {
00600
00601
00602 int side = (((iter->id)>>18) & 0x3);
00603 if(side == 1) HotColdMaps[(mylayer + 2) + (mylayer - 14)]->Fill(-iter->y,iter->x,1.);
00604 else if(side == 2) HotColdMaps[(mylayer + 2) + (mylayer - 13)]->Fill(-iter->y,iter->x,1.);
00605
00606
00607 }
00608 }
00609 }
00610 cout << "Finished HotCold Map Generation\n";
00611 }
00612
00613 void SiStripHitEffFromCalibTree::makeTKMap() {
00614 cout << "Entering TKMap generation!\n";
00615 tkmap = new TrackerMap(" Detector Inefficiency ");
00616 tkmapbad = new TrackerMap(" Inefficient Modules ");
00617 for(Long_t i = 1; i <= 22; i++) {
00618 layertotal[i] = 0;
00619 layerfound[i] = 0;
00620
00621
00622 map<unsigned int, pair<unsigned int, unsigned int> >::const_iterator ih;
00623 for( ih = modCounter[i].begin(); ih != modCounter[i].end(); ih++) {
00624
00625
00626 double myeff = (double)(((*ih).second).second)/(((*ih).second).first);
00627 if ( ((((*ih).second).first) >= nModsMin) && (myeff < threshold) ) {
00628
00629 BadModules[(*ih).first] = myeff;
00630 tkmapbad->fillc((*ih).first,255,0,0);
00631 cout << "Layer " << i << " module " << (*ih).first << " efficiency " << myeff << " " << (((*ih).second).second) << "/" << (((*ih).second).first) << endl;
00632 }
00633 else {
00634
00635 tkmapbad->fillc((*ih).first,255,255,255);
00636 }
00637 if((((*ih).second).first) < 100 ) {
00638 cout << "Module " << (*ih).first << " layer " << i << " is under occupancy at " << (((*ih).second).first) << endl;
00639 }
00640
00641
00642
00643
00644
00645
00646 tkmap->fill((*ih).first,1.-myeff);
00647
00648 layertotal[i] += int(((*ih).second).first);
00649 layerfound[i] += int(((*ih).second).second);
00650 }
00651 }
00652 tkmap->save(true, 0, 0, "SiStripHitEffTKMap.png");
00653 tkmapbad->save(true, 0, 0, "SiStripHitEffTKMapBad.png");
00654 cout << "Finished TKMap Generation\n";
00655 }
00656
00657 void SiStripHitEffFromCalibTree::makeSQLite() {
00658
00659 cout << "Entering SQLite file generation!\n";
00660 std::vector<unsigned int> BadStripList;
00661 unsigned short NStrips;
00662 unsigned int id1;
00663 SiStripQuality* pQuality = new SiStripQuality;
00664
00665
00666
00667 map< unsigned int, double >::const_iterator it;
00668 for(it = BadModules.begin(); it != BadModules.end(); it++) {
00669
00670
00671 NStrips=reader->getNumberOfApvsAndStripLength((*it).first).first*128;
00672 cout << "Number of strips module " << (*it).first << " is " << NStrips << endl;
00673 BadStripList.push_back(pQuality->encode(0,NStrips,0));
00674
00675 id1=(unsigned int)(*it).first;
00676 cout << "ID1 shoudl match list of modules above " << id1 << endl;
00677 quality_->compact(id1,BadStripList);
00678 SiStripQuality::Range range(BadStripList.begin(),BadStripList.end());
00679 quality_->put(id1,range);
00680 BadStripList.clear();
00681 }
00682
00683 quality_->fillBadComponents();
00684 }
00685
00686 void SiStripHitEffFromCalibTree::totalStatistics() {
00687
00688 int totalfound = 0;
00689 int totaltotal = 0;
00690 double layereff;
00691 for(Long_t i=1; i<=22; i++) {
00692 layereff = double(layerfound[i])/double(layertotal[i]);
00693 cout << "Layer " << i << " has total efficiency " << layereff << " " << layerfound[i] << "/" << layertotal[i] << endl;
00694 totalfound += layerfound[i];
00695 totaltotal += layertotal[i];
00696 }
00697 cout << "The total efficiency is " << double(totalfound)/double(totaltotal) << endl;
00698 }
00699
00700 void SiStripHitEffFromCalibTree::makeSummary() {
00701
00702
00703 int nLayers = 34;
00704
00705 TH1F *found = fs->make<TH1F>("found","found",nLayers+1,0,nLayers+1);
00706 TH1F *all = fs->make<TH1F>("all","all",nLayers+1,0,nLayers+1);
00707 TH1F *found2 = fs->make<TH1F>("found2","found2",nLayers+1,0,nLayers+1);
00708 TH1F *all2 = fs->make<TH1F>("all2","all2",nLayers+1,0,nLayers+1);
00709
00710 found->SetBinContent(0,-1);
00711 all->SetBinContent(0,1);
00712
00713 TCanvas *c7 =new TCanvas("c7"," test ",10,10,800,600);
00714 c7->SetFillColor(0);
00715 c7->SetGrid();
00716
00717 for (Long_t i=1; i< nLayers+1; ++i) {
00718 if (i==10) i++;
00719 if (i==25) i++;
00720 if (i==34) break;
00721
00722 cout << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] << " B = " << goodlayertotal[i] << endl;
00723 if (goodlayertotal[i] > 5) {
00724 found->SetBinContent(i,goodlayerfound[i]);
00725 all->SetBinContent(i,goodlayertotal[i]);
00726 } else {
00727 found->SetBinContent(i,0);
00728 all->SetBinContent(i,10);
00729 }
00730
00731 cout << "Filling all modules layer " << i << ": S = " << alllayerfound[i] << " B = " << alllayertotal[i] << endl;
00732 if (alllayertotal[i] > 5) {
00733 found2->SetBinContent(i,alllayerfound[i]);
00734 all2->SetBinContent(i,alllayertotal[i]);
00735 } else {
00736 found2->SetBinContent(i,0);
00737 all2->SetBinContent(i,10);
00738 }
00739
00740 }
00741
00742 found->Sumw2();
00743 all->Sumw2();
00744
00745 found2->Sumw2();
00746 all2->Sumw2();
00747
00748 TGraphAsymmErrors *gr = new TGraphAsymmErrors(nLayers+1);
00749 gr->BayesDivide(found,all);
00750
00751 TGraphAsymmErrors *gr2 = new TGraphAsymmErrors(nLayers+1);
00752 gr2->BayesDivide(found2,all2);
00753
00754 for(int j = 0; j<nLayers+1; j++){
00755 gr->SetPointError(j, 0., 0., gr->GetErrorYlow(j),gr->GetErrorYhigh(j) );
00756 gr2->SetPointError(j, 0., 0., gr2->GetErrorYlow(j),gr2->GetErrorYhigh(j) );
00757 }
00758
00759 gr->GetXaxis()->SetLimits(0,nLayers);
00760 gr->SetMarkerColor(2);
00761 gr->SetMarkerSize(1.2);
00762 gr->SetLineColor(2);
00763 gr->SetLineWidth(4);
00764 gr->SetMarkerStyle(20);
00765 gr->SetMinimum(0.90);
00766 gr->SetMaximum(1.001);
00767 gr->GetYaxis()->SetTitle("Efficiency");
00768
00769 gr2->GetXaxis()->SetLimits(0,nLayers);
00770 gr2->SetMarkerColor(1);
00771 gr2->SetMarkerSize(1.2);
00772 gr2->SetLineColor(1);
00773 gr2->SetLineWidth(4);
00774 gr2->SetMarkerStyle(21);
00775 gr2->SetMinimum(0.90);
00776 gr2->SetMaximum(1.001);
00777 gr2->GetYaxis()->SetTitle("Efficiency");
00778
00779
00780 for ( Long_t k=1; k<nLayers+1; k++) {
00781 if (k==10) k++;
00782 if (k==25) k++;
00783 if (k==34) break;
00784 TString label;
00785 if (k<5) {
00786 label = TString("TIB ") + k;
00787 } else if (k>4&&k<11) {
00788 label = TString("TOB ")+(k-4);
00789 } else if (k>10&&k<14) {
00790 label = TString("TID- ")+(k-10);
00791 } else if (k>13&&k<17) {
00792 label = TString("TID+ ")+(k-13);
00793 } else if (k>16&&k<26) {
00794 label = TString("TEC- ")+(k-16);
00795 } else if (k>25) {
00796 label = TString("TEC+ ")+(k-25);
00797 }
00798 gr->GetXaxis()->SetBinLabel(((k+1)*100)/(nLayers)-2,label);
00799 gr2->GetXaxis()->SetBinLabel(((k+1)*100)/(nLayers)-2,label);
00800 }
00801
00802 gr->Draw("AP");
00803 gr->GetXaxis()->SetNdivisions(36);
00804
00805 c7->cd();
00806 TPad *overlay = new TPad("overlay","",0,0,1,1);
00807 overlay->SetFillStyle(4000);
00808 overlay->SetFillColor(0);
00809 overlay->SetFrameFillStyle(4000);
00810 overlay->Draw("same");
00811 overlay->cd();
00812 gr2->Draw("AP");
00813
00814 TLegend *leg = new TLegend(0.70,0.20,0.92,0.39);
00815 leg->AddEntry(gr,"Good Modules","p");
00816 leg->AddEntry(gr2,"All Modules","p");
00817 leg->SetTextSize(0.020);
00818 leg->SetFillColor(0);
00819 leg->Draw("same");
00820
00821 c7->SaveAs("Summary.png");
00822 }
00823
00824 SiStripBadStrip* SiStripHitEffFromCalibTree::getNewObject() {
00825
00826
00827 SiStripBadStrip* obj=new SiStripBadStrip();
00828
00829 SiStripBadStrip::RegistryIterator rIter=quality_->getRegistryVectorBegin();
00830 SiStripBadStrip::RegistryIterator rIterEnd=quality_->getRegistryVectorEnd();
00831
00832 for(;rIter!=rIterEnd;++rIter){
00833 SiStripBadStrip::Range range(quality_->getDataVectorBegin()+rIter->ibegin,quality_->getDataVectorBegin()+rIter->iend);
00834 if ( ! obj->put(rIter->detid,range) )
00835 edm::LogError("SiStripHitEffFromCalibTree")<<"[SiStripHitEffFromCalibTree::getNewObject] detid already exists"<<std::endl;
00836 }
00837
00838 return obj;
00839 }
00840
00841 float SiStripHitEffFromCalibTree::calcPhi(float x, float y) {
00842 float phi = 0;
00843 float Pi = 3.14159;
00844 if((x>=0)&&(y>=0)) phi = atan(y/x);
00845 else if((x>=0)&&(y<=0)) phi = atan(y/x) + 2*Pi;
00846 else if((x<=0)&&(y>=0)) phi = atan(y/x) + Pi;
00847 else phi = atan(y/x) + Pi;
00848 phi = phi*180.0/Pi;
00849
00850 return phi;
00851 }
00852
00853 void SiStripHitEffFromCalibTree::SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC, std::stringstream ssV[4][19], int NBadComponent[4][19][4]){
00854
00855 int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
00856
00857 ssV[i][component] << "\n\t\t "
00858 << BC.detid
00859 << " \t " << BC.BadModule << " \t "
00860 << ( (BC.BadFibers)&0x1 ) << " ";
00861 if (napv==4)
00862 ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
00863
00864 if (napv==6)
00865 ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
00866 << ( (BC.BadFibers>>2)&0x1 );
00867 ssV[i][component] << " \t "
00868 << ( (BC.BadApvs)&0x1 ) << " "
00869 << ( (BC.BadApvs>>1)&0x1 ) << " ";
00870 if (napv==4)
00871 ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
00872 << ( (BC.BadApvs>>3)&0x1 );
00873 if (napv==6)
00874 ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
00875 << ( (BC.BadApvs>>3)&0x1 ) << " "
00876 << ( (BC.BadApvs>>4)&0x1 ) << " "
00877 << ( (BC.BadApvs>>5)&0x1 ) << " ";
00878
00879 if (BC.BadApvs){
00880 NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
00881 ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
00882 NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
00883 ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
00884 }
00885 if (BC.BadFibers){
00886 NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00887 NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00888 }
00889 if (BC.BadModule){
00890 NBadComponent[i][0][0]++;
00891 NBadComponent[i][component][0]++;
00892 }
00893 }
00894
00895 DEFINE_FWK_MODULE(SiStripHitEffFromCalibTree);