CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Skim_UpdatedMuonInnerTrackRef.cc
Go to the documentation of this file.
1 #include <memory>
6 
13 
15 
16 //
17 // class declaration
18 //
20  public:
23 
24  private:
25  virtual void beginJob() override ;
26  virtual void produce(edm::Event&, const edm::EventSetup&) override;
27  virtual void endJob() override ;
28 
30 
34 
35  double maxInvPtDiff;
36  double minDR;
37 };
38 
39 
42 {
43  // What is being produced
44  produces<std::vector<reco::Muon> >();
45 
46  // Input products
47  muonToken_ = consumes<edm::View<reco::Muon> >(pset.getUntrackedParameter<edm::InputTag> ("MuonTag" , edm::InputTag("muons")));
48  oldTrackToken_ = consumes<reco::TrackCollection>(pset.getUntrackedParameter<edm::InputTag> ("OldTrackTag", edm::InputTag("generalTracks")));
49  newTrackToken_ = consumes<reco::TrackCollection>(pset.getUntrackedParameter<edm::InputTag> ("NewTrackTag", edm::InputTag("generalTracksSkim")));
50 
51  // matching criteria products
52  maxInvPtDiff=pset.getUntrackedParameter<double>("maxInvPtDiff", 0.005);
53  minDR=pset.getUntrackedParameter<double>("minDR", 0.1);
54 }
55 
58 }
59 
62 }
63 
66 }
67 
70 {
71  // Muon collection
72  edm::Handle<edm::View<reco::Muon> > muonCollectionHandle;
73  if (!ev.getByToken(muonToken_, muonCollectionHandle)) {
74  edm::LogError("") << ">>> Muon collection does not exist !!!";
75  return;
76  }
77 
78 
79  edm::Handle<reco::TrackCollection> oldTrackCollection;
80  if (!ev.getByToken(oldTrackToken_, oldTrackCollection)) {
81  edm::LogError("") << ">>> Old Track collection does not exist !!!";
82  return;
83  }
84 
85  edm::Handle<reco::TrackCollection> newTrackCollection;
86  if (!ev.getByToken(newTrackToken_, newTrackCollection)) {
87  edm::LogError("") << ">>> New Track collection does not exist !!!";
88  return;
89  }
90 
91  unsigned int muonCollectionSize = muonCollectionHandle->size();
92  std::auto_ptr<reco::MuonCollection> newmuons (new reco::MuonCollection);
93 
94 
95  for (unsigned int i=0; i<muonCollectionSize; i++) {
96  edm::RefToBase<reco::Muon> mu = muonCollectionHandle->refAt(i);
97  reco::Muon* newmu = mu->clone();
98 
99  if(mu->innerTrack().isNonnull()){
100  reco::TrackRef newTrackRef = findNewRef(mu->innerTrack(), newTrackCollection);
101 /* printf(" %6.2f %+6.2f %+6.2f --> ",mu->innerTrack()->pt (), mu->innerTrack()->eta(), mu->innerTrack()->phi());
102  if(newTrackRef.isNonnull()){
103  printf(" %6.2f %+6.2f %+6.2f\n",newTrackRef->pt (), newTrackRef->eta(), newTrackRef->phi());
104  }else{
105  printf("\n");
106  }
107 */
108  newmu->setInnerTrack(newTrackRef);
109  }
110 
111  newmuons->push_back(*newmu);
112  }
113 
114  ev.put(newmuons);
115 }
116 
118  float dRMin=1000; int found = -1;
119  for(unsigned int i=0;i<newTrackCollection->size();i++){
120  reco::TrackRef newTrackRef = reco::TrackRef( newTrackCollection, i );
121  if(newTrackRef.isNull())continue;
122 
123  if( fabs( (1.0/newTrackRef->pt())-(1.0/oldTrackRef->pt())) > maxInvPtDiff) continue;
124  float dR = deltaR(newTrackRef->momentum(), oldTrackRef->momentum());
125  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = i;}
126  }
127 
128  if(found>=0){
129  return reco::TrackRef( newTrackCollection, found );
130  }else{
131  return reco::TrackRef();
132  }
133 }
134 
136 
137 
138 
139 
edm::EDGetTokenT< reco::TrackCollection > newTrackToken_
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::TrackCollection > oldTrackToken_
reco::TrackRef findNewRef(reco::TrackRef oldTrackRef, edm::Handle< reco::TrackCollection > &newTrackCollection)
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool ev
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
UpdatedMuonInnerTrackRef(const edm::ParameterSet &)
const int mu
Definition: Constants.h:22
bool isNull() const
Checks for null.
Definition: Ref.h:249
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:19
Muon * clone() const
create a clone