Files
JFCalibration/sls_detector_calibration/jungfrauPedestal.C

218 lines
5.1 KiB
C

#include "MovingStat.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TH2F.h"
class jungfrauPedestal {
private:
MovingStat stat [NCH];
public:
TH1F* pedestals1d;
TH2F* pedestals2d;
TH1F* pedestalvars1d;
TH2F* pedestalvars2d;
TH2F* pedestalsvars;
jungfrauPedestal() {
cout << "jungfrauPedestal constructed" << endl;
}
bool addFrameToPedestalCalculation(uint16_t *imagedata) {
for (int i = 0; i<NCH; i++) {
stat[i].Calc(double(imagedata[i]&0x3fff));
}
return true;
}
bool addG0FrameToPedestalCalculation(uint16_t *imagedata) {
for (int i = 0; i<NCH; i++) {
if (((imagedata[i]&0xc000) >> 14) == 0) {
stat[i].Calc(double(imagedata[i]&0x3fff));
}
}
return true;
}
bool addG0PixelToPedestalCalculation(int i, double adc_double) {
stat[i].Calc(adc_double);
return true;
}
bool addG1FrameToPedestalCalculation(uint16_t *imagedata) {
for (int i = 0; i<NCH; i++) {
//if ((((imagedata[i]&0xc000) >> 14) == 1)) {
if ((((imagedata[i]&0xc000) >> 14) == 1)||(((imagedata[i]&0xc000) >> 14) == 2)) { //to fix FW error during JF11 FW develop. needed for modules 243-379
stat[i].Calc(double(imagedata[i]&0x3fff));
}
}
return true;
}
bool addG2FrameToPedestalCalculation(uint16_t *imagedata) {
for (int i = 0; i<NCH; i++) {
if (((imagedata[i]&0xc000) >> 14) == 3) {
stat[i].Calc(double(imagedata[i]&0x3fff));
}
}
return true;
}
// single threshold
bool addG0FrameToPedestalCalculationWThreshold(uint16_t *imagedata, jungfrauPedestal *pedestalObj, uint16_t threshold) {
for (int i = 0; i<NCH; i++) {
if (((imagedata[i]&0xc000) >> 14) == 0) {
if (fabs((imagedata[i]&0x3fff) - pedestalObj->pedestalOfChannel(i)) < threshold) {
stat[i].Calc(double(imagedata[i]&0x3fff));
}
}
}
return true;
}
// array of thresholds
bool addG0FrameToPedestalCalculationWThreshold(uint16_t *imagedata, jungfrauPedestal *pedestalObj, double *thresholds) {
for (int i = 0; i<NCH; i++) {
if (((imagedata[i]&0xc000) >> 14) == 0) {
if (fabs((imagedata[i]&0x3fff) - pedestalObj->pedestalOfChannel(i)) < thresholds[i]) {
stat[i].Calc(double(imagedata[i]&0x3fff));
}
}
}
return true;
}
double pedestalOfChannel(int ichannel) {
return stat[ichannel].Mean();
}
double semOfChannel(int ichannel) {
return stat[ichannel].StandardDeviation() / sqrt(stat[ichannel].NumDataValues());
}
double rmsOfChannel(int ichannel) {
return stat[ichannel].StandardDeviation();
}
double varianceOfChannel(int ichannel) {
return stat[ichannel].Variance();
}
bool pedestalData(double* pedestals) {
for (int i = 0; i < NCH; i++) {
pedestals[i] = stat[i].Mean();
}
return true;
}
bool pedestalData(uint16_t* pedestals) {
for (int i = 0; i < NCH; i++) {
pedestals[i] = uint16_t(round(stat[i].Mean()));
}
return true;
}
bool pedestalRMSData(double* pedestalRMSs) {
for (int i = 0; i < NCH; i++) {
pedestalRMSs[i] = stat[i].StandardDeviation();
}
return true;
}
int pedestalNFrames() {
return stat[0].GetN();
}
int pedestalUpdates(int ichannel) {
return stat[ichannel].GetNUpdates();
}
void pedestalResetUpdates() {
for (int i=0; i < NCH; i++){
stat[i].ResetUpdates();
}
}
void pedestalClear() {
for (int i=0; i < NCH; i++){
stat[i].Clear();
}
}
bool pedestalSetNFrames(int nframes) {
for (int i=0; i < NCH; i++){
stat[i].SetN(nframes);
}
return true;
}
void savePedestals(uint16_t* pedestals, string fileName) {
ofstream pedefile (fileName.c_str());
if (pedefile.is_open()) {
cout << "saving pedestals" << endl;
for (int i=0; i<NCH; i++){
pedefile << pedestals[i] << " " ;
}
pedefile.close();
} else {
cout << "Unable to open file" << endl;
}
}
void savePedestals(double* pedestals, string fileName) {
ofstream pedefile (fileName.c_str());
if (pedefile.is_open()) {
cout << "saving pedestals" << endl;
for (int i=0; i<NCH; i++){
pedefile << pedestals[i] << " " ;
}
pedefile.close();
} else {
cout << "Unable to open file" << endl;
}
}
bool readPedestals(uint16_t* pedestals, string fileName) {
ifstream pedefile(fileName.c_str());
if (pedefile.is_open()) {
cout << "reading pedestal file" << endl;
for (int i = 0; i < NCH; i++) {
pedefile >> pedestals[i];
}
return true;
} else {
cout << "Unable to open file" << endl;
return false;
}
}
bool readPedestals(double* pedestals, string fileName) {
ifstream pedefile(fileName.c_str());
if (pedefile.is_open()) {
cout << "reading pedestal file" << endl;
for (int i = 0; i < NCH; i++) {
pedefile >> pedestals[i];
}
return true;
} else {
cout << "Unable to open file" << endl;
return false;
}
}
bool setPedestalOfChannel(int ichannel, uint16_t set_pede) {
stat[ichannel].Calc(double(set_pede));
return true;
}
};