CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes
MuonErrorMatrix Class Reference

#include <MuonErrorMatrix.h>

Public Types

enum  action { use, constructor }
 enum type to define if the class is used as a tool or to be created More...
 

Public Member Functions

void adjust (FreeTrajectoryState &state)
 adjust the error matrix on the state More...
 
void adjust (TrajectoryStateOnSurface &state)
 adjust the error matrix on the state More...
 
void close ()
 close the root file attached to the class More...
 
void complicatedTerm (const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
 convert sigma/rho -> sigma2/COV More...
 
int findBin (TAxis *axis, double value)
 method to get the bin index, taking care of under/overlow: first(1)/last(GetNbins())returned More...
 
CurvilinearTrajectoryError get (GlobalVector momentum, bool convolute=true)
 main method to be used. Retrieve a 5x5 symetrical matrix according to parametrization of error or scale factor More...
 
TProfile3D * get (int i, int j)
 actually get access to the TProfile3D used for the parametrization More...
 
CurvilinearTrajectoryError getFast (GlobalVector momentum)
 
unsigned int index (int i, int j)
 
 MuonErrorMatrix (const edm::ParameterSet &pset)
 constructor from a parameter set More...
 
void simpleTerm (const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
 convert sigma2/COV -> sigma/rho More...
 
 ~MuonErrorMatrix ()
 destructor More...
 

Static Public Member Functions

static bool divide (CurvilinearTrajectoryError &num_error, const CurvilinearTrajectoryError &denom_error)
 divide term by term the two matrix More...
 
static void multiply (CurvilinearTrajectoryError &initial_error, const CurvilinearTrajectoryError &scale_error)
 multiply term by term the two matrix More...
 
static double Term (const AlgebraicSymMatrix55 &curv, int i, int j)
 provide the numerical value used. sigma or correlation factor More...
 

Static Public Attributes

static const TString vars [5] = {"#frac{q}{|p|}", "#lambda", "#varphi_{0}", "X_{T}", "Y_{T}"}
 names of the variables of the 5x5 error matrix More...
 

Private Types

enum  TermAction { error, scale, assign }
 decide whether to scale of to assigne terms More...
 

Private Member Functions

TProfile3D * Index (int i, int j)
 internal method to get access to the profiles More...
 
int Pindex (int i, int j)
 internal methods to get the index of a matrix term. More...
 
double Rms (GlobalVector &momentum, int i, int j)
 internal method that retreives the error on the value of the parametrization for term i,j More...
 
double Value (GlobalVector &momentum, int i, int j, bool convolute=true)
 internal method that retreives the value of the parametrization for term i,j More...
 

Private Attributes

std::string theCategory
 log category: "MuonErrorMatrix" More...
 
TDirectory * theD
 the attached root file, where the parametrization is saved More...
 
TProfile3D * theData [15]
 15 TProfile, each holding he parametrization of each term of the 5x5 More...
 
TProfile3D * theData_fast [5][5]
 
TermAction theTermAction [15]
 

Detailed Description

This class holds an error matrix paramertization. Either the error matrix value or scale factors. The implementation uses TProfile3D with pt, eta, phi axis. Error/Scale factor matrix is obtained using get(GlobalVector momentum)

Author
Jean-Roch Vlimant UCSB
Finn Rebassoo UCSB

Definition at line 24 of file MuonErrorMatrix.h.

Member Enumeration Documentation

enum type to define if the class is used as a tool or to be created

Enumerator
use 
constructor 

Definition at line 27 of file MuonErrorMatrix.h.

decide whether to scale of to assigne terms

Enumerator
error 
scale 
assign 

Definition at line 83 of file MuonErrorMatrix.h.

Constructor & Destructor Documentation

MuonErrorMatrix::MuonErrorMatrix ( const edm::ParameterSet pset)

constructor from a parameter set

Definition at line 17 of file MuonErrorMatrix.cc.

References a, assign, constructor, data, TrackerOfflineValidation_Dqm_cff::dirName, error, HLT_2018_cff::errorMatrixValuesPSet, edm::ParameterSet::exists(), beamvalidation::exit(), MillePedeFileConverter_cfg::fileName, edm::FileInPath::fullPath(), reco_skim_cfg_mod::fullpath, edm::ParameterSet::getParameter(), mps_fire::i, dqmiolumiharvest::j, LogDebug, LogTrace, maxEta, HLT_2018_cff::maxPhi, MuonErrorMatrixAnalyzer_cfi::maxPt, ticl::constants::minEta, HLT_2018_cff::minPhi, beam_dqm_sourceclient-live_cfg::minPt, MuonErrorMatrixAnalyzer_cfi::NEta, MuonErrorMatrixAnalyzer_cfi::NPhi, MuonErrorMatrixAnalyzer_cfi::NPt, packedPFCandidateRefMixer_cfi::pf, Pi, Pindex(), scale, str, AlCaHLTBitMon_QueryRunRegistry::string, theCategory, theD, theData, theData_fast, theTermAction, use, contentValuesCheck::values, multiplicitycorr_cfi::xBins, and multiplicitycorr_cfi::yBins.

17  : theD(nullptr) {
18  theCategory = "MuonErrorMatrix";
19  std::string action = iConfig.getParameter<std::string>("action");
20 
21  bool madeFromCff = iConfig.exists("errorMatrixValuesPSet");
23 
25  if (!madeFromCff) {
26  fileName = iConfig.getParameter<std::string>("rootFileName");
27  } else {
28  errorMatrixValuesPSet = iConfig.getParameter<edm::ParameterSet>("errorMatrixValuesPSet");
29  }
31 
32  int NPt = 5;
33  std::vector<double> xBins;
34  double *xBinsArray = nullptr;
35  double minPt = 1;
36  double maxPt = 200;
37  int NEta = 5;
38  std::vector<double> yBins;
39  double *yBinsArray = nullptr;
40  double minEta = 0;
41  double maxEta = 2.5;
42  int NPhi = 1;
43  double minPhi = -TMath::Pi();
44  double maxPhi = TMath::Pi();
45 
46  if (action != "use") {
47  a = constructor;
48 
49  NPt = iConfig.getParameter<int>("NPt");
50  if (NPt != 0) {
51  minPt = iConfig.getParameter<double>("minPt");
52  maxPt = iConfig.getParameter<double>("maxPt");
53  } else {
54  xBins = iConfig.getParameter<std::vector<double> >("PtBins");
55  if (xBins.empty()) {
56  edm::LogError(theCategory) << "Npt=0 and no entries in the vector. I will do aseg fault soon.";
57  }
58  NPt = xBins.size() - 1;
59  xBinsArray = &(xBins.front());
60  minPt = xBins.front();
61  maxPt = xBins.back();
62  }
63 
64  NEta = iConfig.getParameter<int>("NEta");
65  if (NEta != 0) {
66  minEta = iConfig.getParameter<double>("minEta");
67  maxEta = iConfig.getParameter<double>("maxEta");
68  } else {
69  yBins = iConfig.getParameter<std::vector<double> >("EtaBins");
70  if (yBins.empty()) {
71  edm::LogError(theCategory) << "NEta=0 and no entries in the vector. I will do aseg fault soon.";
72  }
73  NEta = yBins.size() - 1;
74  yBinsArray = &(yBins.front());
75  minEta = yBins.front();
76  maxEta = yBins.back();
77  }
78 
79  NPhi = iConfig.getParameter<int>("NPhi");
80  std::stringstream get(iConfig.getParameter<std::string>("minPhi"));
81  if (get.str() == "-Pi") {
82  minPhi = -TMath::Pi();
83  } else if (get.str() == "Pi") {
84  minPhi = TMath::Pi();
85  } else {
86  get >> minPhi;
87  }
88  get.str(iConfig.getParameter<std::string>("maxPhi"));
89  if (get.str() == "-Pi") {
90  maxPhi = -TMath::Pi();
91  } else if (get.str() == "Pi") {
92  maxPhi = TMath::Pi();
93  } else {
94  get >> maxPhi;
95  }
96  } //action!=use
97  else if (madeFromCff) {
98  xBins = errorMatrixValuesPSet.getParameter<std::vector<double> >("xAxis");
99  NPt = xBins.size() - 1;
100  xBinsArray = &(xBins.front());
101  minPt = xBins.front();
102  maxPt = xBins.back();
103 
104  yBins = errorMatrixValuesPSet.getParameter<std::vector<double> >("yAxis");
105  NEta = yBins.size() - 1;
106  yBinsArray = &(yBins.front());
107  minEta = yBins.front();
108  maxEta = yBins.back();
109 
110  std::vector<double> zBins = errorMatrixValuesPSet.getParameter<std::vector<double> >("zAxis");
111  NPhi = 1;
112  if (zBins.size() != 2) {
113  edm::LogError(theCategory) << "please specify a zAxis with 2 entries only. more bins not implemented yet.";
114  }
115  minPhi = zBins.front();
116  maxPhi = zBins.back();
117  }
118 
119  if (a == use) {
120  if (!madeFromCff) {
121  edm::LogInfo(theCategory) << "using an error matrix object from: " << fileName;
122  edm::FileInPath data(fileName);
123  std::string fullpath = data.fullPath();
124  gROOT->cd();
125  theD = new TFile(fullpath.c_str());
126  theD->SetWritable(false);
127  } else {
128  static std::atomic<unsigned int> neverTheSame{0};
129  std::stringstream dirName("MuonErrorMatrixDirectory");
130  dirName << neverTheSame++;
132  << "using an error matrix object from configuration file. putting memory histograms to: " << dirName.str();
133  gROOT->cd();
134  theD = new TDirectory(dirName.str().c_str(), "transient directory to host MuonErrorMatrix TProfile3D");
135  theD->SetWritable(false);
136  }
137  } else {
138  edm::LogInfo(theCategory) << "creating an error matrix object: " << fileName;
139  theD = new TFile(fileName.c_str(), "recreate");
140  }
141 
142  if (a == use && !madeFromCff) {
143  gROOT->cd();
144  } else {
145  theD->cd();
146  }
147 
148  for (int i = 0; i != 5; i++) {
149  for (int j = i; j != 5; j++) {
150  TString pfname(Form("pf3_V%1d%1d", i + 1, j + 1));
151  TProfile3D *pf = nullptr;
152  if (a == use && !madeFromCff) {
153  //read from the rootfile
154  edm::LogVerbatim(theCategory) << "getting " << pfname << " from " << fileName;
155  pf = (TProfile3D *)theD->Get(pfname);
156  theData[Pindex(i, j)] = pf;
157  theData_fast[i][j] = pf;
158  theData_fast[j][i] = pf;
159  } else {
160  // curvilinear coordinate system
161  //need to make some input parameter to be to change the number of bins
162 
163  TString pftitle;
164  if (i == j) {
165  pftitle = "#sigma_{" + vars[i] + "}";
166  } else {
167  pftitle = "#rho(" + vars[i] + "," + vars[j] + ")";
168  }
169  edm::LogVerbatim(theCategory) << "booking " << pfname << " into " << fileName;
170  pf = new TProfile3D(pfname, pftitle, NPt, minPt, maxPt, NEta, minEta, maxEta, NPhi, minPhi, maxPhi, "S");
171  pf->SetXTitle("muon p_{T} [GeV]");
172  pf->SetYTitle("muon |#eta|");
173  pf->SetZTitle("muon #varphi");
174 
175  //set variable size binning
176  if (xBinsArray) {
177  pf->GetXaxis()->Set(NPt, xBinsArray);
178  }
179  if (yBinsArray) {
180  pf->GetYaxis()->Set(NEta, yBinsArray);
181  }
182 
183  if (madeFromCff) {
184  edm::ParameterSet pSet = errorMatrixValuesPSet.getParameter<edm::ParameterSet>(pfname.Data());
185  //set the values from the configuration file itself
186  std::vector<double> values = pSet.getParameter<std::vector<double> >("values");
187  unsigned int iX = pf->GetNbinsX();
188  unsigned int iY = pf->GetNbinsY();
189  unsigned int iZ = pf->GetNbinsZ();
190  unsigned int continuous_i = 0;
191  for (unsigned int ix = 1; ix <= iX; ++ix) {
192  for (unsigned int iy = 1; iy <= iY; ++iy) {
193  for (unsigned int iz = 1; iz <= iZ; ++iz) {
194  LogTrace(theCategory) << "filling profile:"
195  << "\n pt (x)= " << pf->GetXaxis()->GetBinCenter(ix)
196  << "\n eta (y)= " << pf->GetYaxis()->GetBinCenter(iy)
197  << "\n phi (z)= " << pf->GetZaxis()->GetBinCenter(iz)
198  << "\n value= " << values[continuous_i];
199  pf->Fill(pf->GetXaxis()->GetBinCenter(ix),
200  pf->GetYaxis()->GetBinCenter(iy),
201  pf->GetZaxis()->GetBinCenter(iz),
202  values[continuous_i++]);
203  }
204  }
205  }
206  //term action
207  std::string tAction = pSet.getParameter<std::string>("action");
208  if (tAction == "scale")
210  else if (tAction == "assign")
212  else {
213  edm::LogError(theCategory) << " wrong configuration: term action: " << tAction << " is not recognized.";
215  }
216  }
217  }
218 
219  LogDebug(theCategory) << " index " << i << ":" << j << " -> " << Pindex(i, j);
220  theData[Pindex(i, j)] = pf;
221  theData_fast[i][j] = pf;
222  theData_fast[j][i] = pf;
223  if (!pf) {
224  edm::LogError(theCategory) << " profile " << pfname << " in file " << fileName << " is not valid. exiting.";
225  exit(1);
226  }
227  }
228  }
229 
230  //verify it
231  for (int i = 0; i != 15; i++) {
232  if (theData[i]) {
233  edm::LogVerbatim(theCategory) << i << " :" << theData[i]->GetName() << " " << theData[i]->GetTitle() << std::endl;
234  }
235  }
236 }
#define LogDebug(id)
const double Pi
T getParameter(std::string const &) const
constexpr float minEta
Definition: Common.h:9
double maxEta
action
enum type to define if the class is used as a tool or to be created
TermAction theTermAction[15]
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
#define LogTrace(id)
TProfile3D * theData_fast[5][5]
NEta
set NEta=0 and the vector of double for variable size binning
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
TDirectory * theD
the attached root file, where the parametrization is saved
double a
Definition: hdecay.h:119
vars
Definition: DeepTauId.cc:158
TProfile3D * theData[15]
15 TProfile, each holding he parametrization of each term of the 5x5
#define str(s)
std::string theCategory
log category: "MuonErrorMatrix"
def exit(msg="")
MuonErrorMatrix::~MuonErrorMatrix ( )

destructor

Definition at line 256 of file MuonErrorMatrix.cc.

References close().

256 { close(); }
void close()
close the root file attached to the class

Member Function Documentation

void MuonErrorMatrix::adjust ( FreeTrajectoryState state)

adjust the error matrix on the state

Definition at line 502 of file MuonErrorMatrix.cc.

References assign, complicatedTerm(), FreeTrajectoryState::curvilinearError(), error, mps_fire::i, dqmiolumiharvest::j, LogDebug, makeMuonMisalignmentScenario::matrix, FreeTrajectoryState::momentum(), FreeTrajectoryState::parameters(), Pindex(), scale, simpleTerm(), theCategory, and theTermAction.

Referenced by TSGForRoadSearch::IPfts(), and TSGForRoadSearch::notAtIPtsos().

502  {
503  LogDebug(theCategory + "|Adjust") << "state: \n" << state;
504  AlgebraicSymMatrix55 simpleTerms;
505  simpleTerm(state.curvilinearError(), simpleTerms);
506  //the above contains sigma(i), rho(i,j)
507  LogDebug(theCategory + "|Adjust") << "state sigma(i), rho(i,j): \n" << simpleTerms;
508 
509  AlgebraicSymMatrix55 simpleValues = get(state.momentum(), false).matrix();
510  LogDebug(theCategory + "|Adjust") << "config: (i,i), (i,j): \n" << simpleValues;
511 
512  for (int i = 0; i != 5; i++) {
513  for (int j = i; j != 5; j++) {
514  //check on each term for desired action
515  switch (theTermAction[Pindex(i, j)]) {
516  case scale: {
517  simpleTerms(i, j) *= simpleValues(i, j);
518  break;
519  }
520  case assign: {
521  simpleTerms(i, j) = simpleValues(i, j);
522  break;
523  }
524  case error: {
525  edm::LogError(theCategory + "|Adjust") << " cannot properly adjust for term: " << i << "," << j;
526  }
527  }
528  }
529  }
530  LogDebug(theCategory + "|Adjust") << "updated state sigma(i), rho(i,j): \n" << simpleTerms;
531 
532  AlgebraicSymMatrix55 finalTerms;
533  complicatedTerm(simpleTerms, finalTerms);
534  LogDebug(theCategory + "|Adjust") << "updated state COV(i,j): \n" << finalTerms;
535 
536  CurvilinearTrajectoryError oMat(finalTerms);
537  state = FreeTrajectoryState(state.parameters(), oMat);
538  LogDebug(theCategory + "|Adjust") << "updated state:\n" << state;
539 }
#define LogDebug(id)
const GlobalTrajectoryParameters & parameters() const
const CurvilinearTrajectoryError & curvilinearError() const
void complicatedTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma/rho -> sigma2/COV
TermAction theTermAction[15]
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
GlobalVector momentum() const
void simpleTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma2/COV -> sigma/rho
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::string theCategory
log category: "MuonErrorMatrix"
void MuonErrorMatrix::adjust ( TrajectoryStateOnSurface state)

adjust the error matrix on the state

Definition at line 541 of file MuonErrorMatrix.cc.

References assign, complicatedTerm(), TrajectoryStateOnSurface::curvilinearError(), error, TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalParameters(), mps_fire::i, dqmiolumiharvest::j, LogDebug, makeMuonMisalignmentScenario::matrix, Pindex(), scale, simpleTerm(), TrajectoryStateOnSurface::surface(), TrajectoryStateOnSurface::surfaceSide(), theCategory, theTermAction, and TrajectoryStateOnSurface::weight().

541  {
542  AlgebraicSymMatrix55 simpleTerms;
543  simpleTerm(state.curvilinearError(), simpleTerms);
544  LogDebug(theCategory + "|Adjust") << "state sigma(i), rho(i,j): \n" << simpleTerms;
545 
546  AlgebraicSymMatrix55 simpleValues = get(state.globalMomentum(), false).matrix();
547  LogDebug(theCategory + "|Adjust") << "config: (i,i), (i,j):\n" << simpleValues;
548 
549  for (int i = 0; i != 5; i++) {
550  for (int j = i; j != 5; j++) {
551  //check on each term for desired action
552  switch (theTermAction[Pindex(i, j)]) {
553  case scale: {
554  simpleTerms(i, j) *= simpleValues(i, j);
555  break;
556  }
557  case assign: {
558  simpleTerms(i, j) = simpleValues(i, j);
559  break;
560  }
561  case error: {
562  edm::LogError(theCategory + "|Adjust") << " cannot properly adjust for term: " << i << "," << j;
563  }
564  }
565  }
566  }
567  LogDebug(theCategory + "|Adjust") << "updated state sigma(i), rho(i,j): \n" << simpleTerms;
568 
569  AlgebraicSymMatrix55 finalTerms;
570  complicatedTerm(simpleTerms, finalTerms);
571  LogDebug(theCategory + "|Adjust") << "updated state COV(i,j): \n" << finalTerms;
572 
573  CurvilinearTrajectoryError oMat(finalTerms);
574  state =
575  TrajectoryStateOnSurface(state.weight(), state.globalParameters(), oMat, state.surface(), state.surfaceSide());
576  LogDebug(theCategory + "|Adjust") << "updated state:\n" << state;
577 }
#define LogDebug(id)
const CurvilinearTrajectoryError & curvilinearError() const
const SurfaceType & surface() const
void complicatedTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma/rho -> sigma2/COV
TermAction theTermAction[15]
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
const GlobalTrajectoryParameters & globalParameters() const
void simpleTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma2/COV -> sigma/rho
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
GlobalVector globalMomentum() const
std::string theCategory
log category: "MuonErrorMatrix"
void MuonErrorMatrix::close ( void  )

close the root file attached to the class

Definition at line 240 of file MuonErrorMatrix.cc.

References mps_fire::i, theD, and theData.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), and ~MuonErrorMatrix().

240  {
241  //close the file
242  if (theD) {
243  theD->cd();
244  //write to it first if constructor
245  if (theD->IsWritable()) {
246  for (int i = 0; i != 15; i++) {
247  if (theData[i]) {
248  theData[i]->Write();
249  }
250  }
251  }
252  theD->Close();
253  }
254 }
TDirectory * theD
the attached root file, where the parametrization is saved
TProfile3D * theData[15]
15 TProfile, each holding he parametrization of each term of the 5x5
void MuonErrorMatrix::complicatedTerm ( const AlgebraicSymMatrix55 input,
AlgebraicSymMatrix55 output 
)

convert sigma/rho -> sigma2/COV

Definition at line 491 of file MuonErrorMatrix.cc.

References mps_fire::i, input, dqmiolumiharvest::j, and convertSQLitetoXML_cfg::output.

Referenced by adjust().

491  {
492  for (int i = 0; i != 5; i++) {
493  for (int j = i; j != 5; j++) {
494  if (i == j)
495  output(i, j) = input(i, j) * input(i, j); //sigma squared
496  else
497  output(i, j) = input(i, j) * input(i, i) * input(j, j); //rho*sigma*sigma
498  }
499  }
500 }
static std::string const input
Definition: EdmProvDump.cc:48
bool MuonErrorMatrix::divide ( CurvilinearTrajectoryError num_error,
const CurvilinearTrajectoryError denom_error 
)
static

divide term by term the two matrix

Definition at line 463 of file MuonErrorMatrix.cc.

References mps_fire::i, dqmiolumiharvest::j, and CurvilinearTrajectoryError::matrix().

463  {
464  //divide term by term the matrix
465  const AlgebraicSymMatrix55 &denom_matrix = denom_error.matrix();
466  AlgebraicSymMatrix55 num_matrix = num_error.matrix();
467  // the true type of the matrix is such that [i][j] is the same memory object as [j][i]: looping i:0-5, j:0-5 double multiply the terms
468  // need to loop only on i:0-5, j:i-5
469  for (int i = 0; i != 5; i++) {
470  for (int j = i; j != 5; j++) {
471  if (denom_matrix(i, j) == 0)
472  return false;
473  num_matrix(i, j) /= denom_matrix(i, j);
474  }
475  }
476  num_error = CurvilinearTrajectoryError(num_matrix);
477  return true;
478 }
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const AlgebraicSymMatrix55 & matrix() const
int MuonErrorMatrix::findBin ( TAxis *  axis,
double  value 
)

method to get the bin index, taking care of under/overlow: first(1)/last(GetNbins())returned

Definition at line 322 of file MuonErrorMatrix.cc.

References mps_fire::result.

Referenced by getFast(), and Value().

322  {
323  //find the proper bin, protecting against under/over flow
324  int result = axis->FindBin(value);
325  if (result <= 0)
326  result = 1; //protect against under flow
327  else if (result > axis->GetNbins())
328  result = axis->GetNbins();
329  return result;
330 }
Definition: value.py:1
CurvilinearTrajectoryError MuonErrorMatrix::get ( GlobalVector  momentum,
bool  convolute = true 
)

main method to be used. Retrieve a 5x5 symetrical matrix according to parametrization of error or scale factor

Definition at line 258 of file MuonErrorMatrix.cc.

References mps_fire::i, dqmiolumiharvest::j, and Value().

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), TSGFromPropagation::adjust(), MuonErrorMatrixAdjuster::fix_cov_matrix(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), and TSGFromPropagation::init().

