UnivRec.h
Go to the documentation of this file.
1 #ifndef __UnivRecNS_h_
2 #define __UnivRecNS_h_
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <math.h>
7 #include <vector>
8 #include <fstream>
9 
10 #define ExternalUse // Used within Offline
11 
12 #ifdef ExternalUse
13 #include <tls/Atmosphere.h>
14 #include <tls/UnivParam.h>
15 #include <tls/UnivParamTime.h>
16 #else
17 #include <ToyShower.h>
18 #endif
19 
20 #include <TVector3.h>
21 #include <tls/UnivCalibConstants.h>
22 
23 #ifndef UNDEF
24 #define UNDEF -100
25 #endif
26 
27 namespace UnivRecNS {
28 
29  const int debug=0;
30 
31  //--- Inherited from DetectorResponse.h ( change accordingly)
32 
33  //-----------------------------
34  // Detector geometry
35  //-----------------------------
36 
37  // WCD
38  const double tankh = 120.;
39  const double tankr = 180.;
40 
41  // ASCII 2 m^2
42  const double scinlength= 180.;
43  const double scinwidth = 108.;
44  const double scinheight= 1.;
45 
46  // AMIGA: 64 strips in 2 sides with 5.12 m^2 each
47  const double nMD=2.;
48  const double MDlength= 400.;
49  const double MDwidth = 128.;
50  const double MDheight= 1.;
51 
52 
53  //-----------------------------
54  //---- MC specific settings
55  //-----------------------------
56  const int nAoP=4;
57  const double AreaOverPeak_Run[nAoP]={3.60,3.60,4.30,2.93};
58  const double SmearingAngle=0.25; // Smearing angle for MC (Hybrid angular resolution)
59 
60  //Saturation ( vem signal in a FADC bin )
61  const double SaturationLevelVEM_WCD[2]={200.,2000.}; // [0] Current SDE [1] Upgraded SDE
62  const double SaturationLevelVEM_Scin[2]={200.,800.}; // [0] Current SDE [1] Upgraded SDE
63  //Saturation ( number of muons in 24 [ns] in a module with 64 scintillator bars )
64  const double SaturationLevelMD=64;
65 
66  //-----------------------------
67  //----- Likelihood related
68  //-----------------------------
69 
70  const int nQ=4;
71  const double lnP_inf=-200.;
72 
73  const int nDetectorType=3;
74 
75  const unsigned int npar=9;
76  const double unit[npar]={ 20.e2, 20.e2, 0.03, 0.20, 30., 100., 2.e-3, 2.e-3 , 0.01 };
77  const double low[npar]= { -1500.e2, -1500.e2, 17.0, 0.05, 400. , -500., -sin(25.*M_PI/180.), -sin(25.*M_PI/180.) , -0.5 };
78  const double high[npar]={ 1500.e2, 1500.e2, 22.5, 3.5 , 1200. , 500., sin(25.*M_PI/180.), sin(25.*M_PI/180.) , 0.5 };
79  const std::string ParName[npar]={ "xgcore_relative","ygcore_relative","logE", "Nmu" , "Xmax", "T0", "l", "m", "OffsetM_Mu" };
80 
81  const double edm_tolerance=0.1;
82 
83  const double InterGPSAccuracy[2]={10.,4.};
84  const double ParameterizationRMSLimit=5.;
85  const double StartAccuracy[2]={6.25,2.0}; // ASCII/WCD 25/8 [ns] traces
86  const double StartAccuracyAMIGA=2.0; // MC -> 8 [ns] traces Data -> 3.25 [ns] traces with pattern recognition
87 
88  //-----------------------------
89  //----- Station selection
90  //-----------------------------
91 
93  const double rStartCut[2]= { 0.e2,800.e2};
94  const double vemStartCut=3.;
95 
96  const double rQuantileCut[2]= { 0.e2,2000.e2};
97  const double vemTimeCut[nQ]={ 1.e10, 5., 5., 5. }; // [0] T1 [1] T10 [2] T50 [3] T90 -> WCD [vem] ASCII [mip] AMIGA [nmu]
98 
99  //---
100  const double rSignalCut[2]= {0.e2,2500.e2}; // WCD ( ASCII and AMIGA are always used if WCD is flagged as useable )
101  const double vemSignalCut=3.;
102 
103 
104  //-----------------------------
105  //----- Event selection
106  //-----------------------------
107 
108  const int nTimeStationsMin=4;
109  const int nSignalStationsMin=3;
110 
111 
112  //----------------------------------
113  // Shower Reconstruction results
114  //----------------------------------
115 
116  typedef struct RecInfo {
117 
118  int id;
119  double AugerDensity;
120  int iatm;
121 
124  double zgcore;
125 
126  double logE, logE_err;
127 
128  double Xmax, Xmax_err;
129 
130  double Nmu, Nmu_err;
131 
132  double theta;
133  double azi;
134 
135  double T0,T0_err;
136 
139 
141 
142  double RA,Dec;
143 
144  int FitStatus[2];
146 
147  double lnP[3]; //Time/Signal/Constrains
148 
149  int nStationsWCD,nStationsScin,nStationsMD; // non-accidental triggered stations above signal threshold ( Different threshold for Time/Signal rec. )
151 
152  int seed [3]; // The ids of the WCD detectors that form the triangle with the highest signal
153  TVector3 theDir_Ref;
154 
155  int FitStage;
156 
157  // Time reconstruction information
158  bool AllTimesOK; // All start time and time quantiles positive
159  double TimeRejected[2]; // Rejected station [0] Maximum standard deviation in time likelihood [1] Id of the station
160  double TimeMaxdev[2]; // [0] Maximum standard deviation in time likelihood [1] Id of the station
161 
162  // Additional information
163  double rHot;
164  int gDetHot;
166  bool IsSaturated[nDetectorType]; // WCD / ASCII / AMIGA
167 
168  } RecInfo_t;
169 
170  //----------------------------------
171  // MC info
172  //----------------------------------
173  typedef struct MCInfo{
174 
176 
178  double theta,azi;
179  double logE,Xmax,Nmu,T0;
180 
181  } MCInfo_t;
182 
183  //----------------------------------
184  // Auger standard reconstruction info
185  //----------------------------------
186  typedef struct AugerRecInfo{
187 
189  double theta_SD,azi_SD;
191  bool isGoodSD; // (Data) relax T5
192 
194  double theta_FD,azi_FD;
197  bool isGoodFD; // (Data) fiducial cuts
198 
199  double RA, dec;
200  } AugerRecInfo_t;
201 
202  //----------------------------------
203  // Rec Station
204  //----------------------------------
205  typedef struct RecStation {
206  int type; // [0] WCD [1] Scin [2] MD
207 
208  int id;
209 
210  double xg,yg,zg;
211  double GPSnano;
212  double AreaOverPeak;
213  double DetectorArea;
214 
216  double quantile[nQ],tquantile[2][nQ]; // [Resampled/Avg][iq]
220 
222  double starttime;
225  double lnP_start;
226 
228  double signalsize;
230  double lnP_signal;
231 
233 
234  double r,psi,DX[4],DL[4],T0_CF[4],T0_PF,density;
235  } RecStation_t;
236 
237 
238 
239  //----------------------------------
240  // UnivRec
241  //----------------------------------
242 
243  class UnivRec {
244 
245  public:
246  UnivRec();
247  ~UnivRec() {}
248 
249  bool InitRec( bool IsData, int RecType, int CalibOpt, int RecDetector /*all*/, int RecSys /*Only CalibOpt=-2*/ , int RecMixture /*Only CalibOpt=0,1*/ );
250  bool InitRec_InternalFramework( bool RecInfill /*all*/, int RecDataSet, int year, std::string &FileName/*Only data*/, bool RecSDEUpgrade, int RecAoP /*Only MC */);
251 
252  void InitRecStation(RecStation *station);
253  void ClearRecEvent();
254 #ifndef ExternalUse
255  bool InitEvent(ToyShowerNS::ToyShower *fevt);
256 #else
257  //#include "UnivRecCDAS.inc"
258 #endif
259  bool InitRecParameters();
260 
261  float DistPoints(float x1, float y1, float x2, float y2);
262  float NormalizeAngle(const float angle);
263 
264  void SetSPCoordinates(int idet);
265  void SetAllSPCoordinates();
266 
267  bool GetRecEstimate(int itype);
268  bool PlaneFit( bool CurvCorr, bool AltitudeCorr, bool RecSeed, int itype );
269  bool PlaneFit(std::vector<double> fX,std::vector<double>fY,std::vector<double>fT,std::vector<double>fW);
270  void GetRecSeed(int itype);
271 
272  void PrintRecInfo( bool PrintResiduals);
273  void WriteTextFile(FILE *fp);
274  bool RWRecinfo(FILE *fp, bool RWStations, bool readFlag);
275  void GetChi2(double *Chi2, int *nChi2);
276  void GetResiduals( std::vector<double> &mean, std::vector<double> &rms, std::vector<double> &rec, int optY, std::vector<double> &fx, int optX,bool OnlyNotSaturated );
277  void GetResiduals( std::vector<double> &mean, std::vector<double> &rms, std::vector<double> &rec, int optY, std::vector<double> &fx, int optX );
278  void GetMeanRMS_AoP(double &mean, double &rms);
279  bool ScanRange(int iparX, int iparY, std::vector<double> par, std::vector<int> parStatus, double *rangeX, double *rangeY, double *d,
280  double RotAngle, double errDef, double InitStep, double &edm);
281  bool ScanRange(int iparX, int iparY, std::vector<double> par, std::vector<int> parStatus, double *rangeX, double *rangeY, double *d,
282  double RotAngle, double errDef, double &edm);
283  void ScanLikelihood( int iparX, int iparY, int N, std::vector<std::pair<double,double> > &parXY, std::vector<double> &lnP,
284  std::pair<double,double> &parXY_min, double &lnP_min);
285  bool IsGoodRec();
286  bool IsGoodRec(bool CutBadYears);
287  bool CheckEnergyCut(bool PrintOut);
288 
289  void SetT0FromHot(bool UseT0_relative, double T0_relative );
290 
291  double GetTimeLikelihood();
292  double GetTimeLikelihood(bool UseAvgQuantiles);
293  double GetSignalLikelihood();
294 
295  bool Check_DX_DL( RecStation* );
296  bool SetFitStage(int FitStage);
297  bool StationSelection();
298  bool TimeSignalOK();
299  bool RejectTimeOutliers();
300  void SetOptPDF();
301 
302  void SaveFCNParameters(std::vector<double> par, std::vector<int> status );
303  int InitFCNParameters(std::vector<double> &par, std::vector<double> &epar , std::vector<int> &status ,std::vector<bool> &hasLimits);
304 
305  void Unrotate(double l_p, double m_p, double &theta, double &azi);
306  int GetErrors(std::vector<double> par, std::vector<double> &epar, std::vector<int> parStatus );
307  double GetLikelihood(std::vector<double> par, std::vector<int> status);
308 
309  //---
310  RecStation_t *GetRecStation(int idet) { return &fstation[idet]; }
311  RecInfo_t *GetRecInfo() { return &recinfo; }
312  MCInfo_t *GetMCInfo() { return &MCinfo; }
314 
315  unsigned int GetGPSsec() { return GPSsec; }
316  unsigned int GetnRecStations() { return nRecStations;}
317  bool isUpgrade() { return gRecSDE_Upgrade;}
318  bool isMC() { return gRecMC; }
319  void GetXmaxRange(double &Xmax0, double &Xmax1){ Xmax0=XmaxLow; Xmax1=XmaxHigh;}
320  void SetXmaxRange(double Xmax0, double Xmax1){XmaxLow=Xmax0; XmaxHigh=Xmax1;}
321  bool IsTimeReco(){ return IsTimeRec; }
322 
323  //private:
324  std::vector<RecStation_t> fstation;
329 
330  int gRecType;
333  int gRecAoP;
334  int gCalibOpt,gRecMixture; // Assumption done in the MC reconstruction
336  int gRecDataSet; //[0] SD standard/infill [1] Golden standard/infill [2] Golden standard/infill (no FOV) [3] SD high energy
337 
339 
340  int gRecSys;
341 
342  unsigned int GPSsec;
344 
349  };
350 
351 }
352 
353 #endif // __UnivRecNS_h_
bool SetFitStage(int FitStage)
Definition: UnivRec.cc:2145
RecInfo_t * GetRecInfo()
Definition: UnivRec.h:311
UnivParamTimeNS::UnivParamTime * ftime[nDetectorType]
Definition: UnivRec.h:347
float NormalizeAngle(const float angle)
Definition: UnivRec.cc:985
bool ScanRange(int iparX, int iparY, std::vector< double > par, std::vector< int > parStatus, double *rangeX, double *rangeY, double *d, double RotAngle, double errDef, double InitStep, double &edm)
Definition: UnivRec.cc:1596
RecInfo_t recinfo
Definition: UnivRec.h:326
double tquantile[2][nQ]
Definition: UnivRec.h:216
double quantile[nQ]
Definition: UnivRec.h:216
bool IsSaturated[nDetectorType]
Definition: UnivRec.h:166
UnivCalibConstantsNS::UnivCalibConstants * fcalib
Definition: UnivRec.h:345
double tq_rec[nQ]
Definition: UnivRec.h:217
double GetLikelihood(std::vector< double > par, std::vector< int > status)
Definition: UnivRec.cc:2514
void InitRecStation(RecStation *station)
Definition: UnivRec.cc:256
const double MDheight
Definition: UnivRec.h:50
const int debug
Definition: UnivRec.h:29
double tq_pred[nQ]
Definition: UnivRec.h:217
const double ParameterizationRMSLimit
Definition: UnivRec.h:84
const double scinwidth
Definition: UnivRec.h:43
AugerRecInfo_t augerinfo
Definition: UnivRec.h:327
const double scinheight
Definition: UnivRec.h:44
const double scinlength
Definition: UnivRec.h:42
RecStation_t * GetRecStation(int idet)
Definition: UnivRec.h:310
const double vemStartCut
Definition: UnivRec.h:94
double tq_rms[nQ]
Definition: UnivRec.h:217
double GetSignalLikelihood()
Definition: UnivRec.cc:2060
unsigned int GetGPSsec()
Definition: UnivRec.h:315
void Unrotate(double l_p, double m_p, double &theta, double &azi)
Definition: UnivRec.cc:2457
const double vemTimeCut[nQ]
Definition: UnivRec.h:97
UnivParamNS::UnivParam * fsignal[nDetectorType]
Definition: UnivRec.h:346
void GetResiduals(std::vector< double > &mean, std::vector< double > &rms, std::vector< double > &rec, int optY, std::vector< double > &fx, int optX, bool OnlyNotSaturated)
Definition: UnivRec.cc:1525
int InitFCNParameters(std::vector< double > &par, std::vector< double > &epar, std::vector< int > &status, std::vector< bool > &hasLimits)
Definition: UnivRec.cc:2333
void PrintRecInfo(bool PrintResiduals)
Definition: UnivRec.cc:1272
bool GetRecEstimate(int itype)
Definition: UnivRec.cc:1051
const unsigned int npar
Definition: UnivRec.h:75
void Chi2(int &, double *const , double &value, double *const par, const int)
const double AreaOverPeak_Run[nAoP]
Definition: UnivRec.h:57
unsigned int GPSsec
Definition: UnivRec.h:342
const double rStartCut[2]
Definition: UnivRec.h:93
const int nAoP
Definition: UnivRec.h:56
const double high[npar]
Definition: UnivRec.h:78
double OffsetM_Mu_err
Definition: UnivRec.h:140
const double MDwidth
Definition: UnivRec.h:49
void SetXmaxRange(double Xmax0, double Xmax1)
Definition: UnivRec.h:320
bool UseGausPDF_quantiles[nQ]
Definition: UnivRec.h:218
AtmosphereNS::Atmosphere * fatm
Definition: UnivRec.h:348
void SetAllSPCoordinates()
Definition: UnivRec.cc:1039
double ygcore_err
Definition: UnivRec.h:123
void ClearRecEvent()
Definition: UnivRec.cc:307
const double rSignalCut[2]
Definition: UnivRec.h:100
void GetRecSeed(int itype)
Definition: UnivRec.cc:1227
unsigned int GetnRecStations()
Definition: UnivRec.h:316
float DistPoints(float x1, float y1, float x2, float y2)
Definition: UnivRec.cc:979
MCInfo_t MCinfo
Definition: UnivRec.h:328
const double SaturationLevelMD
Definition: UnivRec.h:64
const double SmearingAngle
Definition: UnivRec.h:58
const int nDetectorType
Definition: UnivRec.h:73
bool RWRecinfo(FILE *fp, bool RWStations, bool readFlag)
Definition: UnivRec.cc:1394
void SetSPCoordinates(int idet)
Definition: UnivRec.cc:994
const int nTimeStationsMin
Definition: UnivRec.h:108
void ScanLikelihood(int iparX, int iparY, int N, std::vector< std::pair< double, double > > &parXY, std::vector< double > &lnP, std::pair< double, double > &parXY_min, double &lnP_min)
Definition: UnivRec.cc:1741
double TimeMaxdev[2]
Definition: UnivRec.h:160
double GetTimeLikelihood()
Definition: UnivRec.cc:1895
void SaveFCNParameters(std::vector< double > par, std::vector< int > status)
Definition: UnivRec.cc:2413
bool gRecSDE_Upgrade
Definition: UnivRec.h:332
const double SaturationLevelVEM_WCD[2]
Definition: UnivRec.h:61
double signalsize_pred
Definition: UnivRec.h:229
double theta_ref
Definition: UnivRec.h:138
bool Check_DX_DL(RecStation *)
Definition: UnivRec.cc:2134
struct UnivRecNS::RecStation RecStation_t
struct UnivRecNS::RecInfo RecInfo_t
bool InitRec_InternalFramework(bool RecInfill, int RecDataSet, int year, std::string &FileName, bool RecSDEUpgrade, int RecAoP)
Definition: UnivRec.cc:207
const double nMD
Definition: UnivRec.h:47
struct UnivRecNS::MCInfo MCInfo_t
std::vector< RecStation_t > fstation
Definition: UnivRec.h:324
void SetT0FromHot(bool UseT0_relative, double T0_relative)
Definition: UnivRec.cc:2474
const double StartAccuracyAMIGA
Definition: UnivRec.h:86
const double StartAccuracy[2]
Definition: UnivRec.h:85
int GetErrors(std::vector< double > par, std::vector< double > &epar, std::vector< int > parStatus)
Definition: UnivRec.cc:2629
double TimeRejected[2]
Definition: UnivRec.h:159
AugerRecInfo_t * GetAugerRecInfo()
Definition: UnivRec.h:313
struct UnivRecNS::AugerRecInfo AugerRecInfo_t
void GetChi2(double *Chi2, int *nChi2)
Definition: UnivRec.cc:1489
void GetMeanRMS_AoP(double &mean, double &rms)
Definition: UnivRec.cc:1568
const double edm_tolerance
Definition: UnivRec.h:81
const double unit[npar]
Definition: UnivRec.h:76
const bool UseStartTimeOnlyWhenSaturated
Definition: UnivRec.h:92
const double low[npar]
Definition: UnivRec.h:77
bool gDetectorTypeMask[nDetectorType]
Definition: UnivRec.h:335
const double rQuantileCut[2]
Definition: UnivRec.h:96
double AugerDensity
Definition: UnivRec.h:119
void GetXmaxRange(double &Xmax0, double &Xmax1)
Definition: UnivRec.h:319
const int nSignalStationsMin
Definition: UnivRec.h:109
const std::string ParName[npar]
Definition: UnivRec.h:79
double OffsetM_Mu
Definition: UnivRec.h:140
const double vemSignalCut
Definition: UnivRec.h:101
bool InitRec(bool IsData, int RecType, int CalibOpt, int RecDetector, int RecSys, int RecMixture)
Definition: UnivRec.cc:127
static std::vector< int > parStatus
bool RejectTimeOutliers()
Definition: UnivRec.cc:2277
int FitStatus[2]
Definition: UnivRec.h:144
bool InitRecParameters()
Definition: UnivRec.cc:892
double lnP[3]
Definition: UnivRec.h:147
const double tankh
Definition: UnivRec.h:38
double logE_ref_err
Definition: UnivRec.h:137
bool PlaneFit(bool CurvCorr, bool AltitudeCorr, bool RecSeed, int itype)
Definition: UnivRec.cc:1095
bool isUpgrade()
Definition: UnivRec.h:317
const double InterGPSAccuracy[2]
Definition: UnivRec.h:83
bool StationSelection()
Definition: UnivRec.cc:2162
TVector3 theDir_Ref
Definition: UnivRec.h:153
void WriteTextFile(FILE *fp)
double tq_corr[nQ]
Definition: UnivRec.h:217
MCInfo_t * GetMCInfo()
Definition: UnivRec.h:312
double xgcore_err
Definition: UnivRec.h:122
const int nQ
Definition: UnivRec.h:70
bool IsTimeReco()
Definition: UnivRec.h:321
const double MDlength
Definition: UnivRec.h:48
const double tankr
Definition: UnivRec.h:39
const double lnP_inf
Definition: UnivRec.h:71
const double SaturationLevelVEM_Scin[2]
Definition: UnivRec.h:62
const double year
Definition: GalacticUnits.h:22
bool CheckEnergyCut(bool PrintOut)
Definition: UnivRec.cc:1872

, generated on Tue Sep 26 2023.