CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignmentGlobalTrackSelector.cc
Go to the documentation of this file.
1 //Framework
5 
6 //DataFormats
13 
14 #include <DataFormats/RecoCandidate/interface/RecoCandidate.h> //for the get<TrackRef>() Call
15 
17 
18 //STL
19 #include <math.h>
20 
22 
23 
24 using namespace std;
25 using namespace edm;
26 
27 // constructor ----------------------------------------------------------------
28 
30  theMuonSource("muons"),
31  theJetIsoSource("fastjet6CaloJets"),
32  theJetCountSource("fastjet6CaloJets")
33 {
34  theIsoFilterSwitch = cfg.getParameter<bool>( "applyIsolationtest" );
35  theGMFilterSwitch = cfg.getParameter<bool>( "applyGlobalMuonFilter" );
36  theJetCountFilterSwitch = cfg.getParameter<bool>( "applyJetCountFilter" );
37  if (theIsoFilterSwitch || theGMFilterSwitch || theJetCountFilterSwitch)
38  LogDebug("Alignment") << "> applying global Trackfilter ...";
39 
40  if (theGMFilterSwitch){
41  theMuonSource = cfg.getParameter<InputTag>( "muonSource" );
42  theMaxTrackDeltaR =cfg.getParameter<double>("maxTrackDeltaR");
43  theMinIsolatedCount = cfg.getParameter<int>("minIsolatedCount");
44  LogDebug("Alignment") << "> GlobalMuonFilter : source, maxTrackDeltaR, min. Count : " << theMuonSource<<" , "<<theMaxTrackDeltaR<<" , "<<theMinIsolatedCount;
45  }else{
48  }
49 
50  if (theIsoFilterSwitch ){
51  theJetIsoSource = cfg.getParameter<InputTag>( "jetIsoSource" );
52  theMaxJetPt = cfg.getParameter<double>( "maxJetPt" );
53  theMinJetDeltaR = cfg.getParameter<double>( "minJetDeltaR" );
54  theMinGlobalMuonCount = cfg.getParameter<int>( "minGlobalMuonCount" );
55  LogDebug("Alignment") << "> Isolationtest : source, maxJetPt, minJetDeltaR, min. Count: " << theJetIsoSource << " , " << theMaxJetPt<<" ," <<theMinJetDeltaR<<" ," <<theMinGlobalMuonCount;
56  }else{
57  theMaxJetPt = 0;
58  theMinJetDeltaR = 0;
60  }
61 
62  if(theJetCountFilterSwitch){
63  theJetCountSource = cfg.getParameter<InputTag>( "jetCountSource" );
64  theMinJetPt = cfg.getParameter<double>( "minJetPt" );
65  theMaxJetCount = cfg.getParameter<int>( "maxJetCount" );
66  LogDebug("Alignment") << "> JetCountFilter : source, minJetPt, maxJetCount : " << theJetCountSource << " , " << theMinJetPt<<" ," <<theMaxJetCount;
67  }
68 
69 
70 }
71 
72 
73 // destructor -----------------------------------------------------------------
74 
76 {}
77 
78 
81 {
83 }
84 
85 // do selection ---------------------------------------------------------------
88 {
90 
91  if(theGMFilterSwitch) result = findMuons(result,iEvent);
92  if(theIsoFilterSwitch) result = checkIsolation(result,iEvent);
93  if(theJetCountFilterSwitch) result = checkJetCount(result,iEvent);
94  LogDebug("Alignment") << "> Global: tracks all,kept: " << tracks.size() << "," << result.size();
95 // LogDebug("Alignment")<<"> o kept:";
96 // printTracks(result);
97 
98  return result;
99 }
100 
104 {
105  Tracks result; result.clear();
106 
108  iEvent.getByLabel(theJetIsoSource ,jets);
109  if(jets.isValid()){
110  for(Tracks::const_iterator it = cands.begin();it < cands.end();++it){
111  bool isolated = true;
112  for(reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end() ; ++itJet)
113  isolated &= !((*itJet).pt() > theMaxJetPt && deltaR(*(*it),(*itJet)) < theMinJetDeltaR);
114 
115  if(isolated)
116  result.push_back(*it);
117  }
118  // LogDebug("Alignment") << "D Found "<<result.size()<<" isolated of "<< cands.size()<<" Tracks!";
119 
120  }else LogError("Alignment")<<"@SUB=AlignmentGlobalTrackSelector::checkIsolation"
121  <<"> could not optain jetCollection!";
122 
123  if(static_cast<int>(result.size()) < theMinIsolatedCount) result.clear();
124  return result;
125 }
126 
130 {
131  Tracks result; result.clear();
133  iEvent.getByLabel(theJetCountSource ,jets);
134  if(jets.isValid()){
135  int jetCount = 0;
136  for(reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end() ; ++itJet){
137  if((*itJet).pt() > theMinJetPt)
138  jetCount++;
139  }
140  if(jetCount <= theMaxJetCount)
141  result = tracks;
142  LogDebug("Alignment")<<"> found "<<jetCount<<" Jets";
143  }else LogError("Alignment")<<"@SUB=AlignmentGlobalTrackSelector::checkJetCount"
144  <<"> could not optain jetCollection!";
145  return result;
146 }
147 
151 {
152  Tracks result;
154 
155  //fill globalMuons with muons
157  iEvent.getByLabel(theMuonSource, muons);
158  if (muons.isValid()) {
159  for(reco::MuonCollection::const_iterator itMuon = muons->begin(); itMuon != muons->end();
160  ++itMuon) {
161  const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
162  if (!muonTrack) {
163  LogDebug("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
164  << "Found muon without track: Standalone Muon!";
165  } else {
166  globalMuons.push_back(muonTrack);
167  }
168  }
169  } else {
170  LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
171  <<"> could not optain mounCollection!";
172  }
173 
174  result = this->matchTracks(tracks, globalMuons);
175 
176  if (static_cast<int>(result.size()) < theMinGlobalMuonCount) result.clear();
177 
178  return result;
179 }
180 
181 //===================HELPERS===================
182 
186 {
187  Tracks result;
188  for(Tracks::const_iterator itComp = comp.begin(); itComp < comp.end();++itComp){
189  int match = -1;
190  double min = theMaxTrackDeltaR;
191  for(unsigned int i =0; i < src.size();i++){
192  // LogDebug("Alignment") << "> Trackmatch dist: "<<deltaR(src.at(i),*itComp);
193  if(min > deltaR(*(src.at(i)),*(*itComp))){
194  min = deltaR(*(src.at(i)),*(*itComp));
195  match = static_cast<int>(i);
196  }
197  }
198  if(match > -1)
199  result.push_back(src.at(match));
200  }
201  return result;
202 }
203 
206 {
207  int count = 0;
208  LogDebug("Alignment") << ">......................................";
209  for(Tracks::const_iterator it = col.begin();it < col.end();++it,++count){
210  LogDebug("Alignment")
211  <<"> Track No. "<< count <<": p = ("<<(*it)->px()<<","<<(*it)->py()<<","<<(*it)->pz()<<")\n"
212  <<"> pT = "<<(*it)->pt()<<" eta = "<<(*it)->eta()<<" charge = "<<(*it)->charge();
213  }
214  LogDebug("Alignment") << ">......................................";
215 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
Tracks findMuons(const Tracks &tracks, const edm::Event &iEvent) const
filter for Tracks that match the Track of a global Muon
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< const reco::Track * > Tracks
int iEvent
Definition: GenABIO.cc:243
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 ...
tuple result
Definition: query.py:137
void printTracks(const Tracks &col) const
print Information on Track-Collection
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
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]
tuple tracks
Definition: testEve_cfg.py:39
AlignmentGlobalTrackSelector(const edm::ParameterSet &cfg)
constructor
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
Tracks select(const Tracks &tracks, const edm::Event &iEvent)
select tracks
bool useThisFilter()
returns if any of the Filters is used.
Tracks matchTracks(const Tracks &src, const Tracks &comp) const
matches [src] with [comp] returns collection with matching Tracks coming from [src] ...
tuple src
Definition: align_tpl.py:87