Skip to content

Commit f1b2c6d

Browse files
committed
added documentation to the .C files
Signed-off-by: acolijn <auke.pieter.colijn@gmail.com>
1 parent 75e7406 commit f1b2c6d

File tree

6 files changed

+91
-27
lines changed

6 files changed

+91
-27
lines changed

calibration/analyzer.C

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
#define analyzer_cxx
2+
/*---------------------------------------------------------------------------------------------------*/
3+
//
4+
// analyzer.C Routine to analyze spectra and calculate the rate of the sources
5+
//
6+
// Usage:
7+
// prompt> #include "analyzer.C"
8+
// prompt> analyzer ana(<directory_with_energy_calibrated_rootfiles>,<analysis_output_rootfile>)
9+
// prompt> ana.Loop()
10+
//
11+
// To inspect the fit results it is possible to plot the fit results. In analyzer.h set:
12+
// #define PLOT_ON_SCREEN 1
13+
//
14+
// To set the time interval in which a spectrum is calculated, in analyzer.h set:
15+
// #define TIME_INTERVAL <interval_in_seconds>
16+
//
17+
// A.P.
18+
/*---------------------------------------------------------------------------------------------------*/
219
#include "analyzer.h"
320
// RooFit include files
421
#include <RooRealVar.h>
@@ -59,6 +76,10 @@ const float base_max_val = 2000;
5976

6077

