test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
DTOccupancyClusterBuilder Class Reference

#include <DTOccupancyClusterBuilder.h>

Public Member Functions

void addPoint (const DTOccupancyPoint &point)
 Add an occupancy point for a given layer. More...
 
void buildClusters ()
 build the clusters More...
 
void drawClusters (std::string canvasName)
 draw a TH2F histograms showing the clusters More...
 
 DTOccupancyClusterBuilder ()
 Constructor. More...
 
DTOccupancyCluster getBestCluster () const
 get the cluster correspondig to "normal" cell occupancy. More...
 
bool isProblematic (DTLayerId layerId) const
 
virtual ~DTOccupancyClusterBuilder ()
 Destructor. More...
 

Private Member Functions

bool buildNewCluster ()
 
void computeDistancesToCluster (const DTOccupancyCluster &cluster)
 
void computePointToPointDistances ()
 
std::pair< DTOccupancyPoint,
DTOccupancyPoint
getInitialPair ()
 
void sortClusters ()
 

Private Attributes

double maxMean
 
double maxRMS
 
std::vector< DTOccupancyClustertheClusters
 
std::map< double, std::pair
< DTOccupancyPoint,
DTOccupancyPoint > > 
theDistances
 
std::map< double,
DTOccupancyPoint
theDistancesFromTheCluster
 
std::set< DTOccupancyPointthePoints
 
std::set< DTLayerIdtheProblematicLayers
 

Detailed Description

Build clusters of layer occupancies (DTOccupancyCluster) to spot problematic layers. It's used by DTOccupancyTest.

Author
G. Cerminara - INFN Torino

Definition at line 20 of file DTOccupancyClusterBuilder.h.

Constructor & Destructor Documentation

DTOccupancyClusterBuilder::DTOccupancyClusterBuilder ( )

Constructor.

Definition at line 21 of file DTOccupancyClusterBuilder.cc.

DTOccupancyClusterBuilder::~DTOccupancyClusterBuilder ( )
virtual

Destructor.

Definition at line 25 of file DTOccupancyClusterBuilder.cc.

25 {}

Member Function Documentation

void DTOccupancyClusterBuilder::addPoint ( const DTOccupancyPoint point)

Add an occupancy point for a given layer.

Definition at line 29 of file DTOccupancyClusterBuilder.cc.

References RecoTauCleanerPlugins::pt, theDistances, and thePoints.

Referenced by DTOccupancyTest::runOccupancyTest().

29  {
30  // loop over points already stored
31  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
32  theDistances[(*pt).distance(point)] = make_pair(*pt, point);
33  }
34  // cout << "[DTOccupancyClusterBuilder] Add point with mean: " << point.mean()
35  // << " RMS: " << point.rms() << endl;
36  thePoints.insert(point);
37 }
std::map< double, std::pair< DTOccupancyPoint, DTOccupancyPoint > > theDistances
std::set< DTOccupancyPoint > thePoints
void DTOccupancyClusterBuilder::buildClusters ( )

build the clusters

Definition at line 40 of file DTOccupancyClusterBuilder.cc.

References buildNewCluster(), LogTrace, DTOccupancyCluster::maxMean(), maxMean, DTOccupancyCluster::maxRMS(), maxRMS, RecoTauCleanerPlugins::pt, sortClusters(), theClusters, and thePoints.

Referenced by DTOccupancyTest::runOccupancyTest().

40  {
41  // cout << "[DTOccupancyClusterBuilder] buildClusters" << endl;
42  while(buildNewCluster()) {
43  // cout << "New cluster builded" << endl;
44  // cout << "# of remaining points: " << thePoints.size() << endl;
45  if(thePoints.size() <= 1) break;
46  }
47 
48  // build single point clusters with the remaining points
49  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end();
50  ++pt) {
51  DTOccupancyCluster clusterCandidate(*pt);
52  theClusters.push_back(clusterCandidate);
53  // store the range for building the histograms later
54  if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
55  if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
56  }
57  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
58  << " # of valid clusters: " << theClusters.size() << endl;
59  sortClusters();
60 
61 }
std::set< DTOccupancyPoint > thePoints
#define LogTrace(id)
std::vector< DTOccupancyCluster > theClusters
bool DTOccupancyClusterBuilder::buildNewCluster ( )
private

Definition at line 116 of file DTOccupancyClusterBuilder.cc.

