28 for(detIDHistogramMap::iterator thisDetIdHistoGrams=
histograms_.begin(); thisDetIdHistoGrams !=
histograms_.end(); ++thisDetIdHistoGrams){
32 uint32_t detid = (*thisDetIdHistoGrams).first;
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){
53 std::cout<<
"error: could not obtain real fed ID"<<std::endl;
70 static_cast<unsigned int>(cabling.
link),
71 static_cast<unsigned int>(cabling.
roc)};
74 int newrow= locpixel.
rocRow();
75 int newcol = locpixel.
rocCol();
76 myfile<<rocname<<theRoc->
idInDetUnit()<<
" "<<newcol<<
" "<<newrow<<
" "<<thresholdhist->
getBinContent(icol+1, irow+1)<<
" "<<threshold_error;
86 void chi2toMinimize(
int &npar,
double* grad,
double &fcnval,
double* xval,
int iflag)
90 for (
int i = 0;
i < npar;
i++)
91 theFormula->SetParameter(
i, xval[
i]);
95 for (uint32_t i = 0; i < theVCalValues->size(); i++)
106 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Setting up calibration paramters.";
107 std::vector<uint32_t> anEmptyDefaultVectorOfUInts;
108 std::vector<uint32_t> detIDsToSaveVector_;
111 detIDsToSaveVector_ = iConfig.
getUntrackedParameter<std::vector<uint32_t> >(
"detIDsToSave", anEmptyDefaultVectorOfUInts);
130 for(
unsigned int i = 0;
i < detIDsToSaveVector_.size();
i++)
131 detIDsToSave_.insert( std::make_pair(detIDsToSaveVector_[
i],
true) );
143 edm::LogWarning(
"SiPixelSCurveCalibrationAnalysis") <<
"WARNING: Request to save curve for [detid](col/row): [" << detid <<
"](" << col <<
"/" << row <<
") denied. Maximum number of saved curves (defined in .cfi) exceeded.";
146 std::ostringstream rootName;
147 rootName <<
"SCurve_row_" << row <<
"_col_" <<
col;
148 std::ostringstream humanName;
152 if (efficiencies.size() != numberOfVCalPoints || errors.size() != numberOfVCalPoints)
154 edm::LogError(
"SiPixelSCurveCalibrationAnalysis") <<
"Error saving single curve histogram! Number of Vcal values (" << numberOfVCalPoints <<
") does not match number of efficiency points or error points!";
161 for(
unsigned int iBin = 0; iBin < numberOfVCalPoints; ++iBin)
163 int rootBin = iBin + 1;
176 const std::vector<short>* theVCalValues = this->
getVcalValues();
177 unsigned int numberOfVCalPoints = theVCalValues->size();
178 edm::LogWarning(
"SiPixelSCurveCalibrationAnalysis") <<
"WARNING: Option set to save indiviual S-Curves - max number: " 179 <<
maxCurvesToSave_ <<
" This can lead to large memory consumption! (Got " << numberOfVCalPoints <<
" VCal Points";
180 for(
unsigned int i = 0;
i < numberOfVCalPoints;
i++)
183 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Adding calibration Vcal: " << (*theVCalValues)[
i];
210 bool allZeroSoFar =
true;
212 int saturationBin = -1;
213 for (uint32_t iVcalPt = 0; iVcalPt < eff.size(); iVcalPt++)
215 if (allZeroSoFar && eff[iVcalPt] != 0 ) {
217 allZeroSoFar =
false;
219 }
else if (eff[iVcalPt] > 0.90)
221 saturationBin = iVcalPt;
224 short delta = saturationVcal - turnOnVcal;
225 sigma = delta * 0.682;
228 threshold = turnOnVcal + (0.5 *
delta);
252 eff = (
float)nADCResponse / (
float)nTriggers;
253 double effForErrorCalculation = eff;
254 if (eff <= 0 || eff >= 1)
255 effForErrorCalculation = 0.5 / (double)nTriggers;
256 error = TMath::Sqrt(effForErrorCalculation*(1-effForErrorCalculation) / (
double)nTriggers);
262 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Found a new DetID (" << detid <<
")! Checking to make sure it has not been added.";
265 std::pair<detIDHistogramMap::iterator, bool> insertResult;
266 insertResult =
histograms_.insert(std::make_pair(detid, tempMap));
267 if (insertResult.second)
269 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysisHistogramReport") <<
"Histogram Map.insert() returned true! Booking new histogrames for detID: " << detid;
279 insertResult.first->second.insert(std::make_pair(
kSigmas, D2sigma));
280 insertResult.first->second.insert(std::make_pair(
kThresholds, D2thresh));
281 insertResult.first->second.insert(std::make_pair(
kChi2s, D2chi2));
285 insertResult.first->second.insert(std::make_pair(
kFitResults, D2FitResult));
291 insertResult.first->second.insert(std::make_pair(
kSigmaSummary, D1sigma));
293 insertResult.first->second.insert(std::make_pair(
kChi2Summary, D1chi2));
294 insertResult.first->second.insert(std::make_pair(
kFitResultSummary, D1FitResult));
301 uint32_t nVCalPts = calibDigi->getnpoints();
305 for (uint32_t iVcalPt = 0; iVcalPt < nVCalPts; iVcalPt++)
310 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Eff: " << eff <<
" Error: " << error <<
" nEntries: " << calibDigi->getnentries(iVcalPt) <<
" nTriggers: " <<
nTriggers_ <<
" VCalPt " <<
vCalValues_[iVcalPt];
316 float thresholdGuess = -1.0;
317 float sigmaGuess = -1.0;
321 Double_t sigma = -1.0;
322 Double_t sigmaError = -1.0;
324 Double_t thresholdError = -1.0;
326 Double_t amplitudeError = -1.0;
327 Double_t
chi2 = -1.0;
330 Double_t chi2probability = 0;
332 if (errorFlag ==
errOK)
335 TMinuit *gMinuit =
new TMinuit(3);
336 gMinuit->SetPrintLevel(-1);
340 gMinuit->DefineParameter(0,
"Threshold", (Double_t)thresholdGuess, 1, -50, 300);
342 gMinuit->DefineParameter(1,
"Sigma", (Double_t)sigmaGuess, 0.1, 0, 255);
344 gMinuit->DefineParameter(2,
"Amplitude", 1, 0.1, -0.001, 200);
348 gMinuit->GetParameter(0, threshold, thresholdError);
349 gMinuit->GetParameter(1, sigma, sigmaError);
350 gMinuit->GetParameter(2, amplitude, amplitudeError);
353 Double_t params[3] = {
threshold, sigma, amplitude};
354 gMinuit->Eval(3,
nullptr, chi2, params, 0);
359 chi2probability = TMath::Prob(chi2, nDOF);
367 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysis") <<
"Fit finished with errorFlag: " << errorFlag <<
" - threshold: " << threshold <<
" sigma: " << sigma <<
" chi2: " << chi2 <<
" nDOF: " << nDOF <<
" chi2Prob: " << chi2probability <<
" chi2MinUser: " <<
minimumChi2prob_;
372 uint32_t row = calibDigi->row();
373 uint32_t
col = calibDigi->col();
376 detIDHistogramMap::iterator thisDetIdHistoGrams;
380 edm::LogInfo(
"SiPixelSCurveCalibrationAnalysisHistogramReport") <<
"Filling histograms for [detid](col/row): [" << detid <<
"](" << col <<
"/" << row <<
") ErrorFlag: " << errorFlag;
384 (*thisDetIdHistoGrams).second[
kFitResults]->setBinContent(col+1, row+1, errorFlag);
391 (*thisDetIdHistoGrams).second[
kSigmas]->setBinContent(col+1, row+1, sigma);
392 (*thisDetIdHistoGrams).second[
kThresholds]->setBinContent(col+1, row+1, threshold);
395 (*thisDetIdHistoGrams).second[
kChi2Summary]->Fill(chi2probability);
397 (*thisDetIdHistoGrams).second[
kChi2s]->Fill(col, row, chi2probability);
402 bool thisDetIDinList =
false;
404 thisDetIDinList =
true;
406 if (errorFlag !=
errOK || thisDetIDinList)
408 edm::LogError(
"SiPixelSCurveCalibrationAnalysis") <<
"Saving error histogram for [detid](col/row): [" << detid <<
"](" << 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)
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
int getNbinsY(void) const
get # of bins in Y-axis
std::map< sCurveHistogramType, MonitorElement * > sCurveHistogramHolder
bool doFits(uint32_t detid, std::vector< SiPixelCalibDigi >::const_iterator ipix) override
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_
std::string getTitle(void) const
get MonitorElement title
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
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)
int getNbinsX(void) const
get # of bins in X-axis
static const std::vector< short > * getVcalValues()
bool saveCurvesThatFlaggedBad_
std::string calibrationMode_
bool setDQMDirectory(std::string dirName)
unsigned int maxCurvesToSave_
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const override
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)