CMS 3D CMS Logo

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_()
25 {
26  produces<reco::PFRecTrackCollection>();
27 
28 
29  std::vector<InputTag> tags=iConfig.getParameter< vector < InputTag > >("TkColList");
30  trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
31  tracksContainers_.reserve(tags.size());
32  if(trajinev_) { trajContainers_.reserve(tags.size()); }
33  for( auto const& tag: tags) {
34  tracksContainers_.push_back(consumes<reco::TrackCollection>(tag));
35  if(trajinev_) {
36  trajContainers_.push_back(consumes<std::vector<Trajectory> >(tag));
37  }
38  }
39 
40  useQuality_ = iConfig.getParameter<bool>("UseQuality");
41 
42  gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
43  if(gsfinev_) {
44  gsfTrackLabel_ = consumes<reco::GsfTrackCollection>(iConfig.getParameter<InputTag>
45  ("GsfTrackModuleLabel"));
46  }
47 
49 
50  muonColl_ = consumes<reco::MuonCollection>(iConfig.getParameter< InputTag >("MuColl"));
51 
52 
53  vtx_h=consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel"));
54 
55 }
56 
57 void
59 {
60 
61  //create the empty collections
62  auto PfTrColl = std::make_unique<reco::PFRecTrackCollection>();
63 
64  //read track collection
65  Handle<GsfTrackCollection> gsftrackcoll;
66  bool foundgsf = false;
67  if(gsfinev_) {
68  foundgsf = iEvent.getByToken(gsfTrackLabel_,gsftrackcoll);
69  }
70 
71  //Get PV for STIP calculation, if there is none then take the dummy
73  iEvent.getByToken(vtx_h, vertex);
75  const reco::Vertex* pv=&dummy;
76  if (vertex.isValid())
77  {
78  pv = &*vertex->begin();
79  }
80  else
81  { // create a dummy PV
83  e(0, 0) = 0.0015 * 0.0015;
84  e(1, 1) = 0.0015 * 0.0015;
85  e(2, 2) = 15. * 15.;
86  reco::Vertex::Point p(0, 0, 0);
87  dummy = reco::Vertex(p, e, 0, 0, 0);
88  }
89 
91  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
92  TransientTrackBuilder thebuilder = *(builder.product());
93 
94  // read muon collection
96  iEvent.getByToken(muonColl_, recMuons);
97 
98  //default value for when trajinev_ is false
99  const vector<Trajectory> dummyTj(0);
100 
101  for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
102 
103  //Track collection
104  Handle<reco::TrackCollection> tkRefCollection;
105  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
106  reco::TrackCollection Tk=*(tkRefCollection.product());
107 
108  //Use a pointer to aoid unnecessary copying of the collection
109  const vector<Trajectory>* Tj = &dummyTj;
110  if(trajinev_) {
111  //Trajectory collection
112  Handle<vector<Trajectory> > tjCollection;
113  iEvent.getByToken(trajContainers_[istr], tjCollection);
114 
115  Tj =tjCollection.product();
116  }
117 
118 
119  for(unsigned int i=0;i<Tk.size();i++){
120 
121  reco::TrackRef trackRef(tkRefCollection, i);
122 
123  if (useQuality_ &&
124  (!(Tk[i].quality(trackQuality_)))){
125 
126  bool isMuCandidate = false;
127 
128  //TrackRef trackRef(tkRefCollection, i);
129 
130  if(recMuons.isValid() ) {
131  for(unsigned j=0;j<recMuons->size(); j++) {
132  reco::MuonRef muonref( recMuons, j );
133  if (muonref->track().isNonnull())
134  if( muonref->track() == trackRef && muonref->isGlobalMuon()){
135  isMuCandidate=true;
136  //cout<<" SAVING TRACK "<<endl;
137  break;
138  }
139  }
140  }
141  if(!isMuCandidate)
142  {
143  continue;
144  }
145 
146  }
147 
148  // find the pre-id kf track
149  bool preId = false;
150  if(foundgsf) {
151  //NOTE: foundgsf is only true if gsftrackcoll is valid
152  for (auto const& gsfTrack: *gsftrackcoll) {
153  if (gsfTrack.seedRef().isNull()) continue;
154  auto const& seed = *(gsfTrack.extra()->seedRef());
155  auto const& ElSeed = dynamic_cast<ElectronSeed const&>(seed);
156  if (ElSeed.ctfTrack().isNonnull()) {
157  if(ElSeed.ctfTrack() == trackRef) {
158  preId = true;
159  break;
160  }
161  }
162  }
163  }
164  if(preId) {
165  // Set PFRecTrack of type KF_ElCAND
166  reco::PFRecTrack pftrack( trackRef->charge(),
168  i, trackRef );
169 
170  bool valid = false;
171  if(trajinev_) {
172  valid = pfTransformer_->addPoints( pftrack, *trackRef, (*Tj)[i]);
173  }
174  else {
175  Trajectory FakeTraj;
176  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
177  }
178  if(valid) {
179  //calculate STIP
180  double stip=-999;
181  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
182  if(atECAL.isValid()) //if track extrapolates to ECAL
183  {
184  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
185  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
186  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
187  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
188  }
189  pftrack.setSTIP(stip);
190  PfTrColl->push_back(pftrack);
191  }
192  }
193  else {
194  reco::PFRecTrack pftrack( trackRef->charge(),
196  i, trackRef );
197  bool valid = false;
198  if(trajinev_) {
199  valid = pfTransformer_->addPoints( pftrack, *trackRef, (*Tj)[i]);
200  }
201  else {
202  Trajectory FakeTraj;
203  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
204  }
205 
206  if(valid) {
207  double stip=-999;
208  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
209  if(atECAL.isValid())
210  {
211  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
212  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
213  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
214  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
215  }
216  pftrack.setSTIP(stip);
217  PfTrColl->push_back(pftrack);
218  }
219  }
220  }
221  }
222  iEvent.put(std::move(PfTrColl));
223 }
224 
225 // ------------ method called once each job just before starting event loop ------------
226 void
228  const EventSetup& iSetup)
229 {
231  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
232  pfTransformer_.reset( new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0)))) );
233  if(!trajinev_)
234  pfTransformer_->OnlyProp();
235 }
236 
237 // ------------ method called once each job just after ending the event loop ------------
238 void
240  const EventSetup& iSetup) {
241  pfTransformer_.reset();
242 }
T getParameter(std::string const &) const
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:22
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
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
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
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_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
bool useQuality_
TRACK QUALITY.
def pv(vc)
Definition: MetAnalyzer.py:6
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
edm::EDGetTokenT< reco::MuonCollection > muonColl_
bool isValid() const
Definition: HandleBase.h:74
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
bool isValid() const
is this point valid ?
T const * product() const
Definition: Handle.h:81
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:55
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
virtual void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
fixed size matrix
HLT enums.
reco::TrackBase::TrackQuality trackQuality_
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
Definition: Run.h:42