AculCalibration.h 8.74 KB
Newer Older
Kostyleva D.A's avatar
Kostyleva D.A committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#pragma once

#include <TObject.h>
#include <TFile.h>
#include <TTree.h>
#include <TH1I.h>
#include <TPolyMarker.h>
#include <TF1.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TCanvas.h>
#include <TMath.h>
#include <TGraph.h>
#include <TObjArray.h>
#include <TRandom3.h>
#include <THStack.h>
#include <TString.h>
#include <TSpectrum.h>

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

25 26
#include "../TELoss/TELoss.h"

27
//#define DEFAULTNOPEAKS 20
Kostyleva D.A's avatar
Kostyleva D.A committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#define ADDRESSNUMBER 32

using std::cout;
using std::endl;
using std::setw;
using std::setprecision;
using std::stringstream;
using std::ostringstream;

class AculCalibration : public TObject
{


public:

	//smysl jako verejne globalni promenne maji:
	//fNOSpectra	- pocet zkalibrovanych spekter
	//????			- pocet spravne zkalibrovanych spekter
	//????			- pocet nespravne zkalibrovanych spekter
	//fEnergy[4]	- tabulka s energiemi piku, nacita se zvenci

49
private:
Kostyleva D.A's avatar
Kostyleva D.A committed
50

51
//todo: following variables should be deleted
Kostyleva D.A's avatar
Kostyleva D.A committed
52 53 54 55 56 57 58 59 60 61 62
//	TObjArray	*fHRawList;			//list of raw histograms, list is set to owner
	TObjArray	fHRawList;			//list of raw histograms, list is set to owner
	TObjArray	fHAnalyzedList;	//list of fitted and analyzed histograms, list is set to owner
	TObjArray	fHEnergyList;		//list of calibrated histograms, list is set to owner
	THStack		fHEnergyStack;		//some stack
	THStack		*fCurrentHStack;
	//dodelat current histograms
	TObjArray	fCurrentHistList;

	//parameters to be read from file
	Int_t		kRaNOPEAKS;
63 64
	TArrayD		fEnergy;		//energy after passing through deadlayer
	TArrayD		fEnergyInput;		//incidental energy, set from .par 
Kostyleva D.A's avatar
Kostyleva D.A committed
65 66 67 68 69 70 71 72
	Double_t	fLowerChannel;
	Double_t	fUpperChannel;
	Double_t	fLowerPeakRelativeHight;	//pouziva se, private
	Double_t	fUpperPeakRelativeHight;	//pouziva se, private, nastavit nenulovou prednastavenou hodnotu
	Double_t	fPeakPositionTolerance;		//pouziva se, private
	Width_t		fFitFuncLineWidth;			//private
	Double_t	fFitMinSigma;				//pouziva se, private
	Double_t	fFitPeakThreshold;			//pouziva se, private, prozkoumat, k cemu vlastne slouzi ve fci ShowPeaks, popremyslet o vhodnem prednastaveni v konstruktoru
73
	Double_t	fDeadLayer;					//in mcm; it will be used for recalculation of energies outcomming from the alpha source
Kostyleva D.A's avatar
Kostyleva D.A committed
74

75 76
	//these variables are the main for the class
	TArrayD fA;		//calibration parameter, f(x) = fA*x + fB
77
	TArrayD fB;		//calibration parameter, f(x) = fA*x + fB
78 79

	TArrayD fPeak;	//v teto promenne je ulozena momentalni hodnota piku v kanalech, zejmena v jedne fci, mozno udelat ji jako lokalni, bude navratovou hodnotou fce PeaksFitting, predelat delku pole
Kostyleva D.A's avatar
Kostyleva D.A committed
80

81 82
	TELoss fAlphaSi;

83 84
	TString fParFileName;

85
	//it is very doubtful that we need this class variable
86
	TFile		*fCalInformation;
Kostyleva D.A's avatar
Kostyleva D.A committed
87 88

	
89

Kostyleva D.A's avatar
Kostyleva D.A committed
90 91 92
public:
	AculCalibration();
	//default constructor
93
	AculCalibration(const char* calfile);		//
Kostyleva D.A's avatar
Kostyleva D.A committed
94
	virtual ~AculCalibration();
95 96 97
	ClassDef(AculCalibration, 1);

