CMS 3D CMS Logo

Functions
InvMatrixUtils.h File Reference
#include <string>
#include <map>
#include "TObject.h"
#include "TF1.h"
#include "TH2.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Matrix/GenMatrix.h"
#include "CLHEP/Matrix/Matrix.h"
#include "CLHEP/Matrix/Vector.h"
#include "TFile.h"
#include "Calibration/Tools/interface/InvMatrixCommonDefs.h"

Go to the source code of this file.

Functions

double effectiveSigma (TH1F &histogram, int vSteps=100)
 
double etaCorrE1E25 (int eta)
 
double etaCorrE1E49 (int eta)
 
double etaCorrE1E9 (int eta)
 
int etaFromXtal (const int &xtal)
 
int extract (std::vector< int > *output, const std::string &dati)
 
std::pair< int, int > findSupport (TH1F &histogram, double thres=0.)
 
double get3x3 (const Float_t energy[7][7])
 
double get5x5 (const Float_t energy[7][7])
 
TCanvas * getGlobalCanvas (std::string name="Inv MatrixCanvas")
 
TFile * getGlobalTFile (std::string name="Inv MatrixTFile.root")
 
CLHEP::HepMatrix * getSavedMatrix (const std::string &name)
 
int ietaFromXtal (const int &xtal)
 
int iphiFromXtal (const int &xtal)
 
template<class Type >
void mtrReset (Type superModules[85][20], const Type val)
 
void mtrTransfer (double output[85][20], CLHEP::HepMatrix *input, double Default)
 
int parseConfigFile (const TString &config)
 
int phiFromXtal (const int &xtal)
 
int readCMSSWcoeff (CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal=1.)
 
