-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linear regression sums are collected inside PadmeReco and are exported to a json file. This behaveour can be enabled with `GenADCCellCalib` keyword in PadmeReconstruction.cfg under `[RUNNINGMODE]` group. The produced sums need to be interpreted by utils/v1742-offline-cell-calib-linear-regression.py -- poly5 method is slowest but provides best results. On a second iteration, the calibration data can be provided to the reconstruction via `ADCCellCalibData` keyword again under `[RUNNINGMODE]` group Fixes #238
- Loading branch information
1 parent
9c0e826
commit 123b533
Showing
16 changed files
with
578 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef __PADME_RECO__ADC_CELL_CALIB_DATA_H__ | ||
#define __PADME_RECO__ADC_CELL_CALIB_DATA_H__ 0 | ||
|
||
#include"TADCBoard.hh" | ||
#include<map> | ||
#include<string> | ||
|
||
class ADCCellCalibData{ | ||
public: | ||
ADCCellCalibData(const std::string &caldatjson); | ||
void CalibrateADC(TADCBoard* raw_board); | ||
|
||
private: | ||
ADCCellCalibData(); | ||
std::map<unsigned int, double[32][1024][6]> fData; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef __PADME_RECO__ADC_CELL_CALIB_HISTOGRAMS_H__ | ||
#define __PADME_RECO__ADC_CELL_CALIB_HISTOGRAMS_H__ 0 | ||
|
||
#include"TADCBoard.hh" | ||
|
||
#include<TH2S.h> | ||
#include<TFile.h> | ||
|
||
#include<string> | ||
|
||
class ADCCellCalibHistograms{ | ||
public: | ||
struct hists_t{ | ||
TH2S* nocal_cell; | ||
TH2S* calib_cell; | ||
TH2S* nocal_time; | ||
TH2S* calib_time; | ||
}; | ||
void FillHistograms(TADCBoard* raw_board, std::string det_name, bool is_calibrated); | ||
void WriteHistograms(TFile*); | ||
ADCCellCalibHistograms(const std::string& dirname, unsigned ylow=3300, unsigned yhigh=4100): | ||
fYLow(ylow), | ||
fYHigh(yhigh), | ||
fDirName(dirname) | ||
{} | ||
private: | ||
ADCCellCalibHistograms(); | ||
unsigned fYLow, fYHigh; | ||
std::string fDirName; | ||
std::map<int, hists_t[32]> fHists; | ||
void CreateHisos(TADCBoard* raw_board, const std::string &det_name); | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef __PADME_RECO__ADC_CELL_CALIB_SUMS_H__ | ||
#define __PADME_RECO__ADC_CELL_CALIB_SUMS_H__ 0 | ||
|
||
#include "TRawEvent.hh" | ||
|
||
#include<stdint.h> | ||
#include<string> | ||
#include<map> | ||
#include<sstream> | ||
|
||
class ADCCellCalibSums{ | ||
private: | ||
typedef unsigned __int128 uint128_t; | ||
struct capacitor_sum_t{ | ||
capacitor_sum_t(): | ||
n (0), | ||
t (0), | ||
t2 (0), | ||
t3 (0), | ||
t4 (0), | ||
t5 (0), | ||
t6 (0), | ||
t7 (0), | ||
t8 (0), | ||
t9 (0), | ||
t10 (0), | ||
Ct (0), | ||
tCt (0), | ||
t2Ct (0), | ||
t3Ct (0), | ||
t4Ct (0), | ||
t5Ct (0) | ||
{} | ||
// An overflow can occur when the number of | ||
// processed events is bigger than 65535 | ||
uint16_t n ; // 1<<16 65535 | ||
uint32_t t ; // 1<<32/1024**1 4194304 | ||
uint64_t t2 ; | ||
uint64_t t3 ; | ||
uint64_t t4 ; // 1<<64/1024**4 16777216 | ||
uint128_t t5 ; | ||
uint128_t t6 ; | ||
uint128_t t7 ; | ||
uint128_t t8 ; | ||
uint128_t t9 ; | ||
uint128_t t10 ; // 1<<128/1024**10 268435456 | ||
uint64_t Ct ; | ||
uint64_t tCt ; | ||
uint64_t t2Ct; | ||
uint64_t t3Ct; // 1<<64/(4096*1024**3) 4194304 | ||
uint128_t t4Ct; | ||
uint128_t t5Ct; | ||
}; | ||
public: | ||
ADCCellCalibSums(const std::string& sums_out_file_name): | ||
fNEvtsProcessed(0) { | ||
fSumsOutFileName = sums_out_file_name; | ||
} | ||
void Process(TRawEvent* ev); | ||
void WriteFile(); | ||
private: | ||
ADCCellCalibSums(); | ||
std::string fSumsOutFileName; | ||
std::map<int, capacitor_sum_t[32][1024]> fAllBoardSums; | ||
unsigned fNEvtsProcessed; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include"ADCCellCalibData.hh" | ||
#include<json/json.h> | ||
#include<fstream> | ||
|
||
ADCCellCalibData::ADCCellCalibData(const std::string &caldatjson){ | ||
if(caldatjson.size()==0){ | ||
return; | ||
} | ||
Json::Value caldat; | ||
std::ifstream caldat_file(caldatjson.c_str(), std::ifstream::binary); | ||
caldat_file >> caldat; | ||
for(auto it=caldat.begin();it!=caldat.end();it++){ | ||
for(int ch=0;ch<32;++ch){ | ||
for(int cell=0;cell<1024;++cell){ | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][0]= | ||
caldat[it.key().asString()][ch][cell][0].asDouble(); | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][1]= | ||
caldat[it.key().asString()][ch][cell][1].asDouble(); | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][2]= | ||
caldat[it.key().asString()][ch][cell][2].asDouble(); | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][3]= | ||
caldat[it.key().asString()][ch][cell][3].asDouble(); | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][4]= | ||
caldat[it.key().asString()][ch][cell][4].asDouble(); | ||
fData[std::atoi(it.key().asString().c_str())][ch][cell][5]= | ||
caldat[it.key().asString()][ch][cell][5].asDouble(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ADCCellCalibData::CalibrateADC(TADCBoard* raw_board){ | ||
int n_chans = raw_board->GetNADCChannels(); | ||
for(int chan_i=0; chan_i<n_chans; chan_i++){ | ||
TADCChannel* raw_chan = raw_board->ADCChannel(chan_i); | ||
int start_cell = raw_board->ADCTrigger(chan_i/8)->GetStartIndexCell(); | ||
double (*chan_caldat)[6] = fData[raw_board->GetBoardSN()][chan_i]; | ||
auto raw_samp = raw_chan->GetSamplesArray(); | ||
int n_samp = raw_chan->GetNSamples(); | ||
for(int t=0; t<n_samp; t++){ | ||
long long int tPower = 1; | ||
for(int power=0; power<6; power++){ | ||
raw_samp[t] -= chan_caldat[(t+start_cell)%1024][power]*tPower; | ||
tPower*=t; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include"ADCCellCalibHistograms.hh" | ||
|
||
#include<sstream> | ||
|
||
void ADCCellCalibHistograms::FillHistograms(TADCBoard* raw_board, std::string det_name, bool is_calibrated){ | ||
int board_sn = raw_board->GetBoardSN(); | ||
if(fHists.count(board_sn)==0){ | ||
CreateHisos(raw_board, det_name); | ||
} | ||
for(unsigned chan_i=0; chan_i<raw_board->GetNADCChannels(); chan_i++){ | ||
TADCChannel *raw_chan = raw_board->ADCChannel(chan_i); | ||
hists_t& hist = fHists[board_sn][chan_i]; | ||
int start_index_cell = raw_board->ADCTrigger(chan_i/8)->GetStartIndexCell(); | ||
for(unsigned t=0; t < 1000; t++){ // ignore last 24 samples | ||
const int p = (t+start_index_cell)%raw_chan->GetNSamples(); | ||
const int Ct = raw_chan->GetSample(t); | ||
if(is_calibrated){ | ||
hist.calib_cell->Fill(p, Ct); | ||
hist.calib_time->Fill(t, Ct); | ||
}else{ | ||
hist.nocal_cell->Fill(p, Ct); | ||
hist.nocal_time->Fill(t, Ct); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ADCCellCalibHistograms::CreateHisos(TADCBoard* raw_board, const std::string &det_name){ | ||
int board_sn = raw_board->GetBoardSN(); | ||
for(int chan_i=0; chan_i<32; chan_i++){ | ||
std::stringstream name; | ||
name<<det_name<<"_sn"<<board_sn<<"_b"<<int(raw_board->GetBoardId())<<"_ch"<<chan_i<<"_"; | ||
fHists[board_sn][chan_i].nocal_cell = new TH2S((name.str()+"nocal_cell").c_str(),(name.str()+"nocal_cell;CellID; " ).c_str(),1024,0-.5,1024-.5, fYHigh-fYLow, fYLow-.5,fYHigh-.5); | ||
fHists[board_sn][chan_i].calib_cell = new TH2S((name.str()+"calib_cell").c_str(),(name.str()+"calib_cell;CellID; " ).c_str(),1024,0-.5,1024-.5, fYHigh-fYLow, fYLow-.5,fYHigh-.5); | ||
fHists[board_sn][chan_i].nocal_time = new TH2S((name.str()+"nocal_time").c_str(),(name.str()+"nocal_time;Time[samples]; ").c_str(),1024,0-.5,1024-.5, fYHigh-fYLow, fYLow-.5,fYHigh-.5); | ||
fHists[board_sn][chan_i].calib_time = new TH2S((name.str()+"calib_time").c_str(),(name.str()+"calib_time;Time[samples]; ").c_str(),1024,0-.5,1024-.5, fYHigh-fYLow, fYLow-.5,fYHigh-.5); | ||
} | ||
} | ||
|
||
void ADCCellCalibHistograms::WriteHistograms(TFile*rootfile){ | ||
rootfile->cd("/"); | ||
rootfile->mkdir(fDirName.c_str())->cd(); | ||
for(auto hist_it=fHists.begin(); hist_it!=fHists.end(); hist_it++){ | ||
for(int chan_i=0; chan_i<32; chan_i++){ | ||
hist_it->second[chan_i].nocal_cell->Write(); | ||
hist_it->second[chan_i].calib_cell->Write(); | ||
hist_it->second[chan_i].nocal_time->Write(); | ||
hist_it->second[chan_i].calib_time->Write(); | ||
} | ||
} | ||
} |
Oops, something went wrong.