CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTOccupancyClusterBuilder.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * $Date: 2010/07/20 02:58:23 $
6  * $Revision: 1.4 $
7  * \author G. Cerminara - INFN Torino
8  */
9 
12 
13 #include "TCanvas.h"
14 #include "TH2F.h"
15 
16 #include <algorithm>
17 #include <sstream>
18 #include <iostream>
19 
20 using namespace std;
21 using namespace edm;
22 
24  maxRMS(-1.) {
25 }
26 
28 
29 
30 
32  // loop over points already stored
33  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
34  theDistances[(*pt).distance(point)] = make_pair(*pt, point);
35  }
36  // cout << "[DTOccupancyClusterBuilder] Add point with mean: " << point.mean()
37  // << " RMS: " << point.rms() << endl;
38  thePoints.insert(point);
39 }
40 
41 
43  // cout << "[DTOccupancyClusterBuilder] buildClusters" << endl;
44  while(buildNewCluster()) {
45  // cout << "New cluster builded" << endl;
46  // cout << "# of remaining points: " << thePoints.size() << endl;
47  if(thePoints.size() <= 1) break;
48  }
49 
50  // build single point clusters with the remaining points
51  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end();
52  ++pt) {
53  DTOccupancyCluster clusterCandidate(*pt);
54  theClusters.push_back(clusterCandidate);
55  // store the range for building the histograms later
56  if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
57  if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
58  }
59  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
60  << " # of valid clusters: " << theClusters.size() << endl;
61  sortClusters();
62 
63 }
64 
65 
66 void DTOccupancyClusterBuilder::drawClusters(std::string canvasName) {
67  int nBinsX = 100;
68  int nBinsY = 100;
69  int colorMap[12] = {632, 600, 800, 400, 820, 416, 432, 880, 616, 860, 900, 920};
70 
71  // cout << "Draw clusters: " << endl;
72  // cout << " max mean: " << maxMean << " max rms: " << maxRMS << endl;
73 
74  TCanvas *canvas = new TCanvas(canvasName.c_str(),canvasName.c_str());
75  canvas->cd();
76  for(vector<DTOccupancyCluster>::const_iterator cluster = theClusters.begin();
77  cluster != theClusters.end(); ++cluster) {
78  stringstream stream;
79  stream << canvasName << "_" << cluster-theClusters.begin();
80  string histoName = stream.str();
81  TH2F *histo = (*cluster).getHisto(histoName, nBinsX, 0, maxMean+3*maxMean/100.,
82  nBinsY, 0, maxRMS+3*maxRMS/100., colorMap[cluster-theClusters.begin()]);
83  if(cluster == theClusters.begin())
84  histo->Draw("box");
85  else
86  histo->Draw("box,same");
87  }
88 }
89 
90 
91 std::pair<DTOccupancyPoint, DTOccupancyPoint> DTOccupancyClusterBuilder::getInitialPair() {
92  return theDistances.begin()->second;
93 }
94 
96  theDistances.clear();
97  for(set<DTOccupancyPoint>::const_iterator pt_i = thePoints.begin(); pt_i != thePoints.end();
98  ++pt_i) { // i loopo
99  for(set<DTOccupancyPoint>::const_iterator pt_j = thePoints.begin(); pt_j != thePoints.end();
100  ++pt_j) { // j loop
101  if(*pt_i != *pt_j) {
102  theDistances[pt_i->distance(*pt_j)] = make_pair(*pt_i, *pt_j);
103  }
104  }
105  }
106 }
107 
108 
109 
112  for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
113  theDistancesFromTheCluster[cluster.distance(*pt)] = *pt;
114  }
115 }
116 
117 
119  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
120  << "--------- New Cluster Candidate ----------------------" << endl;
121  pair<DTOccupancyPoint, DTOccupancyPoint> initialPair = getInitialPair();
122  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
123  << " Initial Pair: " << endl
124  << " point1: mean " << initialPair.first.mean()
125  << " rms " << initialPair.first.rms() << endl
126  << " point2: mean " << initialPair.second.mean()
127  << " rms " << initialPair.second.rms() << endl;
128  DTOccupancyCluster clusterCandidate(initialPair.first, initialPair.second);
129  if(clusterCandidate.isValid()) {
130  // cout << " cluster candidate is valid" << endl;
131  // remove already used pair
132  thePoints.erase(initialPair.first);
133  thePoints.erase(initialPair.second);
134  if(thePoints.size() != 0) {
135  computeDistancesToCluster(clusterCandidate);
136  while(clusterCandidate.addPoint(theDistancesFromTheCluster.begin()->second)) {
137  thePoints.erase(theDistancesFromTheCluster.begin()->second);
138  if(thePoints.size() ==0) break;
139  computeDistancesToCluster(clusterCandidate);
140  }
141  }
142  } else {
143  return false;
144  }
145  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
146  << " # of layers: " << clusterCandidate.nPoints()
147  << " avrg. mean: " << clusterCandidate.averageMean() << " avrg. rms: " << clusterCandidate.averageRMS() << endl;
148  theClusters.push_back(clusterCandidate);
149  // store the range for building the histograms later
150  if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
151  if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
153  return true;
154 }
155 
156 
157 
159  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder") << " sorting" << endl;
161  // we save the detid of the clusters which are not the best one
162  for(vector<DTOccupancyCluster>::const_iterator cluster = ++(theClusters.begin());
163  cluster != theClusters.end(); ++cluster) { // loop over clusters skipping the first
164  set<DTLayerId> clusterLayers = (*cluster).getLayerIDs();
165  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
166  << " # layers in the cluster: " << clusterLayers.size() << endl;
167  theProblematicLayers.insert(clusterLayers.begin(), clusterLayers.end());
168  }
169  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
170  << " # of problematic layers: " << theProblematicLayers.size() << endl;
171 }
172 
173 
175  return theClusters.front();
176 }
177 
179  if(theProblematicLayers.find(layerId) != theProblematicLayers.end()) {
180  return true;
181  }
182  return false;
183 }
bool isValid() const
Check if the cluster candidate satisfies the quality requirements.
DTOccupancyCluster getBestCluster() const
get the cluster correspondig to &quot;normal&quot; cell occupancy.
std::set< DTLayerId > theProblematicLayers
std::map< double, std::pair< DTOccupancyPoint, DTOccupancyPoint > > theDistances
std::map< double, DTOccupancyPoint > theDistancesFromTheCluster
double maxMean() const
max average cell occupancy of the layers in the cluster
def canvas
Definition: svgfig.py:481
double averageRMS() const
average RMS of the cell occpuancy distributions of the layers in the cluster
double maxRMS() const
max RMS of the cell occpuancy distributions of the layers in the cluster
std::set< DTOccupancyPoint > thePoints
bool addPoint(const DTOccupancyPoint &anotherPoint)
void drawClusters(std::string canvasName)
draw a TH2F histograms showing the clusters
#define LogTrace(id)
virtual ~DTOccupancyClusterBuilder()
Destructor.
double averageMean() const
average cell occupancy of the layers in the cluster
void computeDistancesToCluster(const DTOccupancyCluster &cluster)
void addPoint(const DTOccupancyPoint &point)
Add an occupancy point for a given layer.
void buildClusters()
build the clusters
std::pair< DTOccupancyPoint, DTOccupancyPoint > getInitialPair()
int nPoints() const
of layers belonging to the cluster
std::vector< DTOccupancyCluster > theClusters
bool isProblematic(DTLayerId layerId) const
bool clusterIsLessThan(const DTOccupancyCluster &clusterOne, const DTOccupancyCluster &clusterTwo)
for DTOccupancyCluster sorting
double distance(const DTOccupancyPoint &point) const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5