1 |
/*
|
2 |
* Event.cpp
|
3 |
*
|
4 |
* Created on: Jun 25, 2010
|
5 |
* Author: lkreczko
|
6 |
*/
|
7 |
|
8 |
#include "../interface/Event.h"
|
9 |
#include <iostream>
|
10 |
using namespace std;
|
11 |
|
12 |
namespace BAT {
|
13 |
bool Event::useCustomConversionTagger = false;
|
14 |
bool Event::usePFIsolation = false;
|
15 |
Event::Event() :
|
16 |
HLTs(new std::vector<int>()),
|
17 |
vertices(),
|
18 |
goodVertices(),
|
19 |
tracks(),
|
20 |
allElectrons(),
|
21 |
goodElectrons(),
|
22 |
goodIsolatedElectrons(),
|
23 |
goodPFIsolatedElectrons(),
|
24 |
looseElectrons(),
|
25 |
qcdElectrons(),
|
26 |
allJets(),
|
27 |
goodJets(),
|
28 |
goodBJets(),
|
29 |
allMuons(),
|
30 |
goodMuons(),
|
31 |
goodIsolatedMuons(),
|
32 |
looseMuons(),
|
33 |
genParticles(),
|
34 |
met(),
|
35 |
dataType(DataType::DATA),
|
36 |
runNumber(0),
|
37 |
eventNumber(0),
|
38 |
lumiBlock(0),
|
39 |
eventWeight(1.),
|
40 |
jetCleaningEfficiency(1.),
|
41 |
numberOfHighPurityTracks(0),
|
42 |
isBeamScraping(true),
|
43 |
genNumberOfPileUpVertices(0){
|
44 |
}
|
45 |
|
46 |
Event::~Event() {
|
47 |
}
|
48 |
|
49 |
bool Event::isRealData() const {
|
50 |
return dataType == DataType::DATA;
|
51 |
}
|
52 |
|
53 |
const DataType::value Event::getDataType() const {
|
54 |
return dataType;
|
55 |
}
|
56 |
|
57 |
void Event::setDataType(DataType::value type) {
|
58 |
dataType = type;
|
59 |
}
|
60 |
|
61 |
void Event::setVertices(VertexCollection vertices) {
|
62 |
this->vertices.clear();
|
63 |
this->vertices = vertices;
|
64 |
|
65 |
selectVerticesByQuality();
|
66 |
}
|
67 |
|
68 |
void Event::selectVerticesByQuality() {
|
69 |
goodVertices.clear();
|
70 |
|
71 |
for (unsigned int i = 0; i < vertices.size(); ++i) {
|
72 |
if (vertices.at(i)->isGood())
|
73 |
goodVertices.push_back(vertices.at(i));
|
74 |
}
|
75 |
}
|
76 |
|
77 |
void Event::setTracks(TrackCollection tracks) {
|
78 |
this->tracks.clear();
|
79 |
this->tracks = tracks;
|
80 |
numberOfHighPurityTracks = 0;
|
81 |
for (unsigned int index = 0; index < tracks.size(); ++index) {
|
82 |
if (tracks.at(index)->isHighPurity())
|
83 |
numberOfHighPurityTracks++;
|
84 |
}
|
85 |
}
|
86 |
|
87 |
void Event::setGenParticles(MCParticleCollection genParticles) {
|
88 |
this->genParticles = genParticles;
|
89 |
}
|
90 |
|
91 |
void Event::setElectrons(ElectronCollection electrons) {
|
92 |
allElectrons.clear();
|
93 |
allElectrons = electrons;
|
94 |
selectElectronsByQuality();
|
95 |
}
|
96 |
|
97 |
|
98 |
void Event::setLoosePFElectrons(ElectronCollection electrons) {
|
99 |
loosePFElectrons.clear();
|
100 |
loosePFElectrons = electrons;
|
101 |
}
|
102 |
|
103 |
|
104 |
void Event::selectElectronsByQuality() {
|
105 |
goodElectrons.clear();
|
106 |
goodIsolatedElectrons.clear();
|
107 |
goodPFIsolatedElectrons.clear();
|
108 |
for (unsigned int index = 0; index < allElectrons.size(); ++index) {
|
109 |
ElectronPointer electron = allElectrons.at(index);
|
110 |
|
111 |
if (electron->isGood())
|
112 |
goodElectrons.push_back(electron);
|
113 |
|
114 |
if(electron->isGood(20))
|
115 |
qcdElectrons.push_back(electron);
|
116 |
|
117 |
if (electron->isGood() && electron->isIsolated())
|
118 |
goodIsolatedElectrons.push_back(electron);
|
119 |
|
120 |
if(electron->algorithm() == ElectronAlgorithm::ParticleFlow){
|
121 |
if(electron->isGood() && electron->isPFIsolated())
|
122 |
goodPFIsolatedElectrons.push_back(electron);
|
123 |
}
|
124 |
if (electron->isLoose())
|
125 |
looseElectrons.push_back(electron);
|
126 |
}
|
127 |
}
|
128 |
|
129 |
void Event::setJets(JetCollection jets) {
|
130 |
allJets.clear();
|
131 |
allJets = jets;
|
132 |
selectGoodJets();
|
133 |
}
|
134 |
|
135 |
void Event::setGenJets(JetCollection jets) {
|
136 |
genJets.clear();
|
137 |
genJets = jets;
|
138 |
}
|
139 |
|
140 |
|
141 |
void Event::selectGoodJets() {
|
142 |
goodJets.clear();
|
143 |
for (unsigned int index = 0; index < allJets.size(); ++index) {
|
144 |
const JetPointer jet = allJets.at(index);
|
145 |
if (jet->isGood()) {
|
146 |
goodJets.push_back(jet);
|
147 |
}
|
148 |
}
|
149 |
cleanGoodJets();
|
150 |
for (unsigned int index = 0; index < goodJets.size(); ++index) {
|
151 |
const JetPointer jet = goodJets.at(index);
|
152 |
if (jet->isBJet(BtagAlgorithm::SimpleSecondaryVertexHighEffBTag))
|
153 |
goodBJets.push_back(jet);
|
154 |
}
|
155 |
}
|
156 |
|
157 |
void Event::cleanGoodJets() {
|
158 |
if (goodJets.size() > 0) {
|
159 |
if (goodPFIsolatedElectrons.size() > 0)
|
160 |
cleanGoodJetsAgainstIsolatedLeptons(goodPFIsolatedElectrons);
|
161 |
if (goodIsolatedMuons.size() > 0)
|
162 |
cleanGoodJetsAgainstIsolatedLeptons(goodIsolatedMuons);
|
163 |
}
|
164 |
}
|
165 |
|
166 |
template <class PartColl> void Event::cleanGoodJetsAgainstIsolatedLeptons(const PartColl &leptonColl) {
|
167 |
unsigned int initialGoodJets = goodJets.size();
|
168 |
for (unsigned int jetIndex = 0; jetIndex < goodJets.size(); ++jetIndex) {
|
169 |
for (unsigned int leptonIndex = 0; leptonIndex < leptonColl.size(); ++leptonIndex) {
|
170 |
if (goodJets.at(jetIndex)->isWithinDeltaR(0.3, leptonColl.at(leptonIndex))) {
|
171 |
goodJets.erase(goodJets.begin() + jetIndex);
|
172 |
--jetIndex;
|
173 |
break;
|
174 |
}
|
175 |
}
|
176 |
}
|
177 |
jetCleaningEfficiency = goodJets.size() / initialGoodJets;
|
178 |
}
|
179 |
|
180 |
void Event::cleanGoodJetsAgainstMostIsolatedElectron() {
|
181 |
const ElectronPointer mostIsolatedElectron = MostIsolatedElectron(Event::usePFIsolation);
|
182 |
unsigned int initialGoodJets = goodJets.size();
|
183 |
for (unsigned int jetIndex = 0; jetIndex < goodJets.size(); ++jetIndex) {
|
184 |
if (goodJets.at(jetIndex)->isWithinDeltaR(0.3, mostIsolatedElectron)) {
|
185 |
goodJets.erase(goodJets.begin() + jetIndex);
|
186 |
--jetIndex;
|
187 |
}
|
188 |
}
|
189 |
jetCleaningEfficiency = goodJets.size() / initialGoodJets;
|
190 |
}
|
191 |
|
192 |
const ElectronPointer Event::MostIsolatedElectron(bool usePFIso) const {
|
193 |
float bestIsolation = 999999999;
|
194 |
unsigned int bestIsolatedElectron = 990;
|
195 |
for (unsigned int index = 0; index < allElectrons.size(); ++index) {
|
196 |
float currentIsolation = 999999999;
|
197 |
if(usePFIso)
|
198 |
currentIsolation = allElectrons.at(index)->pfIsolation();
|
199 |
else
|
200 |
currentIsolation = allElectrons.at(index)->relativeIsolation();
|
201 |
|
202 |
if (currentIsolation < bestIsolation) {
|
203 |
bestIsolation = currentIsolation;
|
204 |
bestIsolatedElectron = index;
|
205 |
}
|
206 |
}
|
207 |
return allElectrons.at(bestIsolatedElectron);
|
208 |
}
|
209 |
|
210 |
const ElectronPointer Event::MostIsolatedElectron() const{
|
211 |
return MostIsolatedElectron(false);
|
212 |
}
|
213 |
|
214 |
const ElectronPointer Event::MostPFIsolatedElectron() const{
|
215 |
return MostIsolatedElectron(true);
|
216 |
}
|
217 |
|
218 |
|
219 |
void Event::setMuons(MuonCollection muons) {
|
220 |
allMuons.clear();
|
221 |
allMuons = muons;
|
222 |
selectMuonsByQuality();
|
223 |
}
|
224 |
|
225 |
void Event::selectMuonsByQuality() {
|
226 |
goodMuons.clear();
|
227 |
goodIsolatedMuons.clear();
|
228 |
for (unsigned int index = 0; index < allMuons.size(); ++index) {
|
229 |
MuonPointer muon = allMuons.at(index);
|
230 |
|
231 |
if (muon->isGood())
|
232 |
goodMuons.push_back(muon);
|
233 |
|
234 |
if (muon->isGood() && muon->isIsolated())
|
235 |
goodIsolatedMuons.push_back(muon);
|
236 |
if (muon->isLoose())
|
237 |
looseMuons.push_back(muon);
|
238 |
}
|
239 |
}
|
240 |
|
241 |
void Event::setHLTs(const boost::shared_ptr<std::vector<int> > triggers){
|
242 |
HLTs = triggers;
|
243 |
}
|
244 |
|
245 |
void Event::setMET(const METPointer met) {
|
246 |
this->met = met;
|
247 |
this->met->adjForUnc(allJets);
|
248 |
}
|
249 |
|
250 |
void Event::setRunNumber(unsigned long number) {
|
251 |
runNumber = number;
|
252 |
}
|
253 |
|
254 |
void Event::setEventNumber(unsigned long number) {
|
255 |
eventNumber = number;
|
256 |
}
|
257 |
|
258 |
void Event::setLocalEventNumber(unsigned long number) {
|
259 |
localEventNumber = number;
|
260 |
}
|
261 |
|
262 |
void Event::setLumiBlock(unsigned long block) {
|
263 |
lumiBlock = block;
|
264 |
}
|
265 |
|
266 |
void Event::setEventWeight(float weight) {
|
267 |
eventWeight = weight;
|
268 |
}
|
269 |
|
270 |
void Event::setBeamScrapingVeto(bool isScraping){
|
271 |
isBeamScraping = isScraping;
|
272 |
}
|
273 |
|
274 |
const VertexPointer Event::PrimaryVertex() const {
|
275 |
return goodVertices.front();
|
276 |
}
|
277 |
|
278 |
const VertexCollection& Event::Vertices() const {
|
279 |
return vertices;
|
280 |
}
|
281 |
|
282 |
const VertexCollection& Event::GoodVertices() const {
|
283 |
return goodVertices;
|
284 |
}
|
285 |
|
286 |
const TrackCollection& Event::Tracks() const {
|
287 |
return tracks;
|
288 |
}
|
289 |
|
290 |
const ElectronCollection& Event::Electrons() const {
|
291 |
return allElectrons;
|
292 |
}
|
293 |
|
294 |
const ElectronCollection& Event::GoodElectrons() const {
|
295 |
return goodElectrons;
|
296 |
}
|
297 |
|
298 |
const ElectronCollection& Event::GoodIsolatedElectrons() const {
|
299 |
return goodIsolatedElectrons;
|
300 |
}
|
301 |
|
302 |
const ElectronCollection& Event::GoodPFIsolatedElectrons() const {
|
303 |
return goodPFIsolatedElectrons;
|
304 |
}
|
305 |
|
306 |
const ElectronCollection& Event::QCDElectrons() const{
|
307 |
return qcdElectrons;
|
308 |
}
|
309 |
|
310 |
const ElectronCollection& Event::LoosePFElectrons() const{
|
311 |
return loosePFElectrons;
|
312 |
}
|
313 |
|
314 |
const JetCollection& Event::Jets() const {
|
315 |
return allJets;
|
316 |
}
|
317 |
|
318 |
const JetCollection& Event::GenJets() const {
|
319 |
return genJets;
|
320 |
}
|
321 |
|
322 |
|
323 |
const JetCollection& Event::GoodJets() const {
|
324 |
return goodJets;
|
325 |
}
|
326 |
|
327 |
const JetCollection& Event::GoodBJets() const {
|
328 |
return goodBJets;
|
329 |
}
|
330 |
|
331 |
const MuonCollection& Event::Muons() const {
|
332 |
return allMuons;
|
333 |
}
|
334 |
|
335 |
const MuonCollection& Event::GoodMuons() const {
|
336 |
return goodMuons;
|
337 |
}
|
338 |
|
339 |
const MuonCollection& Event::GoodIsolatedMuons() const {
|
340 |
return goodIsolatedMuons;
|
341 |
}
|
342 |
|
343 |
const MCParticleCollection& Event::GenParticles() const {
|
344 |
return genParticles;
|
345 |
}
|
346 |
|
347 |
const METPointer Event::MET() const {
|
348 |
return met;
|
349 |
}
|
350 |
|
351 |
unsigned long Event::runnumber() const {
|
352 |
return runNumber;
|
353 |
}
|
354 |
|
355 |
unsigned long Event::eventnumber() const {
|
356 |
return eventNumber;
|
357 |
}
|
358 |
|
359 |
unsigned long Event::localnumber() const {
|
360 |
return localEventNumber;
|
361 |
}
|
362 |
|
363 |
unsigned long Event::lumiblock() const {
|
364 |
return lumiBlock;
|
365 |
}
|
366 |
|
367 |
float Event::weight() const {
|
368 |
return eventWeight;
|
369 |
}
|
370 |
|
371 |
void Event::inspect() const {
|
372 |
cout << "run " << runNumber << ", event number " << eventNumber << ", lumi section " << lumiBlock << endl;
|
373 |
|
374 |
cout << "number of tracks: " << tracks.size() << endl;
|
375 |
cout << "number of high purity tracks: " << numberOfHighPurityTracks << endl;
|
376 |
|
377 |
cout << "number of jets: " << allJets.size() << endl;
|
378 |
EventContentPrinter::printJets(allJets);
|
379 |
cout << "number of good jets: " << goodJets.size() << endl;
|
380 |
EventContentPrinter::printJets(goodJets);
|
381 |
|
382 |
cout << "number of good isolated electrons: " << goodIsolatedElectrons.size() << endl;
|
383 |
EventContentPrinter::printElectrons(goodIsolatedElectrons);
|
384 |
|
385 |
cout << "number of good electrons: " << goodElectrons.size() << endl;
|
386 |
EventContentPrinter::printElectrons(goodElectrons);
|
387 |
|
388 |
cout << "number of electrons: " << allElectrons.size() << endl;
|
389 |
EventContentPrinter::printElectrons(allElectrons);
|
390 |
}
|
391 |
|
392 |
bool Event::HLT(HLTriggers::value trigger) const{
|
393 |
if (trigger >= (int) HLTs->size()) {
|
394 |
static bool showMsg = true;
|
395 |
if (showMsg) {
|
396 |
cout << "Seeking trigger # " << trigger << " but only ";
|
397 |
cout << HLTs->size() << " triggers in ntuple\n";
|
398 |
showMsg = false;
|
399 |
}
|
400 |
return false;
|
401 |
}
|
402 |
return (HLTs->at(trigger) > 0);
|
403 |
}
|
404 |
|
405 |
void Event::setGenNumberOfPileUpVertices(unsigned int pileup){
|
406 |
genNumberOfPileUpVertices = pileup;
|
407 |
}
|
408 |
|
409 |
float Event::numberOfGeneratedPileUpVertices() const{
|
410 |
return genNumberOfPileUpVertices;
|
411 |
}
|
412 |
|
413 |
}
|