Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:26

0001 #ifndef Notification_SimTrackManager_h
0002 #define Notification_SimTrackManager_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Notification
0006 // Class  :     SimTrackManager
0007 //
0008 /**\class SimTrackManager SimTrackManager.h SimG4Core/Notification/interface/SimTrackManager.h
0009 
0010  Description: Holds tracking information used by the sensitive detectors
0011  Created:  Fri Nov 25 17:36:41 EST 2005
0012 
0013 */
0014 
0015 // system include files
0016 #include <map>
0017 #include <vector>
0018 
0019 // user include files
0020 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
0021 #include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"
0022 
0023 // forward declarations
0024 
0025 class TmpSimEvent;
0026 class G4Track;
0027 
0028 class SimTrackManager {
0029 public:
0030   class StrictWeakOrdering {
0031   public:
0032     bool operator()(TrackWithHistory*& p, const int& i) const { return p->trackID() < i; }
0033   };
0034 
0035   typedef std::pair<int, math::XYZVectorD> VertexPosition;
0036   typedef std::vector<std::pair<int, math::XYZVectorD> > VertexPositionVector;
0037   typedef std::map<int, VertexPositionVector> VertexMap;
0038 
0039   explicit SimTrackManager(TmpSimEvent*, int);
0040   ~SimTrackManager();
0041 
0042   const std::vector<TrackWithHistory*>* trackContainer() const { return &m_trackContainer; }
0043 
0044   void storeTracks();
0045   void reset();
0046   void deleteTracks();
0047   void cleanTracksWithHistory();
0048 
0049   void addTrack(TrackWithHistory* iTrack, const G4Track* track, bool inHistory, bool withAncestor);
0050 
0051   int giveMotherNeeded(int i) const {
0052     int theResult = 0;
0053     for (auto const& p : idsave) {
0054       if (p.first == i) {
0055         theResult = p.second;
0056         break;
0057       }
0058     }
0059     return theResult;
0060   }
0061 
0062   bool trackExists(int i) const {
0063     bool flag = false;
0064     for (auto const& ptr : m_trackContainer) {
0065       if (ptr->trackID() == i) {
0066         flag = true;
0067         break;
0068       }
0069     }
0070     return flag;
0071   }
0072 
0073   TrackWithHistory* getTrackByID(int trackID, bool strict = false) const {
0074     TrackWithHistory* track = nullptr;
0075     for (auto const& ptr : m_trackContainer) {
0076       if (ptr->trackID() == trackID) {
0077         track = ptr;
0078         break;
0079       }
0080     }
0081     if (nullptr == track && strict) {
0082       ReportException(trackID);
0083     }
0084     return track;
0085   }
0086 
0087   void setLHCTransportLink(const edm::LHCTransportLinkContainer* thisLHCTlink) { theLHCTlink = thisLHCTlink; }
0088 
0089   // stop default
0090   SimTrackManager(const SimTrackManager&) = delete;
0091   const SimTrackManager& operator=(const SimTrackManager&) = delete;
0092 
0093 private:
0094   void saveTrackAndItsBranch(TrackWithHistory*);
0095   int getOrCreateVertex(TrackWithHistory*, int);
0096   void cleanVertexMap();
0097   void reallyStoreTracks();
0098   void fillMotherList();
0099   int idSavedTrack(int) const;
0100   void ReportException(unsigned int id) const;
0101 
0102   // to restore the pre-LHC Transport GenParticle id link to a SimTrack
0103   void resetGenID();
0104 
0105   // ---------- member data --------------------------------
0106 
0107   int m_nVertices{0};
0108   unsigned int lastTrack{0};
0109   unsigned int lastHist{0};
0110 
0111   TmpSimEvent* m_simEvent;
0112   const edm::LHCTransportLinkContainer* theLHCTlink{nullptr};
0113 
0114   VertexMap m_vertexMap;
0115   std::vector<std::pair<int, int> > idsave;
0116   std::vector<std::pair<int, int> > ancestorList;
0117   std::vector<std::pair<int, math::XYZVectorD> > m_endPoints;
0118   std::vector<TrackWithHistory*> m_trackContainer;
0119 };
0120 
0121 class trkIDLess {
0122 public:
0123   bool operator()(TrackWithHistory* trk1, TrackWithHistory* trk2) const { return (trk1->trackID() < trk2->trackID()); }
0124 };
0125 
0126 #endif