1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// -*- C++ -*-
//
// Package: BeamSplash
// Class: BeamSPlash
//
//
// Original Author: Luca Malgeri
#include <memory>
#include <vector>
#include <map>
#include <set>
// user include files
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DPGAnalysis/Skims/interface/FilterOutScraping.h"
using namespace edm;
using namespace std;
FilterOutScraping::FilterOutScraping(const edm::ParameterSet& iConfig) {
applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
debugOn = iConfig.getUntrackedParameter<bool>("debugOn", false);
thresh = iConfig.getUntrackedParameter<double>("thresh", 0.2);
numtrack = iConfig.getUntrackedParameter<unsigned int>("numtrack", 10);
tracks_ = consumes<reco::TrackCollection>(
iConfig.getUntrackedParameter<edm::InputTag>("src", edm::InputTag("generalTracks")));
}
FilterOutScraping::~FilterOutScraping() = default;
bool FilterOutScraping::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
bool accepted = false;
float fraction = 0;
// get GeneralTracks collection
edm::Handle<reco::TrackCollection> tkRef;
iEvent.getByToken(tracks_, tkRef);
const reco::TrackCollection* tkColl = tkRef.product();
//std::cout << "Total Number of Tracks " << tkColl->size() << std::endl;
int numhighpurity = 0;
_trackQuality = reco::TrackBase::qualityByName("highPurity");
if (tkColl->size() > numtrack) {
reco::TrackCollection::const_iterator itk = tkColl->begin();
reco::TrackCollection::const_iterator itk_e = tkColl->end();
for (; itk != itk_e; ++itk) {
// std::cout << "HighPurity? " << itk->quality(_trackQuality) << std::endl;
if (itk->quality(_trackQuality))
numhighpurity++;
}
fraction = (float)numhighpurity / (float)tkColl->size();
if (fraction > thresh)
accepted = true;
} else {
//if less than 10 Tracks accept the event anyway
accepted = true;
}
if (debugOn) {
int ievt = iEvent.id().event();
int irun = iEvent.id().run();
int ils = iEvent.luminosityBlock();
int bx = iEvent.bunchCrossing();
std::cout << "FilterOutScraping_debug: Run " << irun << " Event " << ievt << " Lumi Block " << ils
<< " Bunch Crossing " << bx << " Fraction " << fraction << " NTracks " << tkColl->size() << " Accepted "
<< accepted << std::endl;
}
if (applyfilter)
return accepted;
else
return true;
}
//define this as a plug-in
DEFINE_FWK_MODULE(FilterOutScraping);
|