	void Init();
Kostyleva D.A's avatar
Kostyleva D.A committed
98

99 100 101 102
	Double_t GetA(Int_t i); //to obtain calib parameter A
	Double_t GetB(Int_t i); //to obtain calib parameter B

	void SetParFileName(const char* parfile = "");
Kostyleva D.A's avatar
Kostyleva D.A committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	// Function which loads text file containing parameters for calibration
	//
	//	-inputparfile: file containing information on calibration source
	//	-In file with the data must be preserved systematic
	//	-There cannot be whitelines (probably)
	//
	//Example of "parforcal.par" file
	//................................................................
	//223Ra
	//
	//4		nopeaks		//number of peaks
	//4.415		E1		//in MeV
	//5.153		E2		//in MeV
	//5.683		E3		//in MeV
	//7.419		E4		//in MeV
	//100		lowerchannel	//in channels
	//4096		upperchannel	//in channels
	//0.1		lowerpeakhight		//in relative units
	//0.1		upperpeakhight		//in relative units
	//0.1		peakpositiontolerance	//in relative units
	//2		fitfunctionlinewidth	//integer 1 - 10
	//5		minfitsigma		//minimal sigma of the peaks to be fitted
	//0.4		fithightthreshold	//
	//................................................................

	Bool_t	SetCalibrationParameters(const char* calparfile);
	//Loads the file with calibration parameters
	//
131
	//  calparfile: file containing calibration parameters in format: crate number, address, subaddress, fAOld, fBOld, fC, fD
Kostyleva D.A's avatar
Kostyleva D.A committed
132 133 134 135 136 137
	//
	//	allowed comment characters: *, #, %, //

	void	PrintInputParameters();
	//I hope this is selfunderstanding function

Kostyleva D.A's avatar
Kostyleva D.A committed
138 139
	void	PrintCalibrationParameters();
	//Print calibration parameters fA, fB which are currently saved in object AculCalibration
Kostyleva D.A's avatar
Kostyleva D.A committed
140
	//
Kostyleva D.A's avatar
Kostyleva D.A committed
141 142
	// 
	//  
Kostyleva D.A's avatar
Kostyleva D.A committed
143 144

	Bool_t	CalculateCalibParameters(const char* inputfile, const char* block,
145
			const char* treename, Int_t lowerchannel = 0,
Kostyleva D.A's avatar
Kostyleva D.A committed
146
			Int_t upperchannel = 4095, Int_t nEBins = 1000, Int_t lowersubaddress = 0,
147
			Int_t uppersubaddress = ADDRESSNUMBER-1); //calculate calibration parameters for given block in given file
Kostyleva D.A's avatar
Kostyleva D.A committed
148

Kostyleva D.A's avatar
Kostyleva D.A committed
149 150 151 152 153 154 155 156 157 158 159
	//function is not completely ready to use
	//
	//function for calculation of calibrate parameters for DAQ system based on "Go4"
	//
	//  inputfile: root file with calibration spectra
	//  block: block name to be calibrated
	//  lowerchannel: minimal channel from which the spectrum will be analysed
	//  upperchannel: maximal channel up to which the spectrum will be analysed
	//  lowersubaddress: block subaddress
	//  uppersubaddress: block subbaddress

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	void CalibrateRawSpectra();

	UShort_t SomeFunction(UShort_t x, int len);

	template<typename T> T SomeFunction(T x, int len)
	{
		/*T max = x[0];
		for(int i = 1; i < len; i++)
			if(max < x[i])
				max = x[i];*/

//		return max;
		return x;
	}



177
	void CalibrateRawSpectra(const char* inputfile, const char* block, const char* treename, Int_t lowerchannel = 0, Int_t upperchannel = 4095, Int_t nEBins = 1000, Int_t lowersubaddress = 0, Int_t uppersubaddress = ADDRESSNUMBER-1);
Kostyleva D.A's avatar
Kostyleva D.A committed
178

179
	void FindEnergyPeaks(TCanvas *c1, const char* ifile, const char* outfile); 
180 181 182
	// Outputs calibrated energies for each channel in txt file 
	//
	// 
183 184 185
	//  

