8 #include "CLHEP/Geometry/Point3D.h"
21 gROOT->SetStyle(
"Plain");
22 gStyle->SetTextSize(0.5);
24 gStyle->SetOptStat(0);
27 gStyle->SetTitleBorderSize(0);
28 gStyle->SetTitleX(0.08);
29 gStyle->SetTitleY(0.97);
30 gStyle->SetPalette(1,
nullptr);
31 gStyle->SetStatColor(0);
32 gStyle->SetFrameFillStyle(0);
33 gStyle->SetFrameFillColor(0);
41 TCanvas *globalCanvas =
static_cast<TCanvas *
>(gROOT->FindObject(name.c_str()));
43 globalCanvas->Clear();
44 globalCanvas->UseCurrentStyle();
45 globalCanvas->SetWindowSize(700, 600);
48 globalCanvas =
new TCanvas(name.c_str(), name.c_str(), 700, 600);
58 TFile *globalTFile = (TFile *)gROOT->FindObject(name.c_str());
61 globalTFile =
new TFile(name.c_str(),
"RECREATE");
70 TFile *globalTFile =
static_cast<TFile *
>(gROOT->FindObject(name.c_str()));
83 CLHEP::HepMatrix *savedMatrix;
84 if (reader.
touch(name)) {
85 savedMatrix =
static_cast<CLHEP::HepMatrix *
>(reader.
getMatrix(name));
106 HepGeom::Point3D<Float_t>
TBposition(
const Float_t amplit[7][7],
107 const Float_t beamEne,
112 const Float_t sideY) {
116 Float_t sumWeight = 0.;
118 Float_t sin3 = 0.052335956;
120 Float_t invE3x3 = 1. /
get3x3(amplit);
127 caloX += (
eta - 3) * sideX * weight;
128 caloY -= (
phi - 3) * sideY * weight;
138 caloX -= depth * sin3;
139 caloY -= depth * sin3;
142 HepGeom::Point3D<Float_t>
TBposition(caloX, caloY, 0);
156 total += energy[
eta][
phi];
170 total += energy[
eta][
phi];
205 int xMin = 20 * myEta + 1;
206 int xMax = 20 * (myEta + 1) + 1;
208 int myCryst = 999999;
210 for (
int x = xMin;
x < xMax;
x++) {
224 return 20 * (iEta - 1) + 21 - iPhi;
231 return int(floor((xtal - 1) / 20));
238 return (20 - phi - 1);
252 std::ifstream _dati(dati.c_str());
254 while (!_dati.eof()) {
258 getline(_dati, dataline,
'\n');
259 }
while (*dataline.begin() ==
'#');
260 std::stringstream linea(dataline);
262 while (!linea.eof()) {
266 output->push_back(buffer);
269 return output->size();
277 const CLHEP::HepMatrix &SigmaMatrix,
278 const CLHEP::HepMatrix &StatisticMatrix,
284 if (AmplitudeMatrix[
eta][
phi] && SigmaMatrix[
eta][
phi] < 100 ) {
285 reference = AmplitudeMatrix[
eta][
phi];
286 std::cout <<
"[InvMatrixUtils][writeCalibTxt] reference crystal: "
287 <<
"(" <<
eta <<
"," <<
phi <<
") -> " << reference <<
"\n";
292 std::cerr <<
"ERROR: no calibration coefficients found" << std::endl;
297 std::ofstream txt_outfile;
298 txt_outfile.open(fileName.c_str());
299 txt_outfile <<
"# xtal\tcoeff\tsigma\tevt\tisGood\n";
305 if (AmplitudeMatrix[
eta][
phi] == 0)
307 if (SigmaMatrix[
eta][
phi] > 100 )
310 << SigmaMatrix[
eta][
phi] <<
"\t" << StatisticMatrix[
eta][
phi] <<
"\t" << isGood <<
"\n";
323 const CLHEP::HepMatrix &sigmaMatrix,
324 const CLHEP::HepMatrix &statisticMatrix,
331 std::ofstream txt_outfile;
332 txt_outfile.open(fileName.c_str());
333 txt_outfile <<
"1\n";
334 txt_outfile <<
"-1\n";
335 txt_outfile << genTag <<
"\n";
336 txt_outfile << method <<
"\n";
337 txt_outfile << version <<
"\n";
338 txt_outfile << type <<
"\n";
345 if (amplMatrix[
eta][
phi] <= calibThres)
346 txt_outfile <<
xtalFromiEtaiPhi(
eta + 1,
phi + 1) <<
"\t" << 1 <<
"\t" << -1 <<
"\t" << -1 <<
"\t" << 0 <<
"\n";
349 << sigmaMatrix[
eta][
phi] <<
"\t" << statisticMatrix[
eta][
phi] <<
"\t" << 1 <<
"\n";
363 const CLHEP::HepMatrix &sigmaMatrix,
364 const CLHEP::HepMatrix &statisticMatrix,
371 std::ofstream txt_outfile;
372 txt_outfile.open(fileName.c_str());
373 txt_outfile <<
"1\n";
374 txt_outfile <<
"-1\n";
375 txt_outfile << genTag <<
"\n";
376 txt_outfile << method <<
"\n";
377 txt_outfile << version <<
"\n";
378 txt_outfile << type <<
"\n";
380 if (amplMatrix[etaRef - 1][phiRef - 1] == 0) {
381 std::cerr <<
"The reference crystal: (" << etaRef <<
"," << phiRef <<
") is out of range\n";
384 double reference = amplMatrix[etaRef - 1][phiRef - 1];
389 if (amplMatrix[
eta][
phi] <= calibThres)
390 txt_outfile <<
xtalFromiEtaiPhi(
eta + 1,
phi + 1) <<
"\t" << 1 <<
"\t" << -1 <<
"\t" << -1 <<
"\t" << 0 <<
"\n";
393 << sigmaMatrix[
eta][
phi] <<
"\t" << statisticMatrix[
eta][
phi] <<
"\t" << 1 <<
"\n";
404 const CLHEP::HepMatrix &sigmaMatrix,
405 const CLHEP::HepMatrix &statisticMatrix,
414 std::ofstream txt_outfile;
415 txt_outfile.open(fileName.c_str());
416 txt_outfile << SMnumber <<
"\n";
417 txt_outfile <<
"-1\n";
418 txt_outfile << genTag <<
"\n";
419 txt_outfile << method <<
"\n";
420 txt_outfile << version <<
"\n";
421 txt_outfile << type <<
"\n";
426 if (calibcoeff[
eta][
phi] < calibThres) {
427 txt_outfile <<
xtalFromiEtaiPhi(
eta + 1,
phi + 1) <<
"\t" << 1 <<
"\t" << -1 <<
"\t" << -1 <<
"\t" << 0 <<
"\n";
429 <<
" calib coeff below threshold: "
430 <<
"\t" << 1 <<
"\t" << -1 <<
"\t" << -1 <<
"\t" << 0 <<
"\n";
433 << sigmaMatrix[
eta][
phi] <<
"\t" << statisticMatrix[
eta][
phi] <<
"\t" << 1 <<
"\n";
444 std::ifstream CMSSWfile;
445 CMSSWfile.open(inputFileName.c_str());
453 while (!CMSSWfile.eof()) {
455 CMSSWfile >> xtalnum;
473 std::ifstream CMSSWfile;
474 CMSSWfile.open(inputFileName.c_str());
482 while (!CMSSWfile.eof()) {
484 CMSSWfile >> xtalnum;
502 TProfile *stripProfile = strip->ProfileX();
506 double xmin = stripProfile->GetXaxis()->GetXmin();
507 double xmax = stripProfile->GetXaxis()->GetXmax();
508 int profileBins = stripProfile->GetNbinsX();
512 TH1D *prof =
new TH1D(name.c_str(), strip->GetTitle(), profileBins,
xmin,
xmax);
515 int nbins = strip->GetXaxis()->GetNbins();
521 for (
int bin = binmin;
bin <= binmax;
bin += ngroup) {
522 TH1D *hpy = strip->ProjectionY(
"_temp",
bin,
bin + ngroup - 1,
"e");
525 int nentries = Int_t(hpy->GetEntries());
526 if (nentries == 0 || nentries < cut) {
531 Int_t biny =
bin + ngroup / 2;
533 hpy->GetXaxis()->SetRangeUser(hpy->GetMean() - width * hpy->GetRMS(), hpy->GetMean() + width * hpy->GetRMS());
534 prof->Fill(strip->GetXaxis()->GetBinCenter(biny), hpy->GetMean());
535 prof->SetBinError(biny, hpy->GetRMS());
547 TProfile *stripProfile = strip->ProfileX();
551 double xmin = stripProfile->GetXaxis()->GetXmin();
552 double xmax = stripProfile->GetXaxis()->GetXmax();
553 int profileBins = stripProfile->GetNbinsX();
556 name +=
"_smartGaus";
557 TH1D *prof =
new TH1D(name.c_str(), strip->GetTitle(), profileBins,
xmin,
xmax);
560 int nbins = strip->GetXaxis()->GetNbins();
566 for (
int bin = binmin;
bin <= binmax;
bin += ngroup) {
567 TH1D *hpy = strip->ProjectionY(
"_temp",
bin,
bin + ngroup - 1,
"e");
570 int nentries = Int_t(hpy->GetEntries());
571 if (nentries == 0 || nentries < cut) {
576 Int_t biny =
bin + ngroup / 2;
579 new TF1(
"gaussian",
"gaus", hpy->GetMean() - width * hpy->GetRMS(), hpy->GetMean() + width * hpy->GetRMS());
580 gaussian->SetParameter(1, hpy->GetMean());
581 gaussian->SetParameter(2, hpy->GetRMS());
582 hpy->Fit(
"gaussian",
"RQL");
584 hpy->GetXaxis()->SetRangeUser(hpy->GetMean() - width * hpy->GetRMS(), hpy->GetMean() + width * hpy->GetRMS());
585 prof->Fill(strip->GetXaxis()->GetBinCenter(biny), gaussian->GetParameter(1));
586 prof->SetBinError(biny, gaussian->GetParameter(2));
599 double xmin = strip->GetXaxis()->GetXmin();
600 double xmax = strip->GetXaxis()->GetXmax();
601 int stripsBins = strip->GetNbinsX();
605 TH1D *
error =
new TH1D(name.c_str(), strip->GetTitle(), stripsBins,
xmin,
xmax);
609 int binmax = stripsBins;
610 for (
int bin = binmin;
bin <= binmax;
bin += ngroup) {
611 double dummyError = strip->GetBinError(
bin);
612 error->SetBinContent(
bin, dummyError);
620 double totInt = histogram.Integral();
621 int maxBin = histogram.GetMaximumBin();
622 int maxBinVal = int(histogram.GetBinContent(maxBin));
623 int totBins = histogram.GetNbinsX();
624 double area = totInt;
626 double vStep = maxBinVal / vSteps;
628 int rightBin = totBins - 1;
630 while (area / totInt > 0.683) {
633 for (
int back = maxBin; back > 0; --back) {
634 if (histogram.GetBinContent(back) <
threshold) {
641 for (
int fwd = maxBin; fwd < totBins; ++fwd) {
642 if (histogram.GetBinContent(fwd) <
threshold) {
647 area = histogram.Integral(leftBin, rightBin);
650 histogram.GetXaxis()->SetRange(leftBin, rightBin);
652 double halfWidthRange = 0.5 * (histogram.GetBinCenter(rightBin) - histogram.GetBinCenter(leftBin));
653 return halfWidthRange;
659 int totBins = histogram.GetNbinsX();
660 if (thres >= histogram.GetMaximum())
661 return std::pair<int, int>(0, totBins);
663 int leftBin = totBins - 1;
665 for (
int bin = 1;
bin < totBins; ++
bin) {
666 if (histogram.GetBinContent(
bin) > thres) {
673 for (
int bin = totBins - 1;
bin > 0; --
bin) {
674 if (histogram.GetBinContent(
bin) > thres) {
679 return std::pair<int, int>(leftBin, rightBin);
698 double p0 = 0.807883;
699 double p1 = 0.000182551;
700 double p2 = -5.76961e-06;
701 double p3 = 7.41903e-08;
702 double p4 = -2.25384e-10;
708 corr = p0 + p1 * eta + p2 * eta * eta + p3 * eta * eta * eta + p4 * eta * eta * eta *
eta;
714 double p0 = 0.799895;
715 double p1 = 0.000235487;
716 double p2 = -8.26496e-06;
717 double p3 = 1.21564e-07;
718 double p4 = -4.83286e-10;
724 corr = p0 + p1 * eta + p2 * eta * eta + p3 * eta * eta * eta + p4 * eta * eta * eta *
eta;
733 double p0 = 0.834629;
734 double p1 = 0.00015254;
735 double p2 = -4.91784e-06;
736 double p3 = 6.54652e-08;
737 double p4 = -2.4894e-10;
743 corr = p0 + p1 * eta + p2 * eta * eta + p3 * eta * eta * eta + p4 * eta * eta * eta *
eta;
static std::vector< std::string > checklist log
TH1D * smartError(TH1D *strip)
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
std::pair< int, int > findSupport(TH1F &histogram, double thres=0.)
constexpr unsigned int maxBin
int readCMSSWcoeff(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal=1.)
double etaCorrE1E49(int eta)
void mtrTransfer(double output[85][20], CLHEP::HepMatrix *input, double Default)
int readCMSSWcoeffForComparison(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
double effectiveSigma(TH1F &histogram, int vSteps=100)
static std::string const input
int iphiFromXtal(const int &xtal)
int writeCMSSWCoeff(const CLHEP::HepMatrix &lMatrix, double calibThres, float ERef, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string fileName="calibOutput.txt", std::string genTag="CAL_GENTAG", std::string method="CAL_METHOD", std::string version="CAL_VERSION", std::string type="CAL_TYPE")
TH1D * smartProfile(TH2F *strip, double width)
int phiFromXtal(const int &xtal)
TH1D * smartGausProfile(TH2F *strip, double width)
int writeCalibTxt(const CLHEP::HepMatrix &AmplitudeMatrix, const CLHEP::HepMatrix &SigmaMatrix, const CLHEP::HepMatrix &StatisticMatrix, std::string fileName="calibOutput.txt")
save (read) CLHEP::HepMatrix to (from) text files
TFile * getGlobalTFile(std::string name="Inv MatrixTFile.root")
bool touch(std::string inputFileName)
TCanvas * getGlobalCanvas(std::string name="Inv MatrixCanvas")
int translateCoeff(const CLHEP::HepMatrix &calibcoeff, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string SMnumber="1", double calibThres=0.01, std::string fileName="calibOutput.txt", std::string genTag="CAL_GENTAG", std::string method="CAL_METHOD", std::string version="CAL_VERSION", std::string type="CAL_TYPE")
int saveGlobalTFile(std::string name="Inv MatrixFile.root")
CLHEP::HepGenMatrix * getMatrix(std::string inputFileName)
int extract(std::vector< int > *output, const std::string &dati)
double get3x3(const Float_t energy[7][7])
int ietaFromXtal(const int &xtal)
auto const good
min quality of good
static constexpr float a0
double get5x5(const Float_t energy[7][7])
double etaCorrE1E9(int eta)
CLHEP::HepMatrix * getSavedMatrix(const std::string &name)
int xtalFromEtaPhi(const int &myEta, const int &myPhi)
double etaCorrE1E25(int eta)
HepGeom::Point3D< Float_t > TBposition(const Float_t amplit[7][7], const Float_t beamEne, const Float_t w0=4.0, const Float_t x0=8.9, const Float_t a0=6.2, const Float_t sideX=24.06, const Float_t sideY=22.02)
int etaFromXtal(const int &xtal)