6178
/*----------------------------------------------------------------------------------------------------*/
79+
80+
//
81+
// Gaussian function + 2nd order polynomial for simple rate fitting
82+
//
6283
Double_t fitf(Double_t *v, Double_t *par)
6384
{
6485
Double_t arg = 0;
@@ -74,7 +95,6 @@ void analyzer::fit_spectrum(int ichannel, double *fit_range){
7495
//
7596
// RooFit based spectrum fitter
7697
//
77-
//
7898
cout <<"analyzer::fit_spectrum channel = "<<ichannel<<endl;
7999
//
80100
// identify the peaks in our specified energy range and store their peak ID.
@@ -106,11 +126,14 @@ void analyzer::fit_spectrum(int ichannel, double *fit_range){
106126
//
107127
string mc_file="";
108128
if (ichannel == 2 || ichannel == 3){
109-
mc_file = "/user/z37/Modulation/analysis/calibration/MC_ti44_modulation.root";
129+
// mc_file = "/user/z37/Modulation/analysis/calibration/MC_ti44_modulation.root";
130+
mc_file = "MC_ti44_modulation.root";
110131
} else if(ichannel == 4 || ichannel == 5){
111-
mc_file = "/user/z37/Modulation/analysis/calibration/MC_co60_modulation.root";
132+
// mc_file = "/user/z37/Modulation/analysis/calibration/MC_co60_modulation.root";
133+
mc_file = "MC_co60_modulation.root";
112134
} else if(ichannel == 6 || ichannel == 7){
113-
mc_file = "/user/z37/Modulation/analysis/calibration/MC_cs137_modulation.root";
135+
// mc_file = "/user/z37/Modulation/analysis/calibration/MC_cs137_modulation.root";
136+
mc_file = "MC_cs137_modulation.root";
114137
}
115138

116139
TFile *f_mc = new TFile(mc_file.c_str(),"READONLY");
@@ -267,7 +290,7 @@ void analyzer::fit_spectrum(int ichannel){
267290
//
268291
// spectrum is a function of the energy
269292
//
270-
RooRealVar E("E (keV)","E (keV)",emin,emax);
293+
RooRealVar E("E","E (keV)",emin,emax);
271294

272295
//
273296
// the background template for each of the sources obtained from a GEANT4 simulation

calibration/ecal.C

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@
1111
#include <vector>
1212
#include <stdio.h>
1313

14+
/*---------------------------------------------------------------------------------------------------*/
15+
//
16+
// ecal.C Routine to do the energy calibration of a modulation run
17+
//
18+
// Usage:
19+
// prompt> #include "ecal.C"
20+
// prompt> ecal e(<directory_with_uncalibrated_rootfiles>,<calibration_output_rootfile>)
21+
// prompt> e.Loop()
22+
//
23+
// Important parameter in ecal.h: CALIBRATION_MODE 0 : one calibration for full run (not adviced)
24+
// CALIBRATION_MODE 1 : re-calibrate every TIME_INTERVAL seconds (see ecal.h)
25+
//
26+
// A.P.
1427
/*---------------------------------------------------------------------------------------------------*/
1528
// (1) You need to identify where the first peak is in the histograms of the integrals.
1629
// (2) Set range_low and range_high to find the range in which the peak with cal_energy should be
1730
const double range_low[NUMBER_OF_CHANNELS] ={0.16e-6,0.14e-6,0.05e-6,0.05e-6,0.,0.,0.,0.};
1831
const double range_high[NUMBER_OF_CHANNELS]={1e-6,1e-6,1e-6,1e-6,1e-6,1e-6,1e-6,1e-6};
1932

33+
/*---------------------------------------------------------------------------------------------------*/
2034
float source_energy[NUMBER_OF_CHANNELS][MAX_PEAKS] =
2135
//
22-
// the energy peaks you wish to select should be in this list
36+
// the energy peaks you wish to select for the calibration should be in this list
2337
// NOTE: the first peak should be the highest in the spectrum (sub-optimal, but handy for finding)
2438
//
2539
{

calibration/ecal.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@
1111

1212
/*----------------------------------------------------------------------------*/
1313

14-
#define CHANNEL0 0
15-
#define CHANNEL1 1
16-
#define CHANNEL2 2
17-
#define CHANNEL3 3
18-
#define CHANNEL4 4
19-
#define CHANNEL5 5
20-
#define CHANNEL6 6
21-
#define CHANNEL7 7
22-
2314
#define NUMBER_OF_CHANNELS 8
2415
#define MAX_PEAKS 5
2516
#define MAX_PARAMETERS 3
2617

2718
#define BEFORE_CALIBRATION 0
2819
#define AFTER_CALIBRATION 1
2920

21+
//
22+
// CALIBRATION_MODE 0 = one calibration for full run
23+
// CALIBRATION_MODE 1 = one calibration every TIME_INTERVAL seconds
24+
//
3025
#define CALIBRATION_MODE 1
3126
#define TIME_INTERVAL 1800
3227

monitor/fitspectrum.C

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ float source_energy[NUMBER_OF_CHANNELS][MAX_PEAKS] =
3131
{662.,-1,-1,-1,-1} // channel7: 137Cs
3232
};
3333

34+
/*---------------------------------------------------------------------------------------------*/
35+
//
36+
// fitspectrum.C - RooFit based spectrum fitter. This routine can fit the spectrum for a full
37+
// modulation experiment run. The same algorithm is used in the analysis/calibration/analyzer.C
38+
// routine to fit the spectra after the chosen time interval.
39+
//
40+
// In this routine it is easy to develop new fitting ideas.
41+
//
42+
// Arguments
43+
// data_file : name of the data file to fit
44+
// mc_file : Geant4 prediction of the background spectrum. The spectra are generated
45+
// with the modexp/modusim package from GitHub
46+
// ichannel : channel number [0..7]
47+
// e0 : lowest energy for fit (keV)
48+
// e1 : highest energy for fit (keV)
49+
//
50+
// A.P. 2015-07-02
51+
//
3452
/*---------------------------------------------------------------------------------------------*/
3553
void fitspectrum(string data_file, string mc_file, int ichannel, double e0, double e1){
3654
double fit_range[2];
@@ -113,11 +131,7 @@ void fitspectrum(string data_file, string mc_file, int ichannel, double e0, doub
113131
for (int id=0; id<nselect; id++){
114132
sprintf(vname,"gaus%i",id);
115133
cout <<"vname >>"<<vname<<"<< pk = "<< (pk_mean[id])->getValV()<<endl;
116-
117-
// RooGaussian *gg = new RooGaussian(vname,vname,E,*pk_mean[id],*pk_sigma[id]);
118134
pk_gaus.push_back(new RooGaussian(vname,vname,E,*pk_mean.at(id),*pk_sigma.at(id)));
119-
cout <<"dodo"<<endl;
120-
// delete gg;
121135
}
122136
cout <<"analyzer::fit_spectrum Define photo peak Gaussians ---- DONE"<<endl;
123137
//
@@ -128,17 +142,10 @@ void fitspectrum(string data_file, string mc_file, int ichannel, double e0, doub
128142
//
129143
// compose the joined pdf for background + signal
130144
//
131-
132145
cout <<"analyzer::fit_spectrum Compose the combined pdf"<<endl;
133146

134147
RooAddPdf *sum;
135148
if (nselect==1) sum = new RooAddPdf("sum","g1+bg",RooArgList(*pk_gaus[0],bg),RooArgList(*pk_frac[0]));
136-
// if(peak_id[0] == 2) {
137-
// sum = new RooAddPdf("sum","g1+g2+bg",RooArgList(*pk_gaus[0],*pk_gaus_tail[0],bg),RooArgList(*pk_frac[0],*pk_frac_tail[0]));
138-
// } else {
139-
// sum = new RooAddPdf("sum","g1+bg",RooArgList(*pk_gaus[0],bg),RooArgList(*pk_frac[0]));
140-
// }
141-
// }
142149
if (nselect==2) sum = new RooAddPdf("sum","g1+g2+bg",RooArgList(*pk_gaus[0],*pk_gaus[1],bg),RooArgList(*pk_frac[0],*pk_frac[1]));
143150
if (nselect==3) sum = new RooAddPdf("sum","g1+g2+g3+bg",RooArgList(*pk_gaus[0],*pk_gaus[1],*pk_gaus[2],bg),RooArgList(*pk_frac[0],*pk_frac[1],*pk_frac[2]));
144151

monitor/lifetime.C

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212

1313
const int nmax = 100000;
1414

15+
/*----------------------------------------------------------------------------------------------------*/
16+
//
17+
// Fit the half-life to the tree data produced by the analyzer.C code.
18+
//
19+
// Usage from the ROOT6 command line
20+
//
21+
// prompt> #include<lifetime.C>
22+
// prompt> lifetime l(<directory_with_ANA_files>)
23+
// prompt> l.Life(<channel>, <peak>, <type>, <save>)
24+
//
25+
// <channel> : [0..7]
26+
// <peak> : [0..2] peak identifier in the spectrum. at the moment [0] for BG, [0..2] for 44Ti & 60Co, [0] for 137Cs
27+
// <type> : what to plot : "life" = rate vs time wit exponential fit
28+
// "pull" = (data-fit)/fit_error
29+
// <save> : to file or not?
30+
//
31+
// A.P.
32+
//
33+
/*----------------------------------------------------------------------------------------------------*/
1534
void lifetime::Life(int channel_sel, int peak_sel, string type, bool save)
1635
{
1736
TCanvas *c1 = new TCanvas("c1","c1",600,400);
@@ -59,6 +78,9 @@ void lifetime::Life(int channel_sel, int peak_sel, string type, bool save)
5978
char cmd[128];
6079
gStyle->SetOptFit(111);
6180
if(type == "life"){
81+
//
82+
// plot rate vs time and fitted exponential
83+
//
6284
g1->SetMarkerStyle(24);
6385
g1->Draw("AP");
6486

@@ -68,6 +90,9 @@ void lifetime::Life(int channel_sel, int peak_sel, string type, bool save)
6890
g1->GetYaxis()->SetTitle("rate (Hz)");
6991

7092
} else if (type == "pull"){
93+
//
94+
// plot pull distribution
95+
//
7196
double res;
7297
for(int i=0; i<n; i++){
7398
res = (R[i] - f1->Eval(t[i]) )/dR[i];

monitor/lifetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ lifetime::lifetime(string fname) : fChain(0)
6161
{
6262
char cmd[256];
6363
TChain *tree = new TChain("ana");
64-
sprintf(cmd,"%s*.root",fname.c_str());
64+
sprintf(cmd,"%s/*.root",fname.c_str());
6565
tree->Add(cmd);
6666
Init(tree);
6767
}

0 commit comments

Comments
 (0)