CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicParametersDefinerForTP.cc
Go to the documentation of this file.
18 
20 
21 
24  // to add a new implementation for cosmic. For the moment, it is just as for the base class:
25  using namespace edm;
26  using namespace std;
27  using namespace reco;
28 
30  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
31 
33  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
34 
36  iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
37 
38  // cout<<"TrackingParticle pdgId = "<<tpr->pdgId()<<endl;
39  // cout<<"with tpr->vertex(): ("<<tpr->vertex().x()<<", "<<tpr->vertex().y()<<", "<<tpr->vertex().z()<<")"<<endl;
40  // cout<<"with tpr->momentum(): ("<<tpr->momentum().x()<<", "<<tpr->momentum().y()<<", "<<tpr->momentum().z()<<")"<<endl;
41 
42  GlobalVector finalGV;
43  GlobalPoint finalGP;
44  double radius(9999);
45  bool found(0);
47 
48  if (simHitsTPAssoc.isValid()==0) {
49  LogError("TrackAssociation") << "Invalid handle!";
50  return momentum;
51  }
52  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
53  // sorting only the cluster is needed
54  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
56  for(auto ip = range.first; ip != range.second; ++ip) {
57  TrackPSimHitRef it = ip->second;
58  const GeomDet* tmpDet = tracker->idToDet( DetId(it->detUnitId()) ) ;
59  LocalVector lv = it->momentumAtEntry();
60  Local3DPoint lp = it->localPosition ();
61  GlobalVector gv = tmpDet->surface().toGlobal( lv );
62  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
63  if(gp.perp()<radius){
64  found=true;
65  radius = gp.perp();
66  finalGV = gv;
67  finalGP = gp;
68  }
69  }
70 
71  //cout<<"found = "<<found<<endl;
72  // cout<<"Closest Hit Position: ("<<finalGP.x()<<", "<<finalGP.y()<<", "<<finalGP.z()<<")"<<endl;
73  //cout<<"Momentum at Closest Hit to BL: ("<<finalGV.x()<<", "<<finalGV.y()<<", "<<finalGV.z()<<")"<<endl;
74 
75  if(found)
76  {
77  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
78  TSCBLBuilderNoMaterial tscblBuilder;
79  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
80  if(tsAtClosestApproach.isValid()){
81  GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
82  momentum = TrackingParticle::Vector(p.x(), p.y(), p.z());
83  }
84  return momentum;
85  }
86  return momentum;
87 }
88 
90 
91  using namespace edm;
92  using namespace std;
93  using namespace reco;
94 
96  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
97 
99  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
100 
102  iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
103 
104  GlobalVector finalGV;
105  GlobalPoint finalGP;
106  double radius(9999);
107  bool found(0);
109 
110  if (simHitsTPAssoc.isValid()==0) {
111  LogError("TrackAssociation") << "Invalid handle!";
112  return vertex;
113  }
114  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
115  // sorting only the cluster is needed
116  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
118  for(auto ip = range.first; ip != range.second; ++ip) {
119  TrackPSimHitRef it = ip->second;
120  const GeomDet* tmpDet = tracker->idToDet( DetId(it->detUnitId()) ) ;
121  LocalVector lv = it->momentumAtEntry();
122  Local3DPoint lp = it->localPosition ();
123  GlobalVector gv = tmpDet->surface().toGlobal( lv );
124  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
125  if(gp.perp()<radius){
126  found=true;
127  radius = gp.perp();
128  finalGV = gv;
129  finalGP = gp;
130  }
131  }
132  if(found)
133  {
134  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
135  TSCBLBuilderNoMaterial tscblBuilder;
136  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
137  if(tsAtClosestApproach.isValid()){
138  GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
139  vertex = TrackingParticle::Point(v.x()-bs->x0(),v.y()-bs->y0(),v.z()-bs->z0());
140  }
141  return vertex;
142  }
143  return vertex;
144 }
145 
146 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T perp() const
Definition: PV3DBase.h:72
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
virtual TrackingParticle::Vector momentum(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef tpr) const
T y() const
Definition: PV3DBase.h:63
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
math::XYZPointD Point
point in the space
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:243
T z() const
Definition: PV3DBase.h:64
virtual TrackingParticle::Point vertex(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef tpr) const
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
GlobalVector momentum() const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:97
Definition: DetId.h:20
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:55
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
math::XYZVectorD Vector
point in the space
T x() const
Definition: PV3DBase.h:62
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc