CMS 3D CMS Logo

Skim_UpdatedMuonInnerTrackRef.cc
Go to the documentation of this file.
1 #include <memory>
6 
13 
15 
16 //
17 // class declaration
18 //
20 public:
22 
23 private:
24  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
25 
26  reco::TrackRef findNewRef(reco::TrackRef const& oldTrackRef,
28 
32 
33  double maxInvPtDiff;
34  double minDR;
35 };
36 
39  // What is being produced
40  produces<std::vector<reco::Muon> >();
41 
42  // Input products
43  muonToken_ =
44  consumes<edm::View<reco::Muon> >(pset.getUntrackedParameter<edm::InputTag>("MuonTag", edm::InputTag("muons")));
45  oldTrackToken_ = consumes<reco::TrackCollection>(
46  pset.getUntrackedParameter<edm::InputTag>("OldTrackTag", edm::InputTag("generalTracks")));
47  newTrackToken_ = consumes<reco::TrackCollection>(
48  pset.getUntrackedParameter<edm::InputTag>("NewTrackTag", edm::InputTag("generalTracksSkim")));
49 
50  // matching criteria products
51  maxInvPtDiff = pset.getUntrackedParameter<double>("maxInvPtDiff", 0.005);
52  minDR = pset.getUntrackedParameter<double>("minDR", 0.1);
53 }
54 
57  // Muon collection
58  edm::Handle<edm::View<reco::Muon> > muonCollectionHandle;
59  if (!ev.getByToken(muonToken_, muonCollectionHandle)) {
60  edm::LogError("") << ">>> Muon collection does not exist !!!";
61  return;
62  }
63 
65  if (!ev.getByToken(oldTrackToken_, oldTrackCollection)) {
66  edm::LogError("") << ">>> Old Track collection does not exist !!!";
67  return;
68  }
69 
71  if (!ev.getByToken(newTrackToken_, newTrackCollection)) {
72  edm::LogError("") << ">>> New Track collection does not exist !!!";
73  return;
74  }
75 
76  unsigned int muonCollectionSize = muonCollectionHandle->size();
77  std::unique_ptr<reco::MuonCollection> newmuons(new reco::MuonCollection);
78 
79  for (unsigned int i = 0; i < muonCollectionSize; i++) {
80  edm::RefToBase<reco::Muon> mu = muonCollectionHandle->refAt(i);
81  std::unique_ptr<reco::Muon> newmu{mu->clone()};
82 
83  if (mu->innerTrack().isNonnull()) {
84  reco::TrackRef newTrackRef = findNewRef(mu->innerTrack(), newTrackCollection);
85  /* printf(" %6.2f %+6.2f %+6.2f --> ",mu->innerTrack()->pt (), mu->innerTrack()->eta(), mu->innerTrack()->phi());
86  if(newTrackRef.isNonnull()){
87  printf(" %6.2f %+6.2f %+6.2f\n",newTrackRef->pt (), newTrackRef->eta(), newTrackRef->phi());
88  }else{
89  printf("\n");
90  }
91 */
92  newmu->setInnerTrack(newTrackRef);
93  }
94 
95  newmuons->push_back(*newmu);
96  }
97 
98  ev.put(std::move(newmuons));
99 }
100 
102  reco::TrackRef const& oldTrackRef, edm::Handle<reco::TrackCollection> const& newTrackCollection) const {
103  float dRMin = 1000;
104  int found = -1;
105  for (unsigned int i = 0; i < newTrackCollection->size(); i++) {
107  if (newTrackRef.isNull())
108  continue;
109 
110  if (fabs((1.0 / newTrackRef->pt()) - (1.0 / oldTrackRef->pt())) > maxInvPtDiff)
111  continue;
112  float dR = deltaR(newTrackRef->momentum(), oldTrackRef->momentum());
113  if (dR <= minDR && dR < dRMin) {
114  dRMin = dR;
115  found = i;
116  }
117  }
118 
119  if (found >= 0) {
121  } else {
122  return reco::TrackRef();
123  }
124 }
125 
edm::StreamID
Definition: StreamID.h:30
MuonAlignmentFromReference_cff.newmuons
newmuons
Definition: MuonAlignmentFromReference_cff.py:26
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
Muon.h
MessageLogger.h
UpdatedMuonInnerTrackRef::muonToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition: Skim_UpdatedMuonInnerTrackRef.cc:29
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
HLT_FULL_cff.dRMin
dRMin
Definition: HLT_FULL_cff.py:8730
UpdatedMuonInnerTrackRef::minDR
double minDR
Definition: Skim_UpdatedMuonInnerTrackRef.cc:34
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle< reco::TrackCollection >
edm::Ref< TrackCollection >
MakerMacros.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
UpdatedMuonInnerTrackRef::findNewRef
reco::TrackRef findNewRef(reco::TrackRef const &oldTrackRef, edm::Handle< reco::TrackCollection > const &newTrackCollection) const
Definition: Skim_UpdatedMuonInnerTrackRef.cc:101
UpdatedMuonInnerTrackRef::maxInvPtDiff
double maxInvPtDiff
Definition: Skim_UpdatedMuonInnerTrackRef.cc:33
UpdatedMuonInnerTrackRef::oldTrackToken_
edm::EDGetTokenT< reco::TrackCollection > oldTrackToken_
Definition: Skim_UpdatedMuonInnerTrackRef.cc:30
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
edm::global::EDProducer
Definition: EDProducer.h:32
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
DeltaR.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
UpdatedMuonInnerTrackRef
Definition: Skim_UpdatedMuonInnerTrackRef.cc:19
UpdatedMuonInnerTrackRef::newTrackToken_
edm::EDGetTokenT< reco::TrackCollection > newTrackToken_
Definition: Skim_UpdatedMuonInnerTrackRef.cc:31
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
UpdatedMuonInnerTrackRef::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: Skim_UpdatedMuonInnerTrackRef.cc:56
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
ConversionTrackRefFix_cfi.newTrackCollection
newTrackCollection
Definition: ConversionTrackRefFix_cfi.py:6
edm::RefToBase
Definition: AssociativeIterator.h:54
View.h
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
EDProducer.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
UpdatedMuonInnerTrackRef::UpdatedMuonInnerTrackRef
UpdatedMuonInnerTrackRef(const edm::ParameterSet &)
Definition: Skim_UpdatedMuonInnerTrackRef.cc:38
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ElectronSeedTrackRefFix_cfi.oldTrackCollection
oldTrackCollection
Definition: ElectronSeedTrackRefFix_cfi.py:7