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