CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
InvMatrixUtils.cc File Reference
#include "Calibration/Tools/interface/InvMatrixUtils.h"
#include "Calibration/Tools/interface/InvMatrixCommonDefs.h"
#include "TStyle.h"
#include "TROOT.h"
#include "CLHEP/Geometry/Point3D.h"
#include "Calibration/Tools/interface/matrixSaver.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <cassert>

Go to the source code of this file.

Functions

double effectiveSigma (TH1F &histogram, int vSteps)
 
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)
 
double get3x3 (const Float_t energy[7][7])
 
double get5x5 (const Float_t energy[7][7])
 
TCanvas * getGlobalCanvas (std::string name)
 
TFile * getGlobalTFile (std::string name)
 
CLHEP::HepMatrix * getSavedMatrix (const std::string &name)
 
int ietaFromXtal (const int &xtal)
 
int iphiFromXtal (const int &xtal)
 
void mtrTransfer (double output[SCMaxEta][SCMaxPhi], CLHEP::HepMatrix *input, double Default)
 
int phiFromXtal (const int &xtal)
 
int readCMSSWcoeff (CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName, double defaultVal)
 
int readCMSSWcoeffForComparison (CLHEP::HepMatrix &calibcoeff, const std::string &inputFileName)
 
int saveGlobalTFile (std::string name)
 
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, const Float_t x0, const Float_t a0, const Float_t sideX, const Float_t sideY)
 
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)
 
int writeCalibTxt (const CLHEP::HepMatrix &AmplitudeMatrix, const CLHEP::HepMatrix &SigmaMatrix, const CLHEP::HepMatrix &StatisticMatrix, std::string fileName)
 
int writeCMSSWCoeff (const CLHEP::HepMatrix &amplMatrix, 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)
 