int readCMSSWcoeffForComparison (CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
 
int saveGlobalTFile (std::string name="Inv MatrixFile.root")
 
void setStyle ()
 
TH1D * smartError (TH1D *strip)
 
TH1D * smartGausProfile (TH2F *strip, double width)
 
TH1D * smartProfile (TH2F *strip, double width)
 
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 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 writeCalibTxt (const CLHEP::HepMatrix &AmplitudeMatrix, const CLHEP::HepMatrix &SigmaMatrix, const CLHEP::HepMatrix &StatisticMatrix, std::string fileName="calibOutput.txt")
 
int writeCMSSWCoeff (const CLHEP::HepMatrix &amplMatrix, 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")
 
int writeCMSSWCoeff (const CLHEP::HepMatrix &amplMatrix, double calibThres, int etaRef, int phiRef, 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")
 
int xtalFromEtaPhi (const int &myEta, const int &myPhi)
 
int xtalFromiEtaiPhi (const int &iEta, const int &iPhi)
 

Function Documentation

double effectiveSigma ( TH1F &  histogram,
int  vSteps = 100 
)

find the effective sigma as the half width of the sub-distribution containing 68.3% of the total distribution

Definition at line 758 of file InvMatrixUtils.cc.

References jets_cff::area, createfilelist::int, and electronIdCutBased_cfi::threshold.

759 {
760  double totInt = histogram.Integral () ;
761  int maxBin = histogram.GetMaximumBin () ;
762  int maxBinVal = int(histogram.GetBinContent (maxBin)) ;
763  int totBins = histogram.GetNbinsX () ;
764  double area = totInt ;
765  double threshold = 0 ;
766  double vStep = maxBinVal / vSteps ;
767  int leftBin = 1 ;
768  int rightBin = totBins - 1 ;
769  //loop over the vertical range
770  while (area/totInt > 0.683)
771  {
772  threshold += vStep ;
773  // loop toward the left
774  for (int back = maxBin ; back > 0 ; --back)
775  {
776  if (histogram.GetBinContent (back) < threshold)
777  {
778  leftBin = back ;
779  break ;
780  }
781  } // loop toward the left
782 
783  // loop toward the right
784  for (int fwd = maxBin ; fwd < totBins ; ++fwd)
785  {
786  if (histogram.GetBinContent (fwd) < threshold)
787  {
788  rightBin = fwd ;
789  break ;
790  }
791  } // loop toward the right
792  area = histogram.Integral (leftBin,rightBin) ;
793  } //loop over the vertical range
794 
795  histogram.GetXaxis ()->SetRange (leftBin,rightBin) ;
796  // double sigmaEff = histogram.GetRMS () ;
797  double halfWidthRange = 0.5 * (histogram.GetBinCenter (rightBin) - histogram.GetBinCenter (leftBin)) ;
798  return halfWidthRange ;
799 }
double etaCorrE1E25 ( int  eta)

correction for eta containment for 5*5 cluster

Definition at line 855 of file InvMatrixUtils.cc.

References corr, PVValHelper::eta, p1, p2, p3, and p4.

Referenced by mtrReset().

856 {
857  double p0 = 0.807883 ;
858  double p1 = 0.000182551 ;
859  double p2 = -5.76961e-06 ;
860  double p3 = 7.41903e-08 ;
861  double p4 = -2.25384e-10 ;
862 
863  double corr ;
864  if (eta < 6) corr = p0 ;
865  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
866  return corr/p0 ;
867 }
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:5
double p1[4]
Definition: TauolaWrapper.h:89
double p3[4]
Definition: TauolaWrapper.h:91
double etaCorrE1E49 ( int  eta)

correction for eta containment for 7*7 cluster

Definition at line 870 of file InvMatrixUtils.cc.

References corr, PVValHelper::eta, p1, p2, p3, and p4.

Referenced by mtrReset().

871 {
872  double p0 = 0.799895 ;
873  double p1 = 0.000235487 ;
874  double p2 = -8.26496e-06 ;
875  double p3 = 1.21564e-07 ;
876  double p4 = -4.83286e-10 ;
877 
878  double corr ;
879  if (eta < 8) corr = p0 ;
880  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
881  return corr/p0 ;
882 }
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:5
double p1[4]
Definition: TauolaWrapper.h:89
double p3[4]
Definition: TauolaWrapper.h:91
double etaCorrE1E9 ( int  eta)

correction for eta containment for 3*3 cluster

Definition at line 885 of file InvMatrixUtils.cc.

References corr, PVValHelper::eta, p1, p2, p3, and p4.

Referenced by mtrReset().

886 {
887  if (eta < 4) return 1.0 ;
888  // grazie Paolo
889  double p0 = 0.834629 ;
890  double p1 = 0.00015254 ;
891  double p2 = -4.91784e-06 ;
892  double p3 = 6.54652e-08 ;
893  double p4 = -2.4894e-10 ;
894 
895  double corr ;
896  if (eta < 6) corr = p0 ;
897  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
898  return corr/p0 ;
899 }
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:5
double p1[4]
Definition: TauolaWrapper.h:89
double p3[4]
Definition: TauolaWrapper.h:91
int etaFromXtal ( const int &  xtal)

get the eta coord [0,84]

Definition at line 275 of file InvMatrixUtils.cc.

References createfilelist::int.

Referenced by ietaFromXtal(), phiFromXtal(), readCMSSWcoeff(), and readCMSSWcoeffForComparison().

276 {
277 // return floor (static_cast<double> ((xtal-1) / 20)) ;
278  return int (floor ((xtal-1) / 20) );
279 }
int extract ( std::vector< int > *  output,
const std::string &  dati 
)

to read a file containing unserted integers while avoiding comment lines

Definition at line 313 of file InvMatrixUtils.cc.

References edmScanValgrind::buffer, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by SiStripCalibLorentzAngle::algoBeginJob(), CalibrationHistosUsingDb::CalibrationHistosUsingDb(), reco::tau::disc::ChargedOutlierAngle(), reco::tau::disc::ChargedOutlierPt(), clone(), CommissioningTask::HistoSet::histo(), NoiseHistograms::histoAnalysis(), ApvTimingHistograms::histoAnalysis(), OptoScanHistograms::histoAnalysis(), DaqScopeModeHistograms::histoAnalysis(), PedestalsHistograms::histoAnalysis(), PedsFullNoiseHistograms::histoAnalysis(), PedsOnlyHistograms::histoAnalysis(), FastFedCablingHistograms::histoAnalysis(), VpspScanHistograms::histoAnalysis(), SamplingHistograms::histoAnalysis(), CalibrationHistograms::histoAnalysis(), FedCablingHistograms::histoAnalysis(), CommissioningHistograms::histogram(), SummaryPlotFactory< CommissioningAnalysis * >::init(), reco::tau::disc::IsolationChargedSumHard(), reco::tau::disc::IsolationChargedSumSoft(), reco::tau::disc::IsolationECALSumHard(), reco::tau::disc::IsolationECALSumSoft(), DQMStore::mtEnabled(), reco::tau::disc::NeutralOutlierAngle(), reco::tau::disc::NeutralOutlierPt(), reco::tau::disc::OutlierAngle(), reco::tau::disc::OutlierPt(), reco::tau::disc::PiZeroAngle(), reco::tau::disc::PiZeroEta(), reco::tau::disc::PiZeroPt(), reco::tau::disc::TrackAngle(), reco::tau::disc::TrackEta(), reco::tau::disc::TrackPt(), PedestalsTask::update(), DaqScopeModeTask::update(), PedsOnlyTask::update(), NoiseTask::update(), PedsFullNoiseTask::update(), and CommissioningTask::updateHistoSet().

314  {
315  std::ifstream _dati (dati.c_str ()) ;
316  // loop over the file
317  while (!_dati.eof())
318  {
319  // get the line
320  std::string dataline ;
321  do { getline (_dati, dataline,'\n') ; }
322  while (*dataline.begin () == '#') ;
323  std::stringstream linea (dataline) ;
324  // loop over the line
325  while (!linea.eof ())
326  {
327  int buffer = -1 ;
328  linea >> buffer ;
329  if (buffer != -1) output->push_back (buffer) ;
330  } // loop over the line
331  } // loop over the file
332  return output->size () ;
333  }
std::pair<int,int> findSupport ( TH1F &  histogram,
double  thres = 0. 
)

find the support of the histogram above a threshold return the min and max bins

Definition at line 805 of file InvMatrixUtils.cc.

References stringResolutionProvider_cfi::bin.

806 {
807  int totBins = histogram.GetNbinsX () ;
808  if (thres >= histogram.GetMaximum ())
809  return std::pair<int,int> (0, totBins) ;
810 
811  int leftBin = totBins - 1 ;
812  // search from left for the minimum
813  for (int bin=1 ; bin<totBins ; ++bin)
814  {
815  if (histogram.GetBinContent (bin) > thres)
816  {
817  leftBin = bin ;
818  break ;
819  }
820  } // search from left for the minimum
821  int rightBin = 1 ;
822  // search from right for the maximum
823  for (int bin=totBins - 1 ; bin> 0 ; --bin)
824  {
825  if (histogram.GetBinContent (bin) > thres)
826  {
827  rightBin = bin ;
828  break ;
829  }
830  } // search from right for the maximum
831  return std::pair<int,int> (leftBin,rightBin) ;
832 }
bin
set the eta bin as selection string.
double get3x3 ( const Float_t  energy[7][7])

get the energy in the 3x3 from the 7x7 array around the most energetic crystal

Definition at line 199 of file InvMatrixUtils.cc.

References PVValHelper::eta, PVValHelper::phi, and pileupDistInMC::total.

Referenced by TBposition().

200 {
201  double total = 0. ;
202 
203  for (int eta=2 ; eta<5 ; ++eta)
204  for (int phi=2 ; phi<5 ; ++phi)
205  total += energy[eta][phi] ;
206 
207  return total ;
208 }
double get5x5 ( const Float_t  energy[7][7])

get the energy in the 5x5 from the 7x7 array around the most energetic crystal

Definition at line 182 of file InvMatrixUtils.cc.

References PVValHelper::eta, PVValHelper::phi, and pileupDistInMC::total.

183 {
184  double total = 0. ;
185 
186  for (int eta=1 ; eta<6 ; ++eta)
187  for (int phi=1 ; phi<6 ; ++phi)
188  total += energy[eta][phi] ;
189 
190  return total ;
191 }
TCanvas* getGlobalCanvas ( std::string  name = "Inv MatrixCanvas")

search for an existing canvas with the name and returns the poiter to it

Definition at line 42 of file InvMatrixUtils.cc.

References setStyle().

43 {
44  setStyle () ;
45  TCanvas * globalCanvas = static_cast<TCanvas*>
46  (gROOT->FindObject (name.c_str ())) ;
47  if (globalCanvas)
48  {
49  globalCanvas->Clear () ;
50  globalCanvas->UseCurrentStyle () ;
51  globalCanvas->SetWindowSize (700, 600) ;
52 
53  }
54  else
55  {
56  globalCanvas = new TCanvas (name.c_str (),name.c_str (), 700, 600) ;
57  }
58  return globalCanvas ;
59 }
void setStyle()
TFile* getGlobalTFile ( std::string  name = "Inv MatrixTFile.root")

search for an existing TFile with the name and returns the poiter to it

Definition at line 64 of file InvMatrixUtils.cc.

65 {
66 // std::cout << "writing " << name << std::endl ;
67 // setStyle () ;
68  TFile * globalTFile = (TFile*) gROOT->FindObject (name.c_str()) ;
69  if (!globalTFile)
70  {
71 // std::cout << "does not exist. creating it " << std::endl;
72  globalTFile = new TFile (name.c_str(),"RECREATE") ;
73  }
74 
75  return globalTFile ;
76 }
CLHEP::HepMatrix* getSavedMatrix ( const std::string &  name)

search for an existing calib matrix saved with the name and returns the poiter to it, the deletion is responsiblity of the user

Definition at line 97 of file InvMatrixUtils.cc.

References matrixSaver::getMatrix(), matplotRender::reader, SCMaxEta, SCMaxPhi, and matrixSaver::touch().

98 {
100  CLHEP::HepMatrix * savedMatrix ;
101  if (reader.touch (name))
102  {
103  savedMatrix = static_cast<CLHEP::HepMatrix *> (
104  reader.getMatrix (name)
105  );
106  }
107  else
108  {
109  savedMatrix = new CLHEP::HepMatrix (SCMaxEta,SCMaxPhi,0) ;
110  }
111 
112  return savedMatrix ;
113 }
#define SCMaxEta
#define SCMaxPhi
save (read) CLHEP::HepMatrix to (from) text files
Definition: matrixSaver.h:22
bool touch(std::string inputFileName)
Definition: matrixSaver.cc:137
CLHEP::HepGenMatrix * getMatrix(std::string inputFileName)
Definition: matrixSaver.cc:146
int ietaFromXtal ( const int &  xtal)

get the eta coord [1,85]

Definition at line 295 of file InvMatrixUtils.cc.

References etaFromXtal().

296 {
297  return etaFromXtal (xtal) + 1 ;
298 }
int etaFromXtal(const int &xtal)
int iphiFromXtal ( const int &  xtal)

get the phi coord [1,20]

Definition at line 304 of file InvMatrixUtils.cc.

References phiFromXtal().

305 {
306  return phiFromXtal (xtal) + 1 ;
307 }
int phiFromXtal(const int &xtal)
template<class Type >
void mtrReset ( Type  superModules[85][20],
const Type  val 
)

reset the matrices f the size of a supermodule

Definition at line 183 of file InvMatrixUtils.h.

References MillePedeFileConverter_cfg::e, PVValHelper::eta, etaCorrE1E25(), etaCorrE1E49(), etaCorrE1E9(), AlCaHLTBitMon_ParallelJobs::p, SCMaxEta, SCMaxPhi, and heppy_batch::val.

184  {
185  for (int e = 0 ; e < SCMaxEta ; ++e)
186  for (int p = 0 ; p < SCMaxPhi ; ++p)
187  {
188  superModules[e][p] = val ;
189  }
190  }
#define SCMaxEta
#define SCMaxPhi
void mtrTransfer ( double  output[85][20],
CLHEP::HepMatrix *  input,
double  Default 
)

transfers a CLHEP matrix into a double array with the size of a supermodule

Definition at line 839 of file InvMatrixUtils.cc.

References Default, PVValHelper::eta, convertSQLitetoXML_cfg::output, PVValHelper::phi, mathSSE::return(), SCMaxEta, and SCMaxPhi.

842 {
843  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
844  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
845  {
846  if ((*input)[eta][phi])
847  output[eta][phi] = (*input)[eta][phi] ;
848  else output[eta][phi] = Default ;
849  }
850  return ;
851 }
#define SCMaxEta
#define Default
Definition: vmac.h:110
#define SCMaxPhi
static std::string const input
Definition: EdmProvDump.cc:44
return((rh^lh)&mask)
int parseConfigFile ( const TString &  config)

to get the parameters from a congiguration file

int phiFromXtal ( const int &  xtal)

get the phi coord [0,19]

Definition at line 285 of file InvMatrixUtils.cc.

References etaFromXtal(), and PVValHelper::phi.

Referenced by iphiFromXtal(), readCMSSWcoeff(), readCMSSWcoeffForComparison(), and xtalFromEtaPhi().

286 {
287  int phi = (xtal-1) - 20 * etaFromXtal (xtal) ;
288  return (20 - phi - 1) ;
289 }
int etaFromXtal(const int &xtal)
int readCMSSWcoeff ( CLHEP::HepMatrix &  calibcoeff,
const std::string &  inputFileName,
double  defaultVal = 1. 
)

translates the calib coefficients format, from the CMSSW one to the TB06Studies one

Definition at line 559 of file InvMatrixUtils.cc.

References edmScanValgrind::buffer, etaFromXtal(), phiFromXtal(), and AlCaHLTBitMon_QueryRunRegistry::string.

562 {
563  std::ifstream CMSSWfile ;
564  CMSSWfile.open (inputFileName.c_str ()) ;
566  CMSSWfile >> buffer ;
567  CMSSWfile >> buffer ;
568  CMSSWfile >> buffer ;
569  CMSSWfile >> buffer ;
570  CMSSWfile >> buffer ;
571  CMSSWfile >> buffer ;
572  while (!CMSSWfile.eof ())
573  {
574  int xtalnum ;
575  CMSSWfile >> xtalnum ;
576  double coeff ;
577  CMSSWfile >> coeff ;
578  double buffer ;
579  CMSSWfile >> buffer ;
580  int good ;
581  CMSSWfile >> good ;
582  CMSSWfile >> good ;
583  if (!good) coeff = defaultVal ; //FIXME 0 o 1?
584  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
585  }
586  return 0 ;
587 
588 }
int phiFromXtal(const int &xtal)
int etaFromXtal(const int &xtal)
int readCMSSWcoeffForComparison ( CLHEP::HepMatrix &  calibcoeff,
const std::string &  inputFileName 
)

translates the calib coefficients format, from the CMSSW one to the TB06Studies one

Definition at line 594 of file InvMatrixUtils.cc.

References edmScanValgrind::buffer, etaFromXtal(), phiFromXtal(), and AlCaHLTBitMon_QueryRunRegistry::string.

596 {
597  std::ifstream CMSSWfile ;
598  CMSSWfile.open (inputFileName.c_str ()) ;
600  CMSSWfile >> buffer ;
601  CMSSWfile >> buffer ;
602  CMSSWfile >> buffer ;
603  CMSSWfile >> buffer ;
604  CMSSWfile >> buffer ;
605  CMSSWfile >> buffer ;
606  while (!CMSSWfile.eof ())
607  {
608  int xtalnum ;
609  CMSSWfile >> xtalnum ;
610  double coeff ;
611  CMSSWfile >> coeff ;
612  double buffer ;
613  CMSSWfile >> buffer ;
614  int good ;
615  CMSSWfile >> good ;
616  CMSSWfile >> good ;
617  if (!good) coeff = 0. ; //FIXME 0 o 1?
618  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
619  }
620  return 0 ;
621 
622 }
int phiFromXtal(const int &xtal)
int etaFromXtal(const int &xtal)
int saveGlobalTFile ( std::string  name = "Inv MatrixFile.root")

search for an existing TFile with the name and saves it to disk with his name

Definition at line 82 of file InvMatrixUtils.cc.

83 {
84  TFile * globalTFile = static_cast<TFile*>
85  (gROOT->FindObject (name.c_str ())) ;
86  if (!globalTFile) return 1 ;
87  globalTFile->Write () ;
88  globalTFile->Close () ;
89  delete globalTFile ;
90  return 0 ;
91 }
void setStyle ( )

set the style for the printout

Definition at line 20 of file InvMatrixUtils.cc.

References mathSSE::return().

Referenced by getGlobalCanvas().

21 {
22  gROOT->SetStyle ("Plain") ;
23  gStyle->SetTextSize(0.5);
24  //gStyle->SetOptStat (1111111) ;
25  gStyle->SetOptStat (0) ;
26  //gStyle->SetOptFit (1111) ;
27  gStyle->SetOptFit (0) ;
28  gStyle->SetTitleBorderSize (0) ;
29  gStyle->SetTitleX (0.08) ;
30  gStyle->SetTitleY (0.97) ;
31  gStyle->SetPalette (1,nullptr) ;
32  gStyle->SetStatColor (0) ;
33  gStyle->SetFrameFillStyle (0) ;
34  gStyle->SetFrameFillColor (0) ;
35  return ;
36 }
return((rh^lh)&mask)
TH1D* smartError ( TH1D *  strip)

Definition at line 731 of file InvMatrixUtils.cc.

References stringResolutionProvider_cfi::bin, relativeConstraints::error, dataset::name, AlCaHLTBitMon_QueryRunRegistry::string, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

732 {
733 
734  double xmin = strip->GetXaxis ()->GetXmin () ;
735  double xmax = strip->GetXaxis ()->GetXmax () ;
736  int stripsBins = strip->GetNbinsX () ;
737 
738  std::string name = strip->GetName () ;
739  name += "_error" ;
740  TH1D * error = new TH1D
741  (name.c_str (),strip->GetTitle (),stripsBins,xmin,xmax) ;
742 
743  int binmin = 1 ;
744  int ngroup = 1 ; // bins per step
745  int binmax = stripsBins ;
746  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
747  {
748  double dummyError = strip->GetBinError (bin) ;
749  error->SetBinContent (bin,dummyError) ;
750  }
751  return error;
752 }
bin
set the eta bin as selection string.
TH1D* smartGausProfile ( TH2F *  strip,
double  width 
)

smart profiling by fixing gaussian parameters and range from a first averaging

Definition at line 676 of file InvMatrixUtils.cc.

References stringResolutionProvider_cfi::bin, TkAlMuonSelectors_cfi::cut, dataset::name, pileupCalc::nbins, AlCaHLTBitMon_QueryRunRegistry::string, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

677 {
678  TProfile * stripProfile = strip->ProfileX () ;
679 
680  // (from FitSlices of TH2.h)
681 
682  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
683  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
684  int profileBins = stripProfile->GetNbinsX () ;
685 
686  std::string name = strip->GetName () ;
687  name += "_smartGaus" ;
688  TH1D * prof = new TH1D
689  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
690 
691  int cut = 0 ; // minimum number of entries per fitted bin
692  int nbins = strip->GetXaxis ()->GetNbins () ;
693  int binmin = 1 ;
694  int ngroup = 1 ; // bins per step
695  int binmax = nbins ;
696 
697  // loop over the strip bins
698  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
699  {
700  TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ;
701  if (hpy == nullptr) continue ;
702  int nentries = Int_t (hpy->GetEntries ()) ;
703  if (nentries == 0 || nentries < cut) {delete hpy ; continue ;}
704 
705  Int_t biny = bin + ngroup/2 ;
706 
707  TF1 * gaussian = new TF1 ("gaussian","gaus", hpy->GetMean () - width * hpy->GetRMS (),
708  hpy->GetMean () + width * hpy->GetRMS ()) ;
709  gaussian->SetParameter (1,hpy->GetMean ()) ;
710  gaussian->SetParameter (2,hpy->GetRMS ()) ;
711  hpy->Fit ("gaussian","RQL") ;
712 
713  hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
714  hpy->GetMean () + width * hpy->GetRMS ()) ;
715  prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
716  gaussian->GetParameter (1)) ;
717  prof->SetBinError (biny,gaussian->GetParameter (2)) ;
718 
719  delete gaussian ;
720  delete hpy ;
721  } // loop over the bins
722 
723  delete stripProfile ;
724  return prof ;
725 }
bin
set the eta bin as selection string.
TH1D* smartProfile ( TH2F *  strip,
double  width 
)

smart profiling by double averaging

Definition at line 628 of file InvMatrixUtils.cc.

References stringResolutionProvider_cfi::bin, TkAlMuonSelectors_cfi::cut, dataset::name, pileupCalc::nbins, AlCaHLTBitMon_QueryRunRegistry::string, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

629 {
630  TProfile * stripProfile = strip->ProfileX () ;
631 
632  // (from FitSlices of TH2.h)
633 
634  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
635  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
636  int profileBins = stripProfile->GetNbinsX () ;
637 
638  std::string name = strip->GetName () ;
639  name += "_smart" ;
640  TH1D * prof = new TH1D
641  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
642 
643  int cut = 0 ; // minimum number of entries per fitted bin
644  int nbins = strip->GetXaxis ()->GetNbins () ;
645  int binmin = 1 ;
646  int ngroup = 1 ; // bins per step
647  int binmax = nbins ;
648 
649  // loop over the strip bins
650  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
651  {
652  TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ;
653  if (hpy == nullptr) continue ;
654  int nentries = Int_t (hpy->GetEntries ()) ;
655  if (nentries == 0 || nentries < cut) {delete hpy ; continue ;}
656 
657  Int_t biny = bin + ngroup/2 ;
658 
659  hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
660  hpy->GetMean () + width * hpy->GetRMS ()) ;
661  prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
662  hpy->GetMean ()) ;
663  prof->SetBinError (biny,hpy->GetRMS()) ;
664 
665  delete hpy ;
666  } // loop over the bins
667 
668  delete stripProfile ;
669  return prof ;
670 }
bin
set the eta bin as selection string.
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 
)

return the impact position of the electron over ECAL

Definition at line 131 of file InvMatrixUtils.cc.

References egammaForCoreTracking_cff::depth, PVValHelper::eta, get3x3(), cmsBatch::log, PVValHelper::phi, and mps_merge::weight.

138 {
139  // variables
140  Float_t caloX = 0. ;
141  Float_t caloY = 0. ;
142  Float_t sumWeight = 0. ;
143  Float_t depth = x0 * (log (beamEne)+ a0) ; // shower depthh, in mm
144  Float_t sin3 = 0.052335956 ; // sin (3 degrees) , sin3 = sin(3.*3.141592654/180.)
145 
146  Float_t invE3x3 = 1. / get3x3 (amplit) ;
147 
148  // loop over 3x3 crystals
149  for (int eta = 2; eta <= 4; eta++)
150  {
151  for (int phi = 2; phi <= 4; phi++)
152  {
153  Float_t weight = log( amplit[eta][phi] * invE3x3) + w0 ;
154  if ( weight>0 )
155  {
156  caloX += (eta-3) * sideX * weight;
157  caloY -= (phi-3) * sideY * weight;
158  sumWeight += weight;
159  }
160  }
161  }
162 
163  caloX /=sumWeight;
164  caloY /=sumWeight;
165 
166  // correction for shower depthh
167  caloX -= depth*sin3;
168  caloY -= depth*sin3;
169 
170  // FIXME the z set to zero
171  HepGeom::Point3D<Float_t> TBposition (caloX, caloY, 0) ;
172 
173  return TBposition ;
174 
175 }
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)
Definition: weight.py:1
double get3x3(const Float_t energy[7][7])
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" 
)

translates the calib coefficients format, from the TB06Studies one to the CMSSSW one

Definition at line 502 of file InvMatrixUtils.cc.

References gather_cfg::cout, PVValHelper::eta, PVValHelper::phi, SCMaxEta, SCMaxPhi, and xtalFromiEtaiPhi().

512 {
513  // open the file for output
514  std::ofstream txt_outfile ;
515  txt_outfile.open (fileName.c_str ()) ;
516  txt_outfile << SMnumber << "\n" ; // super-module number
517  txt_outfile << "-1\n" ; // number of events
518  txt_outfile << genTag << "\n" ;
519  txt_outfile << method << "\n" ;
520  txt_outfile << version << "\n" ;
521  txt_outfile << type << "\n" ;
522 
523  // loop over crystals
524  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
525  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
526  {
527  if (calibcoeff[eta][phi] < calibThres)
528  {
529  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
530  << "\t" << 1
531  << "\t" << -1
532  << "\t" << -1
533  << "\t" << 0 <<"\n" ;
534  std::cout << "[translateCoefff][" << SMnumber
535  << "]\t WARNING crystal " << xtalFromiEtaiPhi (eta+1,phi+1)
536  << " calib coeff below threshold: "
537  << "\t" << 1
538  << "\t" << -1
539  << "\t" << -1
540  << "\t" << 0 <<"\n" ;
541  }
542  else
543  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
544  << "\t" << calibcoeff[eta][phi]
545  << "\t" << sigmaMatrix[eta][phi]
546  << "\t" << statisticMatrix[eta][phi]
547  << "\t" << 1 <<"\n" ;
548  } // loop over crystals
549 
550  // save and close the file
551  txt_outfile.close () ;
552  return 0 ;
553 }
type
Definition: HCALResponse.h:21
#define SCMaxEta
#define SCMaxPhi
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
int writeCalibTxt ( const CLHEP::HepMatrix &  AmplitudeMatrix,
const CLHEP::HepMatrix &  SigmaMatrix,
const CLHEP::HepMatrix &  StatisticMatrix,
std::string  fileName = "calibOutput.txt" 
)

to write the calibration constants file

Definition at line 341 of file InvMatrixUtils.cc.

References MessageLogger_cfi::cerr, gather_cfg::cout, PVValHelper::eta, PVValHelper::phi, RecoTauValidation_cfi::reference, SCMaxEta, SCMaxPhi, and xtalFromEtaPhi().

345 {
346  // look for the reference crystal
347  double reference = 0. ;
348  for (int eta = 0 ; eta<SCMaxEta ; ++eta)
349  for (int phi = 0 ; phi<SCMaxPhi ; ++phi)
350  {
351  if (AmplitudeMatrix[eta][phi] &&
352  SigmaMatrix[eta][phi] < 100 /*FIXME sigmaCut*/)
353  {
354  reference = AmplitudeMatrix[eta][phi] ;
355  std::cout << "[InvMatrixUtils][writeCalibTxt] reference crystal: "
356  << "(" << eta << "," << phi << ") -> "
357  << reference << "\n" ;
358  break ;
359  }
360  }
361  if (!reference)
362  {
363  std::cerr << "ERROR: no calibration coefficients found" << std::endl ;
364  return 1 ;
365  }
366 
367  // open the file for output
368  std::ofstream txt_outfile ;
369  txt_outfile.open (fileName.c_str ()) ;
370  txt_outfile << "# xtal\tcoeff\tsigma\tevt\tisGood\n" ;
371 
372  // loop over the crystals
373  for (int eta = 0 ; eta<SCMaxEta ; ++eta)
374  for (int phi = 0 ; phi<SCMaxPhi ; ++phi)
375  {
376  int isGood = 1 ;
377  if (AmplitudeMatrix[eta][phi] == 0) isGood = 0 ;
378  if (SigmaMatrix[eta][phi] > 100 /*FIXME sigmaCut*/) isGood = 0 ;
379  txt_outfile << xtalFromEtaPhi (eta,phi)
380  << "\t" << AmplitudeMatrix[eta][phi]/reference
381  << "\t" << SigmaMatrix[eta][phi]
382  << "\t" << StatisticMatrix[eta][phi]
383  << "\t" << isGood <<"\n" ;
384  }
385 
386  // save and close the file
387  txt_outfile.close () ;
388  return 0 ;
389 }
#define SCMaxEta
#define SCMaxPhi
int xtalFromEtaPhi(const int &myEta, const int &myPhi)
int writeCMSSWCoeff ( const CLHEP::HepMatrix &  amplMatrix,
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" 
)

to write the file fpr the CMSSW in the DB compliant format (using Energy as reference)

Definition at line 395 of file InvMatrixUtils.cc.

References PVValHelper::eta, PVValHelper::phi, RecoTauValidation_cfi::reference, SCMaxEta, SCMaxPhi, and xtalFromiEtaiPhi().

405 {
406  // open the file for output
407  std::ofstream txt_outfile ;
408  txt_outfile.open (fileName.c_str ()) ;
409  txt_outfile << "1\n" ; // super-module number
410  txt_outfile << "-1\n" ; // number of events
411  txt_outfile << genTag << "\n" ;
412  txt_outfile << method << "\n" ;
413  txt_outfile << version << "\n" ;
414  txt_outfile << type << "\n" ;
415 
416  double reference = ERef ;
417 
418  // loop over crystals
419  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
420  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
421  {
422  if (amplMatrix[eta][phi] <= calibThres)
423  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
424  << "\t" << 1
425  << "\t" << -1
426  << "\t" << -1
427  << "\t" << 0 <<"\n" ;
428  else
429  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
430  << "\t" << reference / amplMatrix[eta][phi]
431  << "\t" << sigmaMatrix[eta][phi]
432  << "\t" << statisticMatrix[eta][phi]
433  << "\t" << 1 <<"\n" ;
434  } // loop over crystals
435 
436  // save and close the file
437  txt_outfile.close () ;
438  return 0 ;
439 }
type
Definition: HCALResponse.h:21
#define SCMaxEta
#define SCMaxPhi
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
int writeCMSSWCoeff ( const CLHEP::HepMatrix &  amplMatrix,
double  calibThres,
int  etaRef,
int  phiRef,
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" 
)