258  {
260  //retrieves a 55 matrix containing (i,i)^2 and (i,j)*(i,i)*(j,j)
261  for (int i = 0; i != 5; i++) {
262  for (int j = i; j != 5; j++) {
263  V(i, j) = Value(momentum, i, j, convolute);
264  }
265  }
266  return CurvilinearTrajectoryError(V);
267 }
double Value(GlobalVector &momentum, int i, int j, bool convolute=true)
internal method that retreives the value of the parametrization for term i,j
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
TProfile3D* MuonErrorMatrix::get ( int  i,
int  j 
)
inline

actually get access to the TProfile3D used for the parametrization

Definition at line 48 of file MuonErrorMatrix.h.

References Index(), and dqmiolumiharvest::j.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), and betterConfigParser.BetterConfigParser::getResultingSection().

48 { return Index(i, j); }
TProfile3D * Index(int i, int j)
internal method to get access to the profiles
CurvilinearTrajectoryError MuonErrorMatrix::getFast ( GlobalVector  momentum)

Definition at line 269 of file MuonErrorMatrix.cc.

References PVValHelper::eta, PV3DBase< T, PVType, FrameType >::eta(), findBin(), mps_fire::i, dqmiolumiharvest::j, PV3DBase< T, PVType, FrameType >::perp(), phi, PV3DBase< T, PVType, FrameType >::phi(), PVValHelper::pT, theData_fast, and contentValuesCheck::values.

