00001 #include "MapsSensor.hh"
00002 #include "ToString.h"
00003 #include <iostream>
00004 #include <cmath>
00005 MapsSensor::MapsSensor(unsigned id, double zpos) {
00006 myId = id;
00007 myPosition = zpos;
00008 myAlignment = coord(0, 0);
00009 }
00010
00011 MapsSensor::MapsSensor(unsigned id, double zpos, physXY alignment) {
00012 myId = id;
00013 myPosition = zpos;
00014 myAlignment = alignment;
00015 }
00016 MapsSensor::~MapsSensor() {
00017 }
00018
00019 unsigned MapsSensor::id() {
00020 return myId;
00021 }
00022
00023 MapsSensor::physXY MapsSensor::getAlignment() const {
00024 return myAlignment;
00025 }
00026
00027 void MapsSensor::setAlignment(MapsSensor::physXY alignment) {
00028 myAlignment = alignment;
00029 }
00030
00031 void MapsSensor::registerTrackConfirm(unsigned threshold,
00032 MapsSensor::coord place, unsigned bx) {
00033 if (myHitsByThreshold.count(threshold) == 0) {
00034 myKnownThresholds.push_back(threshold);
00035 std::pair<unsigned, unsigned>* hits =
00036 new std::pair<unsigned, unsigned>(0, 0);
00037 myHitsByThreshold[threshold] = hits;
00038 }
00039
00040 if (myTimes.count(bx) == 0) {
00041 myTimes[bx] = new std::pair<unsigned, unsigned>(0, 0);
00042 }
00043
00044 std::pair<unsigned, unsigned>* hits = myHitsByThreshold[threshold];
00045 std::pair<unsigned, unsigned>* times = myTimes[bx];
00046
00047 (*hits).first++;
00048 (*times).first++;
00049 myEfficientHits.push_back(place);
00050 }
00051
00052 void MapsSensor::registerTrackConfirm(unsigned threshold,
00053 MapsSensor::coord place, unsigned bx, MapsSensor::physXY resid) {
00054 myFourthHitResids.push_back(resid);
00055 registerTrackConfirm(threshold, place, bx);
00056 }
00057 void MapsSensor::registerTrackMiss(unsigned threshold, unsigned bx) {
00058 if (myHitsByThreshold.count(threshold) == 0) {
00059 myKnownThresholds.push_back(threshold);
00060 std::pair<unsigned, unsigned>* hits =
00061 new std::pair<unsigned, unsigned>(0, 0);
00062 myHitsByThreshold[threshold] = hits;
00063 }
00064 if (myTimes.count(bx) == 0) {
00065 myTimes[bx] = new std::pair<unsigned, unsigned>(0, 0);
00066 }
00067 std::pair<unsigned, unsigned>* hits = myHitsByThreshold[threshold];
00068 std::pair<unsigned, unsigned>* times = myTimes[bx];
00069
00070 (*hits).second++;
00071 (*times).second++;
00072 }
00073 void MapsSensor::registerTrackMiss(unsigned threshold, MapsSensor::coord pred,
00074 unsigned bx) {
00075 myInefficientHits.push_back(pred);
00076 registerTrackMiss(threshold, bx);
00077 }
00078
00079 void MapsSensor::registerGeneralHit(unsigned threshold,
00080 MapsSensor::coord place, unsigned bx) {
00081 myGeneralHits.push_back(place);
00082 std::cout<< "WARNING: " << __PRETTY_FUNCTION__
00083 << " not yet fully implemented!!!\n";
00084
00085 }
00086 double MapsSensor::getEfficiency(unsigned threshold) {
00087 if (myHitsByThreshold.count(threshold) == 0)
00088 return -1.0;
00089 std::pair<unsigned, unsigned>* hits = myHitsByThreshold[threshold];
00090 return static_cast<double>((*hits).first) / ((*hits).first + (*hits).second);
00091 }
00092 void MapsSensor::getInefficiencyXYPlot(TH2F& plot) {
00093 plot.SetTitle(("XY inefficiency for sensor " + toString(myId)).c_str());
00094 plot.SetName(("hXYinefficiencySensor" + toString(myId)).c_str());
00095 plot.SetBins(168, 0, 168, 168, 0, 168);
00096 plot.SetXTitle("x pixel");
00097 plot.SetYTitle("y pixel");
00098
00099 for (std::vector<MapsSensor::coord>::const_iterator it =
00100 myInefficientHits.begin(); it != myInefficientHits.end(); it++) {
00101 plot.Fill((*it).first, (*it).second);
00102 }
00103 }
00104 void MapsSensor::getEfficiencyXYPlot(TH2F& plot) {
00105 plot.SetTitle(("XY efficiency for sensor " + toString(myId)).c_str());
00106 plot.SetName(("hXYefficiencySensor" + toString(myId)).c_str());
00107 plot.SetBins(168, 0, 168, 168, 0, 168);
00108 plot.SetXTitle("x pixel");
00109 plot.SetYTitle("y pixel");
00110
00111 for (std::vector<MapsSensor::coord>::const_iterator it =
00112 myEfficientHits.begin(); it != myEfficientHits.end(); it++) {
00113 plot.Fill((*it).first, (*it).second);
00114 }
00115 }
00116 void MapsSensor::getFourthHitResidualPlot(TH2F& plot) {
00117 plot.SetTitle(("R_{4} for 3 hit track w/alignment, sensor " + toString(myId)).c_str());
00118 plot.SetName(("hXYfourthHitResidSensor" + toString(myId)).c_str());
00119 plot.SetBins(40, -20, 20, 40, -20, 20);
00120 plot.SetXTitle("x pixel residual");
00121 plot.SetYTitle("y pixel residual");
00122
00123 for (std::vector<MapsSensor::physXY>::const_iterator it =
00124 myFourthHitResids.begin(); it != myFourthHitResids.end(); it++) {
00125
00126
00127
00128 plot.Fill((*it).first, (*it).second);
00129 }
00130
00131 }
00132 void MapsSensor::getEfficiencyTimestamps(TH1F& plot) {
00133 plot.SetName(("hTimestampsEfficiencySensor"+ toString(myId)).c_str());
00134 plot.SetTitle(("Efficiency timestamps for sensor " + toString(myId)).c_str());
00135 plot.SetBins(128, 0, 8192);
00136 plot.SetYTitle("Entries/64");
00137 plot.SetXTitle("Time");
00138
00139 for (unsigned t(0); t < 8192; t++) {
00140 if (myTimes.count(t) != 0) {
00141 std::pair<unsigned, unsigned>* count = myTimes[t];
00142 plot.Fill(t, (*count).first);
00143 }
00144 }
00145 }
00146
00147 void MapsSensor::getInefficiencyTimestamps(TH1F& plot) {
00148 plot.SetName(("hTimestampsInefficiencySensor"+ toString(myId)).c_str());
00149 plot.SetTitle(("Inefficiency timestamps for sensor " + toString(myId)).c_str());
00150 plot.SetBins(128, 0, 8192);
00151 plot.SetYTitle("Entries/64");
00152 plot.SetXTitle("Time");
00153
00154 for (unsigned t(0); t < 8192; t++) {
00155 if (myTimes.count(t) != 0) {
00156 std::pair<unsigned, unsigned>* count = myTimes[t];
00157 plot.Fill(t, (*count).second);
00158 }
00159 }
00160 }
00161
00162 void MapsSensor::getResidualXYPlot(TH2F& plot) const {
00163 plot.SetName(("hResidualsSensor" + toString(myId)).c_str());
00164 plot.SetTitle(("Residuals for sensor " + toString(myId)).c_str());
00165 plot.SetXTitle("X pixel residual");
00166 plot.SetYTitle("Y pixel residual");
00167 plot.SetBins(40, -20, 20, 40, -20, 20);
00168 for (std::vector<std::pair<double, double> >::const_iterator it =
00169 myResiduals.begin(); it != myResiduals.end(); it++) {
00170 plot.Fill((*it).first, (*it).second);
00171 }
00172 }
00173
00174 void MapsSensor::getEfficiencyCurve(TH1F& plot, int bins, int low, int high) {
00175 plot.SetTitle(("Efficiency for sensor " + toString(myId)).c_str());
00176 plot.SetName(("hEfficiencySensor" + toString(myId)).c_str());
00177 plot.SetXTitle("Threshold");
00178 plot.SetYTitle("Efficiency (%)");
00179 plot.SetBins(bins, low, high);
00180 for (std::vector<unsigned>::iterator it = myKnownThresholds.begin(); it
00181 != myKnownThresholds.end(); it++) {
00182 plot.Fill(*it, 100*getEfficiency(*it));
00183 }
00184
00185 }
00186 void MapsSensor::setResidual(MapsSensor::physXY resid) {
00187 myResiduals.push_back(resid);
00188 }
00189
00190 unsigned MapsSensor::getLowestThresh() const {
00191 unsigned lowest = 100000;
00192 for (std::vector<unsigned>::const_iterator it = myKnownThresholds.begin(); it
00193 != myKnownThresholds.end(); it++) {
00194 if (*it < lowest)
00195 lowest = *it;
00196 }
00197 return lowest;
00198 }
00199 unsigned MapsSensor::getHighestThresh() const {
00200 unsigned highest = 0;
00201 for (std::vector<unsigned>::const_iterator it = myKnownThresholds.begin(); it
00202 != myKnownThresholds.end(); it++) {
00203 if (*it > highest)
00204 highest = *it;
00205 }
00206 return highest;
00207 }
00208
00209 bool MapsSensor::isDeadArea(const physXY xy) const {
00210
00211 if (fabs(xy.second) < 0.025 || fabs(xy.second) > 4.2)
00212 return true;
00213
00214
00215 if (xy.first < -4.45)
00216 return true;
00217
00218 if (xy.first > 4.7)
00219 return true;
00220
00221 if (xy.first > -2.35 && xy.first < -2.1)
00222 return true;
00223
00224 if (xy.first > 0 && xy.first < 0.25)
00225 return true;
00226
00227 if (xy.first > 2.35 && xy.first < 2.6)
00228 return true;
00229
00230 return false;
00231
00232 }
00233
00234 void MapsSensor::convertHitToPhysical(const coord& c, physXY& xy) const {
00235
00236 int r = c.first / 42;
00237
00238
00239
00240 xy.first = (r - 2) * 2.35 + 0.25 + 0.025 + (c.first % 42) * 0.05;
00241
00242
00243 if (c.second > 83)
00244 xy.second = 0.05 + (c.second - 84) * 0.05;
00245 else
00246 xy.second = (c.second - 84) * 0.05;
00247 }
00248
00249 void MapsSensor::convertPhysicalToHit(const physXY& xy, coord& c) const
00250 throw(MapsException) {
00251
00252 if (isDeadArea(xy)) {
00253 std::string desc("Physical xy ");
00254 desc.append(toString(xy));
00255 desc.append(" falls in dead area.");
00256 MapsException me(desc.c_str());
00257 throw me;
00258 }
00259
00260 unsigned r = floor(xy.first/2.35) + 2;
00261
00262
00263 if (xy.second > 0.025)
00264 c.second = 84 + floor((xy.second - 0.025)/0.05);
00265 else
00266 c.second = 84 + floor((xy.second + 0.025)/0.05);
00267
00268
00269 unsigned localX = floor((xy.first - ((r - 2) * 2.35 + 0.25)) / 0.05);
00270
00271 c.first = r * 42 + localX;
00272
00273 }
00274
00275 std::ostream& operator<<(std::ostream& s, const MapsSensor& ms) {
00276 return s << "Sensor id " << ms.myId << " [z=" << ms.myPosition << ",\tal="
00277 << ms.myAlignment << "]";
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292