18 #include "HepPDT/ParticleDataTable.hh"
19 #include "AthLinks/ElementLink.h"
51 const HepPDT::ParticleData* pd_mu = particleDataTable->particle(MC::MUON);
56 if (
m_doTagAndProbe)
ATH_MSG_WARNING(
"You have requested tag and probe mode. Duplicate mu+trk pairs WILL be allowed, charge ordering WILL NOT be done. Tag track will be first in each candidate");
60 bool illogicalOptions(
false);
62 ATH_MSG_WARNING(
"You are requesting incompatible combinations of muons and tracks in the pairs. JpsiCandidates will be EMPTY!");
63 illogicalOptions=
true;
66 ATH_MSG_WARNING(
"You are requesting Tag and Probe analysis but have not requested mu+trk mode. This is impossible. JpsiCandidates will be EMPTY!");
67 illogicalOptions=
true;
70 ATH_MSG_WARNING(
"You are requesting a combined muon measurement to be used with pairs involving non-muon tracks. Not permitted. JpsiCandidates will be EMPTY!");
71 illogicalOptions=
true;
74 ATH_MSG_WARNING(
"You are requesting incompatible combinations of combined muons non-combined muons in the pairs. JpsiCandidates will be EMPTY!");
75 illogicalOptions=
true;
78 ATH_MSG_WARNING(
"You are requesting at least one muon to be combined in a tag and probe analysis. This doesn't make sense. JpsiCandidates will be EMPTY!");
79 illogicalOptions=
true;
82 ATH_MSG_WARNING(
"You are requesting incompatible combinations of charges in the pairs. JpsiCandidates will be EMPTY!");
83 illogicalOptions=
true;
87 ATH_MSG_WARNING(
"You are requesting same-sign or all-sign combinations in a tag and probe analysis. This doesn't make sense. JpsiCandidates will be EMPTY!");
88 illogicalOptions=
true;
91 if (illogicalOptions)
return StatusCode::FAILURE;;
96 return StatusCode::SUCCESS;
107 m_atLeastOneComb(true),
108 m_useCombMeasurement(false),
109 m_useV0Fitter(false),
115 m_trkThresholdPt(0.0),
116 m_invMassUpper(100000.0),
118 m_collAngleTheta(0.0),
125 m_doTagAndProbe(false),
126 m_forceTagAndProbe(false)
129 declareInterface<JpsiFinder>(
this);
169 return StatusCode::FAILURE;
176 std::vector<const xAOD::TrackParticleContainer*> importedMuonTrackCollections;
180 if(!handle.isValid()){
181 ATH_MSG_WARNING(
"No muon TrackParticle collection with name " << handle.key() <<
" found in StoreGate!");
182 return StatusCode::FAILURE;
184 ATH_MSG_DEBUG(
"Found muon TrackParticle collection " << handle.key() <<
" in StoreGate!");
185 ATH_MSG_DEBUG(
"Muon TrackParticle container size "<< handle->size());
186 importedMuonTrackCollections.push_back(handle.cptr());
195 ATH_MSG_WARNING(
"No TrackParticle collection with name " << handle.
key() <<
" found in StoreGate!");
196 return StatusCode::FAILURE;
198 importedTrackCollection = handle.
cptr();
199 ATH_MSG_DEBUG(
"Found TrackParticle collection " << handle.
key() <<
" in StoreGate!");
204 typedef std::vector<const xAOD::TrackParticle*>
TrackBag;
205 typedef std::vector<const xAOD::Muon*>
MuonBag;
212 for (trkCItr=importedTrackCollection->begin(); trkCItr!=importedTrackCollection->end(); ++trkCItr) {
216 theIDTracksAfterSelection.push_back(TP);
218 if (theIDTracksAfterSelection.size() == 0)
return StatusCode::SUCCESS;;
219 ATH_MSG_DEBUG(
"Number of tracks after ID track selection: " << theIDTracksAfterSelection.size());
223 MuonBag theMuonsAfterSelection;
225 for (
auto muItr=importedMuonCollection->
begin(); muItr!=importedMuonCollection->
end(); ++muItr) {
226 if ( *muItr == NULL )
continue;
227 if (!(*muItr)->inDetTrackParticleLink().isValid())
continue;
229 if ( muonTrk==NULL)
continue;
234 if ( (*muItr)->muonType() == xAOD::Muon::SiliconAssociatedForwardMuon && !
m_useCombMeasurement)
continue;
235 theMuonsAfterSelection.push_back(*muItr);
237 if (theMuonsAfterSelection.size() == 0)
return StatusCode::SUCCESS;;
238 ATH_MSG_DEBUG(
"Number of muons after selection: " << theMuonsAfterSelection.size());
242 std::vector<JpsiCandidate> jpsiCandidates;
250 std::vector<JpsiCandidate> selectCandidates;
251 for(
auto &cand : jpsiCandidates) {
if(cand.muonTypes!=
TT) selectCandidates.push_back(cand); }
252 selectCandidates.swap(jpsiCandidates);
253 ATH_MSG_DEBUG(
"Number of candidates after requirement of at least 1 combined muon: " << jpsiCandidates.size() );
261 for (
auto jpsiItr=jpsiCandidates.begin(); jpsiItr!=jpsiCandidates.end(); ++jpsiItr) {
262 (*jpsiItr).collection1 = importedTrackCollection;
263 (*jpsiItr).collection2 = importedTrackCollection;
268 for (
auto jpsiItr=jpsiCandidates.begin(); jpsiItr!=jpsiCandidates.end(); ++jpsiItr) {
270 (*jpsiItr).trackParticle1 = (*jpsiItr).muon1->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
271 (*jpsiItr).trackParticle2 = (*jpsiItr).muon2->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
272 (*jpsiItr).collection1 = importedTrackCollection;
273 (*jpsiItr).collection2 = importedTrackCollection;
276 if (!(*jpsiItr).muon1->combinedTrackParticleLink().isValid()) {
277 (*jpsiItr).trackParticle1 = (*jpsiItr).muon1->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
278 (*jpsiItr).collection1 = importedTrackCollection;
281 if (!(*jpsiItr).muon2->combinedTrackParticleLink().isValid()) {
282 (*jpsiItr).trackParticle2 = (*jpsiItr).muon2->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
283 (*jpsiItr).collection2 = importedTrackCollection;
286 if ((*jpsiItr).muon1->combinedTrackParticleLink().isValid()) {
287 (*jpsiItr).trackParticle1 = (*jpsiItr).muon1->trackParticle( xAOD::Muon::CombinedTrackParticle );
288 bool foundCollection(
false);
290 for (
auto muTrkCollItr=importedMuonTrackCollections.begin(); muTrkCollItr!=importedMuonTrackCollections.end(); ++muTrkCollItr) {
291 if (
isContainedIn((*jpsiItr).trackParticle1,*muTrkCollItr)) { (*jpsiItr).collection1 = *muTrkCollItr; foundCollection=
true;
break;}
293 if (!foundCollection) {
294 (*jpsiItr).trackParticle1 = (*jpsiItr).muon1->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
295 (*jpsiItr).collection1 = importedTrackCollection;
296 ATH_MSG_WARNING(
"Muon track from muon of author " << (*jpsiItr).muon1->author() <<
" not found in muon track collections you have provided.");
297 ATH_MSG_WARNING(
"Defaulting to ID track collection - combined measurement will not be used");
301 if ((*jpsiItr).muon2->combinedTrackParticleLink().isValid()) {
302 (*jpsiItr).trackParticle2 = (*jpsiItr).muon2->trackParticle( xAOD::Muon::CombinedTrackParticle );
303 bool foundCollection(
false);
305 for (
auto muTrkCollItr=importedMuonTrackCollections.begin(); muTrkCollItr!=importedMuonTrackCollections.end(); ++muTrkCollItr) {
306 if (
isContainedIn((*jpsiItr).trackParticle2,*muTrkCollItr)) { (*jpsiItr).collection2 = *muTrkCollItr; foundCollection=
true;
break;}
308 if (!foundCollection) {
309 (*jpsiItr).trackParticle2 = (*jpsiItr).muon2->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
310 (*jpsiItr).collection2 = importedTrackCollection;
311 ATH_MSG_WARNING(
"Muon track from muon of author " << (*jpsiItr).muon2->author() <<
" not found in muon track collections you have provided.");
312 ATH_MSG_WARNING(
"Defaulting to ID track collection - combined measurement will not be used");
322 std::vector<JpsiCandidate> selectCandidates;
323 for(
auto& cand : jpsiCandidates){
324 bool reject = (fabs(cand.trackParticle1->pt()) <
m_higherPt) && (fabs(cand.trackParticle2->pt()) <
m_higherPt);
325 if(!reject) selectCandidates.push_back(cand);
327 selectCandidates.swap(jpsiCandidates);
328 ATH_MSG_DEBUG(
"Number of candidates after higherPt cut: " << jpsiCandidates.size() );
332 std::vector<JpsiCandidate> sortedJpsiCandidates;
335 ATH_MSG_DEBUG(
"Number of candidates after charge selection: " << sortedJpsiCandidates.size() );
339 std::vector<JpsiCandidate> selectCandidates;
340 for(
auto& cand : sortedJpsiCandidates){
341 double deltatheta = fabs( cand.trackParticle1->theta() - cand.trackParticle2->theta() );
344 if(!reject) selectCandidates.push_back(cand);
346 sortedJpsiCandidates.swap(selectCandidates);
347 ATH_MSG_DEBUG(
"Number of collimated candidates: " << sortedJpsiCandidates.size() );
353 std::vector<JpsiCandidate> selectCandidates;
354 for(
auto& cand : sortedJpsiCandidates){
356 bool reject = invMass < m_invMassLower || invMass >
m_invMassUpper;
357 if(!reject) selectCandidates.push_back(cand);
359 selectCandidates.swap(sortedJpsiCandidates);
360 ATH_MSG_DEBUG(
"Number of candidates passing invariant mass selection: " << sortedJpsiCandidates.size() );
363 ATH_MSG_DEBUG(
"Number of pairs passing all selections and going to vertexing: " << sortedJpsiCandidates.size() );
364 if (sortedJpsiCandidates.size() == 0)
return StatusCode::SUCCESS;;
365 std::vector<const xAOD::TrackParticle*> theTracks;
366 std::vector<const xAOD::Muon*> theStoredMuons;
368 for(
auto jpsiItr=sortedJpsiCandidates.begin(); jpsiItr!=sortedJpsiCandidates.end(); ++jpsiItr) {
370 theTracks.push_back((*jpsiItr).trackParticle1);
371 theTracks.push_back((*jpsiItr).trackParticle2);
372 std::unique_ptr<xAOD::Vertex> myVxCandidate {
fit(theTracks,importedTrackCollection)};
375 double chi2 = myVxCandidate->chiSquared();
381 if(!validtrk)
ATH_MSG_WARNING(
"Problem setting tracks " << __FILE__ <<
':' << __LINE__);
383 theStoredMuons.clear();
384 theStoredMuons.push_back((*jpsiItr).muon1);
385 if (
m_mumu) theStoredMuons.push_back((*jpsiItr).muon2);
386 bool valid = jpsiHelper.
setMuons(theStoredMuons,importedMuonCollection);
390 vxContainer.
push_back(std::move(myVxCandidate));
401 return StatusCode::SUCCESS;;
416 if(concreteVertexFitter == 0) {
417 ATH_MSG_FATAL(
"The vertex fitter passed is not a V0 Vertex Fitter");
427 if (errorcode != 0) {startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
432 if(myVxCandidate != 0){
433 std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
437 newLinkVector.push_back( mylink ); }
445 return myVxCandidate;
450 if(myVxCandidate != 0){
451 std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
455 newLinkVector.push_back( mylink ); }
462 return myVxCandidate;
478 std::vector<JpsiCandidate>
JpsiFinder::getPairs(
const std::vector<const xAOD::TrackParticle*> &TracksIn)
const {
480 std::vector<JpsiCandidate> myPairs;
482 std::vector<const xAOD::TrackParticle*>::const_iterator outerItr;
483 std::vector<const xAOD::TrackParticle*>::const_iterator innerItr;
485 if(TracksIn.size()>=2){
486 for(outerItr=TracksIn.begin();outerItr<TracksIn.end();++outerItr){
487 for(innerItr=(outerItr+1);innerItr!=TracksIn.end();++innerItr){
491 myPairs.push_back(pair);
505 std::vector<JpsiCandidate> myPairs;
507 std::vector<const xAOD::Muon*>::const_iterator outerItr;
508 std::vector<const xAOD::Muon*>::const_iterator innerItr;
510 if(muonsIn.size()>=2){
511 for(outerItr=muonsIn.begin();outerItr<muonsIn.end();++outerItr){
512 for(innerItr=(outerItr+1);innerItr!=muonsIn.end();++innerItr){
513 pair.
muon1 = *innerItr;
514 pair.
muon2 = *outerItr;
519 if ( (mu1Comb && !mu2Comb) || (!mu1Comb && mu2Comb) ) pair.
muonTypes =
CT;
521 myPairs.push_back(pair);
535 std::vector<JpsiCandidate>
JpsiFinder::getPairs2Colls(
const std::vector<const xAOD::TrackParticle*> &tracks,
const std::vector<const xAOD::Muon*> &muons,
bool tagAndProbe)
const {
537 std::vector<JpsiCandidate> myPairs;
541 std::vector<const xAOD::TrackParticle*> tracksToKeep;
543 if(tracks.size()>=1 && muons.size()>=1){
545 bool trackIsMuon(
false);
547 auto& link =
mu->inDetTrackParticleLink();
548 if ( link.isValid() && *link == trk ) {
553 if (!trackIsMuon) tracksToKeep.push_back(trk);
556 }
else {tracksToKeep = tracks;}
558 if(tracksToKeep.size()>=1 && muons.size()>=1){
563 pair.
trackParticle1 =
mu->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
566 myPairs.push_back(pair);
592 return (mu1+mu2).M();
604 bool opposite(
false),
same(
false),
all(
false);
610 std::vector<JpsiCandidate> jpsis;
613 for(
auto jpsiItr=jpsisIn.cbegin();jpsiItr!=jpsisIn.cend();jpsiItr++){
614 bool oppCh(
false),sameCh(
false);
617 qOverP2=(*jpsiItr).trackParticle2->qOverP();
618 if(qOverP1*qOverP2<0.0) oppCh=
true;
619 if(qOverP1*qOverP2>0.0) sameCh=
true;
625 tmpJpsi.
muon1 = (*jpsiItr).muon2;
626 tmpJpsi.
muon2 = (*jpsiItr).muon1;
630 if (oppCh && (opposite ||
all) ) jpsis.push_back(tmpJpsi);
631 if (sameCh && (
same ||
all) ) jpsis.push_back(tmpJpsi);
644 return muon->passesIDCuts();
653 return std::find(theCollection->
begin(), theCollection->
end(), theTrack) != theCollection->
end();
662 double px = 0.,
py = 0.,
pz = 0.;
663 if (0 != vxCandidate) {