CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RazorVarProducer.cc
Go to the documentation of this file.
2 
4 
7 
10 
13 
15 
17 
18 #include "TVector3.h"
19 
20 #include <memory>
21 #include <vector>
22 
23 //
24 // constructors and destructor
25 //
27  inputTag_ (iConfig.getParameter<edm::InputTag>("inputTag")),
28  inputMetTag_ (iConfig.getParameter<edm::InputTag>("inputMetTag")){
29 
30  produces<std::vector<double> >();
31 
32  LogDebug("") << "Inputs: "
33  << inputTag_.encode() << " "
34  << inputMetTag_.encode() << ".";
35 }
36 
38 {
39 }
40 
41 // ------------ method called to produce the data ------------
42 void
44 {
45  using namespace std;
46  using namespace edm;
47  using namespace reco;
48 
49 
50  // get hold of collection of objects
52  iEvent.getByLabel (inputTag_,hemispheres);
53 
54  // get hold of the MET Collection
56  iEvent.getByLabel(inputMetTag_,inputMet);
57 
58  std::auto_ptr<std::vector<double> > result(new std::vector<double>);
59  // check the the input collections are available
60  if (hemispheres.isValid() && inputMet.isValid() && hemispheres->size() > 1){
61 
62  TLorentzVector ja(hemispheres->at(0).x(),hemispheres->at(0).y(),hemispheres->at(0).z(),hemispheres->at(0).t());
63  TLorentzVector jb(hemispheres->at(1).x(),hemispheres->at(1).y(),hemispheres->at(1).z(),hemispheres->at(1).t());
64 
65  std::vector<math::XYZTLorentzVector> muonVec;
66  const double MR = CalcMR(ja,jb);
67  const double R = CalcR(MR,ja,jb,inputMet,muonVec);
68  result->push_back(MR);
69  result->push_back(R);
70 
71  }
72  iEvent.put(result);
73 }
74 
75 double
76 RazorVarProducer::CalcMR(TLorentzVector ja, TLorentzVector jb){
77  if(ja.Pt()<=0.1) return -1;
78 
79  ja.SetPtEtaPhiM(ja.Pt(),ja.Eta(),ja.Phi(),0.0);
80  jb.SetPtEtaPhiM(jb.Pt(),jb.Eta(),jb.Phi(),0.0);
81 
82  if(ja.Pt() > jb.Pt()){
83  TLorentzVector temp = ja;
84  ja = jb;
85  jb = temp;
86  }
87 
88  double A = ja.P();
89  double B = jb.P();
90  double az = ja.Pz();
91  double bz = jb.Pz();
92  TVector3 jaT, jbT;
93  jaT.SetXYZ(ja.Px(),ja.Py(),0.0);
94  jbT.SetXYZ(jb.Px(),jb.Py(),0.0);
95  double ATBT = (jaT+jbT).Mag2();
96 
97  double MR = sqrt((A+B)*(A+B)-(az+bz)*(az+bz)-
98  (jbT.Dot(jbT)-jaT.Dot(jaT))*(jbT.Dot(jbT)-jaT.Dot(jaT))/(jaT+jbT).Mag2());
99 
100  double mybeta = (jbT.Dot(jbT)-jaT.Dot(jaT))/
101  sqrt(ATBT*((A+B)*(A+B)-(az+bz)*(az+bz)));
102 
103  double mygamma = 1./sqrt(1.-mybeta*mybeta);
104 
105  //use gamma times MRstar
106  return MR*mygamma;
107 }
108 
109 double
110 RazorVarProducer::CalcR(double MR, TLorentzVector ja, TLorentzVector jb, edm::Handle<reco::CaloMETCollection> inputMet, std::vector<math::XYZTLorentzVector> muons){
111  //now we can calculate MTR
112  TVector3 met;
113  met.SetPtEtaPhi((inputMet->front()).pt(),0.0,(inputMet->front()).phi());
114 
115  std::vector<math::XYZTLorentzVector>::const_iterator muonIt;
116  for(muonIt = muons.begin(); muonIt!=muons.end(); muonIt++){
117  TVector3 tmp;
118  tmp.SetPtEtaPhi(muonIt->pt(),0,muonIt->phi());
119  met-=tmp;
120  }
121 
122  double MTR = sqrt(0.5*(met.Mag()*(ja.Pt()+jb.Pt()) - met.Dot(ja.Vect()+jb.Vect())));
123 
124  //filter events
125  return float(MTR)/float(MR); //R
126 
127 }
128 
#define LogDebug(id)
RazorVarProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double CalcR(double MR, TLorentzVector ja, TLorentzVector jb, edm::Handle< reco::CaloMETCollection > met, std::vector< math::XYZTLorentzVector > muons)
double CalcMR(TLorentzVector ja, TLorentzVector jb)
std::string encode() const
Definition: InputTag.cc:164
edm::InputTag inputMetTag_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple muons
Definition: patZpeak.py:38
edm::InputTag inputTag_
Definition: DDAxes.h:10