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;
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);
138 caloX -=
depth * sin3;
139 caloY -=
depth * sin3;
142 HepGeom::Point3D<Float_t>
TBposition(caloX, caloY, 0);
205 int xMin = 20 * myEta + 1;
206 int xMax = 20 * (myEta + 1) + 1;
208 int myCryst = 999999;
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()) {
277 const CLHEP::HepMatrix &SigmaMatrix,
278 const CLHEP::HepMatrix &StatisticMatrix,
284 if (AmplitudeMatrix[
eta][
phi] && SigmaMatrix[
eta][
phi] < 100 ) {
286 std::cout <<
"[InvMatrixUtils][writeCalibTxt] reference crystal: " 292 std::cerr <<
"ERROR: no calibration coefficients found" << std::endl;
297 std::ofstream txt_outfile;
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;
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;
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;
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;
453 while (!CMSSWfile.eof()) {
455 CMSSWfile >> xtalnum;
473 std::ifstream CMSSWfile;
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();
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";
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();
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;
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;
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;
double etaCorrE1E9(int eta)
int translateCoeff(const CLHEP::HepMatrix &calibcoeff, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string SMnumber, double calibThres, std::string fileName, std::string genTag, std::string method, std::string version, std::string type)
TCanvas * getGlobalCanvas(std::string name)
auto const good
min quality of good
int iphiFromXtal(const int &xtal)
TH1D * smartError(TH1D *strip)
TH1D * smartProfile(TH2F *strip, double width)
int ietaFromXtal(const int &xtal)
constexpr unsigned int maxBin
int readCMSSWcoeffForComparison(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
int extract(std::vector< int > *output, const std::string &dati)
HepGeom::Point3D< Float_t > TBposition(const Float_t amplit[7][7], const Float_t beamEne, const Float_t w0, const Float_t x0, const Float_t a0, const Float_t sideX, const Float_t sideY)
double effectiveSigma(TH1F &histogram, int vSteps)
int phiFromXtal(const int &xtal)
static std::string const input
void mtrTransfer(double output[85][20], CLHEP::HepMatrix *input, double Default)
TFile * getGlobalTFile(std::string name)
TH1D * smartGausProfile(TH2F *strip, double width)
std::pair< int, int > findSupport(TH1F &histogram, double thres)
save (read) CLHEP::HepMatrix to (from) text files
double etaCorrE1E25(int eta)
int xtalFromEtaPhi(const int &myEta, const int &myPhi)
CLHEP::HepMatrix * getSavedMatrix(const std::string &name)
double etaCorrE1E49(int eta)
int etaFromXtal(const int &xtal)
int writeCalibTxt(const CLHEP::HepMatrix &AmplitudeMatrix, const CLHEP::HepMatrix &SigmaMatrix, const CLHEP::HepMatrix &StatisticMatrix, std::string fileName)
static constexpr float a0
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
int readCMSSWcoeff(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal)
double get5x5(const Float_t energy[7][7])
int writeCMSSWCoeff(const CLHEP::HepMatrix &lMatrix, double calibThres, float ERef, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string fileName, std::string genTag, std::string method, std::string version, std::string type)
double get3x3(const Float_t energy[7][7])
int saveGlobalTFile(std::string name)