Ejemplo n.º 1
0
int
RICHEvaluator::process_event(PHCompositeNode *topNode)
{
  _ievent ++;


  /* Get truth information */
  PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");

  /* Get all photon hits in RICH for this event */
  PHG4HitContainer* richhits = findNode::getClass<PHG4HitContainer>(topNode,_richhits_name);

  /* Get track collection with all tracks in this event */
  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,_trackmap_name);

  /* Check if collections found */
  if (!truthinfo) {
    cout << PHWHERE << "PHG4TruthInfoContainer not found on node tree" << endl;
    return Fun4AllReturnCodes::ABORTEVENT;
  }
  if (!richhits) {
    cout << PHWHERE << "PHG4HitContainer not found on node tree" << endl;
    return Fun4AllReturnCodes::ABORTEVENT;
  }
  if (!trackmap) {
    cout << PHWHERE << "SvtxTrackMap node not found on node tree" << endl;
    return Fun4AllReturnCodes::ABORTEVENT;
  }


  /* Loop over tracks */
  for (SvtxTrackMap::ConstIter track_itr = trackmap->begin(); track_itr != trackmap->end(); track_itr++)
    {

      bool use_reconstructed_momentum = false;
      bool use_truth_momentum = false;
      bool use_emission_momentum = true;

      bool use_reconstructed_point = false;
      bool use_approximate_point = true;


      /* Store angles to get RMS value */
      TH1F *ch_ang = new TH1F("","",1000,0.0,1.0);
      
      SvtxTrack* track_j = dynamic_cast<SvtxTrack*>(track_itr->second);

      /* Check if track_j is a null pointer. */
      if (track_j == NULL)
        continue;


      /* Fill momv object which is the normalized momentum vector of the track in the RICH (i.e. its direction) */
      double momv[3] = {0.,0.,0.};

      if (use_reconstructed_momentum) {
	/* 'Continue' with next track if RICH projection not found for this track */
	if ( ! _trackproj->get_projected_momentum( track_j, momv, TrackProjectorPid::SPHERE, _radius ) )
	  {
	    cout << "RICH track projection momentum NOT FOUND; next iteration" << endl;
	    continue;
	  }
      }
      if (use_truth_momentum) {
	/* Fill with truth momentum instead of reco */
	if ( ! _acquire->get_true_momentum( truthinfo, track_j, momv) )
          {
            cout << "No truth momentum found for track; next iteration" << endl;
            continue;
          }
      }
      if (use_emission_momentum) {
        /* Fill with vector constructed from emission points (from truth) */
        if ( ! _acquire->get_emission_momentum( truthinfo, richhits, track_j, momv) )
          {
            cout << "No truth momentum from emission points found for track; next iteration" << endl;
            continue;
          }
      }

      double momv_norm = sqrt( momv[0]*momv[0] + momv[1]*momv[1] + momv[2]*momv[2] );
      momv[0] /= momv_norm;
      momv[1] /= momv_norm;
      momv[2] /= momv_norm;


      /* Get mean emission point from track in RICH */
      double m_emi[3] = {0.,0.,0.};

      if (use_reconstructed_point) {
	/* 'Continue' with next track if RICH projection not found for this track */
	if ( ! _trackproj->get_projected_position( track_j, m_emi, TrackProjectorPid::SPHERE, _radius  ) )
	  {
	    cout << "RICH track projection position NOT FOUND; next iteration" << endl;
	    continue;
	  }
      }
      if (use_approximate_point) {
        m_emi[0] = ((_radius)/momv[2])*momv[0];
        m_emi[1] = ((_radius)/momv[2])*momv[1];
        m_emi[2] = ((_radius)/momv[2])*momv[2];
      }


      /* 'Continue' with next track if track doesn't pass through RICH */
      if ( ! _trackproj->is_in_RICH( momv ) )
	continue;
      

      /* Calculate truth emission angle and truth mass */
      if (truthinfo)
	{
	  _theta_true = calculate_true_emission_angle( truthinfo , track_j , _refractive_index );
	}
      
      /* Loop over all G4Hits in container (i.e. RICH photons in event) */
      PHG4HitContainer::ConstRange rich_hits_begin_end = richhits->getHits();
      PHG4HitContainer::ConstIterator rich_hits_iter;
      
      for (rich_hits_iter = rich_hits_begin_end.first; rich_hits_iter !=  rich_hits_begin_end.second; ++rich_hits_iter)
	{
	  PHG4Hit *hit_i = rich_hits_iter->second;
	  PHG4Particle* particle = NULL;
	  PHG4Particle* parent = NULL;
	  PHG4VtxPoint* vertex = NULL;
	 
	  if ( truthinfo )
	    {  
	      particle = truthinfo->GetParticle( hit_i->get_trkid() );
	      parent = truthinfo->GetParticle( particle->get_parent_id() );
	      vertex = truthinfo->GetVtx( particle->get_vtx_id() );
	    }
 	  
	  _hit_x0 =  hit_i->get_x(0);
	  _hit_y0 =  hit_i->get_y(0);
	  _hit_z0 =  hit_i->get_z(0);
	  
	  _emi_x = vertex->get_x();
	  _emi_y = vertex->get_y();
	  _emi_z = vertex->get_z();
	  
	  _track_px = particle->get_px();
	  _track_py = particle->get_py();
	  _track_pz = particle->get_pz();
	  
	  _mtrack_px = parent->get_px();
	  _mtrack_py = parent->get_py();
	  _mtrack_pz = parent->get_pz();
	  _mtrack_ptot = sqrt( _mtrack_px*_mtrack_px + _mtrack_py*_mtrack_py + _mtrack_pz*_mtrack_pz );
	  
	  _track_e = particle->get_e();
	  _mtrack_e = parent->get_e();
	  _edep = hit_i->get_edep();
	  
	  _bankid = 0;
	  _volumeid = hit_i->get_detid();
	  _hitid = hit_i->get_hit_id();
	  _pid = particle->get_pid();
	  _mpid = parent->get_pid();
	  _trackid = particle->get_track_id();
	  _mtrackid = parent->get_track_id();
	  _otrackid = track_j->get_id();
	  
	  /* Set reconstructed emission angle and reconstructed mass for output tree */
	  _theta_reco = _acquire->calculate_emission_angle( m_emi, momv, hit_i );
	  ch_ang->Fill(_theta_reco);
	  
	  /* Fill tree */
	  _tree_rich->Fill();

	  
	} // END loop over photons


      _theta_rms = ch_ang->GetRMS();  
      _theta_mean = ch_ang->GetMean();
      
      /* Fill condensed tree after every track */
      _tree_rich_small->Fill();
  
      
    } // END loop over tracks


  return 0;
}