ATLAS Offline Software
Public Member Functions | List of all members
dqm_algorithms::BinsDiffFromStripMedian Struct Reference

#include <BinsDiffFromStripMedian.h>

Inheritance diagram for dqm_algorithms::BinsDiffFromStripMedian:
Collaboration diagram for dqm_algorithms::BinsDiffFromStripMedian:

Public Member Functions

 BinsDiffFromStripMedian ()
 
 ~BinsDiffFromStripMedian ()
 
BinsDiffFromStripMedianclone ()
 
dqm_core::Resultexecute (const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
 
void FindStripMedian (std::vector< double > onestrip, std::vector< double > &stripsMedian)
 
colorcluster MakeCluster (const int r0, const int r2, bin &onebin, std::vector< std::vector< colorbin > > &ColorBinMap)
 
void printDescription (std::ostream &out)
 

Detailed Description

Definition at line 25 of file BinsDiffFromStripMedian.h.

Constructor & Destructor Documentation

◆ BinsDiffFromStripMedian()

dqm_algorithms::BinsDiffFromStripMedian::BinsDiffFromStripMedian ( )

Definition at line 27 of file BinsDiffFromStripMedian.cxx.

28 {
29  dqm_core::AlgorithmManager::instance().registerAlgorithm("BinsDiffFromStripMedian", this);
30 }

◆ ~BinsDiffFromStripMedian()

dqm_algorithms::BinsDiffFromStripMedian::~BinsDiffFromStripMedian ( )

Definition at line 32 of file BinsDiffFromStripMedian.cxx.

33 {
34 }

Member Function Documentation

◆ clone()

dqm_algorithms::BinsDiffFromStripMedian * dqm_algorithms::BinsDiffFromStripMedian::clone ( )

Definition at line 37 of file BinsDiffFromStripMedian.cxx.

38 {
39 
40  return new BinsDiffFromStripMedian();
41 }

◆ execute()

dqm_core::Result * dqm_algorithms::BinsDiffFromStripMedian::execute ( const std::string &  name,
const TObject &  object,
const dqm_core::AlgorithmConfig &  config 
)

Definition at line 45 of file BinsDiffFromStripMedian.cxx.

48 {
49  const TH1* histogram;
50 
51  if( object.IsA()->InheritsFrom( "TH1" ) ) {
52  histogram = static_cast<const TH1*>(&object);
53  if (histogram->GetDimension() > 2 ){
54  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
55  }
56  } else {
57  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
58  }
59 
60  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
61  const double ignoreval = dqm_algorithms::tools::GetFirstFromMap( "ignoreval", config.getParameters(), -99999);
62  const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 1);
63  const int Nmaxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
64  const bool VisualMode = (bool) dqm_algorithms::tools::GetFirstFromMap( "VisualMode", config.getParameters(), 1);
65  const int NpublishRed = (int) dqm_algorithms::tools::GetFirstFromMap( "PublishRedBins",config.getParameters(), 0);
66  const bool ClusterResult = (bool) dqm_algorithms::tools::GetFirstFromMap( "ClusterResult", config.getParameters(), 0);
67  const double suppressFactor = dqm_algorithms::tools::GetFirstFromMap("SuppressFactor", config.getParameters(), 0.05);
68  const double suppressRedFactor = dqm_algorithms::tools::GetFirstFromMap("SuppressRedFactor", config.getParameters(), 0.01);
69  if ( histogram->GetEntries() < minstat ) {
71  result->tags_["InsufficientEntries"] = histogram->GetEntries();
72  return result;
73  }
74 
75  double gthreshold;
76  double rthreshold;
77  try {
78  rthreshold = dqm_algorithms::tools::GetFromMap( "MaxDeviation", config.getRedThresholds() );
79  gthreshold = dqm_algorithms::tools::GetFromMap( "MaxDeviation", config.getGreenThresholds() );
80  }
81  catch( dqm_core::Exception & ex ) {
82  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
83  }
84 
85  std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
86  std::vector<double> stripsMedian;
87  std::vector<double> stripsAvg;
88  std::vector<double> stripsVariance;
89  double maxInMap=0;
90  for ( int i = range[0]; i <= range[1]; ++i ) {
91  std::vector<double> onestrip;
92  double stripSum=0;
93  for ( int j = range[2]; j <= range[3]; ++j ) {
94  if (histogram->GetBinContent(i,j) == ignoreval) continue;
95  float binvalue = histogram->GetBinContent(i,j);
96  onestrip.push_back(binvalue);
97  stripSum += binvalue;
98  if(binvalue > maxInMap) {
99  maxInMap = binvalue;
100  }
101  }
102  stripsAvg.push_back(stripSum/onestrip.size());
103  FindStripMedian(onestrip,stripsMedian);
104  }
105  for ( int i = range[0]; i <= range[1]; ++i ) {
106  float sumdiff2=0;
107  int counter=0;
108  for ( int j = range[2]; j <= range[3]; ++j ) {
109  if (histogram->GetBinContent(i,j) == ignoreval) continue;
110  double binvalue = histogram->GetBinContent(i,j);
111  double diff=binvalue-stripsAvg[i-range[0]];
112  sumdiff2 +=std::pow(diff,2);
113  counter++;
114  }
115  double variance=-1;
116  if(counter!=0) variance = sumdiff2 / counter ;
117  stripsVariance.push_back(variance);
118  }
120  std::vector<bin> redbins;
121  std::vector<bin> yellowbins;
122  std::vector<bin> Allbins;
123  for ( int k = range[0]; k <= range[1]; ++k ) {
124  for ( int l = range[2]; l <= range[3]; ++l ) {
125  double binvalue = histogram->GetBinContent(k,l);
126  if (binvalue== ignoreval) continue;
127  double strip_median = stripsMedian[k-range[0]];
128  if(stripsMedian[k-range[0]]==0 && stripsVariance[k-range[0]]==0) continue; // skip empty strip
129  else if(stripsMedian[k-range[0]]==0 && stripsVariance[k-range[0]]!=0 && stripsAvg[k-range[0]]!=0) strip_median = stripsAvg[k-range[0]];
130  else if(stripsMedian[k-range[0]]==0 && stripsVariance[k-range[0]]!=0 && stripsAvg[k-range[0]]==0) continue;
131  double outstandingRatio=0;
132  if(std::abs(strip_median) > 0.00001 ) outstandingRatio= (binvalue-strip_median)/std::sqrt(std::abs(strip_median));
133  else continue;
134  double eta = histogram->GetXaxis()->GetBinCenter(k);
135  double phi = histogram->GetYaxis()->GetBinCenter(l);
136  bin onebin = {eta,phi,k,l,binvalue,outstandingRatio};
137  Allbins.push_back(onebin);
138  if(std::abs(outstandingRatio) > rthreshold ) {
139  if( VisualMode && (binvalue / maxInMap < suppressRedFactor) )
140  continue;
141  redbins.push_back(onebin);
142  }
143  else if(std::abs(outstandingRatio) > gthreshold ){
144  if( VisualMode && (binvalue / maxInMap < suppressFactor) )
145  continue;
146  yellowbins.push_back(onebin);
147  }
148  }
149  }
150  int count_red_c = 0;
151  int count_yellow_c = 0;
152  std::vector<std::vector<colorbin> > ColorBinMap;
153 if(ClusterResult){
154  // initialize ColorBinMap
155  for ( int k = range[0]; k <= range[1]; ++k ) {
156  std::vector<colorbin> oneColorStrip;
157  for ( int l = range[2]; l <= range[3]; ++l ) {
158  colorbin oneColorBin = {static_cast<double>(k), static_cast<double>(l), -1, -1, -1, green, 1};
159  oneColorStrip.push_back(oneColorBin);
160  }
161  ColorBinMap.push_back(oneColorStrip);
162  }
163 
164 // map redbins and yellowbins to ColorBinMap
165  for(unsigned int i=0;i<redbins.size();i++){
166  int k=redbins[i].m_ix;
167  int l=redbins[i].m_iy;
168 
169  ColorBinMap[k-range[0]][l-range[2]].m_eta = redbins[i].m_eta;
170 
171  ColorBinMap[k-range[0]][l-range[2]].m_phi = redbins[i].m_phi;
172  ColorBinMap[k-range[0]][l-range[2]].m_value = redbins[i].m_value;
173  ColorBinMap[k-range[0]][l-range[2]].m_color = red;
174 
175  }
176 
177 
178  for(unsigned int i=0;i<yellowbins.size();i++){
179  int k=yellowbins[i].m_ix;
180  int l=yellowbins[i].m_iy;
181  ColorBinMap[k-range[0]][l-range[2]].m_eta = yellowbins[i].m_eta;
182  ColorBinMap[k-range[0]][l-range[2]].m_phi = yellowbins[i].m_phi;
183  ColorBinMap[k-range[0]][l-range[2]].m_value = yellowbins[i].m_value;
184  ColorBinMap[k-range[0]][l-range[2]].m_color = yellow;
185  }
186 
187 
188 // cluster bad bins
189  std::vector<colorcluster > clusterArray;
190  for(unsigned int i=0;i<redbins.size();i++){
191  const int k=redbins[i].m_ix;
192  const int l=redbins[i].m_iy;
193  if(ColorBinMap[k-range[0]][l-range[2]].m_color != green){
194  colorcluster onecluster = MakeCluster(range[0],range[2],redbins[i],ColorBinMap);
195  if(onecluster.m_size > 1) clusterArray.push_back(onecluster);
196  }
197  }
198  for(unsigned int i=0;i<yellowbins.size();i++){
199  const int k=yellowbins[i].m_ix;
200  const int l=yellowbins[i].m_iy;
201  if(ColorBinMap[k-range[0]][l-range[2]].m_color != green){
202  colorcluster onecluster = MakeCluster(range[0],range[2],yellowbins[i],ColorBinMap);
203  if(onecluster.m_size > 1) clusterArray.push_back(onecluster);
204  }
205  }
206 
207  // publish clusters here:
208  for(unsigned int i=0;i<clusterArray.size();i++){
209  char tmp[500];
210  if(clusterArray[i].m_color==red){
211  sprintf(tmp,"CR%i-(eta,phi)(r)(size)=(%0.3f,%0.3f)(%0.3f)(%i)",count_red_c,clusterArray[i].m_eta,clusterArray[i].m_phi,clusterArray[i].m_radius,clusterArray[i].m_size);
212  count_red_c++;
213  }
214  else if(clusterArray[i].m_color==yellow){
215  sprintf(tmp,"CY%i-(eta,phi)(r)(size)=(%0.3f,%0.3f)(%0.3f)(%i)",count_yellow_c,clusterArray[i].m_eta,clusterArray[i].m_phi,clusterArray[i].m_radius,clusterArray[i].m_size);
216  count_yellow_c++;
217  }
218  std::string tag = tmp;
219  result->tags_[tag] = clusterArray[i].m_value;
220  }
221  result->tags_["NRedClusters"] = count_red_c;
222  result->tags_["NYellowClusters"] = count_yellow_c;
223 
224  }
225 
226 
227  std::sort(redbins.begin(),redbins.end(),mySortfunc);
228  std::sort(yellowbins.begin(),yellowbins.end(),mySortfunc);
229  std::sort(Allbins.begin(),Allbins.end(),mySortfunc_ratio);
230 // publish red bins
231  int count_red=0;
232  for(unsigned int i=0;i<redbins.size();i++){
233  if(ClusterResult && ColorBinMap[redbins[i].m_ix-range[0]][redbins[i].m_iy-range[2]].m_status==0 ) continue;
234  if(publish){
235  char tmp[500];
236  sprintf(tmp,"R%i-(eta,phi)[OSRatio]=(%0.3f,%0.3f)[%0.2e]",count_red,redbins[i].m_eta,redbins[i].m_phi,redbins[i].m_outstandingRatio);
237  std::string tag = tmp;
238  result->tags_[tag] = redbins[i].m_value;
239  }
240  count_red++;
241  if(NpublishRed > 0){
242  if(count_red > NpublishRed) break;
243  }
244  }
245 
246 // publish yellow bins
247  int count_yellow=0;
248  for(unsigned int i=0;i<yellowbins.size();i++){
249  if(ClusterResult &&ColorBinMap[yellowbins[i].m_ix-range[0]][yellowbins[i].m_iy-range[2]].m_status==0) continue;
250  if(publish && (count_red+count_yellow) < Nmaxpublish ){
251  char tmp[500];
252  sprintf(tmp,"Y%i-(eta,phi)[OSRatio]=(%0.3f,%0.3f)[%.2e]",count_yellow,yellowbins[i].m_eta,yellowbins[i].m_phi,yellowbins[i].m_outstandingRatio);
253  std::string tag = tmp;
254  result->tags_[tag] = yellowbins[i].m_value;
255  }
256  count_yellow++;
257  }
258  result->tags_["NRedBins"] = count_red; // count_red is the number of red bins printed
259  result->tags_["NYellowBins"] = count_yellow; // count_yellow is the number of yellow bins printed
260 
261  if(count_red+count_yellow==0 && Allbins.size()>=5 ){
262  for(int i=0;i<5;i++){
263  char tmptmp[500];
264  sprintf(tmptmp,"LeadingBin%i-(eta,phi)=(%0.3f,%0.3f)",i,Allbins[i].m_eta,Allbins[i].m_phi);
265  std::string tagtag = tmptmp;
266  result->tags_[tagtag] = Allbins[i].m_value;
267  }
268 
269  }
270 
271 
272  if(count_red>0 || count_red_c>0) result->status_ = dqm_core::Result::Red;
273  else if (count_yellow>0||count_yellow_c>0) result->status_ = dqm_core::Result::Yellow;
274  else result->status_ = dqm_core::Result::Green;
275 
276  return result;
277 
278 }

