How to send parameters to a ScanRoot macro
Many times we want to change parameters values from run to run. The easiest way is to create global variables that hold those parameters and we can change them from run to run.The following example we have calibration constants A, B, C and D, or an array, called VECTOR, defined as global variables. We use these constants to apply calibration gain corrections from one run to the other. In this case, before we call go() in the GUI or in the prompt, we just set their values (after load the histogram program) as in:
ScanRoot [0]> A = 1.345; ScanRoot [1]> B = 0; ScanRoot [2]> C = 0.9845; ScanRoot [3]> D = 0.45; ScanRoot [4]> float v[] = {0.1, 0.2, 0.3}; ScanRoot [5]> VETOR = v;We can also run it as a macro. See this topic for automation scripts. In this case, before each go() you can change the variables. To execute the macro you just type, in the ScanRoot command prompt:
ScanRoot [0]> .x macro.CNext we list the codes used in this example. The first one is called histograms.cxx and it is used to create the histograms and process the events. The second code, called macro.C, is the one used to automate tasks, if necessary.
histograms.cxx
#include "TH2.h" #include "ScanRoot.h" TH2F* h2[100]; float A, B, C, D; float* VETOR; void fillHistograms(short npar, float *par) { if(npar==0) return; if(par[2]>0 && par[1]>0) { float E = par[2]*A+B+VETOR[2]; float DE = par[1]*C+D+VETOR[1]; h2[0]->Fill(E,DE); } } void bookHistograms(ScanRoot* spm) { // this next line is to be sure that the histograms are // saved in the correct ROOT directory spm->cd(); h2[0] = new TH2F("det1","detetor E-DE 1",512,0,4096,512,0,4096); // this line links the histogram filling function // to the acquisition program. spm->fillHistograms = &fillHistograms; // default values for A,B,C and D A = C = 1; B = D = 0; return; }
macro.C
void macro() { hac("histograms.cxx"); // loads the histogramming program openInput("run01.fil"); // opens the 1st .FIL file A = 1.345; B = 0; C = 0.9845; D = 0.45; float v[] = {0.1, 0.2, 0.3}; VETOR = v; go(); // process all the events in this file saveHist("file1.root"); // saves the fistograms to file1.root closeInput(); zero(); //zero all histograms. The file1.root WILL NOT be zeroed. Just the memory openInput("run02.fil"); // opens the 2nd .FIL file A = 1.216; B = 0.04; C = 1.013; D = 0.23; go(); // process all the events in this file saveHist("file2.root"); // saves the fistograms to file1.root closeInput(); }20 10 08 - 17:40
![]()
![]()