CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFTrackProducer.cc
Go to the documentation of this file.
1 #include <memory>
19 
20 using namespace std;
21 using namespace edm;
22 using namespace reco;
24  pfTransformer_(0)
25 {
26  produces<reco::PFRecTrackCollection>();
27 
28 
29  std::vector<InputTag> tags=iConfig.getParameter< vector < InputTag > >("TkColList");
30  for( unsigned int i=0;i<tags.size();++i)
31  tracksContainers_.push_back(consumes<reco::TrackCollection>(tags[i]));
32 
33  useQuality_ = iConfig.getParameter<bool>("UseQuality");
34 
35  gsfTrackLabel_ = consumes<reco::GsfTrackCollection>(iConfig.getParameter<InputTag>
36  ("GsfTrackModuleLabel"));
37 
39 
40  muonColl_ = consumes<reco::MuonCollection>(iConfig.getParameter< InputTag >("MuColl"));
41 
42  trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
43 
44  gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
45  vtx_h=consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel"));
46 
47 }
48 
50 {
51  delete pfTransformer_;
52 }
53 
54 void
56 {
57 
58  //create the empty collections
59  auto_ptr< reco::PFRecTrackCollection >
60  PfTrColl (new reco::PFRecTrackCollection);
61 
62  //read track collection
63  Handle<GsfTrackCollection> gsftrackcoll;
64  bool foundgsf = iEvent.getByToken(gsfTrackLabel_,gsftrackcoll);
65  GsfTrackCollection gsftracks;
66  //Get PV for STIP calculation, if there is none then take the dummy
68  iEvent.getByToken(vtx_h, vertex);
69  reco::Vertex dummy;
70  const reco::Vertex* pv=&dummy;
71  if (vertex.isValid())
72  {
73  pv = &*vertex->begin();
74  }
75  else
76  { // create a dummy PV
78  e(0, 0) = 0.0015 * 0.0015;
79  e(1, 1) = 0.0015 * 0.0015;
80  e(2, 2) = 15. * 15.;
81  reco::Vertex::Point p(0, 0, 0);
82  dummy = reco::Vertex(p, e, 0, 0, 0);
83  }
84 
86  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
87  TransientTrackBuilder thebuilder = *(builder.product());
88 
89 
90  if(gsfinev_) {
91  if(foundgsf )
92  gsftracks = *(gsftrackcoll.product());
93  }
94 
95  // read muon collection
97  iEvent.getByToken(muonColl_, recMuons);
98 
99 
100  for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
101 
102  //Track collection
103  Handle<reco::TrackCollection> tkRefCollection;
104  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
105  reco::TrackCollection Tk=*(tkRefCollection.product());
106 
107  vector<Trajectory> Tj(0);
108  if(trajinev_) {
109  //Trajectory collection
110  Handle<vector<Trajectory> > tjCollection;
111  iEvent.getByToken(tracksContainers_[istr], tjCollection);
112 
113  Tj =*(tjCollection.product());
114  }
115 
116 
117  for(unsigned int i=0;i<Tk.size();i++){
118 
119  reco::TrackRef trackRef(tkRefCollection, i);
120 
121  if (useQuality_ &&
122  (!(Tk[i].quality(trackQuality_)))){
123 
124  bool isMuCandidate = false;
125 
126  //TrackRef trackRef(tkRefCollection, i);
127 
128  if(recMuons.isValid() ) {
129  for(unsigned j=0;j<recMuons->size(); j++) {
130  reco::MuonRef muonref( recMuons, j );
131  if (muonref->track().isNonnull())
132  if( muonref->track() == trackRef && muonref->isGlobalMuon()){
133  isMuCandidate=true;
134  //cout<<" SAVING TRACK "<<endl;
135  break;
136  }
137  }
138  }
139  if(!isMuCandidate)
140  {
141  continue;
142  }
143 
144  }
145 
146  // find the pre-id kf track
147  bool preId = false;
148  if(foundgsf) {
149  for (unsigned int igsf=0; igsf<gsftracks.size();igsf++) {
150  GsfTrackRef gsfTrackRef(gsftrackcoll, igsf);
151  if (gsfTrackRef->seedRef().isNull()) continue;
152  ElectronSeedRef ElSeedRef= gsfTrackRef->extra()->seedRef().castTo<ElectronSeedRef>();
153  if (ElSeedRef->ctfTrack().isNonnull()) {
154  if(ElSeedRef->ctfTrack() == trackRef) preId = true;
155  }
156  }
157  }
158  if(preId) {
159  // Set PFRecTrack of type KF_ElCAND
160  reco::PFRecTrack pftrack( trackRef->charge(),
162  i, trackRef );
163 
164  bool valid = false;
165  if(trajinev_) {
166  valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
167  }
168  else {
169  Trajectory FakeTraj;
170  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
171  }
172  if(valid) {
173  //calculate STIP
174  double stip=-999;
175  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
176  if(atECAL.isValid()) //if track extrapolates to ECAL
177  {
178  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
179  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
180  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
181  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
182  }
183  pftrack.setSTIP(stip);
184  PfTrColl->push_back(pftrack);
185  }
186  }
187  else {
188  reco::PFRecTrack pftrack( trackRef->charge(),
190  i, trackRef );
191  bool valid = false;
192  if(trajinev_) {
193  valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
194  }
195  else {
196  Trajectory FakeTraj;
197  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
198  }
199 
200  if(valid) {
201  double stip=-999;
202  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
203  if(atECAL.isValid())
204  {
205  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
206  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
207  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
208  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
209  }
210  pftrack.setSTIP(stip);
211  PfTrColl->push_back(pftrack);
212  }
213  }
214  }
215  }
216  iEvent.put(PfTrColl);
217 }
218 
219 // ------------ method called once each job just before starting event loop ------------
220 void
222  const EventSetup& iSetup)
223 {
224  ESHandle<MagneticField> magneticField;
225  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
226  pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
227  if(!trajinev_)
229 }
230 
231 // ------------ method called once each job just after ending the event loop ------------
232 void
234  const EventSetup& iSetup) {
235  delete pfTransformer_;
236  pfTransformer_=nullptr;
237 }
T getParameter(std::string const &) const
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:22
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
PFTrackProducer(const edm::ParameterSet &)
Constructor.
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
bool addPoints(reco::PFRecTrack &pftrack, const reco::Track &track, const Trajectory &traj, bool msgwarning=true) const
Add points to a PFTrack. return false if a TSOS is invalid.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
reco::TransientTrack build(const reco::Track *p) const
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackLabel_
edm::EDGetTokenT< reco::VertexCollection > vtx_h
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
U second(std::pair< T, U > const &p)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int iEvent
Definition: GenABIO.cc:230
bool isNull() const
Checks for null.
Definition: Ref.h:247
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool useQuality_
TRACK QUALITY.
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
edm::EDGetTokenT< reco::MuonCollection > muonColl_
bool isValid() const
Definition: HandleBase.h:76
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
tuple tags
Definition: o2o.py:248
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
bool isValid() const
is this point valid ?
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
PFTrackTransformer * pfTransformer_
PFTrackTransformer.
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
virtual void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
reco::TrackBase::TrackQuality trackQuality_
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
Definition: Run.h:41
~PFTrackProducer()
Destructor.