CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonMaker.cc
Go to the documentation of this file.
2 
5 
6 using namespace std;
7 using namespace reco;
8 using namespace edm;
9 
10 
12 
13  Muon_ = iCollector.consumes<edm::View<reco::Muon> > (iConfig.getParameter<edm::InputTag>("muonsInputTag"));
14  MuonShower_ = iCollector.consumes<edm::ValueMap<reco::MuonShower> > (iConfig.getParameter<edm::InputTag>("muonShower"));
15  thePVCollection_ = iCollector.consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag"));
16  PFCandidateCollection_ = iCollector.consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsInputTag"));
17  BeamSpot_ = iCollector.consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotTag"));
18  MuonCollection_ = iCollector.consumes<reco::MuonCollection> (iConfig.getParameter<edm::InputTag>("muonsInputTag"));
19 
20 }
21 
22 
23 void MuonMaker::SetVars(HWW& hww, const edm::Event& iEvent, const edm::EventSetup& iSetup) {
24 
25  hww.Load_mus_sta_d0();
26  hww.Load_mus_sta_z0corr();
27  hww.Load_mus_sta_p4();
28  hww.Load_mus_gfit_chi2();
29  hww.Load_mus_gfit_ndof();
31  hww.Load_mus_trkKink();
32  hww.Load_mus_type();
33  hww.Load_mus_goodmask();
34  hww.Load_mus_charge();
35  hww.Load_mus_nmatches();
38  hww.Load_mus_p4();
41  hww.Load_mus_pid_PFMuon();
42  hww.Load_mus_e_em();
43  hww.Load_mus_e_had();
44  hww.Load_mus_e_ho();
45  hww.Load_mus_e_emS9();
46  hww.Load_mus_e_hadS9();
47  hww.Load_mus_e_hoS9();
51  hww.Load_mus_iso03_emEt();
54  hww.Load_mus_iso05_emEt();
56  hww.Load_mus_trk_p4();
57  hww.Load_mus_vertex_p4();
58  hww.Load_mus_trkidx();
59  hww.Load_mus_d0();
60  hww.Load_mus_chi2();
61  hww.Load_mus_ndof();
62  hww.Load_mus_validHits();
63  hww.Load_mus_ptErr();
68 
69  bool validToken;
70 
72  // Get Muons //
74 
75  Handle<View<Muon> > muon_h;
76  validToken = iEvent.getByToken( Muon_ , muon_h );
77  if(!validToken) return;
78 
79 
81  // Get Muon Shower Information //
83 
84  Handle<ValueMap<MuonShower> > showerMap;
85  validToken = iEvent.getByToken( MuonShower_ , showerMap );
86  if(!validToken) return;
87 
88 
90  // Get Vertices //
92 
94  validToken = iEvent.getByToken( thePVCollection_ , vertexHandle );
95  if(!validToken) return;
96 
97 
99  // Get PF Candidates //
101 
103  validToken = iEvent.getByToken( PFCandidateCollection_ , pfCand_h );
104  if(!validToken) return;
105 
106 
108  // Beamspot //
110 
111  Handle<reco::BeamSpot> beamspot_h;
112  validToken = iEvent.getByToken(BeamSpot_, beamspot_h);
113  if(!validToken) return;
114  const reco::BeamSpot &beamSpotreco = *(beamspot_h.product());
115  const Point beamSpot = Point(beamSpotreco.x0(), beamSpotreco.y0(), beamSpotreco.z0());
116 
117 
119  // Cosmic Compatibility //
121 
123  validToken = iEvent.getByToken( MuonCollection_, muons );
124  if(!validToken) return;
125 
127  // Muons //
129 
130  unsigned int muonIndex = 0;
131  View<Muon>::const_iterator muons_end = muon_h->end(); // Iterator
132  for ( View<Muon>::const_iterator muon = muon_h->begin(); muon != muons_end; ++muon ) {
133 
134  // References
135  const RefToBase<Muon> muonRef = muon_h->refAt(muonIndex);
136  const TrackRef globalTrack = muon->globalTrack();
137  const TrackRef siTrack = muon->innerTrack();
138  const TrackRef staTrack = muon->outerTrack();
139  const MuonQuality quality = muon->combinedQuality();
140 
141 
143  // STA //
145 
146  hww.mus_sta_d0() .push_back( staTrack.isNonnull() ? staTrack->d0() : -9999. );
147  hww.mus_sta_z0corr() .push_back( staTrack.isNonnull() ? staTrack->dz(beamSpot) : -9999. );
148  hww.mus_sta_p4() .push_back( staTrack.isNonnull() ? LorentzVector( staTrack->px() , staTrack->py() , staTrack->pz() , staTrack->p() ) : LorentzVector(0, 0, 0, 0) );
149 
150 
152  // Global //
154 
155  hww.mus_gfit_chi2() .push_back( globalTrack.isNonnull() ? globalTrack->chi2() : -9999. );
156  hww.mus_gfit_ndof() .push_back( globalTrack.isNonnull() ? globalTrack->ndof() : -9999 );
157  hww.mus_gfit_validSTAHits() .push_back( globalTrack.isNonnull() ? globalTrack->hitPattern().numberOfValidMuonHits() : -9999 );
158 
160  // Muon Quality //
162 
163  hww.mus_trkKink() .push_back( quality.trkKink );
164 
165 
166 
167  // Calculate Overlaps
168  int mus_overlap0 = -1, muInd = -1, mus_nOverlaps = 0;
169  for ( View<Muon>::const_iterator muonJ = muon_h->begin(); muonJ != muons_end; ++muonJ ) {
170  muInd++;
171  if ( muonJ != muon ){
172  if ( muon::overlap( *muon, *muonJ ) ) {
173  if ( mus_overlap0 == -1) mus_overlap0 = muInd;
174  mus_nOverlaps++;
175  }
176  }
177  }
178 
179  // Calculate Muon position at ECAL
180  math::XYZPoint ecal_p( -9999.0, -9999.0, -9999.0 );
181  if( muon->isEnergyValid() ) ecal_p = muon->calEnergy().ecal_position;
182 
183  // Calculate Mask
184  int goodMask = 0;
185  for ( int iG = 0; iG < 24; ++iG ) { //overkill here
186  if( isGoodMuon( *muon, (muon::SelectionType)iG ) ) goodMask |= (1<<iG);
187  }
188 
189 
191  // Muon Quantities //
193 
194  hww.mus_type() .push_back( muon->type() );
195  hww.mus_goodmask() .push_back( goodMask );
196  hww.mus_charge() .push_back( muon->charge() );
197  hww.mus_nmatches() .push_back( muon->isMatchesValid() ? muon->numberOfMatches() : -9999 );
198  hww.mus_caloCompatibility() .push_back( muon->caloCompatibility() );
200  hww.mus_p4() .push_back( LorentzVector( muon->p4() ) );
201  hww.mus_numberOfMatchedStations() .push_back( muon->numberOfMatchedStations() );
202 
203 
205  // Muon Shower Information //
207 
208  const MuonShower muShower = showerMap.isValid() ? (*showerMap)[muonRef] : MuonShower();
209 
210 
212  // ID //
214 
215  bool matchIsValid = muon->isMatchesValid();
216 
217  hww.mus_pid_TMLastStationTight() .push_back( matchIsValid ? muon::isGoodMuon( *muon, muon::TMLastStationTight ) : -9999 );
218  hww.mus_pid_PFMuon() .push_back( muon->isPFMuon() );
219 
221  // Energy //
223 
224  bool energyIsValid = muon->isEnergyValid();
225 
226  hww.mus_e_em() .push_back( energyIsValid ? muon->calEnergy().em : -9999. );
227  hww.mus_e_had() .push_back( energyIsValid ? muon->calEnergy().had : -9999. );
228  hww.mus_e_ho() .push_back( energyIsValid ? muon->calEnergy().ho : -9999. );
229  hww.mus_e_emS9() .push_back( energyIsValid ? muon->calEnergy().emS9 : -9999. );
230  hww.mus_e_hadS9() .push_back( energyIsValid ? muon->calEnergy().hadS9 : -9999. );
231  hww.mus_e_hoS9() .push_back( energyIsValid ? muon->calEnergy().hoS9 : -9999. );
232 
233 
235  // Isolation //
237 
238  hww.mus_iso_ecalvetoDep() .push_back( muon->isEnergyValid() ? muon->isolationR03().emVetoEt : -9999. );
239  hww.mus_iso_hcalvetoDep() .push_back( muon->isEnergyValid() ? muon->isolationR03().hadVetoEt : -9999. );
240  hww.mus_iso03_sumPt() .push_back( muon->isIsolationValid() ? muon->isolationR03().sumPt : -9999. );
241  hww.mus_iso03_emEt() .push_back( muon->isIsolationValid() ? muon->isolationR03().emEt : -9999. );
242  hww.mus_iso03_hadEt() .push_back( muon->isIsolationValid() ? muon->isolationR03().hadEt : -9999. );
243  hww.mus_iso05_sumPt() .push_back( muon->isIsolationValid() ? muon->isolationR05().sumPt : -9999. );
244  hww.mus_iso05_emEt() .push_back( muon->isIsolationValid() ? muon->isolationR05().emEt : -9999. );
245  hww.mus_iso05_hadEt() .push_back( muon->isIsolationValid() ? muon->isolationR05().hadEt : -9999. );
246 
248  // Tracks //
250 
251  hww.mus_trk_p4() .push_back( siTrack.isNonnull() ? LorentzVector( siTrack.get()->px() , siTrack.get()->py() , siTrack.get()->pz() , siTrack.get()->p() ) : LorentzVector( 0.0, 0.0, 0.0, 0.0) );
252  hww.mus_vertex_p4() .push_back( siTrack.isNonnull() ? LorentzVector( siTrack->vx() , siTrack->vy() , siTrack->vz() , 0.0 ) : LorentzVector( -9999.0, -9999.0, -9999.0, -9999.0) );
253  hww.mus_trkidx() .push_back( siTrack.isNonnull() ? static_cast<int>(siTrack.key()) : -9999 );
254  hww.mus_d0() .push_back( siTrack.isNonnull() ? siTrack->d0() : -9999. );
255  hww.mus_chi2() .push_back( siTrack.isNonnull() ? siTrack->chi2() : -9999. );
256  hww.mus_ndof() .push_back( siTrack.isNonnull() ? siTrack->ndof() : -9999. );
257  hww.mus_validHits() .push_back( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -9999 );
258  hww.mus_ptErr() .push_back( siTrack.isNonnull() ? siTrack->ptError() : -9999. );
259 
260 
262  // PF //
264 
265  MuonPFIsolation pfStructR03 = muon->pfIsolationR03();
266 
267  hww.mus_isoR03_pf_ChargedHadronPt() .push_back( pfStructR03.sumChargedHadronPt );
268  hww.mus_isoR03_pf_NeutralHadronEt() .push_back( pfStructR03.sumNeutralHadronEt );
269  hww.mus_isoR03_pf_PhotonEt() .push_back( pfStructR03.sumPhotonEt );
270  hww.mus_isoR03_pf_PUPt() .push_back( pfStructR03.sumPUPt );
271 
272 
273  muonIndex++;
274 
275  } // end loop on muons
276 
277 }
void Load_mus_e_em()
Definition: HWW.cc:1124
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void Load_mus_validHits()
Definition: HWW.cc:1190
T getParameter(std::string const &) const
double z0() const
z coordinate
Definition: BeamSpot.h:68
void Load_mus_trk_p4()
Definition: HWW.cc:1070
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void Load_mus_isoR03_pf_PUPt()
Definition: HWW.cc:1169
std::vector< int > & mus_pid_PFMuon()
Definition: HWW.cc:539
void Load_mus_pid_PFMuon()
Definition: HWW.cc:1196
std::vector< float > & mus_iso05_hadEt()
Definition: HWW.cc:479
std::vector< float > & mus_gfit_chi2()
Definition: HWW.cc:383
void Load_mus_isoR03_pf_ChargedHadronPt()
Definition: HWW.cc:1160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void Load_mus_chi2()
Definition: HWW.cc:1100
void Load_mus_charge()
Definition: HWW.cc:1187
void Load_mus_iso03_sumPt()
Definition: HWW.cc:1136
std::vector< int > & mus_pid_TMLastStationTight()
Definition: HWW.cc:543
void Load_mus_caloCompatibility()
Definition: HWW.cc:1115
void Load_mus_iso03_emEt()
Definition: HWW.cc:1139
std::vector< int > & mus_trkidx()
Definition: HWW.cc:535
std::vector< float > & mus_ptErr()
Definition: HWW.cc:391
void Load_mus_ndof()
Definition: HWW.cc:1103
std::vector< LorentzVector > & mus_p4()
Definition: HWW.cc:367
std::vector< float > & mus_iso03_hadEt()
Definition: HWW.cc:467
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
float trkKink
value of the kink algorithm applied to the inner track stub
Definition: MuonQuality.h:11
std::vector< float > & mus_e_hoS9()
Definition: HWW.cc:451
void Load_mus_isoR03_pf_NeutralHadronEt()
Definition: HWW.cc:1163
std::vector< int > & mus_nmatches()
Definition: HWW.cc:547
float sumPhotonEt
sum pt of PF photons
std::vector< float > & mus_isoR03_pf_ChargedHadronPt()
Definition: HWW.cc:491
std::pair< double, double > Point
Definition: CaloEllipse.h:18
std::vector< float > & mus_iso03_sumPt()
Definition: HWW.cc:459
void Load_mus_sta_z0corr()
Definition: HWW.cc:1157
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< int > & mus_gfit_validSTAHits()
Definition: HWW.cc:515
std::vector< float > & mus_ndof()
Definition: HWW.cc:415
float sumNeutralHadronEt
sum pt of neutral hadrons
void Load_mus_sta_d0()
Definition: HWW.cc:1154
SelectionType
Selector type.
Definition: MuonSelectors.h:17
std::vector< float > & mus_iso_hcalvetoDep()
Definition: HWW.cc:511
std::vector< float > & mus_e_emS9()
Definition: HWW.cc:455
void Load_mus_gfit_ndof()
Definition: HWW.cc:1082
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
void Load_mus_isoR03_pf_PhotonEt()
Definition: HWW.cc:1166
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
int iEvent
Definition: GenABIO.cc:230
void Load_mus_goodmask()
Definition: HWW.cc:1205
void Load_mus_iso05_sumPt()
Definition: HWW.cc:1145
std::vector< LorentzVector > & mus_trk_p4()
Definition: HWW.cc:371
std::vector< int > & mus_validHits()
Definition: HWW.cc:531
void Load_mus_iso05_hadEt()
Definition: HWW.cc:1151
MuonMaker(const edm::ParameterSet &, edm::ConsumesCollector)
Definition: MuonMaker.cc:11
std::vector< float > & mus_isoR03_pf_PhotonEt()
Definition: HWW.cc:499
void Load_mus_e_ho()
Definition: HWW.cc:1121
math::XYZPoint Point
std::vector< int > & mus_charge()
Definition: HWW.cc:527
std::vector< float > & mus_gfit_ndof()
Definition: HWW.cc:387
void Load_mus_iso03_hadEt()
Definition: HWW.cc:1142
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
std::vector< float > & mus_e_hadS9()
Definition: HWW.cc:447
bool isValid() const
Definition: HandleBase.h:76
void Load_mus_d0()
Definition: HWW.cc:1094
void Load_mus_iso_hcalvetoDep()
Definition: HWW.cc:1175
void Load_mus_sta_p4()
Definition: HWW.cc:1076
Definition: HWW.h:11
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
std::vector< float > & mus_iso_ecalvetoDep()
Definition: HWW.cc:507
void Load_mus_iso_ecalvetoDep()
Definition: HWW.cc:1172
void Load_mus_e_hoS9()
Definition: HWW.cc:1130
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
std::vector< float > & mus_e_had()
Definition: HWW.cc:435
std::vector< float > & mus_sta_d0()
Definition: HWW.cc:483
std::vector< float > & mus_trkKink()
Definition: HWW.cc:395
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< float > & mus_segmCompatibility()
Definition: HWW.cc:427
key_type key() const
Accessor for product key.
Definition: Ref.h:266
std::vector< float > & mus_d0()
Definition: HWW.cc:403
void Load_mus_trkKink()
Definition: HWW.cc:1088
void Load_mus_numberOfMatchedStations()
Definition: HWW.cc:1181
T const * product() const
Definition: Handle.h:81
void Load_mus_vertex_p4()
Definition: HWW.cc:1073
std::vector< float > & mus_e_em()
Definition: HWW.cc:443
tuple muons
Definition: patZpeak.py:38
void Load_mus_nmatches()
Definition: HWW.cc:1202
void Load_mus_e_had()
Definition: HWW.cc:1118
std::vector< float > & mus_iso05_sumPt()
Definition: HWW.cc:471
void Load_mus_ptErr()
Definition: HWW.cc:1085
void Load_mus_pid_TMLastStationTight()
Definition: HWW.cc:1199
std::vector< float > & mus_sta_z0corr()
Definition: HWW.cc:487
double y0() const
y coordinate
Definition: BeamSpot.h:66
void Load_mus_trkidx()
Definition: HWW.cc:1193
std::vector< float > & mus_caloCompatibility()
Definition: HWW.cc:431
void Load_mus_type()
Definition: HWW.cc:1208
void Load_mus_e_hadS9()
Definition: HWW.cc:1127
void Load_mus_gfit_validSTAHits()
Definition: HWW.cc:1178
std::vector< float > & mus_e_ho()
Definition: HWW.cc:439
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > XYZTLorentzVectorF
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:22
void Load_mus_gfit_chi2()
Definition: HWW.cc:1079
void Load_mus_iso05_emEt()
Definition: HWW.cc:1148
std::vector< float > & mus_iso05_emEt()
Definition: HWW.cc:475
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
std::vector< LorentzVector > & mus_vertex_p4()
Definition: HWW.cc:375
void Load_mus_segmCompatibility()
Definition: HWW.cc:1112
std::vector< LorentzVector > & mus_sta_p4()
Definition: HWW.cc:379
void Load_mus_p4()
Definition: HWW.cc:1067
std::vector< int > & mus_numberOfMatchedStations()
Definition: HWW.cc:519
std::vector< float > & mus_chi2()
Definition: HWW.cc:411
std::vector< int > & mus_goodmask()
Definition: HWW.cc:551
std::vector< float > & mus_isoR03_pf_PUPt()
Definition: HWW.cc:503
std::vector< float > & mus_isoR03_pf_NeutralHadronEt()
Definition: HWW.cc:495
std::vector< float > & mus_iso03_emEt()
Definition: HWW.cc:463
math::PtEtaPhiELorentzVectorF LorentzVector
void SetVars(HWW &, const edm::Event &, const edm::EventSetup &)
Definition: MuonMaker.cc:23
void Load_mus_e_emS9()
Definition: HWW.cc:1133
std::vector< int > & mus_type()
Definition: HWW.cc:555
double x0() const
x coordinate
Definition: BeamSpot.h:64
float sumChargedHadronPt
sum-pt of charged Hadron