269  {
270  //will be faster but make assumptions that could be broken at some point
271  // same bining for all TProfile
273 
274  double pT = momentum.perp();
275  double eta = fabs(momentum.eta());
276  double phi = momentum.phi();
277 
278  //assume all the same axis in X,Y,Z
279  int iBin_x = findBin(theData_fast[0][0]->GetXaxis(), pT);
280  int iBin_y = findBin(theData_fast[0][0]->GetYaxis(), eta);
281  int iBin_z = findBin(theData_fast[0][0]->GetZaxis(), phi);
282 
283  //retreive values
284  double values[5][5]; //sigma_i and rho_ij
285  for (int i = 0; i != 5; i++) {
286  for (int j = i; j != 5; j++) {
287  values[i][j] = theData_fast[i][j]->GetBinContent(iBin_x, iBin_y, iBin_z);
288  }
289  }
290 
291  for (int i = 0; i != 5; i++) {
292  for (int j = i; j != 5; j++) {
293  if (i == j) {
294  //sigma_i * sigma_i
295  V(i, j) = values[i][j];
296  V(i, j) *= V(i, j);
297  } else {
298  //sigma_i * sigma_j * rho_ij
299  V(i, j) = values[i][i] * values[j][j] * values[i][j];
300  }
301  }
302  }
303 
304  return CurvilinearTrajectoryError(V);
305 }
T perp() const
Definition: PV3DBase.h:69
int findBin(TAxis *axis, double value)
method to get the bin index, taking care of under/overlow: first(1)/last(GetNbins())returned ...
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
TProfile3D * theData_fast[5][5]
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
T eta() const
Definition: PV3DBase.h:73
unsigned int MuonErrorMatrix::index ( int  i,
int  j 
)
inline

Definition at line 49 of file MuonErrorMatrix.h.

References Pindex().

Referenced by BeautifulSoup.PageElement::insert().

49 { return Pindex(i, j); }
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
TProfile3D* MuonErrorMatrix::Index ( int  i,
int  j 
)
inlineprivate

internal method to get access to the profiles

Definition at line 92 of file MuonErrorMatrix.h.

References dqmiolumiharvest::j, Pindex(), Rms(), and Value().

Referenced by get(), Rms(), and Value().

92 { return theData[Pindex(i, j)]; }
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
TProfile3D * theData[15]
15 TProfile, each holding he parametrization of each term of the 5x5
void MuonErrorMatrix::multiply ( CurvilinearTrajectoryError initial_error,
const CurvilinearTrajectoryError scale_error 
)
static

multiply term by term the two matrix

Definition at line 449 of file MuonErrorMatrix.cc.

References mps_fire::i, dqmiolumiharvest::j, and CurvilinearTrajectoryError::matrix().

Referenced by TSGFromPropagation::adjust(), and FastTSGFromPropagation::adjust().

450  {
451  //scale term by term the matrix
452  const AlgebraicSymMatrix55 &scale_matrix = scale_error.matrix();
453  AlgebraicSymMatrix55 revised_matrix = initial_error.matrix();
454  // the true type of the matrix is such that [i][j] is the same memory object as [j][i]: looping i:0-5, j:0-5 double multiply the terms
455  // need to loop only on i:0-5, j:i-5
456  for (int i = 0; i != 5; i++) {
457  for (int j = i; j != 5; j++) {
458  revised_matrix(i, j) *= scale_matrix(i, j);
459  }
460  }
461  initial_error = CurvilinearTrajectoryError(revised_matrix);
462 }
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const AlgebraicSymMatrix55 & matrix() const
int MuonErrorMatrix::Pindex ( int  i,
int  j 
)
inlineprivate

