Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DTOccupancyCluster.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012
00013 #include "TH2F.h"
00014 #include "TMath.h"
00015
00016 #include <iostream>
00017
00018 using namespace std;
00019 using namespace edm;
00020
00021
00022 DTOccupancyCluster::DTOccupancyCluster(const DTOccupancyPoint& firstPoint,
00023 const DTOccupancyPoint& secondPoint) : radius(0),
00024 theMaxMean(-1.),
00025 theMaxRMS(-1.),
00026 theMeanSum(0.),
00027 theRMSSum(0.) {
00028 if(!qualityCriterion(firstPoint,secondPoint)) {
00029 theValidity = false;
00030 } else {
00031
00032 thePoints.push_back(firstPoint);
00033 thePoints.push_back(secondPoint);
00034 if(firstPoint.mean() > secondPoint.mean()) theMaxMean = firstPoint.mean();
00035 else theMaxMean = secondPoint.mean();
00036
00037 if(firstPoint.rms() > secondPoint.rms()) theMaxRMS = firstPoint.rms();
00038 else theMaxRMS = secondPoint.rms();
00039 theMeanSum += firstPoint.mean();
00040 theRMSSum += firstPoint.rms();
00041
00042 theMeanSum += secondPoint.mean();
00043 theRMSSum += secondPoint.rms();
00044
00045
00046 computeRadius();
00047 }
00048 }
00049
00050
00051
00052 DTOccupancyCluster::DTOccupancyCluster(const DTOccupancyPoint& singlePoint) : radius(0),
00053 theMaxMean(singlePoint.mean()),
00054 theMaxRMS(singlePoint.rms()),
00055 theMeanSum(singlePoint.mean()),
00056 theRMSSum(singlePoint.rms()) {
00057 theValidity = true;
00058
00059
00060 thePoints.push_back(singlePoint);
00061 }
00062
00063
00064
00065 DTOccupancyCluster::~DTOccupancyCluster(){}
00066
00067
00068
00069
00070 bool DTOccupancyCluster::isValid() const {
00071 return theValidity;
00072 }
00073
00074
00075
00076
00077
00078 bool DTOccupancyCluster::addPoint(const DTOccupancyPoint& anotherPoint) {
00079 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyCluster")
00080 << " Add a point to the cluster: mean: " << anotherPoint.mean()
00081 << " rms: " << anotherPoint.rms() << endl;
00082 if(qualityCriterion(anotherPoint)) {
00083 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyCluster") << " point is valid" << endl;
00084 thePoints.push_back(anotherPoint);
00085
00086 computeRadius();
00087
00088 if(anotherPoint.mean() > theMaxMean) {
00089 theMaxMean = anotherPoint.mean();
00090 }
00091 if(anotherPoint.rms() > theMaxRMS) {
00092 theMaxRMS = anotherPoint.rms();
00093 }
00094 theMeanSum += anotherPoint.mean();
00095 theRMSSum += anotherPoint.rms();
00096 return true;
00097 }
00098 return false;
00099 }
00100
00101
00102
00103
00104
00105 double DTOccupancyCluster::distance(const DTOccupancyPoint& point) const {
00106 double dist = 99999999;
00107
00108 for(vector<DTOccupancyPoint>::const_iterator pt = thePoints.begin();
00109 pt != thePoints.end(); ++pt) {
00110 double distance = point.distance(*pt);
00111 if(distance < dist) {
00112 dist = distance;
00113 }
00114 }
00115 return dist;
00116 }
00117
00118
00119
00120 double DTOccupancyCluster::averageMean() const {
00121 return theMeanSum/(double)thePoints.size();
00122 }
00123
00124
00125
00126 double DTOccupancyCluster::averageRMS() const {
00127 return theRMSSum/(double)thePoints.size();
00128 }
00129
00130
00131
00132 double DTOccupancyCluster::maxMean() const {
00133 return theMaxMean;
00134 }
00135
00136
00137
00138 double DTOccupancyCluster::maxRMS() const {
00139 return theMaxRMS;
00140 }
00141
00142
00143
00144 TH2F * DTOccupancyCluster::getHisto(std::string histoName, int nBinsX, double minX, double maxX,
00145 int nBinsY, double minY, double maxY, int fillColor) const {
00146 TH2F *histo = new TH2F(histoName.c_str(),histoName.c_str(),
00147 nBinsX, minX, maxX, nBinsY, minY, maxY);
00148 histo->SetFillColor(fillColor);
00149 for(vector<DTOccupancyPoint>::const_iterator pt = thePoints.begin();
00150 pt != thePoints.end(); ++pt) {
00151 histo->Fill((*pt).mean(), (*pt).rms());
00152 }
00153 return histo;
00154 }
00155
00156
00157
00158 bool DTOccupancyCluster::qualityCriterion(const DTOccupancyPoint& firstPoint,
00159 const DTOccupancyPoint& secondPoint) {
00160
00161
00162
00163
00164
00165 if(firstPoint.deltaMean(secondPoint) < computeAverageRMS(firstPoint, secondPoint) &&
00166 firstPoint.deltaRMS(secondPoint) < computeMinRMS(firstPoint, secondPoint)) {
00167 theValidity = true;
00168
00169 return true;
00170 }
00171
00172 theValidity = false;
00173 return false;
00174 }
00175
00176
00177
00178
00179 bool DTOccupancyCluster::qualityCriterion(const DTOccupancyPoint& anotherPoint) {
00180
00181
00182 double minrms = 0;
00183 if(anotherPoint.rms() < averageRMS()) minrms = anotherPoint.rms();
00184 else minrms = averageRMS();
00185
00186
00187
00188
00189
00190
00191
00192
00193 if(fabs(averageMean() - anotherPoint.mean()) < averageRMS() &&
00194 fabs(averageRMS() - anotherPoint.rms()) < 2*minrms/3.) {
00195 theValidity = true;
00196
00197 return true;
00198 }
00199
00200 theValidity = false;
00201 return false;
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 }
00212
00213
00214
00215
00216 void DTOccupancyCluster::computeRadius() {
00217 double radius_squared = 0;
00218 for(vector<DTOccupancyPoint>::const_iterator pt_i = thePoints.begin();
00219 pt_i != thePoints.end(); ++pt_i) {
00220 for(vector<DTOccupancyPoint>::const_iterator pt_j = thePoints.begin();
00221 pt_j != thePoints.end(); ++pt_j) {
00222 radius_squared += TMath::Power(pt_i->distance(*pt_j),2);
00223 }
00224 }
00225 radius_squared = radius_squared/(2*TMath::Power(thePoints.size()+1,2));
00226 radius = sqrt(radius_squared);
00227
00228 }
00229
00230
00231
00232 int DTOccupancyCluster::nPoints() const {
00233 return thePoints.size();
00234 }
00235
00236
00237 set<DTLayerId> DTOccupancyCluster::getLayerIDs() const {
00238 set<DTLayerId> ret;
00239 for(vector<DTOccupancyPoint>::const_iterator point = thePoints.begin();
00240 point != thePoints.end(); ++point) {
00241 ret.insert((*point).layerId());
00242 }
00243 return ret;
00244 }
00245
00246
00247 bool clusterIsLessThan(const DTOccupancyCluster& clusterOne, const DTOccupancyCluster& clusterTwo) {
00248 if(clusterTwo.nPoints() == 1 && clusterOne.nPoints() != 1) {
00249 return true;
00250 }
00251 if(clusterTwo.nPoints() != 1 && clusterOne.nPoints() == 1) {
00252 return false;
00253 }
00254
00255 if(clusterOne.nPoints() > clusterTwo.nPoints()) {
00256 return true;
00257 } else if(clusterOne.nPoints() < clusterTwo.nPoints()) {
00258 return false;
00259 } else {
00260 if(fabs(clusterOne.averageRMS() - sqrt(clusterOne.averageMean())) <
00261 fabs(clusterTwo.averageRMS() - sqrt(clusterTwo.averageMean()))) {
00262 return true;
00263 }
00264 }
00265 return false;
00266
00267 }
00268
00269