CMS 3D CMS Logo

AlignmentGlobalTrackSelector.cc
Go to the documentation of this file.
1 //Framework
6 
7 //DataFormats
12 
14 
15 #include <DataFormats/RecoCandidate/interface/RecoCandidate.h> //for the get<TrackRef>() Call
16 
18 
19 //STL
20 #include <cmath>
21 
23 
24 
25 using namespace std;
26 using namespace edm;
27 
28 // constructor ----------------------------------------------------------------
30  theGMFilterSwitch(cfg.getParameter<bool>("applyGlobalMuonFilter")),
31  theIsoFilterSwitch(cfg.getParameter<bool>("applyIsolationtest")),
32  theJetCountFilterSwitch(cfg.getParameter<bool>("applyJetCountFilter"))
33 {
35  LogDebug("Alignment") << "> applying global Trackfilter ...";
36 
37  if (theGMFilterSwitch) {
38  edm::InputTag theMuonSource = cfg.getParameter<InputTag>("muonSource");
39  theMuonToken = iC.consumes<reco::MuonCollection>(theMuonSource);
40  theMaxTrackDeltaR =cfg.getParameter<double>("maxTrackDeltaR");
41  theMinGlobalMuonCount = cfg.getParameter<int>("minGlobalMuonCount");
42  LogDebug("Alignment") << "> GlobalMuonFilter : source, maxTrackDeltaR, min. Count : "
43  << theMuonSource << " , "
44  << theMaxTrackDeltaR << " , "
46  }
47 
48  if (theIsoFilterSwitch) {
49  edm::InputTag theJetIsoSource = cfg.getParameter<InputTag>("jetIsoSource");
50  theJetIsoToken = iC.consumes<reco::CaloJetCollection>(theJetIsoSource);
51  theMaxJetPt = cfg.getParameter<double>("maxJetPt");
52  theMinJetDeltaR = cfg.getParameter<double>("minJetDeltaR");
53  theMinIsolatedCount = cfg.getParameter<int>("minIsolatedCount");
54  LogDebug("Alignment") << "> Isolationtest : source, maxJetPt, minJetDeltaR, min. Count: "
55  << theJetIsoSource << " , "
56  << theMaxJetPt << " ,"
57  << theMinJetDeltaR << " ,"
59  }
60 
62  edm::InputTag theJetCountSource = cfg.getParameter<InputTag>("jetCountSource");
63  theJetCountToken = iC.consumes<reco::CaloJetCollection>(theJetCountSource);
64  theMinJetPt = cfg.getParameter<double>("minJetPt");
65  theMaxJetCount = cfg.getParameter<int>("maxJetCount");
66  LogDebug("Alignment") << "> JetCountFilter : source, minJetPt, maxJetCount : "
67  << theJetCountSource << " , "
68  << theMinJetPt << " ,"
69  << theMaxJetCount;
70  }
71 }
72 
73 // destructor -----------------------------------------------------------------
75 {}
76 
79 {
81 }
82 
83 // do selection ---------------------------------------------------------------
86 {
88 
89  if (theGMFilterSwitch) result = findMuons(result, iEvent);
90  if (theIsoFilterSwitch) result = checkIsolation(result, iEvent);
91  if (theJetCountFilterSwitch) result = checkJetCount(result, iEvent);
92  LogDebug("Alignment") << "> Global: tracks all, kept: " << tracks.size() << ", " << result.size();
93 // LogDebug("Alignment")<<"> o kept:";
94 // printTracks(result);
95 
96  return result;
97 }
98 
102 {
103  Tracks result;
105 
106  //fill globalMuons with muons
108  iEvent.getByToken(theMuonToken, muons);
109 
110  if (muons.isValid()) {
111  for (reco::MuonCollection::const_iterator itMuon = muons->begin();
112  itMuon != muons->end();
113  ++itMuon) {
114  const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
115  if (!muonTrack) {
116  LogDebug("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
117  << "Found muon without track: Standalone Muon!";
118  } else {
119  globalMuons.push_back(muonTrack);
120  }
121  }
122  } else {
123  LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
124  <<"> could not optain mounCollection!";
125  }
126 
127  result = this->matchTracks(tracks, globalMuons);
128 
129  if (static_cast<int>(result.size()) < theMinGlobalMuonCount) result.clear();
130 
131  return result;
132 }
133 
137 {
138  Tracks result; result.clear();
139 
141  iEvent.getByToken(theJetIsoToken, jets);
142 
143  if (jets.isValid()) {
144  for (Tracks::const_iterator it = cands.begin();
145  it!=cands.end();
146  ++it) {
147  bool isolated = true;
148  for (reco::CaloJetCollection::const_iterator itJet = jets->begin();
149  itJet!=jets->end();
150  ++itJet)
151  isolated &= !((*itJet).pt() > theMaxJetPt && deltaR(*(*it),(*itJet)) < theMinJetDeltaR);
152 
153  if (isolated)
154  result.push_back(*it);
155  }
156  // LogDebug("Alignment") << "D Found "<<result.size()<<" isolated of "<< cands.size()<<" Tracks!";
157 
158  } else
159  LogError("Alignment")<< "@SUB=AlignmentGlobalTrackSelector::checkIsolation"
160  << "> could not optain jetCollection!";
161 
162  if (static_cast<int>(result.size()) < theMinIsolatedCount) result.clear();
163 
164  return result;
165 }
166 
170 {
171  Tracks result; result.clear();
172 
174  iEvent.getByToken(theJetCountToken, jets);
175 
176  if (jets.isValid()) {
177  int jetCount = 0;
178  for (reco::CaloJetCollection::const_iterator itJet = jets->begin();
179  itJet!=jets->end();
180  ++itJet) {
181  if ((*itJet).pt() > theMinJetPt)
182  jetCount++;
183  }
184 
185  if (jetCount <= theMaxJetCount)
186  result = tracks;
187 
188  LogDebug("Alignment") << "> found " << jetCount << " Jets";
189  } else
190  LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::checkJetCount"
191  << "> could not optain jetCollection!";
192 
193  return result;
194 }
195 
196 //===================HELPERS===================
197 
201 {
202  Tracks result;
203  for (Tracks::const_iterator itComp = comp.begin();
204  itComp!=comp.end();
205  ++itComp) {
206  int match = -1;
207  double min = theMaxTrackDeltaR;
208  for (unsigned int i=0;i<src.size();i++) {
209  // LogDebug("Alignment") << "> Trackmatch dist: "<<deltaR(src.at(i),*itComp);
210  if(min > deltaR(*(src.at(i)),*(*itComp))){
211  min = deltaR(*(src.at(i)),*(*itComp));
212  match = static_cast<int>(i);
213  }
214  }
215  if (match > -1)
216  result.push_back(src.at(match));
217  }
218  return result;
219 }
220 
223 {
224  int count = 0;
225  LogDebug("Alignment") << ">......................................";
226  for (Tracks::const_iterator it = col.begin();
227  it < col.end();
228  ++it,++count) {
229  LogDebug("Alignment")
230  << "> Track No. " << count << ": p = ("
231  << (*it)->px() << ","
232  << (*it)->py() << ","
233  << (*it)->pz() << ")\n"
234  << "> pT = "
235  << (*it)->pt() << " eta = "
236  << (*it)->eta() << " charge = "
237  << (*it)->charge();
238  }
239  LogDebug("Alignment") << ">......................................";
240 }
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
AlignmentGlobalTrackSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
constructor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Tracks findMuons(const Tracks &tracks, const edm::Event &iEvent) const
filter for Tracks that match the Track of a global Muon
std::vector< const reco::Track * > Tracks
edm::EDGetTokenT< reco::CaloJetCollection > theJetCountToken
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int iEvent
Definition: GenABIO.cc:230
Tracks select(const Tracks &tracks, const edm::Event &iEvent, const edm::EventSetup &eSetup)
select tracks
vector< PseudoJet > jets
Tracks checkJetCount(const Tracks &cands, const edm::Event &iEvent) const
returns [tracks] if there are less than theMaxCount Jets with theMinJetPt and an empty set if not ...
void printTracks(const Tracks &col) const
print Information on Track-Collection
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< reco::MuonCollection > theMuonToken
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
Tracks checkIsolation(const Tracks &cands, const edm::Event &iEvent) const
returns only isolated tracks in [cands]
HLT enums.
col
Definition: cuy.py:1009
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
bool useThisFilter()
returns if any of the Filters is used.
edm::EDGetTokenT< reco::CaloJetCollection > theJetIsoToken
Tracks matchTracks(const Tracks &src, const Tracks &comp) const
matches [src] with [comp] returns collection with matching Tracks coming from [src] ...
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects