CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorSummary/plugins/SiStripPlotGain.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorSummary/plugins/SiStripPlotGain.h"
00002 
00003 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00004 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00005 
00006 
00007 
00008 SiStripPlotGain::SiStripPlotGain(const edm::ParameterSet& iConfig):
00009   cacheID(0xFFFFFFFF)
00010 {
00011   //now do what ever initialization is needed
00012   if(!edm::Service<SiStripDetInfoFileReader>().isAvailable()){
00013     edm::LogError("TkLayerMap") << 
00014       "\n------------------------------------------"
00015       "\nUnAvailable Service SiStripDetInfoFileReader: please insert in the configuration file an instance like"
00016       "\n\tprocess.SiStripDetInfoFileReader = cms.Service(\"SiStripDetInfoFileReader\")"
00017       "\n------------------------------------------";
00018   }
00019  
00020   fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00021   file = new TFile("correlTest.root","RECREATE");
00022   tkmap = new TrackerMap();
00023 }
00024 
00025 
00026 SiStripPlotGain::~SiStripPlotGain()
00027 {}
00028 
00029 //
00030 
00031 void
00032 SiStripPlotGain::beginRun(const edm::Run& run, const edm::EventSetup& es){
00033 
00034   if(getCache(es)==cacheID )
00035     return;
00036   cacheID=getCache(es);  
00037   
00038   edm::LogInfo("") << "[SiStripPlotGain::beginRun] cacheID " << cacheID << std::endl; 
00039   
00040   es.get<SiStripApvGainRcd>().get(Handle_);
00041   DoAnalysis(es, *Handle_.product());
00042 
00043 
00044 }
00045 
00046 void 
00047 SiStripPlotGain::DoAnalysis(const edm::EventSetup& es, const SiStripApvGain& gain){
00048 
00049   edm::LogInfo("") << "[Doanalysis]";
00050 
00051   //Retrieve tracker topology from geometry
00052   edm::ESHandle<TrackerTopology> tTopoHandle;
00053   es.get<IdealGeometryRecord>().get(tTopoHandle);
00054   const TrackerTopology* const tTopo = tTopoHandle.product();
00055 
00056   std::vector<TH1F *>histos;
00057 
00058   SiStripApvGain::RegistryPointers p=gain.getRegistryPointers();
00059   SiStripApvGain::RegistryConstIterator iter, iterE;
00060   iter=p.detid_begin;
00061   iterE=p.detid_end;
00062 
00063   float value;
00064 
00065   //Divide result by d
00066   for(;iter!=iterE;++iter){
00067     getHistos(*iter,tTopo,histos);
00068     SiStripApvGain::Range range=SiStripApvGain::Range(p.getFirstElement(iter),p.getLastElement(iter));
00069 
00070     edm::LogInfo("") << "[Doanalysis] detid " << *iter << " range " << range.second-range.first;
00071     size_t apv=0, apvE= (range.second-range.first);
00072     for (;apv<apvE;apv+=2){       
00073       value=gain.getApvGain(apv,range);
00074       tkmap->fill(*iter,value);
00075       for(size_t i=0;i<histos.size();++i)
00076         histos[i]->Fill(value);
00077     }
00078     
00079   }
00080 }
00081 
00082 
00083 void
00084 SiStripPlotGain::getHistos(const uint32_t& detid, const TrackerTopology* tTopo, std::vector<TH1F*>& histos){
00085   
00086   histos.clear();
00087   
00088   int subdet=-999; int component=-999;
00089   SiStripDetId a(detid);
00090   if ( a.subdetId() == 3 ){
00091     subdet=0;
00092     component=tTopo->tibLayer(detid);
00093   } else if ( a.subdetId() == 4 ) {
00094     subdet=1;
00095     component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
00096   } else if ( a.subdetId() == 5 ) {
00097     subdet=2;
00098     component=tTopo->tobLayer(detid);
00099   } else if ( a.subdetId() == 6 ) {
00100     subdet=3;
00101     component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
00102   } 
00103   
00104   int index=100+subdet*100+component;
00105 
00106 
00107   histos.push_back(getHisto(subdet+1));
00108   histos.push_back(getHisto(index));
00109   
00110 }
00111 
00112 TH1F*
00113 SiStripPlotGain::getHisto(const long unsigned int& index){
00114   if(vTH1.size()<index+1)
00115     vTH1.resize(index+1,0);
00116   
00117   if(vTH1[index]==0){
00118     char name[128];
00119     sprintf(name,"%lu",index);
00120     edm::LogInfo("")<<"[getHisto] creating index " << index << std::endl;
00121     vTH1[index]=new TH1F(name,name,150,0.,5.);
00122   }
00123   
00124   return vTH1[index];
00125 }
00126 
00127 void 
00128 SiStripPlotGain::endJob() {
00129   for(size_t i=0;i<vTH1.size();i++)
00130     if(vTH1[i]!=0)
00131       vTH1[i]->Write();
00132 
00133   file->Write();
00134   file->Close();
00135 
00136   tkmap->save(false,0,0,"testTkMap.png");
00137 
00138 }
00139