...
 
Commits (20)
*~
# Ignore compiled files
*.o
*.out
*.d
*.so
#Ignore files automatically build by ROOT
*.pcm
*Dict.cpp
# Ignore log files
*.log
# Ignore build directories
build/
# Ignore data and calibration files
*.root
*.cal
#Ignore VS code stuff
.vscode/
# config.ini
\ No newline at end of file
/*
* AculCalParameters.cpp
*
* Created on: Oct 20, 2016
* Author: vratik
*/
#include "AculCalPars.h"
AculCalPars::AculCalPars() {
// TODO Auto-generated constructor stub
Reset();
}
AculCalPars::AculCalPars(const char* parFile) {
// TODO Auto-generated constructor stub
SetParFile(parFile);
Init();
}
AculCalPars::~AculCalPars() {
// TODO Auto-generated destructor stub
}
void AculCalPars::Init() {
SetPars();
}
void AculCalPars::SetParFile(const char* parfile) {
fParFileName = parfile;
return;
}
void AculCalPars::Reset() {
fParFileName = "";
fEtab.clear();
}
/*
* AculCalParameters.h
*
* Created on: Oct 20, 2016
* Author: vratik
*/
#ifndef ACULCALIB_ACULCALPARS_H_
#define ACULCALIB_ACULCALPARS_H_
#include <iostream>
#include <fstream>
#include <vector>
#include "TString.h"
#include "TArrayD.h"
#include "TArrayI.h"
#include "TCutG.h"
using std::cout;
using std::cerr;
using std::endl;
using std::vector;
class AculCalPars {
protected:
//general
TString fParFileName;
vector<Double_t> fEtab; //energy which will be used for calibration
//todo energies used for calibration should be in this class
public:
AculCalPars();
AculCalPars(const char* parFile);
virtual ~AculCalPars();
ClassDef(AculCalPars,1);
virtual void Init();
//getters
const char* GetParFileName() {return fParFileName.Data();}
// Int_t GetNoCrystals() {return fNoCrystals;}
virtual const char* GetDetName() {return 0;}
virtual const char* GetParticleName() {return 0;}
virtual Int_t GetNoRawFiles() {return 0;};
virtual const char* GetFileName(Int_t i) {return 0;};
virtual Int_t GetNoEPoints() {return 0;}
virtual Double_t GetCalEnergy(Int_t i) {return 0.;};
//todo check functions with cuts
// virtual const char* GetCutsFileName() {return 0;}
// virtual Int_t GetNoCuts() {return 0;}
// virtual TCutG* GetCut(Int_t i) {return 0;};
virtual TCutG* GetCut(const char* cutName, Int_t treeID = 0) {return 0;};
virtual Int_t GetMinChannel(Int_t energy, Int_t crystal) {return 0;};
virtual Int_t GetMaxChannel(Int_t energy, Int_t crystal) {return 0;};
void SetParFileName(const char* parFile) {fParFileName = parFile;}
void SetParFile(const char* parfile);
virtual void PrintParameters(const char* option = "") {};
virtual void Reset();
protected:
virtual void SetPars() {};
};
#endif /* ACULCALIB_ACULCALPARS_H_ */
/*
* AculCalParsScint.cpp
*
* Created on: Oct 21, 2016
* Author: vratik
*/
#include "AculCalParsScint.h"
#include "TFile.h"
AculCalParsScint::AculCalParsScint() {
// TODO Auto-generated constructor stub
Reset();
}
AculCalParsScint::AculCalParsScint(const char* parFile) {
// TODO Auto-generated constructor stub
SetParFile(parFile);
Init();
}
AculCalParsScint::~AculCalParsScint() {
// TODO Auto-generated destructor stub
}
void AculCalParsScint::Init() {
SetPars();
// LoadCuts();
}
void AculCalParsScint::SetPars() {
std::ifstream infile(fParFileName.Data());
if ( !infile.is_open() ) {
printf("AculCalParsScint::ReadParFile: File %s was not open and parameters were not set.\n", fParFileName.Data());
Reset();
return;
}
fEnergyPoints = 0;
TString line;
TString word;
Int_t i, min, max;
Int_t lineLength = 400;
Char_t det[lineLength];
Char_t part[lineLength];
Char_t fname[lineLength];
Char_t cname[lineLength];
double en; //energy
while (!infile.eof()) {
line.ReadLine(infile);
if ( line.BeginsWith("#") || line.BeginsWith("//") ) continue;
if ( line.BeginsWith("energies") ) {
sscanf(line.Data(), "%*s %d", &i);
continue;
}
if ( line.BeginsWith("crystals") ) {
sscanf(line.Data(), "%*s %d", &i);
fNoCrystals = i;
continue;
}
if ( line.BeginsWith("files") ) {
sscanf(line.Data(), "%*s %d", &i);
fNoFiles = i;
fFilePars.resize(fNoFiles);
for (Int_t j = 0; j < fNoFiles; j++) {
line.ReadLine(infile);
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
continue;
}
sscanf(line, "%s", fname);
word = fname;
fFilePars[j].SetRawFileName(fname);
fFilePars[j].SetNoCrystals(fNoCrystals);
fFilePars[j].Init();
}
continue;
}
/*if ( line.BeginsWith("cutFile") ) {
sscanf(line.Data(), "%*s %s %d", fname, &fNoCuts);
fCutsFileName = fname;
for (Int_t j = 0; j < fNoCuts; j++) {
line.ReadLine(infile);
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
continue;
}
sscanf(line, "%s", cname);
fCutName.push_back(cname);
}
continue;
}*/
if ( line.BeginsWith("detector") ) {
sscanf(line.Data(), "%*s %s %s", det, part);
fDetName = det;
fPartName = part;
continue;
}
if ( line.BeginsWith("energy") ) {
sscanf(line.Data(), "%*s %lf", &en);
fFilePars[fEnergyPoints].SetEnergy(en);
do {line.ReadLine(infile);}
while (line.BeginsWith("#") || line.BeginsWith("//"));
if ( line.BeginsWith("cutFile") ) {
Int_t noCuts;
// sscanf(line.Data(), "%*s %s %d", fname, &fNoCuts);
sscanf(line.Data(), "%*s %s %d", fname, &noCuts);
fFilePars[fEnergyPoints].SetNoCuts(noCuts);
fFilePars[fEnergyPoints].SetCutFileName(fname);
// cout << line << endl;
// cout << noCuts << endl;
// fCutsFileName = fname;
for (Int_t j = 0; j < noCuts; j++) {
line.ReadLine(infile);
// cout << line << endl;
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
continue;
}
sscanf(line, "%s", cname);
fFilePars[fEnergyPoints].SetCutName(j, cname);
// fCutName.push_back(cname);
}
fFilePars[fEnergyPoints].LoadCuts();
line.ReadLine(infile);
// cout << line << endl;
// continue;
}
// cout << fNoCrystals << endl;
for (Int_t j = 0; j < fNoCrystals; j++) {
// line.ReadLine(infile);
// cout << j << endl;
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
line.ReadLine(infile);
continue;
}
sscanf(line.Data(), "%d %d %d", &j, &min, &max);
// cout << j << endl;
fFilePars.at(fEnergyPoints).SetPeakMin(j, min);
fFilePars.at(fEnergyPoints).SetPeakMax(j, max);
line.ReadLine(infile);
}
fEnergyPoints++;
continue;
}
// cout << "aklsjdlaksjd" << endl;
// sscanf(line.Data(), "%d %d %d", &i, &min, &max);
// fFilePars.at(fEnergyPoints-1).SetPeakMin(i, min);
// fFilePars.at(fEnergyPoints-1).SetPeakMax(i, max);
}//while
infile.close();
return;
}
void AculCalParsScint::PrintParameters(const char* option) {
TString opt = option;
cout << "Parameters read from file \"" << fParFileName.Data() << "\"." << endl;
cout << "\tCalibration of detector \"" << fDetName << "\" with " << fNoCrystals << " crystals." << endl;
cout << "\tParticle: " << fPartName << endl;
cout << "\tInput files with raw data (" << fNoFiles << "):" << endl;
for (Int_t i = 0; i < (Int_t)fFilePars.size(); i++) {
cout << "\t " << GetFileName(i) << endl;
}
cout << "\tInput energies (" << fNoFiles << "):" << endl;
for (Int_t i = 0; i < (Int_t)fFilePars.size(); i++) {
cout << "\t " << fFilePars[i].GetEnergy() << " MeV" << endl;
}
// cout << "\tInput file with " << fNoCuts << " cuts: \"" << fCutsFileName << "\"" << endl;
// if (opt.Contains("all")) {
// for (Int_t i = 0; i < (Int_t)fCutName.size(); i++) {
// cout << "\t cut: \"" << fCutName[i] << "\"" << endl;
// }
// }
for (Int_t k = 0; k < (Int_t)fFilePars.size(); k++) {
cout << "\t" << fFilePars[k].GetNoCuts() << " cuts from file \"" << fFilePars[k].GetCutFileName() << "\":" << endl;
for (Int_t i = 0; i < fFilePars[k].GetNoCuts(); i++) {
cout << "\t " << fFilePars[k].GetCut(i)->GetName() << endl;
}
if (!opt.Contains("all")) continue;
cout << "\tPeak limits for particular channels and energies:" << endl;
cout << "\t Set number: " << k << "; energy: " << fFilePars[k].GetEnergy() << " MeV" << endl;
for (Int_t i = 0; i < (Int_t)fFilePars[k].GetNoCrystals(); i++) {
cout << "\t\t " << fFilePars[k].GetPeakMin(i) << "\t" << fFilePars[k].GetPeakMax(i) << endl;
}
}
return;
}
void AculCalParsScint::Reset() {
fNoCrystals = 0;
fParFileName = "";
fDetName = "";
fPartName = "";
fNoFiles = 0;
fFilePars.clear();
fEnergyPoints = 0;
// fCutsFileName = "";
// fNoCuts = 0; //number of cuts
// fCutName.clear();
return;
}
const char* AculCalParsScint::GetFileName(Int_t i) {
if ( i >= (Int_t)fFilePars.size() ) {
cerr << "\"AculCalParsScint::GetFileName\" index i cannot be higher than " << fFilePars.size() - 1 << endl;
return 0;
}
return fFilePars[i].GetRawFileName();
}
/*const char* AculCalParsScint::GetCutName(Int_t i) {
if ( i > (Int_t)fCutName.size()-1 ) {
cerr << "\"AculCalParsScint::GetCutName\" index i cannot be higher than " << fCutName.size() - 1 << endl;
return 0;
}
return fCutName[i].Data();
}*/
/*TCutG* AculCalParsScint::GetCut(Int_t i) {
if ( i >= (Int_t)fCuts.size() ) {
cerr << "\"AculCalParsScint::GetCut\" index i cannot be higher than " << fCuts.size() - 1 << endl;
return 0;
}
return &fCuts[i];
}*/
TCutG* AculCalParsScint::GetCut(const char* cutName, Int_t treeID) {
const TString cName = cutName;
if (treeID >= (Int_t)fFilePars.size()) {
cerr << "\"AculCalParsScint::GetCut\" treeID does not exist. It cannot be higher than "
<< fFilePars.size() << "." << endl;
return 0;
}
// TCutG *curCut = 0;
for (Int_t i = 0; i < fFilePars[treeID].GetNoCuts(); i++) {
// if (cName.EqualTo(fFilePars[treeID])) { return &fCuts[i]; }
if ( cName.EqualTo( fFilePars[treeID].GetCutName(i) ) ) {
return fFilePars[treeID].GetCut(i);
// return curCut;
}
}
cerr << "\"AculCalParsScint::GetCut\" cut \"" << cutName << "\" was not found." << endl;
return 0;
}
Double_t AculCalParsScint::GetCalEnergy(Int_t i) {
if ( i >= (Int_t)fFilePars.size() ) {
cerr << "\"AculCalParsScint::GetCalEnergy\" index i cannot be higher than " << fFilePars.size() - 1 << endl;
return 0;
}
return fFilePars[i].GetEnergy();
}
Int_t AculCalParsScint::GetMinChannel(Int_t energy, Int_t crystal) {
if ( energy >= (Int_t)fFilePars.size() ) {
cerr << "\"AculCalParsScint::GetMinChannel\" index \"energy\" cannot be higher than "
<< fFilePars.size() - 1 << endl;
return 0;
}
if ( crystal >= fFilePars[energy].GetNoCrystals() ) {
cerr << "\"AculCalParsScint::GetMinChannel\" index \"crystal\" cannot be higher than "
<< fFilePars[energy].GetNoCrystals() - 1 << endl;
return 0;
}
return fFilePars[energy].GetPeakMin(crystal);
}
Int_t AculCalParsScint::GetMaxChannel(Int_t energy, Int_t crystal) {
if ( energy >= (Int_t)fFilePars.size() ) {
cerr << "\"AculCalParsScint::GetMinChannel\" index \"energy\" cannot be higher than "
<< fFilePars.size() - 1 << endl;
return 0;
}
if ( crystal >= fFilePars[energy].GetNoCrystals() ) {
cerr << "\"AculCalParsScint::GetMinChannel\" index \"crystal\" cannot be higher than "
<< fFilePars[energy].GetNoCrystals() - 1 << endl;
return 0;
}
return fFilePars[energy].GetPeakMax(crystal);
}
/*void AculCalParsScint::LoadCuts() {
if (fCutsFileName.Length() == 0) {
printf("AculCalParsScint::LoadCuts: Name of file (*.root) with cuts was not provided.\n");
printf("AculCalParsScint::LoadCuts: No cuts has been loaded.\n");
return;
}
TFile cutFile(fCutsFileName.Data(), "READ");
if(!cutFile.IsOpen()) {
cerr << "\"AculCalParsScint::LoadCuts\" File " << fCutsFileName.Data()
<< " was not open and no cuts were loaded." << endl;
return;
}
for (Int_t i = 0; i < (Int_t)fCutName.size(); i++) {
TCutG *currentCut = (TCutG*)cutFile.Get(fCutName[i]);
if (!currentCut) {
cout << "\"AculCalParsScint::LoadCuts\" Cut \"" << fCutName[i]
<< "\" was not found in file " << fCutsFileName << "." << endl;
continue;
}
fCuts.push_back(*currentCut);
}
}*/
/*
* AculCalParsScint.h
*
* Created on: Oct 21, 2016
* Author: vratik
*/
#ifndef ACULCALIB_ACULCALPARSSCINT_H_
#define ACULCALIB_ACULCALPARSSCINT_H_
#include "AculCalPars.h"
#include "AculCalParsScintFile.h"
//#include "TCutG.h"
using std::cerr;
class AculCalParsScint: public AculCalPars {
private:
Int_t fNoCrystals;
TString fDetName;
TString fPartName;
Int_t fNoFiles;
vector<AculCalParsScintFile> fFilePars;
//todo following parameters should be probably moved to AculCalParsScintFile
//as far as they are related to each file separately
// vector<TString> fCutName;
// vector<TCutG> fCuts;
Int_t fEnergyPoints;
// TString fCutsFileName;
// Int_t fNoCuts; //number of cuts
public:
AculCalParsScint();
AculCalParsScint(const char* parFile);
virtual ~AculCalParsScint();
ClassDef(AculCalParsScint, 1);
virtual void Init();
void PrintParameters(const char* option = "");
// If option contains "all", all parameters will be printed out.
// By default important parameters only will be printed out.
void Reset();
//getters
Int_t GetNoCrystals() {return fNoCrystals;}
const char* GetDetName() {return fDetName.Data();}
const char* GetParticleName() {return fPartName.Data();}
Int_t GetNoRawFiles() {return fNoFiles;}
const char* GetFileName(Int_t i);
const char* GetCutName(Int_t i);
Int_t GetNoEPoints() {return fEnergyPoints;}
Double_t GetCalEnergy(Int_t i);
// const char* GetCutsFileName() {return fCutsFileName.Data();}
// Int_t GetNoCuts() {return fNoCuts;}
// TCutG* GetCut(Int_t i);
TCutG* GetCut(const char* cutName, Int_t treeID = 0);
Int_t GetMinChannel(Int_t energy, Int_t crystal);
Int_t GetMaxChannel(Int_t energy, Int_t crystal);
//private:
// void LoadCuts();
protected:
void SetPars();
};
#endif /* ACULCALIB_ACULCALPARSSCINT_H_ */
/*
* AculCalParsScintFile.cpp
*
* Created on: Oct 25, 2016
* Author: vratik
*/
#include "AculCalParsScintFile.h"
AculCalParsScintFile::AculCalParsScintFile() {
// TODO Auto-generated constructor stub
// fFileID = 0;
fNoCrystals = 0;
fE = 0;
Init();
}
AculCalParsScintFile::~AculCalParsScintFile() {
// TODO Auto-generated destructor stub
}
void AculCalParsScintFile::Init() {
// fNoCrystals = 0;
// fE = 0;
fPeakMin.resize(fNoCrystals);
fPeakMax.resize(fNoCrystals);
fCutName.resize(0);
}
const char* AculCalParsScintFile::GetCutName(Int_t i) {
if ( i >= (Int_t)fCutName.size() ) {
cout << "\"AculCalParsScintFile::GetCutName\" Cut number " << i
<< " is not available. Maximal i can be set as "
<< fCutName.size() - 1 << "." << endl;
}
return fCutName[i].Data();
}
TCutG* AculCalParsScintFile::GetCut(Int_t i) {
if ( i >= (Int_t)fCut.size() ) {
cerr << "\"AculCalParsScintFile::GetCut\" index i cannot be higher than " << fCut.size() - 1 << endl;
return 0;
}
return &fCut[i];
}
TCutG* AculCalParsScintFile::GetCut(const char* cutName) {
const TString cName = cutName;
for (Int_t i = 0; i <= (Int_t)fCut.size(); i++) {
if (cName.EqualTo(fCutName[i])) { return &fCut[i]; }
}
cerr << "\"AculCalParsScint::GetCut\" cut \"" << cutName << "\" was not found." << endl;
return 0;
}
Int_t AculCalParsScintFile::GetPeakMin(Int_t crystalID) {
if ( crystalID >= (Int_t)fPeakMin.size() ) {
cerr << "\"AculCalParsScintFile::GetPeakMin\" index \"crystal\" cannot be higher than "
<< fPeakMin.size() - 1 << endl;
return 0;
}
return fPeakMin[crystalID];
}
Int_t AculCalParsScintFile::GetPeakMax(Int_t crystalID) {
if ( crystalID >= (Int_t)fPeakMax.size() ) {
cerr << "\"AculCalParsScintFile::GetPeakMax\" index \"crystal\" cannot be higher than "
<< fPeakMax.size() - 1 << endl;
return 0;
}
return fPeakMax[crystalID];
}
void AculCalParsScintFile::SetRawFileName(const char* filename) {
fFileName = filename;
// fFileID++;
}
void AculCalParsScintFile::SetCutFileName(const char* filename) {
fCutsFileName = filename;
}
void AculCalParsScintFile::SetNoCuts(Int_t noCuts) {
fCutName.resize(noCuts);
}
void AculCalParsScintFile::SetCutName(Int_t i, const char* cutname) {
if ( i >= (Int_t)fCutName.size() ) {
cout << "\"AculCalParsScintFile::SetCutName\" vector for cut names is not enough large. Maximal i can be set as "
<< fCutName.size() - 1 << "." << endl;
}
fCutName[i] = cutname;
}
void AculCalParsScintFile::SetPeakMin(Int_t crystalID, Double_t limit) {
if ( crystalID>=(Int_t)fPeakMin.size() ) {
cerr << "\"AculCalParsScintFile::SetPeakMin\" maximal allowed crystal ID is " << fPeakMin.size() << "."<< endl;
return;
}
fPeakMin[crystalID] = limit;
}
void AculCalParsScintFile::SetPeakMax(Int_t crystalID, Double_t limit) {
if ( crystalID>=(Int_t)fPeakMax.size() ) {
cerr << "\"AculCalParsScintFile::SetPeakMax\" maximal allowed crystal ID is " << fPeakMax.size() << "."<< endl;
return;
}
fPeakMax[crystalID] = limit;
}
void AculCalParsScintFile::LoadCuts() {
if (fCutsFileName.Length() == 0) {
printf("AculCalParsScintFile::LoadCuts: Name of file (*.root) with cuts was not provided.\n");
printf("AculCalParsScintFile::LoadCuts: No cuts has been loaded.\n");
return;
}
TFile cutFile(fCutsFileName.Data(), "READ");
if(!cutFile.IsOpen()) {
cerr << "\"AculCalParsScintFile::LoadCuts\" File " << fCutsFileName.Data()
<< " was not open and no cuts were loaded." << endl;
return;
}
for (Int_t i = 0; i < (Int_t)fCutName.size(); i++) {
TCutG *currentCut = (TCutG*)cutFile.Get(fCutName[i]);
if (!currentCut) {
cout << "\"AculCalParsScintFile::LoadCuts\" Cut \"" << fCutName[i]
<< "\" was not found in file " << fCutsFileName << "." << endl;
continue;
}
fCut.push_back(*currentCut);
}
}
/*void AculCalParsScintFile::Reset() {
}*/
/*
* AculCalParsScintFile.h
*
* Created on: Oct 25, 2016
* Author: vratik
*/
#ifndef ACULCALIB_ACULCALPARSSCINTFILE_H_
#define ACULCALIB_ACULCALPARSSCINTFILE_H_
#include <vector>
#include <iostream>
#include "TFile.h"
#include "TCutG.h"
#include "TString.h"
using std::vector;
using std::cout;
using std::endl;
using std::cerr;
class AculCalParsScintFile {
private:
// UInt_t fFileID;
Int_t fNoCrystals;
Double_t fE;
// TCutG fCuts;
TString fFileName;
TString fCutsFileName;
vector<TString> fCutName;
vector<TCutG> fCut;
vector<Int_t> fPeakMin;
vector<Int_t> fPeakMax;
public:
AculCalParsScintFile();
virtual ~AculCalParsScintFile();
ClassDef(AculCalParsScintFile, 1);
void Init();
Int_t GetNoCrystals() {return fNoCrystals;}
const char* GetRawFileName() {return fFileName.Data();}
const char* GetCutFileName() {return fCutsFileName.Data();}
Double_t GetEnergy() {return fE;}
Int_t GetNoCuts() {return (Int_t)fCut.size();}
const char* GetCutName(Int_t i);
TCutG* GetCut(Int_t i);
TCutG* GetCut(const char* cutName);
Int_t GetPeakMin(Int_t crystalID);
Int_t GetPeakMax(Int_t crystalID);
void SetNoCrystals(Int_t nocrystals) {fNoCrystals = nocrystals;};
void SetEnergy(Double_t energy) {fE = energy;};
void SetRawFileName(const char* filename);
void SetCutFileName(const char* filename);
void SetNoCuts(Int_t noCuts);
void SetCutName(Int_t i, const char* cutname);
void SetPeakMin(Int_t crystalID, Double_t limit);
void SetPeakMax(Int_t crystalID, Double_t limit);
void LoadCuts();
// void Reset();
private:
// void LoadCuts();
};
#endif /* ACULCALIB_ACULCALPARSSCINTFILE_H_ */
/*
* AculCalParsSi.cpp
*
* Created on: Oct 26, 2016
* Author: vratik
*/
#include "AculCalParsSi.h"
AculCalParsSi::AculCalParsSi() {
// TODO Auto-generated constructor stub
Reset();
}
AculCalParsSi::AculCalParsSi(const char* parFile) {
SetParFile(parFile);
Init();
}
AculCalParsSi::~AculCalParsSi() {
// TODO Auto-generated destructor stub
}
void AculCalParsSi::Init() {
SetELosses();
SetPars();
SetCalEnergies();
}
void AculCalParsSi::Reset() {
fParFileName = "";
kRaNOPEAKS = 0;
fEnergyInput.clear();
fLowerChannel = 0.;
fUpperChannel = 0.;
fLowerPeakRelativeHight = 0.;
fUpperPeakRelativeHight = 0.;
fPeakPositionTolerance = 0.;
fFitFuncLineWidth = 1;
fFitMinSigma = 0.;
fFitPeakThreshold = 0.;
fDeadLayer = 0.;
return;
}
void AculCalParsSi::SetPars() {
if (fParFileName.Length()==0) {
cerr << "\'AculCalibration::SetInputsParameters\" File with input parameters was not set." << endl;
return;
}
const Int_t lineLength = 400;
Char_t line[lineLength];
Char_t parameter[100];
Char_t identificator[100];
std::ifstream fipr;
fipr.open(fParFileName.Data());
if (!fipr.is_open()) {
cerr << "\"AculCalibration::SetInputsParameters\" File with input parameters \""
<< fParFileName << "\" was not opened." << endl;
return;
}
cout << "\"AculCalibration::SetInputsParameters\" File with input parameters \""
<< fParFileName << "\" will be processed." << endl;
while (!fipr.eof()) {
fipr.getline(line, lineLength);
if (strlen(line) < 2) {
continue;
}
sscanf(line, "%s %s", parameter, identificator);
if ( strcmp(identificator, "noPeaks") == 0 ) {
kRaNOPEAKS = static_cast<Int_t>(atoi(parameter));
fEnergyInput.resize(kRaNOPEAKS);
fEtab.resize(kRaNOPEAKS);
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
fipr.getline(line, lineLength);
sscanf(line, "%s", parameter);
fEnergyInput[i] = static_cast<Double_t>(atof(parameter));
}
continue;
}//if
if ( strcmp(identificator, "lowerChannel") == 0 ) {
sscanf(line, "%s", parameter);
fLowerChannel = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "upperChannel") == 0 ) {
sscanf(line, "%s", parameter);
fUpperChannel = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "lowerPeakHight") == 0 ) {
sscanf(line, "%s", parameter);
fLowerPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "upperPeakHight") == 0 ) {
sscanf(line, "%s", parameter);
fUpperPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "peakPositionTolerance") == 0 ) {
sscanf(line, "%s", parameter);
fPeakPositionTolerance = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "fitFunctionLineWidth") == 0 ) {
sscanf(line, "%s", parameter);
fFitFuncLineWidth = static_cast<Width_t>(atoi(parameter));
}
if ( strcmp(identificator, "minFitSigma") == 0 ) {
sscanf(line, "%s", parameter);
fFitMinSigma = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "fitHightThreshold") == 0 ) {
sscanf(line, "%s", parameter);
fFitPeakThreshold = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "deadLayer") == 0 ) {
sscanf(line, "%s", parameter);
fDeadLayer = static_cast<Double_t>(atof(parameter));
}
}
fipr.close();
return;
}
void AculCalParsSi::PrintParameters(const char* option)
{
//print alpha source parameters
cout << "AculCalibration::PrintInputParameters:" << endl;
cout << "\tNumber of peaks: " << kRaNOPEAKS << endl;
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
cout << "\t\tfEnergyInput[" << i << "] = " << fEnergyInput[i] << " MeV" << endl;
}
cout << "\tEnergies used for calibration:" << endl;
cout << "\t(deadLayer: " << fDeadLayer << " mcm)" << endl;
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
cout << "\t\tfE[" << i << "] = " << fEtab[i] << " MeV" << endl;
}
cout << "\tlowerChannel: " << fLowerChannel << "; upperChannel: " << fUpperChannel << ";" << endl;
cout << "\tlowerPeakHight: " << fLowerPeakRelativeHight << "; upperPeakHight: " << fUpperPeakRelativeHight << ";" << endl;
cout << "\tfitHightThreshold: " << fFitPeakThreshold << "; minFitSigma: " << fFitMinSigma << ";" << endl;
cout << "\tpeakPositionTolerance: " << fPeakPositionTolerance << ";" << endl;
cout << "\tfitFunctionLineWidth: " << fFitFuncLineWidth << ";" << endl;
return;
}
void AculCalParsSi::SetELosses() {
Info("AculCalibration::SetELosses", "Combination of aplha particle with silicon material only.");
fAlphaSi.SetEL(1, 2.321); // density in g/cm3
fAlphaSi.AddEL(14., 28.086, 1); //Z, mass
// mSi.SetZP(1., 1.); //protons
fAlphaSi.SetZP(2., 4.); //alphas, Z, A
fAlphaSi.SetEtab(100000, 200.); // ?, MeV calculate ranges
fAlphaSi.SetDeltaEtab(300);
}
void AculCalParsSi::SetCalEnergies() {
if (fDeadLayer<=0.) {
Warning("AculCalibration::SetCalEnergies", "Dead layer was set equal or less than 0.");
for(Int_t i = 0; i < kRaNOPEAKS; i++) {
fEtab[i] = fEnergyInput[i];
}
Info("AculCalibration::SetCalEnergies", "Energies used for calibration are the same as input file.");
return;
}
for(Int_t i = 0; i < kRaNOPEAKS; i++) {
fEtab[i] = fAlphaSi.GetE(fEnergyInput[i], fDeadLayer);
}
Info("AculCalibration::SetCalEnergies", "Energies used for calibration considering %f mcm dead layer were set.", fDeadLayer);
return;
}
/*
* AculCalParsSi.h
*
* Created on: Oct 26, 2016
* Author: vratik
*/
#ifndef ACULCALIB_ACULCALPARSSI_H_
#define ACULCALIB_ACULCALPARSSI_H_
#include "AculCalPars.h"
#include "../TELoss/TELoss.h"
class AculCalParsSi: public AculCalPars {
private:
Int_t kRaNOPEAKS;
// TArrayD fEnergy; //energy after passing through deadlayer
vector<Double_t> fEnergyInput; //incidental energy, set from .par
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
Double_t fDeadLayer; //in mcm; it will be used for recalculation of energies outcomming from the alpha source
TELoss fAlphaSi;
public:
AculCalParsSi();
AculCalParsSi(const char* parFile);
virtual ~AculCalParsSi();
ClassDef(AculCalParsSi, 1);
void Init();
// 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 //
//................................................................
void Reset();
void PrintParameters(const char* option = "");
//I hope this is selfunderstanding function
private:
void SetPars();
void SetELosses();
void SetCalEnergies();
};
#endif /* ACULCALIB_ACULCALPARSSI_H_ */
#include "AculCalib.h"
//----------------------------------------------------------------------------
AculCalib::AculCalib() {
//documentation example
printf("AculCalib::Default constructor called.\n");
Init();
}
//----------------------------------------------------------------------------
/*AculCalib::AculCalib(const char* parfile) {
printf("AculCalib::Constructor called.\n");
SetParFile(parfile);
Init();
}*/
//----------------------------------------------------------------------------
AculCalib::~AculCalib() {
printf("AculCalib::Destructor called.\n");
delete fPars;
}
//----------------------------------------------------------------------------
void AculCalib::Init() {
fPars = 0;
}
//----------------------------------------------------------------------------
void AculCalib::SetParFile(const char* parfile) {
fParFileName = parfile;
return;
}
//----------------------------------------------------------------------------
void AculCalib::PrintParameters(const char* option) {
if (!fPars) {
cerr << "\"AculCalib::PrintParameters\" parameters were not initialized." << endl;
return;
}
fPars->PrintParameters(option);
}
//----------------------------------------------------------------------------
void AculCalib::PrintCalibParameters() {
cout << "i\ta\t\b" << endl;
for (Int_t i = 0; i<=(Int_t)fA.size(); i++) {
cout << i << "\t" << fA[i] << "\t" << fB[i] << endl;
}
}
//----------------------------------------------------------------------------
Double_t AculCalib::GetA(Int_t i) {
if (i >= (Int_t)fA.size()) //if i >= number of array element
{
return 0.;
}
return fA[i];
}
//----------------------------------------------------------------------------
Double_t AculCalib::GetB(Int_t i) {
if (i >= (Int_t)fB.size()) //if i >= number of array element
{
return 0.;
}
return fB[i];
}
//----------------------------------------------------------------------------
void AculCalib::CanDivider(TCanvas *c, Int_t noPads, Int_t columns, Int_t rows) {
c->Clear();
if (noPads == 16) {
c->Divide(4, 4);
return;
}
if (rows != 0 && columns != 0) {
c->Divide(columns, rows);
return;
}
}
//----------------------------------------------------------------------------
ClassImp(AculCalib);
////////////////////////////////////////////////////////////////
// //
// TMyClass //
// //
// This is the description block. //
// //
////////////////////////////////////////////////////////////////
#ifndef ACULCALIB_ACULCALIB_H_
#define ACULCALIB_ACULCALIB_H_
//#include "TObject.h"
//#include "TROOT.h"
#include <iostream>
#include <fstream>
#include "TArrayD.h"
#include "TString.h"
#include "TCanvas.h"
#include "./AculCalPars.h"
using std::cout;
using std::endl;
using std::cerr;
class AculCalib {
protected:
vector<Double_t> fA; //calibration parameter A
vector<Double_t> fB; //calibration parameter A
TString fParFileName; //name of file with parameters
AculCalPars *fPars; //parameters used for calibration
public:
//Default constructor.
AculCalib();
//Destructor.
virtual ~AculCalib();
ClassDef(AculCalib,1);
virtual void Init();
void SetParFile(const char* parfile);
const char* GetParFileName() {return fParFileName.Data();}
//Print parameters used for calibration.
void PrintParameters(const char* option = "");
//Print calibration parameters.
void PrintCalibParameters();
//Get calibration parameter A.
Double_t GetA(Int_t i);
//Get calibration parameter B.
Double_t GetB(Int_t i);
protected:
void CanDivider(TCanvas *c, Int_t noPads, Int_t columns = 0, Int_t rows = 0);
};
#endif
################################################################################
# AculData input with some variables
################################################################################
# ACULCALIBLIBS := -lCore -lCint -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum #-lTELoss
ACULCALIBLIBS := -lCore -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum #-lTELoss
# Add inputs and outputs from these tool invocations to the build variables
ACULCALIB_HEADERS += \
$(ACULCALIB)/AculCalib.h \
$(ACULCALIB)/AculCalibScint.h \
$(ACULCALIB)/AculCalibSi.h \
$(ACULCALIB)/AculCalPars.h \
$(ACULCALIB)/AculCalParsScint.h \
$(ACULCALIB)/AculCalParsScintFile.h \
$(ACULCALIB)/AculCalParsSi.h \
$(ACULCALIB)/AculCalibLinkDef.h
ACULCALIBCPP_SRCS += \
$(ACULCALIB)/AculCalib.cpp \
$(ACULCALIB)/AculCalibScint.cpp \
$(ACULCALIB)/AculCalibSi.cpp \
$(ACULCALIB)/AculCalPars.cpp \
$(ACULCALIB)/AculCalParsScint.cpp \
$(ACULCALIB)/AculCalParsScintFile.cpp \
$(ACULCALIB)/AculCalParsSi.cpp \
$(ACULCALIB)/AculCalibDict.cpp
ACULCALIBOBJS += \
$(ACULCALIB)/AculCalib.o \
$(ACULCALIB)/AculCalibScint.o \
$(ACULCALIB)/AculCalibSi.o \
$(ACULCALIB)/AculCalPars.o \
$(ACULCALIB)/AculCalParsScint.o \
$(ACULCALIB)/AculCalParsScintFile.o \
$(ACULCALIB)/AculCalParsSi.o \
$(ACULCALIB)/AculCalibDict.o
ACULCALIBCPP_DEPS += \
$(ACULCALIB)/AculCalib.d \
$(ACULCALIB)/AculCalibScint.d \
$(ACULCALIB)/AculCalibSi.d \
$(ACULCALIB)/AculCalPars.d \
$(ACULCALIB)/AculCalParsScint.d \
$(ACULCALIB)/AculCalParsScintFile.d \
$(ACULCALIB)/AculCalParsSi.d \
$(ACULCALIB)/AculCalibDict.d
\ No newline at end of file
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
//#pragma link C++ class AculRaw;
//#pragma link C++ class AculConvert;
#pragma link C++ class AculCalib;
#pragma link C++ class AculCalibScint;
#pragma link C++ class AculCalibSi;
#pragma link C++ class AculCalPars;
#pragma link C++ class AculCalParsScint;
#pragma link C++ class AculCalParsScintFile;
#pragma link C++ class AculCalParsSi;
#endif
#include "AculCalibScint.h"
#include "AculCalParsScint.h"
ClassImp(AculCalibScint);
AculCalibScint::AculCalibScint() {
printf("AculCalibScint::Default constructor called.\n");
fInFiles = 0;
fTrees = 0;
fCutFile = 0;
}
AculCalibScint::AculCalibScint(const char* parfile) {
printf("AculCalibScint::Constructor called.\n");
SetParFile(parfile);
Init();
// cout << "nofiles: " << nofiles << endl;
// OpenTrees();
// LoadCuts();
// fr.Print();
// fr.At(0);
}
AculCalibScint::~AculCalibScint() {
printf("AculCalibScint::Destructor called.\n");
}
void AculCalibScint::Init() {
fPars = new AculCalParsScint(fParFileName.Data());
OpenFiles();
LoadTrees();
fHistFull.resize(fPars->GetNoRawFiles());
fHistCut.resize(fPars->GetNoRawFiles());
fMeanPeakPos.resize(fPars->GetNoRawFiles());
fMeanPeakRMS.resize(fPars->GetNoRawFiles());
// SetPars();
}
void AculCalibScint::PrintTrees() {
if (!fTrees) {
cerr << "\"AculCalibScint::PrintTrees\" Probably no tree was open." << endl;
return;
}
// TTree *curTree = 0;
cout << " AculCalibScint::PrintTrees:" << endl;
for (Int_t i = 0; i < fPars->GetNoRawFiles(); i++) {
// curTree = fTrees[i];
if (fTrees[i]) {
printf("\tTree No. %d; File: %s; Name: %s\n", i, fTrees[i]->GetDirectory()->GetName(), fTrees[i]->GetName());
} else {
printf("\tTree No. %d was not loaded. Maximal number of trees is %d\n", i, fPars->GetNoRawFiles());
}
}
return;
}
void AculCalibScint::OpenFiles() {
if (!fPars) {
cerr << "\"AculCalibScint::OpenFiles\" parameters were not initialized." << endl;
return;
}
fPars->GetNoRawFiles();
fInFiles = new TFile* [fPars->GetNoRawFiles()];
for (Int_t i = 0; i < fPars->GetNoRawFiles(); i++) {
fInFiles[i] = new TFile(fPars->GetFileName(i), "READ");
// cout << "\"AculCalibScint::OpenFiles\" File \"" << fInFiles[i]->GetName() << "\" was opened." << endl;
}
}
void AculCalibScint::LoadTrees() {
if (!fInFiles) {
cerr << "\"AculCalibScint::LoadTrees\" Input files were not open." << endl;
return;
}
fTrees = new TTree* [fPars->GetNoRawFiles()];
for (Int_t i = 0; i < fPars->GetNoRawFiles(); i++) {
fTrees[i] = (TTree*)fInFiles[i]->Get("AnalysisxTree");
// cout << "\"AculCalibScint::LoadTrees\" Tree \"" << fTrees[i]->GetName()
// << "\" from file \"" << fInFiles[i]->GetName() << "\" was loaded." << endl;
}
}
TTree* AculCalibScint::GetTree(Int_t treeID) {
if (treeID >= fPars->GetNoRawFiles()) {
cerr << "\"AculCalibScint::DrawVariable\" Tree number " << treeID
<< " cannot exist. Maximal treeID is " << fPars->GetNoRawFiles() - 1 << "." << endl;
return 0;
}
return fTrees[treeID];
}
void AculCalibScint::DrawVariable(const char* variable, Int_t treeID, TCanvas *canvas, Int_t lowRange, Int_t upRange) {
if (!canvas) {
cerr << "\"AculCalibScint::DrawVariable\" Canvas pointer was NULL" << endl;
return;
}
//todo change 16 to parameter
const Int_t nPads = 16;
CanDivider(canvas, nPads);
TString canvasTitle;
TString var;
TString con;
TTree *curTree = 0;
curTree = GetTree(treeID);
if (!curTree) {
printf("AculCalibScint::DrawVariable: Tree No. %d was not found.\n", treeID);
return;
}
canvasTitle.Form("variable: %s; tree: %d", variable, treeID);
canvas->SetTitle(canvasTitle.Data());
for (Int_t i = 0; i < nPads; i++) {
var.Form("%s[%d]", variable, i);
con.Form("%s[%d]>%d && %s[%d]<%d", variable, i, lowRange, variable, i, upRange);
canvas->cd(i+1);
curTree->Draw(var.Data(), con.Data());
canvas->Update();
}
}
void AculCalibScint::DrawBeam(TCanvas *canvas, Int_t file, const char* variable) {
canvas->SetTitle("Beam");
const Int_t noFiles = file;
//todo delet parameter "files"
CanDivider(canvas, 0, noFiles, 3);
TTree *curTree = 0;
TCutG *curCutG = 0;
TString var;
TString con;
// cout << "cuts " << fPars->GetNoCuts() << endl;
cout << "this function has to be checked" << endl;
return;
for (Int_t i = 0; i < noFiles; i++) {
canvas->cd(i+1);
curTree = GetTree(i);
if (!curTree) {
printf("AculCalibCsI::DrawBeam: Tree No. %d was not found.\n", i);
continue;
}
curTree->Draw("QDC[0]:TDC[0]", "TDC[0]<1000 && QDC[0]<2000", "cont");
// curTree->Draw("QDC[0]+QDC[1]:(TDC[2]+TDC[3])/2. - (TDC[0]+TDC[1])/2.", "", "cont");
// cout << "aksjda\t" << energyPoints << endl;
for (Int_t j = 0; j < fPars->GetNoRawFiles(); j++) {
// if ( fPars->GetCut(j) ) {
// TCutG *cutTemp = fPars->GetCut(j);
// curCutG = new TCutG(*cutTemp);
curCutG->Draw("same");
// printf("AculCalibCsI::DrawBeam: cTOF cut No. %d cannot be drawn, need to repair this function.\n", j);
// }
}
canvas->cd(noFiles+1+i);
curTree->Draw("QDC[0]:QDC[1]", "", "cont");
for (Int_t j = 0; j < fPars->GetNoRawFiles(); j++) {
// if ( fPars->GetCut(noFiles + j) ) {
// TCutG *cutTemp = fPars->GetCut(noFiles + j);
// curCutG = new TCutG(*cutTemp);
curCutG->Draw("same");
// printf("AculCalibCsI::DrawBeam: cQCD cut No. %d cannot be drawn, need to repair this function.\n", j);
// }
}
canvas->cd(2*noFiles+1+i);
var.Form("%s[5]:TDC[0]", variable);
con.Form("%s[5]>200", variable);
curTree->Draw(var.Data(), con.Data(), "cont");
for (Int_t j = 0; j < fPars->GetNoRawFiles(); j++) {
// if ( cutsCol.At(files + j) ) {
// curCutG = (TCutG*)cutsCol.At(files + j);
// curCutG->Draw("same");
// printf("AculCalibCsI::DrawBeam: cQCD cut No. %d cannot be drawn, need to repair this function.\n", j);
// }
}
canvas->Update();
}
}
void AculCalibScint::GetPeakMean(const char* variable, Int_t treeID, /*Int_t energy,*/ TCanvas *canvas, const char* beamcut, const Int_t nbins, Int_t lowRange) {
// todo: change this parameter as nonconstant
const Int_t noCrystals = 16;
CanDivider(canvas, noCrystals);
TString var;
TString con;
TString hname;
TString canvasTitle;
TCutG *currCut = fPars->GetCut(beamcut, treeID);
// if (!fPars->GetCut(beamcut, treeID)) {
// cout << "\"AculCalibScint::GetPeakMean\" cut with name \"" << beamcut << "\" was not found." << endl;
// } else {
// currCut =
// }
// todo manage the canvas name using cut name
if (currCut) {
canvasTitle.Form("variable: %s; tree: %d; cut: %s;", variable, treeID, currCut->GetName());
canvas->SetTitle(canvasTitle.Data());
} else {
canvasTitle.Form("variable: %s; tree: %d; no cut;", variable, treeID);
canvas->SetTitle(canvasTitle.Data());
}
TTree *curTree = 0;
curTree = GetTree(treeID);
if (!curTree) {
printf("AculCalibCsI::GetPeakMean: Tree No. %d was not found.\n", treeID);
return;
}
TString sVariable = variable;
sVariable.ToLower();
Int_t channel = 0;
for (Int_t i = 0; i < noCrystals; i++) {
if (sVariable.Contains("anc")) {
channel = i+1;
} else {
channel = i;
}
var.Form("%s[%d]>>hfull[%d][%d]", variable, channel, treeID, i);
if (currCut) {
con.Form("%s[%d]>%d && %s", variable, channel, lowRange, currCut->GetName());
}
else {
// cout << "\"AculCalibScint::GetPeakMean\" cut with name \"" << beamcut << "\" was not found." << endl;
con.Form("%s[%d]>%d", variable, channel, lowRange);
}
canvas->cd(i+1);
hname.Form("hfull[%d][%d]", treeID, i);
fHistFull[treeID].push_back( new TH1I(hname.Data(), "title", nbins, 0, 4096) );
curTree->SetLineColor(1);
curTree->Draw(var.Data(), con.Data());
var.Form("%s[%d]>>hcut[%d][%d]", variable, channel, treeID, i);
if (currCut) {
con.Form("%s[%d]>%d && %s[%d]<%d && %s",
variable, channel, fPars->GetMinChannel(treeID, i),
variable, channel, fPars->GetMaxChannel(treeID, i),
fPars->GetCut(beamcut, treeID)->GetName());
}
else {
con.Form("%s[%d]>%d && %s[%d]<%d",
variable, channel, fPars->GetMinChannel(treeID, i),
variable, channel, fPars->GetMaxChannel(treeID, i));
}
hname.Form("hcut[%d][%d]", treeID, i);
fHistCut[treeID].push_back( new TH1I(hname.Data(), "title", nbins, 0, 4096) );
fHistCut[treeID][i]->SetLineColor(3);
curTree->Draw(var.Data(), con.Data(), "same");
gPad->Update();
fMeanPeakPos[treeID].push_back(fHistCut[treeID][i]->GetMean());
// cout << fMeanPeakPos[treeID][i] << endl;
fMeanPeakRMS[treeID].push_back(fHistCut[treeID][i]->GetRMS());
}
// cout << fMeanPeakPos.size() << "\t" << fMeanPeakPos[treeID].size() << endl;
// cout << fMeanPeakPos.size() << "\t" << fMeanPeakPos[0].size() << endl;
// cout << fMeanPeakPos.size() << "\t" << fMeanPeakPos[1].size() << endl;
// cout << fMeanPeakPos.size() << "\t" << fMeanPeakPos[2].size() << endl;
// cout << fMeanPeakPos.size() << "\t" << fMeanPeakPos[3].size() << endl;
canvas->Update();
}
void AculCalibScint::Calibrate(TCanvas *canvas, Bool_t savefile, const char* filename, const char* option) {
//todo change this parameter as nonconstant
//e.g. the number of found fPeakMeans
const Int_t noChannels = 16;
//todo
if (!canvas) return;
CanDivider(canvas, noChannels);
for (Int_t i = 0; i < fPars->GetNoRawFiles(); i++) {
cout << i << "\t" << fMeanPeakPos[i].size() << endl;
if (fMeanPeakPos[i].size() < noChannels || fMeanPeakRMS[i].size() < noChannels) {
// cout << i << "\t" << fMeanPeakPos[i].size() << endl;
cout << "\"AculCalibScint::Calibrate\" something bad here" << endl;
return;
}
}
// cout << alphas2.GetSize()+1 << endl;
// cout << energyPoints+1 << endl;
cout << fPars->GetNoEPoints() << endl;
const Int_t energyPoints = fPars->GetNoEPoints();
TString gName;
TString gTitle;
// if (savefile) fGraphs->Open(filename, "RECREATE");
TF1 *fnc;
for (Int_t i = 0; i < noChannels; i++) {
canvas->cd(i+1);
gCal[i] = new TGraphErrors(energyPoints+1);
// FillGraph(gCal[i], energies.GetSize()+1, energies.GetArray(), i);
FillGraph(gCal[i], energyPoints+1, i);
// if (savefile) gCal[i]->Write();
// gCal[i]->Draw("Al*");
gCal[i]->Draw("A*");
gName.Form("g%s%s%d\n", fPars->GetDetName(), fPars->GetParticleName(), i);
gTitle.Form("%s %s\n", fPars->GetDetName(), fPars->GetParticleName());
// gCal[i]->SetTitle(gTitle.Data());
gCal[i]->SetName(gName.Data());
gCal[i]->Fit("pol1");
fnc = gCal[i]->GetFunction("pol1");
fnc->SetLineColor(kRed);
fA.push_back(fnc->GetParameter(1));
fB.push_back(fnc->GetParameter(0));
canvas->Update();
}
if (savefile) SaveClbGraphs(filename, option);
}
void AculCalibScint::FillGraph(TGraphErrors *g, Int_t npoints, /*Double_t *energies,*/ Int_t graphNumber, const char* option) {
TString opt = option;
//todo check if fMeanPeakPos is full
//all available energy points and (0,0)
g->SetPoint(0, 0., 0.);
for (Int_t i = 0; i < npoints-1; i++) {
// g->SetPoint(i+1, energies[i], mean[i][graphNumber]);
// g->SetPointError(i+1, 0, meanRMS[i][graphNumber]);
// cout << "Graph number: " << graphNumber << endl;
// cout << graphNumber << "\t" << fMeanPeakPos[i][graphNumber] << endl;
g->SetPoint(i+1, fMeanPeakPos[i][graphNumber], fPars->GetCalEnergy(i));
g->SetPointError(i+1, fMeanPeakRMS[i][graphNumber], 0);
}
// for (Int_t j = 1; j < 4; j++) {
// g->SetPoint(j, 0., 0.);
// }
}
void AculCalibScint::SaveClbGraphs(const char* filename, const char* option) {
// cout << "asdasd" << endl;
// cout << fGraphs << endl;
TFile fGraphs(filename, option);
// if (fGraphs) fGraphs->Close();
// cout << "asdasd" << endl;
// fGraphs = new TFile(filename, option);
cout << fGraphs.IsOpen() << endl;
cout << fGraphs.GetName() << endl;
fGraphs.Print();
// if (!fGraphs->IsOpen()) {
// printf("AculCalibCsI::SaveClbGraphs: file %s was not open.\n", filename);
// return;
// }
for (Int_t i = 0; i<16; i++) {
fGraphs.cd();
gCal[i]->Write();
}
fGraphs.Close();
return;
}
void AculCalibScint::WriteClbParameters(const char* filename) {
std::ofstream outfile(filename);
if ( !outfile.is_open() ) {
printf("AculCalibCsI::WriteClbParameters: File %s was not open.\n", filename);
return;
}
outfile << "#detector:\t" << fPars->GetDetName() << ",\tparticle:\t" << fPars->GetParticleName() << endl;
outfile << "#channel\tfA\tfB" << endl;
for (Int_t i = 0; i < (Int_t)fA.size(); i++) {
outfile << i << "\t" << fA[i] << "\t" << fB[i] << endl;
}
outfile.close();
}
//////////////////////////////////////////////////////////////////////////////
// //
// This class is intended for ... //
// //
// It work like this... User may use such functions ... in such steps. //
//
// Keywords in parameter file and possible comments
//
// Something about order of keywords
//
// Example of parameter file (with explanations)
//
// energies 4 #number of energy points
// crystals 16 #number of crystals in detector
// files 4
// #fileID fileName
// #fileID not implemented yet
// data/csi_13_Ealpha16.root
// data/csi_13_Ealpha21.root
// data/csi_13_Ealpha26.root
// data/csi_13_Ealpha30.root
// #keyword detector particle
// detector SQ13 Alpha
// #keyword energy [MeV/A]
// energy 66.542
// #keyword; filename; number of cuts in file
// cutFile cuts/cutsSQ13Alpha.root 2
// cutsSQ13Alpha16
// cutSQ13Alpha16Amp
// #channel minimum maximum
// 0 650 830
// 1 920 1150
//\ ...
// 15 800 1000
// #CsI2, energy ~ 21 MeV/A, Alpha
// energy 85.437
// #keyword; filename; number of cuts in file
// cutFile cuts/cutsSQ13Alpha.root 2
// cutSQ13Alpha21
// cutSQ13Alpha21Amp
// #channel minimum maximum
// 0 1050 1200
//\ \...
// 15 1150 1350
// #CsI2, energy ~ 26 MeV/A, Alpha
// energy 105.5
// ...
//
//asdasd
//////////////////////////////////////////////////////////////////////////////
#pragma once
//#include "TObject.h"
//#include "TROOT.h"
#include <iostream>
#include <fstream>
//#include <vector>
#include "TFile.h"
#include "TTree.h"
//#include "TCanvas.h"
#include "TH1I.h"
#include "TGraphErrors.h"
//#include "TArrayD.h"
#include "TF1.h"
#include "./AculCalib.h"
using std::cout;
using std::endl;
//using std::vector;
class AculCalibScint : public AculCalib {
private:
//
//todo delete this strange double array somewhere
TFile **fInFiles; //! doc of class member
TTree **fTrees; //!
TFile *fCutFile;
vector< vector<TH1I*> > fHistFull;
vector< vector<TH1I*> > fHistCut;
//
vector< vector<Double_t> > fMeanPeakPos; //doc of class member
vector< vector<Double_t> > fMeanPeakRMS;
//
//todo make vector of graphs
TGraphErrors *gCal[16];
// TFile *fGraphs;
public:
AculCalibScint();
//default constructor
AculCalibScint(const char* parfile);
virtual ~AculCalibScint();
ClassDef (AculCalibScint,1); //decription right after ClassDef
virtual void Init();
void PrintTrees();
//Description of the function. I think it does not work.
void DrawVariable(const char* variable, Int_t treeID, TCanvas *canvas, Int_t lowRange = 0, Int_t upRange = 4096);
//Description of the function. I think it does not work.
void DrawBeam(TCanvas *canvas, Int_t file, const char* variable);
//One of the crucial function. It founds the mean of the peak related to our particle.
void GetPeakMean(const char* variable, Int_t treeID, TCanvas *canvas,
const char* beamcut, const Int_t nbins = 4096, Int_t lowRange = 0);
void Calibrate(TCanvas *canvas, Bool_t savefile = 0, const char* filename = "", const char* option = "READ");
void WriteClbParameters(const char* filename);
TTree* GetTree(Int_t treeID);
//private functions:
// void LoadCuts();
private:
void OpenFiles();
void LoadTrees();
void SaveClbGraphs(const char* filename, const char* option = "READ");
void FillGraph(TGraphErrors *g, Int_t npoints, /*Double_t *energies,*/ Int_t graphNumber, const char* option = "");
// void SetPars();
};
/*
* AculCalibSi.cpp
*
* Created on: Oct 26, 2016
* Author: vratik
*/
#include "AculCalibSi.h"
#include "AculCalParsSi.h"
ClassImp(AculCalibSi);
AculCalibSi::AculCalibSi() {
printf("AculCalibScint::Default constructor called.\n");
// fInFiles = 0;
// fTrees = 0;
// fCutFile = 0;
}
AculCalibSi::AculCalibSi(const char* parfile) {
printf("AculCalibScint::Constructor called.\n");
SetParFile(parfile);
Init();
}
AculCalibSi::~AculCalibSi() {
printf("AculCalibScint::Destructor called.\n");
}
void AculCalibSi::Init() {
fPars = new AculCalParsSi(fParFileName.Data());
}
/*
* AculCalibSi.h
*
* Created on: Oct 26, 2016
* Author: vratik
*/
#ifndef ACULCALIB_ACULCALIBSI_H_
#define ACULCALIB_ACULCALIBSI_H_
#include "AculCalib.h"
class AculCalibSi: public AculCalib {
private:
// Double_t something;
public:
AculCalibSi();
AculCalibSi(const char* parfile);
virtual ~AculCalibSi();
ClassDef(AculCalibSi, 1);
void Init();
// Bool_t CalculateCalibParameters(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); //calculate calibration parameters for given block in given file
//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
};
#endif /* ACULCALIB_ACULCALIBSI_H_ */
############################################################################
# CMakeLists.txt file for building AculCalib package
############################################################################
ROOT_STANDARD_LIBRARY_PACKAGE(AculCalib
HEADERS
AculCalib.h
AculCalibScint.h
AculCalibSi.h
AculCalPars.h
AculCalParsScintFile.h
AculCalParsScint.h
AculCalParsSi.h
SOURCES
AculCalib.cpp
# AculCalibDict.cpp
AculCalibScint.cpp
AculCalibSi.cpp
AculCalPars.cpp
AculCalParsScint.cpp
AculCalParsScintFile.cpp
AculCalParsSi.cpp
# DEPENDENCIES
# MathCore
# Matrix
# RIO
LINKDEF
AculCalibLinkDef.h
)
# ROOT_ADD_TEST_SUBDIRECTORY(test)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/G__AculCalib.cxx DESTINATION ${CMAKE_BINARY_DIR}/include)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculCalib.rootmap DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculCalib_rdict.pcm DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(TARGETS AculCalib LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/lib ARCHIVE DESTINATION ${CMAKE_BINARY_DIR}/lib)
\ No newline at end of file
......@@ -44,8 +44,8 @@ private:
Int_t nCuts; //number of cuts
TClonesArray cutsCol;
TH1I *hfull[NOCALFILES][16];
TH1I *hcut[NOCALFILES][16];
TH1I *hfull[NOCALFILES][16]; //!
TH1I *hcut[NOCALFILES][16]; //!
Int_t peakMin[NOCALFILES][16];
Int_t peakMax[NOCALFILES][16];
......
......@@ -23,11 +23,11 @@ AculCalibration::AculCalibration() : fEnergy(0), fEnergyInput(0), fA(0), fB(0),
fCurrentHStack = NULL;
fCurrentHistList.IsOwner();
// todo: change size of fA and fB in some other place
// todo: change size of fA and fB in some other place
fA.Set(32);
fB.Set(32);
// fEnergy.Set(4);
// fEnergyInput.Set(4);
fB.Set(32);
// fEnergy.Set(4);
// fEnergyInput.Set(4);
kRaNOPEAKS = 0;
fLowerPeakRelativeHight = 0.;
......@@ -171,7 +171,7 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
if (peaksNumber != kRaNOPEAKS) {
Info("PeaksFitting", "In histogram %s was found %d peaks", hSpectrum->GetName(), peaksNumber);
return 1;
}
}
//should be optional output
Info("PeaksFitting", "Number of peaks in %s: %d", hSpectrum->GetName(), peaksNumber);
......@@ -258,7 +258,7 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
TMath::Sort(peaksNumber, peak, j, kFALSE);
fPeak.Set(peaksNumber);
for (Int_t i = 0; i < peaksNumber; i++) {
fPeak[i] = peak[j[i]];
fPeak[i] = peak[j[i]];
//printf("\tPeak peak\t%f\n", fPeak[i]);
}
......@@ -267,23 +267,23 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
for (Int_t i = 0; i < peaksNumber; i++) {
printf("\tPeak position is\t%f\n", fPeak[i]);
}
}
}
// provest kontrolu pomerne polohy piku,
// jestli jsou spatne, provest urcita opatreni,
// napr. zapis daneho histogramu do souboru,
// zapis do souboru s chybama, vypis na obrazovku, ...
for (Int_t i = 0; i < peaksNumber; i++) {
for (Int_t i = 0; i < peaksNumber; i++) {
if ( !( (((1-fPeakPositionTolerance)*(fEnergy[0]/fEnergy[i])) < (fPeak[0]/fPeak[i])) && (((1+fPeakPositionTolerance)*(fEnergy[0]/fEnergy[i])) > (fPeak[0]/fPeak[i])) ) ) {
//printf("\tPeaksFitt fEnergy\t%f\n", fEnergy[i]);
//printf("\tPeaksFitt fEnergy\t%f\n", fEnergy[i]);
if (fCalInformation /* && opt.Contains("writebad")*/) {
fCalInformation->cd();
hSpectrum->Write();
}
//return 2;*/
}
}//for
}//for
return 0;
}
......@@ -358,27 +358,27 @@ void AculCalibration::PrintInputParameters()
return;
}
}
Double_t AculCalibration::GetA(Int_t i)
{
if (i >= fA.GetSize()) //if i >= number of array element
if (i >= fA.GetSize()) //if i >= number of array element
{
return 0.;
}
return fA[i];
}
}
Double_t AculCalibration::GetB(Int_t i)
{
if (i >= fB.GetSize())
if (i >= fB.GetSize())
{
return 0.;
}
return fB[i];
}
}
Bool_t AculCalibration::SetCalibrationParameters(const char* calparfile)
......@@ -393,7 +393,7 @@ Bool_t AculCalibration::SetCalibrationParameters(const char* calparfile)
char cA[40], cB[40], cC[40], cD[40];
//open file with calibration parameters
ifstream calFileR;
std::ifstream calFileR;
calFileR.open(calparfile);
......@@ -439,10 +439,10 @@ void AculCalibration::ShowRawSpectra(const char* filename, const Int_t block, TC
// xaxismax: maximal channel, which will be displayed
// subaddress:
Char_t address[40];
Char_t histName[40];
Char_t fillCommand[40];
Char_t fillCondition[40];
TString address;
TString histName;
TString command;
TString condition;
if (!rawCanvas) {
......@@ -453,11 +453,8 @@ void AculCalibration::ShowRawSpectra(const char* filename, const Int_t block, TC
rawCanvas->Clear();
// cout << "hovno" << endl;
rawCanvas->SetFillColor(10);
// cout << "hovno" << endl;
TFile *fr = new TFile(filename);
if (fr->IsOpen() == 0) {
cout << endl << "File " << filename << " was not opened and won't be processed" << endl << endl;
......@@ -465,23 +462,21 @@ void AculCalibration::ShowRawSpectra(const char* filename, const Int_t block, TC
}
TH1I *hRead = 0;
TTree *tr = (TTree*)fr->Get("RAW");
// cout << "hovno" << endl;
if (subaddress > 15) {
rawCanvas->Divide(4, 4);
rawCanvas->SetFillColor(10);
// cout << "hovno" << endl;
for (Int_t i = 0; i < 16; i++) {
cout << i << endl;
rawCanvas->cd(i+1);
hRead = new TH1I("name", "title", 4096, 0, 4095);
sprintf(address, "C3[%d][%d]", block, i);
sprintf(histName, "H3[%d][%d]", block, i);
address.Form("C3[%d][%d]", block, i);
histName.Form("H3[%d][%d]", block, i);
hRead->SetName(histName);
sprintf(fillCommand, "%s >> %s", address, hRead->GetName());
sprintf(fillCondition, "%s > 0", address);
tr->Draw(fillCommand, fillCondition, "");
command.Form("%s >> %s", address.Data(), hRead->GetName());
// sprintf(fillCondition, "%s > 0", address);
condition.Form("%s > 0", address.Data());
tr->Draw(command, condition, "");
if (hRead) {
hRead->SetDirectory(0);
// cout << hRead->GetEntries() << endl;
......@@ -496,13 +491,14 @@ void AculCalibration::ShowRawSpectra(const char* filename, const Int_t block, TC
else {
fr->cd();
hRead = new TH1I("name", "title", 4096, 0, 4095);
sprintf(address, "C3[%d][%d]", block, subaddress);
sprintf(histName, "H3[%d][%d]", block, subaddress);
address.Form("C3[%d][%d]", block, subaddress);
histName.Form("H3[%d][%d]", block, subaddress);
hRead->SetName(histName);
sprintf(fillCommand, "%s >> %s", address, hRead->GetName());
sprintf(fillCondition, "%s > 0", address);
command.Form("%s >> %s", address.Data(), hRead->GetName());
// sprintf(fillCondition, "%s > 0", address);
condition.Form("%s > 0", address.Data());
// cout << fillCommand << setw(20) << fillCondition << endl;
tr->Draw(fillCommand, fillCondition, "goff");
tr->Draw(command, condition, "goff");
if (hRead) {
hRead->SetDirectory(0);
// if (fHRawList) {
......@@ -621,11 +617,16 @@ void AculCalibration::FillRawSpectraFile(const char* rawdatafile, const char* bl
return;
}
char address[40];
char histName[40];
char histTitle[40];
char fillCommand[40];
char fillCondition[40];
// char address[40];
// char histName[40];
// char histTitle[40];
// char fillCommand[40];
// char fillCondition[40];
TString address;
TString histName;
TString histTitle;
TString command;
TString condition;
fw.cd();
TH1I *hRead = 0;
......@@ -633,14 +634,16 @@ void AculCalibration::FillRawSpectraFile(const char* rawdatafile, const char* bl
for (Int_t i = 0; i < 16; i++) { //zkontrolovat hranice
cout << i << endl; //predelat na info
hRead = new TH1I("name", "title", 4096, 0, 4095);
sprintf(address, "%s[%d]", block, i);
sprintf(histName, "%s[%d]", block, i);
sprintf(histTitle, "%s : %s", rawdatafile, histName);
address.Form("%s[%d]", block, i);
histName.Form("%s[%d]", block, i);
histTitle.Form("%s : %s", rawdatafile, histName.Data());
hRead->SetName(histName);
hRead->SetTitle(histTitle);
sprintf(fillCommand, "%s >> %s", address, hRead->GetName());
sprintf(fillCondition, "%s > 0", address);
tr->Draw(fillCommand, fillCondition, "goff"); //prozkoumat goff
// sprintf(fillCommand, "%s >> %s", address, hRead->GetName());
command.Form("%s >> %s", address.Data(), hRead->GetName());
// sprintf(fillCondition, "%s > 0", address);
condition.Form("%s > 0", address.Data());
tr->Draw(command, condition, "goff"); //prozkoumat goff
hRead->Write();
}//for
......@@ -679,7 +682,7 @@ Bool_t AculCalibration::CalculateCalibParameters(const char* inputfile, const ch
else { oFileName.Form("%s[%d-%d].cal", block, lowersubaddress, uppersubaddress); }
}//if
ofstream outcalfile;
std::ofstream outcalfile;
outcalfile.open(oFileName.Data());
if (!outcalfile.is_open()) {
Error("CalculateCalibParameters", "Output file %s was not opened", oFileName.Data());
......@@ -783,7 +786,7 @@ Bool_t AculCalibration::CalculateCalibParameters(const char* inputfile, const ch
//calibration parameters calculation //ok
for (Int_t j = 0; j < kRaNOPEAKS; j++) { //delat podle poctu zkoumanych piku
calGraph->SetPoint(j, fPeak[j], fEnergy[j]); //calibration graph filling
calGraph->SetPoint(j, fPeak[j], fEnergy[j]); //calibration graph filling
printf("\tPeak\t%f and energy\t%f\n", fPeak[j], fEnergy[j]);
}//for
calGraph->Fit(calFunction, "Q", "goff", 0, 4096); //omezit hlasitost fitovani, udelat volitelne, dodelat volby rozsahu
......@@ -1087,7 +1090,7 @@ void AculCalibration::FindEnergyPeaks(TCanvas *c1, const char* ifile, const char
//creation of output text file with positions of peaks in MeV
TString workFile = outfile;
ofstream ofile;
std::ofstream ofile;
ofile.open(workFile.Data());
if (!ofile.is_open()) {
Error("PeaksFitting", "Output file %s was not opened", workFile.Data());
......@@ -1103,17 +1106,17 @@ void AculCalibration::FindEnergyPeaks(TCanvas *c1, const char* ifile, const char
c1->cd(i+1);
PeaksFitting(hWork);
hWork->Draw();
ofile<<i<<"\t";
ofile<<i<<"\t";
for(Int_t j=0; j<kRaNOPEAKS; j++) {
ofile << fPeak[j] <<"\t";
}
ofile << fPeak[j] <<"\t";
}
ofile<<endl;
}
ofile.close();
}
}
void AculCalibration::FindAverageEnergies(const char* ifile, const char* outfile) {
TString iFile = ifile;
......@@ -1128,51 +1131,51 @@ void AculCalibration::FindAverageEnergies(const char* ifile, const char* outfile
//creation of output text file with average values of peak energies in MeV
TString workFile = outfile;
ofstream ofile;
std::ofstream ofile;
ofile.open(workFile.Data());
if (!ofile.is_open()) {
Error("PeaksFitting", "Output file %s was not opened", workFile.Data());
return;
}
TH1 *hWork = 0;
Double_t hArray[histList->GetEntries()][kRaNOPEAKS];
//TString hSumName;
Double_t hSumE1 = 0.;
Double_t hAvrE1 = 0.;
Double_t hSumE2 = 0.;
Double_t hAvrE2 = 0.;
Double_t hSumE3 = 0.;
Double_t hAvrE3 = 0.;
Double_t hSumE4 = 0.;
TH1 *hWork = 0;
Double_t hArray[histList->GetEntries()][kRaNOPEAKS];
//TString hSumName;
Double_t hSumE1 = 0.;
Double_t hAvrE1 = 0.;
Double_t hSumE2 = 0.;
Double_t hAvrE2 = 0.;
Double_t hSumE3 = 0.;
Double_t hAvrE3 = 0.;
Double_t hSumE4 = 0.;
Double_t hAvrE4 = 0.;
// c1->Clear();
// c1->Divide(6, 6);
for (Int_t i = 0; i < histList->GetEntries(); i++) {
for (Int_t i = 0; i < histList->GetEntries(); i++) {
fr->GetObject(histList->At(i)->GetName(), hWork);
PeaksFitting(hWork);
for(Int_t j = 0; j < kRaNOPEAKS; j++) {
PeaksFitting(hWork);
for(Int_t j = 0; j < kRaNOPEAKS; j++) {
hArray[i][j] = fPeak[j];
if(fPeak[j]==0.){
Error("FindAverageEnergies", "No peak in channel %i !", histList->GetEntries());
}
if(fPeak[j]==0.){
Error("FindAverageEnergies", "No peak in channel %i !", histList->GetEntries());
}
//hSumName.Form("hSumE%i",j);
}
hSumE1 += hArray[i][0];
hSumE2 += hArray[i][1];
hSumE3 += hArray[i][2];
hSumE4 += hArray[i][3];
}
hSumE1 += hArray[i][0];
hSumE2 += hArray[i][1];
hSumE3 += hArray[i][2];
hSumE4 += hArray[i][3];
// std::cout<<"i "<<i<<" hSumE1 "<<hSumE1<<std::endl;
}
hAvrE1 = hSumE1/histList->GetEntries();
hAvrE2 = hSumE2/histList->GetEntries();
hAvrE3 = hSumE3/histList->GetEntries();
hAvrE4 = hSumE4/histList->GetEntries();
hAvrE1 = hSumE1/histList->GetEntries();
hAvrE2 = hSumE2/histList->GetEntries();
hAvrE3 = hSumE3/histList->GetEntries();
hAvrE4 = hSumE4/histList->GetEntries();
ofile <<"Average energies are:\t"<<hAvrE1<<"\t"<<hAvrE2<<"\t"<<hAvrE3<<"\t"<<hAvrE4<<std::endl;
ofile.close();
}
}
void AculCalibration::ShowAnalyzedSpectra(const char *filename, TCanvas* fittedRawCanvas, Int_t xaxismin, Int_t xaxismax, Int_t subaddress)
......@@ -1380,7 +1383,7 @@ void AculCalibration::SetInputParameters() {
Char_t identificator[100];
ifstream fipr;
std::ifstream fipr;
fipr.open(fParFileName.Data());
if (!fipr.is_open()) {
Error("AculCalibration::SetInputsParameters", "File with input parameters \"%s\" was not opened.", fParFileName.Data());
......@@ -1400,8 +1403,8 @@ void AculCalibration::SetInputParameters() {
if ( strcmp(identificator, "noPeaks") == 0 ) {
kRaNOPEAKS = static_cast<Int_t>(atoi(parameter));
fEnergyInput.Set(kRaNOPEAKS);
fEnergy.Set(kRaNOPEAKS);
fEnergyInput.Set(kRaNOPEAKS);
fEnergy.Set(kRaNOPEAKS);
fPeak.Set(kRaNOPEAKS);
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
fipr.getline(line, lineLength);
......
......@@ -74,7 +74,7 @@ private:
//these variables are the main for the class
TArrayD fA; //calibration parameter, f(x) = fA*x + fB
TArrayD fB; //calibration parameter, f(x) = fA*x + fB
TArrayD fB; //calibration parameter, f(x) = fA*x + fB
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
......@@ -83,7 +83,7 @@ private:
TString fParFileName;
//it is very doubtful that we need this class variable
TFile *fCalInformation;
TFile *fCalInformation;
......@@ -144,7 +144,7 @@ public:
Bool_t CalculateCalibParameters(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); //calculate calibration parameters for given block in given file
Int_t uppersubaddress = ADDRESSNUMBER-1); //calculate calibration parameters for given block in given file
//function is not completely ready to use
//
......@@ -176,13 +176,13 @@ public:
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);
void FindEnergyPeaks(TCanvas *c1, const char* ifile, const char* outfile);
void FindEnergyPeaks(TCanvas *c1, const char* ifile, const char* outfile);
// Outputs calibrated energies for each channel in txt file
//
//
//
void FindAverageEnergies(const char* ifile, const char* outfile);
//
void FindAverageEnergies(const char* ifile, const char* outfile);
// Outputs average values of calibrated energies for the whole detector in txt file
//
//
......
......@@ -2,25 +2,25 @@
# AculData input with some variables
################################################################################
ACULDATALIBS := -lCore -lCint -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum #-lTELoss
ACULDATALIBS := -lCore -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum #-lTELoss
# Add inputs and outputs from these tool invocations to the build variables
ACULDATA_HEADERS += \
$(ACULDATA)/AculCalibration.h \
$(ACULDATA)/AculCalibCsI.h \
$(ACULDATA)/linkdef.h
$(ACULDATA)/AculDataLinkDef.h
ACULDATACPP_SRCS += \
$(ACULDATA)/AculCalibration.cpp \
$(ACULDATA)/AculCalibCsI.cpp \
$(ACULDATA)/AculDataCint.cpp
$(ACULDATA)/AculDataDict.cpp
ACULDATAOBJS += \
$(ACULDATA)/AculCalibration.o \
$(ACULDATA)/AculCalibCsI.o \
$(ACULDATA)/AculDataCint.o
$(ACULDATA)/AculDataDict.o
ACULDATACPP_DEPS += \
$(ACULDATA)/AculCalibration.d \
$(ACULDATA)/AculCalibCsI.d \
$(ACULDATA)/AculDataCint.d
\ No newline at end of file
$(ACULDATA)/AculDataDict.d
\ No newline at end of file
#ifdef __CINT__
#ifdef __CLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
......@@ -9,6 +9,4 @@
#pragma link C++ class AculCalibCsI;
//#pragma link C++ class ConfigDictionary;
#endif
#endif
\ No newline at end of file
############################################################################
# CMakeLists.txt file for building AculData package
############################################################################
ROOT_STANDARD_LIBRARY_PACKAGE(AculData
HEADERS
AculCalibCsI.h
AculCalibration.h
SOURCES
AculCalibCsI.cpp
AculCalibration.cpp
# DEPENDENCIES
# MathCore
# Matrix
# RIO
LINKDEF
AculDataLinkDef.h
)
# ROOT_ADD_TEST_SUBDIRECTORY(test)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/G__AculData.cxx DESTINATION ${CMAKE_BINARY_DIR}/include)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculData.rootmap DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculData_rdict.pcm DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(TARGETS AculData LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/lib ARCHIVE DESTINATION ${CMAKE_BINARY_DIR}/lib)
\ No newline at end of file
#ifndef CONFIGDICTIONARY_H
#define CONFIGDICTIONARY_H
#include "TObject.h"
#include "ReturnCodes.h"
#include "TStopwatch.h"
#include "TROOT.h"
#include <string>
#include <map>
#include <sstream>
#include "TLorentzVector.h"
#include <iostream>
#include "TMath.h"
#include "TString.h"
#include "TTree.h"
class ConfigDictionary{
public:
typedef std::map<std::string,std::string>::iterator CDIter;
ConfigDictionary();
ConfigDictionary(std::string);
virtual ~ConfigDictionary(){};//empty virtual destructor
ClassDef(ConfigDictionary,1);
std::string ToString();
void FromString(std::string);
//These throw errors if couldn't find key:
std::string GetString(std::string)throw(std::string);
int GetInt(std::string)throw(std::string);
double GetDouble(std::string)throw(std::string);
bool GetBool(std::string)throw(std::string);
//These will always set 'something' into map:
void SetString(std::string,std::string);
void SetDouble(std::string,double);
void SetInt(std::string,int);
void SetBool(std::string,bool);
CDIter Begin(){return configMap.begin();};
CDIter End(){return configMap.end();};
private:
std::map<std::string,std::string> configMap;
};
#endif
cmake_minimum_required(VERSION 3.0)
project(AculUtils)
# Find ROOT package
find_package(ROOT REQUIRED)
# Set installation prefix
# set(CMAKE_INSTALL_PREFIX "..")
# Set output directories for built targets
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY is: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # prevent mkdir races
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# message(STATUS "ROOT Configuration \n
# System ${CMAKE_SYSTEM}
# Processor ${PROCESSOR} (${CMAKE_SYSTEM_PROCESSOR})
# Build type ${CMAKE_BUILD_TYPE}
# Install path ${CMAKE_INSTALL_PREFIX}
# Compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}
# Compiler flags:
# C ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_BUILD_TYPE_UPPER}}
# C++ ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}}
# Linker flags:
# Executable ${CMAKE_EXE_LINKER_FLAGS}
# Module ${CMAKE_MODULE_LINKER_FLAGS}
# Shared ${CMAKE_SHARED_LINKER_FLAGS}\n")
# Add include directories for ROOT
include_directories(${ROOT_INCLUDE_DIRS})
# Print the value of ROOT_INCLUDE_DIRS
message(STATUS "ROOT include directories: ${ROOT_INCLUDE_DIRS}")
message(STATUS "ROOT_GET_INSTALL_DIR: ${ROOT_GET_INSTALL_DIR}")
# ROOT_GET_INSTALL_DIR
ROOT_GET_INSTALL_DIR(shared_lib_install_dir)
# Add the subdirectories
add_subdirectory(TELoss)
add_subdirectory(AculCalib)
add_subdirectory(AculData)
add_subdirectory(Utilities)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/G__AculData.cxx DESTINATION include)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculData.rootmap DESTINATION lib)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libAculData_rdict.pcm DESTINATION lib)
# install(TARGETS AculData LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
# Set the output directory for the dictionary files
# set(GEN_DICT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
# set(GEN_DICT_OUTPUT_DIR ${CMAKE_BINARY_DIR})
message(STATUS "GEN_DICT_OUTPUT_DIR: ${GEN_DICT_OUTPUT_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
message(STATUS "GEN_DICT_OUTPUT_DIR: ${GEN_DICT_OUTPUT_DIR}")
message(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}")
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# message(STATUS "shared_lib_install_dir: ${shared_lib_install_dir}")
\ No newline at end of file
1) set path in makefile according to your operating system
Tested with
root_6.28_04 (precompiled binaries for Ubuntu 20.04)
root-6.22.08 (compiled from source at nra161: /LynxOS/mbsusr/mbsdaq/analysis/root/root-6.22.08)
I. Use with GNU make
1) set path in makefile according to your operating system
2) type in terminal:
......@@ -7,3 +13,23 @@
make install
3) add the install folder to LD_LIBRARY_PATH
II. Use with cmake
1) mkdir build
2) cd build
3) cmake ..
4) make install
III. Test of compiled libraries
1) cd macros
2) modify libraries paths in rootlogon.C if needed
3) rootlogon.C will automatically load compiled libraries libTELoss.so and libAculData.so, then
root -l testOfAculData.cxx
root -l testOfTELoss.cxx
\ No newline at end of file
############################################################################
# CMakeLists.txt file for building TELoss package
############################################################################
# include_directories(TELoss)
# Get the list of include directories
get_property(INCLUDE_DIRS DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
# Print the include directories
message(STATUS "Include directories: ${INCLUDE_DIRS}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
# Add the source files specific to the TELoss module
set(SOURCES
TELoss.cpp
TELoss.h
TELossLinkDef.h
)
# Add the Fortran source file
set(FORTRAN_SOURCES
ELOSS.f90
)
# Generate dictionary for TELoss class
ROOT_GENERATE_DICTIONARY(
G__TELoss
${CMAKE_CURRENT_SOURCE_DIR}/TELoss.h
LINKDEF
${CMAKE_CURRENT_SOURCE_DIR}/TELossLinkDef.h)
# Add the dictionary source file to the sources list
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/G__TELoss.cxx)
# Create a library target for the TELoss module
add_library(TELoss SHARED ${SOURCES} ${FORTRAN_SOURCES})
# Link against ROOT libraries
target_link_libraries(TELoss ${ROOT_LIBRARIES})
# Set compiler flags for Fortran source
enable_language(Fortran)
set_source_files_properties(${FORTRAN_SOURCES} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/G__AculData.cxx DESTINATION ${CMAKE_BINARY_DIR}/include)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libTELoss.rootmap DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libTELoss_rdict.pcm DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(TARGETS TELoss LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/lib ARCHIVE DESTINATION ${CMAKE_BINARY_DIR}/lib)
\ No newline at end of file
......@@ -4,320 +4,256 @@
!== File: ELOSS.f90
!== Date: 08/12/2000
!======================================================================
! ELOSS.f90
! ELOSS.f90
!
! FUNCTIONS/SUBROUTINES exported from ELOSS.dll:
! ELOSS - subroutine
! ELOSS - subroutine
!======================================================================
!== Date 2024-05-03
! Some reworking of code:
!
subroutine ELOSS(NEL,ZEL,AEL,WEL,DEN,ZP,AP,NE,ETAB,RE,ZW,AW)
! * remove obsolete fortran instructions;
! * replace common block with module;
! * change precision to standard C double;
! * remove restriction for 5 elements in material.
module m_eloss
use iso_c_binding, only: c_int,c_double
real(c_double),allocatable,dimension(:),private:: adj,as,z,f,um
real(c_double),private:: oz,ro,azm,aj,zion,aion, zmed,amed
integer,private :: jc
contains
subroutine ELOSS(NEL,ZEL,AEL,WEL,DEN,ZP,AP,NE,ETAB,RE,ZW,AW)&
bind(C,name='eloss_')
! Expose subroutine ELOSS to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::ELOSS
IMPLICIT REAL*8(A-H,O-Z)
INTERFACE
SUBROUTINE rde(E, R, R1, R2, IRE)
REAL*8 E, R, R1, R2
INTEGER IRE
END SUBROUTINE rde
END INTERFACE
IMPLICIT none
! Variables
! Input:
INTEGER NEL, NE
REAL*8 ZEL(NEL),AEL(NEL),WEL(NEL), DEN,ZP,AP, ETAB(NE)
INTEGER(c_int),intent(in) ::NEL ! number of elements in the material
INTEGER(c_int) ::NE ! number of points in E -- Range table
real(c_double),dimension(nel),intent(in):: zel
real(c_double),dimension(nel),intent(in):: ael
real(c_double),dimension(nel),intent(in):: wel
real(c_double),intent(in) :: den
real(c_double),intent(in) :: ZP,AP
real(c_double),dimension(ne),intent(in):: Etab
! Output:
REAL*8 RE(NE),ZW,AW
! Local
COMMON adj(5),as(5),z(5),f(5),um(5),oz,ro,azm,aj,zion,aion,&
zmed,amed,jc
real(c_double),dimension(ne),intent(out) :: RE
REAL(c_double),intent(out) :: ZW,AW
!!$ local variables
integer :: i,j,ire
real(c_double) :: rel,rel1,uma,umed,zam,zme
! Body of ELOSS
zion = ZP
aion = AP
jc = NEL
ro = DEN
!== two parameters with question
ire = 1
oz = 1.
DO i = 1, NEL
as(i) = AEL(i)
z(i) = ZEL(i)
um(i) = WEL(i)
IF(z(i) .LE. 13.) THEN
adj(i) = 12.*z(i) + 7.
ELSE
adj(i) = 9.76*z(i) + 58.8 / z(i)**0.19
END IF
END DO
uma=0.
zam=0.
umed=0.
zme=0.
aj=0.
DO i = 1, jc
uma=uma+um(i)*as(i)
umed=umed+um(i)
zme=zme+um(i)*z(i)
END DO
amed=uma/umed
zmed=zme/umed
DO i = 1, jc
f(i)=um(i)*as(i)/uma
END DO
DO i = 1, jc
zam=zam+f(i)*z(i)/as(i)
END DO
azm=1./zam
aj=0.
DO i = 1, jc
aj=aj+f(i)*z(i)*log(adj(i))/as(i)
END DO
aj=aj*azm
aj=exp(aj)
ZW = zmed
AW = amed
DO j = 1, NE
!== result [mg/cm^2]
CALL rde(ETAB(j), RE(j), rel1, rel, ire)
END DO
zion = ZP
aion = AP
jc = NEL
ro = DEN
allocate(adj(jc),as(jc),z(jc),f(jc),um(jc))
!== two parameters with question
ire = 1
oz = 1.
as=ael;z = ZEL; um = WEL
DO concurrent (i = 1:jc)
IF(z(i) .LE. 13.) THEN
adj(i) = 12.*z(i) + 7.
ELSE
adj(i) = 9.76*z(i) + 58.8 / z(i)**0.19
END IF
END DO
uma=sum(um*as)
zme=sum(um*z)
zam=zme/uma; azm=1./zam
umed=sum(um)
aj=exp(sum(um*z*log(adj))/uma*azm)
amed=uma/umed
zmed=zme/umed
f=um*as/uma
ZW = zmed
AW = amed
DO j = 1, NE
!== result [mg/cm^2]
CALL rde(ETAB(j), RE(j), rel1, rel, ire)
END DO
deallocate(adj,as,z,f,um)
end subroutine ELOSS
SUBROUTINE rde(e,range,rel1,rel,ix)
IMPLICIT REAL*8(A-H,O-Z)
INTERFACE
REAL*8 FUNCTION c(x)
REAL*8 x
END FUNCTION c
REAL*8 FUNCTION c1(x)
REAL*8 x
END FUNCTION c1
END INTERFACE
! calculates range and de/dx for compounds
dimension ala(3),ala1(3)
dimension a(3,3),a1(4,4),a2(4,4),b(2,3),cc(5)
common adj(5),as(5),z(5),f(5),um(5),oz,ro,azm,aj,zion,aion,&
zmed,amed,jc
dimension alaj1(4),altau1(4)
data a/ -.75265, .073736, .040556, 2.5398,-.312,.018664, &
-.24598, .11548, -.0099661/
data a1/-8.0155, 0.36916, -1.4307e-02, 3.4718e-03, &
1.8371, -1.452e-02, -3.0142e-02, 2.3603e-03, &
0.045233, -9.5873e-04, 7.1303e-03, -6.8538e-04, &
-5.9898e-03,-5.2315e-04, -3.3802e-04, 3.9405e-05/
data a2/-8.725, 0.8309, -0.13396, 0.012625, &
1.8797, 0.11139, -0.064808, 0.0054043, &
0.74192, -0.528805, 0.1264232, -0.00934142, &
0.752005, -0.5558937, 0.12843119, -0.009306336/
data b/ 0.422377e-06, 3.858019e-09, 0.0304043e-06, -0.1667989e-09, &
-0.00038106e-06, 0.00157955e-09/
if(e.le.0.002)then
range=0.
rel1=0.
rel=0.
return
endif
! this a flag
ibis=-1
en = e/aion
tau = en*1.008
altau = log(tau)
alaj = log(aj)
alaj1(1)= 1.
altau1(1)= 1.
DO kk = 2,4
alaj1(kk)=alaj**(kk-1)
altau1(kk)=altau**(kk-1)
END DO
t = tau/938.256
tt = 2.*t + t*t
beta= sqrt(tt)/(1.+t)
s1=0.
DO i=1,4
DO j=1,4
s1 = s1 + a2(j,i)*alaj1(j)*altau1(i)
END DO
END DO
ala(1) = azm*exp(s1)
s2=0.
DO i=2,4
DO j=1,4
s2 = s2 + (i-1)*a2(j,i)*alaj1(j)*altau1(i-1)
END DO
END DO
ala1(1)=ala(1)*s2/tau
s1=0.
DO i=1,4
DO j=1,4
s1 = s1 + a1(j,i)*alaj1(j)*altau1(i)
END DO
END DO
ala(3) = azm*exp(s1)
s2=0.
DO i=2,4
DO j=1,4
s2 = s2 + (i-1)*a1(j,i)*alaj1(j)*altau1(i-1)
END DO
END DO
ala1(3)=ala(3)*s2/tau
s1=0.
DO i=1,3
DO j=1,3
s1 = s1 + a(j,i)*alaj1(j)*altau1(i)
END DO
END DO
ala(2)=azm*exp(s1)/1000.
s2=0.
DO i=2,3
DO j=1,3
s2 = s2 + (i-1)*a(j,i)*alaj1(j)*altau1(i-1)
END DO
END DO
ala1(2)=ala(2)*s2/tau
25 continue
coefa=3.
coefb=1.
alaa=(ala(1)*(tanh(coefa*(.98 - en))+1.)/2. &
+ ala(2)*(tanh(coefa*(en - .98))+1.)/2.) &
* (tanh(coefb*(8.0 - en))+1.)/2. &
+ ala(3)*(tanh(coefb*(en - 8.))+1.)/2.
alim1=0.
alim2=0.
if(coefa*(en-.98).lt.85)then
alim1=1.008/cosh(coefa*(.98-en))/cosh(coefa*(.98-en))
endif
if(coefb*(en-8.).lt.85)then
alim2=1.008/cosh(coefb*(8.-en))/cosh(coefb*(8.-en))
endif
alaa1=(ala1(1)*(tanh(coefa*(.98-en))+1.)/2.+ &
ala1(2)*(tanh(coefa*(en-.98))+1.)/2.)* &
(tanh(coefb*(8.-en))+1.)/2.+ &
ala1(3)*(tanh(coefb*(en-8.))+1.)/2.+ &
coefa/2.*(tanh(coefb*(8.-en))+1.)/2.* &
(ala(2)*alim1-ala(1)*alim1)+ &
coefb/2.*(ala(3)*alim2- &
(ala(1)*(tanh(coefa*(.98-en))+1.)/2.+ &
ala(2)*(tanh(coefa*(en-.98))+1.)/2.)*alim2)
hi=137.*beta/zion
bz=(31.8+3.86*(aj**.625))*azm*.000001
bz=bz*(zion**2.666667)*c(hi)
bz1=(4.357+.5288*(aj**.625))*azm*.001
bz1=bz1*(zion**1.666667)*c1(hi)
bep=beta*beta
rel1=zion*zion/(alaa1+bz1*((1.-bep)**1.5)/931.141/beta)
rel1=rel1/1000.
range=(alaa+bz)*aion/1.008/zion/zion
range=range*1000.
! Atention!! this version do not work correctly for ix.ne.1
if(ix.ne.1)return
ank=.153574*ro/azm
z23=zion**.666667
abet=beta*125./z23
zef=zion*(1.-exp(-abet))
zef2=zef*zef
om=1022000.*bep/(1.-bep)
cbet=0.
DO k=1,jc
cc(k)=0.
DO i=1,2
DO j=1,3
cc(k)=cc(k)+b(i,j)*((1./bep-1.)**j)*((adj(k)**(i+1)))
END DO
END DO
cbet=cbet+f(k)*cc(k)/as(k)
END DO
cbet=cbet*azm
del1=ank*zef2*(log(om/oz)-bep)/bep
del1=del1/ro
del2=2.*ank*zef2*(log(oz/aj)-cbet)/bep
del2=del2/ro
rel2=rel1-del1
rel3=rel1-rel2+del2
if(del1)8,8,9
8 rel=rel1
goto 12
9 if(del1+del2-rel2)10,10,11
10 rel=rel3
goto 12
11 if(del1.lt.rel1)then
rel=rel2
else
rel=rel1
endif
12 return
END
REAL*8 FUNCTION c(x)
REAL*8 x
IF(x .LE. 0.2) THEN
c = -0.00006 + (0.05252 + 0.12857*x)*x
ELSE IF(x .LE. 2.) THEN
c = -0.00185 + (0.07355 + (0.07172 - 0.02723*x)*x)*x
ELSE IF(x .LE. 3.) THEN
c = -0.0793 + (0.3323 - (0.1234 - 0.0153*x)*x)*x
ELSE
c = 0.22
END IF
END
REAL*8 FUNCTION c1(x)
REAL*8 x
IF(x .LE. 0.2) THEN
c1 = 0.05252+.25714*x
ELSE IF(x .LE. 2.0) THEN
c1 = 0.07355 + (0.14344 - 0.08169*x)*x
ELSE IF(x .LE. 3.0) THEN
c1 = 0.3323 - (0.2468 - 0.0459*x)*x
ELSE
c1 = 0.
END IF
END
! calculates range and de/dx for compounds
IMPLICIT none !REAL(c_double) (A-H,O-Z)
real(c_double),intent(in) ::E
integer,intent(in) ::ix
real(c_double),intent(out) ::range
real(c_double),intent(out) ::rel1
real(c_double),intent(out) ::rel
integer :: i,j,k,kk
real(c_double),parameter,dimension(3,3)::a=reshape([&
-0.75265, .073736, .040556,&
+2.53980,-.312000, .018664, &
-0.24598, .115480,-.0099661],shape=[3,3])
real(c_double),parameter,dimension(4,4)::a1=reshape([&
-8.0155 , 0.36916 ,-1.4307e-2, 3.4718e-3, &
+1.8371 ,-1.4520e-2,-3.0142e-2, 2.3603e-3, &
-4.5233e-2,-9.5873e-4, 7.1303e-3,-6.8538e-4, &
-5.9898e-3,-5.2315e-4,-3.3802e-4, 3.9405e-5],shape=[4,4])
real(c_double),parameter,dimension(4,4)::a2=reshape([&
-8.725000, 0.8309000,-0.13396000, 0.012625, &
-1.879700, 0.1113900,-0.06480800, 0.0054043, &
-0.741920,-0.5288050, 0.12642320,-9.341420e-3,&
-0.752005,-0.5558937, 0.12843119,-9.306336e-3 ],shape=[4,4])
real(c_double),parameter,dimension(2,3)::b=reshape([&
+4.223770e-07, 3.858019e-09, 3.04043e-08,&
-1.667989e-10,-3.810600e-10, 1.57955e-12],shape=[2,3])
real(c_double),allocatable,dimension(:) :: cc
real(c_double),dimension(3) :: ala, ala1
real(c_double) :: alaa,alaa1
real(c_double),dimension(4) :: alaj1, altau1
real(c_double) :: abet, alaj, altau, ank, bep, beta, bz, bz1,cbet, t, tau, tt
real(c_double),parameter :: coefa=3., coefb=1.
real(c_double) :: alim1, alim2, del1, del2, en, hi, om, rel2, rel3, zef, zef2
if(e.le.0.002)then
range=0.
rel1=0.
rel=0.
return
endif
en = e/aion
tau = en*1.008
altau = log(tau)
alaj = log(aj)
DO concurrent (kk = 1:4)
alaj1(kk)=alaj**(kk-1)
altau1(kk)=altau**(kk-1)
END DO
t = tau/938.256
tt = 2.*t + t*t
beta= sqrt(tt)/(1.+t)
ala(1) = azm*exp(dot_product(alaj1,matmul(a2,altau1)))
ala(2) = azm*exp(dot_product(alaj1(1:3),matmul(a,altau1(1:3))))/1000.
ala(3) = azm*exp(dot_product(alaj1,matmul(a1,altau1)))
ala1(1)=ala(1)*dot_product(alaj1,matmul(a2(:,2:4),altau1(1:3)*[1,2,3]))/tau
ala1(2)=ala(2)*dot_product(alaj1(1:3),matmul(a(:,2:3),altau1(1:2)*[1,2]))/tau
ala1(3)=ala(3)*dot_product(alaj1,matmul(a1(:,2:4),altau1(1:3)*[1,2,3]))/tau
associate(ca=>coefa*(.98 - en),cb=>coefb*(8.0 - en))
associate(tca=>(1+tanh(ca))/2.,tcb=>(1+tanh(cb))/2.)
alaa=(ala(1)*tca + ala(2)*(1.0-tca))*tcb + ala(3)*(1.0-tcb)
alim1=0.; alim2=0.
if(-ca.lt.85)then
alim1=1.008*(cosh(ca)**(-2))
endif
if(-cb.lt.85)then
alim2=1.008*(cosh(cb)**(-2))
endif
alaa1=(ala1(1)*tca+ ala1(2)*(1.0-tca))*tcb + ala1(3)*(1.0-tcb)+&
coefa*tcb* (ala(2)-ala(1))*alim1/2.+ &
coefb*(ala(3)-(ala(1)*tca+ala(2)*(1.-tca)))*alim2/2.
end associate
end associate
hi=137.*beta/zion
bz=(31.8+3.86*(aj**.625))*azm* 1e-6 *(zion**2.666667)*c(hi)
bz1=(4.357+.5288*(aj**.625))*azm* .001 *(zion**1.666667)*c1(hi)
bep=beta*beta
rel1=zion*zion/(alaa1+bz1*((1.- beta**2)**1.5)/931.141/beta)/1000.
range=(alaa+bz)*aion/(1.008*zion**2)*1000.
! Atention!! this version do not work correctly for ix.ne.1
if(ix.ne.1) then
return
end if
allocate(cc(size(as)))
ank=.153574*ro/azm
! z23=zion**.666667
abet=beta*125.*(zion** (-2.0/3.0))
zef=zion*(1.-exp(-abet))
zef2=zef*zef
om= 1022000. *bep/(1.-bep)
cbet=0.
DO k=1,jc
cc(k)=0.
DO i=1,2
DO j=1,3
cc(k)=cc(k)+b(i,j)*((1./bep-1.)**j)*((adj(k)**(i+1)))
END DO
END DO
cbet=cbet+f(k)*cc(k)/as(k)
END DO
cbet=cbet*azm
del1=ank*zef2*(log(om/oz)-bep)/bep/ro
del2=2.*ank*zef2*(log(oz/aj)-cbet)/bep/ro
rel2=rel1-del1
rel3=rel1-rel2+del2
!!$ here is a replasement for an Arithmetic IF construct
if (del1 <=0.0 ) then
rel=rel1
else if (del1+del2-rel2<=0) then
rel=rel3
else if(del1.lt.rel1)then
rel=rel2
else
rel=rel1
endif
deallocate(cc)
return
END SUBROUTINE rde
pure FUNCTION c(x) result(res)
REAL(c_double),intent(in) :: x
real(c_double) :: res
IF(x .LE. 0.2) THEN
res = -0.00006 + (0.05252 + 0.12857*x)*x
ELSE IF(x .LE. 2.) THEN
res = -0.00185 + (0.07355 + (0.07172 - 0.02723*x)*x)*x
ELSE IF(x .LE. 3.) THEN
res = -0.0793 + (0.3323 - (0.1234 - 0.0153*x)*x)*x
ELSE
res = 0.22
END IF
END FUNCTION c
pure FUNCTION c1(x) result(res)
REAL(c_double),intent(in) :: x
real(c_double) :: res
IF(x .LE. 0.2) THEN
res = 0.05252+.25714*x
ELSE IF(x .LE. 2.0) THEN
res = 0.07355 + (0.14344 - 0.08169*x)*x
ELSE IF(x .LE. 3.0) THEN
res = 0.3323 - (0.2468 - 0.0459*x)*x
ELSE
res = 0.
END IF
END FUNCTION c1
end module m_eloss
......@@ -2,19 +2,24 @@
# TELoss input with some variables
################################################################################
TELOSSLIBS := -lCore -lCint -lMathCore -lMatrix -lHist -lgfortran
# TELOSSLIBS := -lCore -lCint -lMathCore -lMatrix -lHist -lgfortran
TELOSSLIBS := -lCore -lMathCore -lMatrix -lHist -lgfortran
# Add inputs and outputs from these tool invocations to the build variables
TELOSS_HEADERS += \
$(TELOSS)/TELoss.h \
$(TELOSS)/TELossLinkDef.h
TELOSSCPP_SRCS += \
$(TELOSS)/TELoss.cpp \
$(TELOSS)/TELossCint.cpp
$(TELOSS)/TELossDict.cpp
TELOSSOBJS += \
$(TELOSS)/ELOSS.o \
$(TELOSS)/TELoss.o \
$(TELOSS)/TELossCint.o
$(TELOSS)/TELossDict.o
TELOSSCPP_DEPS += \
$(TELOSS)/TELoss.d \
$(TELOSS)/TELossCint.d
$(TELOSS)/TELossDict.d
#ifdef __CINT__
#ifdef __CLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class TELoss;
#endif
\ No newline at end of file
############################################################################
# CMakeLists.txt file for building Utilities package
############################################################################
ROOT_STANDARD_LIBRARY_PACKAGE(Utilities
HEADERS
CalPars.h
ConfigDictionary.h
CsICalib.h
ReturnCodes.h
SOURCES
CalPars.cpp
ConfigDictionary.cpp
CsICalib.cpp
# DEPENDENCIES
# MathCore
# Matrix
# RIO
LINKDEF
UtilitiesLinkDef.h
)
# ROOT_ADD_TEST_SUBDIRECTORY(test)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/G__Utilities.cxx DESTINATION ${CMAKE_BINARY_DIR}/include)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libUtilities.rootmap DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libUtilities_rdict.pcm DESTINATION ${CMAKE_BINARY_DIR}/lib)
install(TARGETS Utilities LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/lib ARCHIVE DESTINATION ${CMAKE_BINARY_DIR}/lib)
\ No newline at end of file
#include "CalPars.h"
ClassImp(CalPars);
CalPars::CalPars(const char* clbfile) {
ReadParFile(clbfile);
}
CalPars::~CalPars() {
printf("CalPars::Destructor called.\n");
}
Double_t CalPars::GetA(Int_t i) {
if (i >= fA.GetSize()) {
return 0.;
}
return fA[i];
}
Double_t CalPars::GetB(Int_t i) {
if (i >= fB.GetSize()) {
return 0.;
}
return fB[i];
}
Double_t CalPars::GetC(Int_t i) {
if (i >= fC.GetSize()) {
return 0.;
}
return fC[i];
}
void CalPars::ReadParFile(const char* clbfile) {
clbFile = clbfile;
std::ifstream infile(clbfile);
if ( !infile.is_open() ) {
printf("CalPars::ReadParFile: File %s was not open.\n", clbfile);
printf("CalPars::ReadParFile: Calibration parameters are empty!!!\n");
return;
}
TString line;
Int_t nopars;
Double_t a, b;
Int_t c; //threshold
printf("CalPars::ReadParFile: File %s was open.\n", clbfile);
line.ReadLine(infile);
sscanf(line.Data(), "%*d %d", &nopars);
// Info("CalPars::ReadParFile", "%d calibration parameters will be loaded", nopars);
printf("CalPars::ReadParFile: %d calibration parameters will be loaded\n", nopars);
fA.Set(nopars);
fB.Set(nopars);
fC.Set(nopars);
for (Int_t i = 0; i <nopars; i++) {
line.ReadLine(infile);
// if ( line.BeginsWith("#") ) continue;
// cout << line.Data() << endl;
sscanf(line.Data(), "%lf %lf %d", &b, &a, &c);
fA[i] = a;
fB[i] = b;
fC[i] = c;
// printf("fA[%d]: %f,\tfB[%d]: %f\n", i, fA[i], i, fB[i]);
// printf("fA[%d]: %f,\tfB[%d]: %f\n\n", i, a, i, b);
}
}
void CalPars::PrintClbPars() {
printf("CalPars::PrintClbPars: %d calibration parameters from %s file.\n", fA.GetSize(), clbFile.Data());
for (Int_t i = 0; i<fA.GetSize(); i++) {
printf("%d\t%f\t%f\t%f\n", i, GetA(i), GetB(i), GetC(i));
}
}
#pragma once
#include <iostream>
#include <fstream>
#include "TArrayD.h"
#include "TArrayI.h"
#include "TString.h"
#include "TObject.h"
using std::cout;
using std::endl;
class CalPars /*: TObject*/ {
private:
TArrayD fA;
TArrayD fB;
TArrayI fC;
TString clbFile;
public:
CalPars() : fA(0), fB(0), fC(0) {};
CalPars(const char* clbfile);
virtual ~CalPars();
Double_t GetA(Int_t i);
Double_t GetB(Int_t i);
Double_t GetC(Int_t i);
void ReadParFile(const char* clbfile);
void PrintClbPars();
ClassDef(CalPars, 1);
};
......@@ -100,17 +100,24 @@ ClassImp(ConfigDictionary);
// Info("Some optional variables wasn't read!");
//}
//--------------------</pre>
//
// ADDED 21.03.2012:
//
// With use of templates, now ConfigDictionary can handle complex objects
// reading and writing instantly as long as proper >> and << operators are
// provided for an object initialization.
//
// END_HTML
//////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________________________
ConfigDictionary::ConfigDictionary(){
//just empty map...
//Empty map...
}
//_____________________________________________________________________________
ConfigDictionary::ConfigDictionary(std::string params){
//Just creates dictionary using FromString method
//Creates dictionary using FromString method
FromString(params);
}
......@@ -154,63 +161,61 @@ void ConfigDictionary::FromString(std::string params){
}
//_____________________________________________________________________________
std::string ConfigDictionary::GetString(std::string key)throw(std::string){
std::string ConfigDictionary::GetString(std::string key){
//Extracts string from given key
//(if it exist, otherwise raises exception)
//This works also for long strings with white spaces in it!
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetString",
"Couldn't find the key: %s!",key.c_str());
throw(key);
// throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
return configMap[key];
}
//_____________________________________________________________________________
int ConfigDictionary::GetInt(std::string key)throw(std::string){
//Extracts integer from given key
//(if it exist, otherwise raises exception)
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetInt",
"Couldn't find the key: %s!",key.c_str());
throw(key);
}
int returned=0;
//Convert string to int:
std::stringstream ss(configMap[key]);
ss>>returned;
return returned;
int ConfigDictionary::GetInt(std::string key) {
// Extracts integer from given key
// (if it exists, otherwise raises exception)
try {
return Get<int>(key);
} catch (const std::string& message) {
// Catch the exception thrown by Get<int> and re-throw it as std::runtime_error
throw std::runtime_error(message);
}
}
//_____________________________________________________________________________
double ConfigDictionary::GetDouble(std::string key)throw(std::string){
//Extracts integer from given key
double ConfigDictionary::GetDouble(std::string key){
//Extracts double precision floating number from given key
//(if it exist, otherwise raises exception)
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetDouble",
"Couldn't find the key: %s!",key.c_str());
throw(key);
}
double returned=0.0;
//Convert string to double:
std::stringstream ss(configMap[key]);
ss>>returned;
return returned;
try
{
return Get<double>(key);
} catch (const std::string& message) {
// Catch the exception thrown by Get<int> and re-throw it as std::runtime_error
throw std::runtime_error(message);
}
}
//_____________________________________________________________________________
bool ConfigDictionary::GetBool(std::string key)throw(std::string){
bool ConfigDictionary::GetBool(std::string key){
//Extracts boolean from given key
//(if it exist, otherwise raises exception)
//Differs from template to make it more readable.
// Check if the key exists in the config map
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetBool",
"Couldn't find the key: %s!",key.c_str());
throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
//Convert string to bool:
if (configMap[key].compare("true") == 0)
return true;
else return false;
else
return false;
}
//_____________________________________________________________________________
......@@ -221,23 +226,19 @@ void ConfigDictionary::SetString(std::string key,std::string value){
//_____________________________________________________________________________
void ConfigDictionary::SetDouble(std::string key,double value){
//Sets value to key, converts double to string first
std::stringstream ss;
ss<<value;
configMap[key] = ss.str();
Set<double>(key,value);
}
//_____________________________________________________________________________
void ConfigDictionary::SetInt(std::string key,int value){
//Sets value to key, converts int to string first
std::stringstream ss;
ss<<value;
configMap[key] = ss.str();
Set<int>(key,value);
}
//_____________________________________________________________________________
void ConfigDictionary::SetBool(std::string key,bool value){
//Sets value to key, converts bool to string first
//Differs from template to make it more readable.
if (value == true) configMap[key] = "true";
else configMap[key] = "false";
}
#ifndef CONFIGDICTIONARY_H
#define CONFIGDICTIONARY_H
#include "TObject.h"
#include "ReturnCodes.h"
#include "TStopwatch.h"
#include "TROOT.h"
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include "TLorentzVector.h"
#include <iostream>
#include "TMath.h"
#include "TString.h"
#include "TTree.h"
#define ARRAY_DELIM '$'
class ConfigDictionary{
public:
typedef std::map<std::string,std::string>::iterator CDIter;
ConfigDictionary();
ConfigDictionary(std::string);
virtual ~ConfigDictionary(){};//empty virtual destructor
ClassDef(ConfigDictionary,1);
std::string ToString();
void FromString(std::string);
//These throw errors if couldn't find key:
//Most of methods below are just using templates to
//make them usable in Cint.
std::string GetString(std::string);
int GetInt(std::string);
double GetDouble(std::string);
bool GetBool(std::string);
//These will always set 'something' into map:
void SetString(std::string,std::string);
void SetDouble(std::string,double);
void SetInt(std::string,int);
void SetBool(std::string,bool);
CDIter Begin(){return configMap.begin();};
CDIter End(){return configMap.end();};
//_________________________________________________________________________
template <class T>
T Get(std::string key) {
//This method will get object of any class
//that was - presumably - stored before in string format in CD.
//Object needs to have proper >> operator.
//If operation fails, returned item should have default value
//depending on its empty constructor.
//For strings containing spaces it won't work properly, as it
//would extract only first space followed item!
if (configMap.find(key) == configMap.end()) {
Error( "ConfigDictionary::Get",
"Couldn't find the key: %s!",
key.c_str());
throw std::runtime_error("Couldn't find the key: " + key);
}
// Use std::istringstream to convert the string to the desired type
std::istringstream inStream(configMap[key]);
T item;
// Extract the value from the stringstream
inStream >> item;
// Check if extraction failed
if (inStream.fail()) {
// Throw std::runtime_error with an informative message
throw std::runtime_error("Failed to extract value for key: " + key);
}
// Return the extracted item
return item;
}
//_____________________________________________________________________________
template <class T>
void Set(std::string key,T value){
//Sets value to key, converts T to string first with << operator.
std::stringstream ss;
ss<<value;
configMap[key] = ss.str();
}
//_________________________________________________________________________
template <class T>
int GetArray(std::string key,std::vector<T> & output){
//Preconditions: T must have >> operator
//Effect: searches for key in map and pushes values stored in it into output vector
//Returns: number of elements pushed into vector
int retNumber = 0; // Counter for the number of elements pushed into the vector
// Check if the key exists in the config map
if (configMap.find(key) == configMap.end()){
Error( "ConfigDictionary::GetInt",
"Couldn't find the key: %s!",key.c_str());
throw std::runtime_error("Couldn't find the key: " + key);
}
// Create a string stream from the value associated with the key
std::istringstream arrayString(configMap[key]);
// Temporary string to hold each item from the string stream
std::string itemString;
//Dangerous - maybe? - exceptions for ss not handled...
// Loop to extract each item from the string stream
while (std::getline(arrayString,itemString,ARRAY_DELIM)){
std::stringstream itemStream(itemString); // Create a string stream from the item string
if (!itemString.empty()) { // Check if the item string is not empty
T item; // Temporary variable to hold the converted item
itemStream >> item; // Extract the item from the string stream
output.push_back(item); // Push the item into the output vector
retNumber++; // Increment the counter
}
}
// Return the number of elements pushed into the vector
return retNumber;
}
//_________________________________________________________________________
template <class T>
void SetArray(std::string key,std::vector<T> & input){
std::ostringstream arrayString;
for (unsigned int i=0;i<input.size();i++){
arrayString<<input[i]<<ARRAY_DELIM;
}
configMap[key] = arrayString.str();
}
private:
std::map<std::string,std::string> configMap;
};
#endif
#include "CsICalib.h"
ClassImp(CsICalib);
CsICalib::CsICalib() : fr("TFile", 5), tr("TTree", 5), cutsCol("TCutG"), fA(16), fB(16) {
printf("CsICalib::Default constructor called.\n");
}
CsICalib::CsICalib(const char* parfile) : fr("TFile", 5), tr("TTree", 5), cutsCol("TCutG", 10), fA(16), fB(16) {
printf("CsICalib::Constructor called.\n");
ReadParFile(parfile);
// PrintParameters();
cout << "nofiles: " << nofiles << endl;
OpenTrees();
LoadCuts();
// fr.Print();
// fr.At(0);
}
CsICalib::~CsICalib() {
printf("CsICalib::Destructor called.\n");
}
void CsICalib::OpenTrees() {
TFile *file;
for (Int_t i = 0; i < nofiles; i++) {
fr[i] = new TFile(fileNames[i], "READ");
file = (TFile*)fr.At(i);
cout << file->GetName() << endl;
tr[i] = (TTree*)file->Get("AnalysisxTree");
}
}
void CsICalib::LoadCuts() {
if (cutsFileName == "") {
printf("CsICalib::LoadCuts: Name of file (*.root) with cuts was not provided.\n");
printf("CsICalib::LoadCuts: No cuts has been loaded.\n");
return;
}
fCuts = new TFile(cutsFileName.Data(), "READ");
for (Int_t i = 0; i < nCuts; i++) {
cutsCol[i] = (TCutG*)fCuts->Get(cutNames[i]);
}
}
void CsICalib::ReadParFile(const char* parfile) {
std::ifstream infile(parfile);
if ( !infile.is_open() ) {
printf("CsICalib::ReadParFile: File %s was not open.\n", parfile);
return;
}
energyPoints = 0;
TString line;
Int_t i, min, max;
char det[100], part[100], fname[500], cname[100];
double en; //energy
while (!infile.eof()) {
line.ReadLine(infile);
if ( line.BeginsWith("#") ) continue;
if ( line.BeginsWith("energies") ) {
sscanf(line.Data(), "%*s %d", &i);
fE.Set(i);
continue;
}
if ( line.BeginsWith("files") ) {
sscanf(line.Data(), "%*s %d", &i);
nofiles = i;
printf("CsICalib::ReadParFile: %d files will be loaded:\n", nofiles);
for (Int_t j = 0; j < nofiles; j++) {
line.ReadLine(infile);
sscanf(line, "%s", fname);
fileNames[j] = fname;
cout << fileNames[j] << endl;
}
continue;
}
if ( line.BeginsWith("cutFile") ) {
sscanf(line.Data(), "%*s %s %d", fname, &nCuts);
cutsFileName = fname;
for (Int_t j = 0; j < nCuts; j++) {
line.ReadLine(infile);
sscanf(line, "%s", cname);
cutNames[j] = cname;
cout << cutNames[j] << endl;
}
continue;
}
if ( line.BeginsWith("detector") ) {
sscanf(line.Data(), "%*s %s %s", det, part);
detName = det;
partName = part;
printf("%s %s\n", detName.Data(), partName.Data());
continue;
}
if ( line.BeginsWith("energy") ) {
sscanf(line.Data(), "%*s %lf", &en);
fE[energyPoints] = en;
printf("%f\n", fE[energyPoints]);
energyPoints++;
continue;
}
sscanf(line.Data(), "%d %d %d", &i, &min, &max);
peakMin[energyPoints-1][i] = min;
peakMax[energyPoints-1][i] = max;
// printf("%d %d %d\n", i, peakMin[energyPoints-1][i], peakMax[energyPoints-1][i]);
}//while
printf("energyPoints: %d\n", energyPoints);
infile.close();
return;
}
void CsICalib::PrintParameters(const char* option) {
TString opt = option;
printf("Energy points: %d\n", energyPoints);
// printf("Detector: %s, Particle: %s\n", ????);
for (Int_t i = 0; i < energyPoints; i++) {
printf("Peak ranges for energy %f:\n", fE[i]);
if ( opt.Contains("v") ) {
for (Int_t j = 0; j < 16; j++) {
printf("ch: %d\tmin: %d\tmax: %d\n", j, peakMin[i][j], peakMax[i][j]);
}
}//if
}//for
}
void CsICalib::PrintPeakRanges() {
for (Int_t i = 0; i < 16; i++) {
printf("%d\t%d\t%d\n", i, peakMin[0][i], peakMax[0][i]);
}
}
void CsICalib::PrintTrees() {
TTree *curTree = 0;
for (Int_t i = 0; i < tr.GetEntries(); i++) {
curTree = (TTree*)tr.At(i);
if (curTree) {
printf("Tree No. %d; File: %s; Name: %s\n", i, curTree->GetDirectory()->GetName(), curTree->GetName());
} else {
printf("Tree No. %d was not loaded. Maximal number of trees is %d\n", i, NOCALFILES);
}
}
return;
}
void CsICalib::PrintFiles() {
printf("Number of loaded files: %d\n", fr.GetEntries());
TFile *curFile = 0;
for (Int_t i = 0; i < fr.GetEntries(); i++) {
curFile = (TFile*)fr.At(i);
if (curFile) {
printf("File No. %d: \"%s\"\n", i, curFile->GetName());
}
// else {
// printf("File No. %d was not loaded. Maximal number of files is %d\n", i, NOCALFILES);
// }
}
return;
}
void CsICalib::PrintCuts() {
// printf("CsICalib::PrintCuts: works wrong\n");
// return;
if (fCuts) printf("Cuts loaded from file \"%s\"\n", fCuts->GetName());
/*for (Int_t i = 0; i < NOCALFILES; i++) {
if (cTOF[i]) {
printf("TOF cut No. %d; Name: \"%s\"\n", i, cutsCol[i]->GetName());
cout << "asdjasd" << endl;
}
else {
printf("TOF cut No. %d was not loaded. Maximal number of cuts is %d\n", i, NOCALFILES);
}
}//for */
TCutG *curCut = 0;
//cutsCol
for (Int_t i = 0; i < cutsCol.GetEntries(); i++) {
curCut = (TCutG*)cutsCol.At(i);
if (curCut) {
printf("Cut No. %d; Name: \"%s\"\n", i, curCut->GetName());
} /*else {
printf("TOF cut No. %d was not loaded. Maximal number of cuts is %d\n", i, NOCALFILES);
}*/
}
/* for (Int_t i = 0; i < NOCALFILES; i++) {
if (cQCD[i]) {
printf("QCD cut No. %d; Name: \"%s\"\n", i, cQCD[i]->GetName());
// cout << "kasjhd" << endl;
} else {
// cout << "bhajskd" << endl;
printf("QCD cut No. %d was not loaded. Maximal number of cuts is %d\n", i, NOCALFILES);
// cout << "vsdfjks" << endl;
}
}
printf("CsICalib::PrintCuts: End of function.\n");
*/
return;
}
void CsICalib::DrawVariable(const char* variable, Int_t tree, TCanvas *canvas, Int_t lowRange, Int_t upRange) {
// if (!canvas) TCanvas *c = new TCanvas();
if (!canvas) return;
canvas->Clear();
canvas->Divide(4,4);
TString canvasTitle;
TString var;
TString con;
TTree *curTree = 0;
curTree = (TTree*)tr.At(tree);
if (!curTree) {
printf("CsICalib::DrawVariable: Tree No. %d was not found.\n", tree);
return;
}
canvasTitle.Form("variable: %s; tree: %d", variable, tree);
canvas->SetTitle(canvasTitle.Data());
for (Int_t i = 0; i < 16; i++) {
var.Form("%s[%d]", variable, i);
con.Form("%s[%d]>%d && %s[%d]<%d", variable, i, lowRange, variable, i, upRange);
canvas->cd(i+1);
curTree->Draw(var.Data(), con.Data());
canvas->Update();
}
}
void CsICalib::DrawBeam(TCanvas *canvas, Int_t files, const char* variable) {
canvas->SetTitle("Beam");
canvas->Clear();
// canvas->Divide(files, 2);
canvas->Divide(files, 3);
TTree *curTree = 0;
TCutG *curCutG = 0;
TString var;
TString con;
for (Int_t i = 0; i < files; i++) {
canvas->cd(i+1);
curTree = (TTree*)tr.At(i);
if (!curTree) {
printf("CsICalib::DrawBeam: Tree No. %d was not found.\n", i);
continue;
}
curTree->Draw("QDC[0]:TDC[0]", "TDC[0]<1000 && QDC[0]<2000", "cont");
// curTree->Draw("QDC[0]+QDC[1]:(TDC[2]+TDC[3])/2. - (TDC[0]+TDC[1])/2.", "", "cont");
// cout << "aksjda\t" << energyPoints << endl;
for (Int_t j = 0; j < energyPoints; j++) {
if ( cutsCol.At(j) ) {
curCutG = (TCutG*)cutsCol.At(j);
curCutG->Draw("same");
// printf("CsICalib::DrawBeam: cTOF cut No. %d cannot be drawn, need to repair this function.\n", j);
}
}
canvas->cd(files+1+i);
curTree->Draw("QDC[0]:QDC[1]", "", "cont");
for (Int_t j = 0; j < energyPoints; j++) {
if ( cutsCol.At(files + j) ) {
curCutG = (TCutG*)cutsCol.At(files + j);
curCutG->Draw("same");
// printf("CsICalib::DrawBeam: cQCD cut No. %d cannot be drawn, need to repair this function.\n", j);
}
}
canvas->cd(2*files+1+i);
var.Form("%s[5]:TDC[0]", variable);
con.Form("%s[5]>200", variable);
curTree->Draw(var.Data(), con.Data(), "cont");
for (Int_t j = 0; j < energyPoints; j++) {
// if ( cutsCol.At(files + j) ) {
// curCutG = (TCutG*)cutsCol.At(files + j);
// curCutG->Draw("same");
// printf("CsICalib::DrawBeam: cQCD cut No. %d cannot be drawn, need to repair this function.\n", j);
// }
}
canvas->Update();
}
}
void CsICalib::DrawVariableCut(const char* variable, Int_t tree, TCanvas *canvas, const char* cut1, const char* cut2, Int_t lowRange) {
// cout << "kjashbdfjka ajsdbf jakhsdb askjdhb" << endl;
if (!cutsCol.FindObject(cut1)) {
printf("Cut %s was not found.\n", cut1);
return;
}
canvas->Clear();
canvas->Divide(4,4);
TString canvasTitle;
TString var;
TString con;
TString sVariable = variable;
sVariable.ToLower();
Int_t channel = 0;
// cout << cutsCol.FindObject(cut1)->GetName() << endl;
canvasTitle.Form("variable: %s; cut1: %s; cut2: %s; tree: %d", variable, cutsCol.FindObject(cut1)->GetName(), cut2 , tree);
canvas->SetTitle(canvasTitle.Data());
TTree *curTree = 0;
curTree = (TTree*)tr.At(tree);
if (!curTree) {
printf("CsICalib::DrawVariableCut: Tree No. %d was not found.\n", tree);
return;
}
for (Int_t i = 0; i<16; i++) {
if (sVariable.Contains("anc")) {
channel = i+1;
} else {
channel = i;
}
// cout << channel << endl;
var.Form("%s[%d]", variable, channel);
con.Form("%s[%d]>%d", variable, channel, lowRange);
canvas->cd(i+1);
curTree->SetLineColor(1);
curTree->Draw(var.Data(), con.Data());
curTree->SetLineColor(3);
con.Form("%s[%d]>0 && %s", variable, channel, cutsCol.FindObject(cut1)->GetName());
curTree->Draw(var.Data(), con.Data(), "same");
TString scut2 = cut2;
if (scut2.Length() != 0) {
if (!cutsCol.FindObject(cut2)) {
printf("Cut %s was not found.\n", cut2);
continue;
}
curTree->SetLineColor(4);
con.Form("%s[%d]>0 && %s", variable, channel, cutsCol.FindObject(cut2)->GetName());
curTree->Draw(var.Data(), con.Data(), "same");
}
canvas->Update();
}
}
void CsICalib::GetPeakMean(const char* variable, Int_t tree, Int_t energy, TCanvas *canvas, const char* beamcut, const Int_t nbins, Int_t lowRange) {
canvas->Clear();
canvas->Divide(4,4);
TString var;
TString con;
TString hname;
TString canvasTitle;
canvasTitle.Form("variable: %s; tree: %d; cut: %s;", variable, tree, cutsCol.FindObject(beamcut)->GetName());
canvas->SetTitle(canvasTitle.Data());
TTree *curTree = 0;
curTree = (TTree*)tr.At(tree);
if (!curTree) {
printf("CsICalib::GetPeakMean: Tree No. %d was not found.\n", tree);
return;
}
TString sVariable = variable;
sVariable.ToLower();
Int_t channel = 0;
for (Int_t i = 0; i<16; i++) {
if (sVariable.Contains("anc")) {
channel = i+1;
} else {
channel = i;
}
var.Form("%s[%d]>>hfull[%d][%d]", variable, channel, tree, i);
con.Form("%s[%d]>%d && %s", variable, channel, lowRange, cutsCol.FindObject(beamcut)->GetName());
canvas->cd(i+1);
hname.Form("hfull[%d][%d]", tree, i);
hfull[tree][i] = new TH1I(hname.Data(), "title", nbins, 0, 4096);
curTree->SetLineColor(1);
curTree->Draw(var.Data(), con.Data());
var.Form("%s[%d]>>hcut[%d][%d]", variable, channel, tree, i);
con.Form("%s[%d]>%d && %s[%d]<%d && %s", variable, channel, peakMin[energy][i], variable, channel, peakMax[energy][i], cutsCol.FindObject(beamcut)->GetName());
hname.Form("hcut[%d][%d]", tree, i);
hcut[tree][i] = new TH1I(hname.Data(), "title", nbins, 0, 4096);
hcut[tree][i]->SetLineColor(3);
curTree->Draw(var.Data(), con.Data(), "same");
gPad->Update();
mean[tree][i] = hcut[tree][i]->GetMean();
meanRMS[tree][i] = hcut[tree][i]->GetRMS();
// cout << meanRMS[tree][i] << endl;
// cout << hcut[tree][i]->GetMean() << "\t" << hcut[tree][i]->GetRMS() << endl << endl;
}
canvas->Update();
}
void CsICalib::Calibrate(TCanvas *canvas, Bool_t savefile, const char* filename, const char* option) {
canvas->Clear();
canvas->Divide(4,4);
// cout << alphas2.GetSize()+1 << endl;
cout << energyPoints+1 << endl;
TString gName;
TString gTitle;
// if (savefile) fGraphs->Open(filename, "RECREATE");
TF1 *fnc;
for (Int_t i = 0; i<16; i++) {
canvas->cd(i+1);
gCal[i] = new TGraphErrors(energyPoints+1);
// FillGraph(gCal[i], energies.GetSize()+1, energies.GetArray(), i);
FillGraph(gCal[i], energyPoints+1, fE.GetArray(), i);
// if (savefile) gCal[i]->Write();
// gCal[i]->Draw("Al*");
gCal[i]->Draw("A*");
gName.Form("g%s%s%d\n", detName.Data(), partName.Data(), i);
gTitle.Form("%s %s\n", detName.Data(), partName.Data());
// gCal[i]->SetTitle(gTitle.Data());
gCal[i]->SetName(gName.Data());
gCal[i]->Fit("pol1");
fnc = gCal[i]->GetFunction("pol1");
fnc->SetLineColor(kRed);
fA[i] = fnc->GetParameter(1);
fB[i] = fnc->GetParameter(0);
canvas->Update();
}
if (savefile) SaveClbGraphs(filename, option);
}
void CsICalib::FillGraph(TGraphErrors *g, Int_t npoints, Double_t *energies, Int_t graphNumber, const char* option) {
TString opt = option;
//all available energy points and (0,0)
g->SetPoint(0, 0., 0.);
for (Int_t i = 0; i < npoints-1; i++) {
// g->SetPoint(i+1, energies[i], mean[i][graphNumber]);
// g->SetPointError(i+1, 0, meanRMS[i][graphNumber]);
g->SetPoint(i+1, mean[i][graphNumber], energies[i]);
g->SetPointError(i+1, meanRMS[i][graphNumber], 0);
}
// for (Int_t j = 1; j < 4; j++) {
// g->SetPoint(j, 0., 0.);
// }
}
void CsICalib::WriteClbParameters(const char* filename) {
std::ofstream outfile(filename);
if ( !outfile.is_open() ) {
printf("CsICalib::WriteClbParameters: File %s was not open.\n", filename);
return;
}
outfile << "#detector:\t" << detName << ",\tparticle:\t" << partName << endl;
outfile << "#channel\tfA\tfB" << endl;
for (Int_t i = 0; i < 16; i++) {
outfile << i << "\t" << fA[i] << "\t" << fB[i] << endl;
}
}
void CsICalib::SaveClbGraphs(const char* filename, const char* option) {
cout << "asdasd" << endl;
cout << fGraphs << endl;
if (fGraphs) fGraphs->Close();
cout << "asdasd" << endl;
fGraphs = new TFile(filename, option);
cout << fGraphs->IsOpen() << endl;
cout << fGraphs->GetName() << endl;
fGraphs->Print();
// if (!fGraphs->IsOpen()) {
// printf("CsICalib::SaveClbGraphs: file %s was not open.\n", filename);
// return;
// }
for (Int_t i = 0; i<16; i++) {
fGraphs->cd();
gCal[i]->Write();
}
fGraphs->Close();
return;
}
void CsICalib::ReadClbParameters(const char* filename) {
std::ifstream infile(filename);
if ( !infile.is_open() ) {
printf("CsICalib::ReadClbParameters: File %s was not open.\n", filename);
return;
}
TString line;
Int_t i;
Double_t a, b;
while (!infile.eof()) {
line.ReadLine(infile);
if ( line.BeginsWith("#") ) continue;
// cout << line.Data() << endl;
sscanf(line.Data(), "%d %lf %lf", &i, &a, &b);
fA[i] = a;
fB[i] = b;
// printf("fA[%d]: %f,\tfB[%d]: %f\n", i, fA[i], i, fB[i]);
// printf("fA[%d]: %f,\tfB[%d]: %f\n\n", i, a, i, b);
}
}
void CsICalib::DrawClbGraphs(const char* filename, const char* graphname, TCanvas *canvas) {
printf("CsICalib::DrawClbGraphs: does not work\n");
return;
TFile gfile(filename);
TString gName;
// TGraph *gr;
for (Int_t i = 0; i < 16; i++) {
gName.Form("%s%d", graphname, i);
gCal[i] = (TGraphErrors*)gfile.Get(gName.Data());
canvas->cd(i+1);
gCal[i]->Draw("A*");
}
}
void CsICalib::DrawEnergyDeposite(const char* variable, TCanvas *canvas, Int_t tree, const char* option) {
if (!canvas) return;
canvas->Divide(4,4);
TString opt;
opt = option;
opt.ToLower();
TString canvasTitle;
TString var;
TString con;
TTree *curTree = 0;
curTree = (TTree*)tr.At(tree);
if (!curTree) {
printf("CsICalib::DrawVariable: Tree No. %d was not found.\n", tree);
return;
}
canvasTitle.Form("variable: %s [MeV]; tree: %d", variable, tree);
canvas->SetTitle(canvasTitle.Data());
if (!opt.Contains("same")) canvas->Divide(4,4);
for (Int_t i = 0; i < 16; i++) {
var.Form("%s[%d]*%f + %f", variable, i, fB[i], fA[i]);
// var.Form("%s[%d]*%f + %f", variable, i, fA[i], fB[i]);
con.Form("%s[%d]>0", variable, i);
if (opt.Contains("same")) {
if (i==0) curTree->Draw(var.Data(), con.Data());
curTree->Draw(var.Data(), con.Data(), "same");
}
else {
canvas->cd(i+1);
curTree->Draw(var.Data(), con.Data());
}
canvas->Update();
}
}
#pragma once
//#include "TObject.h"
//#include "TROOT.h"
#include <iostream>
#include <fstream>
#include "TFile.h"
#include "TTree.h"
#include "TCutG.h"
#include "TCanvas.h"
#include "TClonesArray.h"
#include "TH1I.h"
#include "TGraphErrors.h"
#include "TArrayD.h"
#include "TF1.h"
#define NOCALFILES 5
using std::cout;
using std::endl;
class CsICalib {
private:
TString detName;
TString partName;
TClonesArray fr; //TFile
// TFile *fData;
TClonesArray tr;
TClonesArray colFiles;
TClonesArray colTrees;
Int_t nofiles;
TString fileNames[100];
TString cutNames[100];
Int_t energyPoints;
TArrayD fE;
TFile *fCuts;
TString cutsFileName;
Int_t nCuts; //number of cuts
TClonesArray cutsCol;
TH1I *hfull[NOCALFILES][16]; //!
TH1I *hcut[NOCALFILES][16]; //!
Int_t peakMin[NOCALFILES][16];
Int_t peakMax[NOCALFILES][16];
Double_t mean[NOCALFILES][16];
Double_t meanRMS[NOCALFILES][16];
TGraphErrors *gCal[16];
TFile *fGraphs;
TArrayD fA;
TArrayD fB;
public:
// CsICalib() : a(0), b(0), c(0), p(0){};
CsICalib();
CsICalib(const char* parfile);
virtual ~CsICalib();
void OpenTrees();
void LoadCuts();
void ReadParFile(const char* parfile);
void PrintParameters(const char* option = "");
void PrintPeakRanges();
void DrawVariable(const char* variable, Int_t tree, TCanvas *canvas, Int_t lowRange = 0, Int_t upRange = 4096);
void DrawBeam(TCanvas *canvas, Int_t files, const char* variable);
// void DrawdEE(const char* variable, Int_t tree, TCanvas *canvas);
void DrawVariableCut(const char* variable, Int_t tree, TCanvas *canvas, const char* cut1, const char* cut2 = "", Int_t lowRange = 0);
void GetPeakMean(const char* variable, Int_t tree, Int_t energy, TCanvas *canvas, const char* beamcut, const Int_t nbins = 4096, Int_t lowRange = 0);
void Calibrate(TCanvas *canvas, Bool_t savefile = 0, const char* filename = "", const char* option = "READ");
void FillGraph(TGraphErrors *g, Int_t npoints, Double_t *energies, Int_t graphNumber, const char* option = "");
void WriteClbParameters(const char* filename);
void SaveClbGraphs(const char* filename, const char* option = "READ");
void ReadClbParameters(const char* filename);
void DrawClbGraphs(const char* filename, const char* graphname, TCanvas *canvas);
void DrawEnergyDeposite(const char* variable, TCanvas *canvas, Int_t tree, const char* option = "");
void PrintTrees();
void PrintFiles();
void PrintCuts();
Double_t GetA(Int_t i) {return fA[i];};
Double_t GetB(Int_t i) {return fB[i];};
// Define the class for the cint dictionary
ClassDef (CsICalib,1);
};
################################################################################
# AculData input with some variables
################################################################################
# UTILITIESLIBS := -lCore -lCint -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf
UTILITIESLIBS := -lCore -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf
#UTILITIESLIBS := -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
# Add inputs and outputs from these tool invocations to the build variables
UTILITIES_HEADERS += \
$(UTILITIES)/CalPars.h \
$(UTILITIES)/CsICalib.h \
$(UTILITIES)/ConfigDictionary.h \
$(UTILITIES)/UtilitiesLinkDef.h
UTILITIESCPP_SRCS += \
$(UTILITIES)/CalPars.cpp \
$(UTILITIES)/CsICalib.cpp \
$(UTILITIES)/ConfigDictionary.cpp \
$(UTILITIES)/UtilitiesDict.cpp
UTILITIESOBJS += \
$(UTILITIES)/CalPars.o \
$(UTILITIES)/CsICalib.o \
$(UTILITIES)/ConfigDictionary.o \
$(UTILITIES)/UtilitiesDict.o
UTILITIESCPP_DEPS += \
$(UTILITIES)/CalPars.d \
$(UTILITIES)/CsICalib.d \
$(UTILITIES)/ConfigDictionary.d \
$(UTILITIES)/UtilitiesDict.d
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class CalPars;
#pragma link C++ class CsICalib;
#pragma link C++ class ConfigDictionary;
#endif
#include "THtml.h"
void htmldoc()
{
gSystem->Load("./libAculData.so");
gSystem->Load("./libTELoss.so");
gSystem->Load("./libAculCalib.so");
gSystem->Load("./libAculData.so");
THtml h;
h.SetInputDir(".");
h.SetOutputDir("htmldoc");
h.SetProductName("AculUtils");
h.MakeAll();
......
{
gSystem->Load("~/workspace/Utilities/libAculData.so");
gSystem->Load("libTELoss.so");
gSystem->Load("libAculData.so");
}
......@@ -33,8 +33,14 @@
// cal.DrawBeam(myCanv, 4, "SQ13");
//return;
// <<<<<<< HEAD
// cal.DrawVariableCut("SQ13", 0, c2, "cutsSQ13Alpha16");
// cal.DrawVariableCut("SQ13", 0, c2, "cutsSQ13Alpha16", "cutSQ13Alpha16Amp");
// =======
cal.DrawVariableCut("SQ13", 0, c1, "cutsSQ13Alpha16");
return;
cal.DrawVariableCut("SQ13", 0, c1, "cutsSQ13Alpha16", "cutSQ13Alpha16Amp");
// >>>>>>> newArch
//return;
// cal.DrawVariableCut("SQ13", 1, c2, "cutSQ13Alpha21", "cutSQ13Alpha21Amp");
// cal.DrawVariableCut("SQ13", 2, c3, "cutSQ13Alpha26", "cutSQ13Alpha26Amp");
......
energies 4 #number of energy points
crystals 16 #number of crystals in detector
files 4
#fileID fileName
#fileID not implemented yet
data/csi_13_Ealpha16.root
data/csi_13_Ealpha21.root
data/csi_13_Ealpha26.root
data/csi_13_Ealpha30.root
#keyword detector particle
detector SQ13 Alpha
#keyword energy [MeV/A]
energy 66.542
#keyword; filename; number of cuts in file
cutFile cuts/cutsSQ13Alpha.root 2
cutsSQ13Alpha16
cutSQ13Alpha16Amp
#channel minimum maximum
0 650 830
1 920 1150
2 850 1000
3 1200 1400
4 960 1100
5 700 850
6 650 800
7 1040 1240
8 850 1050
9 650 850
10 950 1200
11 900 1100
12 740 860
13 1140 1380
14 420 500
15 800 1000
#CsI2, energy ~ 21 MeV/A, Alpha
energy 85.437
#keyword; filename; number of cuts in file
cutFile cuts/cutsSQ13Alpha.root 2
cutSQ13Alpha21
cutSQ13Alpha21Amp
#channel minimum maximum
0 1050 1200
1 1350 1550
2 1190 1400
3 1650 1950
4 1300 1500
5 950 1100
6 900 1050
7 1450 1700
8 1150 1400
9 900 1100
10 1350 1600
11 1250 1500
12 950 1200
13 1600 1860
14 550 640
15 1150 1350
#CsI2, energy ~ 26 MeV/A, Alpha
energy 105.5
#keyword; filename; number of cuts in file
cutFile cuts/cutsSQ13Alpha.root 2
cutSQ13Alpha26
cutSQ13Alpha26Amp
#channel minimum maximum
0 1300 1600
1 1750 2050
2 1560 1800
3 2250 2500
4 1720 2000
5 1200 1450
6 1160 1400
7 1800 2200
8 1600 1850
9 1200 1400
10 1750 2100
11 1650 1900
12 1250 1600
13 2150 2450
14 690 900
15 1500 1700
#CsI2, energy ~ 30 MeV/A, Alpha
energy 119.54
#keyword; filename; number of cuts in file
cutFile cuts/cutsSQ13Alpha.root 2
cutSQ13Alpha30
cutSQ13Alpha30Amp
#channel minimum maximum
0 1450 1750
1 2200 2450
2 1900 2150
3 2590 3000
4 2100 2350
5 1500 1650
6 1400 1600
7 2250 2550
8 1900 2150
9 1400 1600
10 2050 2600
11 1950 2200
12 1580 1710
13 2550 2900
14 1100 1250
15 1800 2000
\ No newline at end of file
../calibration_CsI/cuts/
\ No newline at end of file
../calibration_CsI/data/
\ No newline at end of file
//#include "../../AculCalib/AculCalPars.h"
//#include "../../AculCalib/AculCalibScint.h"
//#include "../../AculCalib/AculCalibSi.h"
//#include "TSystem.h"
//#include <iostream>
//
using std::cout;
using std::endl;
void parTest()
{
gSystem->Load("../../libTELoss.so");
gSystem->Load("../../libAculCalib.so");
/* AculCalibSi ps;
ps.SetParFile("parforcal.par");
ps.Init();
ps.PrintParameters();
return;
*/
// AculCalParsScintFile pp;
// pp.SetNoCrystals(16);
// pp.Init();
// return;
cout << "-----------------------" << endl;
AculCalParsScint p;
p.SetParFile("SQ13Alpha.par");
p.Init();
// cout << p.GetFileName(0) << endl;
// cout << p.GetFileName(1) << endl;
// cout << p.GetFileName(2) << endl;
// cout << p.GetFileName(3) << endl;
// cout << p.GetFileName(4) << endl;
// p.PrintParameters("");
p.PrintParameters("all");
// return;
p.Reset();
// p.PrintParameters("");
// return;
cout << "-----------------------" << endl;
AculCalibScint c;
c.SetParFile("SQ13Alpha.par");
c.Init();
c.PrintParameters();
// return;
// c.PrintParameters("all");
// c.OpenFiles();
// c.LoadTrees();
c.PrintTrees();
TCanvas *c1 = new TCanvas("c1", "Plain");
TCanvas *c2 = new TCanvas("c2", "Plain");
TCanvas *c3 = new TCanvas("c3", "Plain");
TCanvas *c4 = new TCanvas("c4", "Plain");
// c.DrawVariable("SQ13", 2, c1);
// c.DrawBeam(c1, 4, "SQ13");
// c.GetPeakMean("SQ13", 0, c1, "cutSQ13Alpha16Amp", 256);
c.GetPeakMean("SQ13", 0, c1, "cutSQ13Ala16Amp", 256);
c.GetPeakMean("SQ13", 1, c2, "cutSQ13Alpha21Amp", 256);
c.GetPeakMean("SQ13", 2, c3, "cutSQ13Alpha26Amp", 256);
c.GetPeakMean("SQ13", 3, c4, "cutSQ13Alpha30Amp", 256);
//return;
// c.PrintFiles();
// c.PrintCuts();
// TCanvas *c1 = new TCanvas("c1", "Plain");
// c.GetPeakMean("SQ13", 0, 0, c1, "cutSQ13Alpha16Amp", 256);
TCanvas *cCal = new TCanvas("cCal", "calibration Alpha");
c.Calibrate(cCal);
return;
}
//226Ra
//relative units are normalized to 1
4 noPeaks //number of peaks// число пиков, по которым происходит калибровка
4.751 E1 //in MeV including dead layer of alpha source//энергии альфа источника
5.459 E2 //in MeV//
5.972 E3 //in MeV//
7.661 E4 //in MeV//
2.3 deadLayer
0 lowersubaddress
15 uppersubaddress
ANS block
AnalysisxTree treename
400 lowerChannel //in channels//каналы,
2000 upperChannel //in channels//каналы
0.5 lowerPeakHight //in relative units; minimal range of the peak//
0.5 upperPeakHight //in relative units; minimal range of the peak//
0.1 peakPositionTolerance //in relative units; for check of the peaks positions in channels//
2 fitFunctionLineWidth //integer 1 - 10; graphics//
20 minFitSigma //minimal sigma of the peaks to be fitted//
0.3 fitHightThreshold //in relative units; the minimal height of the treated peak//
{
TString pathToLibs = "../build/lib/";
// TString pathToLibs = "../";
TString pathToTELoss = pathToLibs + "libTELoss.so";
TString pathToAculData = pathToLibs + "libAculData.so";
TString pathToUtilities = pathToLibs + "libUtilities.so";
TString pathToAculCalib = pathToLibs + "libAculCalib.so";
//libTELoss.so loading
Int_t teloss = gSystem->Load(pathToTELoss);
if (teloss==0) Info("rootlogon.C", "Library %s was successfully loaded.", pathToTELoss.Data());
else Error("rootlogon.C", "Some error with %s loading", pathToTELoss.Data());
//libAculData.so loading
Int_t aculdata = gSystem->Load(pathToAculData);
if (aculdata==0) Info("rootlogon.C", "Library %s was successfully loaded.", pathToAculData.Data());
else Error("rootlogon.C", "Some error with %s loading", pathToAculData.Data());
//libUtilities.so loading
Int_t utilities = gSystem->Load(pathToUtilities);
if (utilities==0) Info("rootlogon.C", "Library %s was successfully loaded.", pathToUtilities.Data());
else Error("rootlogon.C", "Some error with %s loading", pathToUtilities.Data());
//libAculCalib.so loading
Int_t aculcalib = gSystem->Load(pathToAculCalib);
if (aculcalib==0) Info("rootlogon.C", "Library %s was successfully loaded.", pathToAculCalib.Data());
else Error("rootlogon.C", "Some error with %s loading", pathToAculCalib.Data());
}
\ No newline at end of file
#include "../AculData/AculCalibration.h"
void testOfAculData()
{
// gSystem->Load("/home/aculina/AculUt/libAculData.so");
// gSystem->Load("/home/aculina/AculUt/libTELoss.so");
AculCalibration cal;
cal.SetParFileName("./parforcal.par");
cal.Init(); //takes parameters from .par
cal.PrintInputParameters();
cal.PrintCalibrationParameters();
}
#include "TSystem.h"
#include "../TELoss/TELoss.h"
void testOfTELoss() {
//creating two object for combination particle-material
TELoss mSi_4He;
TELoss mSi_1H;
//setting tables for alphas in silicon
mSi_4He.SetEL(1, 2.321); //general properties of material (silicon)
mSi_4He.AddEL(14., 28.086, 1); //add Si element to material
mSi_4He.SetZP(2., 4.); //set 4He particles
mSi_4He.SetEtab(100000, 200.); //set table with ranges
mSi_4He.SetDeltaEtab(300); //some other table
//setting tables for protons in silicon
mSi_1H.SetEL(1, 2.321); //general properties of material (silicon)
mSi_1H.AddEL(14., 28.086, 1); //add Si element to material
mSi_1H.SetZP(1., 1.); //set 4He particles
mSi_1H.SetEtab(100000, 200.); //set table with ranges
mSi_1H.SetDeltaEtab(300); //some other table
cout << "Remaining energy of proton with energy of 20 MeV after penetration 1 mm of silicon is:" << endl;
cout << "expected (according to LISE++):\t14.604 MeV" << endl;
cout << "calculated:\t\t\t" << mSi_1H.GetE(20, 1000) << " MeV" << endl << endl;
cout << "Remaining energy of alpha with energy of 50 MeV after penetration 1 mm of silicon is:" << endl << endl;
cout << "expected (according to LISE++):\t5.447 MeV" << endl;
cout << "calculated:\t\t\t" << mSi_4He.GetE(50, 1000) << " MeV" << endl << endl;
cout << "Remaining energy of alpha with energy of 70 MeV after penetration 1 mm of silicon is:" << endl << endl;
cout << "expected (according to LISE++):\t45.076 MeV" << endl;
cout << "calculated:\t\t\t" << mSi_4He.GetE(70, 1000) << " MeV" << endl << endl;
}
\ No newline at end of file
......@@ -25,48 +25,99 @@ ROOTCFLAGS = $(shell root-config --cflags)
PWD = $(shell pwd)
#INSTALLFOLDER = $(HOME)/AculLib
UTILITIES = $(PWD)/Utilities
ACULDATA = $(PWD)/AculData
ACULCALIB = $(PWD)/AculCalib
TELOSS = $(PWD)/TELoss
-include $(UTILITIES)/Utilities.mk
-include $(ACULDATA)/AculData.mk
-include $(ACULCALIB)/AculCalib.mk
-include $(TELOSS)/TELoss.mk
all: libAculData.so \
all: libUtilities.so \
libAculData.so \
libAculCalib.so \
libTELoss.so
#ROOT html documentation, it will be done as a program which will be alsa compiled by this makefile, program will be as a last condition after all of the libraries
htmldoc: libAculData.so
htmldoc: libAculData.so libAculCalib.so libTELoss.so
-$(RM) htmldoc
root -l -q html.cxx
root -l -q htmldoc.cxx
clean_htmldoc:
-$(RM) htmldoc
-@echo ' '
clean:
-$(RM) $(UTILITIESOBJS) $(UTILITIESCPP_DEPS)
-$(RM) $(UTILITIES)/UtilitiesDict.* libUtilities.so $(UTILITIES)/*.pcm
-@echo ' '
-$(RM) $(ACULDATAOBJS) $(ACULDATACPP_DEPS)
-$(RM) $(ACULDATA)/AculDataCint.* libAculData.so
-$(RM) $(ACULDATA)/AculDataDict.* *.pcm $(ACULDATA)/*.pcm
-$(RM) libAculData.so
-@echo ' '
-$(RM) $(ACULCALIBOBJS) $(ACULCALIBCPP_DEPS)
-$(RM) $(ACULCALIB)/AculCalibDict.* libAculCalib.so $(ACULCALIB)/*.pcm
-@echo ' '
-$(RM) $(TELOSSOBJS) $(TELOSSCPP_DEPS)
-$(RM) $(TELOSS)/TELossCint.* libTELoss.so
-$(RM) $(TELOSS)/TELossDict.* *.pcm $(TELOSS)/*.pcm $(TELOSS)/*.pcm
-$(RM) libTELoss.so
-@echo ' '
-$(RM) htmldoc
-@echo ' '
# Those *Cint* files below need special treating:
$(ACULDATA)/AculDataCint.cpp:
-@echo 'Pre-building AculDataCint.cpp and AculDataCint.h files'
-rootcint -f $(ACULDATA)/AculDataCint.cpp -c -p $(ACULDATA_HEADERS)
# Those *Dictionary* files below need special treating:
$(UTILITIES)/UtilitiesDict.cpp:
-@echo 'Pre-building UtilitiesDict.cpp and UtilitiesDict.h files'
-rootcling -f $(UTILITIES)/UtilitiesDict.cpp -p $(UTILITIES_HEADERS)
-@echo 'Creating: link to UtilitiesDict_rdict.pcm'
-ln -s $(UTILITIES)/UtilitiesDict_rdict.pcm .
-@echo ' '
$(ACULDATA)/AculDataDict.cpp:
-@echo 'Pre-building AculDataDict.cpp and AculDataCint.h files'
-rootcling -f $(ACULDATA)/AculDataDict.cpp -p $(ACULDATA_HEADERS)
-@echo 'Creating: link to AculDataDict_rdict.pcm'
-ln -s $(ACULDATA)/AculDataDict_rdict.pcm .
-@echo ' '
$(ACULCALIB)/AculCalibDict.cpp:
-@echo 'Pre-building AculCalibDict.cpp and AculCalibDict.h files'
-rootcling -f $(ACULCALIB)/AculCalibDict.cpp -p $(ACULCALIB_HEADERS)
-@echo 'Creating: link to AculCalibDict_rdict.pcm'
-ln -s $(ACULCALIB)/AculCalibDict_rdict.pcm .
-@echo ' '
$(TELOSS)/TELossCint.cpp:
-@echo 'Pre-building TELossCint.cpp and TELossCint.h files'
-rootcint -f $(TELOSS)/TELossCint.cpp -c -p $(TELOSS)/TELoss.h $(TELOSS)/linkdef.h
$(TELOSS)/TELossDict.cpp:
-@echo 'Pre-building TELossDict.cpp and TELossDict_rdict.pcm files'
@echo
-rootcling -f $@ -c $(CXXFLAGS) -p $(TELOSS_HEADERS)
-@echo 'Creating: link to TELossDict_rdict.pcm'
-ln -s $(TELOSS)/TELossDict_rdict.pcm .
-@echo ' '
#*.so files
libUtilities.so: $(UTILITIESOBJS)
@echo 'Building target: $@'
@echo 'Invoking: $(CC) Linker'
$(CC) -L $(ROOTLIBS) -shared -o"libUtilities.so" $(UTILITIESOBJS) $(UTILITIESLIBS)
@echo 'Finished building target: $@'
@echo ' '
libAculData.so: libTELoss.so $(ACULDATAOBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
$(CC) -L . -L $(ROOTLIBS) -shared -o"libAculData.so" $(ACULDATAOBJS) $(ACULDATALIBS)
@echo 'Finished building target: $@'
@echo ' '
libAculCalib.so: libTELoss.so $(ACULCALIBOBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
$(CC) -L . -L $(ROOTLIBS) -shared -o"libAculCalib.so" $(ACULCALIBOBJS) $(ACULCALIBLIBS)
@echo 'Finished building target: $@'
@echo ' '
libTELoss.so: $(TELOSSOBJS)
@echo 'Building target: $@'
......@@ -83,7 +134,6 @@ libTELoss.so: $(TELOSSOBJS)
@echo 'Building file: $@'
@echo 'Invoking: $(CC) Compiler'
$(CC) -I$(ROOTINCS) -O0 -g3 -Wall -c -fmessage-length=0 -fPIC $(ROOTCFLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
# $(CC) -I$(ROOTINCS) -O2 -Wall -mmmx -msse -msse2 -msse3 -mfpmath=sse,387 -march=nocona -mtune=nocona -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $@'
@echo ' '
......