int writeCMSSWCoeff (const CLHEP::HepMatrix &amplMatrix, double calibThres, int etaRef, int phiRef, const CLHEP::HepMatrix &sigmaMatrix, const CLHEP::HepMatrix &statisticMatrix, std::string fileName, std::string genTag, std::string method, std::string version, std::string 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 762 of file InvMatrixUtils.cc.

References prof2calltree::back, and crabWrap::threshold.

763 {
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 ;
769  double threshold = 0 ;
770  double vStep = maxBinVal / vSteps ;
771  int leftBin = 1 ;
772  int rightBin = totBins - 1 ;
773  //loop over the vertical range
774  while (area/totInt > 0.683)
775  {
776  threshold += vStep ;
777  // loop toward the left
778  for (int back = maxBin ; back > 0 ; --back)
779  {
780  if (histogram.GetBinContent (back) < threshold)
781  {
782  leftBin = back ;
783  break ;
784  }
785  } // loop toward the left
786 
787  // loop toward the right
788  for (int fwd = maxBin ; fwd < totBins ; ++fwd)
789  {
790  if (histogram.GetBinContent (fwd) < threshold)
791  {
792  rightBin = fwd ;
793  break ;
794  }
795  } // loop toward the right
796  area = histogram.Integral (leftBin,rightBin) ;
797  } //loop over the vertical range
798 
799  histogram.GetXaxis ()->SetRange (leftBin,rightBin) ;
800  // double sigmaEff = histogram.GetRMS () ;
801  double halfWidthRange = 0.5 * (histogram.GetBinCenter (rightBin) - histogram.GetBinCenter (leftBin)) ;
802  return halfWidthRange ;
803 }
float threshold
Definition: crabWrap.py:319
double etaCorrE1E25 ( int  eta)

correction for eta containment for 5*5 cluster

Definition at line 859 of file InvMatrixUtils.cc.

References corr, eta(), p1, p2, p3, and p4.

860 {
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 ;
866 
867  double corr ;
868  if (eta < 6) corr = p0 ;
869  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
870  return corr/p0 ;
871 }
T eta() const
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:9
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 874 of file InvMatrixUtils.cc.

References corr, eta(), p1, p2, p3, and p4.

875 {
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 ;
881 
882  double corr ;
883  if (eta < 8) corr = p0 ;
884  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
885  return corr/p0 ;
886 }
T eta() const
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:9
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 889 of file InvMatrixUtils.cc.

References corr, eta(), p1, p2, p3, and p4.

890 {
891  if (eta < 4) return 1.0 ;
892  // grazie Paolo
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 ;
898 
899  double corr ;
900  if (eta < 6) corr = p0 ;
901  else corr = p0 + p1*eta + p2*eta*eta + p3*eta*eta*eta + p4*eta*eta*eta*eta;
902  return corr/p0 ;
903 }
T eta() const
double p4[4]
Definition: TauolaWrapper.h:92
double p2[4]
Definition: TauolaWrapper.h:90
JetCorrectorParameters corr
Definition: classes.h:9
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 279 of file InvMatrixUtils.cc.

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

280 {
281 // return floor (static_cast<double> ((xtal-1) / 20)) ;
282  return int (floor ((xtal-1) / 20) );
283 }
int extract ( std::vector< int > *  output,
const std::string &  dati 
)
to read a file containing unserted integers

while avoiding comment lines

Definition at line 317 of file InvMatrixUtils.cc.

Referenced by SiStripCalibLorentzAngle::algoBeginJob(), CalibrationHistosUsingDb::CalibrationHistosUsingDb(), reco::tau::disc::ChargedOutlierAngle(), reco::tau::disc::ChargedOutlierPt(), clone(), CommissioningTask::HistoSet::histo(), OptoScanHistograms::histoAnalysis(), PedestalsHistograms::histoAnalysis(), ApvTimingHistograms::histoAnalysis(), PedsFullNoiseHistograms::histoAnalysis(), FastFedCablingHistograms::histoAnalysis(), PedsOnlyHistograms::histoAnalysis(), VpspScanHistograms::histoAnalysis(), NoiseHistograms::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(), 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(), PedsOnlyTask::update(), NoiseTask::update(), PedsFullNoiseTask::update(), and CommissioningTask::updateHistoSet().

318  {
319  std::ifstream _dati (dati.c_str ()) ;
320  // loop over the file
321  while (!_dati.eof())
322  {
323  // get the line
324  std::string dataline ;
325  do { getline (_dati, dataline,'\n') ; }
326  while (*dataline.begin () == '#') ;
327  std::stringstream linea (dataline) ;
328  // loop over the line
329  while (!linea.eof ())
330  {
331  int buffer = -1 ;
332  linea >> buffer ;
333  if (buffer != -1) output->push_back (buffer) ;
334  } // loop over the line
335  } // loop over the file
336  return output->size () ;
337  }
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 809 of file InvMatrixUtils.cc.

References newFWLiteAna::bin.

810 {
811  int totBins = histogram.GetNbinsX () ;
812  if (thres >= histogram.GetMaximum ())
813  return std::pair<int,int> (0, totBins) ;
814 
815  int leftBin = totBins - 1 ;
816  // search from left for the minimum
817  for (int bin=1 ; bin<totBins ; ++bin)
818  {
819  if (histogram.GetBinContent (bin) > thres)
820  {
821  leftBin = bin ;
822  break ;
823  }
824  } // search from left for the minimum
825  int rightBin = 1 ;
826  // search from right for the maximum
827  for (int bin=totBins - 1 ; bin> 0 ; --bin)
828  {
829  if (histogram.GetBinContent (bin) > thres)
830  {
831  rightBin = bin ;
832  break ;
833  }
834  } // search from right for the maximum
835  return std::pair<int,int> (leftBin,rightBin) ;
836 }
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 203 of file InvMatrixUtils.cc.

References eta(), phi, and pileupDistInMC::total.

Referenced by TBposition().

204 {
205  double total = 0. ;
206 
207  for (int eta=2 ; eta<5 ; ++eta)
208  for (int phi=2 ; phi<5 ; ++phi)
209  total += energy[eta][phi] ;
210 
211  return total ;
212 }
T eta() const
Definition: DDAxes.h:10
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 186 of file InvMatrixUtils.cc.

References eta(), phi, and pileupDistInMC::total.

187 {
188  double total = 0. ;
189 
190  for (int eta=1 ; eta<6 ; ++eta)
191  for (int phi=1 ; phi<6 ; ++phi)
192  total += energy[eta][phi] ;
193 
194  return total ;
195 }
T eta() const
Definition: DDAxes.h:10
TCanvas* getGlobalCanvas ( std::string  name = "Inv MatrixCanvas")
search for an existing canvas with the name 

and returns the poiter to it

Definition at line 46 of file InvMatrixUtils.cc.

References setStyle().

47 {
48  setStyle () ;
49  TCanvas * globalCanvas = static_cast<TCanvas*>
50  (gROOT->FindObject (name.c_str ())) ;
51  if (globalCanvas)
52  {
53  globalCanvas->Clear () ;
54  globalCanvas->UseCurrentStyle () ;
55  globalCanvas->SetWindowSize (700, 600) ;
56 
57  }
58  else
59  {
60  globalCanvas = new TCanvas (name.c_str (),name.c_str (), 700, 600) ;
61  }
62  return globalCanvas ;
63 }
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 68 of file InvMatrixUtils.cc.

69 {
70 // std::cout << "writing " << name << std::endl ;
71 // setStyle () ;
72  TFile * globalTFile = (TFile*) gROOT->FindObject (name.c_str()) ;
73  if (!globalTFile)
74  {
75 // std::cout << "does not exist. creating it " << std::endl;
76  globalTFile = new TFile (name.c_str(),"RECREATE") ;
77  }
78 
79  return globalTFile ;
80 }
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 101 of file InvMatrixUtils.cc.

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

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

get the eta coord [1,85]

Definition at line 299 of file InvMatrixUtils.cc.

References etaFromXtal().

300 {
301  return etaFromXtal (xtal) + 1 ;
302 }
int etaFromXtal(const int &xtal)
int iphiFromXtal ( const int &  xtal)

get the phi coord [1,20]

Definition at line 308 of file InvMatrixUtils.cc.

References phiFromXtal().

309 {
310  return phiFromXtal (xtal) + 1 ;
311 }
int phiFromXtal(const int &xtal)
void mtrTransfer ( double  output[SCMaxEta][SCMaxPhi],
CLHEP::HepMatrix *  input,
double  Default 
)

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

Definition at line 843 of file InvMatrixUtils.cc.

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

846 {
847  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
848  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
849  {
850  if ((*input)[eta][phi])
851  output[eta][phi] = (*input)[eta][phi] ;
852  else output[eta][phi] = Default ;
853  }
854  return ;
855 }
#define SCMaxEta
#define Default
Definition: vmac.h:109
#define SCMaxPhi
T eta() const
return((rh^lh)&mask)
tuple input
Definition: collect_tpl.py:10
Definition: DDAxes.h:10
int phiFromXtal ( const int &  xtal)

get the phi coord [0,19]

Definition at line 289 of file InvMatrixUtils.cc.

References etaFromXtal(), and phi.

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

290 {
291  int phi = (xtal-1) - 20 * etaFromXtal (xtal) ;
292  return (20 - phi - 1) ;
293 }
int etaFromXtal(const int &xtal)
Definition: DDAxes.h:10
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 563 of file InvMatrixUtils.cc.

References etaFromXtal(), and phiFromXtal().

566 {
567  std::ifstream CMSSWfile ;
568  CMSSWfile.open (inputFileName.c_str ()) ;
569  std::string buffer ;
570  CMSSWfile >> buffer ;
571  CMSSWfile >> buffer ;
572  CMSSWfile >> buffer ;
573  CMSSWfile >> buffer ;
574  CMSSWfile >> buffer ;
575  CMSSWfile >> buffer ;
576  while (!CMSSWfile.eof ())
577  {
578  int xtalnum ;
579  CMSSWfile >> xtalnum ;
580  double coeff ;
581  CMSSWfile >> coeff ;
582  double buffer ;
583  CMSSWfile >> buffer ;
584  int good ;
585  CMSSWfile >> good ;
586  CMSSWfile >> good ;
587  if (!good) coeff = defaultVal ; //FIXME 0 o 1?
588  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
589  }
590  return 0 ;
591 
592 }
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 598 of file InvMatrixUtils.cc.

References etaFromXtal(), and phiFromXtal().

600 {
601  std::ifstream CMSSWfile ;
602  CMSSWfile.open (inputFileName.c_str ()) ;
603  std::string buffer ;
604  CMSSWfile >> buffer ;
605  CMSSWfile >> buffer ;
606  CMSSWfile >> buffer ;
607  CMSSWfile >> buffer ;
608  CMSSWfile >> buffer ;
609  CMSSWfile >> buffer ;
610  while (!CMSSWfile.eof ())
611  {
612  int xtalnum ;
613  CMSSWfile >> xtalnum ;
614  double coeff ;
615  CMSSWfile >> coeff ;
616  double buffer ;
617  CMSSWfile >> buffer ;
618  int good ;
619  CMSSWfile >> good ;
620  CMSSWfile >> good ;
621  if (!good) coeff = 0. ; //FIXME 0 o 1?
622  calibcoeff[etaFromXtal (xtalnum)][phiFromXtal (xtalnum)] = coeff ;
623  }
624  return 0 ;
625 
626 }
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 86 of file InvMatrixUtils.cc.

87 {
88  TFile * globalTFile = static_cast<TFile*>
89  (gROOT->FindObject (name.c_str ())) ;
90  if (!globalTFile) return 1 ;
91  globalTFile->Write () ;
92  globalTFile->Close () ;
93  delete globalTFile ;
94  return 0 ;
95 }
void setStyle ( )
Date:
2008/03/10 13:54:05
Revision:
1.3
Id:
InvMatrixUtils.cc,v 1.3 2008/03/10 13:54:05 elmer Exp
Author
Author:
elmer

set the style for the printout

Definition at line 24 of file InvMatrixUtils.cc.

References mathSSE::return().

Referenced by getGlobalCanvas().

25 {
26  gROOT->SetStyle ("Plain") ;
27  gStyle->SetTextSize(0.5);
28  //gStyle->SetOptStat (1111111) ;
29  gStyle->SetOptStat (0) ;
30  //gStyle->SetOptFit (1111) ;
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) ;
39  return ;
40 }
return((rh^lh)&mask)
TH1D* smartError ( TH1D *  strip)

