2222// /A program
2323int main (int argc, char *argv[]) {
2424 if (argc < 7 || (argc > 9 && argc < 11 ) || argc > 13 ) {
25- printf (" Usage: %s <module> <channel> <parameter name> <numSteps > <start > <stop > [runtime] [scan.root]\n " ,argv[0 ]);
25+ printf (" Usage: %s <module> <channel> <parameter name> <start > <stop > <stepSize > [runtime] [scan.root]\n " ,argv[0 ]);
2626 return EXIT_FAILURE;
2727 }
2828
@@ -31,43 +31,60 @@ int main(int argc, char *argv[]) {
3131
3232 struct parInfo {
3333 const char * parName;
34- const int numSteps;
3534 const double startVal;
3635 const double stopVal;
36+ const double stepSize;
3737 double value;
38- double stepSize ;
38+ int maxNumSteps ;
3939 double initialVal; // /<Value of parameter prior to scan.
4040 };
4141 int mod = atoi (argv[1 ]);
4242 int ch = atoi (argv[2 ]);
43- parInfo *par1 = new parInfo {argv[3 ],atoi (argv[4 ]),atof (argv[5 ]), atof (argv[6 ])};
43+ parInfo *par1 = new parInfo {argv[3 ],atof (argv[4 ]),atof (argv[5 ]), atof (argv[6 ])};
4444 const char * outputFilename = " scan.root" ;
4545 float runTime = 10 ;
4646 parInfo *par2;
4747 if (argc < 11 ) {
4848 isTwoDim = false ;
49- par2 = new parInfo{" " ,1 ,0 , 0 };
49+ par2 = new parInfo{" " ,1 ,1 , 1 };
5050 if (argc > 7 )
5151 runTime = atoi (argv[7 ]);
5252 if (argc == 9 )
5353 outputFilename = argv[8 ];
5454 }
5555 else {
5656 isTwoDim = true ;
57- par2 = new parInfo{argv[7 ],atoi (argv[8 ]),atof (argv[9 ]), atof (argv[10 ])};
57+ par2 = new parInfo{argv[7 ],atof (argv[8 ]),atof (argv[9 ]), atof (argv[10 ])};
5858 if (argc > 11 )
5959 runTime = atoi (argv[11 ]);
6060 if (argc == 13 )
6161 outputFilename = argv[12 ];
6262 }
6363
6464 std::cout << " Scanning M" << mod << " C" << ch << " \n " ;
65- std::cout << " Scanning " << par1->parName << " over " << par1->numSteps << " steps from " << par1->startVal << " ->" << par1->stopVal << " \n " ;
66- if (isTwoDim) std::cout << " Scanning " << par2->parName << " over " << par2->numSteps << " steps from " << par2->startVal << " ->" << par2->stopVal << " \n " ;
65+ std::cout << " Scanning " << par1->parName << " from " << par1->startVal << " ->" << par1->stopVal << " with steps of " << par1->stepSize << " \n " ;
66+ if (isTwoDim) {
67+ std::cout << " Scanning " << par2->parName << " from " << par2->startVal << " ->" << par2->stopVal << " with steps of " << par2->stepSize << " \n " ;
68+ }
6769 std::cout << " MCA Run time: " << runTime << " s\n " ;
6870 std::cout << " Scan output: " << outputFilename << " \n " ;
6971
72+ par1->maxNumSteps = fabs ((par1->stopVal - par1->startVal ) / par1->stepSize ) + 1.5 ;
73+ par2->maxNumSteps = fabs ((par2->stopVal - par2->startVal ) / par2->stepSize ) + 1.5 ;
74+ if (!isTwoDim) par2->maxNumSteps = 0 ;
75+
76+ std::cout << " Max number of steps: " << par1->maxNumSteps ;
77+ if (isTwoDim) std::cout << " , " << par2->maxNumSteps ;
78+ std::cout << " \n " ;
79+
80+ if (!isTwoDim) std::cout << " Maximum scan time: " << (par1->maxNumSteps * runTime) / 60.0 << " m\n " ;
81+ else std::cout << " Maximum scan time: " << (par1->maxNumSteps * par2->maxNumSteps * runTime) / 60.0 << " m\n " ;
82+
83+ // Set par1 inital scan value
84+ par1->value = par1->startVal - par1->stepSize ;
85+
7086
87+ std::cout << " \n " ;
7188 PixieInterface pif (" pixie.cfg" );
7289 pif.GetSlots ();
7390
@@ -81,10 +98,16 @@ int main(int argc, char *argv[]) {
8198
8299 pif.RemovePresetRunLength (0 );
83100
84- pif.ReadSglChanPar (par1->parName , &par1->initialVal , mod, ch);
101+ if (!pif.ReadSglChanPar (par1->parName , &par1->initialVal , mod, ch)) {
102+ std::cout << " Check parameter name!\n " ;
103+ return EXIT_FAILURE;
104+ }
85105 std::cout << par1->parName << " initial value: " << par1->initialVal << " \n " ;
86106 if (isTwoDim) {
87- pif.ReadSglChanPar (par2->parName , &par2->initialVal , mod, ch);
107+ if (!pif.ReadSglChanPar (par2->parName , &par2->initialVal , mod, ch)) {
108+ std::cout << " Check parameter name!\n " ;
109+ return EXIT_FAILURE;
110+ }
88111 std::cout << par2->parName << " initial value: " << par2->initialVal << " \n " ;
89112 }
90113
@@ -94,16 +117,7 @@ int main(int argc, char *argv[]) {
94117
95118 MCA_ROOT *mca = new MCA_ROOT (&pif," MCA" );
96119
97- // Set inital par1 steps
98- par1->stepSize = (par1->stopVal - par1->startVal ) / (par1->numSteps );
99- par1->value = par1->startVal - par1->stepSize ;
100- // Set inital par2 steps
101- par2->stepSize = (par2->stopVal - par2->startVal ) / (par2->numSteps );
102-
103- printf (" Par 1 step size: %f\n " ,par1->stepSize );
104- if (isTwoDim) printf (" Par 2 step size: %f\n " ,par2->stepSize );
105-
106- for (int step = 0 ; step < par1->numSteps ; ++step) {
120+ for (int step = 0 ; step <= par1->maxNumSteps ; ++step) {
107121 double readback = par1->value ;
108122
109123 // Keep iterating until the value changes
@@ -126,7 +140,7 @@ int main(int argc, char *argv[]) {
126140 // Reset par2 value
127141 par2->value = par2->startVal - par2->stepSize ;
128142
129- for (int step2 = 0 ; step2 < par2->numSteps ; ++step2) {
143+ for (int step2 = 0 ; step2 <= par2->maxNumSteps ; ++step2) {
130144 if (isTwoDim) {
131145 readback = par2->value ;
132146
@@ -138,10 +152,10 @@ int main(int argc, char *argv[]) {
138152
139153 // Write parameter value
140154 pif.WriteSglChanPar (par2->parName ,par2->value ,mod,ch);
141- pif.SaveDSPParameters ();
142155 // Read back the value to see what it actually was set to.
143156 pif.PrintSglChanPar (par2->parName , mod, ch);
144157 pif.ReadSglChanPar (par2->parName , &readback, mod, ch);
158+ pif.SaveDSPParameters ();
145159 }
146160 if (par2->value > par2->stopVal || readback > par2->stopVal ) break ;
147161 par2->value = readback;
@@ -151,7 +165,7 @@ int main(int argc, char *argv[]) {
151165 mca->Run (runTime);
152166
153167 TH1* hist = mca->GetHistogram (mod,ch);
154- TSpectrum *s = new TSpectrum (100 );
168+ TSpectrum *s = new TSpectrum (10 );
155169 s->Search (hist);
156170 TF1 *func = new TF1 (" func" ," gaus" );
157171
@@ -176,13 +190,16 @@ int main(int argc, char *argv[]) {
176190 // E Error Estimation
177191 hist->Fit (func," RQME" );
178192
179- float res = 100 * func->GetParameter (2 ) / func->GetParameter (1 );
180- float resErr = res * sqrt (pow (func->GetParError (1 )/func->GetParameter (1 ),2 ) +
181- pow (func->GetParError (2 )/func->GetParameter (2 ),2 ));
193+ float res = 100 * func->GetParameter (2 ) / func->GetParameter (1 ) *
194+ 2 * sqrt (2 * log (2 ));
195+ float resErr = res *
196+ sqrt (pow (func->GetParError (1 )/func->GetParameter (1 ),2 ) +
197+ pow (func->GetParError (2 )/func->GetParameter (2 ),2 )) *
198+ 2 * sqrt (2 * log (2 ));
182199
183200 if (!isTwoDim) printf (" Loop: %2d %5f " ,step,par1->value );
184201 else printf (" Loop: %2d:%2d %5f %5f " ,step,step2,par1->value ,par2->value );
185- printf (" res: %5f%% FWHM Res: %5f%%\n\n " ,res,res * 2 * sqrt (2 *log (2 )));
202+ printf (" res: %5f%% FWHM Res: %5f%%\n\n " ,res / 2 / sqrt (2 *log (2 )), res );
186203 if (!isTwoDim) {
187204 gr->SetPoint (gr->GetN (),par1->value ,res);
188205 gr->SetPointError (gr->GetN ()-1 ,0 ,resErr);
@@ -209,21 +226,21 @@ int main(int argc, char *argv[]) {
209226 // Set the titles at the end so that the TGraph2D histogram has been created.
210227 if (!isTwoDim) {
211228 gr->GetXaxis ()->SetTitle (Form (" %s" ,par1->parName ));
212- gr->GetYaxis ()->SetTitle (" Resolution" );
229+ gr->GetYaxis ()->SetTitle (" FWHM Resolution [%] " );
213230 gr->SetMinimum (0 );
214231 }
215232 else {
216233 gr2d->GetXaxis ()->SetTitle (Form (" %s" ,par1->parName ));
217234 gr2d->GetYaxis ()->SetTitle (Form (" %s" ,par2->parName ));
218- gr2d->GetZaxis ()->SetTitle (" Resolution" );
235+ gr2d->GetZaxis ()->SetTitle (" FWHM Resolution [%] " );
219236 gr2d->SetMinimum (0 );
220237 }
221238
222239 std::cout << par1->parName << " \t " << " sigmaRes\t " << " FwhmRes\n " ;
223240 for (int i=0 ;i<gr->GetN ();i++) {
224241 double x,y;
225242 if (gr->GetPoint (i,x,y) == i)
226- std::cout << x << " \t " << y << " \t " << y * 2 * sqrt (2 * log (2 )) << " \n " ;
243+ std::cout << x << " \t " << y / 2 / sqrt (2 * log (2 )) << " % \t " << y << " % \n " ;
227244
228245 }
229246
0 commit comments