CMS 3D CMS Logo

PhotonConversionTrajectorySeedProducerFromSingleLegAlgo.cc
Go to the documentation of this file.
4 
8 
9 //#define debugTSPFSLA
10 
11 namespace {
12  inline double sqr(double a) { return a * a; }
13 } // namespace
14 
16  const edm::ParameterSet& conf, edm::ConsumesCollector&& iC)
17  : theHitsGenerator(new CombinedHitPairGeneratorForPhotonConversion(
18  conf.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet"), iC)),
19  theSeedCreator(new SeedForPhotonConversion1Leg(conf.getParameter<edm::ParameterSet>("SeedCreatorPSet"), iC)),
20  theRegionProducer(
21  new GlobalTrackingRegionProducerFromBeamSpot(conf.getParameter<edm::ParameterSet>("RegionFactoryPSet"), iC)),
22  theClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet"), iC),
23  theSilentOnClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet")
24  .getUntrackedParameter<bool>("silentClusterCheck", false)),
25  _vtxMinDoF(conf.getParameter<double>("vtxMinDoF")),
26  _maxDZSigmas(conf.getParameter<double>("maxDZSigmas")),
27  _maxNumSelVtx(conf.getParameter<uint32_t>("maxNumSelVtx")),
28  _applyTkVtxConstraint(conf.getParameter<bool>("applyTkVtxConstraint")),
29  _countSeedTracks(0),
30  _primaryVtxInputTag(conf.getParameter<edm::InputTag>("primaryVerticesTag")),
31  _beamSpotInputTag(conf.getParameter<edm::InputTag>("beamSpotInputTag")) {
34  token_refitter = iC.consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackRefitter"));
35  token_magField = iC.esConsumes();
36 }
37 
39 
41  const edm::EventSetup& setup,
43  myEsetup = &setup;
44  myEvent = &event;
45 
46  assert(seedCollection == nullptr);
47 
49 
50  size_t clustsOrZero = theClusterCheck.tooManyClusters(event);
51  if (clustsOrZero) {
53  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
54  seedCollection = nullptr;
55  return;
56  }
57 
58  const auto& magField = setup.getData(token_magField);
59  if (UNLIKELY(magField.inTesla(GlobalPoint(0., 0., 0.)).z() < 0.01)) {
60  seedCollection = nullptr;
61  return;
62  }
63 
65 
66  event.getByToken(token_vertex, vertexHandle);
67  if (!vertexHandle.isValid() || vertexHandle->empty()) {
68  edm::LogError("PhotonConversionFinderFromTracks")
69  << "Error! Can't get the product primary Vertex Collection " << _primaryVtxInputTag << "\n";
70  seedCollection = nullptr;
71  return;
72  }
73 
74  event.getByToken(token_bs, recoBeamSpotHandle);
75 
76  regions = theRegionProducer->regions(event, setup);
77 
78  // find seeds
79  loopOnTracks();
80 
81 #ifdef debugTSPFSLA
82  std::stringstream ss;
83  ss.str("");
84  ss << "\n++++++++++++++++++\n";
85  ss << "seed collection size " << seedCollection->size();
86  for (auto const& tjS : *seedCollection) {
87  po.print(ss, tjS);
88  }
89  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
90  //-------------------------------------------------
91 #endif
92 
93  // clear memory
94  theHitsGenerator->clearCache();
95 
96  seedCollection = nullptr;
97 }
98 
100  //--- Get Tracks
102 
103  if (trackCollectionH.isValid() == 0) {
104  edm::LogError("MissingInput")
105  << " could not find track collecion in PhotonConversionTrajectorySeedProducerFromSingleLegAlgo";
106  return;
107  }
108 
109  size_t idx = 0;
110  _countSeedTracks = 0;
111 
112 #ifdef debugTSPFSLA
113  size_t sel = 0;
114  ss.str("");
115 #endif
116 
117  for (reco::TrackCollection::const_iterator tr = trackCollectionH->begin(); tr != trackCollectionH->end();
118  tr++, idx++) {
119  if (rejectTrack(*tr))
120  continue;
121  std::vector<reco::Vertex> selectedPriVtxCompatibleWithTrack;
122  if (!_applyTkVtxConstraint) {
123  selectedPriVtxCompatibleWithTrack.push_back(*(vertexHandle->begin())); //Same approach as before
124  } else {
125  if (!selectPriVtxCompatibleWithTrack(*tr, selectedPriVtxCompatibleWithTrack))
126  continue;
127  }
128 #ifdef debugTSPFSLA
129  sel++;
130 #endif
131  loopOnPriVtx(*tr, selectedPriVtxCompatibleWithTrack);
132  }
133 #ifdef debugTSPFSLA
134  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
135  edm::LogInfo("debugTrajSeedFromSingleLeg") << "Inspected " << sel << " tracks over " << idx
136  << " tracks. \t # tracks providing at least one seed " << _countSeedTracks;
137 #endif
138 }
139 
141  const reco::Track& tk, std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack) {
142  std::vector<std::pair<double, short> > idx;
143  short count = -1;
144 
145  double cosPhi = tk.px() / tk.pt();
146  double sinPhi = tk.py() / tk.pt();
147  double sphi2 = tk.covariance(2, 2);
148  double stheta2 = tk.covariance(1, 1);
149 
150  for (const reco::Vertex& vtx : *vertexHandle) {
151  count++;
152  if (vtx.ndof() <= _vtxMinDoF)
153  continue;
154 
155  double _dz = tk.dz(vtx.position());
156  double _dzError = tk.dzError();
157 
158  double cotTheta = tk.pz() / tk.pt();
159  double dx = vtx.position().x();
160  double dy = vtx.position().y();
161  double sx2 = vtx.covariance(0, 0);
162  double sy2 = vtx.covariance(1, 1);
163 
164  double sxy2 = sqr(cosPhi * cotTheta) * sx2 + sqr(sinPhi * cotTheta) * sy2 +
165  sqr(cotTheta * (-dx * sinPhi + dy * cosPhi)) * sphi2 +
166  sqr((1 + cotTheta * cotTheta) * (dx * cosPhi + dy * sinPhi)) * stheta2;
167 
168  _dzError = sqrt(
169  _dzError * _dzError + vtx.covariance(2, 2) +
170  sxy2); //there is a missing component, related to the element (vtx.x*px+vtx.y*py)/pt * pz/pt. since the tk ref point is at the point of closest approach, this scalar product should be almost zero.
171 
172 #ifdef debugTSPFSLA
173  ss << " primary vtx " << vtx.position() << " \tk vz " << tk.vz() << " vx " << tk.vx() << " vy " << tk.vy()
174  << " pz/pt " << tk.pz() / tk.pt() << " \t dz " << _dz << " \t " << _dzError << " sxy2 " << sxy2
175  << " \t dz/dzErr " << _dz / _dzError << std::endl;
176 #endif
177 
178  if (fabs(_dz) / _dzError > _maxDZSigmas)
179  continue;
180 
181  idx.push_back(std::pair<double, short>(fabs(_dz), count));
182  }
183  if (idx.empty()) {
184 #ifdef debugTSPFSLA
185  ss << "no vertex selected " << std::endl;
186 #endif
187  return false;
188  }
189 
190  std::stable_sort(
191  idx.begin(), idx.end(), [](std::pair<double, short> a, std::pair<double, short> b) { return a.first < b.first; });
192 
193  for (size_t i = 0; i < _maxNumSelVtx && i < idx.size(); ++i) {
194  selectedPriVtxCompatibleWithTrack.push_back((*vertexHandle)[idx[i].second]);
195 #ifdef debugTSPFSLA
196  ss << "selected vtx dz " << idx[0].first << " position" << idx[0].second << std::endl;
197 #endif
198  }
199 
200  return true;
201 }
202 
204  const reco::Track& tk, const std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack) {
205  bool foundAtLeastASeedCand = false;
206  for (auto const& vtx : selectedPriVtxCompatibleWithTrack) {
207  math::XYZPoint primaryVertexPoint = math::XYZPoint(vtx.position());
208 
209  for (IR ir = regions.begin(), irEnd = regions.end(); ir < irEnd; ++ir) {
210  const TrackingRegion& region = **ir;
211 
212 #ifdef debugTSPFSLA
213  ss << "[PrintRegion] " << region.print() << std::endl;
214 #endif
215 
216  //This if is just for the _countSeedTracks. otherwise
217  //inspectTrack(&tk,region, primaryVertexPoint);
218  //would be enough
219 
220  if (inspectTrack(&tk, region, primaryVertexPoint) and !foundAtLeastASeedCand) {
221  foundAtLeastASeedCand = true;
223  }
224  }
225  }
226 }
227 
230  if (recoBeamSpotHandle.isValid()) {
232 
234  if (_IdealHelixParameters.GetTangentPoint().r() == 0) {
235  //this case means a null results on the _IdealHelixParameters side
236  return true;
237  }
238 
239  float rMin = 2.; //cm
241  //this case means a track that has the tangent point nearby the primary vertex
242  // if the track is primary, this number tends to be the primary vertex itself
243  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
244  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
245  return true;
246  }
247  }
248 
249  //-------------------------------------------------------
250  /*
251  float maxPt2=64.; //Cut on pt^2 Indeed doesn't do almost nothing
252  if(track.momentum().Perp2() > maxPt2)
253  return true;
254  */
255  //-------------------------------------------------------
256  //Cut in the barrel eta region FIXME: to be extended to endcaps
257  /*
258  float maxEta=1.3;
259  if(fabs(track.eta()) > maxEta)
260  return true;
261  */
262  //-------------------------------------------------------
263  //Reject tracks that have a first valid hit in the pixel barrel/endcap layer/disk 1
264  //assume that the hits are aligned along momentum
265  /*
266  const reco::HitPattern& p=track.hitPattern();
267  for (int i=0; i<p.numberOfHits(); i++) {
268  uint32_t hit = p.getHitPattern(i);
269  // if the hit is valid and in pixel barrel, print out the layer
270  if (! p.validHitFilter(hit) ) continue;
271  if( (p.pixelBarrelHitFilter(hit) || p.pixelEndcapHitFilter(hit))
272  &&
273  p.getLayer(hit) == 1
274  )
275  return true;
276  else
277  break; //because the first valid hit is in a different layer
278  }
279  */
280  //-------------------------------------------------------
281 
282  return false;
283 }
284 
286  const TrackingRegion& region,
287  math::XYZPoint& primaryVertexPoint) {
288  _IdealHelixParameters.setData(track, primaryVertexPoint);
289 
291  (_IdealHelixParameters.GetTangentPoint().r() == 0)) {
292  //this case means a null results on the _IdealHelixParameters side
293  return false;
294  }
295 
296  float rMin = 3.; //cm
298  //this case means a track that has the tangent point nearby the primary vertex
299  // if the track is primary, this number tends to be the primary vertex itself
300  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
301  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
302  return false;
303  }
304 
305  float ptmin = 0.5;
306  float originRBound = 3;
307  float originZBound = 3.;
308 
309  GlobalPoint originPos;
313  float cotTheta;
315  cotTheta =
317  } else {
319  cotTheta = 99999.f;
320  else
321  cotTheta = -99999.f;
322  }
323  GlobalVector originBounds(originRBound, originRBound, originZBound);
324 
325  GlobalPoint pvtxPoint(primaryVertexPoint.x(), primaryVertexPoint.y(), primaryVertexPoint.z());
326 
327  ConversionRegion convRegion(originPos, pvtxPoint, cotTheta, track->thetaError(), -1 * track->charge());
328 
329 #ifdef debugTSPFSLA
330  ss << "\nConversion Point " << originPos << " " << originPos.perp() << "\n";
331 #endif
332 
333  const OrderedSeedingHits& hitss = theHitsGenerator->run(convRegion, region, *myEvent, *myEsetup);
334 
335  unsigned int nHitss = hitss.size();
336 
337  if (nHitss == 0)
338  return false;
339 
340 #ifdef debugTSPFSLA
341  ss << "\n nHitss " << nHitss << "\n";
342 #endif
343 
344  if (seedCollection->empty())
345  seedCollection->reserve(
346  nHitss); // don't do multiple reserves in the case of multiple regions: it would make things even worse
347  // as it will cause N re-allocations instead of the normal log(N)/log(2)
348  for (unsigned int iHits = 0; iHits < nHitss; ++iHits) {
349 #ifdef debugTSPFSLA
350  ss << "\n iHits " << iHits << "\n";
351 #endif
352  const SeedingHitSet& hits = hitss[iHits];
353  theSeedCreator->trajectorySeed(
354  *seedCollection, hits, originPos, originBounds, ptmin, *myEsetup, convRegion.cotTheta(), ss);
355  }
356  return true;
357 }
void setData(const reco::Track *track, const math::XYZVector &refPoint=math::XYZVector(0, 0, 0))
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T perp() const
Definition: PV3DBase.h:69
PhotonConversionTrajectorySeedProducerFromSingleLegAlgo(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
size_t tooManyClusters(const edm::Event &e) const
const Point & position() const
position
Definition: BeamSpot.h:59
void setMagnField(const MagneticField *magnField)
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:655
void find(const edm::Event &event, const edm::EventSetup &setup, TrajectorySeedCollection &output)
T z() const
Definition: PV3DBase.h:61
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:640
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
math::XYZVector GetTangentPoint() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:643
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual unsigned int size() const =0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
Log< level::Error, false > LogError
assert(be >=bs)
U second(std::pair< T, U > const &p)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:716
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
std::vector< TrajectorySeed > TrajectorySeedCollection
double dzError() const
error on dz
Definition: TrackBase.h:778
T sqrt(T t)
Definition: SSEVec.h:23
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
void print(std::stringstream &ss, const SiStripCluster &clus)
bool inspectTrack(const reco::Track *track, const TrackingRegion &region, math::XYZPoint &primaryVertexPoint)
math::XYZVector GetMomentumAtTangentPoint() const
Log< level::Info, false > LogInfo
void loopOnPriVtx(const reco::Track &tk, const std::vector< reco::Vertex > &selectedPriVtxCompatibleWithTrack)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
double b
Definition: hdecay.h:120
bool isValid() const
Definition: HandleBase.h:70
double ptmin
Definition: HydjetWrapper.h:86
std::unique_ptr< CombinedHitPairGeneratorForPhotonConversion > theHitsGenerator
HLT enums.
double a
Definition: hdecay.h:121
Square< F >::type sqr(const F &f)
Definition: Square.h:14
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
Definition: output.py:1
#define UNLIKELY(x)
Definition: Likely.h:21
bool selectPriVtxCompatibleWithTrack(const reco::Track &tk, std::vector< reco::Vertex > &selectedPriVtxCompatibleWithTrack)
Definition: event.py:1