Go to the documentation of this file.00001 #include "DQM/SiStripMonitorSummary/plugins/SiStripCorrelateNoise.h"
00002
00003 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00004 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00005 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00006 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00007 #include "FWCore/Framework/interface/Run.h"
00008 #include "TCanvas.h"
00009
00010
00011 SiStripCorrelateNoise::SiStripCorrelateNoise(const edm::ParameterSet& iConfig):
00012 refNoise(0),oldGain(0),newGain(0),cacheID_noise(0xFFFFFFFF),cacheID_gain(0xFFFFFFFF)
00013 {
00014
00015 if(!edm::Service<SiStripDetInfoFileReader>().isAvailable()){
00016 edm::LogError("TkLayerMap") <<
00017 "\n------------------------------------------"
00018 "\nUnAvailable Service SiStripDetInfoFileReader: please insert in the configuration file an instance like"
00019 "\n\tprocess.SiStripDetInfoFileReader = cms.Service(\"SiStripDetInfoFileReader\")"
00020 "\n------------------------------------------";
00021 }
00022
00023 fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00024 file = new TFile("correlTest.root","RECREATE");
00025
00026 file->cd();
00027 tkmap = new TrackerMap();
00028 }
00029
00030
00031 SiStripCorrelateNoise::~SiStripCorrelateNoise()
00032 {}
00033
00034
00035
00036 void
00037 SiStripCorrelateNoise::beginRun(const edm::Run& run, const edm::EventSetup& es){
00038
00039 if(getNoiseCache(es)==cacheID_noise )
00040 return;
00041
00042
00043 edm::LogInfo("") << "[SiStripCorrelateNoise::beginRun] cacheID_noise " << cacheID_noise << std::endl;
00044
00045 es.get<SiStripNoisesRcd>().get(noiseHandle_);
00046 SiStripNoises * aNoise= new SiStripNoises(*noiseHandle_.product());
00047
00048
00049
00050 checkGainCache(es);
00051
00052 if(cacheID_noise!=0xFFFFFFFF){
00053 char dir[128];
00054 theRun=run.run();
00055 sprintf(dir,"Run_%d",theRun);
00056 file->cd("");
00057 file->mkdir(dir);
00058 file->cd(dir);
00059 DoAnalysis(*noiseHandle_.product(),*refNoise);
00060 DoPlots();
00061 }
00062
00063 cacheID_noise=getNoiseCache(es);
00064 if(refNoise!=0)
00065 delete refNoise;
00066 refNoise=aNoise;
00067 }
00068
00069 void
00070 SiStripCorrelateNoise::checkGainCache(const edm::EventSetup& es){
00071 equalGain=true;
00072 if(getGainCache(es)!=cacheID_gain ){
00073 es.get<SiStripApvGainRcd>().get(gainHandle_);
00074 if(oldGain!=0)
00075 delete oldGain;
00076
00077 oldGain = newGain;
00078 newGain = new SiStripApvGain(*gainHandle_.product());
00079
00080 if(cacheID_gain!=0xFFFFFFFF)
00081 equalGain=false;
00082 cacheID_gain=getGainCache(es);
00083 edm::LogInfo("") << "[SiStripCorrelateNoise::checkGainCache] cacheID_gain " << cacheID_gain << std::endl;
00084 }
00085 }
00086
00087 void
00088 SiStripCorrelateNoise::DoPlots(){
00089 TCanvas *C=new TCanvas();
00090 C->Divide(2,2);
00091
00092 char outName[128];
00093 sprintf(outName,"Run_%d.png",theRun);
00094 for(size_t i=0;i<vTH1.size();i++)
00095 if(vTH1[i]!=0){
00096 if(i%100==0){
00097 C->cd(i/100);
00098 vTH1[i]->SetLineColor(i/100);
00099 vTH1[i]->Draw();
00100 C->cd(i/100)->SetLogy();
00101 }
00102 vTH1[i]->Write();
00103 }
00104
00105 C->Print(outName);
00106 delete C;
00107
00108 vTH1.clear();
00109 file->cd("");
00110
00111 char dir[128];
00112 sprintf(dir,"Run_%d_TkMap.png",theRun);
00113 tkmap->save(false,0,5,dir);
00114 delete tkmap;
00115 tkmap = new TrackerMap();
00116 }
00117
00118 void
00119 SiStripCorrelateNoise::DoAnalysis(SiStripNoises Noise, SiStripNoises& refNoise){
00120 typedef std::vector<SiStripNoises::ratioData> collection;
00121 collection divNoise=Noise/refNoise;
00122
00123 edm::LogInfo("") << "[Doanalysis]";
00124
00125 std::vector<TH1F *>histos;
00126
00127 collection::const_iterator iter=divNoise.begin();
00128 collection::const_iterator iterE=divNoise.end();
00129
00130 float value;
00131 float gainRatio=1.;
00132
00133 for(;iter!=iterE;++iter){
00134 getHistos(iter->detid,histos);
00135
00136 size_t strip=0, stripE= iter->values.size();
00137 size_t apvNb=7;
00138
00139 for (;strip<stripE;++strip){
00140 if(!equalGain && strip/128!=apvNb){
00141 apvNb=strip/128;
00142 if(apvNb<6)
00143 gainRatio=getGainRatio(iter->detid,apvNb);
00144 else
00145 edm::LogInfo("") << "[Doanalysis] detid " << iter->detid << " strip " << strip << " apvNb " << apvNb;
00146 }
00147
00148 value=iter->values[strip]*gainRatio;
00149 tkmap->fill(iter->detid,value);
00150 for(size_t i=0;i<histos.size();++i)
00151 histos[i]->Fill(value);
00152 }
00153 }
00154 }
00155
00156 float
00157 SiStripCorrelateNoise::getGainRatio(const uint32_t& detid, const uint16_t& apv){
00158
00159 SiStripApvGain::Range oldRange=oldGain->getRange(detid);
00160 SiStripApvGain::Range newRange=newGain->getRange(detid);
00161
00162 if(oldRange.first==oldRange.second ||
00163 newRange.first==newRange.second)
00164 return 1.;
00165
00166 return oldGain->getApvGain(apv,oldRange)/newGain->getApvGain(apv,newRange);
00167
00168 }
00169
00170 float
00171 SiStripCorrelateNoise::getMeanNoise(const SiStripNoises::Range& noiseRange,const uint32_t& firstStrip, const uint32_t& range){
00172
00173 float mean=0;
00174 for (size_t istrip=firstStrip;istrip<firstStrip+range;istrip++){
00175 mean+=noiseHandle_->getNoise(istrip,noiseRange);
00176 }
00177 return mean/(1.*range);
00178 }
00179
00180 void
00181 SiStripCorrelateNoise::getHistos(const uint32_t& detid,std::vector<TH1F*>& histos){
00182
00183 histos.clear();
00184
00185 int subdet=-999; int component=-999;
00186 SiStripDetId a(detid);
00187 if ( a.subdetId() == 3 ){
00188 subdet=0;
00189 component=TIBDetId(detid).layer();
00190 } else if ( a.subdetId() == 4 ) {
00191 subdet=1;
00192 component=TIDDetId(detid).side()==2?TIDDetId(detid).wheel():TIDDetId(detid).wheel()+3;
00193 } else if ( a.subdetId() == 5 ) {
00194 subdet=2;
00195 component=TOBDetId(detid).layer();
00196 } else if ( a.subdetId() == 6 ) {
00197 subdet=3;
00198 component=TECDetId(detid).side()==2?TECDetId(detid).wheel():TECDetId(detid).wheel()+9;
00199 }
00200
00201 int index=100+subdet*100+component;
00202
00203
00204 histos.push_back(getHisto(100+100*subdet));
00205 histos.push_back(getHisto(index));
00206
00207 }
00208
00209 TH1F*
00210 SiStripCorrelateNoise::getHisto(const long unsigned int& index){
00211 if(vTH1.size()<index+1)
00212 vTH1.resize(index+1,0);
00213
00214 if(vTH1[index]==0){
00215 char name[128];
00216 std::string SubD;
00217 if(index<200)
00218 SubD="TIB";
00219 else if(index<300)
00220 SubD="TID";
00221 else if(index<400)
00222 SubD="TOB";
00223 else
00224 SubD="TEC";
00225 sprintf(name,"%d_%lu__%s",theRun,index,SubD.c_str());
00226 edm::LogInfo("")<<"[getHisto] creating index " << index << std::endl;
00227 vTH1[index]=new TH1F(name,name,200,-0.5,10.5);
00228 }
00229
00230 return vTH1[index];
00231 }
00232
00233 void
00234 SiStripCorrelateNoise::endJob() {
00235 file->Write();
00236 file->Close();
00237
00238
00239 }
00240