to write the file fpr the CMSSW in the DB compliant format (using Crystal as reference)

Definition at line 445 of file InvMatrixUtils.cc.

References MessageLogger_cfi::cerr, PVValHelper::eta, PVValHelper::phi, RecoTauValidation_cfi::reference, SCMaxEta, SCMaxPhi, and xtalFromiEtaiPhi().

455 {
456  // open the file for output
457  std::ofstream txt_outfile ;
458  txt_outfile.open (fileName.c_str ()) ;
459  txt_outfile << "1\n" ; // super-module number
460  txt_outfile << "-1\n" ; // number of events
461  txt_outfile << genTag << "\n" ;
462  txt_outfile << method << "\n" ;
463  txt_outfile << version << "\n" ;
464  txt_outfile << type << "\n" ;
465 
466  if (amplMatrix[etaRef-1][phiRef-1] == 0)
467  {
468  std::cerr << "The reference crystal: ("
469  << etaRef << "," << phiRef
470  << ") is out of range\n" ;
471  return 1 ;
472  }
473  double reference = amplMatrix[etaRef-1][phiRef-1] ;
474 
475  // loop over crystals
476  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
477  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
478  {
479  if (amplMatrix[eta][phi] <= calibThres)
480  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
481  << "\t" << 1
482  << "\t" << -1
483  << "\t" << -1
484  << "\t" << 0 <<"\n" ;
485  else
486  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
487  << "\t" << reference / amplMatrix[eta][phi]
488  << "\t" << sigmaMatrix[eta][phi]
489  << "\t" << statisticMatrix[eta][phi]
490  << "\t" << 1 <<"\n" ;
491  } // loop over crystals
492 
493  // save and close the file
494  txt_outfile.close () ;
495  return 0 ;
496 }
type
Definition: HCALResponse.h:21
#define SCMaxEta
#define SCMaxPhi
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
int xtalFromEtaPhi ( const int &  myEta,
const int &  myPhi 
)

