Commit 6fc4050f authored by Vratislav Chudoba's avatar Vratislav Chudoba

New library with calibration parameters for EXP1016 added.

parent 3f011dec
......@@ -123,12 +123,12 @@ void AculCalParsScint::SetPars() {
sscanf(line.Data(), "%*s %s %d", fname, &noCuts);
fFilePars[fEnergyPoints].SetNoCuts(noCuts);
fFilePars[fEnergyPoints].SetCutFileName(fname);
cout << line << endl;
cout << noCuts << endl;
// cout << line << endl;
// cout << noCuts << endl;
// fCutsFileName = fname;
for (Int_t j = 0; j < noCuts; j++) {
line.ReadLine(infile);
cout << line << endl;
// cout << line << endl;
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
continue;
......@@ -139,14 +139,14 @@ void AculCalParsScint::SetPars() {
}
fFilePars[fEnergyPoints].LoadCuts();
line.ReadLine(infile);
cout << line << endl;
// cout << line << endl;
// continue;
}
// cout << fNoCrystals << endl;
for (Int_t j = 0; j < fNoCrystals; j++) {
// line.ReadLine(infile);
cout << j << endl;
// cout << j << endl;
if ( line.BeginsWith("#") || line.BeginsWith("//") ) {
j--;
line.ReadLine(infile);
......
#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);
};
#include "ConfigDictionary.h"
ClassImp(ConfigDictionary);
//////////////////////////////////////////////////////////////////////////////
// BEGIN_HTML
// <p><font size="4"><b>Config(uration)Dictionary class</b></font></p>
// <br>
// <i>Author: Bartlomiej Hnatio 2012-08-06</i>
// <br><br>
// This is very useful class to convert strings containing pairs "key"="value"
// into fast dictionaries. This strings are often read from external files.
// From dictionary created in such way one can easily
// extract values in few supported formats (integer, double, boolean, string)
// It can also be used in opposite direction: when dictionary is created with
// given values and keys, one can create config string, which is most
// convenient to write in external files.
// <br><br><br>
// <u>Most simple example of usage:</u>
// <br><br>Suppose you have two variables fD and fI:
// <pre>-------------------
// Double_t fD;
// Int_t fI;
//
//fD = 3.14;
//fI = 2012;
//-----------------------</pre>
// To save its parameters into file you can create ConfigDictionary class
// instance and use <b>SetDouble</b> and <b>SetInt</b> functions to
// insert parameters values with arbitrarly defined keys (let them be
// really long and descriptive in this example):
// <pre>---------------------
//ConfigDictionary CD;
//CD.SetDouble("Most important variable D",fD);
//CD.SetInt("Equally important integer I",fI);
//---------------------</pre>
// Now configuration string saved in <b>ConfigDictionary</b> CD
// can be obtained with <b>ToString</b> method and should look like:
//<pre>
//"Most important variable D"="3.14" "Equally important integer I"="2012"
//</pre>
// <br> It can be easily saved to a file using simplest <i>fstream</i>
// methods. And the advantage is that as a key one can use any string,
// so configuration file created in such way is very self-explanatory.
// <br>
// <br>
// Now lets suppose the opposite action - loading config from file.
// Imagine, that you have 1000 objects of A class, which config was saved
// to file - one object per line:
// <pre>-----------------
//"Most important variable D"="3.14" "Equally important integer I"="2012"
//"Equally important integer I"="1011" "Most important variable D"="8.15"
//"Most important variable D"="13.16" "Equally important integer I"="10"
//(...)
//----------------</pre>
// Please notice that order in which pairs of keys and values are placed
// in file doesn't make any difference to the ConfigDictionary class.
// To recreate objects, you just read each line containing single
// config string and then create with it ConfigDictionary object
// using special constructor with string as argument,
// or using <b>FromString</b> method. After this, you can
// extract parameters (using <b>GetDouble</b> and <b>GetInt</b> methods)
// with using same keys as were used for saving, and ConfigDictionary
// will return their values:
// <pre>----------------------
//string line;//This line you read from file
//ConfigDictionary CD(line);
//fD = CD.GetDouble("Most important variable D");
//fI = CD.GetInt("Equally important integer I");
//--------------------</pre>
//<br>
// And last but not least: what happens, if key requested by user doesn't
// exist in dictionary? (This can be caused by many reasons, mostly errors on
// user side, but not always).
// When you try to extract non-existent key using <b>Get</b> functions,
// an exception is risen. In normal program it should end execution and print
// some information about where program stopped working.
// But lets say that you don't want that, i.e. program may use default
// configs instead of those from files, or not all keys were that important.
// You can surround all uses of <b>Get</b> methods with try/catch clause.
// So when exception is risen, you will catch it, and decide, if you want
// the program to stop running, or anything else. Simple example is
// shown below:
//<pre>-------------------
//ConfigDictionary CD(some_string);
//try{//try to read important variables:
// double d = CD.GetDouble("crucial var");
// bool b = CD.GetBool("most important b");
// int i = CD.GetInt("unique ID");
// //...and so on
//}catch(std::string & e){//catch any kind of exception
// Error("Some crucial variable wasn't read, ending program!");
// return SOME_REALLY_BAD_ERROR_CODE;
//}
//try{//now less important, or optional:
// string name = CD.GetString("least important variable");
// double p = CD.GetDouble("optional parameter");
// //...and so on
//}catch(std::string & f){
// 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(){
//Empty map...
}
//_____________________________________________________________________________
ConfigDictionary::ConfigDictionary(std::string params){
//Creates dictionary using FromString method
FromString(params);
}
//_____________________________________________________________________________
std::string ConfigDictionary::ToString(){
//Builds string that can be easily saved to file.
//Same format that can be read from files or from QtGui
//This should work same way for all uses
std::map<std::string,std::string>::iterator it;//Iterator to map elements
std::stringstream ss;//stream helpful with adding strings
//iterate whole dictionary:
for (it=configMap.begin();it!=configMap.end();++it){
//insert pairs "key"="value":
ss<<"\""<<it->first<<"\""<<"="<<"\""<<it->second<<"\""<<" ";
}
return ss.str();
}
//_____________________________________________________________________________
void ConfigDictionary::FromString(std::string params){
//params - TString containing list of key=value pairs
//
//Changes string formatted:
//"key1"="value1" "key2"="value with spaces 2" ...
//into map with keys and values
//Useful in lots of I/O functions,
//when we want to have a nice, readable format of data
std::stringstream loading(params);
std::string k,v;
while(!loading.fail()){
getline(loading,k,'\"');//removes everything to first "
getline(loading,k,'\"');//All chars between first two "" are the key
getline(loading,v,'\"');//removes all until third "
getline(loading,v,'\"');//All between another pair of "" is the value
if (!loading.fail())
configMap[k]=v;
}
}
//_____________________________________________________________________________
std::string ConfigDictionary::GetString(std::string key)throw(std::string){
//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);
}
return configMap[key];
}
//_____________________________________________________________________________
int ConfigDictionary::GetInt(std::string key)throw(std::string){
//Extracts integer from given key
//(if it exist, otherwise raises exception)
return Get<int>(key);
}
//_____________________________________________________________________________
double ConfigDictionary::GetDouble(std::string key)throw(std::string){
//Extracts double precision floating number from given key
//(if it exist, otherwise raises exception)
return Get<double>(key);
}
//_____________________________________________________________________________
bool ConfigDictionary::GetBool(std::string key)throw(std::string){
//Extracts boolean from given key
//(if it exist, otherwise raises exception)
//Differs from template to make it more readable.
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetBool",
"Couldn't find the key: %s!",key.c_str());
throw(key);
}
//Convert string to bool:
if (configMap[key].compare("true") == 0)
return true;
else return false;
}
//_____________________________________________________________________________
void ConfigDictionary::SetString(std::string key,std::string value){
//Sets value to key, no comments needed here...
configMap[key] = value;
}
//_____________________________________________________________________________
void ConfigDictionary::SetDouble(std::string key,double value){
Set<double>(key,value);
}
//_____________________________________________________________________________
void ConfigDictionary::SetInt(std::string key,int value){
//Sets value to key, converts int to string first
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)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();};
//_________________________________________________________________________
template <class T>
T Get(std::string key) throw (std::string) {
//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(key);
}
std::istringstream inStream(configMap[key]);
T item;
inStream >> 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)throw(std::string){
//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;
if (configMap.find(key) == configMap.end()){
Error( "ConfigDictionary::GetInt",
"Couldn't find the key: %s!",key.c_str());
throw(key);
}
std::istringstream arrayString(configMap[key]);
std::string itemString;
//Dangerous - maybe? - exceptions for ss not handled...
while (arrayString){
std::getline(arrayString,itemString,ARRAY_DELIM);
std::stringstream itemStream(itemString);
if (itemString.length() > 0){
T item;
itemStream>>item;
output.push_back(item);
retNumber++;
}
}
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
This diff is collapsed.
#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);
};
#ifndef RETURN_CODES_H
#define RETURN_CODES_H
//Some useful return codes
const static int SUCCESS = 0;
const static int IOEXCEPTION = -1;
const static int NOTFOUND = -2;
const static int NULLPOINTER = -3;
const static int UNKNOWN = -4;
const static int FAILURE = -5;
const static int CDEXCEPTION = -6;
const static int EMPTYCONTAINER = -7;
const static int NOTDEFINED = -8;
const static int EXCEPTION = -11;
#endif
################################################################################
# AculData input with some variables
################################################################################
UTILITIESLIBS := -lCore -lCint -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)/linkdef.h
UTILITIESCPP_SRCS += \
$(UTILITIES)/CalPars.cpp \
$(UTILITIES)/CsICalib.cpp \
$(UTILITIES)/ConfigDictionary.cpp \
$(UTILITIES)/UtilitiesCint.cpp
UTILITIESOBJS += \
$(UTILITIES)/CalPars.o \
$(UTILITIES)/CsICalib.o \
$(UTILITIES)/ConfigDictionary.o \
$(UTILITIES)/UtilitiesCint.o
UTILITIESCPP_DEPS += \
$(UTILITIES)/CalPars.d \
$(UTILITIES)/CsICalib.d \
$(UTILITIES)/ConfigDictionary.d \
$(UTILITIES)/UtilitiesCint.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
......@@ -25,15 +25,18 @@ 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
......@@ -47,6 +50,9 @@ clean_htmldoc:
-@echo ' '
clean:
-$(RM) $(UTILITIESOBJS) $(UTILITIESCPP_DEPS)
-$(RM) $(UTILITIES)/UtilitiesCint.* libUtilities.so
-@echo ' '
-$(RM) $(ACULDATAOBJS) $(ACULDATACPP_DEPS)
-$(RM) $(ACULDATA)/AculDataCint.* libAculData.so
-@echo ' '
......@@ -60,6 +66,11 @@ clean:
-@echo ' '
# Those *Cint* files below need special treating:
$(UTILITIES)/UtilitiesCint.cpp:
-@echo 'Pre-building UtilitiesCint.cpp and UtilitiesCint.h files'
-rootcint -f $(UTILITIES)/UtilitiesCint.cpp -c -p $(UTILITIES_HEADERS)
-@echo ' '
$(ACULDATA)/AculDataCint.cpp:
-@echo 'Pre-building AculDataCint.cpp and AculDataCint.h files'
-rootcint -f $(ACULDATA)/AculDataCint.cpp -c -p $(ACULDATA_HEADERS)
......@@ -76,6 +87,13 @@ $(TELOSS)/TELossCint.cpp:
-@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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment