Files
JFCalibration/sls_detector_calibration/jungfrauCommonFunctions.h

345 lines
9.8 KiB
C

#ifndef JUNGFRAUCOMMONFUNCTIONS_H
#define JUNGFRAUCOMMONFUNCTIONS_H
#include <algorithm>
int chipOfPixel(int i) {
int chip = 0;
if (i/1024 >= 256 && i%1024 >= 0 && i%1024 < 256) {
chip = 1;
} else if (i/1024 >= 256 && i%1024 >= 256 && i%1024 < 512) {
chip = 2;
} else if (i/1024 >= 256 && i%1024 >= 512 && i%1024 < 768) {
chip = 3;
} else if (i/1024 >= 256 && i%1024 >= 768 && i%1024 < 1024) {
chip = 4;
} else if (i/1024 < 256 && i%1024 >= 0 && i%1024 < 256) {
chip = 5;
} else if (i/1024 < 256 && i%1024 >= 256 && i%1024 < 512) {
chip = 6;
} else if (i/1024 < 256 && i%1024 >= 512 && i%1024 < 768) {
chip = 7;
} else if (i/1024 < 256 && i%1024 >= 768 && i%1024 < 1024) {
chip = 8;
} else {
cout << "problem" << endl;
}
return chip;
}
int supercolumnOfPixel(int i) {
int sc = ((i-((i/256)*256))/64) + 1;
return sc;
}
int ADCOfPixel(int i) {
int adc = -1;
if (i%1024 < 256) {
adc = 0;
} else if (i%1024 < 512) {
adc = 1;
} else if (i%1024 < 768) {
adc = 2;
} else {
adc = 3;
}
return adc;
}
void LoadPaletteFalse() {
// jet
Double_t stops[5] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
Double_t red[5] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
Double_t green[5] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
Double_t blue[5] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
TColor::CreateGradientColorTable(5, stops, red, green, blue, 255, 1.0);
gStyle->SetNumberContours(255);
}
void UsePaletteViridis() {
// viridis
Double_t stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
Double_t red[9] = {26./255., 51./255., 43./255., 33./255., 28./255., 35./255., 74./255., 144./255., 246./255.};
Double_t green[9] = {9./255., 24./255., 55./255., 87./255., 118./255., 150./255., 180./255., 200./255., 222./255.};
Double_t blue[9] = {30./255., 96./255., 112./255., 114./255., 112./255., 101./255., 72./255., 35./255., 0./255.};
TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0);
gStyle->SetNumberContours(255);
}
void UsePaletteDBR() {
// dark body radiator
Double_t stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
Double_t red[9] = {0./255., 45./255., 99./255., 156./255., 212./255., 230./255., 237./255., 234./255., 242./255.};
Double_t green[9] = {0./255., 0./255., 0./255., 45./255., 101./255., 168./255., 238./255., 238./255., 243./255.};
Double_t blue[9] = {0./255., 1./255., 1./255., 3./255., 9./255., 8./255., 11./255., 95./255., 230./255.};
TColor::CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0);
gStyle->SetNumberContours(255);
}
void jungfrauStyle()
{
gROOT->SetStyle("Plain"); /*Default white background for all plots*/
/*set bkg color of all to white*/
gStyle->SetCanvasColor(kWhite);
gStyle->SetFrameFillColor(kWhite);
gStyle->SetStatColor(kWhite);
gStyle->SetPadColor(kWhite);
gStyle->SetFillColor(10);
gStyle->SetTitleFillColor(kWhite);
/* SetPaperSize wants width & height in cm: A4 is 20,26 & US is 20,24*/
gStyle->SetPaperSize(20, 26);
/* No yellow border around histogram*/
gStyle->SetDrawBorder(0);
/* remove border of canvas*/
gStyle->SetCanvasBorderMode(0);
/* remove border of pads*/
gStyle->SetPadBorderMode(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetLegendBorderSize(0);
/* default text size*/
gStyle->SetTextSize(0.05);
gStyle->SetTitleSize(0.07,"xyz");
gStyle->SetLabelSize(0.06,"xyz");
/* title offset: distance between given text and axis, here x,y,z*/
gStyle->SetLabelOffset(0.015,"xyz");
gStyle->SetTitleOffset(1.1,"yz");
gStyle->SetTitleOffset(1.0,"x");
/* Use visible font for all text*/
int font = 42;
gStyle->SetTitleFont(font);
gStyle->SetTitleFontSize(0.06);
gStyle->SetStatFont(font);
gStyle->SetStatFontSize(0.07);
gStyle->SetTextFont(font);
gStyle->SetLabelFont(font,"xyz");
gStyle->SetTitleFont(font,"xyz");
gStyle->SetTitleBorderSize(0);
gStyle->SetStatBorderSize(1);
gStyle->SetLegendFont(font);
/* big marker points*/
gStyle->SetMarkerStyle(1);
gStyle->SetLineWidth(2);
gStyle->SetMarkerSize(1.2);
/*set palette in 2d histogram to nice and colorful one*/
gStyle->SetPalette(1,0);
/*No title for histograms*/
gStyle->SetOptTitle(0);
/* show the errors on the stat box */
gStyle->SetOptStat(0);
/* show errors on fitted parameters*/
gStyle->SetOptFit(0);
/* number of decimals used for errors*/
gStyle->SetEndErrorSize(5);
/* set line width to 2 by default so that histograms are visible when printed small
idea: emphasize the data, not the frame around*/
gStyle->SetHistLineWidth(2);
gStyle->SetFrameLineWidth(2);
gStyle->SetFuncWidth(2);
gStyle->SetHistLineColor(kBlack);
gStyle->SetFuncColor(kRed);
gStyle->SetLabelColor(kBlack,"xyz");
//set the margins
gStyle->SetPadBottomMargin(0.2);
gStyle->SetPadTopMargin(0.05);
gStyle->SetPadRightMargin(0.05);
gStyle->SetPadLeftMargin(0.2);
//set the number of divisions to show
gStyle->SetNdivisions(506, "xy");
//turn off xy grids
gStyle->SetPadGridX(0);
gStyle->SetPadGridY(0);
//set the tick mark style
gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
gStyle->SetCanvasDefW(800);
gStyle->SetCanvasDefH(700);
LoadPaletteFalse();
gROOT->ForceStyle();
}
// types of pixels
bool isQuad(int i) {
if ( (i/NC == 255 || i/NC == 256) && (i%NC == 255 || i%NC == 256 || i%NC == 511 || i%NC == 512 || i%NC == 767 || i%NC == 768) ) {
return true;
} else {
return false;
}
}
bool isDouble(int i) {
if(i/NC == 255 || i/NC == 256 || i%NC == 255 || i%NC == 256 || i%NC == 511 || i%NC == 512 || i%NC == 767 || i%NC == 768) {
if (not isQuad(i)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
bool isNextToDouble(int i) {
if(i/NC == 254 || i/NC == 257 || i%NC == 254 || i%NC == 257 || i%NC == 510 || i%NC == 513 || i%NC == 766 || i%NC == 769) {
if (not isDouble(i) && not isQuad(i)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
bool isEdge(int i) {
if (i%NC == 0 || i%NC == 1023 || i/NC == 0 || i/NC == 511) {
if (not isDouble(i) && not isNextToDouble(i)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
bool isInnerEdge(int i) {
if (i%NC == 1 || i%NC == 1022 || i/NC == 1 || i/NC == 510) {
if (not isEdge(i) && not isDouble(i) && not isNextToDouble(i)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
bool isBulk(int i) {
if (not isEdge(i) && not isInnerEdge(i) && not isDouble(i) && not isQuad(i) && not isNextToDouble(i)) {
return true;
} else {
return false;
}
}
double highestPointBeforeSwitching(const vector<double> &lower_filter, const vector<double> &higher_filter) {
double highest_point_before_switching;
if (higher_filter.size() > 0) {
// find the highest value in lower_filter that is lower than all entries in higher_filter
highest_point_before_switching = *min_element(lower_filter.begin(),lower_filter.end())-1;
double lowest_entry_in_higher_filter = *min_element(higher_filter.begin(),higher_filter.end());
for(vector<double>::const_iterator it = lower_filter.begin(); it != lower_filter.end(); ++it) {
if (*it < lowest_entry_in_higher_filter) {
if (*it > highest_point_before_switching) {
highest_point_before_switching = *it;
}
}
}
} else {
highest_point_before_switching = *max_element(lower_filter.begin(),lower_filter.end());
}
return highest_point_before_switching;
}
double lowestPointAfterSwitching(const vector<double> &higher_filter, const vector<double> &lower_filter) {
double lowest_point_after_switching;
if (lower_filter.size() > 0) {
// find the lowest value in higher_filter that is higher than all entries in lower_filter
lowest_point_after_switching = *max_element(higher_filter.begin(),higher_filter.end())+1;
double highest_entry_in_lower_filter = *max_element(lower_filter.begin(),lower_filter.end());
for(vector<double>::const_iterator it = higher_filter.begin(); it != higher_filter.end(); ++it) {
if (*it > highest_entry_in_lower_filter) {
if (*it < lowest_point_after_switching) {
lowest_point_after_switching = *it;
}
}
}
} else {
lowest_point_after_switching = *min_element(higher_filter.begin(),higher_filter.end());
}
return lowest_point_after_switching;
}
double highestPointBeforeSaturation(const vector<double> &filter, const vector<double> &adc_g2) {
// first look if saturation ever occurs
bool saturation = false;
for(vector<double>::const_iterator it_adc = adc_g2.begin(); it_adc != adc_g2.end(); ++it_adc) {
if (*it_adc == 0) {
saturation = true;
}
}
if (saturation == false) {
double highest_point_before_saturation = *max_element(filter.begin(),filter.end());
return highest_point_before_saturation;
} else {
// find the lowest filter value which saturates
double lowest_point_which_saturates = *max_element(filter.begin(),filter.end());
vector<double>::const_iterator it_adc = adc_g2.begin();
for(vector<double>::const_iterator it_filter = filter.begin(); it_filter != filter.end(); ++it_filter) {
if (*it_adc == 0) {
if (*it_filter < lowest_point_which_saturates) {
lowest_point_which_saturates = *it_filter;
}
}
++it_adc;
}
// find the highest filter value which is below saturation
double highest_point_before_saturation = *min_element(filter.begin(),filter.end());
for(vector<double>::const_iterator it_filter = filter.begin(); it_filter != filter.end(); ++it_filter) {
if (*it_filter < lowest_point_which_saturates) {
if (*it_filter > highest_point_before_saturation) {
highest_point_before_saturation = *it_filter;
}
}
}
return highest_point_before_saturation;
}
}
#endif /* JUNGFRAUCOMMONFUNCTIONS_H */