	void FindAverageEnergies(const char* ifile, const char* outfile);
186 187 188 189
	// Outputs average values of calibrated energies for the whole detector in txt file
	//
	// 
	//  
Kostyleva D.A's avatar
Kostyleva D.A committed
190 191

	Int_t	PeaksFitting(TH1* hSpectrum, Option_t* option = "", Double_t sigmamin = 2);
192 193 194 195
	//return values:
	//	0: OK
	//	1: something wrong
	//	2: something other wrong
Kostyleva D.A's avatar
Kostyleva D.A committed
196
	//
197
	//possible options: "V", "Q", "", ?"gp"?
Kostyleva D.A's avatar
Kostyleva D.A committed
198 199 200 201 202 203

	Int_t	SearchPeaks(const TH1 *hin, Double_t sigma = 2, Option_t *option = "", const Int_t searchedpeaks = 100);

	void	FillRawSpectraFile(const char* rawdatafile, const char* block, const char* treename, TCanvas* rawCanvas = NULL, Option_t *option = "", Int_t xaxismin = 0, Int_t xaxismax = 4096);

	void	ShowRawSpectra(const char* filename, const Int_t block, TCanvas* rawCanvas = NULL, Int_t xaxismin = 0, Int_t xaxismax = 4096, /*TObjArray* histList = NULL,*/ const Int_t subaddress = 16);
Kostyleva D.A's avatar
Kostyleva D.A committed
204 205 206
	//this function is written for old format of raw data
	//do not use this function!!!!!!!!!!!
	void	ShowSpectra(const char* filename, TCanvas* rawCanvas = NULL, Option_t *option = "", Int_t xaxismin = 0, Int_t xaxismax = 4096, /*TObjArray* histList = NULL,*/ const Int_t subaddress = ADDRESSNUMBER);
Kostyleva D.A's avatar
Kostyleva D.A committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
	void	ShowAnalyzedSpectra(const char* filename, TCanvas* fittedRawCanvas = NULL, Int_t xaxismin = 0, Int_t xaxismax = 4096, Int_t subaddress = 16);
	//This function displays analyzed spectrum from a file, divides the canvas into a sufficient number of pads and displays
	//spectrums of each  block subadress on the suitable pads or displays one  selected spectrum .
	//Selects the peaks in the histogram and displays on the histogram how the spectrum were fitted.
	//
	//  filename: file .root containing analysed spectra
	//  fittedRawCanvas: canvas on which one you will see the spectrum
	//  xaxismin: Minimum channel, which will be displayed
	//  xaxismax: Maximum channel, which will be displayed
	//  subaddress:

	void	ShowEnergySpectra(const char *filename, TCanvas* energyCanvas = NULL, const Int_t subaddress = 16, Option_t* option = "", Double_t xaxismin = 0., Double_t xaxismax = 10.); //option: "sum", "c", "+",
	//Displays the spectrum  of the selected subbaddress block in MeV
	//
	//  filename: file .root containing calibrated spectra in MeV
	//  energyCanvas: : canvas on which one you will see the spectrum
	//  subaddress: block subaddress  which will be drawn
	//  option: sum ,+ ,c
	//  xaxismin: Minimum channel, which will be displayed
	//  xaxismax: Maximum channel, which will be displayed


Kostyleva D.A's avatar
Kostyleva D.A committed
229

Kostyleva D.A's avatar
Kostyleva D.A committed
230

231

232
	//dodelat funkce TTree* Get...(...) pro raw, anal i E spectra
Kostyleva D.A's avatar
Kostyleva D.A committed
233 234 235 236 237

	void	ClearHistograms(Option_t* option = "");
	void	DeleteStacks(Option_t* option = "");

	void	Reset();
238
	//reset calibration parameters fA, fB to zero
Kostyleva D.A's avatar
Kostyleva D.A committed
239

240
private:
241 242 243 244

	void DivideCanvas(TCanvas *c1, Int_t inputs);

	void SetInputParameters();
245
	void SetELosses();
246
	void SetCalEnergies();
Kostyleva D.A's avatar
Kostyleva D.A committed
247 248 249


};