test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QuarkoniaTrackSelector.cc
Go to the documentation of this file.
2 
4 
8 
11 
12 
14 
15 #include <memory>
16 #include <iostream>
17 #include <sstream>
18 
20  muonTag_(iConfig.getParameter<edm::InputTag>("muonCandidates")),
21  trackTag_(iConfig.getParameter<edm::InputTag>("tracks")),
22  minMasses_(iConfig.getParameter< std::vector<double> >("MinMasses")),
23  maxMasses_(iConfig.getParameter< std::vector<double> >("MaxMasses")),
24  checkCharge_(iConfig.getParameter<bool>("checkCharge")),
25  minTrackPt_(iConfig.getParameter<double>("MinTrackPt")),
26  minTrackP_(iConfig.getParameter<double>("MinTrackP")),
27  maxTrackEta_(iConfig.getParameter<double>("MaxTrackEta"))
28 {
29 
30 
31  muonToken_ = consumes<reco::RecoChargedCandidateCollection>(muonTag_);
32  trackToken_ = consumes<reco::TrackCollection>(trackTag_);
33 
34 
35  //register your products
36  produces<reco::TrackCollection>();
37  //
38  // verify mass windows
39  //
40  bool massesValid = minMasses_.size()==maxMasses_.size();
41  if ( massesValid ) {
42  for ( size_t i=0; i<minMasses_.size(); ++i ) {
43  if ( minMasses_[i]<0 || maxMasses_[i]<0 ||
44  minMasses_[i]>maxMasses_[i] ) massesValid = false;
45  }
46  }
47  if ( !massesValid ) {
48  edm::LogError("QuarkoniaTrackSelector") << "Inconsistency in definition of mass windows, "
49  << "no track will be selected";
50  minMasses_.clear();
51  maxMasses_.clear();
52  }
53 
54  std::ostringstream stream;
55  stream << "instantiated with parameters\n"
56  << " muonTag = " << muonTag_ << "\n"
57  << " trackTag = " << trackTag_ << "\n";
58  stream << " mass windows =";
59  for ( size_t i=0; i<minMasses_.size(); ++i )
60  stream << " (" << minMasses_[i] << "," << maxMasses_[i] << ")";
61  stream << "\n";
62  stream << " checkCharge = " << checkCharge_ << "\n";
63  stream << " MinTrackPt = " << minTrackPt_ << "\n";
64  stream << " MinTrackP = " << minTrackP_ << "\n";
65  stream << " MaxTrackEta = " << maxTrackEta_;
66  LogDebug("QuarkoniaTrackSelector") << stream.str();
67 }
68 
69 
70 void
72 {
73  //
74  // the product
75  //
76  std::auto_ptr<reco::TrackCollection> product(new reco::TrackCollection);
77  //
78  // Muons
79  //
81  iEvent.getByToken(muonToken_,muonHandle);
82  //
83  // Tracks
84  //
86  iEvent.getByToken(trackToken_,trackHandle);
87  //
88  // Verification
89  //
90  if ( !muonHandle.isValid() || !trackHandle.isValid() || minMasses_.empty() ) {
91  iEvent.put(product);
92  return;
93  }
94  //
95  // Debug output
96  //
97  if ( edm::isDebugEnabled() ) {
98  std::ostringstream stream;
99  stream << "\nInput muons: # / q / pt / p / eta\n";
100  for ( size_t im=0; im<muonHandle->size(); ++im ) {
101  const reco::RecoChargedCandidate& muon = (*muonHandle)[im];
102  stream << " " << im << " "
103  << muon.charge() << " " << muon.pt() << " "
104  << muon.p() << " " << muon.eta() << "\n";
105  }
106  stream << "Input tracks: # / q / pt / p / eta\n";
107  for ( size_t it=0; it<trackHandle->size(); ++it ) {
108  const reco::Track& track = (*trackHandle)[it];
109  stream << " " << it << " "
110  << track.charge() << " " << track.pt() << " "
111  << track.p() << " " << track.eta() << "\n";
112  }
113  LogDebug("QuarkoniaTrackSelector") << stream.str();
114  }
115  //
116  // combinations
117  //
118 // std::ostringstream stream;
119  unsigned int nQ(0);
120  unsigned int nComb(0);
121  std::vector<size_t> selectedTrackIndices;
122  selectedTrackIndices.reserve(muonHandle->size());
125  // muons
126  for ( size_t im=0; im<muonHandle->size(); ++im ) {
127  const reco::RecoChargedCandidate& muon = (*muonHandle)[im];
128  int qMuon = muon.charge();
129  p4Muon = muon.p4();
130  // tracks
131  for ( size_t it=0; it<trackHandle->size(); ++it ) {
132  const reco::Track& track = (*trackHandle)[it];
133  if ( track.pt()<minTrackPt_ || track.p()<minTrackP_ ||
134  fabs(track.eta())>maxTrackEta_ ) continue;
135  if ( checkCharge_ && track.charge()!=-qMuon ) continue;
136  ++nQ;
137  reco::Particle::LorentzVector p4Track(track.px(),track.py(),track.pz(),
138  sqrt(track.p()*track.p()+0.0111636));
139  // mass windows
140  double mass = (p4Muon+p4Track).mass();
141 // stream << "Combined mass = " << im << " " << it
142 // << " " << mass
143 // << " phi " << track.phi() << "\n";
144  for ( size_t j=0; j<minMasses_.size(); ++j ) {
145  if ( mass>minMasses_[j] && mass<maxMasses_[j] ) {
146  ++nComb;
147  if ( find(selectedTrackIndices.begin(),selectedTrackIndices.end(),it)==
148  selectedTrackIndices.end() ) selectedTrackIndices.push_back(it);
149 // stream << "... adding " << "\n";
150  break;
151  }
152  }
153  }
154  }
155 // LogDebug("QuarkoniaTrackSelector") << stream.str();
156  //
157  // filling of output collection
158  //
159  for ( size_t i=0; i<selectedTrackIndices.size(); ++i )
160  product->push_back((*trackHandle)[selectedTrackIndices[i]]);
161  //
162  // debug output
163  //
164  if ( edm::isDebugEnabled() ) {
165  std::ostringstream stream;
166  stream << "Total number of combinations = " << muonHandle->size()*trackHandle->size()
167  << " , after charge " << nQ << " , after mass " << nComb << std::endl;
168  stream << "Selected " << product->size() << " tracks with # / q / pt / eta\n";
169  for ( size_t i=0; i<product->size(); ++i ) {
170  const reco::Track& track = (*product)[i];
171  stream << " " << i << " " << track.charge() << " "
172  << track.pt() << " " << track.eta() << "\n";
173  }
174  LogDebug("QuarkoniaTrackSelector") << stream.str();
175  }
176  //
177  iEvent.put(product);
178 }
179 
180 
181 //define this as a plug-in
#define LogDebug(id)
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muonToken_
double p() const
momentum vector magnitude
Definition: TrackBase.h:602
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
virtual double p() const
magnitude of momentum vector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< double > minMasses_
lower mass limits
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:614
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
std::vector< double > maxMasses_
upper mass limits
QuarkoniaTrackSelector(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:638
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
T sqrt(T t)
Definition: SSEVec.h:48
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
double pt() const
track transverse momentum
Definition: TrackBase.h:608
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:75
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:626
edm::EDGetTokenT< reco::TrackCollection > trackToken_
double minTrackP_
track p cut
int charge() const
track electric charge
Definition: TrackBase.h:554
edm::InputTag trackTag_
tag for TrackCollection
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
double minTrackPt_
track pt cut
edm::InputTag muonTag_
tag for RecoChargedCandidateCollection
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:620
bool checkCharge_
check opposite charge?
double maxTrackEta_
track |eta| cut