CMS 3D CMS Logo

Tau3MuReco.cc
Go to the documentation of this file.
1 #include <TMath.h>
2 
4 
6 
8 
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")),
15  m_kMuonSourceToken(iC.consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("MuonSourceTag"))),
16  m_kTrackSourceToken(iC.consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("TrackSourceTag"))) {}
17 
19 
21  const edm::EventSetup& iSetup,
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 }
74 
75 //private
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 }
91 
93  const edm::EventSetup& iSetup,
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 }
196 
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 }
236 
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 }
259 
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 }
281 
282 double Tau3MuReco::getDeltaR(const reco::Track& track1, const reco::Track& track2) {
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 }
Tau3MuReco::m_kMatchingPt
const double m_kMatchingPt
Definition: Tau3MuReco.h:36
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
Tau3MuReco::findCorrectPairing
bool findCorrectPairing()
Definition: Tau3MuReco.cc:197
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
MuonMass
const double MuonMass
Definition: CosmicMuonParameters.h:24
MessageLogger.h
Tau3MuReco::getDeltaR
double getDeltaR(const reco::Track &track1, const reco::Track &track2)
Definition: Tau3MuReco.cc:282
muon
Definition: MuonCocktails.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
Tau3MuReco::doTau3MuReco
bool doTau3MuReco(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::MuonCollection *muonCollection, reco::TrackCollection *trackCollection)
Definition: Tau3MuReco.cc:20
Tau3MuReco::m_kMuonMass
const double m_kMuonMass
Definition: Tau3MuReco.h:39
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLT_FULL_cff.dPhi
dPhi
Definition: HLT_FULL_cff.py:13768
edm::Handle< reco::MuonCollection >
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
Tau3MuReco::find3rdTrack
bool find3rdTrack(const edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackCollection &Tracks)
Definition: Tau3MuReco.cc:92
Tau3MuReco::~Tau3MuReco
~Tau3MuReco()
Definition: Tau3MuReco.cc:18
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11776
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Combinatorics
Definition: Combinatorics.h:17
reco::Track
Definition: Track.h:27
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
Tau3MuReco::check4MuonTrack
bool check4MuonTrack(const reco::Track &track)
Definition: Tau3MuReco.cc:76
Tau3MuReco.h
reco::TrackBase::phi
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
Tau3MuReco::m_kTauMassCut
const double m_kTauMassCut
Definition: Tau3MuReco.h:37
Tau3MuReco::m_kMuonSourceToken
const edm::EDGetTokenT< reco::MuonCollection > m_kMuonSourceToken
Definition: Tau3MuReco.h:41
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
Tau3MuReco::Tau3MuReco
Tau3MuReco(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
Definition: Tau3MuReco.cc:9
reco::TrackBase::eta
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
Combinatorics::GetCombinations
std::vector< std::vector< UInt_t > > GetCombinations()
Definition: Combinatorics.cc:159
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
gather_cfg.Tracks
Tracks
Definition: gather_cfg.py:251
edm::EventSetup
Definition: EventSetup.h:57
TrackCollections2monitor_cff.normalizedChi2
normalizedChi2
Definition: TrackCollections2monitor_cff.py:247
pdwgLeptonRecoSkim_cfi.muonCollection
muonCollection
Definition: pdwgLeptonRecoSkim_cfi.py:7
Combinatorics.h
Tau3MuReco::getInvariantMass
double getInvariantMass(const reco::TrackCollection *tracks, const double MuonMass=0.106)
Definition: Tau3MuReco.cc:260
HLT_FULL_cff.dEta
dEta
Definition: HLT_FULL_cff.py:13767
Tau3MuReco::m_MuonCollection
reco::MuonCollection * m_MuonCollection
Definition: Tau3MuReco.h:44
PixelTestBeamValidation_cfi.Charge
Charge
Definition: PixelTestBeamValidation_cfi.py:91
Tau3MuReco::m_kTrackSourceToken
const edm::EDGetTokenT< reco::TrackCollection > m_kTrackSourceToken
Definition: Tau3MuReco.h:42
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Tau3MuReco::m_kMatchingDeltaR
const double m_kMatchingDeltaR
Definition: Tau3MuReco.h:35
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Tau3MuReco::m_kTauMass
const double m_kTauMass
Definition: Tau3MuReco.h:38
edm::Event
Definition: Event.h:73
Tau3MuReco::m_TrackCollection
reco::TrackCollection * m_TrackCollection
Definition: Tau3MuReco.h:45
Tau3MuReco::removeIncorrectMuon
bool removeIncorrectMuon()
Definition: Tau3MuReco.cc:237
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ConsumesCollector
Definition: ConsumesCollector.h:45