Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FastPid_RICH.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FastPid_RICH.C
1 #include "FastPid_RICH.h"
2 #include "PidInfo_RICH_v1.h"
3 #include "PidInfoContainer.h"
4 #include "TrackProjectorPid.h"
5 
6 // Fun4All includes
9 
10 #include <phool/getClass.h>
11 #include <phool/PHCompositeNode.h>
12 
13 #include <g4main/PHG4Particle.h>
15 
16 #include <g4hough/SvtxTrackMap.h>
17 #include <g4hough/SvtxTrack.h>
18 #include <g4hough/SvtxTrackState.h>
19 
20 // ROOT includes
21 
22 // other C++ includes
23 #include <cassert>
24 #include <algorithm>
25 
26 using namespace std;
27 
29  SubsysReco("FastPid_RICH" ),
30  _ievent(0),
31  _detector(richname),
32  _trackmap_name(tracksname),
33  _pidinfos(nullptr),
34  _trackproj(nullptr),
35  _radius(220.)
36 {
37  _pidinfo_node_name = "PIDINFO_" + _detector;
38 }
39 
40 
41 int
43 {
44  _verbose = false;
45  _ievent = 0;
46 
47  return 0;
48 }
49 
50 
51 int
53 {
54  /* Create nodes for ParticleID */
55  try
56  {
57  CreateNodes(topNode);
58  }
59  catch (std::exception &e)
60  {
61  std::cout << PHWHERE << ": " << e.what() << std::endl;
62  throw;
63  }
64 
65  /* create track projector object */
66  _trackproj = new TrackProjectorPid( topNode );
67 
68  return 0;
69 }
70 
71 
72 int
74 {
75  _ievent ++;
76 
77  /* Get truth information (temporary) */
78  PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
79 
80  /* Get track collection with all tracks in this event */
81  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,_trackmap_name);
82 
83  /* Check if collections found */
84  if (!truthinfo) {
85  cout << PHWHERE << "PHG4TruthInfoContainer not found on node tree" << endl;
87  }
88  if (!trackmap) {
89  cout << PHWHERE << "SvtxTrackMap node not found on node tree" << endl;
91  }
92 
93  /* Loop over tracks */
94  for (SvtxTrackMap::ConstIter track_itr = trackmap->begin(); track_itr != trackmap->end(); track_itr++)
95  {
96  SvtxTrack* track_j = dynamic_cast<SvtxTrack*>(track_itr->second);
97 
98  /* Check if track_j is a null pointer. */
99  if (track_j == NULL)
100  continue;
101 
102  /* See if there's already a PidInfo object for this track. If yes, retrieve it- if not, create a new one. */
103  PidInfo *pidinfo_j = _pidinfos->getPidInfo( track_j->get_id() );
104  if (!pidinfo_j)
105  {
106  pidinfo_j = new PidInfo_RICH_v1( track_j->get_id() );
107  _pidinfos->AddPidInfo( pidinfo_j );
108  }
109 
110  /* project track to RICH volume and calculate parametrized particle ID response */
111  /* Get mean emission point from track in RICH volume */
113  if ( ! state_j_at_rich )
114  {
115  cout << "RICH track projection position NOT FOUND; next iteration" << endl;
116  continue;
117  }
118 
119  /* Attach track state to PidInfo object */
120  pidinfo_j->set_track_state( state_j_at_rich );
121 
122  /* Get truth particle associated with track */
123  PHG4Particle* particle = truthinfo->GetParticle( track_j->get_truth_track_id() );
124 
125  /* Get particle ID */
126  int pid = particle->get_pid();
127 
128  /* Use parametrized particle ID based on position and momentum at point of track projection */
129  /* @TODO: Implement parametrized particle ID */
130  { // beginning of parametrized RICH response
131 
132  /* approximate RICH acceptance */
133  float eta_min = 1.45;
134  float eta_max = 3.5;
135 
136  /* approximate momentum range for pion / kaon separation */
137  float p_min = 3.;
138  float p_max = 50.;
139 
140  /* check if track projected state in RICH acceptance */
141  if ( pidinfo_j->get_track_state()->get_eta() > eta_min && pidinfo_j->get_track_state()->get_eta() < eta_max )
142  {
143  if ( pidinfo_j->get_track_state()->get_p() > p_min && pidinfo_j->get_track_state()->get_p() < p_max )
144  {
145  /* identified kaon */
146  if ( abs( pid ) == 211 )
147  pidinfo_j->set_likelihood(PidInfo::CHARGEDPION, 1);
148 
149  /* identified kaon */
150  else if ( abs( pid ) == 321 )
151  pidinfo_j->set_likelihood(PidInfo::CHARGEDKAON, 1);
152  }
153  }
154  } // end of parametrized RICH response
155 
156  /* print some information to screen */
157  cout << "True PID: " << pid << endl;
158  cout << "Position: " << pidinfo_j->get_track_state()->get_x() << ", " << pidinfo_j->get_track_state()->get_y() << ", " << pidinfo_j->get_track_state()->get_z() << endl;
159  cout << "Momentum: " << pidinfo_j->get_track_state()->get_px() << ", " << pidinfo_j->get_track_state()->get_py() << ", " << pidinfo_j->get_track_state()->get_pz() << endl;
160  cout << "Eta, |p|: " << pidinfo_j->get_track_state()->get_eta() << ", " << pidinfo_j->get_track_state()->get_p() << endl;
161  cout << "Likelihood (electron): " << pidinfo_j->get_likelihood(PidInfo::ELECTRON) << endl;
162  cout << "Likelihood (charged pion): " << pidinfo_j->get_likelihood(PidInfo::CHARGEDPION) << endl;
163  cout << "Likelihood (charged kaon): " << pidinfo_j->get_likelihood(PidInfo::CHARGEDKAON) << endl;
164  cout << "Likelihood (proton): " << pidinfo_j->get_likelihood(PidInfo::PROTON) << endl;
165 
166  } // END loop over tracks
167 
168  return 0;
169 }
170 
171 int
173 {
174  return 0;
175 }
176 
178 {
179  PHNodeIterator iter(topNode);
180 
181  PHCompositeNode *dstNode = static_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
182  if (!dstNode)
183  {
184  std::cerr << PHWHERE << "DST Node missing, doing nothing." << std::endl;
185  throw std::runtime_error("Failed to find DST node in RICHParticleID::CreateNodes");
186  }
187 
188  PHNodeIterator dstiter(dstNode);
189  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode*>(dstiter.findFirst("PHCompositeNode",_detector ));
190  if(!DetNode){
191  DetNode = new PHCompositeNode(_detector);
192  dstNode->addNode(DetNode);
193  }
194 
195  _pidinfos = new PidInfoContainer();
196  PHIODataNode<PHObject> *pidInfoNode = new PHIODataNode<PHObject>(_pidinfos, _pidinfo_node_name.c_str(), "PHObject");
197  DetNode->addNode(pidInfoNode);
198 }