1 |
/**
|
2 |
* MonitorTriggerAnalyzer
|
3 |
* s8
|
4 |
*
|
5 |
* Created by Samvel Khalatian on Feb 25, 2011
|
6 |
* Copyright 2011, All rights reserved
|
7 |
*/
|
8 |
|
9 |
#include <cmath>
|
10 |
|
11 |
#include <iostream>
|
12 |
#include <stdexcept>
|
13 |
|
14 |
#include <TDirectory.h>
|
15 |
#include <TH1F.h>
|
16 |
#include <TH1D.h>
|
17 |
#include <TLorentzVector.h>
|
18 |
|
19 |
#include "s8/IO/interface/Event.h"
|
20 |
#include "Tree/System8/interface/S8GenEvent.h"
|
21 |
#include "Tree/System8/interface/S8Fwd.h"
|
22 |
#include "Tree/System8/interface/S8Jet.h"
|
23 |
#include "Tree/System8/interface/S8Lepton.h"
|
24 |
#include "s8/Selector/interface/S8Selector.h"
|
25 |
#include "s8/Utility/interface/MonitorPlots.h"
|
26 |
#include "s8/Utility/interface/MuonInJet.h"
|
27 |
#include "s8/Utility/interface/TaggerOperatingPoint.h"
|
28 |
|
29 |
#include "s8/Analyzer/interface/MonitorTriggerAnalyzer.h"
|
30 |
|
31 |
using std::cerr;
|
32 |
using std::clog;
|
33 |
using std::cout;
|
34 |
using std::endl;
|
35 |
|
36 |
using s8::MonitorTriggerAnalyzer;
|
37 |
|
38 |
MonitorTriggerAnalyzer::MonitorTriggerAnalyzer() throw():
|
39 |
_use_trigger_prescale(false),
|
40 |
_prescale(0)
|
41 |
{
|
42 |
_s8_selector = 0;
|
43 |
}
|
44 |
|
45 |
MonitorTriggerAnalyzer::~MonitorTriggerAnalyzer() throw()
|
46 |
{
|
47 |
if (_s8_selector)
|
48 |
delete _s8_selector;
|
49 |
}
|
50 |
|
51 |
|
52 |
|
53 |
// Analyzer interface
|
54 |
//
|
55 |
void MonitorTriggerAnalyzer::init()
|
56 |
{
|
57 |
_muonInJetTagger.reset(new TaggerOperatingPoint());
|
58 |
_awayJetTagger.reset(new TaggerOperatingPoint());
|
59 |
|
60 |
_muonInJet.reset(new MuonInJet());
|
61 |
_muonInJet->setDelegate(this);
|
62 |
_muonInJet->setAwayJetTaggerOperatingPoint(_awayJetTagger.get());
|
63 |
|
64 |
_muons.reset(new TH1D("muons", "N muons",
|
65 |
10, 0, 10));
|
66 |
// Force Manual memory management
|
67 |
//
|
68 |
_muons->SetDirectory(0);
|
69 |
_muons->GetXaxis()->SetTitle("N_{#mu}");
|
70 |
|
71 |
_pthat.reset(new TH1D("pthat", "pT hat", 100, 0, 200));
|
72 |
// Force Manual memory management
|
73 |
//
|
74 |
_pthat->SetDirectory(0);
|
75 |
_pthat->GetXaxis()->SetTitle("#hat{p_{T}}");
|
76 |
|
77 |
_jets.reset(new TH1D("jets", "N jets",
|
78 |
10, 0, 10));
|
79 |
// Force Manual memory management
|
80 |
//
|
81 |
_jets->SetDirectory(0);
|
82 |
_jets->GetXaxis()->SetTitle("N_{jet}");
|
83 |
|
84 |
// Generic
|
85 |
//
|
86 |
_monitorMuons.reset(new MonitorLepton("allmus"));
|
87 |
_monitorJets.reset(new MonitorJet("alljets"));
|
88 |
_monitorJets->plot(MonitorBase::PT)->SetBins(230, 0, 230);
|
89 |
_monitorLeadingJet.reset(new MonitorJet("leadingjet"));
|
90 |
|
91 |
// (n)
|
92 |
//
|
93 |
_monitorNMuons.reset(new MonitorLepton("nmu"));
|
94 |
_monitorNJets.reset(new MonitorJet("njet"));
|
95 |
_monitorNJets->plot(MonitorBase::PT)->SetBins(230, 0, 230);
|
96 |
_monitorNDelta.reset(new MonitorDelta("nmujet"));
|
97 |
|
98 |
// (p)
|
99 |
//
|
100 |
_monitorPMuons.reset(new MonitorLepton("pmu"));
|
101 |
_monitorPJets.reset(new MonitorJet("pjet"));
|
102 |
_monitorPJets->plot(MonitorBase::PT)->SetBins(230, 0, 230);
|
103 |
_monitorPDelta.reset(new MonitorDelta("pmujet"));
|
104 |
|
105 |
// change binning in the Delta plots
|
106 |
//
|
107 |
MonitorDelta *deltas[] = { _monitorNDelta.get(), _monitorPDelta.get() };
|
108 |
for(int i = 0; 2 > i; ++i)
|
109 |
{
|
110 |
deltas[i]->plot(MonitorDelta::PTREL)->SetBins(70, 0, 7);
|
111 |
}
|
112 |
|
113 |
_s8_selector = new S8Selector();
|
114 |
}
|
115 |
|
116 |
void MonitorTriggerAnalyzer::treeDidLoad(const TreeInfo *,
|
117 |
const TriggerCenter *trigger_center)
|
118 |
{
|
119 |
_s8_selector->treeDidLoad(trigger_center);
|
120 |
}
|
121 |
|
122 |
void MonitorTriggerAnalyzer::eventDidLoad(const Event *event)
|
123 |
{
|
124 |
using s8::Jets;
|
125 |
using s8::Leptons;
|
126 |
|
127 |
// check if event passes the selection
|
128 |
//
|
129 |
const Event *modified_event = (*_s8_selector)(event);
|
130 |
if (!modified_event)
|
131 |
return;
|
132 |
|
133 |
event = modified_event;
|
134 |
|
135 |
if (_use_trigger_prescale)
|
136 |
{
|
137 |
// Extract prescale of the trigger
|
138 |
//
|
139 |
// Search for user defined triggers among those that passed the event
|
140 |
//
|
141 |
s8::Triggers::const_iterator found_trigger =
|
142 |
find_if(event->triggers()->begin(),
|
143 |
event->triggers()->end(),
|
144 |
_trigger_predicator);
|
145 |
|
146 |
// Check if trigger was found and passed the event
|
147 |
//
|
148 |
if (event->triggers()->end() != found_trigger)
|
149 |
_prescale = (*found_trigger)->prescale();
|
150 |
}
|
151 |
|
152 |
_pthat->Fill(event->gen()->ptHat());
|
153 |
_muons->Fill(event->muons()->size());
|
154 |
_jets->Fill(event->jets()->size());
|
155 |
|
156 |
for(Leptons::const_iterator muon = event->muons()->begin();
|
157 |
event->muons()->end() != muon;
|
158 |
++muon)
|
159 |
|
160 |
_monitorMuons->fill(_prescale ? _prescale : 1, *muon);
|
161 |
|
162 |
const Jet *leadingJet = 0;
|
163 |
for(Jets::const_iterator jet = event->jets()->begin();
|
164 |
event->jets()->end() != jet;
|
165 |
++jet)
|
166 |
{
|
167 |
_monitorJets->fill(_prescale ? _prescale : 1, *jet);
|
168 |
|
169 |
if (leadingJet &&
|
170 |
leadingJet->p4()->Pt() >= (*jet)->p4()->Pt())
|
171 |
|
172 |
continue;
|
173 |
|
174 |
leadingJet = *jet;
|
175 |
}
|
176 |
|
177 |
if (leadingJet)
|
178 |
_monitorLeadingJet->fill(_prescale ? _prescale : 1, leadingJet);
|
179 |
|
180 |
(*_muonInJet)(event);
|
181 |
|
182 |
_prescale = 0;
|
183 |
}
|
184 |
|
185 |
void MonitorTriggerAnalyzer::print(std::ostream &out) const
|
186 |
{
|
187 |
_s8_selector->print(out);
|
188 |
}
|
189 |
|
190 |
void MonitorTriggerAnalyzer::save(TDirectory *directory) const
|
191 |
{
|
192 |
TDirectory *output = directory->mkdir("MonitorTriggerAnalyzer");
|
193 |
if (!output)
|
194 |
{
|
195 |
cerr << "MonitorTriggerAnalyzer: Failed to create output folder: "
|
196 |
<< "no output is saved" << endl;
|
197 |
|
198 |
return;
|
199 |
}
|
200 |
|
201 |
output->cd();
|
202 |
|
203 |
saveGenericPlots(output);
|
204 |
saveNPlots(output);
|
205 |
savePPlots(output);
|
206 |
}
|
207 |
|
208 |
// MuonInJetOptionsDelegate interface
|
209 |
//
|
210 |
void MonitorTriggerAnalyzer::optionTagIsSet(const std::string &tag)
|
211 |
{
|
212 |
*_muonInJetTagger << tag;
|
213 |
}
|
214 |
|
215 |
void MonitorTriggerAnalyzer::optionAwayTagIsSet(const std::string &tag)
|
216 |
{
|
217 |
*_awayJetTagger << tag;
|
218 |
}
|
219 |
|
220 |
void MonitorTriggerAnalyzer::optionMuonPtIsSet(const Range &value)
|
221 |
{
|
222 |
_n_muon_pt = value;
|
223 |
}
|
224 |
|
225 |
void MonitorTriggerAnalyzer::optionJetPtIsSet(const Range &value)
|
226 |
{
|
227 |
_n_jet_pt = value;
|
228 |
}
|
229 |
|
230 |
void MonitorTriggerAnalyzer::optionJetEtaIsSet(const Range &value)
|
231 |
{
|
232 |
_n_jet_eta = value;
|
233 |
}
|
234 |
|
235 |
// MuonInJetDelegate interface
|
236 |
//
|
237 |
bool MonitorTriggerAnalyzer::shouldSkipMuonInJetPlusAwayJet(const Lepton *muon,
|
238 |
const Jet *jet)
|
239 |
{
|
240 |
return !isValueInRange(muon->p4()->Pt(), _n_muon_pt) ||
|
241 |
!isValueInRange(jet->p4()->Pt(), _n_jet_pt) ||
|
242 |
!isValueInRange(fabs(jet->p4()->Eta()), _n_jet_eta);
|
243 |
}
|
244 |
|
245 |
void MonitorTriggerAnalyzer::muonIsInJetPlusAwayJet(const Lepton *muon,
|
246 |
const Jet *jet)
|
247 |
{
|
248 |
_monitorNMuons->fill(_prescale ? _prescale : 1, muon);
|
249 |
_monitorNJets->fill(_prescale ? _prescale : 1, jet);
|
250 |
_monitorNDelta->fill(_prescale ? _prescale : 1, muon->p4(), jet->p4());
|
251 |
}
|
252 |
|
253 |
void MonitorTriggerAnalyzer::muonIsInJetPlusTaggedAwayJet(const Lepton *muon,
|
254 |
const Jet *jet)
|
255 |
{
|
256 |
_monitorPMuons->fill(_prescale ? _prescale : 1, muon);
|
257 |
_monitorPJets->fill(_prescale ? _prescale : 1, jet);
|
258 |
_monitorPDelta->fill(_prescale ? _prescale : 1, muon->p4(), jet->p4());
|
259 |
}
|
260 |
|
261 |
// PythiaOptionsDelegate interface
|
262 |
//
|
263 |
void MonitorTriggerAnalyzer::optionGluonSplittingIsSet(const GluonSplitting &value)
|
264 |
{
|
265 |
_s8_selector->optionGluonSplittingIsSet(value);
|
266 |
}
|
267 |
|
268 |
void MonitorTriggerAnalyzer::optionPtHatIsSet(const Range &value)
|
269 |
{
|
270 |
_s8_selector->optionPtHatIsSet(value);
|
271 |
}
|
272 |
|
273 |
// Trigger options
|
274 |
//
|
275 |
void MonitorTriggerAnalyzer::optionTriggerIsSet(const Trigger &trigger)
|
276 |
{
|
277 |
_trigger = trigger;
|
278 |
_trigger_predicator.setSearchTrigger(_trigger);
|
279 |
|
280 |
_s8_selector->optionTriggerIsSet(trigger);
|
281 |
}
|
282 |
|
283 |
void MonitorTriggerAnalyzer::optionUseTriggerPrescaleIsSet(const bool &value)
|
284 |
{
|
285 |
_use_trigger_prescale = value;
|
286 |
}
|
287 |
|
288 |
|
289 |
|
290 |
void MonitorTriggerAnalyzer::saveGenericPlots(TDirectory *directory) const
|
291 |
{
|
292 |
TDirectory *subdir = directory->mkdir("generic");
|
293 |
if (!subdir)
|
294 |
{
|
295 |
cerr << "Failed to create 'generic' TDirectory. Plots are not saved"
|
296 |
<< endl;
|
297 |
|
298 |
return;
|
299 |
}
|
300 |
|
301 |
subdir->cd();
|
302 |
|
303 |
_muons->Write();
|
304 |
_jets->Write();
|
305 |
_pthat->Write();
|
306 |
|
307 |
// Generic
|
308 |
//
|
309 |
_monitorMuons->save(subdir);
|
310 |
_monitorJets->save(subdir);
|
311 |
_monitorLeadingJet->save(subdir);
|
312 |
|
313 |
directory->cd();
|
314 |
}
|
315 |
|
316 |
void MonitorTriggerAnalyzer::saveNPlots(TDirectory *directory) const
|
317 |
{
|
318 |
TDirectory *subdir = directory->mkdir("n");
|
319 |
if (!subdir)
|
320 |
{
|
321 |
cerr << "Failed to create 'n' TDirectory. Plots are not saved"
|
322 |
<< endl;
|
323 |
|
324 |
return;
|
325 |
}
|
326 |
|
327 |
subdir->cd();
|
328 |
|
329 |
// (n)
|
330 |
//
|
331 |
_monitorNMuons->save(subdir);
|
332 |
_monitorNJets->save(subdir);
|
333 |
_monitorNDelta->save(subdir);
|
334 |
|
335 |
directory->cd();
|
336 |
}
|
337 |
|
338 |
void MonitorTriggerAnalyzer::savePPlots(TDirectory *directory) const
|
339 |
{
|
340 |
TDirectory *subdir = directory->mkdir("p");
|
341 |
if (!subdir)
|
342 |
{
|
343 |
cerr << "Failed to create 'p' TDirectory. Plots are not saved"
|
344 |
<< endl;
|
345 |
|
346 |
return;
|
347 |
}
|
348 |
|
349 |
subdir->cd();
|
350 |
|
351 |
// (p)
|
352 |
//
|
353 |
_monitorPMuons->save(subdir);
|
354 |
_monitorPJets->save(subdir);
|
355 |
_monitorPDelta->save(subdir);
|
356 |
|
357 |
directory->cd();
|
358 |
}
|