References DTOccupancyCluster::addPoint(), DTOccupancyCluster::averageMean(), DTOccupancyCluster::averageRMS(), computeDistancesToCluster(), computePointToPointDistances(), getInitialPair(), DTOccupancyCluster::isValid(), LogTrace, DTOccupancyCluster::maxMean(), maxMean, DTOccupancyCluster::maxRMS(), maxRMS, DTOccupancyCluster::nPoints(), theClusters, theDistancesFromTheCluster, and thePoints.

Referenced by buildClusters().

116  {
117  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
118  << "--------- New Cluster Candidate ----------------------" << endl;
119  pair<DTOccupancyPoint, DTOccupancyPoint> initialPair = getInitialPair();
120  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
121  << " Initial Pair: " << endl
122  << " point1: mean " << initialPair.first.mean()
123  << " rms " << initialPair.first.rms() << endl
124  << " point2: mean " << initialPair.second.mean()
125  << " rms " << initialPair.second.rms() << endl;
126  DTOccupancyCluster clusterCandidate(initialPair.first, initialPair.second);
127  if(clusterCandidate.isValid()) {
128  // cout << " cluster candidate is valid" << endl;
129  // remove already used pair
130  thePoints.erase(initialPair.first);
131  thePoints.erase(initialPair.second);
132  if(thePoints.size() != 0) {
133  computeDistancesToCluster(clusterCandidate);
134  while(clusterCandidate.addPoint(theDistancesFromTheCluster.begin()->second)) {
135  thePoints.erase(theDistancesFromTheCluster.begin()->second);
136  if(thePoints.size() ==0) break;
137  computeDistancesToCluster(clusterCandidate);
138  }
139  }
140  } else {
141  return false;
142  }
143  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
144  << " # of layers: " << clusterCandidate.nPoints()
145  << " avrg. mean: " << clusterCandidate.averageMean() << " avrg. rms: " << clusterCandidate.averageRMS() << endl;
146  theClusters.push_back(clusterCandidate);
147  // store the range for building the histograms later
148  if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
149  if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
151  return true;
152 }
std::map< double, DTOccupancyPoint > theDistancesFromTheCluster
std::set< DTOccupancyPoint > thePoints
#define LogTrace(id)
void computeDistancesToCluster(const DTOccupancyCluster &cluster)
std::pair< DTOccupancyPoint, DTOccupancyPoint > getInitialPair()
std::vector< DTOccupancyCluster > theClusters
void DTOccupancyClusterBuilder::computeDistancesToCluster ( const DTOccupancyCluster cluster)
private

Definition at line 108 of file DTOccupancyClusterBuilder.cc.

References DTOccupancyCluster::distance(), RecoTauCleanerPlugins::pt, theDistancesFromTheCluster, and thePoints.

Referenced by buildNewCluster().

108  {
110  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
112  }
113 }
std::map< double, DTOccupancyPoint > theDistancesFromTheCluster
std::set< DTOccupancyPoint > thePoints
double distance(const DTOccupancyPoint &point) const
void DTOccupancyClusterBuilder::computePointToPointDistances ( )
private

Definition at line 93 of file DTOccupancyClusterBuilder.cc.

References theDistances, and thePoints.

Referenced by buildNewCluster().

93  {
94  theDistances.clear();
95  for(set<DTOccupancyPoint>::const_iterator pt_i = thePoints.begin(); pt_i != thePoints.end();
96  ++pt_i) { // i loopo
97  for(set<DTOccupancyPoint>::const_iterator pt_j = thePoints.begin(); pt_j != thePoints.end();
98  ++pt_j) { // j loop
99  if(*pt_i != *pt_j) {
100  theDistances[pt_i->distance(*pt_j)] = make_pair(*pt_i, *pt_j);
101  }
102  }
103  }
104 }
std::map< double, std::pair< DTOccupancyPoint, DTOccupancyPoint > > theDistances
std::set< DTOccupancyPoint > thePoints
void DTOccupancyClusterBuilder::drawClusters ( std::string  canvasName)

draw a TH2F histograms showing the clusters

Definition at line 64 of file DTOccupancyClusterBuilder.cc.

References svgfig::canvas(), timingPdfMaker::histo, maxMean, maxRMS, edmStreamStallGrapher::stream, and theClusters.