internal methods to get the index of a matrix term.

Definition at line 87 of file MuonErrorMatrix.h.

References funct::abs(), mps_fire::i, and hltrates_dqm_sourceclient-live_cfg::offset.

Referenced by adjust(), index(), Index(), and MuonErrorMatrix().

87  {
88  static const int offset[5] = {0, 5, 5 + 4, 5 + 4 + 3, 5 + 4 + 3 + 2};
89  return offset[i] + abs(j - i);
90  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double MuonErrorMatrix::Rms ( GlobalVector momentum,
int  i,
int  j 
)
private

internal method that retreives the error on the value of the parametrization for term i,j

Definition at line 396 of file MuonErrorMatrix.cc.

References PVValHelper::eta, PV3DBase< T, PVType, FrameType >::eta(), Index(), LogDebug, PV3DBase< T, PVType, FrameType >::perp(), phi, PV3DBase< T, PVType, FrameType >::phi(), PVValHelper::pT, mps_fire::result, and theCategory.

Referenced by Index().

396  {
397  double result = 0;
398  TProfile3D *ij = Index(i, j);
399  if (!ij) {
400  edm::LogError(theCategory) << "cannot get the profile (" << i << ":" << i << ")";
401  return result;
402  }
403  double pT = momentum.perp();
404  double eta = fabs(momentum.eta());
405  double phi = momentum.phi();
406 
407  int iBin_x = ij->GetXaxis()->FindBin(pT);
408  int iBin_y = ij->GetYaxis()->FindBin(eta);
409  int iBin_z = ij->GetZaxis()->FindBin(phi);
410  result = ij->GetBinError(iBin_x, iBin_y, iBin_z);
411 
412  LogDebug(theCategory) << "for: (pT,eta,phi)=(" << pT << ", " << eta << ", " << phi << ") error[" << i << "," << j
413  << "] is: " << result;
414  return result;
415 }
#define LogDebug(id)
T perp() const
Definition: PV3DBase.h:69
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
std::string theCategory
log category: "MuonErrorMatrix"
TProfile3D * Index(int i, int j)
internal method to get access to the profiles
void MuonErrorMatrix::simpleTerm ( const AlgebraicSymMatrix55 input,
AlgebraicSymMatrix55 output 
)

convert sigma2/COV -> sigma/rho

Definition at line 480 of file MuonErrorMatrix.cc.

References mps_fire::i, input, dqmiolumiharvest::j, convertSQLitetoXML_cfg::output, and mathSSE::sqrt().

Referenced by adjust().

480  {
481  for (int i = 0; i != 5; i++) {
482  for (int j = i; j != 5; j++) {
483  if (i == j)
484  output(i, j) = sqrt(input(i, j)); //sigma
485  else
486  output(i, j) = input(i, j) / sqrt(input(i, i) * input(j, j)); //rho
487  }
488  }
489 }
static std::string const input
Definition: EdmProvDump.cc:48
T sqrt(T t)
Definition: SSEVec.h:19
double MuonErrorMatrix::Term ( const AlgebraicSymMatrix55 curv,
int  i,
int  j 
)
static

provide the numerical value used. sigma or correlation factor

Definition at line 417 of file MuonErrorMatrix.cc.

References mps_fire::result, and mathSSE::sqrt().

417  {
418  //return sigma or correlation factor
419  double result = 0;
420  if (i == j) {
421  result = curv(i, j);
422  if (result < 0) {
423  //check validity of this guy
424  edm::LogError("MuonErrorMatrix") << "invalid term in the error matrix.\n sii: " << result;
425  return 0;
426  }
427  return sqrt(result);
428  } else {
429  double si = curv(i, i);
430  double sj = curv(j, j);
431 
432  if (si <= 0 || sj <= 0) {
433  edm::LogError("MuonErrorMatrix") << "invalid term in the error matrix.\n si: " << si << " sj: " << sj
434  << ". result will be corrupted\n"
435  << curv;
436  return 0;
437  }
438 
439  si = sqrt(si);
440  sj = sqrt(sj);
441  //check validity
442 
443  return result = curv(i, j) / (si * sj);
444  }
445  //by default
446  return 0;
447 }
T sqrt(T t)
Definition: SSEVec.h:19
double MuonErrorMatrix::Value ( GlobalVector momentum,
int  i,
int  j,
bool  convolute = true 
)
private

internal method that retreives the value of the parametrization for term i,j

Definition at line 332 of file MuonErrorMatrix.cc.

References corr, PVValHelper::eta, PV3DBase< T, PVType, FrameType >::eta(), findBin(), cuy::ii, Index(), findQualityFiles::jj, LogDebug, PV3DBase< T, PVType, FrameType >::perp(), phi, PV3DBase< T, PVType, FrameType >::phi(), PVValHelper::pT, mps_fire::result, and theCategory.

Referenced by get(), and Index().

332  {
333  double result = 0;
334  TProfile3D *ij = Index(i, j);
335  if (!ij) {
336  edm::LogError(theCategory) << "cannot get the profile (" << i << ":" << j << ")";
337  return result;
338  }
339 
340  double pT = momentum.perp();
341  double eta = fabs(momentum.eta());
342  double phi = momentum.phi();
343 
344  int iBin_x = findBin(ij->GetXaxis(), pT);
345  int iBin_y = findBin(ij->GetYaxis(), eta);
346  int iBin_z = findBin(ij->GetZaxis(), phi);
347 
348  if (convolute) {
349  if (i != j) {
350  //return the covariance = correlation*sigma_1 *sigma_2;
351  TProfile3D *ii = Index(i, i);
352  TProfile3D *jj = Index(j, j);
353  if (!ii) {
354  edm::LogError(theCategory) << "cannot get the profile (" << i << ":" << i << ")";
355  return result;
356  }
357  if (!jj) {
358  edm::LogError(theCategory) << "cannot get the profile (" << j << ":" << j << ")";
359  return result;
360  }
361 
362  int iBin_i_x = findBin(ii->GetXaxis(), pT);
363  int iBin_i_y = findBin(ii->GetYaxis(), eta);
364  int iBin_i_z = findBin(ii->GetZaxis(), phi);
365  int iBin_j_x = findBin(jj->GetXaxis(), pT);
366  int iBin_j_y = findBin(jj->GetYaxis(), eta);
367  int iBin_j_z = findBin(jj->GetZaxis(), phi);
368 
369  double corr = ij->GetBinContent(iBin_x, iBin_y, iBin_z);
370  double sigma_1 = (ii->GetBinContent(iBin_i_x, iBin_i_y, iBin_i_z));
371  double sigma_2 = (jj->GetBinContent(iBin_j_x, iBin_j_y, iBin_j_z));
372 
373  result = corr * sigma_1 * sigma_2;
374  LogDebug(theCategory) << "for: (pT,eta,phi)=(" << pT << ", " << eta << ", " << phi << ") nterms are"
375  << "\nrho[" << i << "," << j << "]: " << corr << " [" << iBin_x << ", " << iBin_y << ", "
376  << iBin_z << "]"
377  << "\nsigma[" << i << "," << i << "]: " << sigma_1 << "\nsigma[" << j << "," << j
378  << "]: " << sigma_2 << "Covariance[" << i << "," << j << "] is: " << result;
379  return result;
380  } else {
381  //return the variance = sigma_1 **2
382  // result=ij->GetBinContent(iBin);
383  result = ij->GetBinContent(iBin_x, iBin_y, iBin_z);
384  result *= result;
385  LogDebug(theCategory) << "for: (pT,eta,phi)=(" << pT << ", " << eta << ", " << phi << ") sigma^2[" << i << ","
386  << j << "] is: " << result;
387  return result;
388  }
389  } else {
390  //do not convolute
391  result = ij->GetBinContent(iBin_x, iBin_y, iBin_z);
392  return result;
393  }
394 }
#define LogDebug(id)
T perp() const
Definition: PV3DBase.h:69
int findBin(TAxis *axis, double value)
method to get the bin index, taking care of under/overlow: first(1)/last(GetNbins())returned ...
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
JetCorrectorParameters corr
Definition: classes.h:5
ii
Definition: cuy.py:590
T eta() const
Definition: PV3DBase.h:73
std::string theCategory
log category: "MuonErrorMatrix"
TProfile3D * Index(int i, int j)
internal method to get access to the profiles

Member Data Documentation

std::string MuonErrorMatrix::theCategory
private

log category: "MuonErrorMatrix"

Definition at line 74 of file MuonErrorMatrix.h.

Referenced by adjust(), MuonErrorMatrix(), Rms(), and Value().

TDirectory* MuonErrorMatrix::theD
private

the attached root file, where the parametrization is saved

Definition at line 77 of file MuonErrorMatrix.h.

Referenced by close(), and MuonErrorMatrix().

TProfile3D* MuonErrorMatrix::theData[15]
private

15 TProfile, each holding he parametrization of each term of the 5x5

Definition at line 79 of file MuonErrorMatrix.h.

Referenced by close(), and MuonErrorMatrix().

TProfile3D* MuonErrorMatrix::theData_fast[5][5]
private

Definition at line 80 of file MuonErrorMatrix.h.

Referenced by getFast(), and MuonErrorMatrix().

TermAction MuonErrorMatrix::theTermAction[15]
private

Definition at line 84 of file MuonErrorMatrix.h.

Referenced by adjust(), and MuonErrorMatrix().

const TString MuonErrorMatrix::vars = {"#frac{q}{|p|}", "#lambda", "#varphi_{0}", "X_{T}", "Y_{T}"}
static

names of the variables of the 5x5 error matrix

Definition at line 52 of file MuonErrorMatrix.h.