CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
36  InputTag src_,beamSpot_, primaryVertices_, zGenParticlesMatch_;
37  double alpha_, beta_;
38  string hltPath_;
39  int counter;
40 
41 
42 };
43 
44 
45 
47  src_( cfg.getParameter<InputTag>( "src" ) ),
48  beamSpot_(cfg.getParameter<InputTag>( "beamSpot" ) ),
49  primaryVertices_(cfg.getParameter<InputTag>( "primaryVertices" ) ),
50  zGenParticlesMatch_(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.getByLabel(src_,dimuons);
60 
61  Handle<BeamSpot> beamSpotHandle;
62  if (!evt.getByLabel(beamSpot_, beamSpotHandle)) {
63  std::cout << ">>> No beam spot found !!!"<<std::endl;
64  }
65 
66  Handle<VertexCollection> primaryVertices; // Collection of primary Vertices
67  if (!evt.getByLabel(primaryVertices_, primaryVertices)){
68  std::cout << ">>> No primary vertices found !!!"<<std::endl;
69  }
70 
71  bool isMCMatchTrue=false;
72 
73  Handle<GenParticleMatch> zGenParticlesMatch;
74  if(evt.getByLabel( zGenParticlesMatch_, zGenParticlesMatch )){
75  isMCMatchTrue=true;
76  }
77 
78  //cout<<"isMCMatchTrue"<<isMCMatchTrue <<endl;
79  auto_ptr<vector<pat::CompositeCandidate> > dimuonColl( new vector<pat::CompositeCandidate> () );
80 
81 
82  for (unsigned int i = 0; i< dimuons->size();++i){
83  const CompositeCandidate & z = (*dimuons)[i];
84  //CandidateBaseRef zRef = dimuons ->refAt(i);
86  pat::CompositeCandidate dimuon(z);
87 
88  float trueMass,truePt,trueEta,truePhi,trueY;
89  if (isMCMatchTrue){
90  GenParticleRef trueZRef = (*zGenParticlesMatch)[zRef];
91  //CandidateRef trueZRef = trueZIter->val;
92  if( trueZRef.isNonnull() ) {
93  const Candidate & z = * trueZRef;
94  trueMass = z.mass();
95  truePt = z.pt();
96  trueEta = z.eta();
97  truePhi = z.phi();
98  trueY = z.rapidity();
99  } else {
100  trueMass = -100;
101  truePt = -100;
102  trueEta = -100;
103  truePhi = -100;
104  trueY = -100;
105  }
106 
107  dimuon.addUserFloat("TrueMass",trueMass);
108  dimuon.addUserFloat("TruePt",truePt);
109  dimuon.addUserFloat("TrueEta",trueEta);
110  dimuon.addUserFloat("TruePhi",truePhi);
111  dimuon.addUserFloat("TrueY",trueY);
112 
113  }
114 
115  dimuonColl->push_back(dimuon);
116 
117  }
118 
119  evt.put( dimuonColl);
120 }
121 
123 
125 
Analysis-level particle class.
int i
Definition: DBlmapReader.cc:9
virtual float mass() const =0
mass
virtual float eta() const =0
momentum pseudorapidity
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual float phi() const =0
momentum azimuthal angle
ZMuMuUserDataOneTrack(const edm::ParameterSet &)
virtual double rapidity() const =0
rapidity
float float float z
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual float pt() const =0
transverse momentum
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
void addUserFloat(const std::string &label, float data)
Set user-defined float.
Definition: PATObject.h:761
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
tuple cout
Definition: gather_cfg.py:121
void produce(edm::Event &, const edm::EventSetup &) override