CMS 3D CMS Logo

ZMuMuMuonUserData.cc
Go to the documentation of this file.
9 
15 
19 
20 #include <vector>
21 
22 using namespace edm;
23 using namespace std;
24 using namespace reco;
25 using namespace isodeposit;
26 //using namespace pat;
27 
29 public:
31 private:
32  void produce( edm::Event &, const edm::EventSetup & ) override;
33 
37  double alpha_, beta_;
38  double ptThreshold_, etEcalThreshold_, etHcalThreshold_ ,dRVetoTrk_, dRTrk_, dREcal_ , dRHcal_;
39  string hltPath_;
40  template<typename T>
41  vector<double> isolation(const T & t, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal, double alpha, double beta);
42 };
43 
44 template<typename T>
45 vector<double> ZMuMuMuonUserData::isolation(const T & t, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal, double alpha, double beta) {
46 
47  vector<double> iso;
48  const pat::IsoDeposit * trkIso = t.isoDeposit(pat::TrackIso);
49  const pat::IsoDeposit * ecalIso = t.isoDeposit(pat::EcalIso);
50  const pat::IsoDeposit * hcalIso = t.isoDeposit(pat::HcalIso);
51 
52  Direction dir = Direction(t.eta(), t.phi());
53 
55  vetosTrk.push_back(new ConeVeto( dir, dRVetoTrk ));
56  vetosTrk.push_back(new ThresholdVeto( ptThreshold ));
57 
58  pat::IsoDeposit::AbsVetos vetosEcal;
59  vetosEcal.push_back(new ConeVeto( dir, 0.));
60  vetosEcal.push_back(new ThresholdVeto( etEcalThreshold ));
61 
62  pat::IsoDeposit::AbsVetos vetosHcal;
63  vetosHcal.push_back(new ConeVeto( dir, 0. ));
64  vetosHcal.push_back(new ThresholdVeto( etHcalThreshold ));
65 
66  double isovalueTrk = (trkIso->sumWithin(dRTrk,vetosTrk));
67  double isovalueEcal = (ecalIso->sumWithin(dREcal,vetosEcal));
68  double isovalueHcal = (hcalIso->sumWithin(dRHcal,vetosHcal));
69 
70  iso.push_back(isovalueTrk);
71  //cout<<"isoTrk"<<isovalueTrk<<" "<<t.trackIso()<<endl;
72  iso.push_back(isovalueEcal);
73  //cout<<"isoEcal"<<isovalueEcal<<" "<<t.ecalIso()<<endl;
74  iso.push_back(isovalueHcal);
75  //cout<<"isoHcal"<<isovalueHcal<<" "<<t.hcalIso()<<endl;
76  //double isovalueTrk = t.trackIso();
77  //double isovalueEcal = t.ecalIso();
78  //double isovalueHcal = t.hcalIso();
79 
80  //double iso = isovalueTrk + isovalueEcal + isovalueHcal;
81  double combIso = alpha*( ((1+beta)/2*isovalueEcal) + ((1-beta)/2*isovalueHcal) ) + ((1-alpha)*isovalueTrk);
82  iso.push_back(combIso);
83  //cout<<"combIso"<<iso[3]<<endl;
84 
85  double relIso = combIso /= t.pt();
86  iso.push_back(relIso);
87  //cout<<"relIso"<<iso[4]<<endl;
88  return iso;
89 }
90 
92  srcToken_(consumes<vector<pat::Muon> > ( cfg.getParameter<InputTag>( "src" ) ) ),
93  beamSpotToken_(consumes<BeamSpot> (cfg.getParameter<InputTag>( "beamSpot" ) ) ),
94  primaryVerticesToken_(consumes<VertexCollection> (cfg.getParameter<InputTag>( "primaryVertices" ) ) ),
95  alpha_(cfg.getParameter<double>("alpha") ),
96  beta_(cfg.getParameter<double>("beta") ),
97  ptThreshold_(cfg.getParameter<double >("ptThreshold") ),
98  etEcalThreshold_(cfg.getParameter<double >("etEcalThreshold") ),
99  etHcalThreshold_(cfg.getParameter<double >("etHcalThreshold") ),
100  dRVetoTrk_(cfg.getParameter<double >("dRVetoTrk") ),
101  dRTrk_(cfg.getParameter<double >("dRTrk") ),
102  dREcal_(cfg.getParameter<double >("dREcal") ),
103  dRHcal_(cfg.getParameter<double >("dRHcal") ),
104  hltPath_(cfg.getParameter<std::string >("hltPath") ){
105  produces<std::vector<pat::Muon> >();
106 }
107 
110  evt.getByToken(srcToken_,muons);
111 
112  Handle<BeamSpot> beamSpotHandle;
113  evt.getByToken(beamSpotToken_, beamSpotHandle);
114 
115  Handle<VertexCollection> primaryVertices; // Collection of primary Vertices
116  evt.getByToken(primaryVerticesToken_, primaryVertices);
117 
118  unique_ptr<vector<pat::Muon> > muonColl( new vector<pat::Muon> (*muons) );
119  for (unsigned int i = 0; i< muonColl->size();++i){
120  pat::Muon & m = (*muonColl)[i];
121  //pat::Muon *mu = new pat::Muon(m);
123  m.setIsolation(pat::User1Iso, iso[0]);
124  //cout<<"muon User1Iso "<<iso[0]<<endl;
125  m.setIsolation(pat::User2Iso, iso[1]);
126  //cout<<"iso2 "<<iso[1]<<endl;
127  m.setIsolation(pat::User3Iso, iso[2]);
128  //cout<<"iso3 "<<iso[2]<<endl;
129  m.setIsolation(pat::User4Iso, iso[3]);
130  //cout<<"iso4 "<<iso[3]<<endl;
131  m.setIsolation(pat::User5Iso, iso[4]);
132  //cout<<"iso5 "<<iso[4]<<endl;
133  float zDauMuEnergyEm = m.calEnergy().em;
134  float zDauMuEnergyHad = m.calEnergy().had;
135  TrackRef muGlbRef = m.globalTrack();
136  TrackRef muTrkRef = m.innerTrack();
137  TrackRef muSaRef = m.outerTrack();
138  float zDaudxyFromBS = -1;
139  float zDaudzFromBS = -1;
140  float zDaudxyFromPV = -1;
141  float zDaudzFromPV = -1;
142  int zDauNofMuChambers = m.numberOfChambers();
143  int zDauNofMuMatches = m.numberOfMatches();
144  // for the following variables looking at global/trk and sta at the same time
145  float zDauChi2 = -1;
146  float zDauTrkChi2 = -1;
147  float zDauSaChi2 = -1;
148  float zDauNofMuonHits = -1;
149  float zDauSaNofMuonHits = -1;
150  float zDauNofStripHits = -1;
151  float zDauTrkNofStripHits = -1;
152  float zDauNofPixelHits = -1;
153  float zDauTrkNofPixelHits = -1;
154 
155 
156 
157 
158  if (muGlbRef.isNonnull() && m.isGlobalMuon() == true){
159  zDaudxyFromBS = muGlbRef->dxy(beamSpotHandle->position());
160  zDaudzFromBS = muGlbRef->dz(beamSpotHandle->position());
161  zDaudxyFromPV = muGlbRef->dxy(primaryVertices->begin()->position() );
162  zDaudzFromPV = muGlbRef->dz(primaryVertices->begin()->position() );
163  zDauChi2 = muGlbRef->normalizedChi2();
164  zDauTrkChi2 = muTrkRef->normalizedChi2();
165  zDauSaChi2 = muSaRef->normalizedChi2();
166  zDauNofMuonHits = muGlbRef->hitPattern().numberOfValidMuonHits();
167  zDauSaNofMuonHits = muSaRef->hitPattern().numberOfValidMuonHits();
168  zDauNofStripHits = muGlbRef->hitPattern().numberOfValidStripHits();
169  zDauTrkNofStripHits = muTrkRef->hitPattern().numberOfValidStripHits();
170  zDauNofPixelHits = muGlbRef->hitPattern().numberOfValidPixelHits();
171  zDauTrkNofPixelHits = muTrkRef->hitPattern().numberOfValidPixelHits();
172  }
173  else if (muSaRef.isNonnull() && m.isStandAloneMuon() == true){
174  zDaudxyFromBS = muSaRef->dxy(beamSpotHandle->position());
175  zDaudzFromBS = muSaRef->dz(beamSpotHandle->position());
176  zDaudxyFromPV = muSaRef->dxy(primaryVertices->begin()->position() );
177  zDaudzFromPV = muSaRef->dz(primaryVertices->begin()->position() );
178  zDauSaChi2 = muSaRef->normalizedChi2();
179  zDauSaNofMuonHits = muSaRef->hitPattern().numberOfValidMuonHits();
180 
181  }
182  else if (muTrkRef.isNonnull() && m.isTrackerMuon() == true){
183  zDaudxyFromBS = muTrkRef->dxy(beamSpotHandle->position());
184  zDaudzFromBS = muTrkRef->dz(beamSpotHandle->position());
185  zDaudxyFromPV = muTrkRef->dxy(primaryVertices->begin()->position() );
186  zDaudzFromPV = muTrkRef->dz(primaryVertices->begin()->position() );
187  zDauTrkChi2 = muTrkRef->normalizedChi2();
188  zDauTrkNofStripHits = muTrkRef->hitPattern().numberOfValidStripHits();
189  zDauTrkNofPixelHits = muTrkRef->hitPattern().numberOfValidPixelHits();
190 
191  }
192 
194  float muHLTBit;
195  int dimTrig = muHLTMatches.size();
196  if(dimTrig !=0 ){
197  muHLTBit = 1;
198  } else {
199  muHLTBit = 0;
200  }
201  m.addUserFloat("zDau_dxyFromBS", zDaudxyFromBS);
202  m.addUserFloat("zDau_dzFromBS", zDaudzFromBS);
203  m.addUserFloat("zDau_dxyFromPV", zDaudxyFromPV);
204  m.addUserFloat("zDau_dzFromPV", zDaudzFromPV);
205  m.addUserFloat("zDau_HLTBit",muHLTBit);
206  m.addUserFloat("zDau_dzFromPV", zDaudzFromPV);
207  m.addUserFloat("zDau_Chi2", zDauChi2);
208  m.addUserFloat("zDau_TrkChi2", zDauTrkChi2);
209  m.addUserFloat("zDau_SaChi2", zDauSaChi2);
210  m.addUserFloat("zDau_NofMuonHits" , zDauNofMuonHits );
211  m.addUserFloat("zDau_SaNofMuonHits" , zDauSaNofMuonHits );
212  m.addUserFloat("zDau_NofStripHits" , zDauNofStripHits );
213  m.addUserFloat("zDau_TrkNofStripHits" , zDauTrkNofStripHits );
214  m.addUserFloat("zDau_NofPixelHits" , zDauNofPixelHits );
215  m.addUserFloat("zDau_TrkNofPixelHits" , zDauTrkNofPixelHits );
216  m.addUserFloat("zDau_NofMuChambers" , zDauNofMuChambers );
217  m.addUserFloat("zDau_NofMuMatches" , zDauNofMuMatches );
218  m.addUserFloat("zDau_MuEnergyEm", zDauMuEnergyEm );
219  m.addUserFloat("zDau_MuEnergyHad", zDauMuEnergyHad );
220  }
221 
222  evt.put(std::move(muonColl));
223 }
224 
226 
228 
EDGetTokenT< VertexCollection > primaryVerticesToken_
float alpha
Definition: AMPTWrapper.h:95
vector< double > isolation(const T &t, double ptThreshold, double etEcalThreshold, double etHcalThreshold, double dRVetoTrk, double dRTrk, double dREcal, double dRHcal, double alpha, double beta)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:99
bool isStandAloneMuon() const override
Definition: Muon.h:293
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:813
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:138
Definition: HeavyIon.h:7
bool isTrackerMuon() const override
Definition: Muon.h:292
EDGetTokenT< vector< pat::Muon > > srcToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
reco::TrackRef outerTrack() const override
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.h:77
Definition: Muon.py:1
bool isGlobalMuon() const override
Definition: Muon.h:291
EDGetTokenT< BeamSpot > beamSpotToken_
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:612
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:111
primaryVertices
Definition: jets_cff.py:26
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
int numberOfChambers() const
Definition: Muon.h:244
ZMuMuMuonUserData(const edm::ParameterSet &)
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
fixed size matrix
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
dbl *** dir
Definition: mlp_gen.cc:35
isodeposit::AbsVetos AbsVetos
Definition: IsoDeposit.h:51
long double T
Analysis-level muon class.
Definition: Muon.h:50
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &, const edm::EventSetup &) override