CMS 3D CMS Logo

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