Definition at line 735 of file InvMatrixUtils.cc.

References newFWLiteAna::bin, error, and AlCaRecoCosmics_cfg::name.

736 {
737 
738  double xmin = strip->GetXaxis ()->GetXmin () ;
739  double xmax = strip->GetXaxis ()->GetXmax () ;
740  int stripsBins = strip->GetNbinsX () ;
741 
742  std::string name = strip->GetName () ;
743  name += "_error" ;
744  TH1D * error = new TH1D
745  (name.c_str (),strip->GetTitle (),stripsBins,xmin,xmax) ;
746 
747  int binmin = 1 ;
748  int ngroup = 1 ; // bins per step
749  int binmax = stripsBins ;
750  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
751  {
752  double dummyError = strip->GetBinError (bin) ;
753  error->SetBinContent (bin,dummyError) ;
754  }
755  return error;
756 }
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
TH1D* smartGausProfile ( TH2F *  strip,
double  width 
)

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

Definition at line 680 of file InvMatrixUtils.cc.

References newFWLiteAna::bin, align_tpl::cut, AlCaRecoCosmics_cfg::name, and ExpressReco_HICollisions_FallBack::nbins.

681 {
682  TProfile * stripProfile = strip->ProfileX () ;
683 
684  // (from FitSlices of TH2.h)
685 
686  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
687  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
688  int profileBins = stripProfile->GetNbinsX () ;
689 
690  std::string name = strip->GetName () ;
691  name += "_smartGaus" ;
692  TH1D * prof = new TH1D
693  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
694 
695  int cut = 0 ; // minimum number of entries per fitted bin
696  int nbins = strip->GetXaxis ()->GetNbins () ;
697  int binmin = 1 ;
698  int ngroup = 1 ; // bins per step
699  int binmax = nbins ;
700 
701  // loop over the strip bins
702  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
703  {
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 ;}
708 
709  Int_t biny = bin + ngroup/2 ;
710 
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") ;
716 
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)) ;
722 
723  delete gaussian ;
724  delete hpy ;
725  } // loop over the bins
726 
727  delete stripProfile ;
728  return prof ;
729 }
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
tuple cut
Definition: align_tpl.py:88
TH1D* smartProfile ( TH2F *  strip,
double  width 
)

