12 #include "CLHEP/Geometry/Point3D.h"
26 gROOT->SetStyle (
"Plain") ;
27 gStyle->SetTextSize(0.5);
29 gStyle->SetOptStat (0) ;
31 gStyle->SetOptFit (0) ;
32 gStyle->SetTitleBorderSize (0) ;
33 gStyle->SetTitleX (0.08) ;
34 gStyle->SetTitleY (0.97) ;
35 gStyle->SetPalette (1,0) ;
36 gStyle->SetStatColor (0) ;
37 gStyle->SetFrameFillStyle (0) ;
38 gStyle->SetFrameFillColor (0) ;
49 TCanvas * globalCanvas =
static_cast<TCanvas*
>
50 (gROOT->FindObject (name.c_str ())) ;
53 globalCanvas->Clear () ;
54 globalCanvas->UseCurrentStyle () ;
55 globalCanvas->SetWindowSize (700, 600) ;
60 globalCanvas =
new TCanvas (name.c_str (),name.c_str (), 700, 600) ;
72 TFile * globalTFile = (TFile*) gROOT->FindObject (name.c_str()) ;
76 globalTFile =
new TFile (name.c_str(),
"RECREATE") ;
88 TFile * globalTFile =
static_cast<TFile*
>
89 (gROOT->FindObject (name.c_str ())) ;
90 if (!globalTFile)
return 1 ;
91 globalTFile->Write () ;
92 globalTFile->Close () ;
104 CLHEP::HepMatrix * savedMatrix ;
105 if (reader.
touch (name))
107 savedMatrix =
static_cast<CLHEP::HepMatrix *
> (
134 HepGeom::Point3D<Float_t>
136 const Float_t beamEne,
146 Float_t sumWeight = 0. ;
147 Float_t depth = x0 * (
log (beamEne)+ a0) ;
148 Float_t sin3 = 0.052335956 ;
150 Float_t invE3x3 = 1. /
get3x3 (amplit) ;
160 caloX += (
eta-3) * sideX * weight;
161 caloY -= (
phi-3) * sideY * weight;
175 HepGeom::Point3D<Float_t>
TBposition (caloX, caloY, 0) ;
192 total += energy[
eta][
phi] ;
209 total += energy[
eta][
phi] ;
249 int xMin = 20 * myEta + 1 ;
250 int xMax = 20 * (myEta + 1) + 1 ;
252 int myCryst = 999999 ;
254 for (
int x = xMin ;
x < xMax ;
x++)
269 assert (iEta <= 85) ;
271 assert (iPhi <= 20) ;
272 return 20 * (iEta-1) + 21 - iPhi ;
282 return int (floor ((xtal-1) / 20) );
292 return (20 - phi - 1) ;
319 std::ifstream _dati (dati.c_str ()) ;
325 do { getline (_dati, dataline,
'\n') ; }
326 while (*dataline.begin () ==
'#') ;
327 std::stringstream linea (dataline) ;
329 while (!linea.eof ())
333 if (buffer != -1) output->push_back (buffer) ;
336 return output->size () ;
346 const CLHEP::HepMatrix & SigmaMatrix,
347 const CLHEP::HepMatrix & StatisticMatrix,
355 if (AmplitudeMatrix[
eta][
phi] &&
356 SigmaMatrix[
eta][
phi] < 100 )
358 reference = AmplitudeMatrix[
eta][
phi] ;
359 std::cout <<
"[InvMatrixUtils][writeCalibTxt] reference crystal: "
360 <<
"(" <<
eta <<
"," <<
phi <<
") -> "
361 << reference <<
"\n" ;
367 std::cerr <<
"ERROR: no calibration coefficients found" << std::endl ;
372 std::ofstream txt_outfile ;
373 txt_outfile.open (fileName.c_str ()) ;
374 txt_outfile <<
"# xtal\tcoeff\tsigma\tevt\tisGood\n" ;
381 if (AmplitudeMatrix[
eta][
phi] == 0) isGood = 0 ;
382 if (SigmaMatrix[
eta][
phi] > 100 ) isGood = 0 ;
384 <<
"\t" << AmplitudeMatrix[
eta][
phi]/reference
385 <<
"\t" << SigmaMatrix[
eta][
phi]
386 <<
"\t" << StatisticMatrix[
eta][
phi]
387 <<
"\t" << isGood <<
"\n" ;
391 txt_outfile.close () ;
402 const CLHEP::HepMatrix & sigmaMatrix,
403 const CLHEP::HepMatrix & statisticMatrix,
411 std::ofstream txt_outfile ;
412 txt_outfile.open (fileName.c_str ()) ;
413 txt_outfile <<
"1\n" ;
414 txt_outfile <<
"-1\n" ;
415 txt_outfile << genTag <<
"\n" ;
416 txt_outfile << method <<
"\n" ;
417 txt_outfile << version <<
"\n" ;
418 txt_outfile << type <<
"\n" ;
426 if (amplMatrix[
eta][
phi] <= calibThres)
431 <<
"\t" << 0 <<
"\n" ;
434 <<
"\t" << reference / amplMatrix[
eta][
phi]
435 <<
"\t" << sigmaMatrix[
eta][
phi]
436 <<
"\t" << statisticMatrix[
eta][
phi]
437 <<
"\t" << 1 <<
"\n" ;
441 txt_outfile.close () ;
451 int etaRef,
int phiRef,
452 const CLHEP::HepMatrix & sigmaMatrix,
453 const CLHEP::HepMatrix & statisticMatrix,
461 std::ofstream txt_outfile ;
462 txt_outfile.open (fileName.c_str ()) ;
463 txt_outfile <<
"1\n" ;
464 txt_outfile <<
"-1\n" ;
465 txt_outfile << genTag <<
"\n" ;
466 txt_outfile << method <<
"\n" ;
467 txt_outfile << version <<
"\n" ;
468 txt_outfile << type <<
"\n" ;
470 if (amplMatrix[etaRef-1][phiRef-1] == 0)
473 << etaRef <<
"," << phiRef
474 <<
") is out of range\n" ;
477 double reference = amplMatrix[etaRef-1][phiRef-1] ;
483 if (amplMatrix[
eta][
phi] <= calibThres)
488 <<
"\t" << 0 <<
"\n" ;
491 <<
"\t" << reference / amplMatrix[
eta][
phi]
492 <<
"\t" << sigmaMatrix[
eta][
phi]
493 <<
"\t" << statisticMatrix[
eta][
phi]
494 <<
"\t" << 1 <<
"\n" ;
498 txt_outfile.close () ;
507 const CLHEP::HepMatrix & sigmaMatrix,
508 const CLHEP::HepMatrix & statisticMatrix,
518 std::ofstream txt_outfile ;
519 txt_outfile.open (fileName.c_str ()) ;
520 txt_outfile << SMnumber <<
"\n" ;
521 txt_outfile <<
"-1\n" ;
522 txt_outfile << genTag <<
"\n" ;
523 txt_outfile << method <<
"\n" ;
524 txt_outfile << version <<
"\n" ;
525 txt_outfile << type <<
"\n" ;
531 if (calibcoeff[
eta][
phi] < calibThres)
537 <<
"\t" << 0 <<
"\n" ;
538 std::cout <<
"[translateCoefff][" << SMnumber
540 <<
" calib coeff below threshold: "
544 <<
"\t" << 0 <<
"\n" ;
548 <<
"\t" << calibcoeff[
eta][
phi]
549 <<
"\t" << sigmaMatrix[
eta][
phi]
550 <<
"\t" << statisticMatrix[
eta][
phi]
551 <<
"\t" << 1 <<
"\n" ;
555 txt_outfile.close () ;
567 std::ifstream CMSSWfile ;
568 CMSSWfile.open (inputFileName.c_str ()) ;
570 CMSSWfile >> buffer ;
571 CMSSWfile >> buffer ;
572 CMSSWfile >> buffer ;
573 CMSSWfile >> buffer ;
574 CMSSWfile >> buffer ;
575 CMSSWfile >> buffer ;
576 while (!CMSSWfile.eof ())
579 CMSSWfile >> xtalnum ;
583 CMSSWfile >> buffer ;
587 if (!good) coeff = defaultVal ;
601 std::ifstream CMSSWfile ;
602 CMSSWfile.open (inputFileName.c_str ()) ;
604 CMSSWfile >> buffer ;
605 CMSSWfile >> buffer ;
606 CMSSWfile >> buffer ;
607 CMSSWfile >> buffer ;
608 CMSSWfile >> buffer ;
609 CMSSWfile >> buffer ;
610 while (!CMSSWfile.eof ())
613 CMSSWfile >> xtalnum ;
617 CMSSWfile >> buffer ;
621 if (!good) coeff = 0. ;
634 TProfile * stripProfile = strip->ProfileX () ;
638 double xmin = stripProfile->GetXaxis ()->GetXmin () ;
639 double xmax = stripProfile->GetXaxis ()->GetXmax () ;
640 int profileBins = stripProfile->GetNbinsX () ;
644 TH1D * prof =
new TH1D
645 (name.c_str (),strip->GetTitle (),profileBins,
xmin,
xmax) ;
648 int nbins = strip->GetXaxis ()->GetNbins () ;
654 for (
int bin=binmin ;
bin<=binmax ;
bin += ngroup)
656 TH1D *hpy = strip->ProjectionY (
"_temp",
bin,
bin+ngroup-1,
"e") ;
657 if (hpy == 0) continue ;
658 int nentries = Int_t (hpy->GetEntries ()) ;
659 if (nentries == 0 || nentries < cut) {
delete hpy ; continue ;}
661 Int_t biny =
bin + ngroup/2 ;
663 hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
664 hpy->GetMean () + width * hpy->GetRMS ()) ;
665 prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
667 prof->SetBinError (biny,hpy->GetRMS()) ;
672 delete stripProfile ;
682 TProfile * stripProfile = strip->ProfileX () ;
686 double xmin = stripProfile->GetXaxis ()->GetXmin () ;
687 double xmax = stripProfile->GetXaxis ()->GetXmax () ;
688 int profileBins = stripProfile->GetNbinsX () ;
691 name +=
"_smartGaus" ;
692 TH1D * prof =
new TH1D
693 (name.c_str (),strip->GetTitle (),profileBins,
xmin,
xmax) ;
696 int nbins = strip->GetXaxis ()->GetNbins () ;
702 for (
int bin=binmin ;
bin<=binmax ;
bin += ngroup)
704 TH1D *hpy = strip->ProjectionY (
"_temp",
bin,
bin+ngroup-1,
"e") ;
705 if (hpy == 0) continue ;
706 int nentries = Int_t (hpy->GetEntries ()) ;
707 if (nentries == 0 || nentries < cut) {
delete hpy ; continue ;}
709 Int_t biny =
bin + ngroup/2 ;
711 TF1 * gaussian =
new TF1 (
"gaussian",
"gaus", hpy->GetMean () - width * hpy->GetRMS (),
712 hpy->GetMean () + width * hpy->GetRMS ()) ;
713 gaussian->SetParameter (1,hpy->GetMean ()) ;
714 gaussian->SetParameter (2,hpy->GetRMS ()) ;
715 hpy->Fit (
"gaussian",
"RQL") ;
717 hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
718 hpy->GetMean () + width * hpy->GetRMS ()) ;
719 prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
720 gaussian->GetParameter (1)) ;
721 prof->SetBinError (biny,gaussian->GetParameter (2)) ;
727 delete stripProfile ;
738 double xmin = strip->GetXaxis ()->GetXmin () ;
739 double xmax = strip->GetXaxis ()->GetXmax () ;
740 int stripsBins = strip->GetNbinsX () ;
744 TH1D *
error =
new TH1D
745 (name.c_str (),strip->GetTitle (),stripsBins,
xmin,
xmax) ;
749 int binmax = stripsBins ;
750 for (
int bin=binmin ;
bin<=binmax ;
bin += ngroup)
752 double dummyError = strip->GetBinError (
bin) ;
753 error->SetBinContent (
bin,dummyError) ;
764 double totInt = histogram.Integral () ;
765 int maxBin = histogram.GetMaximumBin () ;
766 int maxBinVal = int(histogram.GetBinContent (maxBin)) ;
767 int totBins = histogram.GetNbinsX () ;
768 double area = totInt ;
770 double vStep = maxBinVal / vSteps ;
772 int rightBin = totBins - 1 ;
774 while (area/totInt > 0.683)
788 for (
int fwd = maxBin ; fwd < totBins ; ++fwd)
790 if (histogram.GetBinContent (fwd) <
threshold)
796 area = histogram.Integral (leftBin,rightBin) ;
799 histogram.GetXaxis ()->SetRange (leftBin,rightBin) ;
801 double halfWidthRange = 0.5 * (histogram.GetBinCenter (rightBin) - histogram.GetBinCenter (leftBin)) ;
802 return halfWidthRange ;
811 int totBins = histogram.GetNbinsX () ;
812 if (thres >= histogram.GetMaximum ())
813 return std::pair<int,int> (0, totBins) ;
815 int leftBin = totBins - 1 ;
819 if (histogram.GetBinContent (
bin) > thres)
827 for (
int bin=totBins - 1 ;
bin> 0 ; --
bin)
829 if (histogram.GetBinContent (
bin) > thres)
835 return std::pair<int,int> (leftBin,rightBin) ;
844 CLHEP::HepMatrix *
input,
861 double p0 = 0.807883 ;
862 double p1 = 0.000182551 ;
863 double p2 = -5.76961e-06 ;
864 double p3 = 7.41903e-08 ;
865 double p4 = -2.25384e-10 ;
868 if (eta < 6) corr = p0 ;
869 else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*
eta;
876 double p0 = 0.799895 ;
877 double p1 = 0.000235487 ;
878 double p2 = -8.26496e-06 ;
879 double p3 = 1.21564e-07 ;
880 double p4 = -4.83286e-10 ;
883 if (eta < 8) corr = p0 ;
884 else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*
eta;
891 if (eta < 4)
return 1.0 ;
893 double p0 = 0.834629 ;
894 double p1 = 0.00015254 ;
895 double p2 = -4.91784e-06 ;
896 double p3 = 6.54652e-08 ;
897 double p4 = -2.4894e-10 ;
900 if (eta < 6) corr = p0 ;
901 else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*
eta;
TH1D * smartError(TH1D *strip)
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
int readCMSSWcoeff(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal=1.)
double etaCorrE1E49(int eta)
void mtrTransfer(double output[SCMaxEta][SCMaxPhi], CLHEP::HepMatrix *input, double Default)
int readCMSSWcoeffForComparison(CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
double effectiveSigma(TH1F &histogram, int vSteps=100)
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")
int 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)
double get5x5(const Float_t energy[7][7])
std::pair< int, int > findSupport(TH1F &histogram, double thres=0.)
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)