PelROOT
The Pelletron-Linac data analysis tools for ROOT

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.C
Next 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 |

Last Comments
  
Remember personal info?

Emoticons / Textile


 

  ( Register your username / Log in )

Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.

Options:

Calendar

« May 2024
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Last Comments

admin (version 3.01): Both men and women are wo…
Appannababu (Make your questio…): Hello Patrico, Thanks, I …
Patricio Carnelli… (Make your questio…): Hi Appannababu, This scri…
Appannababu (Make your questio…): Hello, I am new t…
cheap nashville p… (Using Graphical C…): Thanks for your sharing.i…
Supra Skytop (version 3.01): This topic was really edu…
Supra Sneakers (Using Graphical C…): Hey, appreciate it for ta…
Patricio Carnelli… (Make your questio…): Hello, I’m a PhD student …
Bob (Pivot 1.30 Beta 2…): And this is what a commen…

Search site

Archives

01 Sep - 30 Sep 2006
01 Dec - 31 Dec 2006
01 Jan - 31 Jan 2007
01 Feb - 28 Feb 2007
01 Mar - 31 Mar 2007
01 Apr - 30 Apr 2007
01 Jun - 30 Jun 2007
01 Oct - 31 Oct 2007
01 May - 31 May 2008
01 Oct - 31 Oct 2008
01 May - 31 May 2013
01 Nov - 30 Nov 2013
01 Jun - 30 Jun 2014

RSS & Atom

XML: RSS Feed XML: Atom Feed