to get the crystal number from eta and phi

to get the parameters from a congiguration file

Definition at line 243 of file InvMatrixUtils.cc.

References phiFromXtal(), vertices_cff::x, anotherprimaryvertexanalyzer_cfi::xMax, and anotherprimaryvertexanalyzer_cfi::xMin.

Referenced by writeCalibTxt().

244 {
245  int xMin = 20 * myEta + 1 ;
246  int xMax = 20 * (myEta + 1) + 1 ;
247 
248  int myCryst = 999999 ;
249 
250  for (int x = xMin ; x < xMax ; x++)
251  {
252  if (phiFromXtal (x) == myPhi)
253  myCryst = x ;
254  }
255  return myCryst ;
256 }
int phiFromXtal(const int &xtal)
int xtalFromiEtaiPhi ( const int &  iEta,
const int &  iPhi 
)

to get the crystal number from iEta and iPhi iEta runs from 1 to 85 iPhi runs from 1 to 20

Definition at line 262 of file InvMatrixUtils.cc.

Referenced by translateCoeff(), and writeCMSSWCoeff().

263 {
264  assert (iEta >= 1) ;
265  assert (iEta <= 85) ;
266  assert (iPhi >= 1) ;
267  assert (iPhi <= 20) ;
268  return 20 * (iEta-1) + 21 - iPhi ;
269 }