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