test
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  theSeedCreator(new SeedForPhotonConversion1Leg(conf.getParameter<edm::ParameterSet>("SeedCreatorPSet"))),
21  theRegionProducer(new GlobalTrackingRegionProducerFromBeamSpot(conf.getParameter<edm::ParameterSet>("RegionFactoryPSet"), iC)),
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 }
36 
38 }
39 
42 
43  myEsetup = &setup;
44  myEvent = &event;
45 
46  if(seedCollection!=0)
47  delete seedCollection;
48 
51 
54 
55  size_t clustsOrZero = theClusterCheck.tooManyClusters(event);
56  if (clustsOrZero){
58  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
59  return ;
60  }
61 
62 
63  edm::ESHandle<MagneticField> handleMagField;
64  setup.get<IdealMagneticFieldRecord>().get(handleMagField);
65  magField = handleMagField.product();
66  if (unlikely(magField->inTesla(GlobalPoint(0.,0.,0.)).z()<0.01)) return;
67 
69 
70 
71  event.getByToken(token_vertex, vertexHandle);
72  if (!vertexHandle.isValid() || vertexHandle->empty()){
73  edm::LogError("PhotonConversionFinderFromTracks") << "Error! Can't get the product primary Vertex Collection "<< _primaryVtxInputTag << "\n";
74  return;
75  }
76 
77  event.getByToken(token_bs,recoBeamSpotHandle);
78 
79 
80  regions = theRegionProducer->regions(event,setup);
81 
82  //Do the analysis
83  loopOnTracks();
84 
85 
86 #ifdef debugTSPFSLA
87  std::stringstream ss;
88  ss.str("");
89  ss << "\n++++++++++++++++++\n";
90  ss << "seed collection size " << seedCollection->size();
91  BOOST_FOREACH(TrajectorySeed tjS,*seedCollection){
92  po.print(ss, tjS);
93  }
94  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
95  //-------------------------------------------------
96 #endif
97 
98  // clear memory
99  theHitsGenerator->clearLayerCache();
100  for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) delete (*ir);
101 
102 }
103 
104 
107 
108  //--- Get Tracks
110 
111  if(trackCollectionH.isValid()==0){
112  edm::LogError("MissingInput")<<" could not find track collecion:"<<_conf.getParameter<edm::InputTag>("TrackRefitter");
113  return;
114  }
115  size_t idx=0, sel=0;
117 
118  ss.str("");
119 
120  for( reco::TrackCollection::const_iterator tr = trackCollectionH->begin();
121  tr != trackCollectionH->end(); tr++, idx++) {
122 
123  // #ifdef debugTSPFSLA
124  // ss << "\nStuding track Nb " << idx;
125  // #endif
126 
127  if(rejectTrack(*tr)) continue;
128  std::vector<reco::Vertex> selectedPriVtxCompatibleWithTrack;
130  selectedPriVtxCompatibleWithTrack.push_back(*(vertexHandle->begin())); //Same approach as before
131  }else{
132  if(!selectPriVtxCompatibleWithTrack(*tr,selectedPriVtxCompatibleWithTrack)) continue;
133  }
134 
135  sel++;
136  loopOnPriVtx(*tr,selectedPriVtxCompatibleWithTrack);
137  }
138 #ifdef debugTSPFSLA
139  edm::LogInfo("debugTrajSeedFromSingleLeg") << ss.str();
140  edm::LogInfo("debugTrajSeedFromSingleLeg") << "Inspected " << sel << " tracks over " << idx << " tracks. \t # tracks providing at least one seed " << _countSeedTracks ;
141 #endif
142 }
143 
145 selectPriVtxCompatibleWithTrack(const reco::Track& tk, std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack){
146 
147  std::vector< std::pair< double, short> > idx;
148  short count=-1;
149 
150  double cosPhi=tk.px()/tk.pt();
151  double sinPhi=tk.py()/tk.pt();
152  double sphi2=tk.covariance(2,2);
153  double stheta2=tk.covariance(1,1);
154 
155  BOOST_FOREACH(const reco::Vertex& vtx, *vertexHandle){
156  count++;
157  if(vtx.ndof()<= _vtxMinDoF) continue;
158 
159  double _dz= tk.dz(vtx.position());
160  double _dzError=tk.dzError();
161 
162  double cotTheta=tk.pz()/tk.pt();
163  double dx = vtx.position().x();
164  double dy = vtx.position().y();
165  double sx2=vtx.covariance(0,0);
166  double sy2=vtx.covariance(1,1);
167 
168  double sxy2= sqr(cosPhi*cotTheta)*sx2+
169  sqr(sinPhi*cotTheta)*sy2+
170  sqr(cotTheta*(-dx*sinPhi+dy*cosPhi))*sphi2+
171  sqr((1+cotTheta*cotTheta)*(dx*cosPhi+dy*sinPhi))*stheta2;
172 
173  _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.
174 
175 #ifdef debugTSPFSLA
176  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;
177 #endif
178 
179  if(fabs(_dz)/_dzError > _maxDZSigmas) continue;
180 
181  idx.push_back(std::pair<double,short>(fabs(_dz),count));
182  }
183  if(idx.size()==0) {
184 #ifdef debugTSPFSLA
185  ss << "no vertex selected " << std::endl;
186 #endif
187  return false;
188 }
189 
190  std::stable_sort(idx.begin(),idx.end(),lt_);
191  for(size_t i=0;i<_maxNumSelVtx && i<idx.size();++i){
192  selectedPriVtxCompatibleWithTrack.push_back((*vertexHandle)[idx[i].second]);
193 #ifdef debugTSPFSLA
194  ss << "selected vtx dz " << idx[0].first << " position" << idx[0].second << std::endl;
195 #endif
196  }
197 
198  return true;
199 }
200 
202 loopOnPriVtx(const reco::Track& tk, const std::vector<reco::Vertex>& selectedPriVtxCompatibleWithTrack){
203 
204  bool foundAtLeastASeedCand=false;
205  BOOST_FOREACH(const reco::Vertex vtx, selectedPriVtxCompatibleWithTrack){
206 
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(
221  inspectTrack(&tk,region, primaryVertexPoint)
222  and
223  !foundAtLeastASeedCand
224  ){
225  foundAtLeastASeedCand=true;
226  _countSeedTracks++;
227  }
228 
229  }
230  }
231 }
232 
234 rejectTrack(const reco::Track& track){
235 
238  beamSpot = math::XYZVector(recoBeamSpotHandle->position());
239 
240  _IdealHelixParameters.setData(&track,beamSpot);
242  //this case means a null results on the _IdealHelixParameters side
243  return true;
244  }
245 
246  float rMin=2.; //cm
247  if(_IdealHelixParameters.GetTangentPoint().rho()<rMin){
248  //this case means a track that has the tangent point nearby the primary vertex
249  // if the track is primary, this number tends to be the primary vertex itself
250  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
251  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
252  return true;
253  }
254  }
255 
256  //-------------------------------------------------------
257  /*
258  float maxPt2=64.; //Cut on pt^2 Indeed doesn't do almost nothing
259  if(track.momentum().Perp2() > maxPt2)
260  return true;
261  */
262  //-------------------------------------------------------
263  //Cut in the barrel eta region FIXME: to be extended to endcaps
264  /*
265  float maxEta=1.3;
266  if(fabs(track.eta()) > maxEta)
267  return true;
268  */
269  //-------------------------------------------------------
270  //Reject tracks that have a first valid hit in the pixel barrel/endcap layer/disk 1
271  //assume that the hits are aligned along momentum
272  /*
273  const reco::HitPattern& p=track.hitPattern();
274  for (int i=0; i<p.numberOfHits(); i++) {
275  uint32_t hit = p.getHitPattern(i);
276  // if the hit is valid and in pixel barrel, print out the layer
277  if (! p.validHitFilter(hit) ) continue;
278  if( (p.pixelBarrelHitFilter(hit) || p.pixelEndcapHitFilter(hit))
279  &&
280  p.getLayer(hit) == 1
281  )
282  return true;
283  else
284  break; //because the first valid hit is in a different layer
285  }
286  */
287  //-------------------------------------------------------
288 
289 
290  return false;
291 }
292 
293 
295 inspectTrack(const reco::Track* track, const TrackingRegion & region, math::XYZPoint& primaryVertexPoint){
296 
297  _IdealHelixParameters.setData(track,primaryVertexPoint);
298 
301  //this case means a null results on the _IdealHelixParameters side
302  return false;
303  }
304 
305  float rMin=3.; //cm
306  if(_IdealHelixParameters.GetTangentPoint().rho()<rMin){
307  //this case means a track that has the tangent point nearby the primary vertex
308  // if the track is primary, this number tends to be the primary vertex itself
309  //Rejecting all the potential photon conversions having a "vertex" inside the beampipe
310  //We should not miss too much, seen that the conversions at the beam pipe are the better reconstructed
311  return false;
312  }
313 
314  float ptmin = 0.5;
315  float originRBound = 3;
316  float originZBound = 3.;
317 
318  GlobalPoint originPos;
322  );
323  float cotTheta;
326  }else{
328  cotTheta=99999.f;
329  else
330  cotTheta=-99999.f;
331  }
332  GlobalVector originBounds(originRBound,originRBound,originZBound);
333 
334  GlobalPoint pvtxPoint(primaryVertexPoint.x(),
335  primaryVertexPoint.y(),
336  primaryVertexPoint.z()
337  );
338  ConversionRegion convRegion(originPos, pvtxPoint, cotTheta, track->thetaError(), -1*track->charge());
339 
340 #ifdef debugTSPFSLA
341  ss << "\nConversion Point " << originPos << " " << originPos.perp() << "\n";
342 #endif
343 
344  const OrderedSeedingHits & hitss = theHitsGenerator->run(convRegion, region, *myEvent, *myEsetup);
345 
346  unsigned int nHitss = hitss.size();
347 
348  if(nHitss==0)
349  return false;
350 
351 #ifdef debugTSPFSLA
352  ss << "\n nHitss " << nHitss << "\n";
353 #endif
354 
355  if (seedCollection->empty()) seedCollection->reserve(nHitss); // don't do multiple reserves in the case of multiple regions: it would make things even worse
356  // as it will cause N re-allocations instead of the normal log(N)/log(2)
357  for (unsigned int iHits = 0; iHits < nHitss; ++iHits) {
358 
359 #ifdef debugTSPFSLA
360  ss << "\n iHits " << iHits << "\n";
361 #endif
362  const SeedingHitSet & hits = hitss[iHits];
363  //if (!theComparitor || theComparitor->compatible( hits, es) ) {
364  //try{
365  theSeedCreator->trajectorySeed(*seedCollection,hits, originPos, originBounds, ptmin, *myEsetup,convRegion.cotTheta(),ss);
366  //}catch(cms::Exception& er){
367  // edm::LogError("SeedingConversion") << " Problem in the Single Leg Seed creator " <<er.what()<<std::endl;
368  //}catch(std::exception& er){
369  // edm::LogError("SeedingConversion") << " Problem in the Single Leg Seed creator " << er.what()<<std::endl;
370  //}
371  }
372  return true;
373 }
374 
375 
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
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
virtual unsigned int size() const =0
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:123
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:131
const Point & position() const
position
Definition: Vertex.h:106
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:180
math::XYZVector GetMomentumAtTangentPoint() const
return((rh^lh)&mask)
#define unlikely(x)
U second(std::pair< T, U > const &p)
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:102
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
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