CMS 3D CMS Logo

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