DLECorrectionGG/DLECorrection.cc
Go to the documentation of this file.
1 #include "DLECorrection.h"
2 
3 #include <evt/Event.h>
4 #include <evt/ShowerRecData.h>
5 #include <evt/ShowerSRecData.h>
6 #include <evt/ShowerSimData.h>
7 
8 #include <sevt/SEvent.h>
9 #include <sevt/Station.h>
10 #include <sevt/PMTCalibData.h>
11 #include <sevt/PMTRecData.h>
12 #include <sevt/StationRecData.h>
13 #include <sevt/StationConstants.h>
14 
15 #include <det/Detector.h>
16 
17 #include <sdet/SDetector.h>
18 
19 #include <utl/ErrorLogger.h>
20 #include <utl/MathConstants.h>
21 #include <utl/CoordinateSystemPtr.h>
22 #include <utl/AxialVector.h>
23 #include <utl/Vector.h>
24 #include <utl/Point.h>
25 #include <utl/AugerUnits.h>
26 #include <utl/PhysicalConstants.h>
27 #include <utl/Trace.h>
28 #include <utl/TraceAlgorithm.h>
29 
30 #define max(a,b) ((a) > (b) ? (a) : (b))
31 #define max3(a,b,c) (max((a),max((b),(c))))
32 
33 using namespace sdet;
34 using namespace det;
35 using namespace sevt;
36 using namespace evt;
37 using namespace std;
38 using namespace utl;
39 using namespace fwk;
40 
41 
42 namespace DLECorrection{
43 
44  const double VEM_Threshold_DLE = 0.2; //Threshold for direct light correction
46 
47  //Parametrized function to remove average azimuthal dependence
48  double DLECorrection::b(double theta){
49 
50  //Fit Result:
51  const double a = 1.60484e-03;
52  const double a0 = 2.00000e-05;
53  const double a1 = 1.70001e-03;
54  const double a2 = -1.74851e-05;
55  const double a3 = -1.35945e-01;
56  const double a4 = 5.79209e+01;
57  const double B = a*theta + (a0 + a1*theta + a2*theta*theta)
58  / (1 + exp( a3 * (theta -a4)));
59 
60  return B;
61  }
62 
63  //correcting for direct light...
64  //zenithal & azimuthal dependence:
65  void DLECorrection::Direct_Light_Azim_Depen_PMT(int pmtId, double ang,
66  double phi,
67  utl::TraceD &times)
68  {
69  if (pmtId == 1)
70  f = b(ang)*cos((phi-30.+180.)*3.14159/180.);
71  if (pmtId == 2)
72  f = b(ang)*cos((phi-270.+180.)*3.14159/180.);
73  if (pmtId == 3)
74  f = b(ang)*cos((phi-150.+180.)*3.14159/180.);
75 
76  for (int j = 0; j < fTraceSize; j++){
77  if (times[j] > VEM_Threshold_DLE)
78  times[j] -= f;
79  }
80  }
81  //correcting individual instances of Direct Light
82  void DLECorrection:: PMT2_Correction(utl::TraceD &t1,utl::TraceD &t2)
83  {
84  for (int j = 0; j < fTraceSize; j++){
85  const double s1=t1[j];
86  const double s2=t2[j];
87  const double smean=(s1+s2)/2.;
88  const double sigma=sqrt(((s1-smean)*(s1-smean)+(s2-smean)*(s2-smean))/2.);
89  if(sigma>=1.)
90  (s1>s2) ? t1[j]=t2[j] : t2[j]=t1[j] ;
91  }
92  }
93  void DLECorrection::Individual_Direct_Light_Corr(int NPMTs,sevt::Station& station, const StationConstants::SignalComponent source)
94  {
95 
96  if(NPMTs==2){
97 
98  vector<unsigned int> workingPMTsIds;
99  for (sevt::Station::PMTIterator pIt = station.PMTsBegin();
100  pIt != station.PMTsEnd(); ++pIt) {
101  if (!pIt->HasRecData())
102  continue;
103  if (!pIt->GetRecData().HasVEMTrace(source))
104  continue;
105  workingPMTsIds.push_back(pIt->GetId());
106  }
107 
108  if (workingPMTsIds.size() !=2 ){
109  INFO("DLECorrection::Individual_Direct_Light_Corr"
110  " => Something is wrong, less than 2 PMTS ");
111  return;
112  }
113  TraceD &times1 = station.GetPMT(workingPMTsIds[0]).GetRecData().GetVEMTrace(source);
114  TraceD &times2 = station.GetPMT(workingPMTsIds[1]).GetRecData().GetVEMTrace(source);
115  PMT2_Correction(times1,times2);
116 
117  }
118  else //Correction for the case the 3 PMTs work normally
119  {
120  TraceD &times1 = station.GetPMT(1).GetRecData().GetVEMTrace(source);
121  TraceD &times2 = station.GetPMT(2).GetRecData().GetVEMTrace(source);
122  TraceD &times3 = station.GetPMT(3).GetRecData().GetVEMTrace(source);
123 
124  for ( int j = 0; j < fTraceSize; j++){
125  double s1 = times1[j];
126  double s2 = times2[j];
127  double s3 = times3[j];
128  double smean = (s1+s2+s3)/3;
129  double sigma = sqrt(((s1-smean)*(s1-smean)+(s2-smean)*(s2-smean)+(s3-smean)*(s3-smean))/3);
130  if(sigma>=1.){
131  double peak = max3(s1,s2,s3);
132 
133  if(peak==s1)
134  times1[j] = (s2+s3)/2.;
135  else if(peak==s2)
136  times2[j] = (s1+s3)/2.;
137  else
138  times3[j] = (s1+s2)/2.;
139  }
140  }
141  }
142  }
143 
144 
145  void DLECorrection::CorrectDLE(Event & event, const StationConstants::SignalComponent component, const StationConstants::SignalComponent source){
146  INFO("DLECorrection::CorrectDLE()");
147  sevt::SEvent& sevent = event.GetSEvent();
148  const det::Detector& detector = det::Detector::GetInstance();
149  const CoordinateSystemPtr siteCS = detector.GetSiteCoordinateSystem();
150  evt::ShowerSRecData& showersrec = event.GetRecShower().GetSRecShower();
151  const Vector& axis = showersrec.GetAxis();
152  double theta=axis.GetTheta(siteCS)/deg;
153  double phi=axis.GetPhi(siteCS)/deg;
154 
155  //Loop over stations
156  for (SEvent::StationIterator sIt = sevent.StationsBegin();
157  sIt != sevent.StationsEnd(); ++sIt) {
158 
159  sevt::Station& station = *sIt;
160 
161  if (!station.IsCandidate()) // do not work with bad stations
162  continue;
163  if (station.IsLowGainSaturation()) // do not work with saturated stations
164  continue;
165 
166  const sdet::Station& dStation =
167  det::Detector::GetInstance().GetSDetector().GetStation(station);
168 
169  fTraceSize = dStation.GetFADCTraceLength();
170 
171  int NumberOfPMTs=0;
172  //Loop over 3 PMTs
173  for (sevt::Station::PMTIterator pIt = sIt->PMTsBegin();
174  pIt != sIt->PMTsEnd(); ++pIt) {
175  if (!pIt->HasRecData())
176  continue;
177  if (pIt->GetRecData().HasVEMTrace(component))
178  ++NumberOfPMTs;
179  }
180 
181  for (sevt::Station::PMTIterator pIt = sIt->PMTsBegin();
182  pIt != sIt->PMTsEnd(); ++pIt) {
183 
184  if (!pIt->HasRecData())
185  continue;
186 
187  PMTRecData& pmtRec = pIt->GetRecData();
188 
189  if (!pmtRec.HasVEMTrace(component))
190  continue;
191 
192  const int pmtId = pIt->GetId();
193 
194  const TraceD& vemtrace = pmtRec.GetVEMTrace(component);
195 
196  if (!pmtRec.HasVEMTrace(source))
197  pmtRec.MakeVEMTrace(source);
198 
199  for ( int i =0 ; i < fTraceSize; ++i)
200  pmtRec.GetVEMTrace(source)[i] = vemtrace[i];
201 
202  //Correct for azimuthal dependence of direct light
203  Direct_Light_Azim_Depen_PMT(pmtId,theta,phi,pmtRec.GetVEMTrace(source));
204 
205 
206  }//loop over the pmts
207  //Correct individual instances of direct light
208  if(NumberOfPMTs>1)
209  Individual_Direct_Light_Corr(NumberOfPMTs,station,source);
210 
211  } //Loop over stations
212 
213 
214  }
215 
217  }
218 
219  DLECorrection::~DLECorrection(){
220  }
221 
222 
224  {
225 
226  INFO("DLECorrection::Init()");
227 
228  return eSuccess;
229  }
230 
231 
232  VModule::ResultFlag DLECorrection::Run(evt::Event& event)
233  {
234 
235  INFO("DLECorrection::Run()");
236  if (!(event.HasSEvent() && event.HasRecShower() &&
237  event.GetRecShower().HasSRecShower()))
238  return eContinueLoop;
239 
241 
242 
243  return eSuccess;
244  }
245 
246 
247  VModule::ResultFlag DLECorrection::Finish()
248  {
249 
250  INFO("DLECorrection::Finish()");
251 
252  return eSuccess;
253  }
254 
255 }
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
utl::TraceD & GetVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal)
Traces calibrated in VEM Peak.
Definition: PMTRecData.h:46
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
Detector description interface for Station-related data.
Report success to RunController.
Definition: VModule.h:62
void MakeVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal)
Definition: PMTRecData.h:52
Interface class to access to the SD Reconstruction of a Shower.
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
PMTIterator PMTsBegin(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
begin PMT iterator for read/write
PMTRecData & GetRecData()
Get object containing PMT reconstructed data.
Definition: SEvent/PMT.h:48
Skip remaining modules in the current loop and continue with next iteration of the loop...
Definition: VModule.h:68
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
utl::CoordinateSystemPtr GetSiteCoordinateSystem() const
Get the coordinate system for the site.
Definition: Detector.h:137
boost::filter_iterator< PMTFilter, InternalPMTIterator > PMTIterator
Iterator over station for read/write.
bool IsCandidate() const
Check if the station is a candidate.
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
class to hold data at Station level
class to hold reconstructed data at PMT level
Definition: PMTRecData.h:38
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
PMTIterator PMTsEnd(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
end PMT iterator for read/write
signal after subtracting direct light (includes all particle sources).
const utl::Vector & GetAxis() const
a second level trigger
Definition: XbT2.h:8
bool IsLowGainSaturation() const
Check which gains are saturated.
#define max3(a, b, c)
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
PMT & GetPMT(const unsigned int pmtId)
Retrive a PMT by Id.
void CorrectDLE(evt::Event &event, const sevt::StationConstants::SignalComponent component, const sevt::StationConstants::SignalComponent source)
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
total (shower and background)
Vector object.
Definition: Vector.h:30
boost::indirect_iterator< InternalStationIterator, Station & > StationIterator
Iterator over all stations.
Definition: SEvent.h:52
unsigned int GetFADCTraceLength() const
bool HasVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Definition: PMTRecData.h:55
bool HasSEvent() const
const StationConstants::SignalComponent source1

, generated on Tue Sep 26 2023.