CMS 3D CMS Logo

PFConversionProducer.cc
Go to the documentation of this file.
1 #include <memory>
16 
17 typedef std::multimap<unsigned, std::vector<unsigned> > BlockMap;
18 using namespace std;
19 using namespace edm;
20 
21 
23  pfTransformer_(nullptr)
24 {
25  produces<reco::PFRecTrackCollection>();
26  produces<reco::PFConversionCollection>();
27 
28  pfConversionContainer_ =consumes<reco::ConversionCollection>(iConfig.getParameter< InputTag >("conversionCollection"));
29 
30  vtx_h=consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("PrimaryVertexLabel"));
31 }
32 
34 {
35  delete pfTransformer_;
36 }
37 
38 void
40 {
41 
42  //create the empty collections
43  auto pfConversionColl = std::make_unique<reco::PFConversionCollection>();
44  auto pfRecTrackColl = std::make_unique<reco::PFRecTrackCollection>();
45 
47  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
48  TransientTrackBuilder thebuilder = *(builder.product());
51  iEvent.getByToken(pfConversionContainer_, convCollH);
52 
53  const reco::ConversionCollection& convColl = *(convCollH.product());
54 
56  iEvent.getByToken(vtx_h, vertex);
57  //Find PV for IP calculation, if there is no PV in collection than use dummy
59  const reco::Vertex* pv=&dummy;
60  if (vertex.isValid())
61  {
62  pv = &*vertex->begin();
63  }
64  else
65  { // create a dummy PV
67  e(0, 0) = 0.0015 * 0.0015;
68  e(1, 1) = 0.0015 * 0.0015;
69  e(2, 2) = 15. * 15.;
70  reco::Vertex::Point p(0, 0, 0);
71  dummy = reco::Vertex(p, e, 0, 0, 0);
72  }
73 
74  int idx = 0; //index of track in PFRecTrack collection
75  multimap<unsigned int, unsigned int> trackmap; //Map of Collections and tracks
76  std::vector<unsigned int> conv_coll(0);
77 
78  // CLEAN CONVERSION COLLECTION FOR DUPLICATES
79  for( unsigned int icoll1=0; icoll1 < convColl.size(); icoll1++)
80  {
81  if (( !convColl[icoll1].quality(reco::Conversion::arbitratedMergedEcalGeneral)) || (!convColl[icoll1].quality(reco::Conversion::highPurity))) continue;
82 
83  bool greater_prob=false;
84  std::vector<edm::RefToBase<reco::Track> > tracksRefColl1 = convColl[icoll1].tracks();
85  for(unsigned it1 = 0; it1 < tracksRefColl1.size(); it1++)
86  {
87  reco::TrackRef trackRef1 = (tracksRefColl1[it1]).castTo<reco::TrackRef>();
88 
89  for( unsigned int icoll2=0; icoll2 < convColl.size(); icoll2++)
90  {
91  if(icoll1==icoll2)continue;
92  if (( !convColl[icoll2].quality(reco::Conversion::arbitratedMergedEcalGeneral)) || (!convColl[icoll2].quality(reco::Conversion::highPurity))) continue;
93  std::vector<edm::RefToBase<reco::Track> > tracksRefColl2 = convColl[icoll2].tracks();
94  for(unsigned it2 = 0; it2 < tracksRefColl2.size(); it2++)
95  {
96  reco::TrackRef trackRef2 = (tracksRefColl2[it2]).castTo<reco::TrackRef>();
97  double like1=-999;
98  double like2=-999;
99  //number of shared hits
100  int shared=0;
101  for(auto const& hit1 : trackRef1->recHits()) if(hit1->isValid()) {
102  //count number of shared hits
103  for(auto const& hit2 : trackRef2->recHits()) {
104  if(hit2->isValid() && hit1->sharesInput(hit2, TrackingRecHit::some)) shared++;
105  }
106  }
107  float frac=0;
108  //number of valid hits in tracks that are duplicates
109  float size1=trackRef1->found();
110  float size2=trackRef2->found();
111  //divide number of shared hits by the total number of hits for the track with less hits
112  if(size1>size2)frac=(double)shared/size2;
113  else frac=(double)shared/size1;
114  if(frac>0.9)
115  {
116  like1=ChiSquaredProbability(convColl[icoll1].conversionVertex().chi2(), convColl[icoll1].conversionVertex().ndof());
117  like2=ChiSquaredProbability(convColl[icoll2].conversionVertex().chi2(), convColl[icoll2].conversionVertex().ndof());
118  }
119  if(like2>like1)
120  {greater_prob=true; break;}
121  }//end loop over tracks in collection 2
122 
123  if(greater_prob)break; //if a duplicate track is found in a collection with greater Chi^2 probability for Vertex fit then break out of comparison loop
124  }//end loop over collection 2 checking
125  if(greater_prob)break;//if a duplicate track is found in a collection with greater Chi^2 probability for Vertex fit then one does not need to check the other track the collection will not be stored
126  } //end loop over tracks in collection 1
127  if(!greater_prob)conv_coll.push_back(icoll1);
128  }//end loop over collection 1
129 
130  //Finally fill empty collections
131  for(unsigned iColl=0; iColl<conv_coll.size(); iColl++)
132  {
133  unsigned int collindex=conv_coll[iColl];
134  //std::cout<<"Filling this collection"<<collindex<<endl;
135  std::vector<reco::PFRecTrackRef> pfRecTkcoll;
136 
137  std::vector<edm::RefToBase<reco::Track> > tracksRefColl = convColl[collindex].tracks();
138  // convert the secondary tracks
139  for(unsigned it = 0; it < tracksRefColl.size(); it++)
140  {
141  reco::TrackRef trackRef = (tracksRefColl[it]).castTo<reco::TrackRef>();
142  reco::PFRecTrack pfRecTrack( trackRef->charge(),
144  trackRef.key(),
145  trackRef );
146  //std::cout<<"Track Pt "<<trackRef->pt()<<std::endl;
147  Trajectory FakeTraj;
148  bool valid = pfTransformer_->addPoints( pfRecTrack, *trackRef, FakeTraj);
149  if(valid)
150  {
151  double stip=-999;
152  const reco::PFTrajectoryPoint& atECAL=pfRecTrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance);
153  //if extrapolation to ECAL is valid then calculate STIP
154  if(atECAL.isValid())
155  {
156  GlobalVector direction(pfRecTrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().x(),
157  pfRecTrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().y(),
158  pfRecTrack.extrapolatedPoint(reco::PFTrajectoryPoint::ECALEntrance).position().z());
159  stip = IPTools::signedTransverseImpactParameter(thebuilder.build(*trackRef), direction, *pv).second.significance();
160  }
161  pfRecTrack.setSTIP(stip);
162  pfRecTkcoll.push_back(reco::PFRecTrackRef( pfTrackRefProd, idx++));
163  pfRecTrackColl->push_back(pfRecTrack);
164  }
165  }//end loop over tracks
166  //store reference to the Conversion collection
167  reco::ConversionRef niRef(convCollH, collindex);
168  pfConversionColl->push_back( reco::PFConversion( niRef, pfRecTkcoll ));
169  }//end loop over collections
170  iEvent.put(std::move(pfRecTrackColl));
171  iEvent.put(std::move(pfConversionColl));
172 }
173 
174 // ------------ method called once each job just before starting event loop ------------
175 void
177  const EventSetup& iSetup)
178 {
180  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
183 }
184 
185 // ------------ method called once each job just after ending the event loop ------------
186 void
188  const EventSetup& iSetup) {
189  delete pfTransformer_;
190  pfTransformer_=nullptr;
191 }
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:125
edm::EDGetTokenT< reco::ConversionCollection > pfConversionContainer_
~PFConversionProducer() override
Destructor.
void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void endRun(const edm::Run &, const edm::EventSetup &) override
std::multimap< unsigned, std::vector< unsigned > > BlockMap
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.
#define nullptr
reco::TransientTrack build(const reco::Track *p) const
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
key_type key() const
Accessor for product key.
Definition: Ref.h:263
PFConversionProducer(const edm::ParameterSet &)
Constructor.
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
def pv(vc)
Definition: MetAnalyzer.py:7
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
float ChiSquaredProbability(double chiSquared, double nrDOF)
edm::EDGetTokenT< reco::VertexCollection > vtx_h
bool isValid() const
Definition: HandleBase.h:74
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
bool isValid() const
is this point valid ?
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
HLT enums.
T get() const
Definition: EventSetup.h:71
PFTrackTransformer * pfTransformer_
PFTrackTransformer.
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45