CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Tau3MuReco Class Reference

#include <Tau3MuReco.h>

Public Member Functions

bool doTau3MuReco (const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::MuonCollection *muonCollection, reco::TrackCollection *trackCollection)
 
 Tau3MuReco (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
 ~Tau3MuReco ()
 

Private Member Functions

bool check4MuonTrack (const reco::Track &track)
 
bool find3rdTrack (const edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackCollection &Tracks)
 
bool findCorrectPairing ()
 
double getDeltaR (const reco::Track &track1, const reco::Track &track2)
 
double getInvariantMass (const reco::TrackCollection *tracks, const double MuonMass=0.106)
 
bool removeIncorrectMuon ()
 

Private Attributes

const double m_kMatchingDeltaR
 
const double m_kMatchingPt
 
const double m_kMuonMass
 
const edm::EDGetTokenT< reco::MuonCollectionm_kMuonSourceToken
 
const double m_kTauMass
 
const double m_kTauMassCut
 
const edm::EDGetTokenT< reco::TrackCollectionm_kTrackSourceToken
 
reco::MuonCollectionm_MuonCollection
 
reco::TrackCollectionm_TrackCollection
 

Detailed Description

Definition at line 13 of file Tau3MuReco.h.

Constructor & Destructor Documentation

Tau3MuReco::Tau3MuReco ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 9 of file Tau3MuReco.cc.

10  : m_kMatchingDeltaR(iConfig.getParameter<double>("RecoAnalysisMatchingDeltaR")),
11  m_kMatchingPt(iConfig.getParameter<double>("RecoAnalysisMatchingPt")),
12  m_kTauMassCut(iConfig.getParameter<double>("RecoAnalysisTauMassCut")),
13  m_kTauMass(iConfig.getParameter<double>("RecoAnalysisTauMass")),
14  m_kMuonMass(iConfig.getParameter<double>("RecoAnalysisMuonMass")),
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const double m_kTauMass
Definition: Tau3MuReco.h:38
const double m_kMatchingPt
Definition: Tau3MuReco.h:36
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const double m_kMatchingDeltaR
Definition: Tau3MuReco.h:35
const double m_kTauMassCut
Definition: Tau3MuReco.h:37
const double m_kMuonMass
Definition: Tau3MuReco.h:39
const edm::EDGetTokenT< reco::MuonCollection > m_kMuonSourceToken
Definition: Tau3MuReco.h:41
const edm::EDGetTokenT< reco::TrackCollection > m_kTrackSourceToken
Definition: Tau3MuReco.h:42
Tau3MuReco::~Tau3MuReco ( )

Definition at line 18 of file Tau3MuReco.cc.

18 {}

Member Function Documentation

bool Tau3MuReco::check4MuonTrack ( const reco::Track track)
private

Definition at line 76 of file Tau3MuReco.cc.

References reco::TrackBase::charge(), getDeltaR(), LogDebug, m_kMatchingDeltaR, m_kMatchingPt, m_TrackCollection, and reco::TrackBase::pt().

Referenced by find3rdTrack().

76  {
77  reco::TrackCollection::const_iterator iter;
78 
79  for (iter = m_TrackCollection->begin(); iter != m_TrackCollection->end(); iter++) {
80  //check if the track has the right charge
81  //and check if dR is smaller than fMatchingDeltaR
82  if ((*iter).charge() == track.charge() && getDeltaR(*iter, track) < m_kMatchingDeltaR &&
83  fabs(((*iter).pt()) - (track.pt())) <= (track.pt() * m_kMatchingPt)) {
84  LogDebug("Tau3MuReco") << "Found muon track in Tracks with DeltaR: " << getDeltaR(*iter, track)
85  << " Pt: " << track.pt() << " Muons Pt is: " << (*iter).pt() << std::endl;
86  return true;
87  }
88  }
89  return false;
90 }
#define LogDebug(id)
double getDeltaR(const reco::Track &track1, const reco::Track &track2)
Definition: Tau3MuReco.cc:282
const double m_kMatchingPt
Definition: Tau3MuReco.h:36
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45
const double m_kMatchingDeltaR
Definition: Tau3MuReco.h:35
double pt() const
track transverse momentum
Definition: TrackBase.h:602
int charge() const
track electric charge
Definition: TrackBase.h:575
bool Tau3MuReco::doTau3MuReco ( const edm::Event iEvent,
const edm::EventSetup iSetup,
reco::MuonCollection muonCollection,
reco::TrackCollection trackCollection 
)

Definition at line 20 of file Tau3MuReco.cc.

References find3rdTrack(), findCorrectPairing(), edm::Event::getByToken(), getInvariantMass(), LogDebug, m_kMuonMass, m_kMuonSourceToken, m_kTauMass, m_kTauMassCut, m_kTrackSourceToken, m_MuonCollection, m_TrackCollection, HLT_2018_cff::muon, pdwgLeptonRecoSkim_cfi::muonCollection, PDWG_BPHSkim_cff::muons, edm::Handle< T >::product(), removeIncorrectMuon(), duplicaterechits_cfi::trackCollection, and PDWG_EXOHSCP_cff::tracks.

Referenced by Tau3MuSkim::filter().

23  {
26 
29 
30  reco::MuonCollection::const_iterator muon;
31 
32  iEvent.getByToken(m_kMuonSourceToken, muons);
33  iEvent.getByToken(m_kTrackSourceToken, tracks);
34 
35  for (muon = muons->begin(); muon != muons->end(); ++muon) {
36  m_TrackCollection->push_back(*(muon->track().get()));
37  m_MuonCollection->push_back(*muon);
38  }
39 
40  if (m_TrackCollection->size() > 3) {
41  //find the right three ones coming from tau
42  if (findCorrectPairing() == false) { //maybe implement something like in ==3 (throw away ....)
43  LogDebug("Tau3MuReco") << "Could not find correct combination!" << std::endl;
44  return false;
45  }
46 
47  return true;
48  }
49 
50  if (m_TrackCollection->size() == 3) {
52  return true;
53  else //throw away one muon which don't match
55  }
56 
57  if (m_TrackCollection->size() == 2) {
58  //search the third track
59 
60  //get 3rd muon canidate from tracks
61  if (find3rdTrack(iEvent, iSetup, *(tracks.product())) == false) {
62  LogDebug("Tau3MuReco") << "A 3rd Track can not be assigned!" << std::endl;
63  return false;
64  } else
65  return true;
66  }
67 
68  // cannot use this event, because less than 2 muons have been found
69 
70  LogDebug("Tau3MuReco") << "Not enough (" << m_TrackCollection->size() << ") muons found! Event skipped!" << std::endl;
71 
72  return false;
73 }
#define LogDebug(id)
double getInvariantMass(const reco::TrackCollection *tracks, const double MuonMass=0.106)
Definition: Tau3MuReco.cc:260
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const double m_kTauMass
Definition: Tau3MuReco.h:38
bool find3rdTrack(const edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackCollection &Tracks)
Definition: Tau3MuReco.cc:92
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45
bool findCorrectPairing()
Definition: Tau3MuReco.cc:197
T const * product() const
Definition: Handle.h:69
const double m_kTauMassCut
Definition: Tau3MuReco.h:37
const double m_kMuonMass
Definition: Tau3MuReco.h:39
bool removeIncorrectMuon()
Definition: Tau3MuReco.cc:237
const edm::EDGetTokenT< reco::MuonCollection > m_kMuonSourceToken
Definition: Tau3MuReco.h:41
const edm::EDGetTokenT< reco::TrackCollection > m_kTrackSourceToken
Definition: Tau3MuReco.h:42
reco::MuonCollection * m_MuonCollection
Definition: Tau3MuReco.h:44
bool Tau3MuReco::find3rdTrack ( const edm::Event iEvent,
const edm::EventSetup iSetup,
const reco::TrackCollection Tracks 
)
private

Definition at line 92 of file Tau3MuReco.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, check4MuonTrack(), KineDebug3::count(), getDeltaR(), getInvariantMass(), LogDebug, m_kTauMass, m_kTauMassCut, m_TrackCollection, TrackCollections2monitor_cff::normalizedChi2, and HLT_2018_cff::track.

Referenced by doTau3MuReco().

94  {
95  //check size of TrackVector (should be two!)
96  if (m_TrackCollection->size() != 2)
97  return false;
98 
99  //more then two tracks should be in the event
100  if (Tracks.size() <= 2)
101  return false;
102 
103  double SumDeltaR = 0;
104 
105  double MuonDeltaR = getDeltaR(m_TrackCollection->at(0), m_TrackCollection->at(1));
106 
107  //Loop overall tracks
108 
109  LogDebug("Tau3MuReco") << "Number of tracks found: " << Tracks.size() << std::endl;
110 
111  std::multimap<double, const reco::Track> TrackMultiMap;
112 
113  unsigned short muonCounter = 0;
114 
115  reco::TrackCollection::const_iterator track;
116 
117  for (track = Tracks.begin(); track != Tracks.end(); track++) {
118  if (check4MuonTrack(*track)) {
119  muonCounter++;
120  continue;
121  }
122 
123  SumDeltaR = MuonDeltaR;
124 
125  SumDeltaR += getDeltaR(m_TrackCollection->at(1), *track);
126  SumDeltaR += getDeltaR(*track, m_TrackCollection->at(0));
127 
128  std::pair<double, const reco::Track> actTrack(SumDeltaR, *track);
129 
130  TrackMultiMap.insert(actTrack);
131  }
132 
133  //two tracks should be clearly identified as muons by check4MuonTrack
134  //else event is not useable
135  if (muonCounter < 2) {
136  LogDebug("Tau3MuReco") << "Not enough muons (" << muonCounter << ") assigned to a track! Event skipped!"
137  << std::endl;
138  return false;
139  }
140 
141  std::multimap<double, const reco::Track>::iterator it = TrackMultiMap.begin();
142 
143  if (it == TrackMultiMap.end()) {
144  LogDebug("Tau3MuReco") << "Not enough tracks (0) left! Event skipped!" << std::endl;
145  return false;
146  }
147 
148  //get 2mu+track with minimal DeltaR Sum (MultiMaps are sorted)
149  m_TrackCollection->push_back((*it).second);
150 
151  //and check charge of this track
152  //and check invariant mass of this combination
153  //and make a vertex fit
154 
155  char Charge = m_TrackCollection->at(0).charge() * m_TrackCollection->at(1).charge();
156 
157  unsigned int count = 0;
158 
159  //Charge > 0 means the two muons have same charge, so the third track has to have the opposit charge
160  while ((Charge > 0 && ((*it).second).charge() == (m_TrackCollection->at(0)).charge()) ||
162  count++;
163 
164  LogDebug("Tau3MuReco") << "Track canidate: " << count << std::endl;
165 
166  if (Charge > 0 && ((*it).second).charge() != (m_TrackCollection->at(0)).charge())
167  LogDebug("Tau3MuReco") << "\tWrong charge!" << std::endl;
168  LogDebug("Tau3MuReco") << "\tInvariant Mass deviation! " << fabs(getInvariantMass(m_TrackCollection) - m_kTauMass)
169  << std::endl;
170  LogDebug("Tau3MuReco") << "\tTrack Pt: " << (*it).second.pt() << std::endl;
171  LogDebug("Tau3MuReco") << "\tDelta R: " << (*it).first << std::endl;
172  LogDebug("Tau3MuReco") << "\tChi2: " << ((*it).second).normalizedChi2() << std::endl;
173 
174  ++it;
175 
176  //was not the best canidate
177  m_TrackCollection->pop_back();
178 
179  if (it == TrackMultiMap.end())
180  return false;
181 
182  //get next to minimal (Delta R Sum) track
183  m_TrackCollection->push_back((*it).second);
184  }
185 
186  LogDebug("Tau3MuReco") << "Found corresponding 3rd track: " << std::endl;
187  LogDebug("Tau3MuReco") << "Track canidate: " << count << std::endl;
188  LogDebug("Tau3MuReco") << "\tInvariant Mass deviation! " << fabs(getInvariantMass(m_TrackCollection) - m_kTauMass)
189  << std::endl;
190  LogDebug("Tau3MuReco") << "\tDelta R: " << (*it).first << std::endl;
191  LogDebug("Tau3MuReco") << "\tNormChi2: " << ((*it).second).normalizedChi2() << std::endl;
192 
193  //choose this track, because it is the best canidate
194  return true;
195 }
#define LogDebug(id)
double getDeltaR(const reco::Track &track1, const reco::Track &track2)
Definition: Tau3MuReco.cc:282
double getInvariantMass(const reco::TrackCollection *tracks, const double MuonMass=0.106)
Definition: Tau3MuReco.cc:260
const double m_kTauMass
Definition: Tau3MuReco.h:38
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45
const double m_kTauMassCut
Definition: Tau3MuReco.h:37
bool check4MuonTrack(const reco::Track &track)
Definition: Tau3MuReco.cc:76
bool Tau3MuReco::findCorrectPairing ( )
private

Definition at line 197 of file Tau3MuReco.cc.

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, Combinatorics::GetCombinations(), getInvariantMass(), mps_fire::i, createfilelist::int, LogDebug, m_kTauMass, m_kTauMassCut, m_MuonCollection, and m_TrackCollection.

Referenced by doTau3MuReco().

197  {
198  Combinatorics myCombinatorics(m_TrackCollection->size(), 3);
199 
200  std::vector<std::vector<UInt_t> > CombinationVec = myCombinatorics.GetCombinations();
201 
202  std::vector<std::vector<UInt_t> >::iterator it = CombinationVec.begin();
203 
204  char Charge = 0;
205 
206  reco::TrackCollection tempTrackCollection;
207  reco::MuonCollection tempMuonCollection;
208 
209  do {
210  if (it == CombinationVec.end())
211  return false;
212 
213  Charge = 0;
214 
215  tempMuonCollection.clear();
216  tempTrackCollection.clear();
217 
218  for (UInt_t i = 0; i < (*it).size(); i++) {
219  Charge += m_TrackCollection->at((*it).at(i)).charge();
220  tempTrackCollection.push_back(m_TrackCollection->at((*it).at(i)));
221  tempMuonCollection.push_back(m_MuonCollection->at((*it).at(i)));
222  }
223 
224  LogDebug("Tau3MuReco") << "Charge is: " << (int)Charge << " Have to be -1 or 1!!!" << std::endl;
225  LogDebug("Tau3MuReco") << "Invariant mass is: " << fabs(getInvariantMass(&tempTrackCollection) - m_kTauMass)
226  << " Have to be smaller than " << m_kTauMassCut << std::endl;
227 
228  it++;
229  } while (abs(Charge) != 1 || fabs(getInvariantMass(&tempTrackCollection) - m_kTauMass) > m_kTauMassCut);
230 
231  *m_MuonCollection = tempMuonCollection;
232  *m_TrackCollection = tempTrackCollection;
233 
234  return true;
235 }
#define LogDebug(id)
std::vector< std::vector< UInt_t > > GetCombinations()
double getInvariantMass(const reco::TrackCollection *tracks, const double MuonMass=0.106)
Definition: Tau3MuReco.cc:260
const double m_kTauMass
Definition: Tau3MuReco.h:38
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double m_kTauMassCut
Definition: Tau3MuReco.h:37
reco::MuonCollection * m_MuonCollection
Definition: Tau3MuReco.h:44
double Tau3MuReco::getDeltaR ( const reco::Track track1,
const reco::Track track2 
)
private

Definition at line 282 of file Tau3MuReco.cc.

References HLT_2018_cff::dEta, HLT_2018_cff::dPhi, reco::TrackBase::eta(), reco::TrackBase::phi(), Pi, funct::pow(), and mathSSE::sqrt().

Referenced by check4MuonTrack(), find3rdTrack(), and removeIncorrectMuon().

282  {
283  double dEta = track1.eta() - track2.eta();
284  double dPhi = track1.phi() - track2.phi();
285 
286  while (dPhi >= TMath::Pi())
287  dPhi -= (2.0 * TMath::Pi());
288  while (dPhi < (-1.0 * TMath::Pi()))
289  dPhi += (2.0 * TMath::Pi());
290 
291  return sqrt(pow(dEta, 2) + pow(dPhi, 2));
292 }
const double Pi
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:614
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
T sqrt(T t)
Definition: SSEVec.h:19
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
double Tau3MuReco::getInvariantMass ( const reco::TrackCollection tracks,
const double  MuonMass = 0.106 
)
private

Definition at line 260 of file Tau3MuReco.cc.

References mps_fire::i, funct::pow(), and mathSSE::sqrt().

Referenced by doTau3MuReco(), find3rdTrack(), and findCorrectPairing().

260  {
261  unsigned int numOfParticles = tracks->size();
262 
263  double SumPx = 0;
264  double SumPy = 0;
265  double SumPz = 0;
266 
267  double SumE = 0;
268 
269  for (unsigned int i = 0; i < numOfParticles; i++) {
270  SumPx += tracks->at(i).px();
271  SumPy += tracks->at(i).py();
272  SumPz += tracks->at(i).pz();
273 
274  SumE += sqrt(pow(tracks->at(i).p(), 2) + pow(MuonMass, 2));
275  }
276 
277  double invmass = sqrt(pow(SumE, 2) - pow(SumPx, 2) - pow(SumPy, 2) - pow(SumPz, 2));
278 
279  return invmass;
280 }
T sqrt(T t)
Definition: SSEVec.h:19
const double MuonMass
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
bool Tau3MuReco::removeIncorrectMuon ( )
private

Definition at line 237 of file Tau3MuReco.cc.

References getDeltaR(), m_TrackCollection, and groupFilesInBlocks::temp.

Referenced by doTau3MuReco().

237  {
238  double deltaR12 = getDeltaR(m_TrackCollection->at(0), m_TrackCollection->at(1));
239  double deltaR23 = getDeltaR(m_TrackCollection->at(1), m_TrackCollection->at(2));
240  double deltaR31 = getDeltaR(m_TrackCollection->at(2), m_TrackCollection->at(0));
241 
242  //if DeltaR12 is the smallest, than the 3rd one seems to be wrong
243  //if DeltaR23 is the smallest, than the 2nd one seems to be wrong
244  //if DeltaR31 is the smallest, than the 1st one seems to be wrong
245 
246  unsigned char temp;
247  double junk;
248 
249  deltaR12 < deltaR23 ? temp = 3 : temp = 1;
250  deltaR12 < deltaR23 ? junk = deltaR12 : junk = deltaR23;
251 
252  if (deltaR31 < junk)
253  temp = 2;
254 
255  m_TrackCollection->erase(m_TrackCollection->begin() + temp - 1);
256 
257  return true;
258 }
double getDeltaR(const reco::Track &track1, const reco::Track &track2)
Definition: Tau3MuReco.cc:282
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45

Member Data Documentation

const double Tau3MuReco::m_kMatchingDeltaR
private

Definition at line 35 of file Tau3MuReco.h.

Referenced by check4MuonTrack().

const double Tau3MuReco::m_kMatchingPt
private

Definition at line 36 of file Tau3MuReco.h.

Referenced by check4MuonTrack().

const double Tau3MuReco::m_kMuonMass
private

Definition at line 39 of file Tau3MuReco.h.

Referenced by doTau3MuReco().

const edm::EDGetTokenT<reco::MuonCollection> Tau3MuReco::m_kMuonSourceToken
private

Definition at line 41 of file Tau3MuReco.h.

Referenced by doTau3MuReco().

const double Tau3MuReco::m_kTauMass
private

Definition at line 38 of file Tau3MuReco.h.

Referenced by doTau3MuReco(), find3rdTrack(), and findCorrectPairing().

const double Tau3MuReco::m_kTauMassCut
private

Definition at line 37 of file Tau3MuReco.h.

Referenced by doTau3MuReco(), find3rdTrack(), and findCorrectPairing().

const edm::EDGetTokenT<reco::TrackCollection> Tau3MuReco::m_kTrackSourceToken
private

Definition at line 42 of file Tau3MuReco.h.

Referenced by doTau3MuReco().

reco::MuonCollection* Tau3MuReco::m_MuonCollection
private

Definition at line 44 of file Tau3MuReco.h.

Referenced by doTau3MuReco(), and findCorrectPairing().

reco::TrackCollection* Tau3MuReco::m_TrackCollection
private