◆ FindStripMedian()

void dqm_algorithms::BinsDiffFromStripMedian::FindStripMedian ( std::vector< double >  onestrip,
std::vector< double > &  stripsMedian 
)

Definition at line 280 of file BinsDiffFromStripMedian.cxx.

280  {
281  double median=0;
282 
283  std::sort(onestrip_tmp.begin(),onestrip_tmp.end());
284  int index1=onestrip_tmp.size()/4;
285 
286  int index2=onestrip_tmp.size()/2;
287  int index3=3*onestrip_tmp.size()/4;
288  median = (onestrip_tmp[index1]+onestrip_tmp[index2]+onestrip_tmp[index3])/3.0;
289  stripsMedian.push_back(median);
290 }

◆ MakeCluster()

colorcluster dqm_algorithms::BinsDiffFromStripMedian::MakeCluster ( const int  r0,
const int  r2,
bin onebin,
std::vector< std::vector< colorbin > > &  ColorBinMap 
)

Definition at line 386 of file BinsDiffFromStripMedian.cxx.

386  {
387  colorcluster onecluster={0,0,0,0,green,-1};
388  if(ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2].m_status==0)
389  return onecluster;
390  std::vector<colorbin> LookAtList;
391  if(ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2].m_color!=green){
392  LookAtList.push_back(ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2]);
393  ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2].m_status=0;
394  AddToList(r0,r2,onebin.m_ix,onebin.m_iy,ColorBinMap, LookAtList);
395  if(LookAtList.size()>1){
396  onecluster.m_size = LookAtList.size();
397  onecluster.m_value = CalVal(LookAtList);
398  if(ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2].m_color==red)
399  onecluster.m_color = red;
400  else onecluster.m_color = yellow;
401  onecluster.m_eta = CalEta(LookAtList);
402  onecluster.m_phi = CalPhi(LookAtList);
403  onecluster.m_radius = CalR(LookAtList,onecluster.m_eta,onecluster.m_phi);
404  }
405  else ColorBinMap[onebin.m_ix-r0][onebin.m_iy-r2].m_status=1;
406  }
407  return onecluster;
408 }

