Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DTOccupancyClusterBuilder.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012
00013 #include "TCanvas.h"
00014 #include "TH2F.h"
00015
00016 #include <algorithm>
00017 #include <sstream>
00018 #include <iostream>
00019
00020 using namespace std;
00021 using namespace edm;
00022
00023 DTOccupancyClusterBuilder:: DTOccupancyClusterBuilder() : maxMean(-1.),
00024 maxRMS(-1.) {
00025 }
00026
00027 DTOccupancyClusterBuilder::~DTOccupancyClusterBuilder(){}
00028
00029
00030
00031 void DTOccupancyClusterBuilder::addPoint(const DTOccupancyPoint& point) {
00032
00033 for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
00034 theDistances[(*pt).distance(point)] = make_pair(*pt, point);
00035 }
00036
00037
00038 thePoints.insert(point);
00039 }
00040
00041
00042 void DTOccupancyClusterBuilder::buildClusters() {
00043
00044 while(buildNewCluster()) {
00045
00046
00047 if(thePoints.size() <= 1) break;
00048 }
00049
00050
00051 for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end();
00052 ++pt) {
00053 DTOccupancyCluster clusterCandidate(*pt);
00054 theClusters.push_back(clusterCandidate);
00055
00056 if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
00057 if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
00058 }
00059 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00060 << " # of valid clusters: " << theClusters.size() << endl;
00061 sortClusters();
00062
00063 }
00064
00065
00066 void DTOccupancyClusterBuilder::drawClusters(std::string canvasName) {
00067 int nBinsX = 100;
00068 int nBinsY = 100;
00069 int colorMap[12] = {632, 600, 800, 400, 820, 416, 432, 880, 616, 860, 900, 920};
00070
00071
00072
00073
00074 TCanvas *canvas = new TCanvas(canvasName.c_str(),canvasName.c_str());
00075 canvas->cd();
00076 for(vector<DTOccupancyCluster>::const_iterator cluster = theClusters.begin();
00077 cluster != theClusters.end(); ++cluster) {
00078 stringstream stream;
00079 stream << canvasName << "_" << cluster-theClusters.begin();
00080 string histoName = stream.str();
00081 TH2F *histo = (*cluster).getHisto(histoName, nBinsX, 0, maxMean+3*maxMean/100.,
00082 nBinsY, 0, maxRMS+3*maxRMS/100., colorMap[cluster-theClusters.begin()]);
00083 if(cluster == theClusters.begin())
00084 histo->Draw("box");
00085 else
00086 histo->Draw("box,same");
00087 }
00088 }
00089
00090
00091 std::pair<DTOccupancyPoint, DTOccupancyPoint> DTOccupancyClusterBuilder::getInitialPair() {
00092 return theDistances.begin()->second;
00093 }
00094
00095 void DTOccupancyClusterBuilder::computePointToPointDistances() {
00096 theDistances.clear();
00097 for(set<DTOccupancyPoint>::const_iterator pt_i = thePoints.begin(); pt_i != thePoints.end();
00098 ++pt_i) {
00099 for(set<DTOccupancyPoint>::const_iterator pt_j = thePoints.begin(); pt_j != thePoints.end();
00100 ++pt_j) {
00101 if(*pt_i != *pt_j) {
00102 theDistances[pt_i->distance(*pt_j)] = make_pair(*pt_i, *pt_j);
00103 }
00104 }
00105 }
00106 }
00107
00108
00109
00110 void DTOccupancyClusterBuilder::computeDistancesToCluster(const DTOccupancyCluster& cluster) {
00111 theDistancesFromTheCluster.clear();
00112 for(set<DTOccupancyPoint>::const_iterator pt = thePoints.begin(); pt != thePoints.end(); ++pt) {
00113 theDistancesFromTheCluster[cluster.distance(*pt)] = *pt;
00114 }
00115 }
00116
00117
00118 bool DTOccupancyClusterBuilder::buildNewCluster() {
00119 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00120 << "--------- New Cluster Candidate ----------------------" << endl;
00121 pair<DTOccupancyPoint, DTOccupancyPoint> initialPair = getInitialPair();
00122 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00123 << " Initial Pair: " << endl
00124 << " point1: mean " << initialPair.first.mean()
00125 << " rms " << initialPair.first.rms() << endl
00126 << " point2: mean " << initialPair.second.mean()
00127 << " rms " << initialPair.second.rms() << endl;
00128 DTOccupancyCluster clusterCandidate(initialPair.first, initialPair.second);
00129 if(clusterCandidate.isValid()) {
00130
00131
00132 thePoints.erase(initialPair.first);
00133 thePoints.erase(initialPair.second);
00134 if(thePoints.size() != 0) {
00135 computeDistancesToCluster(clusterCandidate);
00136 while(clusterCandidate.addPoint(theDistancesFromTheCluster.begin()->second)) {
00137 thePoints.erase(theDistancesFromTheCluster.begin()->second);
00138 if(thePoints.size() ==0) break;
00139 computeDistancesToCluster(clusterCandidate);
00140 }
00141 }
00142 } else {
00143 return false;
00144 }
00145 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00146 << " # of layers: " << clusterCandidate.nPoints()
00147 << " avrg. mean: " << clusterCandidate.averageMean() << " avrg. rms: " << clusterCandidate.averageRMS() << endl;
00148 theClusters.push_back(clusterCandidate);
00149
00150 if(clusterCandidate.maxMean() > maxMean) maxMean = clusterCandidate.maxMean();
00151 if(clusterCandidate.maxRMS() > maxRMS) maxRMS = clusterCandidate.maxRMS();
00152 computePointToPointDistances();
00153 return true;
00154 }
00155
00156
00157
00158 void DTOccupancyClusterBuilder::sortClusters() {
00159 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder") << " sorting" << endl;
00160 sort(theClusters.begin(), theClusters.end(), clusterIsLessThan);
00161
00162 for(vector<DTOccupancyCluster>::const_iterator cluster = ++(theClusters.begin());
00163 cluster != theClusters.end(); ++cluster) {
00164 set<DTLayerId> clusterLayers = (*cluster).getLayerIDs();
00165 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00166 << " # layers in the cluster: " << clusterLayers.size() << endl;
00167 theProblematicLayers.insert(clusterLayers.begin(), clusterLayers.end());
00168 }
00169 LogTrace("DTDQM|DTMonitorClient|DTOccupancyTest|DTOccupancyClusterBuilder")
00170 << " # of problematic layers: " << theProblematicLayers.size() << endl;
00171 }
00172
00173
00174 DTOccupancyCluster DTOccupancyClusterBuilder::getBestCluster() const {
00175 return theClusters.front();
00176 }
00177
00178 bool DTOccupancyClusterBuilder::isProblematic(DTLayerId layerId) const {
00179 if(theProblematicLayers.find(layerId) != theProblematicLayers.end()) {
00180 return true;
00181 }
00182 return false;
00183 }