ShowerMaker.cc
Go to the documentation of this file.
1 #include <fwk/CentralConfig.h>
2 #include <fwk/LocalCoordinateSystem.h>
3 #include <fwk/CoordinateSystemRegistry.h>
4 #include <utl/Point.h>
5 #include <evt/Header.h>
6 #include <evt/Event.h>
7 #include <evt/ShowerRecData.h>
8 #include <evt/ShowerSRecData.h>
9 #include <utl/TimeStamp.h>
10 #include <utl/AugerUnits.h>
11 #include <det/Detector.h>
12 #include <rdet/RDetector.h>
13 #include <boost/tokenizer.hpp>
14 
15 #include "ShowerMaker.h"
16 
17 
18 //Just for Ben
19 
20 #include <rdet/Station.h>
21 #include <TMath.h>
22 using namespace std;
23 using namespace evt;
24 using namespace utl;
25 using namespace fwk;
26 using namespace det;
27 typedef boost::tokenizer<boost::char_separator<char> > mytok;
28 
29 namespace ShowerMaker {
30 
32  fHeraldFilePath("/localdata/melissas/NewSimParams/shower_parameter_test_file.txt"),
33  fHeraldStream(NULL),
34  frand2(4173),
35  // DEBUG
36  foutfile(NULL),
37  fH2_GroundMap(NULL),
38  fDetGraph(NULL),
39  fH2_Skymap(NULL),
40  fH_energy(NULL),
41  fH_theta(NULL),
42  fH_phi(NULL)
43  {
44  }
45  ShowerMaker::~ShowerMaker() {
46  if (fHeraldStream!=NULL) delete fHeraldStream;
47  //for debug
48  /*
49  if (foutfile!=NULL) delete foutfile;
50  if (fH2_GroundMap!=NULL) delete fH2_GroundMap;
51  if (fH2_Skymap!=NULL) delete fH2_Skymap;
52  if (fH_energy!=NULL) delete fH_energy;*/
53  //
54  }
55 
57 //Debug
58  foutfile= new TFile("out.root","RECREATE");
59  fH2_GroundMap = new TH2F("GroundMap","GroundMap",700,-500,6500,350,-200,+3300);
60  fH2_Skymap = new TH2F("skymap","sky",180,-2*TMath::Pi(),2*TMath::Pi(),180,-2*TMath::Pi(),2*TMath::Pi());
61  fH_phi = new TH1F("phi","phi",180,0,360);
62  fH_theta = new TH1F("theta","theta",45,0,90);
63  fH_energy = new TH1F("nrj","nrj",30,17,20);
64  fHeraldStream = new ifstream(fHeraldFilePath.c_str(), ios_base::in);
65  string index("");
66  boost::char_separator<char> sep(" ");
67  getline(*fHeraldStream,index);
68  mytok tok(index,sep);
69  int ii=0;
70  for(mytok::const_iterator titer=tok.begin();titer!=tok.end();++titer) {
71  if (*titer=="#") continue;
72  fm_index[string(*titer)]=ii;
73  ii++;
74  }
75  unsigned int seed=46150;
76  frand2.SetSeed(seed);
77  return VModule::eSuccess;
78  }
79 
80  fwk::VModule::ResultFlag ShowerMaker::Run(evt::Event& theevent ) {
81  if (fHeraldStream->eof()) {
82  INFO("End Of File Reached");
83  return eBreakLoop;
84  }
85  string zeline("");
86  getline(*fHeraldStream,zeline);
87 // event->MakeSEvent();
88  theevent.MakeRecShower();
89  ShowerRecData& Show= theevent.GetRecShower();
90  Show.MakeSRecShower();
91  ShowerSRecData& SdShow = Show.GetSRecShower();
92  boost::char_separator<char> sep(" ");
93  mytok tok(zeline,sep);
94  vector<string> zetokens;
95  for(mytok::const_iterator titer=tok.begin();titer!=tok.end();++titer) {
96  zetokens.push_back(*titer);
97  }
98 // for (int i=0;i<zetokens.size();++i) {
99  // cout <<i<< "\t" << zetokens[i]<<endl;
100 // }
101  if (zetokens.size()<12) {
102 
103  for (unsigned int i=0;i<zetokens.size();++i) cout << " " << zetokens[i];
104  cout <<endl;
105  return eContinueLoop;}
106  Detector& Det = Detector::GetInstance();
108  const rdet::RDetector& RadioDet = Det.GetRDetector();
109 // Point refpos=RadioDet.GetStation(115).GetPosition(); // For AERA Ideal = AERA_13
110  Point refpos=RadioDet.GetStation(113).GetPosition(); // For AERA Real = AERA_13
111 // Point refpos=RadioDet.GetStation(10).GetPosition(); // For MAXIMA = M4
112 
113  // get reference coordinate system from detector (usually PampaAmarilla)
115  float coreX=atof(zetokens[fm_index["fXCore"]].c_str())*m;
116  float coreY=atof(zetokens[fm_index["fYCore"]].c_str())*m;
117  float coreZ=refpos.GetZ(coordsys);
118 // float coreZ=0;
119  Point core(coreX,coreY,coreZ,coordsys);
120  cout << "X : " << core.GetX(coordsys)/m << " Y: " << core.GetY(coordsys)/m << " Z : " << core.GetZ(coordsys)/m << endl;
121  SdShow.SetCorePosition(core);
122  //Get ID;
123  //int eventid=0;
124  //eventid=atoi(zetokens[fm_index["AugerId"]].c_str());
125 
126  //This piece of code is used to keep a monitoring plot of core positions
127  //double x=0;
128  //double y=0;
129  Point refst153=RadioDet.GetStation(115).GetPosition();
131  if (fDetGraph==NULL) {
132  const vector<int>& v_stid= RadioDet.GetFullStationList();
133  fDetGraph = new TGraph(v_stid.size());
134  int icount=0;
135  for (vector<int>::const_iterator stiter=v_stid.begin();stiter!=v_stid.end();++stiter) {
136  Point pos=RadioDet.GetStation(*stiter).GetPosition();
137  fDetGraph->SetPoint(icount,pos.GetX(refCS)*m,pos.GetY(refCS)*m);
138  ++icount;
139  }
140  }
141  /*************************************************************************************
142  * This bunch of code can generate a random core position in some position *
143  * Please uncomment the case you want to generate *
144  *************************************************************************************
145 
146  //Circle around AERA_11
147  Point statpos=RadioDet.GetStation(113).GetPosition();
148  const CoordinateSystemPtr statCS = fwk::LocalCoordinateSystem::Create(statpos);
149  double radius=550;
150  this->Diskgen(frand2,x,y,radius);
151  x*=m;
152  y*=m;
153  Point newcore(x,y,0,statCS);
154  SdShow.SetCorePosition(newcore);
155  fH2_GroundMap->Fill(newcore.GetX(refCS),newcore.GetY(refCS));
156  //Circle around AERA_28
157  Point statpos=RadioDet.GetStation(128).GetPosition(); //AERA_28
158  const CoordinateSystemPtr statCS = fwk::LocalCoordinateSystem::Create(statpos);
159  double radius=1000;
160  this->Diskgen(frand2,x,y,radius);
161 // frand2.Circle(x,y,radius);
162  x*=m;
163  y*=m;
164  Point newcore(x,y,0,statCS);
165  SdShow.SetCorePosition(newcore);
166  fH2_GroundMap->Fill(newcore.GetX(refCS),newcore.GetY(refCS));
167 
168  //Random in the AERA_ARRAY
169  x=0;y=0;
170  while (1==1) {
171  x=-200+frand2.Rndm()*6550;
172  y=-250+frand2.Rndm()*3500;
173  if (x<=3800 && y<0.51*x+1200) break;
174  if (x>3800 && x<=5200) break;
175  if (x>5200 && y<2000) break;
176 
177  x*=m;y*=m;
178  Point newcore(x,y,0,refCS);
179  fH2_GroundMap->Fill(x,y);
180  SdShow.SetCorePosition(newcore);
181  fH2_GroundMap->Fill(newcore.GetX(refCS),newcore.GetY(refCS));
182  }
183  ************************************************************************************
184  * End of the Random core setting *
185  ***********************************************************************************/
186 
187  //float energy=atof(zetokens[fm_index["Energy(CIC+FD_cal)"]].c_str())*EeV;
188  float energy=atof(zetokens[fm_index["Energy(CICINFILL)"]].c_str())*EeV;
189  fH_energy->Fill(TMath::Log10(energy/eV));
190  SdShow.SetEnergy(energy,energy/4.);
191  Show.SetEnergy(energy,energy/4.);
192 // cout << " MM :: Energy ==" << zetokens[fm_index["Energy(CIC+FD_cal)"]] << "UTCTime " << zetokens[fm_index["UTCTime"]].c_str() <<endl ;
193  cout << " MM :: Energy ==" << zetokens[fm_index["Energy(CICINFILL)"]] << "UTCTime " << zetokens[fm_index["UTCTime"]].c_str() <<endl ;
194  cout << " MM :: " << fm_index["AugerId"] << " " << fm_index["NrStations"] << " " << fm_index["UTCTime"] << endl;
195 // Show.SetAzimuthAngle(atof(zetokens[11].c_str()));
196 // Show.SetZenithAngle(atof(zetokens[10].c_str()));
197 // CoordinateSystemPtr coresys=core.GetCoordinateSystem();
199 // utl::Vector axis(1/tan(atof(zetokens[11].c_str())*degree),1,cos(atof(zetokens[10].c_str())*degree),coresys);
200 
201  float theta=atof(zetokens[fm_index["Theta"]].c_str())*degree;
202  float phi=atof(zetokens[fm_index["Phi"]].c_str())*degree;
203 // float theta=atof(zetokens[fm_index["LocalTheta"]].c_str())*degree;
204 // float phi=atof(zetokens[fm_index["LocalPhi"]].c_str())*degree;
205  cout << " MM :: " << theta/degree << " ph "<< phi/degree <<endl;
206  fH2_Skymap->Fill(theta,phi);
207  fH_theta->Fill(theta/degree);
208  fH_phi->Fill(phi/degree);
209 // utl::Vector axis(cos(phi)*sin(theta),sin(phi)*sin(theta),cos(theta),coresys);
210  utl::Vector axis(cos(phi)*sin(theta),sin(phi)*sin(theta),cos(theta),coordsys);
211  SdShow.SetAxis(axis);
212  Header& head=theevent.GetHeader();
213  head.SetId(zetokens[fm_index["AugerId"]]);
214  TimeStamp ts(atoi(zetokens[fm_index["UTCTime"]].c_str()),atoi(zetokens[fm_index["fRec.fT0"]].c_str()));
215  head.SetTime(ts);
216  det::Detector::GetInstance().Update(head.GetTime());
217  return VModule::eSuccess;
218  }
219  VModule::ResultFlag ShowerMaker::Finish() {
220  fHeraldStream->close();
221  fH2_GroundMap->Write();
222  fH2_Skymap->Write();
223  fH_energy->Write();
224  fDetGraph->Write();
225 // fH_phi->Write();
226  fH_theta->Write();
227  foutfile->Close();
228  return VModule::eSuccess;
229  }
230  void ShowerMaker::Diskgen(TRandom2& rnd, double& x, double& y, double r) {
231  double phi = rnd.Rndm()*TMath::TwoPi();
232  double radius=rnd.Rndm()*r;
233  x = radius*TMath::Cos(phi);
234  y= radius*TMath::Sin(phi);
235  }
236  } // namespace;
const double eV
Definition: GalacticUnits.h:35
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
const double degree
Point object.
Definition: Point.h:32
evt::Header & GetHeader()
Interface class to access to the SD Reconstruction of a Shower.
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
void SetTime(const utl::TimeStamp &t)
Definition: Event/Header.h:38
CoordinateSystemPtr GetCoordinateSystem() const
Get the coordinate system of the current internal representation.
Definition: BasicVector.h:234
Skip remaining modules in the current loop and continue with next iteration of the loop...
Definition: VModule.h:68
ShowerRecData & GetRecShower()
const std::vector< int > & GetFullStationList() const
Get list of ID&#39;s for all stations available in the database or configuration file.
Definition: RDetector.cc:84
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
const double EeV
Definition: GalacticUnits.h:34
std::string fHeraldFilePath
Definition: ShowerMaker.h:29
ShowerSRecData & GetSRecShower()
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
void SetId(const std::string &id)
Set the event identifier.
Definition: Event/Header.h:36
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Break current loop. It works for nested loops too!
Definition: VModule.h:66
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
void SetEnergy(const double energy, const double error)
std::ifstream * fHeraldStream
Definition: ShowerMaker.h:30
void SetAxis(const utl::Vector &axis)
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
boost::tokenizer< boost::char_separator< char > > mytok
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Definition: Detector.h:141
Vector object.
Definition: Vector.h:30
TimeStamp GetCurrentSystemTime()
get current time as reported by system
Definition: TimeStamp.cc:46
const utl::Point & GetCorePosition() const
void SetCorePosition(const utl::Point &core)
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
void SetEnergy(const double energy, const double error)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
constexpr double m
Definition: AugerUnits.h:121
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
Global event header.
Definition: Event/Header.h:27
std::map< std::string, unsigned int > fm_index
Definition: ShowerMaker.h:31

, generated on Tue Sep 26 2023.