◆ printDescription()

void dqm_algorithms::BinsDiffFromStripMedian::printDescription ( std::ostream &  out)

Definition at line 411 of file BinsDiffFromStripMedian.cxx.

412 {
413 
414  out<<"BinsDiffFromStripMedian: Calculates smoothed strip median and then find out bins which are aliens "<<std::endl;
415 
416  out<<"Mandatory Green/Red Threshold is the value of outstandingRatio=(bin value)/(strip median) based on which to give Green/Red result\n"<<std::endl;
417 
418  out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
419  out<<"Optional Parameter: ignoreval: valued to be ignored for being processed"<<std::endl;
420  out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (on:1,off:0,default is 1)"<<std::endl;
421  out<<"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
422  out<<"Optional Parameter: VisualMode: is to make the evaluation process similar to the shift work, so one will get resonable result efficiently."<<std::endl;
423 
424 }

The documentation for this struct was generated from the following files:
mySortfunc
bool mySortfunc(const bin &i, const bin &j)
Definition: BinsDiffFromStripMedian.cxx:23
colorbin
Definition: BinsDiffFromStripMedian.h:53
colorcluster::m_phi
double m_phi
Definition: BinsDiffFromStripMedian.h:66
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
dqm_algorithms::BinsDiffFromStripMedian::BinsDiffFromStripMedian
BinsDiffFromStripMedian()
Definition: BinsDiffFromStripMedian.cxx:27
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
bin
Definition: BinsDiffFromStripMedian.h:43
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
bin::m_iy
int m_iy
Definition: BinsDiffFromStripMedian.h:48
mySortfunc_ratio
bool mySortfunc_ratio(const bin &i, const bin &j)
Definition: BinsDiffFromStripMedian.cxx:24
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
InDet::median
float median(std::vector< float > &Vec)
Definition: BTagVrtSec.cxx:35
CalPhi
double CalPhi(std::vector< colorbin > &LookAtList)
Definition: BinsDiffFromStripMedian.cxx:355
MCP::ScaleSmearParam::r2
@ r2
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
colorcluster::m_radius
double m_radius
Definition: BinsDiffFromStripMedian.h:67
bin::m_ix
int m_ix
Definition: BinsDiffFromStripMedian.h:47
colorcluster::m_eta
double m_eta
Definition: BinsDiffFromStripMedian.h:65
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
Trk::index3
@ index3
Definition: BoundarySurfaceFace.h:50
CalR
double CalR(std::vector< colorbin > &LookAtList, double eta, double phi)
Definition: BinsDiffFromStripMedian.cxx:375
Trk::index1
@ index1
Definition: BoundarySurfaceFace.h:48
yellow
@ yellow
Definition: BinsDiffFromStripMedian.h:18
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
colorcluster::m_value
double m_value
Definition: BinsDiffFromStripMedian.h:68
TRT_PAI_physicsConstants::r0
const double r0
electron radius{cm}
Definition: TRT_PAI_physicsConstants.h:20
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.handimod.Green
int Green
Definition: handimod.py:524
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
CalVal
double CalVal(std::vector< colorbin > &LookAtList)
Definition: BinsDiffFromStripMedian.cxx:367
colorcluster::m_size
int m_size
Definition: BinsDiffFromStripMedian.h:70
python.handimod.Red
Red
Definition: handimod.py:551
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
green
@ green
Definition: BinsDiffFromStripMedian.h:18
colorcluster
Definition: BinsDiffFromStripMedian.h:63
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::BinsDiffFromStripMedian::MakeCluster
colorcluster MakeCluster(const int r0, const int r2, bin &onebin, std::vector< std::vector< colorbin > > &ColorBinMap)
Definition: BinsDiffFromStripMedian.cxx:386
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
dqm_algorithms::BinsDiffFromStripMedian::FindStripMedian
void FindStripMedian(std::vector< double > onestrip, std::vector< double > &stripsMedian)
Definition: BinsDiffFromStripMedian.cxx:280
test_pyathena.counter
counter
Definition: test_pyathena.py:15
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
red
@ red
Definition: BinsDiffFromStripMedian.h:18
colorcluster::m_color
double m_color
Definition: BinsDiffFromStripMedian.h:69
CalEta
double CalEta(std::vector< colorbin > &LookAtList)
Definition: BinsDiffFromStripMedian.cxx:343
AddToList
void AddToList(const int r0, const int r2, int i, int j, std::vector< std::vector< colorbin > > &ColorBinMap, std::vector< colorbin > &LookAtList)
Definition: BinsDiffFromStripMedian.cxx:291
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528