Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:11

0001 #include "PHG4TrackUserInfoV1.h"
0002 
0003 #include <Geant4/G4Track.hh>
0004 #include <Geant4/G4VUserTrackInformation.hh>  // for G4VUserTrackInformation
0005 
0006 #include <boost/lexical_cast.hpp>
0007 
0008 #include <iostream>  // for operator<<, basic_ostream, endl, cout
0009 #include <string>    // for string, operator<<
0010 
0011 namespace PHG4TrackUserInfo
0012 {
0013   void SetUserTrackId(G4Track* track, const int usertrackid)
0014   {
0015     if (G4VUserTrackInformation* p = track->GetUserInformation())
0016     {
0017       // User info exists, test it for something valid
0018       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0019       {
0020         pp->SetUserTrackId(usertrackid);
0021       }
0022       else
0023       {
0024         std::cout << "Unknown UserTrackInformation stored in track number "
0025                   << boost::lexical_cast<std::string>(track->GetTrackID())
0026                   << std::endl;
0027       }
0028     }
0029     else
0030     {
0031       // User info does not exist, add it.
0032       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0033       pp->SetUserTrackId(usertrackid);
0034       track->SetUserInformation(pp);
0035     }
0036   }
0037 
0038   void SetUserParentId(G4Track* track, const int userparentid)
0039   {
0040     if (G4VUserTrackInformation* p = track->GetUserInformation())
0041     {
0042       // User info exists, test it for something valid
0043       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0044       {
0045         pp->SetUserParentId(userparentid);
0046       }
0047       else
0048       {
0049         std::cout << "Unknown UserTrackInformation stored in track number "
0050                   << boost::lexical_cast<std::string>(track->GetTrackID())
0051                   << std::endl;
0052       }
0053     }
0054     else
0055     {
0056       // User info does not exist, add it.
0057       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0058       pp->SetUserParentId(userparentid);
0059       track->SetUserInformation(pp);
0060     }
0061   }
0062 
0063   void SetUserPrimaryId(G4Track* track, const int userprimaryid)
0064   {
0065     if (G4VUserTrackInformation* p = track->GetUserInformation())
0066     {
0067       // User info exists, test it for something valid
0068       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0069       {
0070         pp->SetUserPrimaryId(userprimaryid);
0071       }
0072       else
0073       {
0074         std::cout << "Unknown UserTrackInformation stored in track number "
0075                   << boost::lexical_cast<std::string>(track->GetTrackID())
0076                   << std::endl;
0077       }
0078     }
0079     else
0080     {
0081       // User info does not exist, add it.
0082       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0083       pp->SetUserPrimaryId(userprimaryid);
0084       track->SetUserInformation(pp);
0085     }
0086   }
0087 
0088   void SetWanted(G4Track* track, const int trkid)
0089   {
0090     if (G4VUserTrackInformation* p = track->GetUserInformation())
0091     {
0092       // User info exists, test it for something valid
0093       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0094       {
0095         pp->SetWanted(trkid);
0096       }
0097       else
0098       {
0099         std::cout << "Unknown UserTrackInformation stored in track number "
0100                   << boost::lexical_cast<std::string>(track->GetTrackID())
0101                   << std::endl;
0102       }
0103     }
0104     else
0105     {
0106       // User info does not exist, add it.
0107       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0108       pp->SetWanted(trkid);
0109       track->SetUserInformation(pp);
0110     }
0111   }
0112 
0113   void SetKeep(G4Track* track, const int trkid)
0114   {
0115     if (G4VUserTrackInformation* p = track->GetUserInformation())
0116     {
0117       // User info exists, test it for something valid
0118       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0119       {
0120         pp->SetKeep(trkid);
0121       }
0122       else
0123       {
0124         std::cout << "Unknown UserTrackInformation stored in track number "
0125                   << boost::lexical_cast<std::string>(track->GetTrackID())
0126                   << std::endl;
0127       }
0128     }
0129     else
0130     {
0131       // User info does not exist, add it.
0132       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0133       pp->SetKeep(trkid);
0134       track->SetUserInformation(pp);
0135     }
0136   }
0137 
0138   void SetShower(G4Track* track, PHG4Shower* shower)
0139   {
0140     if (G4VUserTrackInformation* p = track->GetUserInformation())
0141     {
0142       // User info exists, test it for something valid
0143       if (PHG4TrackUserInfoV1* pp = dynamic_cast<PHG4TrackUserInfoV1*>(p))
0144       {
0145         pp->SetShower(shower);
0146       }
0147       else
0148       {
0149         std::cout << "Unknown UserTrackInformation stored in track number "
0150                   << boost::lexical_cast<std::string>(track->GetTrackID())
0151                   << std::endl;
0152       }
0153     }
0154     else
0155     {
0156       // User info does not exist, add it.
0157       PHG4TrackUserInfoV1* pp = new PHG4TrackUserInfoV1();
0158       pp->SetShower(shower);
0159       track->SetUserInformation(pp);
0160     }
0161   }
0162 
0163 }  // namespace PHG4TrackUserInfo