CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTOccupancyCluster.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Cerminara - INFN Torino
6  */
7 
8 #include "DTOccupancyCluster.h"
10 
11 #include "TH2F.h"
12 #include "TMath.h"
13 
14 #include <iostream>
15 
16 using namespace std;
17 using namespace edm;
18 
19 
21  const DTOccupancyPoint& secondPoint) : radius(0),
22  theMaxMean(-1.),
23  theMaxRMS(-1.),
24  theMeanSum(0.),
25  theRMSSum(0.) {
26  if(!qualityCriterion(firstPoint,secondPoint)) {
27  theValidity = false;
28  } else {
29  // compute the cluster quantities
30  thePoints.push_back(firstPoint);
31  thePoints.push_back(secondPoint);
32  if(firstPoint.mean() > secondPoint.mean()) theMaxMean = firstPoint.mean();
33  else theMaxMean = secondPoint.mean();
34 
35  if(firstPoint.rms() > secondPoint.rms()) theMaxRMS = firstPoint.rms();
36  else theMaxRMS = secondPoint.rms();
37  theMeanSum += firstPoint.mean();
38  theRMSSum += firstPoint.rms();
39 
40  theMeanSum += secondPoint.mean();
41  theRMSSum += secondPoint.rms();
42 
43 
44  computeRadius();
45  }
46 }
47 
48 
49 
51  theMaxMean(singlePoint.mean()),
52  theMaxRMS(singlePoint.rms()),
53  theMeanSum(singlePoint.mean()),
54  theRMSSum(singlePoint.rms()) {
55  theValidity = true;
56 
57  // compute the cluster quantities
58  thePoints.push_back(singlePoint);
59 }
60 
61 
62 
64 
65 
66 
67  // Check if the cluster candidate satisfies the quality requirements
69  return theValidity;
70 }
71 
72 
73 
74 // Add a point to the cluster: returns false if the point does not satisfy the
75 // quality requirement
77  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyCluster")
78  << " Add a point to the cluster: mean: " << anotherPoint.mean()
79  << " rms: " << anotherPoint.rms() << endl;
80  if(qualityCriterion(anotherPoint)) {
81  LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyCluster") << " point is valid" << endl;
82  thePoints.push_back(anotherPoint);
83  // Compute the new cluster size
84  computeRadius();
85  // compute the max mean and RMS
86  if(anotherPoint.mean() > theMaxMean) {
87  theMaxMean = anotherPoint.mean();
88  }
89  if(anotherPoint.rms() > theMaxRMS) {
90  theMaxRMS = anotherPoint.rms();
91  }
92  theMeanSum += anotherPoint.mean();
93  theRMSSum += anotherPoint.rms();
94  return true;
95  }
96  return false;
97 }
98 
99 
100 
101 // Compute the distance of a single point from the cluster
102 // (minimum distance with respect to the cluster points)
104  double dist = 99999999;
105  // compute the minimum distance from a point
106  for(vector<DTOccupancyPoint>::const_iterator pt = thePoints.begin();
107  pt != thePoints.end(); ++pt) {
108  double distance = point.distance(*pt);
109  if(distance < dist) {
110  dist = distance;
111  }
112  }
113  return dist;
114 }
115 
116 
117 
119  return theMeanSum/(double)thePoints.size();
120 }
121 
122 
123 
125  return theRMSSum/(double)thePoints.size();
126 }
127 
128 
129 
131  return theMaxMean;
132 }
133 
134 
135 
137  return theMaxRMS;
138 }
139 
140 
141 
142 TH2F * DTOccupancyCluster::getHisto(std::string histoName, int nBinsX, double minX, double maxX,
143  int nBinsY, double minY, double maxY, int fillColor) const {
144  TH2F *histo = new TH2F(histoName.c_str(),histoName.c_str(),
145  nBinsX, minX, maxX, nBinsY, minY, maxY);
146  histo->SetFillColor(fillColor);
147  for(vector<DTOccupancyPoint>::const_iterator pt = thePoints.begin();
148  pt != thePoints.end(); ++pt) {
149  histo->Fill((*pt).mean(), (*pt).rms());
150  }
151  return histo;
152 }
153 
154 
155 
157  const DTOccupancyPoint& secondPoint) {
158  // cout << " Seed qualityCriterion results: " << endl;
159  // cout << " delta mean: " << firstPoint.deltaMean(secondPoint) << endl;
160  // cout << " delta rms: " << firstPoint.deltaRMS(secondPoint) << endl;
161  // cout << " average rms: " << computeAverageRMS(firstPoint, secondPoint) << endl;
162  // cout << " min rms: " << computeMinRMS(firstPoint, secondPoint) << endl;
163  if(firstPoint.deltaMean(secondPoint) < computeAverageRMS(firstPoint, secondPoint) &&
164  firstPoint.deltaRMS(secondPoint) < computeMinRMS(firstPoint, secondPoint)) {
165  theValidity = true;
166  // cout << " seed is valid!" << endl;
167  return true;
168  }
169  // cout << " seed is not valid!" << endl;
170  theValidity = false;
171  return false;
172 }
173 
174 
175 
176 
178  // double minDistance = distance(anotherPoint);
179 
180  double minrms = 0;
181  if(anotherPoint.rms() < averageRMS()) minrms = anotherPoint.rms();
182  else minrms = averageRMS();
183 
184  // cout << " delta mean: " << fabs(averageMean() - anotherPoint.mean()) << endl;
185  // cout << " average RMS: " << fabs(averageRMS() + anotherPoint.rms())/2. << endl;
186  // cout << " delta rms: " << fabs(averageRMS() - anotherPoint.rms()) << endl;
187  // cout << " min rms: " << minrms << endl;
188  // if(fabs(averageMean() - anotherPoint.mean()) < fabs(averageRMS() + anotherPoint.rms())/2. &&
189  // fabs(averageRMS() - anotherPoint.rms()) < minrms) {
190 
191  if(fabs(averageMean() - anotherPoint.mean()) < averageRMS() &&
192  fabs(averageRMS() - anotherPoint.rms()) < 2*minrms/3.) {
193  theValidity = true;
194  // cout << " point is valid!" << endl;
195  return true;
196  }
197  // cout << " point is not valid!" << endl;
198  theValidity = false;
199  return false;
200 
201  // if(thePoints.size() == 1) return false;
202  // // Get the minimum distance from the point
203  // double minDistance = distance(anotherPoint);
204  // cout << " min distance from cluster is: " << minDistance << endl;
205  // cout << " radius is: " << radius << endl;
206  // // compare the minimum distance with the radius;
207  // if(minDistance < 2*radius) return true;
208  // else return false;
209 }
210 
211 
212 
213 
215  double radius_squared = 0;
216  for(vector<DTOccupancyPoint>::const_iterator pt_i = thePoints.begin();
217  pt_i != thePoints.end(); ++pt_i) {
218  for(vector<DTOccupancyPoint>::const_iterator pt_j = thePoints.begin();
219  pt_j != thePoints.end(); ++pt_j) {
220  radius_squared += TMath::Power(pt_i->distance(*pt_j),2);
221  }
222  }
223  radius_squared = radius_squared/(2*TMath::Power(thePoints.size()+1,2));
224  radius = sqrt(radius_squared);
225  // cout << " the new cluster radius is: " << radius << endl;
226 }
227 
228 
229 
231  return thePoints.size();
232 }
233 
234 
235 set<DTLayerId> DTOccupancyCluster::getLayerIDs() const {
236  set<DTLayerId> ret;
237  for(vector<DTOccupancyPoint>::const_iterator point = thePoints.begin();
238  point != thePoints.end(); ++point) {
239  ret.insert((*point).layerId());
240  }
241  return ret;
242 }
243 
244 
245 bool clusterIsLessThan(const DTOccupancyCluster& clusterOne, const DTOccupancyCluster& clusterTwo) {
246  if(clusterTwo.nPoints() == 1 && clusterOne.nPoints() != 1) {
247  return true;
248  }
249  if(clusterTwo.nPoints() != 1 && clusterOne.nPoints() == 1) {
250  return false;
251  }
252 
253  if(clusterOne.nPoints() > clusterTwo.nPoints()) {
254  return true;
255  } else if(clusterOne.nPoints() < clusterTwo.nPoints()) {
256  return false;
257  } else {
258  if(fabs(clusterOne.averageRMS() - sqrt(clusterOne.averageMean())) <
259  fabs(clusterTwo.averageRMS() - sqrt(clusterTwo.averageMean()))) {
260  return true;
261  }
262  }
263  return false;
264 
265 }
266 
267 
bool isValid() const
Check if the cluster candidate satisfies the quality requirements.
double mean() const
average cell occupancy in the layer
DTOccupancyCluster(const DTOccupancyPoint &firstPoint, const DTOccupancyPoint &secondPoint)
Constructor.
double deltaMean(const DTOccupancyPoint &anotherPoint) const
TH2F * getHisto(std::string histoName, int nBinsX, double minX, double maxX, int nBinsY, double minY, double maxY, int fillColor) const
get a TH2F displaying the cluster
double computeAverageRMS(const DTOccupancyPoint &onePoint, const DTOccupancyPoint &anotherPoint)
double maxMean() const
max average cell occupancy of the layers in the cluster
double deltaRMS(const DTOccupancyPoint &anotherPoint) const
double averageRMS() const
average RMS of the cell occpuancy distributions of the layers in the cluster
double rms() const
RMS of the distribution of the cell occupancies in the layer.
double computeMinRMS(const DTOccupancyPoint &onePoint, const DTOccupancyPoint &anotherPoint)
double maxRMS() const
max RMS of the cell occpuancy distributions of the layers in the cluster
std::vector< DTOccupancyPoint > thePoints
T sqrt(T t)
Definition: SSEVec.h:48
bool addPoint(const DTOccupancyPoint &anotherPoint)
#define LogTrace(id)
double averageMean() const
average cell occupancy of the layers in the cluster
int nPoints() const
of layers belonging to the cluster
virtual ~DTOccupancyCluster()
Destructor.
double distance(const DTOccupancyPoint &anotherPoint) const
distance from another point in the 2D plane
std::set< DTLayerId > getLayerIDs() 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
bool qualityCriterion(const DTOccupancyPoint &firstPoint, const DTOccupancyPoint &secondPoint)