ATLAS Offline Software
Loading...
Searching...
No Matches
AFP_NoisyPixelTool Class Reference

#include <AFP_NoisyPixelTool.h>

Inheritance diagram for AFP_NoisyPixelTool:
Collaboration diagram for AFP_NoisyPixelTool:

Public Member Functions

 AFP_NoisyPixelTool ()
int Identify (std::shared_ptr< const TH2F > input, std::vector< TH2F > &output) const override
std::vector< std::vector< double > > makeFits (std::shared_ptr< const TH2F > input) const
void setThreshNoisy (double t)
double getThreshNoisy () const
void setThreshLeff (double t)
double getThreshLeff () const
void setSensitivity (double s)
double getSensitivity () const
void setMethods (const std::vector< std::string > &m)
const std::vector< std::string > & getMethods () const

Private Member Functions

std::vector< std::pair< int, int > > getLegitPixels (std::shared_ptr< const TH2F > input, const int col_ID, const int row_ID, const std::string &method) const
TH2F countInactivePixelsAround (std::shared_ptr< const TH2F > input) const
double getNeighbours (std::shared_ptr< const TH2F > input, int row_ID, int col_ID) const
std::tuple< TH2F, TH2F, TH2F, TH2F > findLEffAndNoisyPixels (std::shared_ptr< const TH2F > input, const TH2F &inact, const std::string &method) const
void filterLEffPixelsAroundNoisy (std::shared_ptr< const TH2F > input, const TH2F &inact, TH2F &fleff, TH2F &fnoisy, TH2F &eleff, TH2F &enoisy, const std::string &method) const

Private Attributes

double m_threshNoisy
double m_threshLEff
double m_sensitivity
std::vector< std::string > m_methods

Detailed Description

Definition at line 22 of file AFP_NoisyPixelTool.h.

Constructor & Destructor Documentation

◆ AFP_NoisyPixelTool()

AFP_NoisyPixelTool::AFP_NoisyPixelTool ( )
inline

Definition at line 24 of file AFP_NoisyPixelTool.h.

24: m_threshNoisy(1.4), m_threshLEff(0.6), m_sensitivity(0.0), m_methods({"2_ROW","2_COL"}) {}
std::vector< std::string > m_methods

Member Function Documentation

◆ countInactivePixelsAround()

TH2F AFP_NoisyPixelTool::countInactivePixelsAround ( std::shared_ptr< const TH2F > input) const
private

Definition at line 183 of file AFP_NoisyPixelTool.cxx.

184{
185 TH2F tmp_inact_pix_around(*input);
186 tmp_inact_pix_around.SetName("tmp_inact_pix_around");
187 tmp_inact_pix_around.Reset();
188
189 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
190 {
191 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
192 {
193 int inactive_pixels_around=0;
194 auto legit_pixels=getLegitPixels(input, col_ID, row_ID);
195
196 for(auto legpix : legit_pixels)
197 {
198 if(input->GetBinContent(legpix.first, legpix.second)<1) ++inactive_pixels_around;
199 }
200
201 tmp_inact_pix_around.SetBinContent(row_ID,col_ID, inactive_pixels_around+0.01);
202 }
203 }
204
205 return tmp_inact_pix_around;
206}
std::vector< std::pair< int, int > > getLegitPixels(std::shared_ptr< const TH2F > input, const int col_ID, const int row_ID, const std::string &method) const
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)

◆ filterLEffPixelsAroundNoisy()

void AFP_NoisyPixelTool::filterLEffPixelsAroundNoisy ( std::shared_ptr< const TH2F > input,
const TH2F & inact,
TH2F & fleff,
TH2F & fnoisy,
TH2F & eleff,
TH2F & enoisy,
const std::string & method ) const
private

Definition at line 289 of file AFP_NoisyPixelTool.cxx.

