CMS 3D CMS Logo

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