source: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc@ 4019

Last change on this file since 4019 was 3973, checked in by rico, 21 years ago
*** empty log message ***
File size: 6.7 KB
Line 
1////////////////////////////////////////////////////////////////////////////////////
2//
3// _____ Source Position macro_____
4//
5// Take as input root files with hillas parameters and recompute the ones depending
6// on the source position for a new (input) position, optionally rotating it in an
7// event by event basis. Output is a file with recomputed hillas parameters
8//
9// Ester Aliu <aliu@ifae.es>
10// Oscar Blanch <blanch@ifae.es>
11// Javier Rico <jrico@ifae.es>
12////////////////////////////////////////////////////////////////////////////////////
13
14#include <fstream>
15#include <iostream>
16
17#include "TString.h"
18
19#include "MHillasSrcCalc.h"
20#include "MHillasSrc.h"
21#include "MSrcRotate.h"
22#include "MSrcTranslate.h"
23#include "MParList.h"
24#include "MTaskList.h"
25#include "MHillas.h"
26#include "MReadTree.h"
27#include "MEvtLoop.h"
28#include "MLog.h"
29#include "MArgs.h"
30#include "MWriteRootFile.h"
31
32using namespace std;
33
34Bool_t readDatacards(TString& filename);
35void srcPos();
36
37//-----------------------------------------------------------------------------
38// declaration of variables read from datacards
39//-----------------------------------------------------------------------------
40
41TString inputFile;
42TString outputFile;
43ULong_t nmaxevents=999999999;
44Float_t xsrcpos=0.;
45Float_t ysrcpos=0.;
46Bool_t kRotate=1;
47Bool_t kSrcPolicy=kTRUE;
48Double_t fRA= -1.;
49Double_t fDEC= -1.;
50
51//-----------------------------------------------------------------------------
52// constants
53//-----------------------------------------------------------------------------
54
55const TString defaultcard="srcpos.datacard";
56
57const Float_t alphamin = 0.; // minimum value in alpha (degrees)
58const Float_t alphamax = 90.; // maximum value in alpha (degrees)
59const Float_t conver = 189./0.6; // conversion factor degrees to mm
60
61//-----------------------------------------------------------------------------
62
63static void Usage()
64{
65 gLog <<endl;
66 gLog << "Usage is:" << endl;
67 gLog << " srcPos [-h] [-?] <datacards>" << endl << endl;
68 gLog << " <datacards>: datacards file name (dafault " << defaultcard <<")" << endl;
69 gLog << " -?/-h: This help" << endl << endl;
70}
71
72//-----------------------------------------------------------------------------
73int main(int argc, char **argv)
74{
75 // evaluate arguments
76 MArgs arg(argc, argv);
77 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
78 {
79 Usage();
80 return -1;
81 }
82
83 TString datacard = arg.GetArgumentStr(0);
84 if(!datacard.Length())
85 datacard = defaultcard;
86
87 if(!readDatacards(datacard))
88 {
89 cout << "Error reading datacards. Stoping" << endl;
90 return -1;
91 }
92 srcPos();
93}
94
95//-----------------------------------------------------------------------------
96void srcPos()
97{
98 // variable declaration
99 Float_t xpos=xsrcpos*conver; // [mm]
100 Float_t ypos=ysrcpos*conver; // [mm]
101
102 // containers
103 MParList plist;
104 MTaskList tlist;
105
106 // include containers in parameter list
107 plist.AddToList(&tlist);
108
109 // tasks
110 MReadTree read("Parameters", inputFile);
111 read.DisableAutoScheme();
112
113 MSrcTranslate srctranslate;
114 srctranslate.SetTranslation(xpos,ypos);
115 srctranslate.SetRelativeTranslation(kSrcPolicy);
116
117 MSrcRotate srcrotate;
118 srcrotate.SetRAandDEC(fRA,fDEC);
119
120 MHillasSrcCalc csrc1;
121
122 MWriteRootFile write(outputFile,"RECREATE");
123 write.AddContainer("MHillas" , "Parameters");
124 write.AddContainer("MHillasSrc" , "Parameters");
125 write.AddContainer("MHillasExt" , "Parameters");
126 write.AddContainer("MNewImagePar" , "Parameters");
127 write.AddContainer("MRawEvtHeader" , "Parameters");
128 write.AddContainer("MRawRunHeader" , "Parameters");
129 write.AddContainer("MConcentration" , "Parameters");
130 write.AddContainer("MSrcPosCam" , "Parameters");
131
132 // include tasks in task list
133 tlist.AddToList(&read);
134 tlist.AddToList(&srctranslate);
135 if(kRotate)
136 tlist.AddToList(&srcrotate);
137 tlist.AddToList(&csrc1);
138 tlist.AddToList(&write);
139
140 // Eventloop
141 MEvtLoop evtloop;
142 evtloop.SetParList(&plist);
143 if (!evtloop.Eventloop(nmaxevents))
144 return;
145
146 tlist.PrintStatistics();
147
148}
149//-----------------------------------------------------------------------
150
151Bool_t readDatacards(TString& filename)
152{
153 ifstream ifun(filename.Data());
154 if(!ifun)
155 {
156 cout << "File " << filename << " not found" << endl;
157 return kFALSE;
158 }
159
160 TString word;
161
162 while(ifun >> word)
163 {
164 // skip comments
165 if(word[0]=='/' && word[1]=='/')
166 {
167 while(ifun.get()!='\n'); // skip line
168 continue;
169 }
170
171 // number of events
172 if(strcmp(word.Data(),"NEVENTS")==0)
173 ifun >> nmaxevents;
174
175 // input file name
176 if(strcmp(word.Data(),"INPUTFILES")==0)
177 {
178 if(inputFile.Length())
179 cout << "readDataCards Warning: overriding on-data file name" << endl;
180 ifun >> inputFile;
181 }
182
183 // output file name
184 if(strcmp(word.Data(),"OUTFILE")==0)
185 {
186 if(outputFile.Length())
187 cout << "readDataCards Warning: overriding output file name" << endl;
188 ifun >> outputFile;
189 }
190
191 // source position
192 if(strcmp(word.Data(),"SRCPOS")==0)
193 {
194 ifun >> xsrcpos;
195 ifun >> ysrcpos;
196 }
197
198 // source celestial coordinates
199 if(strcmp(word.Data(),"SRCCOORDS")==0)
200 {
201 ifun >> fRA;
202 ifun >> fDEC;
203 }
204
205 // source movement policy flag
206 if(strcmp(word.Data(),"SRCABS")==0)
207 ifun >> kSrcPolicy;
208
209 // rotation flag
210 if(strcmp(word.Data(),"ROTFLAG")==0)
211 ifun >> kRotate;
212 }
213
214 // check compulsory values
215 if(!inputFile.Length())
216 {
217 cout << "No on-data file name specified" << endl;
218 return kFALSE;
219 }
220
221 if(!outputFile.Length())
222 {
223 cout << "No output file name specified" << endl;
224 return kFALSE;
225 }
226
227 if(xsrcpos==0 && ysrcpos==0)
228 {
229 cout << "Source position is center of the camera (as in input file)" << endl;
230 return kFALSE;
231 }
232
233 // Dump read values
234 cout << "************************************************" << endl;
235 cout << "* Datacards read from file " << filename << endl;
236 cout << "************************************************" << endl;
237 cout << "Maximum number of input events: " << nmaxevents << endl;
238 cout << "Input file name(s): " << inputFile << endl;
239 cout << "Output file name: " << outputFile << endl;
240 cout << "Source position (degrees) X=" << xsrcpos << ", Y="<<ysrcpos;
241 if(kSrcPolicy)
242 cout << " (RELATIVE TO INITIAL SOURCE POSITION)" << endl;
243 else
244 cout << " (ABSOLUTE POSITION IN THE CAMERA)" << endl;
245 cout << "De-rotation flag " << kRotate << endl;
246 cout << "Source celestial coordiantes (rad): RA = " << fRA << ", DEC = " << fDEC << endl;
247 cout << "***********" << endl << endl;
248
249 return kTRUE;
250}
Note: See TracBrowser for help on using the repository browser.