290{
291 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
292 {
293 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
294 {
295 if(input->GetBinContent(row_ID,col_ID)==0) continue;
296
297 int inactive_pixels_around=tmp_inact_pix_around.GetBinContent(row_ID, col_ID);
298 int leff_pixels_around=0;
299 auto legit_pixels=getLegitPixels(input, col_ID,row_ID);
300 for(auto legpix : legit_pixels)
301 {
302 if(tmp_found_leff.GetBinContent(legpix.first,legpix.second)>0) leff_pixels_around++;
303 }
304
305 if(leff_pixels_around!=0 && inactive_pixels_around==0)
306 {
307 //if low eff. pixels around > 0, recalculate avarage
308 double re_av=0.;
309 int npix=0;
310
311 auto legit_pixels=getLegitPixels(input, col_ID,row_ID, method);
312 for(auto legpix : legit_pixels)
313 {
314 if(tmp_found_leff.GetBinContent(legpix.first,legpix.second)==0)
315 {
316 re_av+=input->GetBinContent(legpix.first,legpix.second);
317 npix++;
318 }
319 }
320
321 if(npix==0)
322 {
323 re_av=0;
324 for(const auto & legpix : legit_pixels)
325 {
326 re_av+=input->GetBinContent(legpix.first,legpix.second);
327 }
328
329 if(re_av/input->GetBinContent(row_ID,col_ID)<1.5 && re_av/input->GetBinContent(row_ID,col_ID)>0.5) re_av=1;
330 }
331 else
332 {
333 re_av/=npix;
334 }
335 if (re_av == 0)[[unlikely]]{
336 std::cerr<< "AFP_NoisyPixelTool::findLEffAndNoisyPixels: re_av denominator is zero\n";
337 continue;
338 }
339 double ratio_noisy = m_sensitivity+input->GetBinContent(row_ID,col_ID)/re_av;
340 double ratio_leff = input->GetBinContent(row_ID,col_ID)/re_av;
341 if(re_av==1)
342 {
343 tmp_eff_leff.SetBinContent(row_ID,col_ID,1);
344 tmp_eff_noisy.SetBinContent(row_ID,col_ID,1);
345 }
346
347 if(row_ID!=input->GetNbinsX() && row_ID!=1 && col_ID!=1 && col_ID!=input->GetNbinsY())
348 {
349 if( ((ratio_noisy>m_threshNoisy && re_av!=1) || re_av==1) )
350 {
351 tmp_found_noisy.SetBinContent(row_ID,col_ID,1);
352 if(re_av!=1) tmp_eff_noisy.SetBinContent(row_ID,col_ID,100.*ratio_noisy);
353 }
354 if( ((ratio_leff<m_threshLEff && re_av!=1) || re_av==1) )
355 {
356 tmp_found_leff.SetBinContent(row_ID,col_ID,1);
357 if(re_av!=1) tmp_eff_leff.SetBinContent(row_ID,col_ID,100.*ratio_leff);
358 }
359 }
360 }
361 }
362 }
363
364 return;
365}
#define unlikely(x)
Definition dictionary.h:41

◆ findLEffAndNoisyPixels()

std::tuple< TH2F, TH2F, TH2F, TH2F > AFP_NoisyPixelTool::findLEffAndNoisyPixels ( std::shared_ptr< const TH2F > input,
const TH2F & inact,
const std::string & method ) const
private

Definition at line 217 of file AFP_NoisyPixelTool.cxx.

