6 #include "TGraphErrors.h" 12 for (
int i = 0;
i < 256; ++
i)
17 LogDebug(
"EcalPedOffset") <<
"entering TPedValues ctor ...";
18 for (
int i = 0;
i < 1700; ++
i)
23 LogDebug(
"EcalPedOffset") <<
"entering TPedValues copyctor ...";
28 for (
int crystal = 0; crystal < 1700; ++crystal)
29 for (
int DAC = 0; DAC < 256; ++DAC)
32 for (
int i = 0;
i < 1700; ++
i)
41 if (gainId <= 0 || gainId >= 4) {
42 edm::LogWarning(
"EcalPedOffset") <<
"WARNING : TPedValues : gainId " << gainId <<
" does not exist, entry skipped";
47 if (crystal <= 0 || crystal > 1700) {
48 edm::LogWarning(
"EcalPedOffset") <<
"WARNING : TPedValues : crystal " << crystal
49 <<
" does not exist, entry skipped";
54 if (DAC < 0 || DAC >= 256) {
55 edm::LogWarning(
"EcalPedOffset") <<
"WARNING : TPedValues : DAC value " << DAC <<
" is out range, entry skipped";
64 assert(DACstart >= 0);
65 assert(DACend <= 256);
72 for (
int crystal = 0; crystal < 1700; ++crystal) {
75 int dummyBestDAC = -1;
76 bool hasDigis =
false;
78 for (
int DAC = DACstart; DAC < DACend; ++DAC) {
93 if ((dummyBestDAC == (DACend - 1) || dummyBestDAC == -1) && hasDigis) {
103 edm::LogError(
"EcalPedOffset") <<
" TPedValues : cannot find best DAC value for channel: " 113 assert(DACstart >= 0);
114 assert(DACend <= 256);
119 for (
int crystal = 0; crystal < 1700; ++crystal) {
121 for (
int DAC = DACstart; DAC < DACend; ++DAC) {
153 const double maxSlope,
154 const double minSlope,
155 const double maxChi2OverNDF)
const {
158 if (!rootFile->cd(dirName.c_str())) {
159 rootFile->mkdir(dirName.c_str());
160 rootFile->cd(dirName.c_str());
164 for (
int xtl = 0; xtl < 1700; ++xtl) {
167 vector<double> asseX;
169 vector<double> asseY;
176 for (
int dac = 0; dac < 256; ++dac) {
180 asseX.push_back(dac);
182 asseY.push_back(average);
183 sigmaY.push_back(rms);
186 if (!asseX.empty()) {
188 while (lastBin < (
int)asseX.size() - 1 && asseY[lastBin + 1] > 0 &&
189 (asseY[lastBin + 1] - asseY[lastBin + 2]) != 0)
192 int fitRangeEnd = (
int)asseX[lastBin];
194 if (fitRangeEnd < 66)
195 kinkPt = fitRangeEnd - 4;
196 TGraphErrors graph(asseX.size(), &(*asseX.begin()), &(*asseY.begin()), &(*sigmaX.begin()), &(*sigmaY.begin()));
198 sprintf(funct,
"(x<%d)*([0]*x+[1])+(x>=%d)*([2]*x+[3])", kinkPt, kinkPt);
199 TF1 fitFunction(
"fitFunction", funct, asseX[0], fitRangeEnd);
200 fitFunction.SetLineColor(2);
213 graph.GetXaxis()->SetTitle(
"DAC value");
214 graph.GetYaxis()->SetTitle(
"Average pedestal ADC");
215 graph.Fit(&fitFunction,
"RWQ");
218 double slope1 = fitFunction.GetParameter(0);
219 double slope2 = fitFunction.GetParameter(2);
221 if (fitFunction.GetChisquare() / fitFunction.GetNDF() > maxChi2OverNDF ||
222 fitFunction.GetChisquare() / fitFunction.GetNDF() < 0 || slope1 > 0 || slope2 > 0 ||
223 ((slope1 < -29 || slope1 > -18) && slope1 < 0) || ((slope2 < -29 || slope2 > -18) && slope2 < 0)) {
225 <<
" gain:" << gainHuman <<
" is not linear;" 226 <<
" slope of line1:" << fitFunction.GetParameter(0)
227 <<
" slope of line2:" << fitFunction.GetParameter(2) <<
" reduced chi-squared:" 228 << fitFunction.GetChisquare() / fitFunction.GetNDF();
235 if ((asseX.back() - asseX.front() + 1) != asseX.size())
236 edm::LogError(
"EcalPedOffset") <<
"TPedValues : Pedestal average not found " 238 <<
" gain:" << gainHuman;
TSinglePedEntry m_entries[3][1700][256]
int makePlots(TFile *rootFile, const std::string &dirName, const double maxSlopeAllowed, const double minSlopeAllowed, const double maxChi2OverNDF) const
create a plot of the DAC pedestal trend
Transient container Store all the pedestal values depending on the gain and pedestal offset $Date: $R...
TPedValues(double RMSmax=2, int bestPedestal=200)
ctor
double RMS() const
get the RMS of the inserted values
double average() const
get the average of the inserted values
TPedResult terminate(const int &DACstart=0, const int &DACend=256) const
calculate the offset values for all the containers
int getCrystalNumber(int xtal) const
return the index from the table
int checkEntries(const int &DACstart=0, const int &DACend=256) const
check whether the scan was complete in the range
int endcapCrystalNumbers[1700]
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
void insert(const int gainId, const int crystal, const int DAC, const int pedestal, const int endcapIndex)
add a single value
void reset(double vett[256])
void insert(const int &pedestal)
add a single value