CMS 3D CMS Logo

ZMuMuOneTrackUserData.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 private:
34  void produce( edm::Event &, const edm::EventSetup & ) override;
35 
40  double alpha_, beta_;
41  string hltPath_;
42  int counter;
43 
44 
45 };
46 
47 
48 
50  srcToken_(consumes<std::vector<reco::CompositeCandidate> > ( cfg.getParameter<InputTag>( "src" ) ) ),
51  beamSpotToken_(consumes<BeamSpot> (cfg.getParameter<InputTag>( "beamSpot" ) ) ),
52  primaryVerticesToken_(consumes<VertexCollection> (cfg.getParameter<InputTag>( "primaryVertices" ) ) ),
53  zGenParticlesMatchToken_(consumes<GenParticleMatch> (cfg.getParameter<InputTag>( "zGenParticlesMatch" ) ) ),
54  alpha_(cfg.getParameter<double>("alpha") ),
55  beta_(cfg.getParameter<double>("beta") ),
56  hltPath_(cfg.getParameter<std::string >("hltPath") ){
57  produces<vector<pat::CompositeCandidate> >();
58 }
59 
62  evt.getByToken(srcToken_,dimuons);
63 
64  Handle<BeamSpot> beamSpotHandle;
65  if (!evt.getByToken(beamSpotToken_, beamSpotHandle)) {
66  std::cout << ">>> No beam spot found !!!"<<std::endl;
67  }
68 
69  Handle<VertexCollection> primaryVertices; // Collection of primary Vertices
70  if (!evt.getByToken(primaryVerticesToken_, primaryVertices)){
71  std::cout << ">>> No primary vertices found !!!"<<std::endl;
72  }
73 
74  bool isMCMatchTrue=false;
75 
76  Handle<GenParticleMatch> zGenParticlesMatch;
77  if(evt.getByToken( zGenParticlesMatchToken_, zGenParticlesMatch )){
78  isMCMatchTrue=true;
79  }
80 
81  //cout<<"isMCMatchTrue"<<isMCMatchTrue <<endl;
82  unique_ptr<vector<pat::CompositeCandidate> > dimuonColl( new vector<pat::CompositeCandidate> () );
83 
84 
85  for (unsigned int i = 0; i< dimuons->size();++i){
86  const CompositeCandidate & z = (*dimuons)[i];
87  //CandidateBaseRef zRef = dimuons ->refAt(i);
89  pat::CompositeCandidate dimuon(z);
90 
91  float trueMass,truePt,trueEta,truePhi,trueY;
92  if (isMCMatchTrue){
93  GenParticleRef trueZRef = (*zGenParticlesMatch)[zRef];
94  //CandidateRef trueZRef = trueZIter->val;
95  if( trueZRef.isNonnull() ) {
96  const Candidate & z = * trueZRef;
97  trueMass = z.mass();
98  truePt = z.pt();
99  trueEta = z.eta();
100  truePhi = z.phi();
101  trueY = z.rapidity();
102  } else {
103  trueMass = -100;
104  truePt = -100;
105  trueEta = -100;
106  truePhi = -100;
107  trueY = -100;
108  }
109 
110  dimuon.addUserFloat("TrueMass",trueMass);
111  dimuon.addUserFloat("TruePt",truePt);
112  dimuon.addUserFloat("TrueEta",trueEta);
113  dimuon.addUserFloat("TruePhi",truePhi);
114  dimuon.addUserFloat("TrueY",trueY);
115 
116  }
117 
118  dimuonColl->push_back(dimuon);
119 
120  }
121 
122  evt.put(std::move(dimuonColl));
123 }
124 
126 
128 
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
EDGetTokenT< GenParticleMatch > zGenParticlesMatchToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
ZMuMuUserDataOneTrack(const edm::ParameterSet &)
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
EDGetTokenT< VertexCollection > primaryVerticesToken_
EDGetTokenT< BeamSpot > beamSpotToken_
EDGetTokenT< std::vector< reco::CompositeCandidate > > srcToken_
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:30
virtual double mass() const =0
mass
virtual double rapidity() const =0
rapidity
fixed size matrix
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
virtual double phi() const =0
momentum azimuthal angle
def move(src, dest)
Definition: eostools.py:510