218{
219 TH2F tmp_found_leff(*input);
220 tmp_found_leff.SetName("tmp_found_leff");
221 tmp_found_leff.Reset();
222
223 TH2F tmp_found_noisy(*input);
224 tmp_found_noisy.SetName("tmp_found_noisy");
225 tmp_found_noisy.Reset();
226
227 TH2F tmp_eff_leff(*input);
228 tmp_eff_leff.SetName("tmp_eff_leff");
229 tmp_eff_leff.Reset();
230
231 TH2F tmp_eff_noisy(*input);
232 tmp_eff_noisy.SetName("tmp_eff_noisy");
233 tmp_eff_noisy.Reset();
234
235 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
236 {
237 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
238 {
239 if(input->GetBinContent(row_ID, col_ID)!=0 && tmp_inact_pix_around.GetBinContent(row_ID, col_ID)<0.1)
240 {
241 double npixels=getNeighbours(input, row_ID, col_ID);
242
243 double sum=0.;
244 auto legit_pixels=getLegitPixels(input, col_ID, row_ID, method);
245 for(auto legpix : legit_pixels)
246 {
247 sum+=input->GetBinContent(legpix.first,legpix.second);
248 }
249
250 double av_noisy=0;
251 double av_leff=0;
252
253 // TODO: something about edges?
254 if(method=="2_ROW" || method=="2_COL")
255 {
256 av_noisy=sum/(std::abs(npixels-4)*0.5);
257 av_leff=sum/2.;
258 }
259 else if(method=="4_PIX")
260 {
261 av_noisy=sum/(std::ceil(npixels*0.5));
262 av_leff=sum/4.;
263 }
264 else if(method=="8_PIX")
265 {
266 av_noisy=sum/(npixels);
267 av_leff=sum/8.;
268 }
269
270 if ((av_leff == 0) or (av_noisy == 0))[[unlikely]]{
271 std::cerr<< "AFP_NoisyPixelTool::findLEffAndNoisyPixels: denominator is zero\n";
272 continue;
273 }
274 double ratio_leff = input->GetBinContent(row_ID,col_ID)/av_leff;
275 double ratio_noisy = input->GetBinContent(row_ID,col_ID)/av_noisy;
276 tmp_eff_leff.SetBinContent(row_ID,col_ID,100.*ratio_leff);
277 tmp_eff_noisy.SetBinContent(row_ID,col_ID,100.*ratio_noisy);
278
279 if(ratio_leff < m_threshLEff) tmp_found_leff.SetBinContent(row_ID,col_ID,1.);
280 if(ratio_noisy > m_threshNoisy) tmp_found_noisy.SetBinContent(row_ID,col_ID,1.);
281 }
282 }
283 }
284
285 return {tmp_found_leff,tmp_found_noisy,tmp_eff_leff,tmp_eff_noisy};
286}
double getNeighbours(std::shared_ptr< const TH2F > input, int row_ID, int col_ID) const

◆ getLegitPixels()

std::vector< std::pair< int, int > > AFP_NoisyPixelTool::getLegitPixels ( std::shared_ptr< const TH2F > input,
const int col_ID,
const int row_ID,
const std::string & method = "8_PIX" ) const
private

Definition at line 158 of file AFP_NoisyPixelTool.cxx.

159{
160 // method="8_PIX" means to investigate all pixels around
161
162 std::vector<std::pair<int,int>> legit_pixels={};
163
164 for(int r=-1; r<2; r++)
165 {
166 for(int c=-1; c<2; c++)
167 {
168 if( (row_ID+r)>=1 && (col_ID+c)>=1 && (col_ID+c)<=input->GetNbinsY() && (row_ID+r)<=input->GetNbinsX() && (r!=0 || c!=0))
169 {
170 if( (method=="2_ROW" && c==0) || (method=="2_COL" && r==0)
171 || (method=="4_PIX" && (c==0 || r==0)) || (method=="8_PIX") )
172 {
173 legit_pixels.push_back(std::pair<int,int>(row_ID+r,col_ID+c));
174 }
175 }
176 }
177 }
178
179 return legit_pixels;
180}
int r
Definition globals.cxx:22

◆ getMethods()

const std::vector< std::string > & AFP_NoisyPixelTool::getMethods ( ) const
inline

Definition at line 40 of file AFP_NoisyPixelTool.h.

40{return m_methods;}

◆ getNeighbours()

double AFP_NoisyPixelTool::getNeighbours ( std::shared_ptr< const TH2F > input,
int row_ID,
int col_ID ) const
private

Definition at line 209 of file AFP_NoisyPixelTool.cxx.

210{
211 if( row_ID!=input->GetNbinsX() && row_ID!=1 && col_ID!=1 && col_ID!=input->GetNbinsY()) return 8.;
212 else if( (row_ID==input->GetNbinsX() || row_ID==1) && (col_ID==1 || col_ID==input->GetNbinsY())) return 3.;
213 else return 5;
214}