smart profiling by double averaging

Definition at line 632 of file InvMatrixUtils.cc.

References newFWLiteAna::bin, align_tpl::cut, AlCaRecoCosmics_cfg::name, and ExpressReco_HICollisions_FallBack::nbins.

633 {
634  TProfile * stripProfile = strip->ProfileX () ;
635 
636  // (from FitSlices of TH2.h)
637 
638  double xmin = stripProfile->GetXaxis ()->GetXmin () ;
639  double xmax = stripProfile->GetXaxis ()->GetXmax () ;
640  int profileBins = stripProfile->GetNbinsX () ;
641 
642  std::string name = strip->GetName () ;
643  name += "_smart" ;
644  TH1D * prof = new TH1D
645  (name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ;
646 
647  int cut = 0 ; // minimum number of entries per fitted bin
648  int nbins = strip->GetXaxis ()->GetNbins () ;
649  int binmin = 1 ;
650  int ngroup = 1 ; // bins per step
651  int binmax = nbins ;
652 
653  // loop over the strip bins
654  for (int bin=binmin ; bin<=binmax ; bin += ngroup)
655  {
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 ;}
660 
661  Int_t biny = bin + ngroup/2 ;
662 
663  hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (),
664  hpy->GetMean () + width * hpy->GetRMS ()) ;
665  prof->Fill (strip->GetXaxis ()->GetBinCenter (biny),
666  hpy->GetMean ()) ;
667  prof->SetBinError (biny,hpy->GetRMS()) ;
668 
669  delete hpy ;
670  } // loop over the bins
671 
672  delete stripProfile ;
673  return prof ;
674 }
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
tuple cut
Definition: align_tpl.py:88
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 135 of file InvMatrixUtils.cc.

