00001 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/ClusterShapeHitFilter.h"
00002
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/ParameterSet/interface/FileInPath.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007
00008 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/HitInfo.h"
00009 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/ClusterShape.h"
00010 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/ClusterData.h"
00011
00012 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00013 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00014
00015 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00016 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00017
00018 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00019
00020 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00021 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00022 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00023 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00024
00025 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
00026 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00027
00028 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00029 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00030
00031 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00032 #include "MagneticField/Engine/interface/MagneticField.h"
00033
00034 #include "CondFormats/DataRecord/interface/SiPixelLorentzAngleRcd.h"
00035 #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
00036
00037 #include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
00038 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
00039
00040 #include <fstream>
00041 using namespace std;
00042
00043
00044
00045 ClusterShapeHitFilter::ClusterShapeHitFilter
00046 (const GlobalTrackingGeometry * theTracker_,
00047 const MagneticField * theMagneticField_,
00048 const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
00049 const SiStripLorentzAngle * theSiStripLorentzAngle_)
00050 : theTracker(theTracker_),
00051 theMagneticField(theMagneticField_),
00052 theSiPixelLorentzAngle(theSiPixelLorentzAngle_),
00053 theSiStripLorentzAngle(theSiStripLorentzAngle_)
00054
00055 {
00056
00057 loadPixelLimits();
00058
00059
00060 loadStripLimits();
00061 }
00062
00063
00064 ClusterShapeHitFilter::~ClusterShapeHitFilter()
00065 {
00066 }
00067
00068
00069 void ClusterShapeHitFilter::loadPixelLimits()
00070 {
00071 edm::FileInPath
00072 fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/pixelShape.par");
00073 ifstream inFile(fileInPath.fullPath().c_str());
00074
00075 vector<float> v1(2,0);
00076 vector<vector<float> > v2(2,v1);
00077 vector<vector<vector<float> > > v3(2,v2);
00078
00079 while(inFile.eof() == false)
00080 {
00081 int part,dx,dy;
00082
00083 inFile >> part;
00084 inFile >> dx;
00085 inFile >> dy;
00086
00087 for(int b = 0; b<2 ; b++)
00088 for(int d = 0; d<2 ; d++)
00089 for(int k = 0; k<2 ; k++)
00090 inFile >> v3[b][d][k];
00091
00092 const PixelKeys key(part,dx,dy);
00093 pixelLimits[key] = v3;
00094
00095 double f;
00096 int d;
00097
00098 inFile >> f;
00099 inFile >> d;
00100 inFile >> f;
00101 inFile >> d;
00102 }
00103
00104 inFile.close();
00105
00106 LogTrace("MinBiasTracking|ClusterShapeHitFilter")
00107 << " [ClusterShapeHitFilter] pixel-cluster-shape filter loaded";
00108 }
00109
00110
00111 void ClusterShapeHitFilter::loadStripLimits()
00112 {
00113
00114 edm::FileInPath
00115 fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/stripShape.par");
00116 ifstream inFile(fileInPath.fullPath().c_str());
00117
00118 vector<float> v1(2,0);
00119 vector<vector<float> > v2(2,v1);
00120
00121 while(inFile.eof() == false)
00122 {
00123 int dx;
00124 inFile >> dx;
00125
00126 for(int b = 0; b<2 ; b++)
00127 for(int k = 0; k<2 ; k++)
00128 inFile >> v2[b][k];
00129
00130 StripKeys key(dx);
00131 stripLimits[key] = v2;
00132 }
00133
00134 inFile.close();
00135
00136 LogTrace("MinBiasTracking|ClusterShapeHitFilter")
00137 << " [ClusterShapeHitFilter] strip-cluster-width filter loaded";
00138 }
00139
00140
00141 bool ClusterShapeHitFilter::isInside
00142 (const vector<vector<float> > & limit, const pair<float,float> & pred) const
00143 {
00144 return (pred.first > limit[0][0] && pred.first < limit[0][1] &&
00145 pred.second > limit[1][0] && pred.second < limit[1][1]);
00146 }
00147
00148
00149 bool ClusterShapeHitFilter::isInside
00150 (const vector<float> & limit, const float & pred) const
00151 {
00152 return (pred > limit[0] && pred < limit[1]);
00153 }
00154
00155
00156 pair<float,float> ClusterShapeHitFilter::getCotangent
00157 (const PixelGeomDetUnit * pixelDet) const
00158 {
00159 pair<float,float> cotangent;
00160
00161 cotangent.first = pixelDet->surface().bounds().thickness() /
00162 pixelDet->specificTopology().pitch().first;
00163 cotangent.second = pixelDet->surface().bounds().thickness() /
00164 pixelDet->specificTopology().pitch().second;
00165
00166 return cotangent;
00167 }
00168
00169
00170 float ClusterShapeHitFilter::getCotangent
00171 (const StripGeomDetUnit * stripDet) const
00172 {
00173
00174 return stripDet->surface().bounds().thickness() /
00175 stripDet->specificTopology().localPitch(LocalPoint(0,0,0));
00176 }
00177
00178
00179 pair<float,float> ClusterShapeHitFilter::getDrift
00180 (const PixelGeomDetUnit * pixelDet) const
00181 {
00182 LocalVector lBfield =
00183 (pixelDet->surface()).toLocal(
00184 theMagneticField->inTesla(
00185 pixelDet->surface().position()));
00186
00187 double theTanLorentzAnglePerTesla =
00188 theSiPixelLorentzAngle->getLorentzAngle(
00189 pixelDet->geographicalId().rawId());
00190
00191 pair<float,float> dir;
00192 dir.first = - theTanLorentzAnglePerTesla * lBfield.y();
00193 dir.second = theTanLorentzAnglePerTesla * lBfield.x();
00194
00195 return dir;
00196 }
00197
00198
00199 float ClusterShapeHitFilter::getDrift(const StripGeomDetUnit * stripDet)
00200 const
00201 {
00202 LocalVector lBfield =
00203 (stripDet->surface()).toLocal(
00204 theMagneticField->inTesla(
00205 stripDet->surface().position()));
00206
00207 double theTanLorentzAnglePerTesla =
00208 theSiStripLorentzAngle->getLorentzAngle(
00209 stripDet->geographicalId().rawId());
00210
00211 float dir = theTanLorentzAnglePerTesla * lBfield.y();
00212
00213 return dir;
00214 }
00215
00216
00217 bool ClusterShapeHitFilter::isNormalOriented
00218 (const GeomDetUnit * geomDet) const
00219 {
00220 if(geomDet->type().isBarrel())
00221 {
00222 float perp0 = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).perp();
00223 float perp1 = geomDet->toGlobal( Local3DPoint(0.,0.,1.) ).perp();
00224 return (perp1 > perp0);
00225 }
00226 else
00227 {
00228 float rot = geomDet->toGlobal( LocalVector (0.,0.,1.) ).z();
00229 float pos = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).z();
00230 return (rot * pos > 0);
00231 }
00232 }
00233
00234
00235 bool ClusterShapeHitFilter::getSizes
00236 (const SiPixelRecHit & recHit, const LocalVector & ldir,
00237 int & part, vector<pair<int,int> > & meas, pair<float,float> & pred) const
00238 {
00239
00240 DetId id = recHit.geographicalId();
00241 const PixelGeomDetUnit* pixelDet =
00242 dynamic_cast<const PixelGeomDetUnit*> (theTracker->idToDet(id));
00243
00244
00245 ClusterData data;
00246 ClusterShape theClusterShape;
00247 theClusterShape.determineShape(*pixelDet, recHit, data);
00248 bool usable = (data.isStraight && data.isComplete);
00249
00250
00251
00252 {
00253 part = (pixelDet->type().isBarrel() ? 0 : 1);
00254
00255
00256 pred.first = ldir.x() / ldir.z();
00257 pred.second = ldir.y() / ldir.z();
00258
00259 if(data.size.front().second < 0)
00260 pred.second = - pred.second;
00261
00262 for(vector<pair<int,int> >::const_iterator s = data.size.begin();
00263 s!= data.size.end(); s++)
00264 {
00265 meas.push_back(*s);
00266
00267 if(data.size.front().second < 0)
00268 meas.back().second = - meas.back().second;
00269 }
00270
00271
00272 pair<float,float> drift = getDrift(pixelDet);
00273 pred.first += drift.first;
00274 pred.second += drift.second;
00275
00276
00277 pair<float,float> cotangent = getCotangent(pixelDet);
00278 pred.first *= cotangent.first;
00279 pred.second *= cotangent.second;
00280 }
00281
00282
00283 return usable;
00284 }
00285
00286
00287 bool ClusterShapeHitFilter::getSizes
00288 (const SiStripRecHit2D & recHit, const LocalVector & ldir,
00289 int & meas, float & pred) const
00290 {
00291
00292 DetId id = recHit.geographicalId();
00293 const StripGeomDetUnit* stripDet =
00294 dynamic_cast<const StripGeomDetUnit*> (theTracker->idToDet(id));
00295
00296
00297 meas = recHit.cluster()->amplitudes().size();
00298
00299
00300 int fs = recHit.cluster()->firstStrip();
00301 int ns = stripDet->specificTopology().nstrips();
00302
00303 bool usable = (fs >= 1 && fs + meas - 1 <= ns);
00304
00305
00306
00307 {
00308
00309 pred = ldir.x() / ldir.z();
00310
00311
00312 float drift = getDrift(stripDet);
00313 pred += drift;
00314
00315
00316 pred *= getCotangent(stripDet);
00317 }
00318
00319 return usable;
00320 }
00321
00322
00323 bool ClusterShapeHitFilter::isCompatible
00324 (const SiPixelRecHit & recHit, const LocalVector & ldir) const
00325 {
00326 int part;
00327 vector<pair<int,int> > meas;
00328 pair<float,float> pred;
00329
00330 if(getSizes(recHit, ldir, part,meas, pred))
00331 {
00332 for(vector<pair<int,int> >::const_iterator m = meas.begin();
00333 m!= meas.end(); m++)
00334 {
00335 PixelKeys key(part, (*m).first, (*m).second);
00336
00337 PixelLimitsMap::const_iterator i = pixelLimits.find(key);
00338 if(i != pixelLimits.end())
00339 {
00340
00341 if (isInside((i->second)[0], pred) ||
00342 isInside((i->second)[1], pred))
00343 return true;
00344 }
00345 else
00346 {
00347
00348 return true;
00349 }
00350 }
00351
00352
00353 return false;
00354 }
00355 else
00356 {
00357
00358 return true;
00359 }
00360 }
00361
00362
00363 bool ClusterShapeHitFilter::isCompatible
00364 (const SiStripRecHit2D & recHit, const LocalVector & ldir) const
00365 {
00366 int meas;
00367 float pred;
00368
00369 if(getSizes(recHit, ldir, meas, pred))
00370 {
00371 StripKeys key(meas);
00372
00373 StripLimitsMap::const_iterator i=stripLimits.find(key);
00374 if (i!=stripLimits.end())
00375 return (isInside((i->second)[0], pred) ||
00376 isInside((i->second)[1], pred));
00377
00378 }
00379
00380
00381 return true;
00382 }
00383
00384
00385 bool ClusterShapeHitFilter::isCompatible
00386 (const SiPixelRecHit & recHit, const GlobalVector & gdir) const
00387 {
00388 LocalVector ldir =
00389 theTracker->idToDet(recHit.geographicalId())->toLocal(gdir);
00390
00391 return isCompatible(recHit, ldir);
00392 }
00393
00394
00395 bool ClusterShapeHitFilter::isCompatible
00396 (const SiStripRecHit2D & recHit, const GlobalVector & gdir) const
00397 {
00398 LocalVector ldir =
00399 theTracker->idToDet(recHit.geographicalId())->toLocal(gdir);
00400
00401 return isCompatible(recHit, ldir);
00402 }
00403
00404
00405 #include "FWCore/PluginManager/interface/ModuleDef.h"
00406 #include "FWCore/Framework/interface/MakerMacros.h"
00407
00408 #include "FWCore/Utilities/interface/typelookup.h"
00409 TYPELOOKUP_DATA_REG(ClusterShapeHitFilter);
00410