1 #include <utl/config.h>
8 #include <fwk/CentralConfig.h>
9 #include <fwk/RunController.h>
10 #include <fwk/CoordinateSystemRegistry.h>
11 #include <io/CorsikaUtilities.h>
13 #include <evt/Event.h>
14 #include <evt/ShowerSimData.h>
16 #include <sevt/SEvent.h>
17 #include <sevt/Station.h>
18 #include <sevt/StationSimData.h>
20 #include <det/Detector.h>
22 #include <sdet/SDetector.h>
23 #include <sdet/Station.h>
25 #include <utl/AugerUnits.h>
26 #include <utl/ErrorLogger.h>
27 #include <utl/GeometryUtilities.h>
28 #include <utl/MathConstants.h>
29 #include <utl/Particle.h>
30 #include <utl/PhysicalConstants.h>
31 #include <utl/Point.h>
32 #include <utl/TimeStamp.h>
34 #include <utl/Reader.h>
35 #include <utl/TabularStream.h>
36 #include <utl/NucleusProperties.h>
40 using namespace CachedDirectInjectorOG;
48 namespace CachedDirectInjectorOG {
74 const Point& position)
81 Round(
const double div,
const double val)
83 return round(div*val)/div;
93 useAtt[
"use"] = string(
"yes");
98 Branch partTrackB = topB.
GetChild(
"ParticleInjectionFile", useAtt);
101 ifstream
file(filename);
102 if (!file.is_open()) {
103 ERROR(
"Could not open particle-injection file.");
107 info <<
"Successfully opened particle injection file " <<
filename;
111 while (getline(file, line)) {
113 fTankToInjectedParticles[particle.
fId].push_back(particle);
119 Branch particleTankDistB = topB.
GetChild(
"ParticleTankDistanceCut");
120 if (particleTankDistB)
121 particleTankDistB.
GetData(fParticleTankDistanceCut);
124 maxPart.
GetData(fMaxParticles);
129 denseStations.
GetData(fUseDense);
132 if (denseStationsOnly)
133 denseStationsOnly.
GetData(fUseDenseOnly);
138 ERROR(
"Cannot find XML scheme for direct injection.");
153 ERROR(
"Current event does not have a simulated shower.");
164 SEvent& sEvent =
event.GetSEvent();
166 const sdet::SDetector& sDetector = det::Detector::GetInstance().GetSDetector();
168 vector<const sdet::Station*> dStationVec;
169 vector<sevt::Station*> stationVec;
171 vector<double> sRShowerFrameVec;
172 vector<double> sPhiShowerFrameVec;
178 const int sId = dStation.
GetId();
181 if (!fUseDense && dStation.
IsDense())
184 if (fUseDenseOnly && !dStation.
IsDense())
201 const Point sPos = sdIt->GetPosition();
202 const double sR = sPos.
GetRho(showerCS);
208 dStationVec.push_back(&dStation);
209 stationVec.push_back(&station);
210 sRShowerFrameVec.push_back(sR);
211 sPhiShowerFrameVec.push_back(sPos.
GetPhi(showerCS));
215 if (!dStation.
IsDense() && fTankToInjectedParticles.size()) {
216 if (fTankToInjectedParticles.count(sId)) {
218 const Vector myDir(
p.fDirX,
p.fDirY,
p.fDirZ, dStationCS);
219 const Point pShiftedPosition(
p.fR,
p.fPhi,
p.fHeight, dStationCS, Point::kCylindrical);
221 pShiftedPosition, myDir,
p.fSTime,
p.fWeight,
p.fEk);
228 const unsigned int nStations = dStationVec.size();
229 fEarliestTime.clear();
231 unsigned int nParticles = 0;
232 unsigned int nParticlesInjected = 0;
240 const Point pPosition = fParticleIt->GetPosition();
241 const double pRShowerFrame = pPosition.
GetRho(showerCS);
242 const double pPhiShowerFrame = pPosition.
GetPhi(showerCS);
243 const double pTime = fParticleIt->GetTime().GetInterval();
252 const double pPlaneFrontDelay =
254 if (pPlaneFrontDelay < -0.1*
ns)
257 for (
unsigned int si = 0; si < nStations; ++si) {
260 Station& station = *stationVec[si];
261 const unsigned int sId = dStation.
GetId();
266 if (
std::abs(sRShowerFrameVec[si] - pRShowerFrame) > fParticleTankDistanceCut ||
267 std::abs(dPhi)*sRShowerFrameVec[si] > fParticleTankDistanceCut)
271 if (earliestTime.
GetInterval() < numeric_limits<double>::min())
272 earliestTime = TimeInterval::Max();
278 bool particleHit =
false;
282 fParticleIt->GetDirection());
284 particleHit = dStation.
IsHit(fParticleIt->GetPosition(),
285 fParticleIt->GetDirection());
292 const double sHeight = dStation.
GetHeight() + 2*sThickness;
293 double injectionHeight = sHeight;
296 injectionHeight =
max(injectionHeight, scintHeight);
298 const Line particleLine(fParticleIt->GetPosition(), fParticleIt->GetDirection());
300 Vector(0, 0, 1, dStationCS));
302 const double timeShift =
303 pTime + (fParticleIt->GetPosition() - hitPoint).GetMag() /
kSpeedOfLight;
306 newParticle.
SetTime(timeShift);
308 if (timeShift < earliestTime)
309 earliestTime = timeShift;
312 ++nParticlesInjected;
315 info <<
"\nInjecting particle with ";
317 info <<
"at time = " << newParticle.
GetTime()/
utl::ns <<
" ns \n";
318 info <<
"in (x,y,z) = (" << newParticle.
GetPosition().
GetX(dStationCS)/utl::meter <<
", "
327 if (nParticlesInjected >= fMaxParticles) {
329 info <<
"Reached max number of " << nParticlesInjected <<
" injected particles.";
338 info << nParticlesInjected <<
" particles injected over "
339 << nParticles <<
" particles processed.";
342 for (
unsigned si = 0; si < nStations; ++si) {
344 const unsigned sId = dStationVec[si]->GetId();
345 const TimeStamp newTime = coreTime + fEarliestTime[sId];
349 if (!sTime || newTime < sTime)
void SetTime(const TimeInterval &time)
Branch GetTopBranch() const
VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Station Level Simulated Data
double NormalizeAngleMinusPiPi(const double x)
Normalize angle to lie between -pi and pi (-180 and 180 deg)
const utl::TimeStamp & GetTimeStamp() const
Get the TimeStamp of the absolute shower core-time.
bool HasStation(const int stationId) const
Check whether station exists.
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
utl::ShowerParticleIterator GroundParticlesEnd() const
const TimeInterval & GetTime() const
Arrival time delay at the ground.
Detector description interface for Station-related data.
void MakeSimData()
Make station simulated data object.
void SetPosition(const utl::Point &position)
bool IsInsideStation(const utl::Point &pos) const
Interface class to access to the SD part of an event.
Describes a particle for Simulation.
bool IsHit(const utl::Point &from, const utl::Vector &direction, const double halo=0) const
const utl::TimeStamp & GetPlaneFrontTime() const
Get Shower front plane arrival time.
VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
bool is(const double a, const double b)
bool HasSimShower() const
std::map< std::string, std::string > AttributeMap
void ClearParticleList()
Clear the station particle list.
#define INFO(message)
Macro for logging informational messages.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
A TimeStamp holds GPS second and nanosecond for some event.
Line Intersection(const Plane &p1, const Plane &p2)
Interface class to access Shower Simulated parameters.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
bool IsHit(const utl::Point &from, const utl::Vector &direction, utl::Point &where) const
Class representing a document branch.
class to hold data at Station level
double PlaneFrontTime(const CoordinateSystemPtr showerCS, const Point &corePosition, const Point &position)
bool HasSimData() const
Check whether station simulated data exists.
Class describing a Plane object.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
double abs(const SVector< n, T > &v)
const utl::Point & GetPosition() const
Get the position of the shower core.
StationIterator StationsEnd() const
End of the collection of pointers to commissioned stations.
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the tank.
const Scintillator & GetScintillator() const
double GetHeight() const
Height of the tank (water only)
StationIterator StationsBegin() const
Beginning of the collection of pointers to commissioned stations.
void SetPlaneFrontTime(const utl::TimeStamp &time)
Set shower front plane arrival time.
Scintillator & GetScintillator()
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
void AddParticle(const utl::Particle &particle)
void GetData(bool &b) const
Overloads of the GetData member template function.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
double GetInterval() const
Get the time interval as a double (in Auger base units)
double GetRho(const CoordinateSystemPtr &coordinateSystem) const
radius r in cylindrical coordinates (distance to z axis)
double GetKineticEnergy() const
Get kinetic energy of the particle.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
istream & operator>>(istream &is, InjectedParticle &p)
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
int CorsikaToPDG(const int corsikaCode)
converters from CORSIKA to PDG particle codes
double Round(const double div, const double val)
double GetThickness() const
Thickness of the tank walls.
struct particle_info particle[80]
bool IsDense() const
Tells whether the station belongs to set of hypothetical "dense" stations.
bool HasScintillator() const
bool HasScintillator() const
Detector description interface for SDetector-related data.
const Point & GetPosition() const
Position of the particle.
sevt::StationSimData & GetSimData()
Get simulated data at station level.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
double GetMaxHeight() const
int GetId() const
Station ID.
#define ERROR(message)
Macro for logging error messages.
utl::ShowerParticleIterator GroundParticlesBegin() const
utl::CoordinateSystemPtr GetShowerCoordinateSystem() const