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>
23 
24 using namespace std;
25 using namespace edm;
26 using namespace reco;
28  pfTransformer_(0)
29 {
30  produces<reco::PFRecTrackCollection>();
31 
33  iConfig.getParameter< vector < InputTag > >("TkColList");
34 
35  useQuality_ = iConfig.getParameter<bool>("UseQuality");
36 
38  ("GsfTrackModuleLabel");
39 
40  trackQuality_=reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
41 
42  muonColl_ = iConfig.getParameter< InputTag >("MuColl");
43 
44  trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
45 
46  gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
47  vtx_h=iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel");
48 }
49 
51 {
52  delete pfTransformer_;
53 }
54 
55 void
57 {
58 
59  //create the empty collections
60  auto_ptr< reco::PFRecTrackCollection >
61  PfTrColl (new reco::PFRecTrackCollection);
62 
63  //read track collection
64  Handle<GsfTrackCollection> gsftrackcoll;
65  bool foundgsf = iEvent.getByLabel(gsfTrackLabel_,gsftrackcoll);
66  GsfTrackCollection gsftracks;
67  //Get PV for STIP calculation, if there is none then take the dummy
69  iEvent.getByLabel(vtx_h, vertex);
70  reco::Vertex dummy;
71  const reco::Vertex* pv=&dummy;
72  if (vertex.isValid())
73  {
74  pv = &*vertex->begin();
75  }
76  else
77  { // create a dummy PV
79  e(0, 0) = 0.0015 * 0.0015;
80  e(1, 1) = 0.0015 * 0.0015;
81  e(2, 2) = 15. * 15.;
82  reco::Vertex::Point p(0, 0, 0);
83  dummy = reco::Vertex(p, e, 0, 0, 0);
84  }
85 
87  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
88  TransientTrackBuilder thebuilder = *(builder.product());
89 
90 
91  if(gsfinev_) {
92  if(!foundgsf )
93  LogError("PFTrackProducer")
94  <<" cannot get GsfTracks (probably in HI events): "
95  << " please set GsfTracksInEvents = False in RecoParticleFlow/PFTracking/python/pfTrack_cfi.py" << endl;
96  else
97  gsftracks = *(gsftrackcoll.product());
98  }
99 
100  // read muon collection
102  iEvent.getByLabel(muonColl_, recMuons);
103 
104 
105  for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
106 
107  //Track collection
108  Handle<reco::TrackCollection> tkRefCollection;
109  iEvent.getByLabel(tracksContainers_[istr], tkRefCollection);
110  reco::TrackCollection Tk=*(tkRefCollection.product());
111 
112  vector<Trajectory> Tj(0);
113  if(trajinev_) {
114  //Trajectory collection
115  Handle<vector<Trajectory> > tjCollection;
116  bool found = iEvent.getByLabel(tracksContainers_[istr], tjCollection);
117  if(!found )
118  LogError("PFTrackProducer")
119  <<" cannot get Trajectories of: "
120  << tracksContainers_[istr]
121  << " please set TrajInEvents = False in RecoParticleFlow/PFTracking/python/pfTrack_cfi.py" << endl;
122 
123  Tj =*(tjCollection.product());
124  }
125 
126 
127  for(unsigned int i=0;i<Tk.size();i++){
128 
129  reco::TrackRef trackRef(tkRefCollection, i);
130 
131  if (useQuality_ &&
132  (!(Tk[i].quality(trackQuality_)))){
133 
134  bool isMuCandidate = false;
135 
136  //TrackRef trackRef(tkRefCollection, i);
137 
138  if(recMuons.isValid() ) {
139  for(unsigned j=0;j<recMuons->size(); j++) {
140  reco::MuonRef muonref( recMuons, j );
141  if (muonref->track().isNonnull())
142  if( muonref->track() == trackRef && muonref->isGlobalMuon()){
143  isMuCandidate=true;
144  //cout<<" SAVING TRACK "<<endl;
145  break;
146  }
147  }
148  }
149  else{
150  edm::LogError("MissingInput")<<"there is no valide:"<<muonColl_<<" to be used.";
151  }
152 
153  if(!isMuCandidate)
154  {
155  continue;
156  }
157 
158  }
159 
160  // find the pre-id kf track
161  bool preId = false;
162  if(foundgsf) {
163  for (unsigned int igsf=0; igsf<gsftracks.size();igsf++) {
164  GsfTrackRef gsfTrackRef(gsftrackcoll, igsf);
165  if (gsfTrackRef->seedRef().isNull()) continue;
166  ElectronSeedRef ElSeedRef= gsfTrackRef->extra()->seedRef().castTo<ElectronSeedRef>();
167  if (ElSeedRef->ctfTrack().isNonnull()) {
168  if(ElSeedRef->ctfTrack() == trackRef) preId = true;
169  }
170  }
171  }
172  if(preId) {
173  // Set PFRecTrack of type KF_ElCAND
174  reco::PFRecTrack pftrack( trackRef->charge(),
176  i, trackRef );
177 
178  bool valid = false;
179  if(trajinev_) {
180  valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
181  }
182  else {
183  Trajectory FakeTraj;
184  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
185  }
186  if(valid) {
187  //calculate STIP
188  double stip=-999;
189  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
190  if(atECAL.isValid()) //if track extrapolates to ECAL
191  {
192  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
193  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
194  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
195  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
196  }
197  pftrack.setSTIP(stip);
198  PfTrColl->push_back(pftrack);
199  }
200  }
201  else {
202  reco::PFRecTrack pftrack( trackRef->charge(),
204  i, trackRef );
205  bool valid = false;
206  if(trajinev_) {
207  valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
208  }
209  else {
210  Trajectory FakeTraj;
211  valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
212  }
213 
214  if(valid) {
215  double stip=-999;
216  const reco::PFTrajectoryPoint& atECAL=pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
217  if(atECAL.isValid())
218  {
219  GlobalVector direction(pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
220  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
221  pftrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
222  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
223  }
224  pftrack.setSTIP(stip);
225  PfTrColl->push_back(pftrack);
226  }
227  }
228  }
229  }
230  iEvent.put(PfTrColl);
231 }
232 
233 // ------------ method called once each job just before starting event loop ------------
234 void
236  const EventSetup& iSetup)
237 {
238  ESHandle<MagneticField> magneticField;
239  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
240  pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
241  if(!trajinev_)
243 }
244 
245 // ------------ method called once each job just after ending the event loop ------------
246 void
248  delete pfTransformer_;
249 }
virtual void produce(edm::Event &, const edm::EventSetup &)
Produce the PFRecTrack collection.
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
edm::InputTag muonColl_
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.
edm::InputTag vtx_h
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:44
std::vector< edm::InputTag > 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:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
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:40
bool isValid() const
Definition: HandleBase.h:76
virtual void beginRun(edm::Run &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag gsfTrackLabel_
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:31
PFTrackTransformer * pfTransformer_
PFTrackTransformer.
const T & get() const
Definition: EventSetup.h:55
virtual void endRun()
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
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:33
~PFTrackProducer()
Destructor.