CMS 3D CMS Logo

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