27 for (detIDHistogramMap::iterator thisDetIdHistoGrams =
histograms_.begin(); thisDetIdHistoGrams !=
histograms_.end();
28 ++thisDetIdHistoGrams) {
32 uint32_t detid = (*thisDetIdHistoGrams).first;
34 std::string rocname = name.substr(0, name.size() - 7);
37 int total_columns = sigmahist->
getNbinsX();
39 for (
int irow = 0; irow < total_rows; ++irow) {
40 for (
int icol = 0; icol < total_columns; ++icol) {
41 float threshold_error = sigmahist->
getBinContent(icol + 1, irow + 1);
45 for (
int fedid = 0; fedid <= 40; ++fedid) {
52 if (realfedID == -1) {
53 std::cout <<
"error: could not obtain real fed ID" << std::endl;
74 static_cast<unsigned int>(cabling.
link),
75 static_cast<unsigned int>(cabling.
roc)};
78 int newrow = locpixel.
rocRow();
79 int newcol = locpixel.
rocCol();
80 myfile << rocname << theRoc->
idInDetUnit() <<
" " << newcol <<
" " << newrow <<
" " 92 void chi2toMinimize(
int &npar,
double *grad,
double &fcnval,
double *xval,
int iflag) {
95 for (
int i = 0;
i < npar;
i++)
96 theFormula->SetParameter(
i, xval[
i]);
100 for (uint32_t i = 0; i < theVCalValues->size(); i++) {
108 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Setting up calibration paramters.";
109 std::vector<uint32_t> anEmptyDefaultVectorOfUInts;
110 std::vector<uint32_t> detIDsToSaveVector_;
113 detIDsToSaveVector_ =
133 for (
unsigned int i = 0;
i < detIDsToSaveVector_.size();
i++)
134 detIDsToSave_.insert(std::make_pair(detIDsToSaveVector_[
i],
true));
146 const std::vector<float> &
errors) {
149 <<
"WARNING: Request to save curve for [detid](col/row): [" << detid <<
"](" << col <<
"/" << row
150 <<
") denied. Maximum number of saved curves (defined in .cfi) " 154 std::ostringstream rootName;
155 rootName <<
"SCurve_row_" << row <<
"_col_" <<
col;
156 std::ostringstream humanName;
161 if (efficiencies.size() != numberOfVCalPoints || errors.size() != numberOfVCalPoints) {
163 <<
"Error saving single curve histogram! Number of Vcal values (" << numberOfVCalPoints
164 <<
") does not match number of efficiency points or error points!";
174 vcalValuesToPassToCrappyRoot);
177 for (
unsigned int iBin = 0; iBin < numberOfVCalPoints; ++iBin) {
178 int rootBin = iBin + 1;
192 const std::vector<short> *theVCalValues = this->
getVcalValues();
193 unsigned int numberOfVCalPoints = theVCalValues->size();
195 <<
"WARNING: Option set to save indiviual S-Curves - max number: " <<
maxCurvesToSave_ 196 <<
" This can lead to large memory consumption! (Got " << numberOfVCalPoints <<
" VCal Points";
197 for (
unsigned int i = 0;
i < numberOfVCalPoints;
i++) {
199 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Adding calibration Vcal: " << (*theVCalValues)[
i];
206 "0.5*[2]*(1+TMath::Erf( (x-[0]) / ([1]*sqrt(2)) ) )",
230 bool allZeroSoFar =
true;
232 int saturationBin = -1;
233 for (uint32_t iVcalPt = 0; iVcalPt < eff.size(); iVcalPt++) {
234 if (allZeroSoFar && eff[iVcalPt] != 0) {
236 allZeroSoFar =
false;
238 }
else if (eff[iVcalPt] > 0.90) {
239 saturationBin = iVcalPt;
242 short delta = saturationVcal - turnOnVcal;
243 sigma = delta * 0.682;
247 threshold = turnOnVcal + (0.5 *
delta);
270 eff = (
float)nADCResponse / (
float)nTriggers;
271 double effForErrorCalculation = eff;
272 if (eff <= 0 || eff >= 1)
273 effForErrorCalculation = 0.5 / (double)nTriggers;
274 error = TMath::Sqrt(effForErrorCalculation * (1 - effForErrorCalculation) / (
double)nTriggers);
280 <<
"Found a new DetID (" << detid <<
")! Checking to make sure it has not been added.";
283 std::pair<detIDHistogramMap::iterator, bool> insertResult;
284 insertResult =
histograms_.insert(std::make_pair(detid, tempMap));
285 if (insertResult.second)
287 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysisHistogramReport")
288 <<
"Histogram Map.insert() returned true! Booking new histogrames for " 300 insertResult.first->second.insert(std::make_pair(
kSigmas, D2sigma));
301 insertResult.first->second.insert(std::make_pair(
kThresholds, D2thresh));
302 insertResult.first->second.insert(std::make_pair(
kChi2s, D2chi2));
306 insertResult.first->second.insert(std::make_pair(
kFitResults, D2FitResult));
311 detid,
"ScurveThresholdSummary", detIdName +
" Thresholds Summary", 255, 0,
maximumThresholdBin_);
313 bookDQMHistogram1D(detid,
"ScurveChi2ProbSummary", detIdName +
" Chi2Prob Summary", 101, 0, 1.01);
315 bookDQMHistogram1D(detid,
"ScurveFitResultSummary", detIdName +
" Fit Result Summary", 10, -0.5, 9.5);
316 insertResult.first->second.insert(std::make_pair(
kSigmaSummary, D1sigma));
318 insertResult.first->second.insert(std::make_pair(
kChi2Summary, D1chi2));
319 insertResult.first->second.insert(std::make_pair(
kFitResultSummary, D1FitResult));
325 uint32_t nVCalPts = calibDigi->getnpoints();
329 for (uint32_t iVcalPt = 0; iVcalPt < nVCalPts; iVcalPt++) {
334 <<
"Eff: " << eff <<
" Error: " << error <<
" nEntries: " << calibDigi->getnentries(iVcalPt)
341 float thresholdGuess = -1.0;
342 float sigmaGuess = -1.0;
347 Double_t sigma = -1.0;
348 Double_t sigmaError = -1.0;
350 Double_t thresholdError = -1.0;
352 Double_t amplitudeError = -1.0;
353 Double_t
chi2 = -1.0;
356 Double_t chi2probability = 0;
358 if (errorFlag ==
errOK)
361 TMinuit *gMinuit =
new TMinuit(3);
362 gMinuit->SetPrintLevel(-1);
366 gMinuit->DefineParameter(0,
"Threshold", (Double_t)thresholdGuess, 1, -50, 300);
368 gMinuit->DefineParameter(1,
"Sigma", (Double_t)sigmaGuess, 0.1, 0, 255);
370 gMinuit->DefineParameter(2,
"Amplitude", 1, 0.1, -0.001, 200);
374 gMinuit->GetParameter(0, threshold, thresholdError);
375 gMinuit->GetParameter(1, sigma, sigmaError);
376 gMinuit->GetParameter(2, amplitude, amplitudeError);
379 Double_t params[3] = {
threshold, sigma, amplitude};
380 gMinuit->Eval(3,
nullptr, chi2, params, 0);
385 chi2probability = TMath::Prob(chi2, nDOF);
394 <<
"Fit finished with errorFlag: " << errorFlag <<
" - threshold: " << threshold <<
" sigma: " << sigma
395 <<
" chi2: " << chi2 <<
" nDOF: " << nDOF <<
" chi2Prob: " << chi2probability
401 uint32_t row = calibDigi->row();
402 uint32_t
col = calibDigi->col();
405 detIDHistogramMap::iterator thisDetIdHistoGrams;
408 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysisHistogramReport")
409 <<
"Filling histograms for [detid](col/row): [" << detid <<
"](" << col <<
"/" << row
410 <<
") ErrorFlag: " << errorFlag;
414 (*thisDetIdHistoGrams)
416 ->setBinContent(col + 1,
424 (*thisDetIdHistoGrams)
426 ->setBinContent(col + 1,
429 (*thisDetIdHistoGrams)
431 ->setBinContent(col + 1,
436 (*thisDetIdHistoGrams).second[
kChi2Summary]->Fill(chi2probability);
438 (*thisDetIdHistoGrams).second[
kChi2s]->Fill(col, row, chi2probability);
442 bool thisDetIDinList =
false;
444 thisDetIDinList =
true;
446 if (errorFlag !=
errOK || thisDetIDinList) {
447 edm::LogError(
"SiPixelSCurveCalibrationAnalysis") <<
"Saving error histogram for [detid](col/row): [" << detid
448 <<
"](" << col <<
"/" << row <<
") ErrorFlag: " << errorFlag;
std::string thresholdfilename_
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
std::map< sCurveHistogramType, MonitorElement * > sCurveHistogramHolder
void calculateEffAndError(int nADCResponse, int nTriggers, float &eff, float &error)
bool useDetectorHierarchyFolders_
void doSetup(const edm::ParameterSet &)
~SiPixelSCurveCalibrationAnalysis() override
std::vector< float > vCalPointsAsFloats_
static std::vector< float > efficiencies_
void calibrationSetup(const edm::EventSetup &iSetup) override
std::string translateDetIdToString(uint32_t detid)
unsigned int curvesSavedCounter_
static std::vector< float > effErrors_
MonitorElement * bookDQMHistoPlaquetteSummary2D(uint32_t detid, std::string name, std::string title)
identify pixel inside single ROC
bool doFits(uint32_t detid, std::vector< SiPixelCalibDigi >::const_iterator ipix) override
std::string getTitle() const
get MonitorElement title
static TF1 * fitFunction_
std::map< uint32_t, bool > detIDsToSave_
MonitorElement * bookDQMHistogram1D(uint32_t detid, std::string name, std::string title, int nchX, double lowX, double highX)
double maximumEffAsymptote_
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
sCurveErrorFlag estimateSCurveParameters(const std::vector< float > &eff, float &threshold, float &sigma)
static std::vector< short > vCalValues_
void makeThresholdSummary(void)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
detIDHistogramMap histograms_
bool checkCorrectCalibrationType() override
double collumn and pixel ID in double collumn representation
double minimumEffAsymptote_
double maximumThresholdBin_
sCurveErrorFlag fittedSCurveSanityCheck(float threshold, float sigma, float amplitude)
void calibrationEnd() override
int toCabling(sipixelobjects::ElectronicIndex &cabling, const sipixelobjects::DetectorIndex &detector) const
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const final
int getNbinsY() const
get # of bins in Y-axis
void chi2toMinimize(int &npar, double *grad, double &fcnval, double *xval, int iflag)
void newDetID(uint32_t detid) override
double getBinContent(int binx) const
get content of bin (1-D)
static const std::vector< short > * getVcalValues()
bool saveCurvesThatFlaggedBad_
std::string calibrationMode_
bool setDQMDirectory(std::string dirName)
int getNbinsX() const
get # of bins in X-axis
unsigned int maxCurvesToSave_
edm::ESHandle< SiPixelFedCablingMap > theCablingMap_
T const * product() const
void buildACurveHistogram(const uint32_t &detid, const uint32_t &row, const uint32_t &col, sCurveErrorFlag errorFlag, const std::vector< float > &efficiencies, const std::vector< float > &errors)