CMS 3D CMS Logo

RazorMonitor.cc
Go to the documentation of this file.
1 // -----------------------------
2 //
3 // Offline DQM for razor triggers. The razor inclusive analysis measures trigger efficiency
4 // in SingleElectron events (orthogonal to analysis), as a 2D function of the razor variables
5 // M_R and R^2. Also monitor dPhi_R, used offline for QCD and/or detector-related MET tail
6 // rejection.
7 // Based on DQMOffline/Trigger/plugins/METMonitor.*
8 //
9 // -----------------------------
10 
12 
14 
16 
17 // -----------------------------
18 // constructors and destructor
19 // -----------------------------
20 
22  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
23  , metToken_ ( consumes<reco::PFMETCollection> (iConfig.getParameter<edm::InputTag>("met") ) )
24  , jetToken_ ( mayConsume<reco::PFJetCollection> (iConfig.getParameter<edm::InputTag>("jets") ) )
25  , rsq_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> > ("rsqBins") )
26  , mr_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> > ("mrBins") )
27  , dphiR_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> > ("dphiRBins") )
28  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
29  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
30  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
31  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
32  , njets_ ( iConfig.getParameter<unsigned int>("njets" ) )
33  , rsqCut_ ( iConfig.getParameter<double>("rsqCut" ) )
34  , mrCut_ ( iConfig.getParameter<double>("mrCut" ) )
35 {
36 
37  theHemispheres_ = consumes<std::vector<math::XYZTLorentzVector> >(iConfig.getParameter<edm::InputTag>("hemispheres"));
38 
39  MR_ME_.numerator = nullptr;
40  MR_ME_.denominator = nullptr;
41  Rsq_ME_.numerator = nullptr;
42  Rsq_ME_.denominator = nullptr;
43  dPhiR_ME_.numerator = nullptr;
44  dPhiR_ME_.denominator = nullptr;
45 
46  MRVsRsq_ME_.numerator = nullptr;
47  MRVsRsq_ME_.denominator = nullptr;
48 
49 }
50 
51 RazorMonitor::~RazorMonitor() = default;
52 
53 void RazorMonitor::setMETitle(RazorME& me, const std::string& titleX, const std::string& titleY)
54 {
55  me.numerator->setAxisTitle(titleX,1);
56  me.numerator->setAxisTitle(titleY,2);
57  me.denominator->setAxisTitle(titleX,1);
58  me.denominator->setAxisTitle(titleY,2);
59 
60 }
61 
62 void RazorMonitor::bookME(DQMStore::IBooker &ibooker, RazorME& me, const std::string& histname, const std::string& histtitle, int nbins, double min, double max)
63 {
64  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
65  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
66 }
67 void RazorMonitor::bookME(DQMStore::IBooker &ibooker, RazorME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binning)
68 {
69  int nbins = binning.size()-1;
70  std::vector<float> fbinning(binning.begin(),binning.end());
71  float* arr = &fbinning[0];
72  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
73  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
74 }
75 void RazorMonitor::bookME(DQMStore::IBooker &ibooker, RazorME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, double ymin, double ymax)
76 {
77  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
78  me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
79 }
80 void RazorMonitor::bookME(DQMStore::IBooker &ibooker, RazorME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, int nbinsY, double ymin, double ymax)
81 {
82  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
83  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
84 }
85 void RazorMonitor::bookME(DQMStore::IBooker &ibooker, RazorME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binningX, const std::vector<double>& binningY)
86 {
87  int nbinsX = binningX.size()-1;
88  std::vector<float> fbinningX(binningX.begin(),binningX.end());
89  float* arrX = &fbinningX[0];
90  int nbinsY = binningY.size()-1;
91  std::vector<float> fbinningY(binningY.begin(),binningY.end());
92  float* arrY = &fbinningY[0];
93 
94  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
95  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
96 }
97 
99  edm::Run const & iRun,
100  edm::EventSetup const & iSetup)
101 {
102 
103  std::string histname, histtitle;
104 
105  std::string currentFolder = folderName_ ;
106  ibooker.setCurrentFolder(currentFolder);
107 
108  // 1D hist, MR
109  histname = "MR"; histtitle = "PF MR";
110  bookME(ibooker,MR_ME_,histname,histtitle,mr_binning_);
111  setMETitle(MR_ME_,"PF M_{R} [GeV]","events / [GeV]");
112 
113  // 1D hist, Rsq
114  histname = "Rsq"; histtitle = "PF Rsq";
115  bookME(ibooker,Rsq_ME_,histname,histtitle,rsq_binning_);
116  setMETitle(Rsq_ME_,"PF R^{2}","events");
117 
118  // 1D hist, dPhiR
119  histname = "dPhiR"; histtitle = "dPhiR";
120  bookME(ibooker,dPhiR_ME_,histname,histtitle,dphiR_binning_);
121  setMETitle(dPhiR_ME_,"dPhi_{R}","events");
122 
123  // 2D hist, MR & Rsq
124  histname = "MRVsRsq"; histtitle = "PF MR vs PF Rsq";
125  bookME(ibooker,MRVsRsq_ME_,histname,histtitle,mr_binning_, rsq_binning_);
126  setMETitle(MRVsRsq_ME_,"M_{R} [GeV]","R^{2}");
127 
128  // Initialize the GenericTriggerEventFlag
129  if ( num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() ) num_genTriggerEventFlag_->initRun( iRun, iSetup );
130  if ( den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on() ) den_genTriggerEventFlag_->initRun( iRun, iSetup );
131 
132 }
133 
137 
138  // Filter out events if Trigger Filtering is requested
139  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
140 
141  //met collection
143  iEvent.getByToken( metToken_, metHandle );
144  reco::PFMET pfmet = metHandle->front();
145  if ( ! metSelection_( pfmet ) ) return;
146 
147  //jet collection, track # of jets for two working points
149  iEvent.getByToken( jetToken_, jetHandle );
150  std::vector<reco::PFJet> jets;
151  if ( jetHandle->size() < njets_ ) return;
152  for ( auto const & j : *jetHandle ) {
153  if ( jetSelection_( j ) ) jets.push_back(j);
154  }
155  if ( jets.size() < njets_ ) return;
156 
157  //razor hemisphere clustering from previous step
159  iEvent.getByToken (theHemispheres_,hemispheres);
160 
161  if (not hemispheres.isValid()){
162  return;
163  }
164 
165  if(hemispheres->empty()){ // the Hemisphere Maker will produce an empty collection of hemispheres if # of jets is too high
166  edm::LogError("DQM_HLT_Razor") << "Cannot calculate M_R and R^2 because there are too many jets! (trigger passed automatically without forming the hemispheres)" << endl;
167  return;
168  }
169 
170  // should always have 2 hemispheres -- no muons included (c. 2017), if not return invalid hemisphere collection
171  // retaining check for hemisphere size 5 or 10 which correspond to the one or two muon case for possible future use
172  if(!hemispheres->empty() && hemispheres->size() != 2 && hemispheres->size() != 5 && hemispheres->size() != 10){
173  edm::LogError("DQM_HLT_Razor") << "Invalid hemisphere collection! hemispheres->size() = " << hemispheres->size() << endl;
174  return;
175  }
176 
177  //calculate razor variables, with hemispheres pT-ordered
178  double MR = 0, R = 0;
179  if (hemispheres->at(1).Pt() > hemispheres->at(0).Pt()) {
180  MR = CalcMR(hemispheres->at(1),hemispheres->at(0));
181  R = CalcR(MR,hemispheres->at(1),hemispheres->at(0),metHandle);
182  }
183  else {
184  MR = CalcMR(hemispheres->at(0),hemispheres->at(1));
185  R = CalcR(MR,hemispheres->at(0),hemispheres->at(1),metHandle);
186  }
187 
188  double Rsq = R*R;
189  double dPhiR = abs(deltaPhi(hemispheres->at(0).Phi(), hemispheres->at(1).Phi()));
190 
191  //apply offline selection cuts
192  if (Rsq<rsqCut_ && MR<mrCut_) return;
193 
194  // applying selection for denominator
195  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
196 
197  // filling histograms (denominator)
198  if (Rsq>=rsqCut_) {
199  MR_ME_.denominator -> Fill(MR);
200  }
201 
202  if (MR>=mrCut_) {
203  Rsq_ME_.denominator -> Fill(Rsq);
204  }
205 
206  dPhiR_ME_.denominator -> Fill(dPhiR);
207 
208  MRVsRsq_ME_.denominator -> Fill(MR, Rsq);
209 
210  // applying selection for numerator
211  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
212 
213  // filling histograms (numerator)
214  if (Rsq>=rsqCut_) {
215  MR_ME_.numerator -> Fill(MR);
216  }
217 
218  if (MR>=mrCut_) {
219  Rsq_ME_.numerator -> Fill(Rsq);
220  }
221 
222  dPhiR_ME_.numerator -> Fill(dPhiR);
223 
224  MRVsRsq_ME_.numerator -> Fill(MR, Rsq);
225 
226 }
227 
229 {
231  desc.add<std::string> ( "FolderName", "HLT/SUSY/Razor" );
232 
233  desc.add<edm::InputTag>( "met", edm::InputTag("pfMet") );
234  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
235  desc.add<edm::InputTag>("hemispheres",edm::InputTag("hemispheresDQM"))->setComment("hemisphere jets used to compute razor variables");
236  desc.add<std::string>("metSelection", "pt > 0");
237 
238  // from 2016 offline selection
239  desc.add<std::string>("jetSelection", "pt > 80");
240  desc.add<unsigned int>("njets", 2);
241  desc.add<double>("mrCut", 300);
242  desc.add<double>("rsqCut", 0.15);
243 
244  edm::ParameterSetDescription genericTriggerEventPSet;
245  genericTriggerEventPSet.add<bool>("andOr");
246  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
247  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
248  genericTriggerEventPSet.add<bool>("andOrDcs", false);
249  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
250  genericTriggerEventPSet.add<std::string>("dbLabel","");
251  genericTriggerEventPSet.add<bool>("andOrHlt", true);
252  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
253  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
254  genericTriggerEventPSet.add<std::string>("hltDBKey","");
255  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
256  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
257 
258  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
259  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
260 
261  //binning from 2016 offline selection
263  std::vector<double> mrbins = {0., 100., 200., 300., 400., 500., 575., 650., 750., 900., 1200., 1600., 2500., 4000.};
264  histoPSet.add<std::vector<double> >("mrBins", mrbins);
265 
266  std::vector<double> rsqbins = {0., 0.05, 0.1, 0.15, 0.2, 0.25, 0.30, 0.41, 0.52, 0.64, 0.8, 1.5};
267  histoPSet.add<std::vector<double> >("rsqBins", rsqbins);
268 
269  std::vector<double> dphirbins = {0., 0.5, 1.0, 1.5, 2.0, 2.5, 2.8, 3.0, 3.2};
270  histoPSet.add<std::vector<double> >("dphiRBins", dphirbins);
271 
272  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
273 
274  descriptions.add("razorMonitoring", desc);
275 }
276 
277 //CalcMR and CalcR borrowed from HLTRFilter.cc
279  if(ja.Pt()<=0.1) return -1;
280 
281  double A = ja.P();
282  double B = jb.P();
283  double az = ja.Pz();
284  double bz = jb.Pz();
285  TVector3 jaT, jbT;
286  jaT.SetXYZ(ja.Px(),ja.Py(),0.0);
287  jbT.SetXYZ(jb.Px(),jb.Py(),0.0);
288  double ATBT = (jaT+jbT).Mag2();
289 
290  double MR = sqrt((A+B)*(A+B)-(az+bz)*(az+bz)-
291  (jbT.Dot(jbT)-jaT.Dot(jaT))*(jbT.Dot(jbT)-jaT.Dot(jaT))/(jaT+jbT).Mag2());
292  double mybeta = (jbT.Dot(jbT)-jaT.Dot(jaT))/
293  sqrt(ATBT*((A+B)*(A+B)-(az+bz)*(az+bz)));
294 
295  double mygamma = 1./sqrt(1.-mybeta*mybeta);
296 
297  //use gamma times MRstar
298  return MR*mygamma;
299 }
300 
301 double RazorMonitor::CalcR(double MR, const math::XYZTLorentzVector& ja, const math::XYZTLorentzVector& jb, const edm::Handle<std::vector<reco::PFMET> >& inputMet){
302 
303  //now we can calculate MTR
304  const math::XYZVector met = (inputMet->front()).momentum();
305 
306  double MTR = sqrt(0.5*(met.R()*(ja.Pt()+jb.Pt()) - met.Dot(ja.Vect()+jb.Vect())));
307 
308  //filter events
309  return float(MTR)/float(MR); //R
310 }
311 
312 // Define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: RazorMonitor.h:85
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: RazorMonitor.h:84
void bookME(DQMStore::IBooker &, RazorME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
Definition: RazorMonitor.cc:62
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: RazorMonitor.h:97
void setMETitle(RazorME &me, const std::string &titleX, const std::string &titleY)
Definition: RazorMonitor.cc:53
static double CalcMR(const math::XYZTLorentzVector &ja, const math::XYZTLorentzVector &jb)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
MonitorElement * numerator
Definition: RazorMonitor.h:50
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< std::vector< math::XYZTLorentzVector > > theHemispheres_
Definition: RazorMonitor.h:86
unsigned int njets_
Definition: RazorMonitor.h:102
int iEvent
Definition: GenABIO.cc:230
std::vector< double > mr_binning_
Definition: RazorMonitor.h:89
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:18
vector< PseudoJet > jets
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
static const std::string B
std::vector< double > dphiR_binning_
Definition: RazorMonitor.h:90
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
RazorME Rsq_ME_
Definition: RazorMonitor.h:93
RazorME dPhiR_ME_
Definition: RazorMonitor.h:94
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
std::vector< double > rsq_binning_
Definition: RazorMonitor.h:88
met
===> hadronic RAZOR
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: RazorMonitor.h:100
RazorME MR_ME_
Definition: RazorMonitor.h:92
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: RazorMonitor.h:98
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: RazorMonitor.cc:98
MonitorElement * denominator
Definition: RazorMonitor.h:51
~RazorMonitor() override
RazorMonitor(const edm::ParameterSet &)
Definition: RazorMonitor.cc:21
static double CalcR(double MR, const math::XYZTLorentzVector &ja, const math::XYZTLorentzVector &jb, const edm::Handle< std::vector< reco::PFMET > > &met)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
RazorME MRVsRsq_ME_
Definition: RazorMonitor.h:95
std::string folderName_
Definition: RazorMonitor.h:81
Definition: Run.h:43
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: RazorMonitor.h:101
Collection of PF MET.