// PosGen_Laserball.cc // Contact person: Jose Maneira // See PosGen_Laserball.hh for more details //------------------------------------------------/// #include #include #include using namespace std; #include #include #include using namespace RAT; PosGen_Laserball::PosGen_Laserball(const std::string& dbname) : GLG4PosGen( dbname ) { // Not yet initialised - call the Init function to setup on first event fInitDB=false; } void PosGen_Laserball::BeginOfRun() { Init(); } void PosGen_Laserball::Init() { // This function should be run once on the first event (once DB all set up) warn << "PosGen_Laserball::Init: Initialising simulation settings \n"; // Load database values DBLinkPtr lLASERBALL = DB::Get()->GetLink("LASERBALL_SIMULATION"); try { fSimulationMode = lLASERBALL->GetI("simulation_mode"); } catch( DBNotFoundError& e ) { Log::Die("PosGen_Laserball: DBNotFoundError. Table " + e.table + ", index " + e.index + ", field " + e.field +"."); }; if (fSimulationMode == 3) Log::Die("PosGen_LaserBall::Init: Loading position from Camera tables not implemented yet"); std::vector aPosition; // Load position from Manip if simulation_mode = 2 if (fSimulationMode == 2){ DBLinkPtr lCAL_SOURCE = DB::Get()->GetLink("CALIB_COMMON_RUN_LEVEL","MANIP"); try { aPosition = lCAL_SOURCE->GetFArrayFromD("position"); } catch( DBNotFoundError& e ) { Log::Die("PosGen_Laserball: DBNotFoundError. Table " + e.table + ", index " + e.index + ", field " + e.field +"."); }; // Manip position comes in AV coordinates from Manip. For the simulation, it needs to be converted to PSUP coordinates std::vector avPosition = DB::Get()->GetLink("GEO", "av")->GetFArrayFromD("position"); aPosition[0] = aPosition[0] + avPosition[0]; aPosition[1] = aPosition[1] + avPosition[1]; aPosition[2] = aPosition[2] + avPosition[2]; } // Load position from LASERBALL_SIMULATION if simulation_mode = 0 else if (fSimulationMode == 0){ try { aPosition = lLASERBALL->GetFArrayFromD("position"); } catch( DBNotFoundError& e ) { Log::Die("PosGen_Laserball: DBNotFoundError. Table " + e.table + ", index " + e.index + ", field " + e.field +"."); }; } else { Log::Die(dformat("PosGen_Laserball: Unexpected simulation mode. Received %d",fSimulationMode)); } fPosition.set(aPosition[0], aPosition[1], aPosition[2]); info << "PosGen_Laserball::Init: Setting position LASERBALL_SIMULATION table to "<< (float) fPosition.x() <<" " << (float) fPosition.y() << " "<< (float) fPosition.z()<<"\n"; fInitDB = true; } void PosGen_Laserball::GeneratePosition( G4ThreeVector& argResult ) { if(!fInitDB)Init(); argResult = fPosition; } void PosGen_Laserball::SetState( G4String newValues ) { Log::Die("SetState is deprecated, do not call it. Set all variables with /rat/db/set."); return; } G4String PosGen_Laserball::GetState() const { stringstream result; result << "Laserball at (" << fPosition.x() << ", " << fPosition.y() << ", " << fPosition.z() << ")"; return result.str(); }