ATLAS Offline Software
JpsiFinder_ee.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ****************************************************************************
6 // ----------------------------------------------------------------------------
7 // JpsiFinder_ee
8 // James Catmore <James.Catmore@cern.ch>
9 // Evelina Bouhova-Thacker <e.bouhova@cern.ch>
10 // Daniel.Scheirich <daniel.scheirich@cern.ch>
11 // Migration to xAOD
12 // ----------------------------------------------------------------------------
13 // ****************************************************************************
14 
16 #include "xAODBPhys/BPhysHelper.h"
22 #include "GaudiKernel/IPartPropSvc.h"
23 #include "AthLinks/ElementLink.h"
24 #include "HepPDT/ParticleDataTable.hh"
25 #include "xAODTracking/Vertex.h"
30 namespace Analysis {
31 
33 
34  // Initialize the ReadHandles
37 
38  // retrieving vertex Fitter
39  ATH_CHECK(m_iVertexFitter.retrieve());
40 
41  // retrieving V0 Fitter
42  ATH_CHECK(m_iV0VertexFitter.retrieve(DisableTool{!m_useV0Fitter }));
43  // Get the track selector tool from ToolSvc
44  ATH_CHECK(m_trkSelector.retrieve());
45 
46 
47  // Get the vertex point estimator tool from ToolSvc
48  ATH_CHECK(m_vertexEstimator.retrieve());
49 
50 
51  if (m_diElectrons) {
52  // Get the Particle Properties Service
53  ATH_CHECK(m_partPropSvc.retrieve());
54  auto particleDataTable = m_partPropSvc->PDT();
55  const HepPDT::ParticleData* pd_el = particleDataTable->particle(MC::ELECTRON);
56  m_trk1M = pd_el->mass();
57  m_trk2M = pd_el->mass();
58  }
59 
60  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");
61 
62 
63 // // Check that the user's settings are sensible
64  bool illogicalOptions(false);
65  if ( (m_elel && m_eltrk) || (m_elel && m_trktrk) || (m_eltrk && m_trktrk) ) {
66  ATH_MSG_WARNING("You are requesting incompatible combinations of muons and tracks in the pairs. JpsiEECandidates will be EMPTY!");
67  illogicalOptions=true;
68  };
69  if ( (m_doTagAndProbe && m_elel) || (m_doTagAndProbe && m_trktrk) ) {
70  ATH_MSG_WARNING("You are requesting Tag and Probe analysis but have not requested mu+trk mode. This is impossible. JpsiEECandidates will be EMPTY!");
71  illogicalOptions=true;
72  };
74  ATH_MSG_WARNING("You are requesting incompatible combinations of charges in the pairs. JpsiEECandidates will be EMPTY!");
75  illogicalOptions=true;
76  };
78  ATH_MSG_WARNING("You are requesting same-sign or all-sign combinations in a tag and probe analysis. This doesn't make sense. JpsiEECandidates will be EMPTY!");
79  illogicalOptions=true;
80  }
81  if (illogicalOptions) return StatusCode::FAILURE;
82 
83 
84 
85  ATH_MSG_DEBUG("Initialize successful");
86 
87  return StatusCode::SUCCESS;
88 
89  }
90 
91 
92  JpsiFinder_ee::JpsiFinder_ee(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t,n,p),
93  m_elel(true),
94  m_eltrk(false),
95  m_trktrk(false),
96  m_allElectrons(false),
97  m_useTrackMeasurement(true),
98  m_useV0Fitter(false),
99  m_diElectrons(true),
100  m_trk1M(0.511),
101  m_trk2M(0.511),
102  m_thresholdPt(0.0),
103  m_higherPt(0.0),
104  m_trkThresholdPt(0.0),
105  m_invMassUpper(100000.0),
106  m_invMassLower(0.0),
107  m_collAngleTheta(0.0),
108  m_collAnglePhi(0.0),
109  m_Chi2Cut(50.),
110  m_oppChOnly(true),
111  m_sameChOnly(false),
112  m_allChCombs(false),
113  m_electronCollectionKey("Electrons"),
114  m_TrkParticleCollection("InDetTrackParticles"),
115  m_iVertexFitter("Trk::TrkVKalVrtFitter"),
116  m_iV0VertexFitter("Trk::V0VertexFitter"),
117  m_trkSelector("InDet::TrackSelectorTool"),
118  m_vertexEstimator("InDet::VertexPointEstimator"),
119  m_egammaCuts(true),
120  m_elSelection("d0_or_nod0"),
121  m_doTagAndProbe(false)
122 
123  {
124  declareInterface<JpsiFinder_ee>(this);
125  declareProperty("elAndEl",m_elel);
126  declareProperty("elAndTrack",m_eltrk);
127  declareProperty("TrackAndTrack",m_trktrk);
128  declareProperty("allElectrons",m_allElectrons);
129  declareProperty("useElectronTrackMeasurement",m_useTrackMeasurement);
130  declareProperty("useV0Fitter",m_useV0Fitter);
131  declareProperty("assumeDiElectrons",m_diElectrons);
132 // declareProperty("electronLHValue",m_electronLHValue);
133  declareProperty("track1Mass",m_trk1M);
134  declareProperty("track2Mass",m_trk2M);
135  declareProperty("elThresholdPt",m_thresholdPt);
136  declareProperty("higherPt",m_higherPt);
137  declareProperty("trackThresholdPt",m_trkThresholdPt);
138  declareProperty("invMassUpper",m_invMassUpper);
139  declareProperty("invMassLower",m_invMassLower);
140  declareProperty("collAngleTheta",m_collAngleTheta);
141  declareProperty("collAnglePhi",m_collAnglePhi);
142  declareProperty("Chi2Cut",m_Chi2Cut);
143  declareProperty("oppChargesOnly",m_oppChOnly);
144  declareProperty("sameChargesOnly",m_sameChOnly);
145  declareProperty("allChargeCombinations",m_allChCombs);
146  declareProperty("electronCollectionKey",m_electronCollectionKey);
147  declareProperty("TrackParticleCollection",m_TrkParticleCollection);
148  declareProperty("TrkVertexFitterTool",m_iVertexFitter);
149  declareProperty("V0VertexFitterTool",m_iV0VertexFitter);
150  declareProperty("TrackSelectorTool",m_trkSelector);
151  declareProperty("VertexPointEstimator",m_vertexEstimator);
152  declareProperty("useEgammaCuts",m_egammaCuts);
153  declareProperty("doTagAndProbe",m_doTagAndProbe);
154  declareProperty("ElectronSelection",m_elSelection);
155  }
156 
158 
159  //-------------------------------------------------------------------------------------
160  // Find the candidates
161  //-------------------------------------------------------------------------------------
162 
163 
164  StatusCode JpsiFinder_ee::performSearch(const EventContext& ctx, xAOD::VertexContainer& vxContainer) const
165  {
166  ATH_MSG_DEBUG( "JpsiFinder_ee::performSearch" );
167 
168 
169  // Get the electrons from StoreGate
170  const xAOD::ElectronContainer* importedElectronCollection=nullptr;
172  if(!ehandle.isValid()){
173  ATH_MSG_WARNING("No electron collection with key " << m_electronCollectionKey.key() << " found in StoreGate. JpsiEECandidates will be EMPTY!");
174  return StatusCode::SUCCESS;;
175  }else{
176  importedElectronCollection = ehandle.cptr();
177  ATH_MSG_DEBUG("Found electron collections with key "<<m_electronCollectionKey.key());
178  }
179  ATH_MSG_DEBUG("Electron container size "<<importedElectronCollection->size());
180 
181  // Get ID tracks
183  const xAOD::TrackParticleContainer* importedTrackCollection(0);
184  if(!thandle.isValid()){
185  ATH_MSG_WARNING("No TrackParticle collection with name " << m_TrkParticleCollection << " found in StoreGate!");
186  return StatusCode::SUCCESS;;
187  } else {
188  importedTrackCollection = thandle.cptr();
189  }
190 
191  // Typedef for vectors of tracks and muons
192  typedef std::vector<const xAOD::TrackParticle*> TrackBag;
193  typedef std::vector<const xAOD::Electron*> ElectronBag;
194 
195  // Select the inner detector tracks
196  const xAOD::Vertex* vx = 0;
197  TrackBag theIDTracksAfterSelection;
198  if (m_trktrk || m_eltrk) {
200  for (trkCItr=importedTrackCollection->begin(); trkCItr!=importedTrackCollection->end(); ++trkCItr) {
201  const xAOD::TrackParticle* TP = (*trkCItr);
202  if ( fabs(TP->pt())<m_trkThresholdPt ) continue;
203  if ( !m_trkSelector->decision(*TP, vx) ) continue;
204  theIDTracksAfterSelection.push_back(TP);
205  }
206  if (theIDTracksAfterSelection.size() == 0) return StatusCode::SUCCESS;;
207  ATH_MSG_DEBUG("Number of tracks after ID track selection: " << theIDTracksAfterSelection.size());
208  }
209 
210  // Select the muons
211  ElectronBag theElectronsAfterSelection;
213  if (m_elel || m_eltrk) {
214  for (elItr=importedElectronCollection->begin(); elItr!=importedElectronCollection->end(); ++elItr) {
215  if ( *elItr == NULL ) continue;
216  if (!(*elItr)->trackParticleLink().isValid()) continue; // No electrons without ID tracks
217  const xAOD::TrackParticle* elTrk(0);
218  elTrk = (*elItr)->trackParticleLink().cachedElement();
219 
220  if ( elTrk==NULL) continue;
221  if ( !m_trkSelector->decision(*elTrk, vx) ) continue; // all ID tracks must pass basic tracking cuts
222  if ( fabs(elTrk->pt())<m_thresholdPt ) continue; // higher pt cut if needed
223 
224  if ( m_egammaCuts && !passesEgammaCuts(*elItr)) continue; // egamma cuts
225  theElectronsAfterSelection.push_back(*elItr);
226  }
227  if (theElectronsAfterSelection.size() == 0) return StatusCode::SUCCESS;;
228  ATH_MSG_DEBUG("Number of electrons after selection: " << theElectronsAfterSelection.size());
229  }
230 
231  // Sort into pairs - end result will be a vector of JpsiEECandidate structs
232  std::vector<JpsiEECandidate> jpsiCandidates;
233  if (m_elel) jpsiCandidates = getPairs(theElectronsAfterSelection);
234  if (m_trktrk) jpsiCandidates = getPairs(theIDTracksAfterSelection);
235  if (m_eltrk) jpsiCandidates = getPairs2Colls(theIDTracksAfterSelection,theElectronsAfterSelection,m_doTagAndProbe);
236 
237  ATH_MSG_DEBUG("Number of pairs with ee from a B decay: " << jpsiCandidates.size() );
238 
239  // Pair-wise selections
241 
242  // (1) Enforce one combined muon [deleted, no electron equivalent]
243 
244  // (2) Establish track content for candidates
245  // and set the appropriate track collections for the combined muon tracks where appropriate (for saving to persistency later)
246 
247  // el+trk or trk+trk - always ID track collection
248  if (m_eltrk || m_trktrk) {
249  for (jpsiItr=jpsiCandidates.begin(); jpsiItr!=jpsiCandidates.end(); ++jpsiItr) {
250  (*jpsiItr).collection1 = importedTrackCollection;
251  (*jpsiItr).collection2 = importedTrackCollection;
252  }
253  }
254 
255  if (m_elel) {
256  for (jpsiItr=jpsiCandidates.begin(); jpsiItr!=jpsiCandidates.end(); ++jpsiItr) {
257  if ( m_useTrackMeasurement ) {
258  (*jpsiItr).trackParticle1 = (*jpsiItr).el1->trackParticleLink().cachedElement();
259  (*jpsiItr).trackParticle2 = (*jpsiItr).el2->trackParticleLink().cachedElement();
260  (*jpsiItr).collection1 = importedTrackCollection;
261  (*jpsiItr).collection2 = importedTrackCollection;
262  } else {
263  ATH_MSG_WARNING("Not setup for non-track electron measurements yet....");
264  }
265  } // iteration over candidates
266  }
267 
268 
269  // (3) Enforce higher track pt if requested
270  if (m_higherPt>0.0) {
271  int index(0);
272  std::vector<int> listToDelete;
273  std::vector<int>::reverse_iterator ii;
274  for(jpsiItr=jpsiCandidates.begin(); jpsiItr!=jpsiCandidates.end();++jpsiItr,++index) {
275  if( (fabs((*jpsiItr).trackParticle1->pt()) < m_higherPt) && (fabs((*jpsiItr).trackParticle2->pt()) < m_higherPt) ) listToDelete.push_back(index);
276  }
277  for (ii=listToDelete.rbegin(); ii!=listToDelete.rend(); ++ii) {
278  jpsiCandidates.erase(jpsiCandidates.begin() + (*ii) );
279  }
280  ATH_MSG_DEBUG("Number of candidates after higherPt cut: " << jpsiCandidates.size() );
281  }
282 
283  // (4) Select all opp/same charged track pairs
284  std::vector<JpsiEECandidate> sortedJpsiEECandidates;
285  if (m_oppChOnly) sortedJpsiEECandidates = selectCharges(jpsiCandidates,"OPPOSITE");
286  if (m_sameChOnly) sortedJpsiEECandidates = selectCharges(jpsiCandidates,"SAME");
287  if (m_allChCombs) sortedJpsiEECandidates = selectCharges(jpsiCandidates,"ALL");
288  ATH_MSG_DEBUG("Number of candidates after charge selection: " << sortedJpsiEECandidates.size() );
289 
290  // (5) Select for decay angle, if requested
291  if (m_collAnglePhi>0.0 && m_collAngleTheta>0.0) {
292  int index(0);
293  std::vector<int> listToDelete;
294  std::vector<int>::reverse_iterator ii;
295  for(jpsiItr=sortedJpsiEECandidates.begin(); jpsiItr!=sortedJpsiEECandidates.end();++jpsiItr,++index) {
296  double deltatheta = fabs( (*jpsiItr).trackParticle1->theta() - (*jpsiItr).trackParticle2->theta() );
297  // -3.14 < phi < +3.14 ==> correction
298  double deltaphi = std::abs(xAOD::P4Helpers::deltaPhi((*jpsiItr).trackParticle1->phi0() , (*jpsiItr).trackParticle2->phi0()));
299  // perform the angle cuts
300  if ((deltatheta > m_collAngleTheta) || (deltaphi > m_collAnglePhi)) listToDelete.push_back(index);
301  }
302  for (ii=listToDelete.rbegin(); ii!=listToDelete.rend(); ++ii) {
303  sortedJpsiEECandidates.erase(sortedJpsiEECandidates.begin() + (*ii) );
304  }
305  ATH_MSG_DEBUG("Number of collimated candidates: " << sortedJpsiEECandidates.size() );
306  }
307 
308  // (6) Select for invariant mass, if requested
309  std::vector<double> trkMasses;
310  trkMasses.push_back(m_trk1M);
311  trkMasses.push_back(m_trk2M);
312  if ( (m_invMassLower > 0.0) || (m_invMassUpper > 0.0) ) {
313  int index(0);
314  std::vector<int> listToDelete;
315  std::vector<int>::reverse_iterator ii;
316  for(jpsiItr=sortedJpsiEECandidates.begin(); jpsiItr!=sortedJpsiEECandidates.end(); ++jpsiItr,++index) {
317  double invMass = getInvariantMass(*jpsiItr,trkMasses);
318  // std::cout << "inv. mass: " << invMass << std::endl;
319  if ( invMass < m_invMassLower || invMass > m_invMassUpper ) {
320  listToDelete.push_back(index);
321  }
322  }
323  for (ii=listToDelete.rbegin(); ii!=listToDelete.rend(); ++ii) {
324  sortedJpsiEECandidates.erase(sortedJpsiEECandidates.begin() + (*ii) );
325  }
326  ATH_MSG_DEBUG("Number of candidates passing invariant mass selection: " << sortedJpsiEECandidates.size() );
327  }
328 
329  if (sortedJpsiEECandidates.size() == 0) return StatusCode::SUCCESS;;
330 
331  // Fit each pair of tracks to a vertex
332  int itritn = 0;
333  for(jpsiItr=sortedJpsiEECandidates.begin(); jpsiItr!=sortedJpsiEECandidates.end(); ++jpsiItr) {
334  ATH_MSG_DEBUG("jpsiItr: " << itritn); itritn++;
335  std::vector<const xAOD::TrackParticle*> theTracks; theTracks.clear();
336  theTracks.push_back((*jpsiItr).trackParticle1);
337  theTracks.push_back((*jpsiItr).trackParticle2);
338  ATH_MSG_DEBUG("theTracks size (should be two!) " << theTracks.size() << " being vertexed with tracks " << importedTrackCollection);
339  std::unique_ptr<xAOD::Vertex> myVxCandidate{fit(theTracks,importedTrackCollection)}; // This line actually does the fitting and object making
340  if (myVxCandidate != 0) {
341  // Chi2 cut if requested
342  double chi2 = myVxCandidate->chiSquared();
343  ATH_MSG_DEBUG("chi2 is: " << chi2);
344  if (m_Chi2Cut == 0.0 || chi2 <= m_Chi2Cut) {
345  // decorate the candidate with refitted tracks and muons via the BPhysHelper
346  xAOD::BPhysHelper jpsiHelper(myVxCandidate.get());
347  jpsiHelper.setRefTrks();
348  if (m_elel || m_eltrk) {
349  std::vector<const xAOD::Electron*> theStoredElectrons;
350  theStoredElectrons.push_back((*jpsiItr).el1);
351  if (m_elel) theStoredElectrons.push_back((*jpsiItr).el2);
352  jpsiHelper.setElectrons(theStoredElectrons,importedElectronCollection);
353  }
354  // Retain the vertex
355  vxContainer.push_back(std::move(myVxCandidate));
356  }
357  } else { // fit failed
358  ATH_MSG_DEBUG("Fitter failed!");
359  // Don't try to delete the object, since we arrived here,
360  // because this pointer is null...
361  //delete myVxCandidate;
362  }
363  }
364  ATH_MSG_DEBUG("vxContainer size " << vxContainer.size());
365 
366  return StatusCode::SUCCESS;;
367  }
368 
369  // *********************************************************************************
370 
371  // ---------------------------------------------------------------------------------
372  // fit - does the fit
373  // ---------------------------------------------------------------------------------
374 
375  xAOD::Vertex* JpsiFinder_ee::fit(const std::vector<const xAOD::TrackParticle*> &inputTracks,const xAOD::TrackParticleContainer* importedTrackCollection) const {
376  ATH_MSG_DEBUG("inside JpsiFinder_ee::fit");
377  const Trk::TrkV0VertexFitter* concreteVertexFitter=0;
378  if (m_useV0Fitter) {
379  ATH_MSG_DEBUG("using v0 fitter");
380  // making a concrete fitter for the V0Fitter
381  concreteVertexFitter = dynamic_cast<const Trk::TrkV0VertexFitter * >(m_iV0VertexFitter.get());
382  if(concreteVertexFitter == 0) {
383  ATH_MSG_FATAL("The vertex fitter passed is not a V0 Vertex Fitter");
384  return NULL;
385  }
386  }
387 
388  const Trk::Perigee& aPerigee1 = inputTracks[0]->perigeeParameters();
389  const Trk::Perigee& aPerigee2 = inputTracks[1]->perigeeParameters();
390  int sflag = 0;
391  int errorcode = 0;
392  Amg::Vector3D startingPoint = m_vertexEstimator->getCirclesIntersectionPoint(&aPerigee1,&aPerigee2,sflag,errorcode);
393  if (errorcode != 0) {startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
394  if (m_useV0Fitter) {
395  xAOD::Vertex* myVxCandidate = concreteVertexFitter->fit(inputTracks, startingPoint);
396  ATH_MSG_DEBUG("Initial fit was a success!");
397  // Added by ASC
398  if(myVxCandidate != 0){
399  std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
400  for(unsigned int i=0; i< myVxCandidate->trackParticleLinks().size(); i++)
401  { ElementLink<DataVector<xAOD::TrackParticle> > mylink=myVxCandidate->trackParticleLinks()[i]; //makes a copy (non-const)
402  mylink.setStorableObject(*importedTrackCollection, true);
403  newLinkVector.push_back( mylink ); }
404 
405  myVxCandidate->clearTracks();
406  myVxCandidate->setTrackParticleLinks( newLinkVector );
407  }
408 
409 
410 
411  return myVxCandidate;
412  } else {
413  xAOD::Vertex* myVxCandidate = m_iVertexFitter->fit(inputTracks, startingPoint);
414  ATH_MSG_DEBUG("Initial fit was a success! " << myVxCandidate);
415  // Added by ASC
416  if(myVxCandidate != 0){
417  std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
418  for(unsigned int i=0; i< myVxCandidate->trackParticleLinks().size(); i++){
419  ElementLink<DataVector<xAOD::TrackParticle> > mylink=myVxCandidate->trackParticleLinks()[i]; //makes a copy (non-const)
420  mylink.setStorableObject(*importedTrackCollection, true);
421  newLinkVector.push_back( mylink );
422  ATH_MSG_DEBUG("Set a link!");
423  }
424  myVxCandidate->clearTracks();
425  myVxCandidate->setTrackParticleLinks( newLinkVector );
426  ATH_MSG_DEBUG("Set all links");
427  }
428 
429  return myVxCandidate;
430  }
431 
432 
433 
434  return NULL;
435 
436  } // End of fit method
437 
438 
439  // *********************************************************************************
440 
441  // ---------------------------------------------------------------------------------
442  // getPairs: forms up 2-plets of tracks
443  // ---------------------------------------------------------------------------------
444 
445  std::vector<JpsiEECandidate> JpsiFinder_ee::getPairs(const std::vector<const xAOD::TrackParticle*> &TracksIn) const {
446 
447  std::vector<JpsiEECandidate> myPairs;
448  JpsiEECandidate pair;
449  std::vector<const xAOD::TrackParticle*>::const_iterator outerItr;
450  std::vector<const xAOD::TrackParticle*>::const_iterator innerItr;
451 
452  if(TracksIn.size()>=2){
453  for(outerItr=TracksIn.begin();outerItr<TracksIn.end();++outerItr){
454  for(innerItr=(outerItr+1);innerItr!=TracksIn.end();++innerItr){
455  pair.trackParticle1 = *innerItr;
456  pair.trackParticle2 = *outerItr;
457  pair.pairType = TRK2;
458  myPairs.push_back(pair);
459  }
460  }
461  }
462 
463  return(myPairs);
464  }
465 
466  // *********************************************************************************
467 
468  // ---------------------------------------------------------------------------------
469  // getPairs: forms up 2-plets of electrons
470  // ---------------------------------------------------------------------------------
471 
472  std::vector<JpsiEECandidate> JpsiFinder_ee::getPairs(const std::vector<const xAOD::Electron*> &electronsIn) const {
473 
474  std::vector<JpsiEECandidate> myPairs;
475  JpsiEECandidate pair;
476  std::vector<const xAOD::Electron*>::const_iterator outerItr;
477  std::vector<const xAOD::Electron*>::const_iterator innerItr;
478 
479  if(electronsIn.size()>=2){
480  for(outerItr=electronsIn.begin();outerItr<electronsIn.end();++outerItr){
481  for(innerItr=(outerItr+1);innerItr!=electronsIn.end();++innerItr){
482  pair.el1 = *innerItr;
483  pair.el2 = *outerItr;
484  pair.pairType = ELEL;
485  myPairs.push_back(pair);
486  }
487  }
488  }
489 
490  return(myPairs);
491  }
492 
493  // *********************************************************************************
494 
495  // ---------------------------------------------------------------------------------
496  // getPairs2Colls: forms up 2-plets of tracks from two independent collections
497  // ---------------------------------------------------------------------------------
498 
499  std::vector<JpsiEECandidate> JpsiFinder_ee::getPairs2Colls(const std::vector<const xAOD::TrackParticle*> &tracks, const std::vector<const xAOD::Electron*> &electrons, bool tagAndProbe) const {
500 
501  std::vector<JpsiEECandidate> myPairs;
502  JpsiEECandidate pair;
503 
504  // Unless user is running in tag and probe mode, remove tracks which are also identified as muons
505  std::vector<const xAOD::TrackParticle*> tracksToKeep;
506  if (!tagAndProbe) {
507  if(tracks.size()>=1 && electrons.size()>=1){
508  for (const xAOD::TrackParticle* trk : tracks) {
509  bool trackIsElectron(false);
510  for (const xAOD::Electron* ele : electrons) {
511  if ( ele->trackParticleLink().cachedElement() == trk ) {
512  trackIsElectron=true;
513  break;
514  }
515  }
516  if (!trackIsElectron) tracksToKeep.push_back(trk);
517  }
518  }
519  } else {tracksToKeep = tracks;}
520 
521  if(tracksToKeep.size()>=1 && electrons.size()>=1){
522  for (const xAOD::TrackParticle* trk : tracks) {
523  for (const xAOD::Electron* ele : electrons) {
524  pair.el1 = ele;
525  // Muon track 1st
526  pair.trackParticle1 = ele->trackParticleLink().cachedElement();
527  pair.trackParticle2 = trk;
528  pair.pairType = ELTRK;
529  myPairs.push_back(pair);
530  }
531  }
532  }
533 
534  return(myPairs);
535  }
536 
537 
538 
539  // *********************************************************************************
540 
541  // ---------------------------------------------------------------------------------
542  // getInvariantMass: returns invariant mass
543  // ---------------------------------------------------------------------------------
544 
545  double JpsiFinder_ee::getInvariantMass(const JpsiEECandidate &jpsiIn, const std::vector<double> &massHypotheses) const {
546  double mass1 = massHypotheses.at(0);
547  double mass2 = massHypotheses.at(1);
548 
549  // construct 4-vectors from track perigee parameters using given mass hypotheses.
550  // NOTE: in new data model (xAOD) the defining parameters are expressed as perigee parameters w.r.t. the beamspot
551  // NOTE2: TrackParticle::p4() method already returns TLorentzVector, however, we want to enforce our own mass hypothesis
552  TLorentzVector mu1;
553  TLorentzVector mu2;
554  mu1.SetVectM(jpsiIn.trackParticle1->p4().Vect(), mass1);
555  mu2.SetVectM(jpsiIn.trackParticle2->p4().Vect(), mass2);
556 
557  return (mu1+mu2).M();
558 
559  }
560 
561  // ---------------------------------------------------------------------------------
562  // selectCharges: selects track pairs with opposite charge / store + before -
563  // Boolean argument is to decide whether to accept oppositely or identically charged
564  // particles (true for oppositely charged)
565  // ---------------------------------------------------------------------------------
566 
567  std::vector<JpsiEECandidate> JpsiFinder_ee::selectCharges(const std::vector<JpsiEECandidate> &jpsisIn, const std::string &selection) const {
568 
569  bool opposite(false),same(false),all(false);
570  if (selection=="OPPOSITE") opposite=true;
571  if (selection=="SAME") same=true;
572  if (selection=="ALL") all=true;
573 
574  JpsiEECandidate tmpJpsi;
575  std::vector<JpsiEECandidate> jpsis;
576  double qOverP1=0.;
577  double qOverP2=0.;
578  for(auto jpsiItr=jpsisIn.cbegin();jpsiItr!=jpsisIn.cend();jpsiItr++){
579  bool oppCh(false),sameCh(false);
580  tmpJpsi = *jpsiItr;
581  qOverP1=(*jpsiItr).trackParticle1->qOverP();
582  qOverP2=(*jpsiItr).trackParticle2->qOverP();
583  if(qOverP1*qOverP2<0.0) oppCh=true; // product charge < 0
584  if(qOverP1*qOverP2>0.0) sameCh=true; // product charge > 0
585  // +ve should be first so swap
586  // Don't do it for tag and probe analyses (because tag muon must not change position)
587  if (oppCh && qOverP1<0.0 && !m_doTagAndProbe) {
588  tmpJpsi.trackParticle1 = (*jpsiItr).trackParticle2;
589  tmpJpsi.trackParticle2 = (*jpsiItr).trackParticle1;
590  tmpJpsi.el1 = (*jpsiItr).el2;
591  tmpJpsi.el2 = (*jpsiItr).el1;
592  tmpJpsi.collection1 = (*jpsiItr).collection2;
593  tmpJpsi.collection2 = (*jpsiItr).collection1;
594  }
595  if (oppCh && (opposite || all) ) jpsis.push_back(tmpJpsi);
596  if (sameCh && (same || all) ) jpsis.push_back(tmpJpsi);
597 
598  } // end of for loop
599 
600  return(jpsis);
601  }
602 
603  // ---------------------------------------------------------------------------------
604  // Apply the current cuts of the MCP group recommendation.
605  // ---------------------------------------------------------------------------------
606 
608 
609  static const SG::AuxElement::ConstAccessor<char> isLHVeryLoosenod0("DFCommonElectronsLHVeryLoosenod0");
610  static const SG::AuxElement::ConstAccessor<char> isLHVeryLoose("DFCommonElectronsLHVeryLoose");
611 
612  bool passesSelection = false;
613  bool passesLHVLoose = isLHVeryLoose(*electron);
614  bool passesLHVLoosenod0 = isLHVeryLoosenod0(*electron);
615 
616  if(m_elSelection == "d0") passesSelection = passesLHVLoose;
617  else if(m_elSelection == "nod0") passesSelection = passesLHVLoosenod0;
618  else if(m_elSelection == "d0_or_nod0") passesSelection = passesLHVLoose || passesLHVLoosenod0;
619  else ATH_MSG_ERROR("Invalid electron selection " << m_elSelection);
620 
621  ATH_MSG_DEBUG("Electron with pT, eta: " << electron->pt() << " " << electron->eta() << " passes " << m_elSelection << " " << passesSelection);
622  return passesSelection;
623 
624  }
625 
626 
627  // ---------------------------------------------------------------------------------
628  // Checks whether a TPB is in the collection
629  // ---------------------------------------------------------------------------------
630 
631  bool JpsiFinder_ee::isContainedIn(const xAOD::TrackParticle* theTrack, const xAOD::TrackParticleContainer* theCollection) const {
632  return std::find(theCollection->begin(), theCollection->end(), theTrack) != theCollection->end();
633  }
634 
635  // ---------------------------------------------------------------------------------
636  // trackMomentum: returns refitted track momentum
637  // ---------------------------------------------------------------------------------
638 
639  TVector3 JpsiFinder_ee::trackMomentum(const xAOD::Vertex * vxCandidate, int trkIndex) const
640  {
641  double px = 0., py = 0., pz = 0.;
642  if (0 != vxCandidate) {
643  const Trk::TrackParameters* aPerigee = vxCandidate->vxTrackAtVertex()[trkIndex].perigeeAtVertex();
644  px = aPerigee->momentum()[Trk::px];
645  py = aPerigee->momentum()[Trk::py];
646  pz = aPerigee->momentum()[Trk::pz];
647  }
648  TVector3 mom(px,py,pz);
649  return mom;
650  }
651 
652 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
Analysis::JpsiFinder_ee::m_invMassUpper
double m_invMassUpper
Definition: JpsiFinder_ee.h:90
Trk::py
@ py
Definition: ParamDefs.h:60
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Analysis::JpsiEECandidate::trackParticle1
const xAOD::TrackParticle * trackParticle1
Definition: JpsiFinder_ee.h:45
xAOD::BPhysHelper
Definition: BPhysHelper.h:71
test_pyathena.px
px
Definition: test_pyathena.py:18
JpsiFinder_ee.h
Analysis::JpsiFinder_ee::m_trkSelector
ToolHandle< Trk::ITrackSelectorTool > m_trkSelector
Definition: JpsiFinder_ee.h:102
P4Helpers::invMass
double invMass(const I4Momentum &pA, const I4Momentum &pB)
invariant mass from two I4momentum references
Definition: P4Helpers.h:252
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
VertexPointEstimator.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Analysis::JpsiFinder_ee::getPairs2Colls
std::vector< JpsiEECandidate > getPairs2Colls(const std::vector< const xAOD::TrackParticle * > &, const std::vector< const xAOD::Electron * > &, bool) const
Definition: JpsiFinder_ee.cxx:499
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
xAODP4Helpers.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Analysis::JpsiFinder_ee::~JpsiFinder_ee
~JpsiFinder_ee()
Definition: JpsiFinder_ee.cxx:157
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
Analysis::JpsiFinder_ee::m_TrkParticleCollection
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrkParticleCollection
Definition: JpsiFinder_ee.h:99
Analysis::JpsiFinder_ee::m_useTrackMeasurement
bool m_useTrackMeasurement
Definition: JpsiFinder_ee.h:82
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
Analysis::JpsiFinder_ee::m_sameChOnly
bool m_sameChOnly
Definition: JpsiFinder_ee.h:96
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
Analysis::JpsiEECandidate::trackParticle2
const xAOD::TrackParticle * trackParticle2
Definition: JpsiFinder_ee.h:46
Analysis::JpsiFinder_ee::m_collAnglePhi
double m_collAnglePhi
Definition: JpsiFinder_ee.h:93
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Analysis::JpsiFinder_ee::JpsiFinder_ee
JpsiFinder_ee(const std::string &t, const std::string &n, const IInterface *p)
Definition: JpsiFinder_ee.cxx:92
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Analysis::JpsiFinder_ee::m_elSelection
std::string m_elSelection
Definition: JpsiFinder_ee.h:106
Analysis::JpsiFinder_ee::m_electronCollectionKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronCollectionKey
Definition: JpsiFinder_ee.h:98
Trk::pz
@ pz
global momentum (cartesian)
Definition: ParamDefs.h:61
python.TrigEgammaFastCaloHypoTool.same
def same(val, tool)
Definition: TrigEgammaFastCaloHypoTool.py:12
Analysis::JpsiFinder_ee::m_doTagAndProbe
bool m_doTagAndProbe
Definition: JpsiFinder_ee.h:107
Analysis::JpsiFinder_ee::initialize
virtual StatusCode initialize() override
Definition: JpsiFinder_ee.cxx:32
Analysis::JpsiEECandidate
Definition: JpsiFinder_ee.h:44
TrkVKalVrtFitter.h
Analysis::JpsiEECandidate::el2
const xAOD::Electron * el2
Definition: JpsiFinder_ee.h:48
Analysis::JpsiFinder_ee::passesEgammaCuts
bool passesEgammaCuts(const xAOD::Electron *) const
Definition: JpsiFinder_ee.cxx:607
Analysis::JpsiFinder_ee::m_trk2M
double m_trk2M
Definition: JpsiFinder_ee.h:86
Analysis::JpsiFinder_ee::getPairs
std::vector< JpsiEECandidate > getPairs(const std::vector< const xAOD::TrackParticle * > &) const
Definition: JpsiFinder_ee.cxx:445
Analysis::JpsiFinder_ee::m_trkThresholdPt
double m_trkThresholdPt
Definition: JpsiFinder_ee.h:89
Analysis::JpsiFinder_ee::fit
xAOD::Vertex * fit(const std::vector< const xAOD::TrackParticle * > &, const xAOD::TrackParticleContainer *importedTrackCollection) const
Definition: JpsiFinder_ee.cxx:375
Analysis::ELEL
@ ELEL
Definition: JpsiFinder_ee.h:42
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TrackParticle_v1.cxx:129
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Analysis::JpsiFinder_ee::m_invMassLower
double m_invMassLower
Definition: JpsiFinder_ee.h:91
python.TrigInDetConfig.inputTracks
inputTracks
Definition: TrigInDetConfig.py:183
Analysis::JpsiFinder_ee::m_thresholdPt
double m_thresholdPt
Definition: JpsiFinder_ee.h:87
lumiFormat.i
int i
Definition: lumiFormat.py:85
Analysis::JpsiFinder_ee::m_allChCombs
bool m_allChCombs
Definition: JpsiFinder_ee.h:97
Analysis::JpsiFinder_ee::performSearch
virtual StatusCode performSearch(const EventContext &ctx, xAOD::VertexContainer &vxContainer) const override
Definition: JpsiFinder_ee.cxx:164
Analysis::JpsiFinder_ee::trackMomentum
TVector3 trackMomentum(const xAOD::Vertex *vxCandidate, int trkIndex) const
Definition: JpsiFinder_ee.cxx:639
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Analysis::JpsiFinder_ee::m_partPropSvc
ServiceHandle< IPartPropSvc > m_partPropSvc
Definition: JpsiFinder_ee.h:104
Analysis::JpsiFinder_ee::m_Chi2Cut
double m_Chi2Cut
Definition: JpsiFinder_ee.h:94
xAOD::Vertex_v1::setTrackParticleLinks
void setTrackParticleLinks(const TrackParticleLinks_t &trackParticles)
Set all track particle links at once.
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
Analysis::JpsiFinder_ee::m_diElectrons
bool m_diElectrons
Definition: JpsiFinder_ee.h:84
Trk::px
@ px
Definition: ParamDefs.h:59
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
Analysis::JpsiFinder_ee::m_trktrk
bool m_trktrk
Definition: JpsiFinder_ee.h:80
PlotRamps.passesSelection
def passesSelection(gain, offset)
Definition: PlotRamps.py:8
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::TrackBag
std::vector< const xAOD::TrackParticle * > TrackBag
Definition: BPhysAddMuonBasedInvMass.h:32
xAOD::Vertex_v1::clearTracks
void clearTracks()
Remove all tracks from the vertex.
Definition: Vertex_v1.cxx:331
Trk::ParametersBase
Definition: ParametersBase.h:55
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Analysis::JpsiFinder_ee::selectCharges
std::vector< JpsiEECandidate > selectCharges(const std::vector< JpsiEECandidate > &, const std::string &) const
Definition: JpsiFinder_ee.cxx:567
Analysis::JpsiEECandidate::collection1
const xAOD::TrackParticleContainer * collection1
Definition: JpsiFinder_ee.h:49
Analysis::JpsiFinder_ee::m_vertexEstimator
ToolHandle< InDet::VertexPointEstimator > m_vertexEstimator
Definition: JpsiFinder_ee.h:103
Analysis::JpsiEECandidate::el1
const xAOD::Electron * el1
Definition: JpsiFinder_ee.h:47
xAOD::BPhysHelper::setElectrons
bool setElectrons(const std::vector< const xAOD::Electron * > &electrons, const xAOD::ElectronContainer *electronContainer)
Definition: BPhysHelper.cxx:559
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Vertex.h
Analysis::JpsiFinder_ee::m_iVertexFitter
ToolHandle< Trk::IVertexFitter > m_iVertexFitter
Definition: JpsiFinder_ee.h:100
Analysis::JpsiFinder_ee::m_egammaCuts
bool m_egammaCuts
Definition: JpsiFinder_ee.h:105
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Analysis::JpsiEECandidate::pairType
PairTypeEE pairType
Definition: JpsiFinder_ee.h:51
Analysis::JpsiFinder_ee::isContainedIn
bool isContainedIn(const xAOD::TrackParticle *, const xAOD::TrackParticleContainer *) const
Definition: JpsiFinder_ee.cxx:631
Analysis::JpsiFinder_ee::m_higherPt
double m_higherPt
Definition: JpsiFinder_ee.h:88
Analysis::JpsiFinder_ee::m_oppChOnly
bool m_oppChOnly
Definition: JpsiFinder_ee.h:95
Amg::py
@ py
Definition: GeoPrimitives.h:39
xAOD::TrackParticle_v1::qOverP
float qOverP() const
Returns the parameter.
selection
const std::string selection
Definition: fbtTestBasics.cxx:74
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
Analysis::JpsiFinder_ee::m_trk1M
double m_trk1M
Definition: JpsiFinder_ee.h:85
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAOD::Electron_v1
Definition: Electron_v1.h:34
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
IVertexFitter.h
TrkV0VertexFitter.h
BPhysHelper.h
: B-physics xAOD helpers.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrackParticle.h
xAOD::BPhysHelper::setRefTrks
bool setRefTrks(std::vector< float > px, std::vector< float > py, std::vector< float > pz)
Sets refitted track momenta.
Definition: BPhysHelper.cxx:286
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
DeMoScan.index
string index
Definition: DeMoScan.py:364
Trk::TrkV0VertexFitter::fit
virtual xAOD::Vertex * fit(const std::vector< const xAOD::TrackParticle * > &vectorTrk, const Amg::Vector3D &startingPoint) const override
Interface for xAOD::TrackParticle with Amg::Vector3D starting point.
Definition: TrkV0VertexFitter.cxx:83
VertexContainer.h
Analysis::JpsiFinder_ee::getInvariantMass
double getInvariantMass(const JpsiEECandidate &, const std::vector< double > &) const
Definition: JpsiFinder_ee.cxx:545
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Analysis::JpsiFinder_ee::m_collAngleTheta
double m_collAngleTheta
Definition: JpsiFinder_ee.h:92
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Analysis::JpsiFinder_ee::m_elel
bool m_elel
Definition: JpsiFinder_ee.h:78
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
Analysis::ELTRK
@ ELTRK
Definition: JpsiFinder_ee.h:42
Trk::TrkV0VertexFitter
This class implements a vertex fitting algorithm optimised for V0 finding.
Definition: TrkV0VertexFitter.h:40
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Analysis::JpsiFinder_ee::m_eltrk
bool m_eltrk
Definition: JpsiFinder_ee.h:79
xAOD::Vertex_v1::vxTrackAtVertex
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
Definition: Vertex_v1.cxx:181
AthAlgTool
Definition: AthAlgTool.h:26
Analysis::JpsiFinder_ee::m_allElectrons
bool m_allElectrons
Definition: JpsiFinder_ee.h:81
Analysis::TRK2
@ TRK2
Definition: JpsiFinder_ee.h:42
Analysis::JpsiFinder_ee::m_iV0VertexFitter
ToolHandle< Trk::IVertexFitter > m_iV0VertexFitter
Definition: JpsiFinder_ee.h:101
ITrackSelectorTool.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Analysis::JpsiEECandidate::collection2
const xAOD::TrackParticleContainer * collection2
Definition: JpsiFinder_ee.h:50
Analysis::JpsiFinder_ee::m_useV0Fitter
bool m_useV0Fitter
Definition: JpsiFinder_ee.h:83
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.