CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonConversionTrajectorySeedProducerFromSingleLegAlgo.cc
Go to the documentation of this file.
4 
9 
10 
11 //#define debugTSPFSLA
12 
13 inline double sqr(double a){return a*a;}
14 
18  :_conf(conf),seedCollection(0),seedCollectionOfSourceTracks(0),
19  theHitsGenerator(new CombinedHitPairGeneratorForPhotonConversion(conf.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet"), iC)),
20  theRegionProducer(new GlobalTrackingRegionProducerFromBeamSpot(conf.getParameter<edm::ParameterSet>("RegionFactoryPSet"), iC)),
21  creatorPSet(conf.getParameter<edm::ParameterSet>("SeedCreatorPSet")),
22  theClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet"), iC),
23  theSilentOnClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet").getUntrackedParameter<bool>("silentClusterCheck",false)),
24  _vtxMinDoF(conf.getParameter<double>("vtxMinDoF")),
25  _maxDZSigmas(conf.getParameter<double>("maxDZSigmas")),
26  _maxNumSelVtx(conf.getParameter<uint32_t>("maxNumSelVtx")),
27  _applyTkVtxConstraint(conf.getParameter<bool>("applyTkVtxConstraint")),
28  _countSeedTracks(0),
29  _primaryVtxInputTag(conf.getParameter<edm::InputTag>("primaryVerticesTag")),
30  _beamSpotInputTag(conf.getParameter<edm::InputTag>("beamSpotInputTag"))
31 {
34  token_refitter = iC.consumes<reco::TrackCollection>(_conf.getParameter<edm::InputTag>("TrackRefitter"));
35  init();
36 }
37 
39 }
40 
43  if(theSeedCreator!=NULL)
44  delete theSeedCreator;
45 }
46 
48 init(){
50 }
51 
54 
55  myEsetup = &setup;
56  myEvent = &event;
57 
58  if(seedCollection!=0)
59  delete seedCollection;
60 
63 
66 
67  size_t clustsOrZero = theClusterCheck.tooManyClusters(event);
68  if (clustsOrZero){
70  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
71  return ;
72  }
73 
74 
75  edm::ESHandle<MagneticField> handleMagField;
76  setup.get<IdealMagneticFieldRecord>().get(handleMagField);
77  magField = handleMagField.product();
78  if (unlikely(magField->inTesla(GlobalPoint(0.,0.,0.)).z()<0.01)) return;
79 
81 
82 
83  event.getByToken(token_vertex, vertexHandle);
84  if (!vertexHandle.isValid() || vertexHandle->empty()){
85  edm::LogError("PhotonConversionFinderFromTracks") << "Error! Can't get the product primary Vertex Collection "<< _primaryVtxInputTag << "\n";
86  return;
87  }
88 
89  event.getByToken(token_bs,recoBeamSpotHandle);
90 
91 
92  regions = theRegionProducer->regions(event,setup);
93 
94  //Do the analysis
95  loopOnTracks();
96 
97 
98 #ifdef debugTSPFSLA
99  std::stringstream ss;
100  ss.str("");
101  ss << "\n++++++++++++++++++\n";
102  ss << "seed collection size " << seedCollection->size();
103  BOOST_FOREACH(TrajectorySeed tjS,*seedCollection){
104  po.print(ss, tjS);
105  }
106  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
107  //-------------------------------------------------
108 #endif
109 
110  // clear memory
111  theHitsGenerator->clearLayerCache();
112  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) delete (*ir);
113 
114 }
115 
116 
119 
120  //--- Get Tracks
122 
123  if(trackCollectionH.isValid()==0){
124  edm::LogError("MissingInput")<<" could not find track collecion:"<<_conf.getParameter<edm::InputTag>("TrackRefitter");
125  return;
126  }
127  size_t idx=0, sel=0;
129 
130  ss.str("");
131 
132  for( reco::TrackCollection::const_iterator tr = trackCollectionH->begin();
133  tr != trackCollectionH->end(); tr++, idx++) {
134 
135  // #ifdef debugTSPFSLA
136  // ss << "\nStuding track Nb " << idx;
137  // #endif
138 
139  if(rejectTrack(*tr)) continue;
140  std::vector<reco::Vertex> selectedPriVtxCompatibleWithTrack;
142  selectedPriVtxCompatibleWithTrack.push_back(*(vertexHandle->begin())); //Same approach as before
143  }else{
144  if(!selectPriVtxCompatibleWithTrack(*tr,selectedPriVtxCompatibleWithTrack)) continue;
145  }
146 
147  sel++;
148  loopOnPriVtx(*tr,selectedPriVtxCompatibleWithTrack);
149  }
150 #ifdef debugTSPFSLA
151  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
152  edm::LogInfo("debugTrajSeedFromSingleLeg") << "Inspected " << sel << " tracks over " << idx << " tracks. \t # tracks providing at least one seed " << _countSeedTracks ;
153 #endif
154 }
155 
157 selectPriVtxCompatibleWithTrack(const reco::Track& tk, std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack){
158 
159  std::vector< std::pair< double, short> > idx;
160  short count=-1;
161 
162  double cosPhi=tk.px()/tk.pt();
163  double sinPhi=tk.py()/tk.pt();
164  double sphi2=tk.covariance(2,2);
165  double stheta2=tk.covariance(1,1);
166 
167  BOOST_FOREACH(const reco::Vertex& vtx, *vertexHandle){
168  count++;
169  if(vtx.ndof()<= _vtxMinDoF) continue;
170 
171  double _dz= tk.dz(vtx.position());
172  double _dzError=tk.dzError();
173 
174  double cotTheta=tk.pz()/tk.pt();
175  double dx = vtx.position().x();
176  double dy = vtx.position().y();
177  double sx2=vtx.covariance(0,0);
178  double sy2=vtx.covariance(1,1);
179 
180  double sxy2= sqr(cosPhi*cotTheta)*sx2+
181  sqr(sinPhi*cotTheta)*sy2+
182  sqr(cotTheta*(-dx*sinPhi+dy*cosPhi))*sphi2+
183  sqr((1+cotTheta*cotTheta)*(dx*cosPhi+dy*sinPhi))*stheta2;
184 
185  _dzError=sqrt(_dzError*_dzError+vtx.covariance(2,2)+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.
186 
187 #ifdef debugTSPFSLA
188  ss << " primary vtx " << vtx.position() << " \tk vz " << tk.vz() << " vx " << tk.vx() << " vy " << tk.vy() << " pz/pt " << tk.pz()/tk.pt() << " \t dz " << _dz << " \t " << _dzError << " sxy2 "<< sxy2<< " \t dz/dzErr " << _dz/_dzError<< std::endl;
189 #endif
190 
191  if(fabs(_dz)/_dzError > _maxDZSigmas) continue;
192 
193  idx.push_back(std::pair<double,short>(fabs(_dz),count));
194  }
195  if(idx.size()==0) {
196 #ifdef debugTSPFSLA
197  ss << "no vertex selected " << std::endl;
198 #endif
199  return false;
200 }
201 
202  std::stable_sort(idx.begin(),idx.end(),lt_);
203  for(size_t i=0;i<_maxNumSelVtx && i<idx.size();++i){
204  selectedPriVtxCompatibleWithTrack.push_back((*vertexHandle)[idx[i].second]);
205 #ifdef debugTSPFSLA
206  ss << "selected vtx dz " << idx[0].first << " position" << idx[0].second << std::endl;
207 #endif
208  }
209 
210  return true;
211 }
212 
214 loopOnPriVtx(const reco::Track& tk, const std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack){
215 
216  bool foundAtLeastASeedCand=false;
217  BOOST_FOREACH(const reco::Vertex vtx, selectedPriVtxCompatibleWithTrack){
218 
219  math::XYZPoint primaryVertexPoint=math::XYZPoint(vtx.position());
220 
221  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) {
222  const TrackingRegion & region = **ir;
223 
224 #ifdef debugTSPFSLA
225  ss << "[PrintRegion] " << region.print() << std::endl;
226 #endif
227 
228  //This if is just for the _countSeedTracks. otherwise
229  //inspectTrack(&tk,region, primaryVertexPoint);
230  //would be enough
231 
232  if(
233  inspectTrack(&tk,region, primaryVertexPoint)
234  and
235  !foundAtLeastASeedCand
236  ){
237  foundAtLeastASeedCand=true;
238  _countSeedTracks++;
239  }
240 
241  }
242  }
243 }
244 
246 rejectTrack(const reco::Track& track){
247 
250  beamSpot = math::XYZVector(recoBeamSpotHandle->position());
251 
252  _IdealHelixParameters.setData(&track,beamSpot);
254  //this case means a null results on the _IdealHelixParameters side
255  return true;
256  }
257 
258  float rMin=2.; //cm
259  if(_IdealHelixParameters.GetTangentPoint().rho()<rMin){
260  //this case means a track that has the tangent point nearby the primary vertex
261  // if the track is primary, this number tends to be the primary vertex itself
262  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
263  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
264  return true;
265  }
266  }
267 
268  //-------------------------------------------------------
269  /*
270  float maxPt2=64.; //Cut on pt^2 Indeed doesn't do almost nothing
271  if(track.momentum().Perp2() > maxPt2)
272  return true;
273  */
274  //-------------------------------------------------------
275  //Cut in the barrel eta region FIXME: to be extended to endcaps
276  /*
277  float maxEta=1.3;
278  if(fabs(track.eta()) > maxEta)
279  return true;
280  */
281  //-------------------------------------------------------
282  //Reject tracks that have a first valid hit in the pixel barrel/endcap layer/disk 1
283  //assume that the hits are aligned along momentum
284  /*
285  const reco::HitPattern& p=track.hitPattern();
286  for (int i=0; i<p.numberOfHits(); i++) {
287  uint32_t hit = p.getHitPattern(i);
288  // if the hit is valid and in pixel barrel, print out the layer
289  if (! p.validHitFilter(hit) ) continue;
290  if( (p.pixelBarrelHitFilter(hit) || p.pixelEndcapHitFilter(hit))
291  &&
292  p.getLayer(hit) == 1
293  )
294  return true;
295  else
296  break; //because the first valid hit is in a different layer
297  }
298  */
299  //-------------------------------------------------------
300 
301 
302  return false;
303 }
304 
305 
307 inspectTrack(const reco::Track* track, const TrackingRegion & region, math::XYZPoint& primaryVertexPoint){
308 
309  _IdealHelixParameters.setData(track,primaryVertexPoint);
310 
313  //this case means a null results on the _IdealHelixParameters side
314  return false;
315  }
316 
317  float rMin=3.; //cm
318  if(_IdealHelixParameters.GetTangentPoint().rho()<rMin){
319  //this case means a track that has the tangent point nearby the primary vertex
320  // if the track is primary, this number tends to be the primary vertex itself
321  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
322  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
323  return false;
324  }
325 
326  float ptmin = 0.5;
327  float originRBound = 3;
328  float originZBound = 3.;
329 
330  GlobalPoint originPos;
334  );
335  float cotTheta;
338  }else{
340  cotTheta=99999.f;
341  else
342  cotTheta=-99999.f;
343  }
344  GlobalVector originBounds(originRBound,originRBound,originZBound);
345 
346  GlobalPoint pvtxPoint(primaryVertexPoint.x(),
347  primaryVertexPoint.y(),
348  primaryVertexPoint.z()
349  );
350  ConversionRegion convRegion(originPos, pvtxPoint, cotTheta, track->thetaError(), -1*track->charge());
351 
352 #ifdef debugTSPFSLA
353  ss << "\nConversion Point " << originPos << " " << originPos.perp() << "\n";
354 #endif
355 
356  const OrderedSeedingHits & hitss = theHitsGenerator->run(convRegion, region, *myEvent, *myEsetup);
357 
358  unsigned int nHitss = hitss.size();
359 
360  if(nHitss==0)
361  return false;
362 
363 #ifdef debugTSPFSLA
364  ss << "\n nHitss " << nHitss << "\n";
365 #endif
366 
367  if (seedCollection->empty()) seedCollection->reserve(nHitss); // don't do multiple reserves in the case of multiple regions: it would make things even worse
368  // as it will cause N re-allocations instead of the normal log(N)/log(2)
369  for (unsigned int iHits = 0; iHits < nHitss; ++iHits) {
370 
371 #ifdef debugTSPFSLA
372  ss << "\n iHits " << iHits << "\n";
373 #endif
374  const SeedingHitSet & hits = hitss[iHits];
375  //if (!theComparitor || theComparitor->compatible( hits, es) ) {
376  //try{
377  theSeedCreator->trajectorySeed(*seedCollection,hits, originPos, originBounds, ptmin, *myEsetup,convRegion.cotTheta(),ss);
378  //}catch(cms::Exception& er){
379  // edm::LogError("SeedingConversion") << " Problem in the Single Leg Seed creator " <<er.what()<<std::endl;
380  //}catch(std::exception& er){
381  // edm::LogError("SeedingConversion") << " Problem in the Single Leg Seed creator " << er.what()<<std::endl;
382  //}
383  }
384  return true;
385 }
386 
387 
T getParameter(std::string const &) const
void setData(const reco::Track *track, const math::XYZVector &refPoint=math::XYZVector(0, 0, 0))
int i
Definition: DBlmapReader.cc:9
PhotonConversionTrajectorySeedProducerFromSingleLegAlgo(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
T perp() const
Definition: PV3DBase.h:72
void setMagnField(const MagneticField *magnField)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
#define NULL
Definition: scimark2.h:8
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual unsigned int size() const =0
const TrajectorySeed * trajectorySeed(TrajectorySeedCollection &seedCollection, const SeedingHitSet &hits, const GlobalPoint &vertex, const GlobalVector &vertexBounds, float ptmin, const edm::EventSetup &es, float cotTheta, std::stringstream &ss)
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:109
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:131
const Point & position() const
position
Definition: Vertex.h:92
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:180
math::XYZVector GetMomentumAtTangentPoint() const
U second(std::pair< T, U > const &p)
#define unlikely(x)
Definition: Likely.h:21
bool isNotFinite(T x)
Definition: isFinite.h:10
math::XYZVector GetTangentPoint() const
std::vector< TrajectorySeed > TrajectorySeedCollection
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:129
T z() const
Definition: PV3DBase.h:64
size_t tooManyClusters(const edm::Event &e) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
void print(std::stringstream &ss, const SiStripCluster &clus)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
bool inspectTrack(const reco::Track *track, const TrackingRegion &region, math::XYZPoint &primaryVertexPoint)
double ndof() const
Definition: Vertex.h:88
tuple conf
Definition: dbtoconf.py:185
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:135
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:125
double dzError() const
error on dz
Definition: TrackBase.h:213
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:145
void loopOnPriVtx(const reco::Track &tk, const std::vector< reco::Vertex > &selectedPriVtxCompatibleWithTrack)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual std::string print() const
return(e1-e2)*(e1-e2)+dp *dp
double ptmin
Definition: HydjetWrapper.h:85
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:143
std::unique_ptr< CombinedHitPairGeneratorForPhotonConversion > theHitsGenerator
double a
Definition: hdecay.h:121
Square< F >::type sqr(const F &f)
Definition: Square.h:13
bool lt_(std::pair< double, short > a, std::pair< double, short > b)
int charge() const
track electric charge
Definition: TrackBase.h:111
volatile std::atomic< bool > shutdown_flag false
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
bool selectPriVtxCompatibleWithTrack(const reco::Track &tk, std::vector< reco::Vertex > &selectedPriVtxCompatibleWithTrack)
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:133
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:141
double thetaError() const
error on theta
Definition: TrackBase.h:199