◆ getSensitivity()

double AFP_NoisyPixelTool::getSensitivity ( ) const
inline

Definition at line 37 of file AFP_NoisyPixelTool.h.

37{return m_sensitivity;}

◆ getThreshLeff()

double AFP_NoisyPixelTool::getThreshLeff ( ) const
inline

Definition at line 34 of file AFP_NoisyPixelTool.h.

34{return m_threshLEff;}

◆ getThreshNoisy()

double AFP_NoisyPixelTool::getThreshNoisy ( ) const
inline

Definition at line 31 of file AFP_NoisyPixelTool.h.

31{return m_threshNoisy;}

◆ Identify()

int AFP_NoisyPixelTool::Identify ( std::shared_ptr< const TH2F > input,
std::vector< TH2F > & output ) const
overridevirtual

Implements IAFP_GenericPixelTool.

Definition at line 8 of file AFP_NoisyPixelTool.cxx.

9{
10 if(output.size()!=1)
11 {
12 return 0;
13 }
14
15 output[0].Reset();
16 output.resize(4, output[0]);//container now has 4 copies of the 0'th element
17 auto name = [&output](const char * n)->TString{
18 return Form(n,output[0].GetName());
19 };
20 auto title = [&output](const char * t)->TString{
21 return Form(t,output[0].GetTitle());
22 };
23 output[1].SetNameTitle(name("leffpixels_found_%s"), title("low efficiency pixels, found, %s"));
24 output[2].SetNameTitle(name("noisypixels_eff_%s"), title("noisy pixels, efficiency, %s"));
25 output[3].SetNameTitle(name("leffpixels_eff_%s"), title("low efficiency pixels, efficiency, %s"));
26 output[0].SetNameTitle(name("noisypixels_found_%s"), title("noisy pixels, found, %s"));
27
28 TH2F& noisypixels_found_output = output[0];
29 TH2F& leffpixels_found_output = output[1];
30 TH2F& noisypixels_eff_output = output[2];
31 TH2F& leffpixels_eff_output = output[3];
32
33
34 if(input->GetMaximum()<0.5) return 0;
35
36 std::vector<TH2F> vec_found_leff{},vec_found_noisy{},vec_eff_leff{},vec_eff_noisy{};
37
38 for(const auto& method : m_methods)
39 {
40 TH2F tmp_eff_noisy, tmp_eff_leff;
41 TH2F tmp_found_leff, tmp_found_noisy;
42
43 if(method!="FIT")
44 {
45 // count inactive pixels around each pixel
46 TH2F tmp_inact_pix_around=countInactivePixelsAround(input);
47
48 // find low eff. and noisy pixels
49 std::tie(tmp_found_leff,tmp_found_noisy,tmp_eff_leff, tmp_eff_noisy) = findLEffAndNoisyPixels(input, tmp_inact_pix_around, method);
50
51 // reconsider some pixels
52 filterLEffPixelsAroundNoisy(input, tmp_inact_pix_around, tmp_found_leff,tmp_found_noisy,tmp_eff_leff,tmp_eff_noisy, method);
53 }
54 else
55 {
56 // method is "FIT"
57
58 tmp_eff_noisy=TH2F(*input);
59 tmp_eff_noisy.SetName("tmp_eff_noisy");
60 tmp_eff_noisy.Reset();
61 tmp_eff_leff=TH2F(*input);
62 tmp_eff_leff.SetName("tmp_eff_leff");
63 tmp_eff_leff.Reset();
64 tmp_found_noisy=TH2F(*input);
65 tmp_found_noisy.SetName("tmp_found_noisy");
66 tmp_found_noisy.Reset();
67 tmp_found_leff=TH2F(*input);
68 tmp_found_leff.SetName("tmp_found_leff");
69 tmp_found_leff.Reset();
70
71 auto p=makeFits(input);
72
73 const double Threshold_LEFF=5.;
74 const double Threshold_NOISY=(m_threshNoisy-1)*100;
75
76 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
77 {
78 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
79 {
80 double ratio_leff=0, ratio_noisy=0;
81 double gauss_helper_12 = (col_ID-p[1][row_ID])/p[2][row_ID];
82 double gauss_helper_45 = (col_ID-p[4][row_ID])/p[5][row_ID];
83 double fit = p[0][row_ID]*exp(-0.5*gauss_helper_12*gauss_helper_12)
84 + p[3][row_ID]*exp(-0.5*gauss_helper_45*gauss_helper_45) + p[6][row_ID];
85 double sigma=std::sqrt(fit);
86 if(sigma<1) sigma=1;
87
88 double bin_content=input->GetBinContent(row_ID,col_ID);
89
90 if(fit>=bin_content) ratio_leff = std::abs(fit-bin_content)/sigma;
91 else ratio_noisy = std::abs(fit-bin_content)/sigma;
92
93 if(bin_content!=0)
94 {
95 if( ratio_leff > Threshold_LEFF) tmp_found_leff.SetBinContent(row_ID,col_ID,1);
96 if( ratio_noisy > Threshold_NOISY) tmp_found_noisy.SetBinContent(row_ID,col_ID,1);
97 }
98 tmp_eff_leff.SetBinContent(row_ID,col_ID,100.*ratio_leff);
99 tmp_eff_noisy.SetBinContent(row_ID,col_ID,100.*ratio_noisy);
100 }
101 }
102 }
103
104 // save output for this method
105 vec_found_leff.push_back(tmp_found_leff);
106 vec_found_noisy.push_back(tmp_found_noisy);
107 vec_eff_leff.push_back(tmp_eff_leff);
108 vec_eff_noisy.push_back(tmp_eff_noisy);
109 }
110
111 // sum found pixels for all methods, set efficiency to the maximum of all methods
112 for(unsigned int m=0; m<m_methods.size(); m++)
113 {
114 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
115 {
116 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
117 {
118 noisypixels_found_output.Fill(row_ID,col_ID, vec_found_noisy[m].GetBinContent(row_ID,col_ID));
119 leffpixels_found_output.Fill(row_ID,col_ID, vec_found_leff[m].GetBinContent(row_ID,col_ID));
120
121 if(m==0)
122 {
123 noisypixels_eff_output.SetBinContent(row_ID,col_ID, vec_eff_noisy[m].GetBinContent(row_ID,col_ID));
124 leffpixels_eff_output.SetBinContent(row_ID,col_ID, vec_eff_leff[m].GetBinContent(row_ID,col_ID));
125 }
126 else
127 {
128 if(noisypixels_eff_output.GetBinContent(row_ID,col_ID)<vec_eff_noisy[m].GetBinContent(row_ID,col_ID))
129 {
130 noisypixels_eff_output.SetBinContent(row_ID,col_ID, vec_eff_noisy[m].GetBinContent(row_ID,col_ID));
131 }
132 if(leffpixels_eff_output.GetBinContent(row_ID,col_ID)>vec_eff_leff[m].GetBinContent(row_ID,col_ID))
133 {
134 leffpixels_eff_output.SetBinContent(row_ID,col_ID, vec_eff_leff[m].GetBinContent(row_ID,col_ID));
135 }
136 }
137 }
138 }
139 }
140
141 // report only pixels that are identified by all methods
142 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
143 {
144 for(int row_ID=1; row_ID<=input->GetNbinsX(); row_ID++)
145 {
146 if(noisypixels_found_output.GetBinContent(row_ID,col_ID)==m_methods.size()) noisypixels_found_output.SetBinContent(row_ID,col_ID,1);
147 else noisypixels_found_output.SetBinContent(row_ID,col_ID,0);
148
149 if(leffpixels_found_output.GetBinContent(row_ID,col_ID)==m_methods.size()) leffpixels_found_output.SetBinContent(row_ID,col_ID,1);
150 else leffpixels_found_output.SetBinContent(row_ID,col_ID,0);
151 }
152 }
153
154 return 0;
155}
std::tuple< TH2F, TH2F, TH2F, TH2F > findLEffAndNoisyPixels(std::shared_ptr< const TH2F > input, const TH2F &inact, const std::string &method) const
std::vector< std::vector< double > > makeFits(std::shared_ptr< const TH2F > input) const
TH2F countInactivePixelsAround(std::shared_ptr< const TH2F > input) const
void filterLEffPixelsAroundNoisy(std::shared_ptr< const TH2F > input, const TH2F &inact, TH2F &fleff, TH2F &fnoisy, TH2F &eleff, TH2F &enoisy, const std::string &method) const
output
Definition merge.py:16