64  {
65  int nBinsX = 100;
66  int nBinsY = 100;
67  int colorMap[12] = {632, 600, 800, 400, 820, 416, 432, 880, 616, 860, 900, 920};
68 
69  // cout << "Draw clusters: " << endl;
70  // cout << " max mean: " << maxMean << " max rms: " << maxRMS << endl;
71 
72  TCanvas *canvas = new TCanvas(canvasName.c_str(),canvasName.c_str());
73  canvas->cd();
74  for(vector<DTOccupancyCluster>::const_iterator cluster = theClusters.begin();
75  cluster != theClusters.end(); ++cluster) {
76  stringstream stream;
77  stream << canvasName << "_" << cluster-theClusters.begin();
78  string histoName = stream.str();
79  TH2F *histo = (*cluster).getHisto(histoName, nBinsX, 0, maxMean+3*maxMean/100.,
80  nBinsY, 0, maxRMS+3*maxRMS/100., colorMap[cluster-theClusters.begin()]);
81  if(cluster == theClusters.begin())
82  histo->Draw("box");
83  else
84  histo->Draw("box,same");
85  }
86 }
def canvas
Definition: svgfig.py:481
std::vector< DTOccupancyCluster > theClusters
DTOccupancyCluster DTOccupancyClusterBuilder::getBestCluster ( ) const

get the cluster correspondig to "normal" cell occupancy.

Definition at line 172 of file DTOccupancyClusterBuilder.cc.

References theClusters.

Referenced by DTOccupancyTest::runOccupancyTest().

172  {
173  return theClusters.front();
174 }
std::vector< DTOccupancyCluster > theClusters
std::pair< DTOccupancyPoint, DTOccupancyPoint > DTOccupancyClusterBuilder::getInitialPair ( )
private

Definition at line 89 of file DTOccupancyClusterBuilder.cc.

References theDistances.

Referenced by buildNewCluster().

89  {
90  return theDistances.begin()->second;
91 }
std::map< double, std::pair< DTOccupancyPoint, DTOccupancyPoint > > theDistances
bool DTOccupancyClusterBuilder::isProblematic ( DTLayerId  layerId) const

Definition at line 176 of file DTOccupancyClusterBuilder.cc.

References theProblematicLayers.

Referenced by DTOccupancyTest::runOccupancyTest().

176  {
177  if(theProblematicLayers.find(layerId) != theProblematicLayers.end()) {
178  return true;
179  }
180  return false;
181 }
std::set< DTLayerId > theProblematicLayers
void DTOccupancyClusterBuilder::sortClusters ( )
private

Definition at line 156 of file DTOccupancyClusterBuilder.cc.

References clusterIsLessThan(), LogTrace, python.multivaluedict::sort(), theClusters, and theProblematicLayers.

Referenced by buildClusters().

156  {
157  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder") << " sorting" << endl;
159  // we save the detid of the clusters which are not the best one
160  for(vector<DTOccupancyCluster>::const_iterator cluster = ++(theClusters.begin());
161  cluster != theClusters.end(); ++cluster) { // loop over clusters skipping the first
162  set<DTLayerId> clusterLayers = (*cluster).getLayerIDs();
163  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
164  << " # layers in the cluster: " << clusterLayers.size() << endl;
165  theProblematicLayers.insert(clusterLayers.begin(), clusterLayers.end());
166  }
167  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
168  << " # of problematic layers: " << theProblematicLayers.size() << endl;
169 }
std::set< DTLayerId > theProblematicLayers
#define LogTrace(id)
std::vector< DTOccupancyCluster > theClusters
bool clusterIsLessThan(const DTOccupancyCluster &clusterOne, const DTOccupancyCluster &clusterTwo)
for DTOccupancyCluster sorting

Member Data Documentation

double DTOccupancyClusterBuilder::maxMean
private

Definition at line 62 of file DTOccupancyClusterBuilder.h.

Referenced by buildClusters(), buildNewCluster(), and drawClusters().

double DTOccupancyClusterBuilder::maxRMS
private

Definition at line 63 of file DTOccupancyClusterBuilder.h.

Referenced by buildClusters(), buildNewCluster(), and drawClusters().

std::vector<DTOccupancyCluster> DTOccupancyClusterBuilder::theClusters
private
std::map<double, std::pair<DTOccupancyPoint, DTOccupancyPoint> > DTOccupancyClusterBuilder::theDistances
private
std::map<double, DTOccupancyPoint> DTOccupancyClusterBuilder::theDistancesFromTheCluster
private

Definition at line 58 of file DTOccupancyClusterBuilder.h.

Referenced by buildNewCluster(), and computeDistancesToCluster().

std::set<DTOccupancyPoint> DTOccupancyClusterBuilder::thePoints
private
std::set<DTLayerId> DTOccupancyClusterBuilder::theProblematicLayers
private

Definition at line 60 of file DTOccupancyClusterBuilder.h.

Referenced by isProblematic(), and sortClusters().