Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:48

0001 #include "PHG4GenHit.h"
0002 #include "PHG4CylinderGeom.h"
0003 #include "PHG4CylinderGeomContainer.h"
0004 
0005 #include <g4main/PHG4Hit.h>
0006 #include <g4main/PHG4HitContainer.h>
0007 #include <g4main/PHG4Hitv1.h>
0008 
0009 #include <fun4all/Fun4AllReturnCodes.h>
0010 #include <fun4all/SubsysReco.h>  // for SubsysReco
0011 
0012 #include <phool/getClass.h>
0013 
0014 #include <cmath>
0015 #include <iostream>  // for operator<<, basic_ostream
0016 
0017 class PHCompositeNode;
0018 
0019 PHG4GenHit::PHG4GenHit(const std::string &name)
0020   : SubsysReco(name)
0021 {
0022 }
0023 
0024 int PHG4GenHit::process_event(PHCompositeNode *topNode)
0025 {
0026   std::string hitnodename = "G4HIT_" + detector;
0027   std::string geonodename = "CYLINDERGEOM_" + detector;
0028   PHG4CylinderGeomContainer *geo = findNode::getClass<PHG4CylinderGeomContainer>(topNode, geonodename);
0029   if (!geo)
0030   {
0031     std::cout << "cannot find geo node " << geonodename << std::endl;
0032     return Fun4AllReturnCodes::EVENT_OK;
0033   }
0034   PHG4HitContainer *hits_ = findNode::getClass<PHG4HitContainer>(topNode, hitnodename);
0035   if (!hits_)
0036   {
0037     std::cout << "cannot find hit node " << hitnodename << std::endl;
0038     return Fun4AllReturnCodes::EVENT_OK;
0039   }
0040   PHG4CylinderGeom *mygeom = geo->GetLayerGeom(layer);
0041   double inner_radius = mygeom->get_radius();
0042   double outer_radius = inner_radius + mygeom->get_thickness();
0043   PHG4Hit *hit = new PHG4Hitv1();
0044   hit->set_layer((unsigned int) layer);
0045   double x0 = inner_radius * cos(phi * M_PI / 180.);
0046   double y0 = inner_radius * sin(phi * M_PI / 180.);
0047   double z0 = inner_radius * cos(theta * M_PI / 180.);
0048   double x1 = outer_radius * cos(phi * M_PI / 180.);
0049   double y1 = outer_radius * sin(phi * M_PI / 180.);
0050   double z1 = outer_radius * cos(theta * M_PI / 180.);
0051   hit->set_x(0, x0);
0052   hit->set_y(0, y0);
0053   hit->set_z(0, z0);
0054   hit->set_x(1, x1);
0055   hit->set_y(1, y1);
0056   hit->set_z(1, z1);
0057   hit->set_edep(eloss);
0058   hit->set_trkid(-1);
0059   hits_->AddHit(layer, hit);
0060   if (Verbosity() > 0)
0061   {
0062     std::cout << "phi " << phi << " inner rad: " << inner_radius
0063               << ", outer rad: " << outer_radius
0064               << " x0/y0/z0: " << x0 << "/" << y0 << "/" << z0
0065               << " x1/y1/z1: " << x1 << "/" << y1 << "/" << z1
0066               << " edep: " << eloss
0067               << std::endl;
0068   }
0069   return Fun4AllReturnCodes::EVENT_OK;
0070 }