◆ makeFits()

std::vector< std::vector< double > > AFP_NoisyPixelTool::makeFits ( std::shared_ptr< const TH2F > input) const

Definition at line 368 of file AFP_NoisyPixelTool.cxx.

369{
370 const int nParams=7;
371 std::vector<std::vector<double>> params(nParams, std::vector<double>(input->GetNbinsX()+1, 0.));
372
373 for(int row_ID=0; row_ID<=input->GetNbinsX(); row_ID++)
374 {
375 std::string srow_ID = std::to_string(row_ID);
376 std::unique_ptr<TH1F> hist(new TH1F(("ROW"+srow_ID).c_str(), ("ROW"+srow_ID).c_str(), input->GetNbinsY(), 0.5, input->GetNbinsX()+0.5));
377
378 for(int col_ID=1; col_ID<=input->GetNbinsY(); col_ID++)
379 {
380 hist->Fill(col_ID, 1.0*input->GetBinContent(row_ID,col_ID));
381 }
382
383 //Set double gaussian fit with starting parameters
384 std::shared_ptr<TF1> FIT_2(new TF1("gaus","gaus(0)+gaus(3)+[6]",0,input->GetNbinsY(),nParams));
385 if(row_ID==1)
386 {
387 FIT_2->SetParameters(25000,hist->GetMean(),hist->GetStdDev()/std::sqrt(2),
388 5000,hist->GetMean(),hist->GetStdDev()/std::sqrt(2),
389 std::max(hist->GetBinContent(2),std::max(hist->GetBinContent(3),hist->GetBinContent(4))) );
390 }
391 else
392 {
393 for(int par=0;par<nParams;++par)
394 {
395 FIT_2->SetParameter(par,params.at(par).at(row_ID-1));
396 }
397 }
398
399 //fit
400 hist->Fit(FIT_2.get(),"Q");
401
402 for(int par=0;par<nParams;++par)
403 {
404 params.at(par).at(row_ID-1)=FIT_2->GetParameter(par);
405 }
406 }
407
408 return params;
409}
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)

