CMS 3D CMS Logo

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
QuarkoniaTrackSelector::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: QuarkoniaTrackSelector.cc:64
edm::StreamID
Definition: StreamID.h:30
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
MessageLogger.h
muon
Definition: MuonCocktails.h:17
QuarkoniaTrackSelector::minTrackP_
double minTrackP_
track p cut
Definition: QuarkoniaTrackSelector.h:35
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition: HistoContainer.h:51
QuarkoniaTrackSelector::trackToken_
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: QuarkoniaTrackSelector.h:29
QuarkoniaTrackSelector.h
QuarkoniaTrackSelector
Definition: QuarkoniaTrackSelector.h:17
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< reco::RecoChargedCandidateCollection >
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
QuarkoniaTrackSelector::trackTag_
edm::InputTag trackTag_
tag for TrackCollection
Definition: QuarkoniaTrackSelector.h:27
reco::Track
Definition: Track.h:27
QuarkoniaTrackSelector::muonToken_
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muonToken_
Definition: QuarkoniaTrackSelector.h:28
QuarkoniaTrackSelector::minTrackPt_
double minTrackPt_
track pt cut
Definition: QuarkoniaTrackSelector.h:34
QuarkoniaTrackSelector::muonTag_
edm::InputTag muonTag_
tag for RecoChargedCandidateCollection
Definition: QuarkoniaTrackSelector.h:26
QuarkoniaTrackSelector::checkCharge_
bool checkCharge_
check opposite charge?
Definition: QuarkoniaTrackSelector.h:33
QuarkoniaTrackSelector::maxTrackEta_
double maxTrackEta_
track |eta| cut
Definition: QuarkoniaTrackSelector.h:36
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
MessageDrop.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
reco::RecoChargedCandidate
Definition: RecoChargedCandidate.h:15
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
QuarkoniaTrackSelector::minMasses_
std::vector< double > minMasses_
lower mass limits
Definition: QuarkoniaTrackSelector.h:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
QuarkoniaTrackSelector::maxMasses_
std::vector< double > maxMasses_
upper mass limits
Definition: QuarkoniaTrackSelector.h:32
Frameworkfwd.h
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::isDebugEnabled
bool isDebugEnabled()
Definition: MessageLogger.cc:12
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
QuarkoniaTrackSelector::QuarkoniaTrackSelector
QuarkoniaTrackSelector(const edm::ParameterSet &)
Definition: QuarkoniaTrackSelector.cc:18