00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <vector>
00056 #include <iostream>
00057 #include <cmath>
00058
00059 #include "RecoTracker/RoadSearchCloudMaker/interface/RoadSearchCloudMakerAlgorithm.h"
00060
00061 #include "FWCore/ServiceRegistry/interface/Service.h"
00062
00063 #include "DataFormats/Common/interface/Handle.h"
00064 #include "FWCore/Framework/interface/ESHandle.h"
00065 #include "FWCore/Framework/interface/EventSetup.h"
00066 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00067
00068 #include "DataFormats/Common/interface/Ref.h"
00069 #include "DataFormats/RoadSearchSeed/interface/RoadSearchSeedCollection.h"
00070 #include "DataFormats/RoadSearchCloud/interface/RoadSearchCloud.h"
00071 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00072 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00073 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00074 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00075 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00076 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00077 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00078 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00079 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00080 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00081
00082 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00083 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00084 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00085 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00086 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00087 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00088
00089 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00090 #include "Geometry/TrackerTopology/interface/RectangularPixelTopology.h"
00091
00092 #include "TrackingTools/RoadSearchHitAccess/interface/RoadSearchDetIdHelper.h"
00093
00094 #include "RecoTracker/RoadMapRecord/interface/RoadMapRecord.h"
00095
00096 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00097 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00098
00099 using namespace std;
00100
00101 double RoadSearchCloudMakerAlgorithm::epsilon = 0.000000001;
00102
00103 RoadSearchCloudMakerAlgorithm::RoadSearchCloudMakerAlgorithm(const edm::ParameterSet& conf) : conf_(conf) {
00104 recHitVectorClass.setMode(DetHitAccess::standard);
00105 recHitVectorClass.use_rphiRecHits(conf_.getParameter<bool>("UseRphiRecHits"));
00106 recHitVectorClass.use_stereoRecHits(conf_.getParameter<bool>("UseStereoRecHits"));
00107
00108
00109 theRPhiRoadSize = conf_.getParameter<double>("RPhiRoadSize");
00110 theZPhiRoadSize = conf_.getParameter<double>("ZPhiRoadSize");
00111 UsePixels = conf_.getParameter<bool>("UsePixelsinRS");
00112 NoFieldCosmic = conf_.getParameter<bool>("StraightLineNoBeamSpotCloud");
00113 theMinimumHalfRoad = conf_.getParameter<double>("MinimumHalfRoad");
00114
00115 maxDetHitsInCloudPerDetId = conf_.getParameter<unsigned int>("MaxDetHitsInCloudPerDetId");
00116 minFractionOfUsedLayersPerCloud = conf_.getParameter<double>("MinimalFractionOfUsedLayersPerCloud");
00117 maxFractionOfMissedLayersPerCloud = conf_.getParameter<double>("MaximalFractionOfMissedLayersPerCloud");
00118 maxFractionOfConsecutiveMissedLayersPerCloud = conf_.getParameter<double>("MaximalFractionOfConsecutiveMissedLayersPerCloud");
00119 increaseMaxNumberOfConsecutiveMissedLayersPerCloud = conf_.getParameter<unsigned int>("IncreaseMaxNumberOfConsecutiveMissedLayersPerCloud");
00120 increaseMaxNumberOfMissedLayersPerCloud = conf_.getParameter<unsigned int>("IncreaseMaxNumberOfMissedLayersPerCloud");
00121
00122 doCleaning_ = conf.getParameter<bool>("DoCloudCleaning");
00123 mergingFraction_ = conf.getParameter<double>("MergingFraction");
00124 maxRecHitsInCloud_ = (unsigned int)conf.getParameter<int>("MaxRecHitsInCloud");
00125 scalefactorRoadSeedWindow_ = conf.getParameter<double>("scalefactorRoadSeedWindow");
00126
00127 roadsLabel_ = conf.getParameter<std::string>("RoadsLabel");
00128
00129 }
00130
00131 RoadSearchCloudMakerAlgorithm::~RoadSearchCloudMakerAlgorithm() {
00132
00133 }
00134
00135 double RoadSearchCloudMakerAlgorithm::map_phi(double phi) {
00136
00137 double result = phi;
00138 if ( result < -1.0*Geom::twoPi()) result = result + Geom::twoPi();
00139 if ( result < 0) result = Geom::twoPi() + result;
00140 if ( result > Geom::twoPi()) result = result - Geom::twoPi();
00141 return result;
00142 }
00143
00144 double RoadSearchCloudMakerAlgorithm::map_phi2(double phi) {
00145
00146 double result = phi;
00147 if ( result < 1.0*Geom::pi() ) result = result + Geom::twoPi();
00148 if ( result >= Geom::pi()) result = result - Geom::twoPi();
00149 return result;
00150 }
00151
00152 void RoadSearchCloudMakerAlgorithm::run(edm::Handle<RoadSearchSeedCollection> input,
00153 const SiStripRecHit2DCollection* rphiRecHits,
00154 const SiStripRecHit2DCollection* stereoRecHits,
00155 const SiStripMatchedRecHit2DCollection* matchedRecHits,
00156 const SiPixelRecHitCollection *pixRecHits,
00157 const edm::EventSetup& es,
00158 RoadSearchCloudCollection &output)
00159 {
00160
00161 const int nphibin = 24;
00162 const int netabin = 24;
00163 RoadSearchCloudCollection CloudArray[nphibin][netabin];
00164
00165
00166 edm::ESHandle<Roads> roads;
00167 es.get<RoadMapRecord>().get(roadsLabel_, roads);
00168
00169
00170 const RoadSearchSeedCollection* inputSeeds = input.product();
00171
00172
00173 const std::vector<DetId> availableIDs = rphiRecHits->ids();
00174 const std::vector<DetId> availableIDs2 = stereoRecHits->ids();
00175 const std::vector<DetId> availableIDs3 = pixRecHits->ids();
00176
00177
00178 recHitVectorClass.setCollections(rphiRecHits,stereoRecHits,matchedRecHits,pixRecHits);
00179 recHitVectorClass.setMode(DetHitAccess::standard);
00180
00181
00182 edm::ESHandle<TrackerGeometry> tracker;
00183 es.get<TrackerDigiGeometryRecord>().get(tracker);
00184
00185
00186 SiStripRecHitMatcher* theHitMatcher = new SiStripRecHitMatcher(3.0);
00187
00188 edm::LogInfo("RoadSearch") << "Found " << inputSeeds->size() << " input seeds.";
00189
00190 for ( RoadSearchSeedCollection::const_iterator seed = inputSeeds->begin(); seed != inputSeeds->end(); ++seed) {
00191
00192 const Roads::RoadSeed *roadSeed = seed->getSeed();
00193
00194 if ( roadSeed == 0 ) {
00195 edm::LogWarning("RoadSearch") << "RoadSeed could not be resolved from RoadSearchSeed hits, discard seed!";
00196 } else {
00197
00198 Roads::type roadType = roads->getRoadType(roadSeed);
00199 if (NoFieldCosmic) roadType = Roads::RPhi;
00200
00201
00202
00203
00204
00205 const TrackingRecHit* innerSeedRingHit = (*(seed->begin()));
00206 const TrackingRecHit* outerSeedRingHit = (*(seed->end() - 1));
00207
00208 GlobalPoint innerSeedHitGlobalPosition = tracker->idToDet(innerSeedRingHit->geographicalId())->surface().toGlobal(innerSeedRingHit->localPosition());
00209 GlobalPoint outerSeedHitGlobalPosition = tracker->idToDet(outerSeedRingHit->geographicalId())->surface().toGlobal(outerSeedRingHit->localPosition());
00210
00211 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " inner hit (x/y/z): "
00212 << innerSeedHitGlobalPosition.x() << " / "
00213 << innerSeedHitGlobalPosition.y() << " / "
00214 << innerSeedHitGlobalPosition.z();
00215 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " outer hit (x/y/z): "
00216 << outerSeedHitGlobalPosition.x() << " / "
00217 << outerSeedHitGlobalPosition.y() << " / "
00218 << outerSeedHitGlobalPosition.z();
00219
00220 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " inner hit (r/phi): "
00221 << innerSeedHitGlobalPosition.perp() << " / "
00222 << innerSeedHitGlobalPosition.phi();
00223 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " outer hit (r/phi): "
00224 << outerSeedHitGlobalPosition.perp() << " / "
00225 << outerSeedHitGlobalPosition.phi();
00226
00227
00228
00229 double d0 = 0.0;
00230 double phi0 = -99.;
00231 double k0 = -99999999.99;
00232
00233 double phi1 = -99.;
00234 double k1 = -99999999.99;
00235
00236
00237 double outer_phi = map_phi(outerSeedHitGlobalPosition.phi());
00238 double outer_eta = outerSeedHitGlobalPosition.eta();
00239
00240 int phibin = (int)(nphibin*(outer_phi/(2*Geom::pi())));
00241 int etabin = (int)(netabin*(outer_eta+3.0)/6.0);
00242
00243
00244 if ( roadType == Roads::RPhi ) {
00245 double dr = outerSeedHitGlobalPosition.perp() - innerSeedHitGlobalPosition.perp();
00246 const double dr_min = 1;
00247 if ( dr < dr_min ) {
00248 edm::LogWarning("RoadSearch") << "RPhi road: seed Hits distance smaller than 1 cm, do not consider this seed.";
00249 } else {
00250
00251 double det = innerSeedHitGlobalPosition.x() * outerSeedHitGlobalPosition.y() - innerSeedHitGlobalPosition.y() * outerSeedHitGlobalPosition.x();
00252 if ( det == 0 ) {
00253 edm::LogWarning("RoadSearch") << "RPhi road: 'det' == 0, do not consider this seed.";
00254 } else {
00255 double x0=0.0; double y0=0.0;
00256 double innerx=innerSeedHitGlobalPosition.x();
00257 double innery=innerSeedHitGlobalPosition.y();
00258 double outerx=outerSeedHitGlobalPosition.x();
00259 double outery=outerSeedHitGlobalPosition.y();
00260
00261 if (NoFieldCosmic){
00262 phi0=atan2(outery-innery,outerx-innerx);
00263 double alpha=atan2(innery,innerx);
00264 double d1=sqrt(innerx*innerx+innery*innery);
00265 d0=d1*sin(alpha-phi0); x0=-d0*sin(phi0); y0=d0*cos(phi0); k0=0.0;
00266 }else{
00267 makecircle(innerx,innery,outerx,outery,x0,y0);
00268 phi0 = phi0h;
00269 k0 = omegah;
00270 }
00271 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " trajectory parameters: d0 = "<< d0 << " phi0 = " << phi0;
00272 }
00273 }
00274 } else {
00275 double dz = outerSeedHitGlobalPosition.z() - innerSeedHitGlobalPosition.z();
00276 const double dz_min = 1.e-6;
00277 if ( std::abs(dz) < dz_min ) {
00278 edm::LogWarning("RoadSearch") << "ZPhi road: seed Hits are less than .01 microns away in z, do not consider this seed.";
00279 } else {
00280
00281 k0 = map_phi2(outerSeedHitGlobalPosition.phi() - innerSeedHitGlobalPosition.phi()) / dz;
00282 phi0 = map_phi(innerSeedHitGlobalPosition.phi() - k0 * innerSeedHitGlobalPosition.z());
00283
00284
00285 makecircle(innerSeedHitGlobalPosition.x(),innerSeedHitGlobalPosition.y(),
00286 outerSeedHitGlobalPosition.x(),outerSeedHitGlobalPosition.y(),
00287 0.0,0.0);
00288 phi1 = phi0h;
00289 k1 = omegah;
00290 }
00291 }
00292
00293
00294 if ( (phi0 != -99.) && (k0 != -99999999.99) ) {
00295 const Roads::RoadSet *roadSet = seed->getSet();
00296
00297
00298 RoadSearchCloud cloud;
00299
00300 bool firstHitFound = false;
00301 unsigned int layerCounter = 0;
00302 unsigned int usedLayers = 0;
00303 unsigned int missedLayers = 0;
00304 unsigned int consecutiveMissedLayers = 0;
00305
00306 unsigned int totalLayers = roadSet->size();
00307
00308
00309
00310 unsigned int minNumberOfUsedLayersPerCloud = static_cast<unsigned int>(totalLayers * minFractionOfUsedLayersPerCloud + 0.5);
00311 if (minNumberOfUsedLayersPerCloud < 3) minNumberOfUsedLayersPerCloud = 3;
00312 unsigned int maxNumberOfMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfMissedLayersPerCloud + 0.5);
00313 unsigned int maxNumberOfConsecutiveMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfConsecutiveMissedLayersPerCloud + 0.5);
00314
00315
00316 if (std::abs(outer_eta) > 0.9 && std::abs(outer_eta) < 1.5) {
00317 maxNumberOfConsecutiveMissedLayersPerCloud += increaseMaxNumberOfConsecutiveMissedLayersPerCloud;
00318 maxNumberOfMissedLayersPerCloud += increaseMaxNumberOfMissedLayersPerCloud;
00319 }
00320
00321 for ( Roads::RoadSet::const_iterator roadSetVector = roadSet->begin();
00322 roadSetVector != roadSet->end();
00323 ++roadSetVector ) {
00324
00325 ++layerCounter;
00326 unsigned int usedHitsInThisLayer = 0;
00327 bool intersectsLayer = false;
00328
00329 for ( std::vector<const Ring*>::const_iterator ring = roadSetVector->begin(); ring != roadSetVector->end(); ++ring ) {
00330
00331
00332
00333 double ringRadius = (*ring)->getrmin() + ((*ring)->getrmax()-(*ring)->getrmin())/2;
00334 double ringZ = (*ring)->getzmin() + ((*ring)->getzmax()-(*ring)->getzmin())/2;
00335 double ringPhi = 0.0;
00336 if ( roadType == Roads::RPhi ) {
00337 ringPhi = phiFromExtrapolation(d0,phi0,k0,ringRadius,roadType);
00338 } else {
00339 ringPhi = phiFromExtrapolation(d0,phi0,k0,ringZ,roadType);
00340 }
00341 if (ringPhi == -99) continue;
00342 intersectsLayer = true;
00343
00344 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " testing ring at R = " << ringRadius
00345 << " Z = " << ringZ << " ringPhi = " << ringPhi;
00346
00347 int nDetIds = (*ring)->getNumDetIds();
00348 double theHalfRoad = theMinimumHalfRoad*(2.0*Geom::pi())/((double)nDetIds);
00349
00350 double upperPhiRangeBorder = map_phi2(ringPhi + theHalfRoad);
00351 double lowerPhiRangeBorder = map_phi2(ringPhi - theHalfRoad);
00352
00353 if ( lowerPhiRangeBorder <= upperPhiRangeBorder ) {
00354
00355 for ( Ring::const_iterator detid = (*ring)->lower_bound(lowerPhiRangeBorder); detid != (*ring)->upper_bound(upperPhiRangeBorder); ++detid) {
00356 usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
00357 tracker.product(),theHitMatcher,cloud);
00358 }
00359
00360 } else {
00361 for ( Ring::const_iterator detid = (*ring)->lower_bound(lowerPhiRangeBorder); detid != (*ring)->end(); ++detid) {
00362 usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
00363 tracker.product(),theHitMatcher,cloud);
00364 }
00365
00366 for ( Ring::const_iterator detid = (*ring)->begin(); detid != (*ring)->upper_bound(upperPhiRangeBorder); ++detid) {
00367 usedHitsInThisLayer += FillRecHitsIntoCloudGeneral(detid->second,d0,phi0,k0,phi1,k1,roadType,ringPhi,
00368 tracker.product(),theHitMatcher,cloud);
00369 }
00370 }
00371 LogDebug("RoadSearch") << "Seed # " <<seed-inputSeeds->begin() << " now has " << usedHitsInThisLayer << " hits in ring at R = " << ringRadius
00372 << " Z = " << ringZ << " ringPhi = " << ringPhi;
00373 }
00374
00375 if ( !firstHitFound ) {
00376 if ( usedHitsInThisLayer > 0 ) {
00377
00378 firstHitFound = true;
00379
00380
00381 totalLayers = roadSet->size() - layerCounter + 1;
00382
00383
00384
00385 minNumberOfUsedLayersPerCloud = static_cast<unsigned int>(totalLayers * minFractionOfUsedLayersPerCloud + 0.5);
00386 if (minNumberOfUsedLayersPerCloud < 3) minNumberOfUsedLayersPerCloud = 3;
00387 maxNumberOfMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfMissedLayersPerCloud + 0.5);
00388 maxNumberOfConsecutiveMissedLayersPerCloud = static_cast<unsigned int>(totalLayers * maxFractionOfConsecutiveMissedLayersPerCloud + 0.5);
00389
00390
00391 if (std::abs(outer_eta) > 0.9 && std::abs(outer_eta) < 1.5) {
00392 maxNumberOfConsecutiveMissedLayersPerCloud += increaseMaxNumberOfConsecutiveMissedLayersPerCloud;
00393 maxNumberOfMissedLayersPerCloud += increaseMaxNumberOfMissedLayersPerCloud;
00394 }
00395
00396 ++usedLayers;
00397 consecutiveMissedLayers = 0;
00398
00399 }
00400 } else {
00401 if (intersectsLayer){
00402 if ( usedHitsInThisLayer > 0 ) {
00403 ++usedLayers;
00404 consecutiveMissedLayers = 0;
00405 } else {
00406 ++ missedLayers;
00407 ++consecutiveMissedLayers;
00408 }
00409 }
00410 LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() << " Layer info: "
00411 << " totalLayers: " << totalLayers
00412 << " usedLayers: " << usedLayers
00413 << " missedLayers: " << missedLayers
00414 << " consecutiveMissedLayers: " << consecutiveMissedLayers;
00415
00416
00417 if ( consecutiveMissedLayers > maxNumberOfConsecutiveMissedLayersPerCloud ) {
00418 LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
00419 << " More than " << maxNumberOfConsecutiveMissedLayersPerCloud << " missed consecutive layers!";
00420 break;
00421 }
00422
00423
00424 if ( missedLayers > maxNumberOfMissedLayersPerCloud ) {
00425 LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
00426 << " More than " << maxNumberOfMissedLayersPerCloud << " missed layers!";
00427 break;
00428 }
00429
00430
00431 if ( totalLayers-missedLayers < minNumberOfUsedLayersPerCloud ) {
00432 LogDebug("RoadSearch") << "BREAK: seed # "<<seed-inputSeeds->begin()
00433 << " Cannot satisfy at least " << minNumberOfUsedLayersPerCloud << " used layers!";
00434 break;
00435 }
00436 }
00437
00438 }
00439
00440 if ( consecutiveMissedLayers <= maxNumberOfConsecutiveMissedLayersPerCloud ) {
00441 if ( usedLayers >= minNumberOfUsedLayersPerCloud ) {
00442 if ( missedLayers <= maxNumberOfMissedLayersPerCloud ) {
00443
00444 CloudArray[phibin][etabin].push_back(cloud);
00445
00446 if ( roadType == Roads::RPhi ){
00447 LogDebug("RoadSearch") << "This r-phi seed # "<<seed-inputSeeds->begin()
00448 <<" yields a cloud with " <<cloud.size() <<" hits on " << usedLayers << " layers out of " << totalLayers;
00449 } else {
00450 LogDebug("RoadSearch") << "This z-phi seed # "<<seed-inputSeeds->begin()
00451 <<" yields a cloud with " <<cloud.size() <<" hits on " << usedLayers << " layers out of " << totalLayers;
00452 }
00453 } else {
00454 LogDebug("RoadSearch") << "Missed layers: " << missedLayers << " More than " << maxNumberOfMissedLayersPerCloud << " missed layers!";
00455 if ( roadType == Roads::RPhi ){
00456 LogDebug("RoadSearch") << "This r-phi seed # "<<seed-inputSeeds->begin() <<" yields no clouds";
00457 } else {
00458 LogDebug("RoadSearch") << "This z-phi seed # "<<seed-inputSeeds->begin() <<" yields no clouds";
00459 }
00460 }
00461 }
00462 else {
00463 LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() <<" fails: used layers = " << usedLayers << " < " << minNumberOfUsedLayersPerCloud;
00464 }
00465 }
00466 else {
00467 LogDebug("RoadSearch") << "Seed # "<<seed-inputSeeds->begin() <<" fails: consecutive missed layers = " << consecutiveMissedLayers << " > " << maxNumberOfConsecutiveMissedLayersPerCloud;
00468 }
00469 }
00470 }
00471 }
00472
00473
00474 for (int iphi=0; iphi<nphibin; ++iphi){
00475 for (int ieta=0; ieta<netabin; ++ieta){
00476 if (!CloudArray[iphi][ieta].empty()) {
00477 if (doCleaning_){
00478 RoadSearchCloudCollection temp = Clean(&CloudArray[iphi][ieta]);
00479 for ( RoadSearchCloudCollection::const_iterator ic = temp.begin(); ic!=temp.end(); ++ic)
00480 output.push_back(*ic);
00481 }
00482 else
00483 for ( RoadSearchCloudCollection::const_iterator ic = CloudArray[iphi][ieta].begin();
00484 ic!=CloudArray[iphi][ieta].end(); ++ic)
00485 output.push_back(*ic);
00486 }
00487 }
00488 }
00489
00490 delete theHitMatcher;
00491 edm::LogInfo("RoadSearch") << "Found " << output.size() << " clouds.";
00492 for ( RoadSearchCloudCollection::const_iterator ic = output.begin(); ic!=output.end(); ++ic)
00493 edm::LogInfo("RoadSearch") << " Cloud " << ic-output.begin()<< " has " << ic->size() << " hits.";
00494
00495 }
00496
00497 unsigned int RoadSearchCloudMakerAlgorithm::FillRecHitsIntoCloudGeneral(DetId id, double d0, double phi0, double k0, double phi1, double k1,
00498 Roads::type roadType, double ringPhi,
00499 const TrackerGeometry *tracker, const SiStripRecHitMatcher* theHitMatcher,
00500 RoadSearchCloud &cloud) {
00501
00502 unsigned int usedRecHits = 0;
00503
00504 bool double_ring_layer = !isSingleLayer(id);
00505
00506 std::vector<TrackingRecHit*> recHitVector = recHitVectorClass.getHitVector(&id);
00507
00508 for ( std::vector<TrackingRecHit*>::const_iterator recHitIterator = recHitVector.begin(); recHitIterator != recHitVector.end(); ++recHitIterator) {
00509
00510 if ( (unsigned int)id.subdetId() == StripSubdetector::TIB
00511 || (unsigned int)id.subdetId() == StripSubdetector::TOB
00512 || (unsigned int)id.subdetId() == StripSubdetector::TID
00513 || (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00514
00515 const SiStripRecHit2D *recHit = (SiStripRecHit2D*)(*recHitIterator);
00516 DetId hitId = recHit->geographicalId();
00517
00518 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00519
00520 LogDebug("RoadSearch") << " Testing hit at (x/y/z): "
00521 << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).x() << " / "
00522 << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).y() << " / "
00523 << tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition()).z();
00524
00525 if ( roadType == Roads::RPhi ) {
00526 if (double_ring_layer && isSingleLayer(hitId)) {
00527
00528
00529
00530
00531
00532
00533 const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(tracker->idToDet(hitId));
00534
00535 SiStripMatchedRecHit2D* theCorrectedHit = CorrectMatchedHit(*recHitIterator,theGluedDet,
00536 tracker, theHitMatcher,
00537 k0, phi0);
00538 if (theCorrectedHit != 0){
00539
00540 GlobalPoint ghit = tracker->idToDet(theCorrectedHit->geographicalId())->surface().toGlobal(theCorrectedHit->localPosition());
00541 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00542 double hitphi = map_phi(ghit.phi());
00543 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00544
00545 float dp = (hitphi-phi);
00546 float dx = hitRadius*tan(dp);
00547
00548 LogDebug("RoadSearch") << " Hit phi = " << hitphi << " expected phi = " << phi
00549 <<" dx = " << dx << " for dxMax = " << phiMax(roadType,phi0,k0);
00550
00551
00552 if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
00553 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00554 cloud.addHit(recHit);
00555 ++usedRecHits;
00556 }
00557 }
00558 delete theCorrectedHit;
00559 }
00560 } else {
00561 if ( isBarrelSensor(hitId) ) {
00562
00563
00564
00565 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00566 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00567 double hitphi = map_phi(ghit.phi());
00568 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00569
00570 float dp = (hitphi-phi);
00571 float dx = hitRadius*tan(dp);
00572 LogDebug("RoadSearch") << " Hit phi = " << hitphi << " expected phi = " << phi
00573 <<" dx = " << dx << " for dxMax = " << phiMax(roadType,phi0,k0);
00574
00575 if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
00576 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00577 cloud.addHit(recHit);
00578 ++usedRecHits;
00579 }
00580 }
00581 }
00582 else {
00583
00584 LocalPoint hit = recHit->localPosition();
00585 const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
00586 double stripAngle = topology->stripAngle(topology->strip(hit));
00587 double stripLength = topology->localStripLength(hit);
00588
00589 LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
00590 LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
00591
00592 double innerRadius = tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).perp();
00593 double outerRadius = tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).perp();
00594 double innerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,innerRadius,roadType);
00595 double outerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,outerRadius,roadType);
00596
00597 GlobalPoint innerHitGlobal =tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal);
00598 GlobalPoint outerHitGlobal =tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal);
00599
00600 GlobalPoint innerRoadGlobal(GlobalPoint::Cylindrical(innerRadius,innerExtrapolatedPhi,
00601 tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z()));
00602 GlobalPoint outerRoadGlobal(GlobalPoint::Cylindrical(outerRadius,outerExtrapolatedPhi,
00603 tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z()));
00604
00605 LocalPoint innerRoadLocal = tracker->idToDetUnit(hitId)->surface().toLocal(innerRoadGlobal);
00606 LocalPoint outerRoadLocal = tracker->idToDetUnit(hitId)->surface().toLocal(outerRoadGlobal);
00607
00608 double dxinter = CheckXYIntersection(innerHitLocal, outerHitLocal,
00609 innerRoadLocal, outerRoadLocal);
00610
00611 LogDebug("RoadSearch") << " Hit phi inner = " << innerHitGlobal.phi() << " and outer = " << outerHitGlobal.phi()
00612 << " expected inner phi = " << innerExtrapolatedPhi
00613 << " and outer phi = " << outerExtrapolatedPhi
00614 <<" dx = " << dxinter << " for dxMax = " << phiMax(roadType,phi0,k0);
00615
00616 if ( fabs(dxinter) < phiMax(roadType,phi0,k0)) {
00617
00618
00619
00620 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00621 cloud.addHit(recHit);
00622 ++usedRecHits;
00623 }
00624 }
00625
00626
00627 }
00628 }
00629 } else {
00630
00631
00632
00633 if (double_ring_layer && isSingleLayer(hitId)) {
00634
00635
00636
00637
00638 const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(tracker->idToDet(hitId));
00639
00640 SiStripMatchedRecHit2D* theCorrectedHit = CorrectMatchedHit(*recHitIterator,theGluedDet,
00641 tracker, theHitMatcher,
00642 k1, phi1);
00643 if (theCorrectedHit != 0){
00644
00645 GlobalPoint ghit = tracker->idToDet(theCorrectedHit->geographicalId())->surface().toGlobal(theCorrectedHit->localPosition());
00646 double hitphi = map_phi(ghit.phi());
00647 double hitZ = ghit.z();
00648 double phi = phiFromExtrapolation(d0,phi0,k0,hitZ,roadType);
00649
00650 float dp = hitphi-phi;
00651 float dx = hitZ*tan(dp);
00652
00653
00654
00655
00656 if ( std::abs(dx) < phiMax(roadType,phi0,k1)) {
00657 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00658 cloud.addHit(recHit);
00659 ++usedRecHits;
00660 }
00661 }
00662 delete theCorrectedHit;
00663 }
00664 } else {
00665 if ( isBarrelSensor(hitId) ) {
00666
00667
00668
00669 LocalPoint hit = recHit->localPosition();
00670 const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
00671 double stripAngle = topology->stripAngle(topology->strip(hit));
00672 double stripLength = topology->localStripLength(hit);
00673
00674
00675
00676 LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
00677 LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
00678 double innerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).phi());
00679 double outerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).phi());
00680 double innerHitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).z();
00681 double outerHitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).z();
00682 double innerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,innerHitZ,roadType);
00683 double outerExtrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,outerHitZ,roadType);
00684
00685 double midPointZ = 0.5*(innerHitZ+outerHitZ);
00686
00687 double dPhiInter = CheckZPhiIntersection(innerHitPhi, innerHitZ, outerHitPhi, outerHitZ,
00688 innerExtrapolatedPhi, innerHitZ,
00689 outerExtrapolatedPhi, outerHitZ);
00690
00691 double dX = midPointZ*tan(dPhiInter);
00692
00693 if (std::abs(dX) < 1.5*phiMax(roadType,phi0,k1)) {
00694 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00695 cloud.addHit(recHit);
00696 ++usedRecHits;
00697 }
00698 }
00699
00700 } else {
00701
00702
00703
00704
00705 LocalPoint hit = recHit->localPosition();
00706 const StripTopology *topology = dynamic_cast<const StripTopology*>(&(tracker->idToDetUnit(hitId)->topology()));
00707 double stripAngle = topology->stripAngle(topology->strip(hit));
00708 double stripLength = topology->localStripLength(hit);
00709
00710 double hitZ = tracker->idToDetUnit(hitId)->surface().toGlobal(hit).z();
00711 double extrapolatedPhi = phiFromExtrapolation(d0,phi0,k0,hitZ,roadType);
00712
00713 LocalPoint innerHitLocal(hit.x()+stripLength/2*std::sin(stripAngle),hit.y()-stripLength/2*std::cos(stripAngle),0);
00714 LocalPoint outerHitLocal(hit.x()-stripLength/2*std::sin(stripAngle),hit.y()+stripLength/2*std::cos(stripAngle),0);
00715
00716 double innerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(innerHitLocal).phi());
00717 double outerHitPhi = map_phi(tracker->idToDetUnit(hitId)->surface().toGlobal(outerHitLocal).phi());
00718
00719
00720
00721
00722 double deltaPhi = ZPhiDeltaPhi(innerHitPhi,outerHitPhi,extrapolatedPhi);
00723 double deltaX = hitZ*tan(deltaPhi);
00724 if (std::abs(deltaX) < phiMax(roadType,phi0,k1)){
00725 if ((usedRecHits < maxDetHitsInCloudPerDetId) && (cloud.size() < maxRecHitsInCloud_)) {
00726 cloud.addHit(recHit);
00727 ++usedRecHits;
00728 }
00729 }
00730 }
00731 }
00732 }
00733 } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel
00734 || (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap) {
00735 if ( UsePixels ) {
00736
00737 const SiPixelRecHit *recHit = (SiPixelRecHit*)(*recHitIterator);
00738
00739 if ( roadType == Roads::RPhi ) {
00740
00741 if ( isBarrelSensor(id) ) {
00742
00743
00744 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00745 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00746 double hitphi = map_phi(ghit.phi());
00747 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00748
00749 float dp = hitphi-phi;
00750 float dx = hitRadius*tan(dp);
00751
00752
00753 if ( std::abs(dx) < phiMax(roadType,phi0,k0) ) {
00754 cloud.addHit(recHit);
00755 ++usedRecHits;
00756 }
00757 } else {
00758
00759
00760
00761
00762 LocalPoint hit = recHit->localPosition();
00763
00764
00765 double hitphi = map_phi(tracker->idToDetUnit(id)->surface().toGlobal(hit).phi());
00766
00767
00768 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00769
00770
00771 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00772
00773
00774 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00775
00776 if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
00777 cloud.addHit(recHit);
00778 ++usedRecHits;
00779 }
00780 }
00781 } else {
00782
00783 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00784 double phi = phiFromExtrapolation(d0,phi0,k0,ghit.z(),roadType);
00785 double hitphi = map_phi(ghit.phi());
00786 double dphi = map_phi2(hitphi-phi);
00787 float dx = ghit.z()*tan(dphi);
00788
00789 if ( std::abs(dx) < 0.25 ) {
00790 cloud.addHit(recHit);
00791 ++usedRecHits;
00792 }
00793 }
00794 }
00795 } else {
00796 edm::LogError("RoadSearch") << "recHitVector from general hit access function contains unknown detector id: " << (unsigned int)id.subdetId() << " rawId: " << id.rawId();
00797 }
00798
00799 }
00800
00801
00802 return usedRecHits;
00803 }
00804
00805 unsigned int RoadSearchCloudMakerAlgorithm::FillPixRecHitsIntoCloud(DetId id, const SiPixelRecHitCollection *inputRecHits,
00806 double d0, double phi0, double k0, Roads::type roadType, double ringPhi,
00807 const TrackerGeometry *tracker, RoadSearchCloud &cloud) {
00808
00809
00810 unsigned int usedRecHits = 0;
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820 const SiPixelRecHitCollection::range recHitRange = inputRecHits->get(id);
00821
00822 for ( SiPixelRecHitCollection::const_iterator recHitIterator = recHitRange.first;
00823 recHitIterator != recHitRange.second; ++recHitIterator) {
00824
00825 const SiPixelRecHit * recHit = &(*recHitIterator);
00826
00827 if ( roadType == Roads::RPhi ) {
00828
00829 if ( isBarrelSensor(id) ) {
00830
00831
00832 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00833 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00834 double hitphi = map_phi(ghit.phi());
00835 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00836
00837 if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
00838 cloud.addHit(recHit);
00839 ++usedRecHits;
00840 }
00841 }
00842 else {
00843
00844
00845
00846
00847 LocalPoint hit = recHit->localPosition();
00848
00849
00850 double hitphi = map_phi(tracker->idToDetUnit(id)->surface().toGlobal(hit).phi());
00851
00852
00853 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00854
00855
00856 double hitRadius = sqrt(ghit.x()*ghit.x()+ghit.y()*ghit.y());
00857
00858
00859 double phi = phiFromExtrapolation(d0,phi0,k0,hitRadius,roadType);
00860
00861 if ( std::abs(hitphi-phi) < phiMax(roadType,phi0,k0) ) {
00862 cloud.addHit(recHit);
00863 ++usedRecHits;
00864 }
00865 }
00866 }
00867
00868 else {
00869
00870 GlobalPoint ghit = tracker->idToDet(recHit->geographicalId())->surface().toGlobal(recHit->localPosition());
00871
00872 double phi = phiFromExtrapolation(d0,phi0,k0,ghit.z(),roadType);
00873 if ( (phi - phiMax(roadType,phi0,k0)) < ringPhi && (phi + phiMax(roadType,phi0,k0))>ringPhi ) {
00874 cloud.addHit(recHit);
00875 ++usedRecHits;
00876 }
00877 }
00878
00879 }
00880
00881 return usedRecHits;
00882 }
00883
00884 bool RoadSearchCloudMakerAlgorithm::isSingleLayer(DetId id) {
00885
00886 if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00887 TIBDetId tibid(id.rawId());
00888 if ( !tibid.glued() ) {
00889 return true;
00890 }
00891 } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00892 TOBDetId tobid(id.rawId());
00893 if ( !tobid.glued() ) {
00894 return true;
00895 }
00896 } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00897 TIDDetId tidid(id.rawId());
00898 if ( !tidid.glued() ) {
00899 return true;
00900 }
00901 } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00902 TECDetId tecid(id.rawId());
00903 if ( !tecid.glued() ) {
00904 return true;
00905 }
00906 } else {
00907 return false;
00908 }
00909
00910 return false;
00911 }
00912
00913 bool RoadSearchCloudMakerAlgorithm::isBarrelSensor(DetId id) {
00914
00915 if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00916 return true;
00917 } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00918 return true;
00919 } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
00920 return true;
00921 } else {
00922 return false;
00923 }
00924
00925 }
00926
00927 double RoadSearchCloudMakerAlgorithm::phiFromExtrapolation(double d0, double phi0, double k0, double ringRadius, Roads::type roadType) {
00928
00929 double ringPhi = -99.;
00930 if ( roadType == Roads::RPhi ) {
00931 double omega=k0, rl=ringRadius;
00932 double sp0=sin(phi0); double cp0=cos(phi0);
00933 if (fabs(omega)>0.000005){
00934 double xc=-sp0*(d0+1.0/omega);
00935 double yc=cp0*(d0+1.0/omega);
00936 double rh=fabs(1.0/omega);
00937 double bbb=fabs(d0+1.0/omega);
00938 double sss=0.5*(rl+rh+bbb);
00939 double ddd=sqrt((sss-bbb)*(sss-rh)/(sss*(sss-rl)));
00940 double phil1=2.0*atan(ddd);
00941 double phit=phi0+phil1; if (omega<0.0)phit=phi0-phil1;
00942 double xh=xc+sin(phit)/omega;
00943 double yh=yc-cos(phit)/omega;
00944 double phih=atan2(yh,xh);
00945 ringPhi = map_phi(phih);
00946 }
00947 else {
00948 double cee = rl*rl - d0*d0 -0.25*omega*omega - omega*d0;
00949 if (cee<0.0){return ringPhi;}
00950 double l = sqrt(cee);
00951 double xh=-sp0*d0+l*cp0-0.5*l*l*omega*sp0;
00952 double yh= cp0*d0+l*sp0+0.5*l*l*omega*cp0;
00953 double phih=atan2(yh,xh);
00954 ringPhi = map_phi(phih);
00955 }
00956 }
00957 else {
00958 ringPhi = map_phi(phi0 + k0 * ringRadius);
00959 }
00960
00961 return ringPhi;
00962 }
00963
00964 double RoadSearchCloudMakerAlgorithm::phiMax(Roads::type roadType,
00965 double phi0, double k0) {
00966
00967 double dphi;
00968 if ( roadType == Roads::RPhi ) {
00969
00970
00971 dphi = theRPhiRoadSize + 0.15*82.0*fabs(k0);
00972 }
00973 else if ( roadType == Roads::ZPhi ) {
00974 dphi = theZPhiRoadSize + 0.4*82.0*fabs(k0);
00975 }
00976 else {
00977 edm::LogWarning("RoadSearch") << "Bad roadType: "<< roadType;
00978 dphi = theZPhiRoadSize;
00979 }
00980 return dphi;
00981
00982 }
00983
00984 void RoadSearchCloudMakerAlgorithm::makecircle(double x1, double y1,
00985 double x2,double y2, double x3, double y3){
00986 double x1t=x1-x3; double y1t=y1-y3; double r1s=x1t*x1t+y1t*y1t;
00987 double x2t=x2-x3; double y2t=y2-y3; double r2s=x2t*x2t+y2t*y2t;
00988 double rho=x1t*y2t-x2t*y1t;
00989 double xc, yc, rc, fac;
00990 if (fabs(rho)<RoadSearchCloudMakerAlgorithm::epsilon){
00991 rc=1.0/(RoadSearchCloudMakerAlgorithm::epsilon);
00992 fac=sqrt(x1t*x1t+y1t*y1t);
00993 xc=x2+y1t*rc/fac;
00994 yc=y2-x1t*rc/fac;
00995 }else{
00996 fac=0.5/rho;
00997 xc=fac*(r1s*y2t-r2s*y1t);
00998 yc=fac*(r2s*x1t-r1s*x2t);
00999 rc=sqrt(xc*xc+yc*yc); xc+=x3; yc+=y3;
01000 }
01001 double s3=0.0;
01002 double f1=x1*yc-y1*xc; double f2=x2*yc-y2*xc;
01003 double f3=x3*yc-y3*xc;
01004 if ((f1<0.0)&&(f2<0.0)&&(f3<=0.0))s3=1.0;
01005 if ((f1>0.0)&&(f2>0.0)&&(f3>=0.0))s3=-1.0;
01006 d0h=-s3*(sqrt(xc*xc+yc*yc)-rc);
01007 phi0h=atan2(yc,xc)+s3*Geom::halfPi();
01008 omegah=-s3/rc;
01009 }
01010
01011 double RoadSearchCloudMakerAlgorithm::CheckXYIntersection(LocalPoint& inner1, LocalPoint& outer1,
01012 LocalPoint& inner2, LocalPoint& outer2){
01013
01014 double deltaX = -999.;
01015
01016
01017 double det12 = inner1.x()*outer1.y() - inner1.y()*outer1.x();
01018 double det34 = inner2.x()*outer2.y() - inner2.y()*outer2.x();
01019
01020 double xinter = (det12*(inner2.x()-outer2.x()) - det34*(inner1.x()-outer1.x()))/
01021 ((inner1.x()-outer1.x())*(inner2.y()-outer2.y()) -
01022 (inner2.x()-outer2.x())*(inner1.y()-outer1.y()));
01023
01024 bool inter = true;
01025 if (inner1.x() < outer1.x()){
01026 if ((xinter<inner1.x()) || (xinter>outer1.x())) inter = false;
01027 }
01028 else{
01029 if ((xinter>inner1.x()) || (xinter<outer1.x())) inter = false;
01030 }
01031
01032 if (inner2.x() < outer2.x()){
01033 if ((xinter<inner2.x()) || (xinter>outer2.x())) inter = false;
01034 }
01035 else{
01036 if ((xinter>inner2.x()) || (xinter<outer2.x())) inter = false;
01037 }
01038
01039 if (inter){
01040 deltaX = 0;
01041 }
01042 else{
01043 deltaX = min(fabs(inner1.x()-inner2.x()),fabs(outer1.x()-outer2.x()));
01044 }
01045 return deltaX;
01046
01047 }
01048
01049 double RoadSearchCloudMakerAlgorithm::CheckZPhiIntersection(double iPhi1, double iZ1, double oPhi1, double oZ1,
01050 double iPhi2, double iZ2, double oPhi2, double oZ2){
01051
01052
01053 if ((iPhi1 > Geom::pi() || oPhi1 > Geom::pi() || iPhi2 > Geom::pi() || oPhi2 > Geom::pi()) &&
01054 (iPhi1 < Geom::pi() || oPhi1 < Geom::pi() || iPhi2 < Geom::pi() || oPhi2 < Geom::pi())){
01055 iPhi1 = map_phi2(iPhi1); oPhi1 = map_phi2(oPhi1);
01056 iPhi2 = map_phi2(iPhi2); oPhi2 = map_phi2(oPhi2);
01057 }
01058
01059 double deltaPhi = -999.;
01060
01061
01062 double det12 = iZ1*oPhi1 - iPhi1*oZ1;
01063 double det34 = iZ2*oPhi2 - iPhi2*oZ2;
01064
01065 double xinter = (det12*(iZ2-oZ2) - det34*(iZ1-oZ1))/
01066 ((iZ1-oZ1)*(iPhi2-oPhi2) -
01067 (iZ2-oZ2)*(iPhi1-oPhi1));
01068
01069 bool inter = true;
01070 if (iZ1 < oZ1){
01071 if ((xinter<iZ1) || (xinter>oZ1)) inter = false;
01072 }
01073 else{
01074 if ((xinter>iZ1) || (xinter<oZ1)) inter = false;
01075 }
01076
01077 if (iZ2 < oZ2){
01078 if ((xinter<iZ2) || (xinter>oZ2)) inter = false;
01079 }
01080 else{
01081 if ((xinter>iZ2) || (xinter<oZ2)) inter = false;
01082 }
01083
01084 if (inter){
01085 deltaPhi = 0;
01086 }
01087 else{
01088 deltaPhi = min(fabs(iPhi2-iPhi1),fabs(oPhi2-oPhi1));
01089 }
01090 return deltaPhi;
01091
01092 }
01093
01094
01095 double RoadSearchCloudMakerAlgorithm::ZPhiDeltaPhi(double hitPhi1, double hitPhi2, double predictedPhi){
01096
01097 double deltaPhi = -999.;
01098
01099 double dPhiHits = map_phi2(hitPhi1-hitPhi2);
01100 double dPhi1 = map_phi2(hitPhi1-predictedPhi);
01101 double dPhi2 = map_phi2(hitPhi2-predictedPhi);
01102
01103 if (dPhiHits >= 0){
01104 if ( (dPhi1>=0.0) && (dPhi2 <= 0.0))
01105 deltaPhi = 0.0;
01106 else{
01107 if (std::abs(dPhi1)<std::abs(dPhi2))
01108 deltaPhi = dPhi1;
01109 else
01110 deltaPhi = dPhi2;
01111 }
01112 }
01113 else {
01114 if ( (dPhi1<=0.0) && (dPhi2 >= 0.0))
01115 deltaPhi = 0.0;
01116 else{
01117 if (std::abs(dPhi1)<std::abs(dPhi2))
01118 deltaPhi = dPhi1;
01119 else
01120 deltaPhi = dPhi2;
01121 }
01122 }
01123
01124 return deltaPhi;
01125
01126 }
01127
01128 RoadSearchCloudCollection RoadSearchCloudMakerAlgorithm::Clean(RoadSearchCloudCollection* inputCollection){
01129
01130 RoadSearchCloudCollection output;
01131
01132
01133
01134
01135
01136 if ( inputCollection->empty() ){
01137 LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
01138 return output;
01139 }
01140
01141
01142
01143
01144
01145 if ( 1==inputCollection->size() ){
01146 output = *inputCollection;
01147
01148
01149
01150 LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
01151 return output;
01152 }
01153
01154
01155
01156
01157 std::vector<bool> already_gone(inputCollection->size());
01158 for (unsigned int i=0; i<inputCollection->size(); ++i) {
01159 already_gone[i] = false;
01160 }
01161
01162 int raw_cloud_ctr=0;
01163
01164 for ( RoadSearchCloudCollection::const_iterator raw_cloud = inputCollection->begin(); raw_cloud != inputCollection->end(); ++raw_cloud) {
01165 ++raw_cloud_ctr;
01166
01167 if (already_gone[raw_cloud_ctr-1])continue;
01168
01169
01170
01171
01172
01173 RoadSearchCloud lone_cloud = *raw_cloud;
01174
01175 int second_cloud_ctr=raw_cloud_ctr;
01176 for ( RoadSearchCloudCollection::const_iterator second_cloud = raw_cloud+1; second_cloud != inputCollection->end(); ++second_cloud) {
01177 second_cloud_ctr++;
01178
01179 std::vector<const TrackingRecHit*> unshared_hits;
01180
01181 if ( already_gone[second_cloud_ctr-1] )continue;
01182
01183 for ( RoadSearchCloud::RecHitVector::const_iterator second_cloud_hit = second_cloud->begin_hits();
01184 second_cloud_hit != second_cloud->end_hits();
01185 ++ second_cloud_hit ) {
01186 bool is_shared = false;
01187 for ( RoadSearchCloud::RecHitVector::const_iterator lone_cloud_hit = lone_cloud.begin_hits();
01188 lone_cloud_hit != lone_cloud.end_hits();
01189 ++ lone_cloud_hit ) {
01190
01191 if ((*lone_cloud_hit)->geographicalId() == (*second_cloud_hit)->geographicalId())
01192 if ((*lone_cloud_hit)->localPosition().x() == (*second_cloud_hit)->localPosition().x())
01193 if ((*lone_cloud_hit)->localPosition().y() == (*second_cloud_hit)->localPosition().y())
01194 {is_shared=true; break;}
01195 }
01196 if (!is_shared) unshared_hits.push_back(*second_cloud_hit);
01197
01198 if ( ((float(unshared_hits.size())/float(lone_cloud.size())) >
01199 ((float(second_cloud->size())/float(lone_cloud.size()))-mergingFraction_)) &&
01200 ((float(unshared_hits.size())/float(second_cloud->size())) > (1-mergingFraction_))){
01201
01202 break;
01203 }
01204
01205 if (lone_cloud.size()+unshared_hits.size() > maxRecHitsInCloud_) {
01206 break;
01207 }
01208
01209 }
01210
01211 double f_lone_shared=double(second_cloud->size()-unshared_hits.size())/double(lone_cloud.size());
01212 double f_second_shared=double(second_cloud->size()-unshared_hits.size())/double(second_cloud->size());
01213
01214 if ( ( (static_cast<unsigned int>(f_lone_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9))||(static_cast<unsigned int>(f_second_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9)) )
01215 && (lone_cloud.size()+unshared_hits.size() <= maxRecHitsInCloud_) ){
01216
01217 LogDebug("RoadSearch") << " Merge CloudA: " << raw_cloud_ctr << " with CloudB: " << second_cloud_ctr
01218 << " Shared fractions are " << f_lone_shared << " and " << f_second_shared;
01219
01220
01221
01222
01223 for (unsigned int k=0; k<unshared_hits.size(); ++k) {
01224 lone_cloud.addHit(unshared_hits[k]);
01225 }
01226
01227 already_gone[second_cloud_ctr-1]=true;
01228
01229 }
01230
01231 }
01232
01233 output.push_back(lone_cloud);
01234
01235 }
01236
01237 LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
01238
01239 return output;
01240 }
01241
01242 SiStripMatchedRecHit2D* RoadSearchCloudMakerAlgorithm::CorrectMatchedHit(const TrackingRecHit *originalHit,
01243 const GluedGeomDet* gluedDet,
01244 const TrackerGeometry *tracker,
01245 const SiStripRecHitMatcher* theHitMatcher,
01246 double k0, double phi0) {
01247
01248 const SiStripMatchedRecHit2D *theRH = dynamic_cast<const SiStripMatchedRecHit2D*>(originalHit);
01249 if (theRH == 0) {
01250 std::cout<<" Could not cast original hit" << std::endl;
01251 }
01252 if (theRH != 0){
01253 const GeomDet *recHitGeomDet = tracker->idToDet(theRH->geographicalId());
01254 const GluedGeomDet *theGluedDet = dynamic_cast<const GluedGeomDet*>(recHitGeomDet);
01255
01256 const GeomDetUnit* theMonoDet = theGluedDet->monoDet();
01257 const SiStripRecHit2D* theMonoHit = theRH->monoHit();
01258 GlobalPoint monoRHpos = (theMonoDet->surface()).toGlobal(theMonoHit->localPosition());
01259
01260 GlobalPoint gcenterofstrip=(theMonoDet->surface()).toGlobal(theMonoHit->localPosition());
01261
01262 float gtrackangle_xy = map_phi2(phi0 + 2.0*asin(0.5*gcenterofstrip.perp()*k0));
01263 float rzangle = atan2(gcenterofstrip.perp(),gcenterofstrip.z());
01264
01265 GlobalVector gtrackangle2(cos(gtrackangle_xy)*sin(rzangle),
01266 sin(gtrackangle_xy)*sin(rzangle),
01267 cos(rzangle));
01268 LocalVector trackdirection2=((tracker->idToDet(theRH->geographicalId()))->surface()).toLocal(gtrackangle2);
01269 GlobalVector gdir = theMonoDet->surface().toGlobal(trackdirection2);
01270
01271 SiStripMatchedRecHit2D* theCorrectedHit = theHitMatcher->match(theRH,theGluedDet,trackdirection2);
01272 if (theCorrectedHit!=0) return theCorrectedHit;
01273 }
01274
01275 return 0;
01276 }