◆ setMethods()

void AFP_NoisyPixelTool::setMethods ( const std::vector< std::string > & m)
inline

Definition at line 39 of file AFP_NoisyPixelTool.h.

39{m_methods=m;}

◆ setSensitivity()

void AFP_NoisyPixelTool::setSensitivity ( double s)
inline

Definition at line 36 of file AFP_NoisyPixelTool.h.

◆ setThreshLeff()

void AFP_NoisyPixelTool::setThreshLeff ( double t)
inline

Definition at line 33 of file AFP_NoisyPixelTool.h.

◆ setThreshNoisy()

void AFP_NoisyPixelTool::setThreshNoisy ( double t)
inline

Definition at line 30 of file AFP_NoisyPixelTool.h.

Member Data Documentation

◆ m_methods

std::vector<std::string> AFP_NoisyPixelTool::m_methods
private

Definition at line 48 of file AFP_NoisyPixelTool.h.

◆ m_sensitivity

double AFP_NoisyPixelTool::m_sensitivity
private

Definition at line 46 of file AFP_NoisyPixelTool.h.

◆ m_threshLEff

double AFP_NoisyPixelTool::m_threshLEff
private

Definition at line 45 of file AFP_NoisyPixelTool.h.

◆ m_threshNoisy

double AFP_NoisyPixelTool::m_threshNoisy
private

Definition at line 44 of file AFP_NoisyPixelTool.h.


The documentation for this class was generated from the following files: