CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
MultiHitGeneratorFromChi2 Class Reference

#include <MultiHitGeneratorFromChi2.h>

Inheritance diagram for MultiHitGeneratorFromChi2:
MultiHitGeneratorFromPairAndLayers MultiHitGenerator OrderedHitsGenerator

Public Member Functions

virtual void hitSets (const TrackingRegion &region, OrderedMultiHits &trs, const edm::Event &ev, const edm::EventSetup &es)
 
virtual void init (const HitPairGenerator &pairs, const std::vector< ctfseeding::SeedingLayer > &layers, LayerCacheType *layerCache)
 
 MultiHitGeneratorFromChi2 (const edm::ParameterSet &cfg)
 
const HitPairGeneratorpairGenerator () const
 
const std::vector
< ctfseeding::SeedingLayer > & 
thirdLayers () const
 
virtual ~MultiHitGeneratorFromChi2 ()
 
- Public Member Functions inherited from MultiHitGeneratorFromPairAndLayers
virtual ~MultiHitGeneratorFromPairAndLayers ()
 
- Public Member Functions inherited from MultiHitGenerator
virtual void clear ()
 
virtual void hitSets (const TrackingRegion &reg, OrderedMultiHits &prs, const edm::EventSetup &es)
 
 MultiHitGenerator (unsigned int size=500)
 
virtual const OrderedMultiHitsrun (const TrackingRegion &region, const edm::Event &ev, const edm::EventSetup &es)
 
virtual ~MultiHitGenerator ()
 
- Public Member Functions inherited from OrderedHitsGenerator
 OrderedHitsGenerator ()
 
virtual ~OrderedHitsGenerator ()
 

Private Types

typedef
CombinedMultiHitGenerator::LayerCacheType 
LayerCacheType
 

Private Member Functions

bool checkPhiInRange (float phi, float phi1, float phi2) const
 
std::pair< float, float > mergePhiRanges (const std::pair< float, float > &r1, const std::pair< float, float > &r2) const
 

Private Attributes

const MagneticFieldbfield
 
std::vector< double > chi2_cuts
 
bool chi2VsPtCut
 
bool debug
 
std::vector< int > detIdsToDebug
 
float dphi
 
float extraHitRPhitolerance
 
float extraHitRZtolerance
 
float extraPhiKDBox
 
const ClusterShapeHitFilterfilter
 
std::string filterName_
 
double fnSigmaRZ
 
double maxChi2
 
float nomField
 
double nSigmaPhi
 
double nSigmaRZ
 
std::vector< double > pt_interv
 
bool refitHits
 
LayerCacheTypetheLayerCache
 
std::vector
< ctfseeding::SeedingLayer
theLayers
 
HitPairGeneratorthePairGenerator
 
bool useFixedPreFiltering
 

Additional Inherited Members

- Public Types inherited from MultiHitGeneratorFromPairAndLayers
typedef LayerHitMapCache LayerCacheType
 
- Public Attributes inherited from OrderedHitsGenerator
unsigned int theMaxElement
 

Detailed Description

A MultiHitGenerator from HitPairGenerator and vector of Layers. The HitPairGenerator provides a set of hit pairs. For each pair the search for compatible hit(s) is done among provided Layers

Definition at line 23 of file MultiHitGeneratorFromChi2.h.

Member Typedef Documentation

Definition at line 25 of file MultiHitGeneratorFromChi2.h.

Constructor & Destructor Documentation

MultiHitGeneratorFromChi2::MultiHitGeneratorFromChi2 ( const edm::ParameterSet cfg)

Definition at line 49 of file MultiHitGeneratorFromChi2.cc.

References bfield, chi2_cuts, chi2VsPtCut, debug, detIdsToDebug, dphi, edm::ParameterSet::getParameter(), nomField, pt_interv, OrderedHitsGenerator::theMaxElement, and useFixedPreFiltering.

50  : thePairGenerator(0),
51  theLayerCache(0),
52  useFixedPreFiltering(cfg.getParameter<bool>("useFixedPreFiltering")),
53  extraHitRZtolerance(cfg.getParameter<double>("extraHitRZtolerance")),
54  extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")),
55  extraPhiKDBox(cfg.getParameter<double>("extraPhiKDBox")),
56  fnSigmaRZ(cfg.getParameter<double>("fnSigmaRZ")),
57  chi2VsPtCut(cfg.getParameter<bool>("chi2VsPtCut")),
58  maxChi2(cfg.getParameter<double>("maxChi2")),
59  refitHits(cfg.getParameter<bool>("refitHits")),
60  debug(cfg.getParameter<bool>("debug")),
61  filterName_(cfg.getParameter<std::string>("ClusterShapeHitFilterName"))
62 {
63  theMaxElement=cfg.getParameter<unsigned int>("maxElement");
65  dphi = cfg.getParameter<double>("phiPreFiltering");
66  if (chi2VsPtCut) {
67  pt_interv = cfg.getParameter<std::vector<double> >("pt_interv");
68  chi2_cuts = cfg.getParameter<std::vector<double> >("chi2_cuts");
69  }
70  if (debug) {
71  detIdsToDebug = cfg.getParameter<std::vector<int> >("detIdsToDebug");
72  //if (detIdsToDebug.size()<3) //fixme
73  } else {
74  detIdsToDebug.push_back(0);
75  detIdsToDebug.push_back(0);
76  detIdsToDebug.push_back(0);
77  }
78  bfield = 0;
79  nomField = -1.;
80 }
T getParameter(std::string const &) const
virtual MultiHitGeneratorFromChi2::~MultiHitGeneratorFromChi2 ( )
inlinevirtual

Definition at line 30 of file MultiHitGeneratorFromChi2.h.

References thePairGenerator.

30 { delete thePairGenerator; }

Member Function Documentation

bool MultiHitGeneratorFromChi2::checkPhiInRange ( float  phi,
float  phi1,
float  phi2 
) const
private

Definition at line 598 of file MultiHitGeneratorFromChi2.cc.

References M_PI.

599 { while (phi > phi2) phi -= 2. * M_PI;
600  while (phi < phi1) phi += 2. * M_PI;
601  return phi <= phi2;
602 }
#define M_PI
Definition: BFit3D.cc:3
Definition: DDAxes.h:10
void MultiHitGeneratorFromChi2::hitSets ( const TrackingRegion region,
OrderedMultiHits trs,
const edm::Event ev,
const edm::EventSetup es 
)
virtual

Implements MultiHitGenerator.

Definition at line 106 of file MultiHitGeneratorFromChi2.cc.

References RecHitsSortedInPhi::all(), angle(), GeomDetEnumerators::barrel, bfield, KDTreeLinkerAlgo< DATA >::build(), RZLine::chi2(), chi2_cuts, chi2VsPtCut, gather_cfg::cout, ThirdHitPredictionFromCircle::curvature(), PixelRecoUtilities::curvature(), debug, detIdsToDebug, dphi, relativeConstraints::empty, extraHitRPhitolerance, extraHitRZtolerance, extraPhiKDBox, filter, filterName_, RZLine::fit(), fnSigmaRZ, edm::EventSetup::get(), ClusterShapeHitFilter::isCompatible(), geometryCSVtoXML::line, DetLayer::location(), max(), maxChi2, mergePhiRanges(), mergeVDriftHistosByStation::name, nomField, MagneticField::nominalValue(), ProjectedSiStripRecHit2D::originalHit(), TrackingRegion::originRBound(), PV3DBase< T, PVType, FrameType >::perp(), Geom::pi(), PixelSubdetector::PixelBarrel, edm::ESHandle< class >::product(), RecoTauCleanerPlugins::pt, pt_interv, TrackingRegion::ptMin(), alignCSCRings::r, CosmicsPD_Skims::radius, refitHits, rho, KDTreeLinkerAlgo< DATA >::search(), OrderedMultiHits::size(), OrderedHitPairs::size(), findQualityFiles::size, mathSSE::sqrt(), swap(), theLayers, OrderedHitsGenerator::theMaxElement, thePairGenerator, StripSubdetector::TIB, SiStripDetId::TIB, StripSubdetector::TOB, patCandidatesForDimuonsSequences_cff::tracker, Geom::twoPi(), useFixedPreFiltering, and detailsBasic3DVector::z.

110 {
111 
112  //gc: why is this here and not in some initialization???
114  es.get<TrackerDigiGeometryRecord>().get(tracker);
115  if (nomField<0 && bfield == 0) {
117  es.get<IdealMagneticFieldRecord>().get(bfield_h);
118  bfield = bfield_h.product();
120  }
121 
123  es.get<CkfComponentsRecord>().get(filterName_, filterHandle_);
124  filter = filterHandle_.product();
125 
126  //Retrieve tracker topology from geometry
127  //edm::ESHandle<TrackerTopology> tTopoHand;
128  //es.get<IdealGeometryRecord>().get(tTopoHand);
129  //const TrackerTopology *tTopo=tTopoHand.product();
130 
131  if (debug) cout << "pair: " << ((HitPairGeneratorFromLayerPair*) thePairGenerator)->innerLayer().name() << "+" << ((HitPairGeneratorFromLayerPair*) thePairGenerator)->outerLayer().name() << " 3rd lay size: " << theLayers.size() << endl;
132 
133  //gc: first get the pairs
134  OrderedHitPairs pairs;
135  pairs.reserve(30000);
136  thePairGenerator->hitPairs(region,pairs,ev,es);
137  if (pairs.empty()) {
138  //cout << "empy pairs" << endl;
139  return;
140  }
141 
142  //gc: these are all the layers compatible with the layer pairs (as defined in the config file)
143  int size = theLayers.size();
144 
145  unsigned int debug_Id0 = detIdsToDebug[0];//402664068;
146  unsigned int debug_Id1 = detIdsToDebug[1];//402666628;
147  unsigned int debug_Id2 = detIdsToDebug[2];//402669320;//470049160;
148 
149  //gc: initialize a KDTree per each 3rd layer
150  std::vector<KDTreeNodeInfo<RecHitsSortedInPhi::HitIter> > layerTree; // re-used throughout
151  std::vector<RecHitsSortedInPhi::HitIter> foundNodes; // re-used thoughout
152  foundNodes.reserve(100);
154  float rzError[size]; //save maximum errors
155  double maxphi = Geom::twoPi(), minphi = -maxphi; //increase to cater for any range
156 
157  //map<const DetLayer*, LayerRZPredictions> mapPred;//gc
158  map<std::string, LayerRZPredictions> mapPred;//need to use the name as map key since we may have more than one SeedingLayer per DetLayer (e.g. TEC and OTEC)
159  const RecHitsSortedInPhi * thirdHitMap[size];//gc: this comes from theLayerCache
160 
161  //gc: loop over each layer
162  for(int il = 0; il < size; il++) {
163  thirdHitMap[il] = &(*theLayerCache)(&theLayers[il], region, ev, es);
164  if (debug) cout << "considering third layer: " << theLayers[il].name() << " with hits: " << thirdHitMap[il]->all().second-thirdHitMap[il]->all().first << endl;
165  const DetLayer *layer = theLayers[il].detLayer();
166  LayerRZPredictions &predRZ = mapPred[theLayers[il].name()];
167  predRZ.line.initLayer(layer);
168  predRZ.line.initTolerance(extraHitRZtolerance);
169 
170  //gc: now we take all hits in the layer and fill the KDTree
171  RecHitsSortedInPhi::Range hitRange = thirdHitMap[il]->all(); // Get iterators
172  layerTree.clear();
173  double minz=999999.0, maxz= -999999.0; // Initialise to extreme values in case no hits
174  float maxErr=0.0f;
175  bool barrelLayer = (theLayers[il].detLayer()->location() == GeomDetEnumerators::barrel);
176  if (hitRange.first != hitRange.second)
177  { minz = barrelLayer? hitRange.first->hit()->globalPosition().z() : hitRange.first->hit()->globalPosition().perp();
178  maxz = minz; //In case there's only one hit on the layer
179  for (RecHitsSortedInPhi::HitIter hi=hitRange.first; hi != hitRange.second; ++hi)
180  { double angle = hi->phi();
181  double myz = barrelLayer? hi->hit()->globalPosition().z() : hi->hit()->globalPosition().perp();
182 
183  if (debug && hi->hit()->rawId()==debug_Id2) cout << "filling KDTree with hit in id=" << debug_Id2
184  << " with pos: " << hi->hit()->globalPosition()
185  << " phi=" << hi->hit()->globalPosition().phi()
186  << " z=" << hi->hit()->globalPosition().z()
187  << " r=" << hi->hit()->globalPosition().perp()
188  << " trans: " << hi->hit()->transientHits()[0]->globalPosition() << " "
189  << (hi->hit()->transientHits().size()>1 ? hi->hit()->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
190  << endl;
191 
192  //use (phi,r) for endcaps rather than (phi,z)
193  if (myz < minz) { minz = myz;} else { if (myz > maxz) {maxz = myz;}}
194  float myerr = barrelLayer? hi->hit()->errorGlobalZ(): hi->hit()->errorGlobalR();
195  if (myerr > maxErr) { maxErr = myerr;}
196  layerTree.push_back(KDTreeNodeInfo<RecHitsSortedInPhi::HitIter>(hi, angle, myz)); // save it
197  if (angle < 0) // wrap all points in phi
198  { layerTree.push_back(KDTreeNodeInfo<RecHitsSortedInPhi::HitIter>(hi, angle+Geom::twoPi(), myz));}
199  else
200  { layerTree.push_back(KDTreeNodeInfo<RecHitsSortedInPhi::HitIter>(hi, angle-Geom::twoPi(), myz));}
201  }
202  }
203  KDTreeBox phiZ(minphi, maxphi, minz-0.01, maxz+0.01); // declare our bounds
204  //add fudge factors in case only one hit and also for floating-point inaccuracy
205  hitTree[il].build(layerTree, phiZ); // make KDtree
206  rzError[il] = maxErr; //save error
207  }
208  //gc: ok now we have initialized the KDTrees and we are out of the layer loop
209 
210  //gc: ok, this sets the minPt of the triplet
211  double curv = PixelRecoUtilities::curvature(1. / region.ptMin(), es);
212 
213  if (debug) std::cout << "pair size=" << pairs.size() << std::endl;
214 
215  //gc: now we loop over all pairs
216  for (OrderedHitPairs::const_iterator ip = pairs.begin(); ip != pairs.end(); ++ip) {
217 
218  int foundTripletsFromPair = 0;
219  bool usePair = false;
220  SeedingHitSet triplet;
222 
225 
226  GlobalPoint gp0 = hit0->globalPosition();//ip->inner()->globalPosition();
227  GlobalPoint gp1 = hit1->globalPosition();//ip->outer()->globalPosition();
228 
229  if (refitHits) {//fixme
230  GlobalVector pairMomentum(gp1 - gp0);
231  pairMomentum *= (1./pairMomentum.perp()); //set pT=1
232  GlobalTrajectoryParameters kinePair0 = GlobalTrajectoryParameters(hit0->globalPosition(), pairMomentum, 1, &*bfield);
233  TrajectoryStateOnSurface statePair0(kinePair0,*hit0->surface());
234  GlobalTrajectoryParameters kinePair1 = GlobalTrajectoryParameters(hit1->globalPosition(), pairMomentum, 1, &*bfield);
235  TrajectoryStateOnSurface statePair1(kinePair1,*hit1->surface());
236  hit0 = hit0->clone(statePair0);
237  hit1 = hit1->clone(statePair1);
238 
239  if (/* hit0->geographicalId().subdetId() > 2 && (*/
240  hit0->geographicalId().subdetId()==SiStripDetId::TIB /*|| hit0->geographicalId().subdetId()==SiStripDetId::TOB)*/
241  ) {
242  const std::type_info &tid = typeid(*hit0->hit());
243  if (tid == typeid(SiStripMatchedRecHit2D)) {
244  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(hit0->hit());
245  if (filter->isCompatible(DetId(matchedHit->monoId()), matchedHit->monoCluster(), pairMomentum)==0 ||
246  filter->isCompatible(DetId(matchedHit->stereoId()), matchedHit->stereoCluster(), pairMomentum)==0) continue;
247  } else if (tid == typeid(SiStripRecHit2D)) {
248  const SiStripRecHit2D* recHit = dynamic_cast<const SiStripRecHit2D *>(hit0->hit());
249  if (filter->isCompatible(*recHit, pairMomentum)==0) continue;
250  } else if (tid == typeid(ProjectedSiStripRecHit2D)) {
251  const ProjectedSiStripRecHit2D* precHit = dynamic_cast<const ProjectedSiStripRecHit2D *>(hit0->hit());
252  if (filter->isCompatible(precHit->originalHit(), pairMomentum)==0) continue;;
253  }
254  }
255 
256  if (/*hit1->geographicalId().subdetId() > 2 && (*/
257  hit1->geographicalId().subdetId()==SiStripDetId::TIB /*|| hit1->geographicalId().subdetId()==SiStripDetId::TOB)*/
258  ) {
259  const std::type_info &tid = typeid(*hit1->hit());
260  if (tid == typeid(SiStripMatchedRecHit2D)) {
261  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(hit1->hit());
262  if (filter->isCompatible(DetId(matchedHit->monoId()), matchedHit->monoCluster(), pairMomentum)==0 ||
263  filter->isCompatible(DetId(matchedHit->stereoId()), matchedHit->stereoCluster(), pairMomentum)==0) continue;
264  } else if (tid == typeid(SiStripRecHit2D)) {
265  const SiStripRecHit2D* recHit = dynamic_cast<const SiStripRecHit2D *>(hit1->hit());
266  if (filter->isCompatible(*recHit, pairMomentum)==0) continue;
267  } else if (tid == typeid(ProjectedSiStripRecHit2D)) {
268  const ProjectedSiStripRecHit2D* precHit = dynamic_cast<const ProjectedSiStripRecHit2D *>(hit1->hit());
269  if (filter->isCompatible(precHit->originalHit(), pairMomentum)==0) continue;;
270  }
271  }
272 
273 
274  }
275  //const TransientTrackingRecHit::ConstRecHitPointer& hit0 = refitHits ? ip->inner()->clone(statePair0) : ip->inner();
276  //const TransientTrackingRecHit::ConstRecHitPointer& hit1 = refitHits ? ip->outer()->clone(statePair1) : ip->outer();
277 
278  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) {
279  cout << "found new pair with ids "<<debug_Id0<<" "<<debug_Id1<<" with pos: " << gp0 << " " << gp1
280  << " trans0: " << ip->inner()->transientHits()[0]->globalPosition() << " " << ip->inner()->transientHits()[1]->globalPosition()
281  << " trans1: " << ip->outer()->transientHits()[0]->globalPosition() << " " << ip->outer()->transientHits()[1]->globalPosition()
282  << endl;
283  }
284 
285  //gc: create the RZ line for the pair
286  PixelRecoLineRZ line(gp0, gp1);
287  ThirdHitPredictionFromCircle predictionRPhi(gp0, gp1, extraHitRPhitolerance);
288 
289  //gc: this is the curvature of the two hits assuming the region
290  Range generalCurvature = predictionRPhi.curvature(region.originRBound());
291  if (!intersect(generalCurvature, Range(-curv, curv))) {
292  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) std::cout << "curvature cut: curv=" << curv << " gc=(" << generalCurvature.first << ", " << generalCurvature.second << ")" << std::endl;
293  continue;
294  }
295 
296  //gc: loop over all third layers compatible with the pair
297  for(int il = 0; il < size && !usePair; il++) {
298 
299  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1)
300  cout << "cosider layer: " << theLayers[il].name() << " for this pair. Location: " << theLayers[il].detLayer()->location() << endl;
301 
302  if (hitTree[il].empty()) {
303  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) {
304  cout << "empty hitTree" << endl;
305  }
306  continue; // Don't bother if no hits
307  }
308 
309  SeedingHitSet tripletFromThisLayer;
310  float chi2FromThisLayer = std::numeric_limits<float>::max();
311 
312  const DetLayer *layer = theLayers[il].detLayer();
313  bool barrelLayer = layer->location() == GeomDetEnumerators::barrel;
314 
315  //gc: this is the curvature of the two hits assuming the region
316  Range curvature = generalCurvature;
317 
318  //LayerRZPredictions &predRZ = mapPred.find(layer)->second;
319  LayerRZPredictions &predRZ = mapPred.find(theLayers[il].name())->second;
320  predRZ.line.initPropagator(&line);
321 
322  //gc: ok, this takes the z at R-thick/2 and R+thick/2 according to
323  // the line from the two points and the adds the extra tolerance
324  Range rzRange = predRZ.line();
325 
326  if (rzRange.first >= rzRange.second) {
327  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) {
328  cout << "rzRange empty" << endl;
329  }
330  continue;
331  }
332 
333  //gc: define the phi range of the hits
334  Range phiRange;
335  if (useFixedPreFiltering) {
336  //gc: in this case it takes as range the phi of the outer
337  // hit +/- the phiPreFiltering value from cfg
338  float phi0 = ip->outer()->globalPosition().phi();
339  phiRange = Range(phi0 - dphi, phi0 + dphi);
340  } else {
341  Range radius;
342 
343  if (barrelLayer) {
344  //gc: this is R-thick/2 and R+thick/2
345  radius = predRZ.line.detRange();
346  if (!intersect(rzRange, predRZ.line.detSize())) {// theDetSize = Range(-maxZ, maxZ);
347  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) {
348  cout << "rzRange and detector do not intersect" << endl;
349  }
350  continue;
351  }
352  } else {
353  radius = rzRange;
354  if (!intersect(radius, predRZ.line.detSize())) {
355  if (debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1) {
356  cout << "rzRange and detector do not intersect" << endl;
357  }
358  continue;
359  }
360  }
361 
362  //gc: predictionRPhi uses the cosine rule to find the phi of the 3rd point at radius, assuming the curvature range [-c,+c]
363  //not sure if it is really needed to do it both for radius.first and radius.second... maybe one can do it once and inflate a bit
364  Range rPhi1 = predictionRPhi(curvature, radius.first);
365  Range rPhi2 = predictionRPhi(curvature, radius.second);
366  rPhi1.first /= radius.first;
367  rPhi1.second /= radius.first;
368  rPhi2.first /= radius.second;
369  rPhi2.second /= radius.second;
370  phiRange = mergePhiRanges(rPhi1, rPhi2);
371  /*
372  //test computing predictionRPhi only once
373  float avgRad = (radius.first+radius.second)/2.;
374  phiRange = predictionRPhi(curvature, avgRad);
375  phiRange.first = phiRange.first/avgRad - 0.0;
376  phiRange.second = phiRange.second/avgRad + 0.0;
377  */
378  }
379 
380  //gc: this is the place where hits in the compatible region are put in the foundNodes
382  foundNodes.clear(); // Now recover hits in bounding box...
383  float prmin=phiRange.min(), prmax=phiRange.max(); //get contiguous range
384  if ((prmax-prmin) > Geom::twoPi())
385  { prmax=Geom::pi(); prmin = -Geom::pi();}
386  else
387  { while (prmax>maxphi) { prmin -= Geom::twoPi(); prmax -= Geom::twoPi();}
388  while (prmin<minphi) { prmin += Geom::twoPi(); prmax += Geom::twoPi();}
389  // This needs range -twoPi to +twoPi to work
390  }
391  if (barrelLayer) {
392  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) cout << "defining kd tree box" << endl;
393  //gc: this is R-thick/2 and R+thick/2 (was already computed above!)
394  Range detR = predRZ.line.detRange();
395  //gc: it seems to me the same thing done here could be obtained from predRZ.line() which has already been computed
396  Range regMin = predRZ.line(detR.min());
397  Range regMax = predRZ.line(detR.max());
398  if (regMax.min() < regMin.min()) { swap(regMax, regMin);}
399  KDTreeBox phiZ(prmin-extraPhiKDBox, prmax+extraPhiKDBox,
400  regMin.min()-fnSigmaRZ*rzError[il],
401  regMax.max()+fnSigmaRZ*rzError[il]);
402 
403  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) cout << "kd tree box bounds, phi: " << prmin <<","<< prmax
404  << " z: "<< regMin.min()-fnSigmaRZ*rzError[il] <<","<<regMax.max()+fnSigmaRZ*rzError[il]
405  << " detR: " << detR.min() <<","<<detR.max()
406  << " regMin: " << regMin.min() <<","<<regMin.max()
407  << " regMax: " << regMax.min() <<","<<regMax.max()
408  << endl;
409  hitTree[il].search(phiZ, foundNodes);
410  }
411  else {
412  KDTreeBox phiR(prmin-extraPhiKDBox, prmax+extraPhiKDBox,
413  rzRange.min()-fnSigmaRZ*rzError[il],
414  rzRange.max()+fnSigmaRZ*rzError[il]);
415  hitTree[il].search(phiR, foundNodes);
416 
417  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) cout << "kd tree box bounds, phi: " << prmin <<","<< prmax
418  << " r: "<< rzRange.min()-fnSigmaRZ*rzError[il] <<","<<rzRange.max()+fnSigmaRZ*rzError[il]
419  << " rzRange: " << rzRange.min() <<","<<rzRange.max()
420  << endl;
421 
422  }
423 
424  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) cout << "kd tree box size: " << foundNodes.size() << endl;
425 
426 
427  //gc: now we loop over the hits in the box for this layer
428  for (std::vector<RecHitsSortedInPhi::HitIter>::iterator ih = foundNodes.begin();
429  ih !=foundNodes.end() && !usePair; ++ih) {
430 
431 
432 
433  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) std::cout << "triplet candidate" << std::endl;
434 
435  const RecHitsSortedInPhi::HitIter KDdata = *ih;
436 
437  TransientTrackingRecHit::ConstRecHitPointer hit2 = KDdata->hit();
438  if (refitHits) {//fixme
439  GlobalVector initMomentum(hit2->globalPosition() - gp1);
440  initMomentum *= (1./initMomentum.perp()); //set pT=1
441  if (/*hit2->geographicalId().subdetId() > 2 && (*/
442  hit2->geographicalId().subdetId()==SiStripDetId::TIB /*|| hit2->geographicalId().subdetId()==SiStripDetId::TOB)*/
443  ) {
444  const std::type_info &tid = typeid(*hit2->hit());
445  if (tid == typeid(SiStripMatchedRecHit2D)) {
446  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(hit2->hit());
447  if (filterHandle_->isCompatible(DetId(matchedHit->monoId()), matchedHit->monoCluster(), initMomentum)==0 ||
448  filterHandle_->isCompatible(DetId(matchedHit->stereoId()), matchedHit->stereoCluster(), initMomentum)==0) continue;
449  } else if (tid == typeid(SiStripRecHit2D)) {
450  const SiStripRecHit2D* recHit = dynamic_cast<const SiStripRecHit2D *>(hit2->hit());
451  if (filterHandle_->isCompatible(*recHit, initMomentum)==0) continue;
452  } else if (tid == typeid(ProjectedSiStripRecHit2D)) {
453  const ProjectedSiStripRecHit2D* precHit = dynamic_cast<const ProjectedSiStripRecHit2D *>(hit2->hit());
454  if (filterHandle_->isCompatible(precHit->originalHit(), initMomentum)==0) continue;;
455  }
456  }
457  GlobalTrajectoryParameters kine = GlobalTrajectoryParameters(hit2->globalPosition(), initMomentum, 1, &*bfield);
458  TrajectoryStateOnSurface state(kine,*hit2->surface());
459  hit2 = hit2->clone(state);
460  }
461  //const TransientTrackingRecHit::ConstRecHitPointer& hit2 = refitHits ? KDdata->hit()->clone(state) : KDdata->hit();
462 
463  //gc: try to add the chi2 cut
464  vector<GlobalPoint> gp(3);
465  vector<GlobalError> ge(3);
466  vector<bool> bl(3);
467  gp[0] = hit0->globalPosition();
468  ge[0] = hit0->globalPositionError();
469  int subid0 = hit0->geographicalId().subdetId();
470  bl[0] = (subid0 == StripSubdetector::TIB || subid0 == StripSubdetector::TOB || subid0 == (int) PixelSubdetector::PixelBarrel);
471  gp[1] = hit1->globalPosition();
472  ge[1] = hit1->globalPositionError();
473  int subid1 = hit1->geographicalId().subdetId();
474  bl[1] = (subid1 == StripSubdetector::TIB || subid1 == StripSubdetector::TOB || subid1 == (int) PixelSubdetector::PixelBarrel);
475  gp[2] = hit2->globalPosition();
476  ge[2] = hit2->globalPositionError();
477  int subid2 = hit2->geographicalId().subdetId();
478  bl[2] = (subid2 == StripSubdetector::TIB || subid2 == StripSubdetector::TOB || subid2 == (int) PixelSubdetector::PixelBarrel);
479  RZLine rzLine(gp,ge,bl);
480  float cottheta, intercept, covss, covii, covsi;
481  rzLine.fit(cottheta, intercept, covss, covii, covsi);
482  float chi2 = rzLine.chi2(cottheta, intercept);
483 
484  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1) {
485  if (hit2->rawId()==debug_Id2) {
486  std::cout << endl << "triplet candidate" << std::endl;
487  cout << "hit in id="<<debug_Id2<<" (from KDTree) with pos: " << KDdata->hit()->globalPosition()
488  << " refitted: " << hit2->globalPosition()
489  << " trans2: " << hit2->transientHits()[0]->globalPosition() << " " << (hit2->transientHits().size()>1 ? hit2->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
490  << " chi2: " << chi2
491  << endl;
492  //cout << state << endl;
493  }
494  //gc: try to add the chi2 cut OLD version
495  vector<float> r(3),z(3),errR(3);
496  r[0] = ip->inner()->globalPosition().perp();
497  z[0] = ip->inner()->globalPosition().z();
498  errR[0] = sqrt(ip->inner()->globalPositionError().cxx()+ip->inner()->globalPositionError().cyy());
499  r[1] = ip->outer()->globalPosition().perp();
500  z[1] = ip->outer()->globalPosition().z();
501  errR[1] = sqrt(ip->outer()->globalPositionError().cxx()+ip->outer()->globalPositionError().cyy());
502  r[2] = KDdata->hit()->globalPosition().perp();
503  z[2] = KDdata->hit()->globalPosition().z();
504  errR[2] = sqrt(KDdata->hit()->globalPositionError().cxx()+KDdata->hit()->globalPositionError().cxx());
505  RZLine oldLine(z,r,errR);
506  float cottheta_old, intercept_old, covss_old, covii_old, covsi_old;
507  oldLine.fit(cottheta_old, intercept_old, covss_old, covii_old, covsi_old);
508  float chi2_old = oldLine.chi2(cottheta_old, intercept_old);
509  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1 && hit2->rawId()==debug_Id2) {
510  cout << "triplet with ids: " << hit0->geographicalId().rawId() << " " << hit1->geographicalId().rawId() << " " << hit2->geographicalId().rawId()
511  << " hitpos: " << gp[0] << " " << gp[1] << " " << gp[2]
512  << " eta,phi: " << gp[0].eta() << "," << gp[0].phi() << " chi2: " << chi2 << " chi2_old: " << chi2_old << endl
513  << "trans0: " << hit0->transientHits()[0]->globalPosition() << " " << hit0->transientHits()[1]->globalPosition() << endl
514  << "trans1: " << hit1->transientHits()[0]->globalPosition() << " " << hit1->transientHits()[1]->globalPosition() << endl
515  << "trans2: " << hit2->transientHits()[0]->globalPosition() << " " << (hit2->transientHits().size()>1 ? hit2->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
516  << endl;
517  }
518  }
519 
520  if (chi2 > maxChi2) continue;
521 
522  if (chi2VsPtCut) {
523 
524  //FastHelix helix = FastHelix(hit2->globalPosition(),hit1->globalPosition(),hit0->globalPosition(),nomField,bfield);
525  //if (helix.isValid()==0) continue;//fixme: check cases where helix fails
526  //this is to compute the status at the 3rd point
527  //FastCircle theCircle = helix.circle();
528 
529  //GlobalPoint maxRhit2(hit2->globalPosition().x()+(hit2->globalPosition().x()>0 ? sqrt(hit2->globalPositionError().cxx()) : sqrt(hit2->globalPositionError().cxx())*(-1.)),
530  //hit2->globalPosition().y()+(hit2->globalPosition().y()>0 ? sqrt(hit2->globalPositionError().cyy()) : sqrt(hit2->globalPositionError().cyy())*(-1.)),
531  //hit2->globalPosition().z());
532  FastCircle theCircle(hit2->globalPosition(),hit1->globalPosition(),hit0->globalPosition());
533  float tesla0 = 0.1*nomField;
534  float rho = theCircle.rho();
535  float cm2GeV = 0.01 * 0.3*tesla0;
536  float pt = cm2GeV * rho;
537  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1 && hit2->rawId()==debug_Id2) {
538  std::cout << "triplet pT=" << pt << std::endl;
539  }
540  if (pt<region.ptMin()) continue;
541 
542  if (chi2_cuts.size()>1) {
543  int ncuts = chi2_cuts.size();
544  if ( pt<=pt_interv[0] && chi2 > chi2_cuts[0] ) continue;
545  bool pass = true;
546  for (int icut=1; icut<ncuts-1; icut++){
547  if ( pt>pt_interv[icut-1] && pt<=pt_interv[icut] && chi2 > chi2_cuts[icut] ) pass=false;
548  }
549  if (!pass) continue;
550  if ( pt>pt_interv[ncuts-2] && chi2 > chi2_cuts[ncuts-1] ) continue;
551 
552  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1 && hit2->rawId()==debug_Id2) {
553  std::cout << "triplet passed chi2 vs pt cut" << std::endl;
554  }
555  }
556 
557  }
558 
559  if (theMaxElement!=0 && result.size() >= theMaxElement) {
560  result.clear();
561  edm::LogError("TooManyTriplets")<<" number of triples exceed maximum. no triplets produced.";
562  return;
563  }
564  if (debug && hit0->rawId()==debug_Id0 && hit1->rawId()==debug_Id1 && hit2->rawId()==debug_Id2) std::cout << "triplet made" << std::endl;
565  //result.push_back(SeedingHitSet(hit0, hit1, hit2));
566  tripletFromThisLayer = SeedingHitSet(hit0, hit1, hit2);
567  chi2FromThisLayer = chi2;
568  foundTripletsFromPair++;
569  if (foundTripletsFromPair>=2) {
570  usePair=true;
571  break;
572  }
573  }//loop over hits in KDTree
574 
575  if (usePair) break;
576  else {
577  //if there is one triplet in more than one layer, try picking the one with best chi2
578  if (chi2FromThisLayer<minChi2) {
579  triplet = tripletFromThisLayer;
580  minChi2 = chi2FromThisLayer;
581  }
582  }
583 
584  }//loop over layers
585 
586  if (foundTripletsFromPair==0) continue;
587 
588  //push back only (max) once per pair
589  if (usePair) result.push_back(SeedingHitSet(ip->inner(), ip->outer()));
590  else result.push_back(triplet);
591 
592  }//loop over pairs
593  if (debug) {
594  std::cout << "triplet size=" << result.size() << std::endl;
595  }
596 }
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
std::pair< float, float > mergePhiRanges(const std::pair< float, float > &r1, const std::pair< float, float > &r2) const
void build(std::vector< KDTreeNodeInfo > &eltList, const KDTreeBox &region)
virtual Location location() const =0
Which part of the detector (barrel, endcap)
int nominalValue() const
The nominal field value for this map in kGauss.
const ClusterShapeHitFilter * filter
Definition: DDAxes.h:10
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< ctfseeding::SeedingLayer > theLayers
virtual unsigned int size() const
void search(const KDTreeBox &searchBox, std::vector< KDTreeNodeInfo > &resRecHitList)
float float float z
std::pair< HitIter, HitIter > Range
T curvature(T InversePt, const edm::EventSetup &iSetup)
const T & max(const T &a, const T &b)
std::vector< HitWithPhi >::const_iterator HitIter
virtual void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::EventSetup &es)
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, PixelData const *pd=nullptr) const
Definition: RZLine.h:8
Definition: DetId.h:18
PixelRecoRange< float > Range
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
double pi()
Definition: Pi.h:31
double twoPi()
Definition: Pi.h:32
TransientTrackingRecHit::ConstRecHitPointer Hit
tuple cout
Definition: gather_cfg.py:121
const SiStripRecHit2D & originalHit() const
tuple size
Write out results.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
void MultiHitGeneratorFromChi2::init ( const HitPairGenerator pairs,
const std::vector< ctfseeding::SeedingLayer > &  layers,
LayerCacheType layerCache 
)
virtual

Implements MultiHitGeneratorFromPairAndLayers.

Definition at line 82 of file MultiHitGeneratorFromChi2.cc.

References HitPairGenerator::clone(), theLayerCache, theLayers, and thePairGenerator.

85 {
86  thePairGenerator = pairs.clone();
87  theLayers = layers;
88  theLayerCache = layerCache;
89 }
virtual HitPairGenerator * clone() const =0
std::vector< ctfseeding::SeedingLayer > theLayers
std::pair< float, float > MultiHitGeneratorFromChi2::mergePhiRanges ( const std::pair< float, float > &  r1,
const std::pair< float, float > &  r2 
) const
private

Definition at line 605 of file MultiHitGeneratorFromChi2.cc.

References M_PI, max(), and bookConverter::min.

Referenced by hitSets().

607 { float r2Min = r2.first;
608  float r2Max = r2.second;
609  while (r1.first - r2Min > +M_PI) r2Min += 2. * M_PI, r2Max += 2. * M_PI;
610  while (r1.first - r2Min < -M_PI) r2Min -= 2. * M_PI, r2Max -= 2. * M_PI;
611  //std::cout << "mergePhiRanges " << fabs(r1.first-r2Min) << " " << fabs(r1.second-r2Max) << endl;
612  return std::make_pair(min(r1.first, r2Min), max(r1.second, r2Max));
613 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: BFit3D.cc:3
const HitPairGenerator& MultiHitGeneratorFromChi2::pairGenerator ( ) const
inline

Definition at line 38 of file MultiHitGeneratorFromChi2.h.

References thePairGenerator.

38 { return *thePairGenerator; }
const std::vector<ctfseeding::SeedingLayer>& MultiHitGeneratorFromChi2::thirdLayers ( ) const
inline

Definition at line 39 of file MultiHitGeneratorFromChi2.h.

References theLayers.

39 { return theLayers; }
std::vector< ctfseeding::SeedingLayer > theLayers

Member Data Documentation

const MagneticField* MultiHitGeneratorFromChi2::bfield
private

Definition at line 59 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

std::vector<double> MultiHitGeneratorFromChi2::chi2_cuts
private

Definition at line 65 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

bool MultiHitGeneratorFromChi2::chi2VsPtCut
private

Definition at line 62 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

bool MultiHitGeneratorFromChi2::debug
private

Definition at line 67 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

std::vector<int> MultiHitGeneratorFromChi2::detIdsToDebug
private

Definition at line 69 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

float MultiHitGeneratorFromChi2::dphi
private

Definition at line 58 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

float MultiHitGeneratorFromChi2::extraHitRPhitolerance
private

Definition at line 56 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

float MultiHitGeneratorFromChi2::extraHitRZtolerance
private

Definition at line 55 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

float MultiHitGeneratorFromChi2::extraPhiKDBox
private

Definition at line 57 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

const ClusterShapeHitFilter* MultiHitGeneratorFromChi2::filter
private
std::string MultiHitGeneratorFromChi2::filterName_
private

Definition at line 68 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

double MultiHitGeneratorFromChi2::fnSigmaRZ
private

Definition at line 61 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

double MultiHitGeneratorFromChi2::maxChi2
private

Definition at line 63 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

float MultiHitGeneratorFromChi2::nomField
private

Definition at line 60 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

double MultiHitGeneratorFromChi2::nSigmaPhi
private

Definition at line 61 of file MultiHitGeneratorFromChi2.h.

double MultiHitGeneratorFromChi2::nSigmaRZ
private

Definition at line 61 of file MultiHitGeneratorFromChi2.h.

std::vector<double> MultiHitGeneratorFromChi2::pt_interv
private

Definition at line 64 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().

bool MultiHitGeneratorFromChi2::refitHits
private

Definition at line 66 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets().

LayerCacheType* MultiHitGeneratorFromChi2::theLayerCache
private

Definition at line 51 of file MultiHitGeneratorFromChi2.h.

Referenced by init().

std::vector<ctfseeding::SeedingLayer> MultiHitGeneratorFromChi2::theLayers
private

Definition at line 50 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), init(), and thirdLayers().

HitPairGenerator* MultiHitGeneratorFromChi2::thePairGenerator
private
bool MultiHitGeneratorFromChi2::useFixedPreFiltering
private

Definition at line 54 of file MultiHitGeneratorFromChi2.h.

Referenced by hitSets(), and MultiHitGeneratorFromChi2().