00001 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/TripletGenerator.h"
00002 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/ThirdHitPrediction.h"
00003 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/TripletFilter.h"
00004 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/HitInfo.h"
00005
00006 #include "RecoTracker/TkHitPairs/interface/LayerHitMap.h"
00007 #include "RecoTracker/TkHitPairs/interface/LayerHitMapLoop.h"
00008
00009 #include "RecoTracker/TkMSParametrization/interface/PixelRecoPointRZ.h"
00010
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00012 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014
00015 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00016 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00017
00018 #define DBG 0
00019
00020 using namespace std;
00021 using namespace ctfseeding;
00022
00023
00024 void TripletGenerator::init( const HitPairGenerator & pairs,
00025 const std::vector<SeedingLayer> & layers,
00026 LayerCacheType* layerCache)
00027 {
00028 thePairGenerator = pairs.clone();
00029 theLayers = layers;
00030 theLayerCache = layerCache;
00031
00032 checkMultipleScattering = ps.getParameter<bool>("checkMultipleScattering");
00033 nSigMultipleScattering = ps.getParameter<double>("nSigMultipleScattering");
00034 checkClusterShape = ps.getParameter<bool>("checkClusterShape");
00035 rzTolerance = ps.getParameter<double>("rzTolerance");
00036 maxAngleRatio = ps.getParameter<double>("maxAngleRatio");
00037 }
00038
00039
00040 void TripletGenerator::getTracker
00041 (const edm::EventSetup& es)
00042 {
00043 if(theTracker == 0)
00044 {
00045
00046 edm::ESHandle<TrackerGeometry> tracker;
00047 es.get<TrackerDigiGeometryRecord>().get(tracker);
00048
00049 theTracker = tracker.product();
00050 }
00051 }
00052
00053
00054 GlobalPoint TripletGenerator::getGlobalPosition
00055 (const TrackingRecHit* recHit)
00056 {
00057 DetId detId = recHit->geographicalId();
00058
00059 return
00060 theTracker->idToDet(detId)->toGlobal(recHit->localPosition());
00061 }
00062
00063
00064 void TripletGenerator::hitTriplets(
00065 const TrackingRegion& region,
00066 OrderedHitTriplets & result,
00067 const edm::Event & ev,
00068 const edm::EventSetup& es)
00069 {
00070
00071 OrderedHitPairs pairs; pairs.reserve(30000);
00072 thePairGenerator->hitPairs(region,pairs,ev,es);
00073
00074 if (pairs.size() == 0) return;
00075
00076 int size = theLayers.size();
00077
00078
00079 TripletFilter theFilter(es);
00080
00081
00082 const LayerHitMap **thirdHitMap = new const LayerHitMap* [size];
00083 for(int il=0; il<size; il++)
00084 thirdHitMap[il] = &(*theLayerCache)(&theLayers[il], region, ev, es);
00085
00086
00087 getTracker(es);
00088
00089
00090 for(OrderedHitPairs::const_iterator ip = pairs.begin();
00091 ip!= pairs.end(); ip++)
00092 {
00093
00094 vector<const TrackingRecHit*> recHits(3);
00095 vector<GlobalPoint> points(3);
00096
00097 recHits[0] = (*ip).inner();
00098 recHits[1] = (*ip).outer();
00099
00100 if(DBG)
00101 cerr << " RecHits " + HitInfo::getInfo(*recHits[0]) +
00102 HitInfo::getInfo(*recHits[1]) << endl;
00103
00104 for(int i=0; i<2; i++)
00105 points[i] = getGlobalPosition(recHits[i]);
00106
00107
00108 ThirdHitPrediction
00109 thePrediction(region.originRBound(), region.ptMin(),
00110 points[0],points[1], es,
00111 nSigMultipleScattering,maxAngleRatio);
00112
00113
00114 for(int il=0; il<size; il++)
00115 {
00116 const SeedingLayer & layerwithhits = theLayers[il];
00117 const DetLayer * layer = layerwithhits.detLayer();
00118
00119 if(DBG)
00120 cerr << " check layer " << layer->subDetector() << " " << layer->location() << endl;
00121
00122
00123 float phi[2],rz[2];
00124 thePrediction.getRanges(layer, phi,rz);
00125
00126 PixelRecoRange<float> phiRange(phi[0] , phi[1] );
00127 PixelRecoRange<float> rzRange( rz[0] - rzTolerance, rz[1] + rzTolerance);
00128
00129
00130 LayerHitMapLoop thirdHits = thirdHitMap[il]->loop(phiRange, rzRange);
00131 const SeedingHit * th;
00132 while( (th = thirdHits.getHit()) )
00133 {
00134
00135 recHits[2] = *th;
00136 points[2] = getGlobalPosition(recHits[2]);
00137
00138 if(DBG)
00139 cerr << " third hit " + HitInfo::getInfo(*recHits[2]) << endl;
00140
00141
00142 vector<GlobalVector> globalDirs;
00143 if(thePrediction.isCompatibleWithMultipleScattering
00144 (points[2], recHits, globalDirs, es) == false)
00145 {
00146 if(DBG)
00147 cerr << " not compatible: multiple scattering" << endl;
00148 if(checkMultipleScattering) continue;
00149 }
00150
00151
00152 vector<LocalVector> localDirs;
00153 vector<GlobalVector>::const_iterator globalDir = globalDirs.begin();
00154 for(vector<const TrackingRecHit *>::const_iterator
00155 recHit = recHits.begin();
00156 recHit != recHits.end(); recHit++)
00157 {
00158 localDirs.push_back(theTracker->idToDet(
00159 (*recHit)->geographicalId())->toLocal(*globalDir));
00160 globalDir++;
00161 }
00162
00163
00164 if(checkClusterShape)
00165 {
00166 if(theFilter.checkTrack(recHits,localDirs) == false)
00167 {
00168 if(DBG)
00169 cerr << " not compatible: cluster shape" << endl;
00170 continue;
00171 }
00172 }
00173
00174
00175 result.push_back(OrderedHitTriplet((*ip).inner(),(*ip).outer(),*th));
00176 }
00177 }
00178 }
00179 delete [] thirdHitMap;
00180
00181 return;
00182 }
00183
00184