test
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_()
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_ptr< reco::PFRecTrackCollection >
63  PfTrColl (new reco::PFRecTrackCollection);
64 
65  //read track collection
66  Handle<GsfTrackCollection> gsftrackcoll;
67  bool foundgsf = false;
68  if(gsfinev_) {
69  foundgsf = iEvent.getByToken(gsfTrackLabel_,gsftrackcoll);
70  }
71 
72  //Get PV for STIP calculation, if there is none then take the dummy
74  iEvent.getByToken(vtx_h, vertex);
75  reco::Vertex dummy;
76  const reco::Vertex* pv=&dummy;
77  if (vertex.isValid())
78  {
79  pv = &*vertex->begin();
80  }
81  else
82  { // create a dummy PV
84  e(0, 0) = 0.0015 * 0.0015;
85  e(1, 1) = 0.0015 * 0.0015;
86  e(2, 2) = 15. * 15.;
87  reco::Vertex::Point p(0, 0, 0);
88  dummy = reco::Vertex(p, e, 0, 0, 0);
89  }
90 
92  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
93  TransientTrackBuilder thebuilder = *(builder.product());
94 
95  // read muon collection
97  iEvent.getByToken(muonColl_, recMuons);
98 
99  //default value for when trajinev_ is false
100  const vector<Trajectory> dummyTj(0);
101 
102  for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
103 
104  //Track collection
105  Handle<reco::TrackCollection> tkRefCollection;
106  iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
107  reco::TrackCollection Tk=*(tkRefCollection.product());
108 
109  //Use a pointer to aoid unnecessary copying of the collection
110  const vector<Trajectory>* Tj = &dummyTj;
111  if(trajinev_) {
112  //Trajectory collection
113  Handle<vector<Trajectory> > tjCollection;
114  iEvent.getByToken(trajContainers_[istr], tjCollection);
115 
116  Tj =tjCollection.product();
117  }
118 
119 
120  for(unsigned int i=0;i<Tk.size();i++){
121 
122  reco::TrackRef trackRef(tkRefCollection, i);
123 
124  if (useQuality_ &&
125  (!(Tk[i].quality(trackQuality_)))){
126 
127  bool isMuCandidate = false;
128 
129  //TrackRef trackRef(tkRefCollection, i);
130 
131  if(recMuons.isValid() ) {
132  for(unsigned j=0;j<recMuons->size(); j++) {
133  reco::MuonRef muonref( recMuons, j );
134  if (muonref->track().isNonnull())
135  if( muonref->track() == trackRef && muonref->isGlobalMuon()){
136  isMuCandidate=true;
137  //cout<<" SAVING TRACK "<<endl;
138  break;
139  }
140  }
141  }
142  if(!isMuCandidate)
143  {
144  continue;
145  }
146 
147  }
148 
149  // find the pre-id kf track
150  bool preId = false;
151  if(foundgsf) {
152  //NOTE: foundgsf is only true if gsftrackcoll is valid
153  for (auto const& gsfTrack: *gsftrackcoll) {
154  if (gsfTrack.seedRef().isNull()) continue;
155  auto const& seed = *(gsfTrack.extra()->seedRef());
156  auto const& ElSeed = dynamic_cast<ElectronSeed const&>(seed);
157  if (ElSeed.ctfTrack().isNonnull()) {
158  if(ElSeed.ctfTrack() == trackRef) {
159  preId = true;
160  break;
161  }
162  }
163  }
164  }
165  if(preId) {
166  // Set PFRecTrack of type KF_ElCAND
167  reco::PFRecTrack pftrack( trackRef->charge(),
169  i, trackRef );
170 
171  bool valid = false;
172  if(trajinev_) {
173  valid = pfTransformer_->addPoints( pftrack, *trackRef, (*Tj)[i]);
174  }
175  else {
176  Trajectory FakeTraj;
177  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
178  }
179  if(valid) {
180  //calculate STIP
181  double stip=-999;
182  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
183  if(atECAL.isValid()) //if track extrapolates to ECAL
184  {
185  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
186  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
187  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
188  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
189  }
190  pftrack.setSTIP(stip);
191  PfTrColl->push_back(pftrack);
192  }
193  }
194  else {
195  reco::PFRecTrack pftrack( trackRef->charge(),
197  i, trackRef );
198  bool valid = false;
199  if(trajinev_) {
200  valid = pfTransformer_->addPoints( pftrack, *trackRef, (*Tj)[i]);
201  }
202  else {
203  Trajectory FakeTraj;
204  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
205  }
206 
207  if(valid) {
208  double stip=-999;
209  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
210  if(atECAL.isValid())
211  {
212  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
213  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
214  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
215  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
216  }
217  pftrack.setSTIP(stip);
218  PfTrColl->push_back(pftrack);
219  }
220  }
221  }
222  }
223  iEvent.put(PfTrColl);
224 }
225 
226 // ------------ method called once each job just before starting event loop ------------
227 void
229  const EventSetup& iSetup)
230 {
232  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
233  pfTransformer_.reset( new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0)))) );
234  if(!trajinev_)
235  pfTransformer_->OnlyProp();
236 }
237 
238 // ------------ method called once each job just after ending the event loop ------------
239 void
241  const EventSetup& iSetup) {
242  pfTransformer_.reset();
243 }
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 isNonnull() const
Checks for non-null.
Definition: Ref.h:252
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
bool useQuality_
TRACK QUALITY.
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:75
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: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:56
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
T const * product() const
Definition: ESHandle.h:86
string const
Definition: compareJSON.py:14
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
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
Definition: Run.h:43