References eta(), get3x3(), funct::log(), phi, TBposition(), and CommonMethods::weight().

Referenced by TBposition().

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

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

516 {
517  // open the file for output
518  std::ofstream txt_outfile ;
519  txt_outfile.open (fileName.c_str ()) ;
520  txt_outfile << SMnumber << "\n" ; // super-module number
521  txt_outfile << "-1\n" ; // number of events
522  txt_outfile << genTag << "\n" ;
523  txt_outfile << method << "\n" ;
524  txt_outfile << version << "\n" ;
525  txt_outfile << type << "\n" ;
526 
527  // loop over crystals
528  for (int eta = 0 ; eta < SCMaxEta ; ++eta)
529  for (int phi = 0 ; phi < SCMaxPhi ; ++phi)
530  {
531  if (calibcoeff[eta][phi] < calibThres)
532  {
533  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
534  << "\t" << 1
535  << "\t" << -1
536  << "\t" << -1
537  << "\t" << 0 <<"\n" ;
538  std::cout << "[translateCoefff][" << SMnumber
539  << "]\t WARNING crystal " << xtalFromiEtaiPhi (eta+1,phi+1)
540  << " calib coeff below threshold: "
541  << "\t" << 1
542  << "\t" << -1
543  << "\t" << -1
544  << "\t" << 0 <<"\n" ;
545  }
546  else
547  txt_outfile << xtalFromiEtaiPhi (eta+1,phi+1)
548  << "\t" << calibcoeff[eta][phi]
549  << "\t" << sigmaMatrix[eta][phi]
550  << "\t" << statisticMatrix[eta][phi]
551  << "\t" << 1 <<"\n" ;
552  } // loop over crystals
553 
554  // save and close the file
555  txt_outfile.close () ;
556  return 0 ;
557 }
type
Definition: HCALResponse.h:22
#define SCMaxEta
int xtalFromiEtaiPhi(const int &iEta, const int &iPhi)
#define SCMaxPhi
T eta() const
tuple cout
Definition: gather_cfg.py:41
Definition: DDAxes.h:10
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 345 of file InvMatrixUtils.cc.

References ExpressReco_HICollisions_FallBack::cerr, gather_cfg::cout, eta(), phi, SCMaxEta, SCMaxPhi, and xtalFromEtaPhi().

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

References eta(), phi, SCMaxEta, SCMaxPhi, and xtalFromiEtaiPhi().

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

References ExpressReco_HICollisions_FallBack::cerr, eta(), phi, SCMaxEta, SCMaxPhi, and xtalFromiEtaiPhi().

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

to get the parameters from a congiguration file

Definition at line 247 of file InvMatrixUtils.cc.

References phiFromXtal(), and ExpressReco_HICollisions_FallBack::x.

Referenced by writeCalibTxt().

248 {
249  int xMin = 20 * myEta + 1 ;
250  int xMax = 20 * (myEta + 1) + 1 ;
251 
252  int myCryst = 999999 ;
253 
254  for (int x = xMin ; x < xMax ; x++)
255  {
256  if (phiFromXtal (x) == myPhi)
257  myCryst = x ;
258  }
259  return myCryst ;
260 }
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 266 of file InvMatrixUtils.cc.

Referenced by translateCoeff(), and writeCMSSWCoeff().

267 {
268  assert (iEta >= 1) ;
269  assert (iEta <= 85) ;
270  assert (iPhi >= 1) ;
271  assert (iPhi <= 20) ;
272  return 20 * (iEta-1) + 21 - iPhi ;
273 }