CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripCorrelateNoise.cc
Go to the documentation of this file.
2 
6 #include "TCanvas.h"
7 
8 
10  refNoise(0),oldGain(0),newGain(0),cacheID_noise(0xFFFFFFFF),cacheID_gain(0xFFFFFFFF)
11 {
12  //now do what ever initialization is needed
13  if(!edm::Service<SiStripDetInfoFileReader>().isAvailable()){
14  edm::LogError("TkLayerMap") <<
15  "\n------------------------------------------"
16  "\nUnAvailable Service SiStripDetInfoFileReader: please insert in the configuration file an instance like"
17  "\n\tprocess.SiStripDetInfoFileReader = cms.Service(\"SiStripDetInfoFileReader\")"
18  "\n------------------------------------------";
19  }
20 
22  file = new TFile("correlTest.root","RECREATE");
23 
24  file->cd();
25  tkmap = new TrackerMap();
26 }
27 
28 
30 {}
31 
32 //
33 
34 void
36 
38  return;
39 
40  edm::LogInfo("") << "[SiStripCorrelateNoise::beginRun] cacheID_noise " << cacheID_noise << std::endl;
41 
44 
45  //Check if gain is the same from one noise iov to the other, otherwise cache the new gain (and the old one) to rescale
46 
47  checkGainCache(es);
48 
49  if(cacheID_noise!=0xFFFFFFFF){
50  char dir[128];
51  theRun=run.run();
52  sprintf(dir,"Run_%d",theRun);
53  file->cd("");
54  file->mkdir(dir);
55  file->cd(dir);
57  DoPlots();
58  }
59 
61  if(refNoise!=0)
62  delete refNoise;
63  refNoise=aNoise;
64 }
65 
66 void
68  equalGain=true;
69  if(getGainCache(es)!=cacheID_gain ){
71  if(oldGain!=0)
72  delete oldGain;
73 
74  oldGain = newGain;
76 
77  if(cacheID_gain!=0xFFFFFFFF)
78  equalGain=false;
80  edm::LogInfo("") << "[SiStripCorrelateNoise::checkGainCache] cacheID_gain " << cacheID_gain << std::endl;
81  }
82 }
83 
84 void
86  TCanvas *C=new TCanvas();
87  C->Divide(2,2);
88 
89  char outName[128];
90  sprintf(outName,"Run_%d.png",theRun);
91  for(size_t i=0;i<vTH1.size();i++)
92  if(vTH1[i]!=0){
93  if(i%100==0){
94  C->cd(i/100);
95  vTH1[i]->SetLineColor(i/100);
96  vTH1[i]->Draw();
97  C->cd(i/100)->SetLogy();
98  }
99  vTH1[i]->Write();
100  }
101 
102  C->Print(outName);
103  delete C;
104 
105  vTH1.clear();
106  file->cd("");
107 
108  char dir[128];
109  sprintf(dir,"Run_%d_TkMap.png",theRun);
110  tkmap->save(false,0,5,dir);
111  delete tkmap;
112  tkmap = new TrackerMap();
113 }
114 
115 void
117  SiStripNoises Noise = _Noise;
118  typedef std::vector<SiStripNoises::ratioData> collection;
119  collection divNoise=Noise/refNoise;
120 
121  edm::LogInfo("") << "[Doanalysis]";
122 
123  //Retrieve tracker topology from geometry
124  edm::ESHandle<TrackerTopology> tTopoHandle;
125  es.get<TrackerTopologyRcd>().get(tTopoHandle);
126  const TrackerTopology* const tTopo = tTopoHandle.product();
127 
128  std::vector<TH1F *>histos;
129 
130  collection::const_iterator iter=divNoise.begin();
131  collection::const_iterator iterE=divNoise.end();
132 
133  float value;
134  float gainRatio=1.;
135  //Divide result by d
136  for(;iter!=iterE;++iter){
137  getHistos(iter->detid, tTopo, histos);
138 
139  size_t strip=0, stripE= iter->values.size();
140  size_t apvNb=7;
141 
142  for (;strip<stripE;++strip){
143  if(!equalGain && strip/128!=apvNb){
144  apvNb=strip/128;
145  if(apvNb<6)
146  gainRatio=getGainRatio(iter->detid,apvNb);
147  else
148  edm::LogInfo("") << "[Doanalysis] detid " << iter->detid << " strip " << strip << " apvNb " << apvNb;
149  }
150  //edm::LogInfo("") << "[Doanalysis] detid " << iter->detid << " strip " << strip << " value " << iter->values[strip];
151  value=iter->values[strip]*gainRatio;
152  tkmap->fill(iter->detid,value);
153  for(size_t i=0;i<histos.size();++i)
154  histos[i]->Fill(value);
155  }
156  }
157 }
158 
159 float
160 SiStripCorrelateNoise::getGainRatio(const uint32_t& detid, const uint16_t& apv){
161 
162  SiStripApvGain::Range oldRange=oldGain->getRange(detid);
163  SiStripApvGain::Range newRange=newGain->getRange(detid);
164 
165  if(oldRange.first==oldRange.second ||
166  newRange.first==newRange.second)
167  return 1.;
168 
169  return oldGain->getApvGain(apv,oldRange)/newGain->getApvGain(apv,newRange);
170 
171 }
172 
173 float
174 SiStripCorrelateNoise::getMeanNoise(const SiStripNoises::Range& noiseRange,const uint32_t& firstStrip, const uint32_t& range){
175 
176  float mean=0;
177  for (size_t istrip=firstStrip;istrip<firstStrip+range;istrip++){
178  mean+=noiseHandle_->getNoise(istrip,noiseRange);
179  }
180  return mean/(1.*range);
181 }
182 
183 void
184 SiStripCorrelateNoise::getHistos(const uint32_t& detid, const TrackerTopology* tTopo, std::vector<TH1F*>& histos){
185 
186  histos.clear();
187 
188  int subdet=-999; int component=-999;
189  SiStripDetId a(detid);
190  if ( a.subdetId() == 3 ){
191  subdet=0;
192  component=tTopo->tibLayer(detid);
193  } else if ( a.subdetId() == 4 ) {
194  subdet=1;
195  component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
196  } else if ( a.subdetId() == 5 ) {
197  subdet=2;
198  component=tTopo->tobLayer(detid);
199  } else if ( a.subdetId() == 6 ) {
200  subdet=3;
201  component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
202  }
203 
204  int index=100+subdet*100+component;
205 
206 
207  histos.push_back(getHisto(100+100*subdet));
208  histos.push_back(getHisto(index));
209 
210 }
211 
212 TH1F*
213 SiStripCorrelateNoise::getHisto(const long unsigned int& index){
214  if(vTH1.size()<index+1)
215  vTH1.resize(index+1,0);
216 
217  if(vTH1[index]==0){
218  char name[128];
219  std::string SubD;
220  if(index<200)
221  SubD="TIB";
222  else if(index<300)
223  SubD="TID";
224  else if(index<400)
225  SubD="TOB";
226  else
227  SubD="TEC";
228  sprintf(name,"%d_%lu__%s",theRun,index,SubD.c_str());
229  edm::LogInfo("")<<"[getHisto] creating index " << index << std::endl;
230  vTH1[index]=new TH1F(name,name,200,-0.5,10.5);
231  }
232 
233  return vTH1[index];
234 }
235 
236 void
238  file->Write();
239  file->Close();
240 
241 
242 }
243 
TH1F * getHisto(const long unsigned int &index)
int i
Definition: DBlmapReader.cc:9
unsigned long long cacheID_noise
void getHistos(const uint32_t &detid, const TrackerTopology *tTopo, std::vector< TH1F * > &histos)
unsigned int tibLayer(const DetId &id) const
RunNumber_t run() const
Definition: RunBase.h:42
std::vector< TH1F * > vTH1
static float getApvGain(uint16_t apv, const Range &range)
float getMeanNoise(const SiStripNoises::Range &noiseRange, const uint32_t &first, const uint32_t &range)
unsigned int tidWheel(const DetId &id) const
void DoAnalysis(const edm::EventSetup &, const SiStripNoises &, SiStripNoises &)
virtual void beginRun(const edm::Run &run, const edm::EventSetup &es)
unsigned int tidSide(const DetId &id) const
edm::ESHandle< SiStripApvGain > gainHandle_
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
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
std::pair< ContainerIterator, ContainerIterator > Range
float getGainRatio(const uint32_t &detid, const uint16_t &apv)
unsigned long long getNoiseCache(const edm::EventSetup &eSetup)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::ESHandle< SiStripNoises > noiseHandle_
unsigned long long cacheID_gain
unsigned long long getGainCache(const edm::EventSetup &eSetup)
double a
Definition: hdecay.h:121
const Range getRange(const uint32_t detID) const
dbl *** dir
Definition: mlp_gen.cc:35
SiStripCorrelateNoise(const edm::ParameterSet &)
void checkGainCache(const edm::EventSetup &es)
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:48
unsigned int tecWheel(const DetId &id) const
SiStripDetInfoFileReader * fr
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2777
unsigned int tobLayer(const DetId &id) const
Definition: Run.h:43
unsigned int tecSide(const DetId &id) const