CMS 3D CMS Logo

ZMuMuUserData.cc
Go to the documentation of this file.
10 
16 
20 
21 #include <vector>
22 
23 using namespace edm;
24 using namespace std;
25 using namespace reco;
26 using namespace isodeposit;
27 //using namespace pat;
28 
30 public:
33 
34 private:
35  void produce(edm::Event &, const edm::EventSetup &) override;
36 
41  double alpha_, beta_;
42  string hltPath_;
43  int counter;
44 };
45 
47  : srcToken_(consumes<std::vector<reco::CompositeCandidate> >(cfg.getParameter<InputTag>("src"))),
48  beamSpotToken_(consumes<BeamSpot>(cfg.getParameter<InputTag>("beamSpot"))),
49  primaryVerticesToken_(consumes<VertexCollection>(cfg.getParameter<InputTag>("primaryVertices"))),
50  zGenParticlesMatchToken_(consumes<GenParticleMatch>(cfg.getParameter<InputTag>("zGenParticlesMatch"))),
51  alpha_(cfg.getParameter<double>("alpha")),
52  beta_(cfg.getParameter<double>("beta")),
53  hltPath_(cfg.getParameter<std::string>("hltPath")) {
54  produces<vector<pat::CompositeCandidate> >();
55 }
56 
59  evt.getByToken(srcToken_, dimuons);
60 
61  Handle<BeamSpot> beamSpotHandle;
62  evt.getByToken(beamSpotToken_, beamSpotHandle);
63 
64  Handle<VertexCollection> primaryVertices; // Collection of primary Vertices
65  evt.getByToken(primaryVerticesToken_, primaryVertices);
66 
67  bool isMCMatchTrue = false;
68 
70  if (evt.getByToken(zGenParticlesMatchToken_, zGenParticlesMatch)) {
71  isMCMatchTrue = true;
72  }
73 
74  //cout<<"isMCMatchTrue"<<isMCMatchTrue <<endl;
75  unique_ptr<vector<pat::CompositeCandidate> > dimuonColl(new vector<pat::CompositeCandidate>());
76 
77  for (unsigned int i = 0; i < dimuons->size(); ++i) {
78  const CompositeCandidate &z = (*dimuons)[i];
79  //CandidateBaseRef zRef = dimuons ->refAt(i);
81  pat::CompositeCandidate dimuon(z);
82 
83  float trueMass, truePt, trueEta, truePhi, trueY;
84  if (isMCMatchTrue) {
85  GenParticleRef trueZRef = (*zGenParticlesMatch)[zRef];
86  //CandidateRef trueZRef = trueZIter->val;
87  if (trueZRef.isNonnull()) {
88  const Candidate &z = *trueZRef;
89  trueMass = z.mass();
90  truePt = z.pt();
91  trueEta = z.eta();
92  truePhi = z.phi();
93  trueY = z.rapidity();
94  } else {
95  trueMass = -100;
96  truePt = -100;
97  trueEta = -100;
98  truePhi = -100;
99  trueY = -100;
100  }
101 
102  dimuon.addUserFloat("TrueMass", trueMass);
103  dimuon.addUserFloat("TruePt", truePt);
104  dimuon.addUserFloat("TrueEta", trueEta);
105  dimuon.addUserFloat("TruePhi", truePhi);
106  dimuon.addUserFloat("TrueY", trueY);
107  }
108  const Candidate *dau1 = z.daughter(0);
109  const Candidate *dau2 = z.daughter(1);
110  const pat::Muon &mu1 = dynamic_cast<const pat::Muon &>(*dau1->masterClone());
111  const pat::Muon &mu2 = dynamic_cast<const pat::Muon &>(*dau2->masterClone());
112 
113  /*cout<<"mu1 is null? "<<mu1.isMuon()<<endl;
114  cout<<"mu2 is null? "<<mu2.isMuon()<<endl;
115  cout<<"mu1 is global?"<<mu1.isGlobalMuon()<<endl;
116  cout<<"mu2 is global?"<<mu2.isGlobalMuon()<<endl;
117  */
118 
119  if (mu1.isGlobalMuon() == true && mu2.isGlobalMuon() == true) {
120  TrackRef stAloneTrack1;
121  TrackRef stAloneTrack2;
122  Vector momentum;
124  double mu_mass;
125  stAloneTrack1 = dau1->get<TrackRef, reco::StandAloneMuonTag>();
126  stAloneTrack2 = dau2->get<TrackRef, reco::StandAloneMuonTag>();
127  float zDau1SaEta = stAloneTrack1->eta();
128  float zDau2SaEta = stAloneTrack2->eta();
129  float zDau1SaPhi = stAloneTrack1->phi();
130  float zDau2SaPhi = stAloneTrack2->phi();
131  float zDau1SaPt, zDau2SaPt;
132  if (counter % 2 == 0) {
133  momentum = stAloneTrack1->momentum();
134  p4_1 = dau2->polarP4();
135  mu_mass = dau1->mass();
137  zDau1SaPt = stAloneTrack1->pt();
138  zDau2SaPt = -stAloneTrack2->pt();
139  } else {
140  momentum = stAloneTrack2->momentum();
141  p4_1 = dau1->polarP4();
142  mu_mass = dau2->mass();
144  zDau1SaPt = -stAloneTrack1->pt();
145  zDau2SaPt = stAloneTrack2->pt();
146  }
147 
148  Candidate::PolarLorentzVector p4_2(momentum.rho(), momentum.eta(), momentum.phi(), mu_mass);
149  double mass = (p4_1 + p4_2).mass();
150  float zMassSa = mass;
151  //cout<<"zMassSa "<<zMassSa;
152  dimuon.addUserFloat("MassSa", zMassSa);
153  dimuon.addUserFloat("Dau1SaPt", zDau1SaPt);
154  dimuon.addUserFloat("Dau2SaPt", zDau2SaPt);
155  dimuon.addUserFloat("Dau1SaPhi", zDau1SaPhi);
156  dimuon.addUserFloat("Dau2SaPhi", zDau2SaPhi);
157  dimuon.addUserFloat("Dau1SaEta", zDau1SaEta);
158  dimuon.addUserFloat("Dau2SaEta", zDau2SaEta);
159  ++counter;
160  }
161  dimuonColl->push_back(dimuon);
162  }
163 
164  evt.put(std::move(dimuonColl));
165 }
166 
168 
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
virtual const PolarLorentzVector & polarP4() const =0
four-momentum Lorentz vector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
stand alone muon component tag
Definition: RecoCandidate.h:77
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:897
EDGetTokenT< BeamSpot > beamSpotToken_
EDGetTokenT< VertexCollection > primaryVerticesToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ZMuMuUserData(const edm::ParameterSet &)
bool isGlobalMuon() const override
Definition: Muon.h:298
void produce(edm::Event &, const edm::EventSetup &) override
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual const CandidateBaseRef & masterClone() const =0
EDGetTokenT< GenParticleMatch > zGenParticlesMatchToken_
virtual double eta() const =0
momentum pseudorapidity
virtual double pt() const =0
transverse momentum
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
virtual double mass() const =0
mass
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
EDGetTokenT< std::vector< reco::CompositeCandidate > > srcToken_
virtual double rapidity() const =0
rapidity
fixed size matrix
HLT enums.
T get() const
get a component
Definition: Candidate.h:222
virtual double phi() const =0
momentum azimuthal angle
Analysis-level muon class.
Definition: Muon.h:51
def move(src, dest)
Definition: eostools.py:511
math::XYZVector Vector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39