diff --git a/.gitignore b/.gitignore index 811f8dc3a414a625f79481e44374fc006f9f0477..faaef28c56ad8060f6ad56b95b51a2014cac8e80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ anaroot/ build/ +rootfiles/ *.ridf *.root diff --git a/README.md b/README.md index 1be2b91bcf324710388ae9a1d89bf5e0f279f9ee..8c2f02799e8ebff2c57eaffa78371bd9dc26d8aa 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ ANAROOT is automatically installed by "cmake" in the project directory in order * The format of +* Assume that calibration parameters of two energy output are the same + ## Usage ### Config file diff --git a/calibration/si26a/mpos.prm b/calibration/si26a/mpos.prm index c2a401bc6649f106bfe0c7b35c1f54743e08fb2a..a2f4d33bfe807c90320a73d7b35db95af8314b6b 100644 --- a/calibration/si26a/mpos.prm +++ b/calibration/si26a/mpos.prm @@ -1,7 +1,8 @@ # MUX position calibration # channel of the 16 peaks +# for high0272 # 1ch, 2ch, ... , 16ch ; name -100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, ; MUX1-1-p0 +386.0, 401.0, 418.0, 435.0, 455.0, 471.0, 489.0, 506.0, 527.0, 543.0, 562.0, 578.0, 599.0, 615.0, 635.0, 653.0, ; MUX1-1-p0 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, ; MUX1-1-p1 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, ; MUX1-2-p0 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, ; MUX1-2-p1 diff --git a/include/CalibParamReader.hh b/include/CalibParamReader.hh new file mode 100644 index 0000000000000000000000000000000000000000..13bb2be19fd1946f78b80eaedfee538d51da06ce --- /dev/null +++ b/include/CalibParamReader.hh @@ -0,0 +1,39 @@ +#ifndef _CALIBPARAMREADER_HH_ +#define _CALIBPARAMREADER_HH_ + +#include +#include + +#include + +using namespace std; + +class CalibParamReader +{ + private: + TString file_name; + TString detector_name; + Int_t detector_id; + + public: + CalibParamReader(){} + CalibParamReader(TString det_name, TString cname){ + detector_name = det_name; + file_name = cname; + ReadCalibration(); + } + ~CalibParamReader(){} + + Int_t dim; + vector< vector > parameters; //parameters[branches][dims] + vector branch_name; + vector< vector > position_prms; //parameters[MUX_id][boundary=17] + + void SetDetectorId(); + Double_t GetCalibrateValue(Int_t id, Int_t branch_id, Int_t ch); + + void ReadCalibration(); + void ReadMUXposCalib(TString pos_file_name); +}; + +#endif diff --git a/include/CalibrationManager.hh b/include/CalibrationManager.hh index ff31cbee20ce143dfa9fbda0c796d4fb5c3c57f9..ccb37fce4473292b565264caadc66181e89e5d10 100644 --- a/include/CalibrationManager.hh +++ b/include/CalibrationManager.hh @@ -4,39 +4,12 @@ #include #include -#include +#include using namespace std; -class CalibrationManager -{ - private: - TString file_name; - TString detector_name; - Int_t detector_id; +//these functions are used to the TCordferCalibBranch +Double_t GetCalibValue(Int_t val, vector params); - public: - CalibrationManager(){} - CalibrationManager(TString det_name, TString cname){ - detector_name = det_name; - file_name = cname; - ReadCalibration(); - } - ~CalibrationManager(){} - - Int_t dim; - vector< vector > parameters; //parameters[branches][dims] - vector branch_name; - - void SetDetectorId(); - Double_t GetCalibrateValue(Int_t id, Int_t branch_id, Int_t ch); - Double_t GetdssdValue(); - Double_t GetssdValue(); - Double_t GetmssdValue(); - Double_t GetppacValue(); - Double_t GetcoinValue(); - - void ReadCalibration(); -}; #endif diff --git a/include/TCordferBranch.hh b/include/TCordferBranch.hh deleted file mode 100644 index a858ae9834c32beeaddcb24bacebb60f9eff3e2a..0000000000000000000000000000000000000000 --- a/include/TCordferBranch.hh +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef TCORDFERBRANCH_HH_ -#define TCORDFERBRANCH_HH_ - -#include -#include - -#include -#include - -using namespace std; - -class TCordferBranch -{ - private: - TString name; - - public: - TCordferBranch(){} - TCordferBranch(TString bname){ - name = bname; - } - TCordferBranch(TString bname, Int_t bsize){ - name = bname; - size = bsize; - } - TCordferBranch(TString bname, Int_t bsize, Int_t bnhit){ - name = bname; - size = bsize; - nhit = bnhit; - } - ~TCordferBranch(){} - - bool adc; - Int_t size; - Int_t nhit; - Int_t geo; - Int_t ch; - Int_t calib_dim; - Int_t count_hit; - Int_t *bra_val; - Int_t **mhtdc_val; - Double_t cbra_val; - Double_t cbra_tval[12]; - vector segment_id; - vector channel; - vector calib_param; - - //for MUX - bool mux_status1; - bool mux_status2; - bool mux_pos1; - bool mux_pos2; - Int_t mux_ch1; //0-15 - Int_t mux_ch2; //0-15 - Int_t geo_tmp1; - Int_t geo_tmp2; - Int_t ch_tmp1; - Int_t ch_tmp2; - Int_t val_tmp1; - Int_t val_tmp2; - - TString GetBranchName(){ return name; } - - void Setgeo(Int_t id){ geo = id; } - - void MemorySet(){ bra_val = new Int_t[size]; } - void TwoDimMemorySet(){ - mhtdc_val = new Int_t*[size]; - for(Int_t i=0; i seg, vector ch); - void CopyCalibInfo(Int_t dim, vector param); -}; - -#endif diff --git a/include/TCordferBranchManager.hh b/include/TCordferBranchManager.hh index ff55e9323cb13a4da1edb5b98543ba33a344e27b..39af4da3dfd4e674f77f245567040c4338509542 100644 --- a/include/TCordferBranchManager.hh +++ b/include/TCordferBranchManager.hh @@ -11,8 +11,7 @@ #include #include "ChannelMap.hh" -#include "CalibrationManager.hh" -#include "TCordferBranch.hh" +#include "CalibParamReader.hh" #include "TCordferRawBranch.hh" #include "TCordferMapBranch.hh" #include "TCordferCalibBranch.hh" @@ -42,6 +41,11 @@ class TCordferBranchManager vector< vector > mpos; //for mssd + //for temporary + bool rmapflag = false; + bool mapflag = false; + bool cmapflag = false; + public: TCordferBranchManager(){} TCordferBranchManager(TString input, TString output){ @@ -55,13 +59,12 @@ class TCordferBranchManager void Readyaml(TString yamlfile); void CreateRootFile(){ rootfile = new TFile(root_name.Data(), "recreate"); } - void CreateTree(); + void CreateRawTree(); void CreateMapTree(); void CreateCalibTree(); - void CreateBranch(); + void CreateRawBranch(); void CreateMapBranch(); void CreateCalibBranch(); - void ReadMUXposCalib(TString filename); void CreateRawMapping(); void CreateMapping(); void CreateCalibMapping(); diff --git a/include/TCordferCalibBranch.hh b/include/TCordferCalibBranch.hh index 71a9428793b953eb9f6e592b000b5d1846bbb627..23f34557d0ce64618484eec15e204f5e835ebeb4 100644 --- a/include/TCordferCalibBranch.hh +++ b/include/TCordferCalibBranch.hh @@ -5,7 +5,6 @@ #include #include -#include using namespace std; @@ -19,30 +18,15 @@ class TCordferCalibBranch TCordferCalibBranch(TString bname){ name = bname; } - TCordferCalibBranch(TString bname, Int_t bsize){ - name = bname; - size = bsize; - } - TCordferCalibBranch(TString bname, Int_t bsize, Int_t bnhit){ - name = bname; - size = bsize; - nhit = bnhit; - } ~TCordferCalibBranch(){} bool adc; - Int_t size; - Int_t nhit; Int_t geo; Int_t ch; Int_t calib_dim; Int_t count_hit; - Int_t *bra_val; - Int_t **mhtdc_val; Double_t cbra_val; Double_t cbra_tval[12]; - vector segment_id; - vector channel; vector calib_param; //for MUX @@ -50,34 +34,32 @@ class TCordferCalibBranch bool mux_status2; bool mux_pos1; bool mux_pos2; - Int_t mux_ch1; //0-15 - Int_t mux_ch2; //0-15 + bool mux1_junk; + bool mux2_junk; + Int_t mux_ch1; + Int_t mux_ch2; Int_t geo_tmp1; Int_t geo_tmp2; Int_t ch_tmp1; Int_t ch_tmp2; Int_t val_tmp1; Int_t val_tmp2; + vector mpos1_prm; + vector mpos2_prm; TString GetBranchName(){ return name; } - void Setgeo(Int_t id){ geo = id; } - - void MemorySet(){ bra_val = new Int_t[size]; } - void TwoDimMemorySet(){ - mhtdc_val = new Int_t*[size]; - for(Int_t i=0; i seg, vector ch); + void CopyCalibInfo(Int_t dim, vector param); }; diff --git a/include/TCordferMapBranch.hh b/include/TCordferMapBranch.hh index a2cf4dc388a9d32270f016ca3d55b3d17ef7810b..33475b99b6d0ed17469cb3da00f1964228e5b3cf 100644 --- a/include/TCordferMapBranch.hh +++ b/include/TCordferMapBranch.hh @@ -5,7 +5,6 @@ #include #include -#include using namespace std; @@ -16,69 +15,23 @@ class TCordferMapBranch public: TCordferMapBranch(){} - TCordferMapBranch(TString bname){ - name = bname; - } TCordferMapBranch(TString bname, Int_t bsize){ name = bname; size = bsize; } - TCordferMapBranch(TString bname, Int_t bsize, Int_t bnhit){ - name = bname; - size = bsize; - nhit = bnhit; - } ~TCordferMapBranch(){} bool adc; - Int_t size; - Int_t nhit; - Int_t geo; - Int_t ch; - Int_t calib_dim; - Int_t count_hit; - Int_t *bra_val; - Int_t **mhtdc_val; - Double_t cbra_val; - Double_t cbra_tval[12]; - vector segment_id; - vector channel; - vector calib_param; - - //for MUX - bool mux_status1; - bool mux_status2; - bool mux_pos1; - bool mux_pos2; - Int_t mux_ch1; //0-15 - Int_t mux_ch2; //0-15 - Int_t geo_tmp1; - Int_t geo_tmp2; - Int_t ch_tmp1; - Int_t ch_tmp2; - Int_t val_tmp1; - Int_t val_tmp2; + Int_t size; //use + Int_t *bra_val; //use + vector segment_id; //use + vector channel; //use TString GetBranchName(){ return name; } - void Setgeo(Int_t id){ geo = id; } - void MemorySet(){ bra_val = new Int_t[size]; } - void TwoDimMemorySet(){ - mhtdc_val = new Int_t*[size]; - for(Int_t i=0; i seg, vector ch); - void CopyCalibInfo(Int_t dim, vector param); }; #endif diff --git a/include/TCordferRawBranch.hh b/include/TCordferRawBranch.hh index 0ca24494845c16c27a0e05a6db75f742556cbe3f..b8472b8b3b6d15195d362500302702c353acb305 100644 --- a/include/TCordferRawBranch.hh +++ b/include/TCordferRawBranch.hh @@ -5,7 +5,6 @@ #include #include -#include using namespace std; @@ -16,9 +15,6 @@ class TCordferRawBranch public: TCordferRawBranch(){} - TCordferRawBranch(TString bname){ - name = bname; - } TCordferRawBranch(TString bname, Int_t bsize){ name = bname; size = bsize; @@ -30,55 +26,20 @@ class TCordferRawBranch } ~TCordferRawBranch(){} - bool adc; Int_t size; Int_t nhit; Int_t geo; - Int_t ch; - Int_t calib_dim; - Int_t count_hit; Int_t *bra_val; Int_t **mhtdc_val; - Double_t cbra_val; - Double_t cbra_tval[12]; - vector segment_id; - vector channel; - vector calib_param; - - //for MUX - bool mux_status1; - bool mux_status2; - bool mux_pos1; - bool mux_pos2; - Int_t mux_ch1; //0-15 - Int_t mux_ch2; //0-15 - Int_t geo_tmp1; - Int_t geo_tmp2; - Int_t ch_tmp1; - Int_t ch_tmp2; - Int_t val_tmp1; - Int_t val_tmp2; TString GetBranchName(){ return name; } void Setgeo(Int_t id){ geo = id; } void MemorySet(){ bra_val = new Int_t[size]; } - void TwoDimMemorySet(){ - mhtdc_val = new Int_t*[size]; - for(Int_t i=0; i seg, vector ch); - void CopyCalibInfo(Int_t dim, vector param); + void FreeTwoDimMemory(); }; #endif diff --git a/macro/compare.C b/macro/compare.C new file mode 100644 index 0000000000000000000000000000000000000000..2c63c0851048d8f7bff41ecf0f8cee05f52fd120 --- /dev/null +++ b/macro/compare.C @@ -0,0 +1,2 @@ +{ +} diff --git a/main.cpp b/main.cpp index 7ea2d455cced6fba10bdfcbd128407d71d6c2230..2d8f117394d83e7894d2109ecd400edb8870dc65 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,7 @@ using namespace std; Int_t main(Int_t argc, Char_t **argv) { //map tree is require to make calibration tree - bool rawdata = false; + bool rawdata = true; bool mapdata = true; bool calibration = true; @@ -37,12 +37,12 @@ Int_t main(Int_t argc, Char_t **argv) TCordferBranchManager *branch_manager = new TCordferBranchManager(filename[0], filename[1]); branch_manager->Readyaml(yamlfile); branch_manager->CreateRootFile(); - if(rawdata){ branch_manager->CreateTree(); } + if(rawdata){ branch_manager->CreateRawTree(); } if(mapdata){ branch_manager->CreateMapTree(); } if(calibration){ branch_manager->CreateCalibTree(); } //prepare branch - if(rawdata){ branch_manager->CreateBranch(); } + if(rawdata){ branch_manager->CreateRawBranch(); } if(mapdata){ branch_manager->CreateMapBranch(); } if(calibration){ branch_manager->CreateCalibBranch(); } @@ -59,8 +59,6 @@ Int_t main(Int_t argc, Char_t **argv) Int_t evtn = 0; while(estore->GetNextEvent()){ - if(print_progress && evtn%10000 == 0) { cout << "reading..." << evtn << endl; } - if(rawdata){ branch_manager->ClearRawAll(); } if(mapdata){ branch_manager->ClearMapAll(); } if(calibration){ branch_manager->ClearCalibAll(); } @@ -89,6 +87,7 @@ Int_t main(Int_t argc, Char_t **argv) if(calibration){ branch_manager->CalibFill(); } estore->ClearData(); + if(print_progress && evtn%10000 == 0) { cout << "reading..." << evtn << endl; } evtn++; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89eaaa9dad722f41d4a2e5a1924ceb0f29429b6d..9281a02ba7181d5ed760432582847bd2d4eac51f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ add_library(sources SHARED CommandlineReader.cpp ChannelMap.cpp + CalibParamReader.cpp CalibrationManager.cpp - TCordferBranch.cpp TCordferRawBranch.cpp TCordferMapBranch.cpp TCordferCalibBranch.cpp diff --git a/src/CalibParamReader.cpp b/src/CalibParamReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e074b9698f52dee2cf5a50de45d79999453e47b --- /dev/null +++ b/src/CalibParamReader.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include + +#include + +#include "CalibParamReader.hh" + +using namespace std; + + +void CalibParamReader::ReadCalibration(){ + if(detector_name == "ppac"){ + cout << file_name << endl; + }else{ + ifstream fin(file_name.Data()); + string buf; + + Int_t flag = 0; + while(getline(fin, buf)){ + if(buf[0]=='#' || buf[0]=='c' || buf == ""){ continue; } + if(flag == 0){ + dim = stoi(buf); + flag++; + continue; + } + + if((buf.find(';') != buf.rfind(';')) || buf.find(';') == string::npos){ + cerr << "ERROR: calibration file is not correct" << endl; + exit(0); + } + string name = buf.substr(buf.find(';')+1); + if(name[0] == ' '){ name.erase(0, 1); } + if(name[name.length()-1] == ' '){ name.pop_back(); } + replace(name.begin(), name.end(), ' ', '_'); + replace(name.begin(), name.end(), '/', '_'); + replace(name.begin(), name.end(), '-', '_'); + + branch_name.push_back(name); + + vector calib; + Int_t check_dim = 0; + string tmp = buf.substr(0, buf.find(';')); + stringstream ss{tmp}; + string val; + while(getline(ss, val, ',')){ + while(val[0] == ' '){ val.erase(0, 1); } + while(val[val.length()-1] == ' '){ val.pop_back(); } + double d_val = stod(val); + calib.push_back(d_val); + check_dim++; + } + if(dim != check_dim-1){ + cerr << "ERROR: dimention miss in parameter file" << endl; + exit(0); + } + parameters.push_back(calib); + } + fin.close(); + } +} + + +void CalibParamReader::ReadMUXposCalib(TString pos_file_name){ + ifstream fin(pos_file_name.Data()); + string buf; + + while(getline(fin, buf)){ + if(buf[0]=='#' || buf[0]=='c' || buf == ""){ continue; } + vector mpos_peak; + string pos_array = buf.substr(0, buf.find(';')); + stringstream ss{pos_array}; + string val; + while(getline(ss, val, ',')){ + if(val == "" || val == " "){ continue; } + while(val[0] == ' '){ val.erase(0, 1); } + while(val[val.length()-1] == ' '){ val.pop_back(); } + double d_val = stod(val); + mpos_peak.push_back(d_val); + } + if(mpos_peak.size() != 16){ + cerr << "ERROR: MUX position calibration file is not correct" << endl; + exit(0); + } + vector mpos_tmp; + mpos_tmp.push_back(mpos_peak[0] - (mpos_peak[1]-mpos_peak[0])/2.0); + for(Int_t i=0; i<15; i++){ mpos_tmp.push_back((mpos_peak[i]+mpos_peak[i+1])/2.0); } + mpos_tmp.push_back(mpos_peak[15] + (mpos_peak[15]-mpos_peak[14])/2.0); + + position_prms.push_back(mpos_tmp); + if(mpos_tmp.size() != 17){ + cerr << "ERROR: MUX position calibration file is not correct" << endl; + exit(0); + } + } + fin.close(); +} diff --git a/src/CalibrationManager.cpp b/src/CalibrationManager.cpp index 604870a7bd95149b6f3328d97c5991ba54cf64ed..f08437978c5dd9f57fda6754eb7825f69dfc16e3 100644 --- a/src/CalibrationManager.cpp +++ b/src/CalibrationManager.cpp @@ -1,63 +1,17 @@ #include -#include -#include -#include #include - -#include +#include #include "CalibrationManager.hh" using namespace std; -void CalibrationManager::ReadCalibration(){ - if(detector_name == "ppac"){ - cout << file_name << endl; - }else{ - ifstream fin(file_name.Data()); - string buf; - - Int_t flag = 0; - while(getline(fin, buf)){ - if(buf[0]=='#' || buf[0]=='c' || buf == ""){ continue; } - if(flag == 0){ - dim = stoi(buf); - flag++; - continue; - } - - if((buf.find(';') != buf.rfind(';')) || buf.find(';') == string::npos){ - cerr << "ERROR: calibration file is not correct" << endl; - exit(0); - } - string name = buf.substr(buf.find(';')+1); - if(name[0] == ' '){ name.erase(0, 1); } - if(name[name.length()-1] == ' '){ name.pop_back(); } - replace(name.begin(), name.end(), ' ', '_'); - replace(name.begin(), name.end(), '/', '_'); - replace(name.begin(), name.end(), '-', '_'); - - branch_name.push_back(name); - - vector calib; - Int_t check_dim = 0; - string tmp = buf.substr(0, buf.find(';')); - stringstream ss{tmp}; - string val; - while(getline(ss, val, ',')){ - while(val[0] == ' '){ val.erase(0, 1); } - while(val[val.length()-1] == ' '){ val.pop_back(); } - double d_val = stod(val); - calib.push_back(d_val); - check_dim++; - } - if(dim != check_dim-1){ - cerr << "ERROR: dimention miss in parameter file" << endl; - exit(0); - } - parameters.push_back(calib); - } - fin.close(); +Double_t GetCalibValue(Int_t val, vector params){ + Double_t tmp = 0.0; + for(Int_t i=0; i -#include - -#include -#include - -#include - -using namespace std; - - -void TCordferBranch::CopyMapInfo(vector seg, vector ch){ - copy(seg.begin(), seg.end(), back_inserter(segment_id)); - copy(ch.begin(), ch.end(), back_inserter(channel)); -} - -void TCordferBranch::CopyCalibInfo(Int_t dim, vector param){ - calib_dim = dim; - copy(param.begin(), param.end(), back_inserter(calib_param)); - if(calib_dim != calib_param.size()-1){ - cerr << "ERROR: calibration dimention is wrong" << endl; - exit(0); - } -} - diff --git a/src/TCordferBranchManager.cpp b/src/TCordferBranchManager.cpp index a720a31635bd61207f5ad9548600278f31aaf160..6a2d0c278e720043c855e6da6f8f3de756f0e533 100644 --- a/src/TCordferBranchManager.cpp +++ b/src/TCordferBranchManager.cpp @@ -16,6 +16,7 @@ #include #include "TCordferBranchManager.hh" +#include "CalibrationManager.hh" using namespace std; @@ -30,7 +31,7 @@ void TCordferBranchManager::Readyaml(TString yamlfile){ } -void TCordferBranchManager::CreateTree(){ +void TCordferBranchManager::CreateRawTree(){ TString rawname = recipe["raw_tree"]["name"].as(); TString rawdesc = recipe["raw_tree"]["description"].as(); @@ -54,7 +55,7 @@ void TCordferBranchManager::CreateCalibTree(){ } -void TCordferBranchManager::CreateBranch(){ +void TCordferBranchManager::CreateRawBranch(){ YAML::Node setup = recipe["setup"].as(); for(Int_t i=0; i(); @@ -149,12 +150,9 @@ void TCordferBranchManager::CreateCalibBranch(){ continue; } - CalibrationManager *cfile = new CalibrationManager(det_name, cname[j]); + CalibParamReader *cfile = new CalibParamReader(det_name, cname[j]); for(Int_t k=0; kbranch_name.size(); k++){ TString bname = cfile->branch_name[k]; - //////////////// - //cout << bname << endl; - //////////////// TCordferCalibBranch *calib_branch = new TCordferCalibBranch(bname); calib_branch->CopyCalibInfo(cfile->dim, cfile->parameters[k]); @@ -179,45 +177,12 @@ void TCordferBranchManager::CreateCalibBranch(){ cerr << " mssd calibration requires " << pos_name.Data() << " !" << endl; exit(0); } - ReadMUXposCalib(pos_name); - } - } -} - -void TCordferBranchManager::ReadMUXposCalib(TString filename){ - ifstream fin(filename.Data()); - string buf; - - while(getline(fin, buf)){ - if(buf[0]=='#' || buf[0]=='c' || buf == ""){ continue; } - vector mpos_peak; - string pos_array = buf.substr(0, buf.find(';')); - stringstream ss{pos_array}; - string val; - while(getline(ss, val, ',')){ - if(val == "" || val == " "){ continue; } - while(val[0] == ' '){ val.erase(0, 1); } - while(val[val.length()-1] == ' '){ val.pop_back(); } - double d_val = stod(val); - mpos_peak.push_back(d_val); - } - if(mpos_peak.size() != 16){ - cerr << "ERROR: MUX position calibration file is not correct" << endl; - exit(0); - } - vector mpos_tmp; - mpos_tmp.push_back(mpos_peak[0] - (mpos_peak[1]-mpos_peak[0])/2.0); - for(Int_t i=0; i<15; i++){ mpos_tmp.push_back((mpos_peak[i]+mpos_peak[i+1])/2.0); } - mpos_tmp.push_back(mpos_peak[15] + (mpos_peak[15]-mpos_peak[14])/2.0); - - mpos.push_back(mpos_tmp); - if(mpos_tmp.size() != 17){ - cerr << "ERROR: MUX position calibration file is not correct" << endl; - exit(0); + CalibParamReader *cfile = new CalibParamReader(); + cfile->ReadMUXposCalib(pos_name); + mpos = cfile->position_prms; } } - fin.close(); } @@ -279,32 +244,38 @@ void TCordferBranchManager::CreateCalibMapping(){ else if(cbranch_name.find("mssd") != string::npos && cbranch_name.substr(0, 2) != "t_"){ mssd_tune++; if(mssd_tune%16 == 1){ + Int_t mux_id = mssd_tune/16; + cbranch[i]->mpos1_prm = mpos[2*mux_id]; + cbranch[i]->mpos2_prm = mpos[2*mux_id + 1]; + + Int_t seg0, seg1, seg2, seg3; + for(Int_t j=0; jGetBranchName().Data()); if(cbranch_name.find(mbranch_name) != string::npos){ - Int_t ene0_seg = mbranch[j]->segment_id[0]; - Int_t ene0_ch = mbranch[j]->channel[0]; - cmapping[ene0_seg*1000 + ene0_ch] = i; - muxmapping[ene0_seg*1000 + ene0_ch] = ((16 + mssd_tune)/16)*1000 + 1; - - Int_t ene1_seg = mbranch[j]->segment_id[1]; - Int_t ene1_ch = mbranch[j]->channel[1]; - cmapping[ene1_seg*1000 + ene1_ch] = i; - muxmapping[ene1_seg*1000 + ene1_ch] = ((16 + mssd_tune)/16)*1000 + 2; - - Int_t pos0_seg = mbranch[j]->segment_id[2]; - Int_t pos0_ch = mbranch[j]->channel[2]; - cmapping[pos0_seg*1000 + pos0_ch] = i; - muxmapping[pos0_seg*1000 + pos0_ch] = ((16 + mssd_tune)/16)*1000 + 3; - - Int_t pos1_seg = mbranch[j]->segment_id[3]; - Int_t pos1_ch = mbranch[j]->channel[3]; - cmapping[pos1_seg*1000 + pos1_ch] = i; - muxmapping[pos1_seg*1000 + pos1_ch] = ((16 + mssd_tune)/16)*1000 + 4; + seg0 = mbranch[j]->segment_id[0]*1000 + mbranch[j]->channel[0]; + cmapping[seg0] = i; + muxmapping[seg0] = 1; + + seg1 = mbranch[j]->segment_id[1]*1000 + mbranch[j]->channel[1]; + cmapping[seg1] = i; + muxmapping[seg1] = 2; + + seg2 = mbranch[j]->segment_id[2]*1000 + mbranch[j]->channel[2]; + cmapping[seg2] = i; + muxmapping[seg2] = 3; + + seg3 = mbranch[j]->segment_id[3]*1000 + mbranch[j]->channel[3]; + cmapping[seg2] = i; + muxmapping[seg2] = 4; } } + //cout << i << " " << cbranch_name << " " << seg0 << ", " << seg1 << ", " << seg2 << ", " << seg3 << endl; continue; - }else{ continue; } + }else{ + //cout << i << " " << cbranch_name << endl; + continue; + } }else if(cbranch_name.find("mssd") != string::npos && cbranch_name.substr(0, 2) == "t_"){ for(Int_t j=0; jGetBranchName().Data()); @@ -342,11 +313,23 @@ void TCordferBranchManager::CreateCalibMapping(){ Int_t seg = cbranch[i]->geo*1000 + cbranch[i]->ch; Int_t index = i; cmapping[seg] = index; + + //cout << i << " " << cbranch_name << " " << seg << endl; } } void TCordferBranchManager::GiveRawValue(Int_t geo, Int_t ch, Int_t val){ + //if not register segment + auto itr = mapping.find(geo); + if(itr == mapping.end()){ + if(rmapflag == false){ + cout << "WARNING: rmapping is not completed" << endl; + } + rmapflag=true; + return; + } + Int_t index = mapping[geo]; if(branch[index]->GetBranchName() == "mhtdc"){ @@ -361,6 +344,17 @@ void TCordferBranchManager::GiveRawValue(Int_t geo, Int_t ch, Int_t val){ void TCordferBranchManager::GiveMapValue(Int_t geo, Int_t ch, Int_t val){ Int_t seg = geo*1000 + ch; + + //if not register segment + auto itr = mmapping.find(seg); + if(itr == mmapping.end()){ + if(mapflag == false){ + cout << "WARNING: mapping is not completed" << endl; + } + mapflag=true; + return; + } + Int_t index = mmapping[seg]; Int_t j = index % 1000; Int_t i = (index - j)/1000; @@ -371,51 +365,67 @@ void TCordferBranchManager::GiveMapValue(Int_t geo, Int_t ch, Int_t val){ void TCordferBranchManager::GiveCalibValue(Int_t geo, Int_t ch, Int_t val){ Int_t seg = geo*1000 + ch; + + //if not register segment + auto itr = cmapping.find(seg); + if(itr == cmapping.end()){ + if(cmapflag == false){ + cout << "WARNING: cmapping is not completed" << endl; + } + cmapflag=true; + return; + } + Int_t index = cmapping[seg]; string cbranch_name = string(cbranch[index]->GetBranchName().Data()); - //for mssd - if(cbranch_name.find("mssd") != string::npos){ - Int_t mux_index = muxmapping[seg]; - Int_t mux_sig = mux_index % 1000; - Int_t mux_id = (mux_index - mux_sig)/1000; + //for mssd energy calibration + if(cbranch_name.find("mssd") != string::npos && cbranch_name.substr(0, 2) != "t_"){ + Int_t mux_sig = muxmapping[seg]; if(mux_sig==1 && cbranch[index]->mux_pos1==false){ - cbranch[index]->geo_tmp1 = geo; - cbranch[index]->ch_tmp1 = ch; - cbranch[index]->val_tmp1 = val; + cbranch[index]->SetGeometrytmp1(geo, ch, val); cbranch[index]->mux_status1=true; + }else if(mux_sig==1 && cbranch[index]->mux_pos1==true){ - // + if(cbranch[index]->mux1_junk == true){ return; } + Int_t add_ch = cbranch[index]->mux_ch1; + cbranch[index + add_ch]->cbra_val = GetCalibValue(val, cbranch[index+add_ch]->calib_param); + }else if(mux_sig==2 && cbranch[index]->mux_pos2==false){ - cbranch[index]->geo_tmp2 = geo; - cbranch[index]->ch_tmp2 = ch; - cbranch[index]->val_tmp2 = val; + cbranch[index]->SetGeometrytmp2(geo, ch, val); cbranch[index]->mux_status2=true; + }else if(mux_sig==2 && cbranch[index]->mux_pos2==true){ - // + if(cbranch[index]->mux2_junk == true){ return; } + Int_t add_ch = cbranch[index]->mux_ch2; + cbranch[index + add_ch]->cbra_val = GetCalibValue(val, cbranch[index+add_ch]->calib_param); + }else if(mux_sig==3){ cbranch[index]->mux_pos1 = true; - //for(Int_t i=0; i<16; i++){ - // - //} + for(Int_t i=0; i<16; i++){ + if(cbranch[index]->mpos1_prm[i] < val && cbranch[index]->mpos1_prm[i+1] > val){ + cbranch[index]->mux_ch1 = i; + } + } + if(cbranch[index]->mux_ch1 < 0){ cbranch[index]->mux1_junk = true; } + }else if(mux_sig==4){ cbranch[index]->mux_pos2 = true; - // + for(Int_t i=0; i<16; i++){ + if(cbranch[index]->mpos2_prm[i] < val && cbranch[index]->mpos2_prm[i+1] > val){ + cbranch[index]->mux_ch2 = i; + } + } + if(cbranch[index]->mux_ch2 < 0){ cbranch[index]->mux2_junk = true; } } //for others }else{ - Double_t tmp = 0.0; if(cbranch[index]->adc){ - for(Int_t i=0; icalib_param.size(); i++){ - tmp += cbranch[index]->calib_param[i]*pow(val, i); - } - cbranch[index]->cbra_val = tmp; + cbranch[index]->cbra_val = GetCalibValue(val, cbranch[index]->calib_param); }else{ - for(Int_t i=0; icalib_param.size(); i++){ - tmp += cbranch[index]->calib_param[i]*pow(val, i); - } - cbranch[index]->cbra_tval[cbranch[index]->count_hit] = tmp; + cbranch[index]->cbra_tval[cbranch[index]->count_hit] = GetCalibValue(val, cbranch[index]->calib_param); + cbranch[index]->count_hit++; } } } @@ -465,6 +475,8 @@ void TCordferBranchManager::ClearCalibAll(){ cbranch[i]->mux_status2=false; cbranch[i]->mux_pos1=false; cbranch[i]->mux_pos2=false; + cbranch[i]->mux1_junk=false; + cbranch[i]->mux2_junk=false; cbranch[i]->mux_ch1=-99; cbranch[i]->mux_ch2=-99; cbranch[i]->geo_tmp1=-99; diff --git a/src/TCordferCalibBranch.cpp b/src/TCordferCalibBranch.cpp index 383dcbf6187029d54e0022fc99d0514b694381da..649b641089ceacf1fa47e2f83392f4e4a92b5e98 100644 --- a/src/TCordferCalibBranch.cpp +++ b/src/TCordferCalibBranch.cpp @@ -2,18 +2,12 @@ #include #include -#include #include "TCordferCalibBranch.hh" using namespace std; -void TCordferCalibBranch::CopyMapInfo(vector seg, vector ch){ - copy(seg.begin(), seg.end(), back_inserter(segment_id)); - copy(ch.begin(), ch.end(), back_inserter(channel)); -} - void TCordferCalibBranch::CopyCalibInfo(Int_t dim, vector param){ calib_dim = dim; copy(param.begin(), param.end(), back_inserter(calib_param)); diff --git a/src/TCordferMapBranch.cpp b/src/TCordferMapBranch.cpp index a2b8af227200c224f15aa4beab4140434776310d..1e8772ab65501a3816be194b1066cb0352f78352 100644 --- a/src/TCordferMapBranch.cpp +++ b/src/TCordferMapBranch.cpp @@ -2,7 +2,6 @@ #include #include -#include #include "TCordferMapBranch.hh" @@ -14,12 +13,3 @@ void TCordferMapBranch::CopyMapInfo(vector seg, vector ch){ copy(ch.begin(), ch.end(), back_inserter(channel)); } -void TCordferMapBranch::CopyCalibInfo(Int_t dim, vector param){ - calib_dim = dim; - copy(param.begin(), param.end(), back_inserter(calib_param)); - if(calib_dim != calib_param.size()-1){ - cerr << "ERROR: calibration dimention is wrong" << endl; - exit(0); - } -} - diff --git a/src/TCordferRawBranch.cpp b/src/TCordferRawBranch.cpp index 412a77c0b2f666172a25febedfb023f8ddf87dbb..3547555ceeaa97dc358726d4d7344c8a7075a21e 100644 --- a/src/TCordferRawBranch.cpp +++ b/src/TCordferRawBranch.cpp @@ -2,24 +2,23 @@ #include #include -#include #include "TCordferRawBranch.hh" using namespace std; -void TCordferRawBranch::CopyMapInfo(vector seg, vector ch){ - copy(seg.begin(), seg.end(), back_inserter(segment_id)); - copy(ch.begin(), ch.end(), back_inserter(channel)); +void TCordferRawBranch::TwoDimMemorySet(){ + mhtdc_val = new Int_t*[size]; + for(Int_t i=0; i param){ - calib_dim = dim; - copy(param.begin(), param.end(), back_inserter(calib_param)); - if(calib_dim != calib_param.size()-1){ - cerr << "ERROR: calibration dimention is wrong" << endl; - exit(0); +void TCordferRawBranch::FreeTwoDimMemory(){ + for(Int_t i=0; i