15 const TString
MuonErrorMatrix::vars[5] = {
"#frac{q}{|p|}",
"#lambda",
"#varphi_{0}",
"X_{T}",
"Y_{T}"};
21 bool madeFromCff = iConfig.
exists(
"errorMatrixValuesPSet");
33 std::vector<double> xBins;
34 double *xBinsArray =
nullptr;
38 std::vector<double> yBins;
39 double *yBinsArray =
nullptr;
46 if (action !=
"use") {
54 xBins = iConfig.
getParameter<std::vector<double> >(
"PtBins");
58 NPt = xBins.size() - 1;
59 xBinsArray = &(xBins.front());
60 minPt = xBins.front();
69 yBins = iConfig.
getParameter<std::vector<double> >(
"EtaBins");
73 NEta = yBins.size() - 1;
74 yBinsArray = &(yBins.front());
75 minEta = yBins.front();
76 maxEta = yBins.back();
81 if (
get.
str() ==
"-Pi") {
83 }
else if (
get.
str() ==
"Pi") {
89 if (
get.
str() ==
"-Pi") {
91 }
else if (
get.
str() ==
"Pi") {
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();
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();
110 std::vector<double> zBins = errorMatrixValuesPSet.
getParameter<std::vector<double> >(
"zAxis");
112 if (zBins.size() != 2) {
115 minPhi = zBins.front();
116 maxPhi = zBins.back();
125 theD =
new TFile(fullpath.c_str());
126 theD->SetWritable(
false);
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();
134 theD =
new TDirectory(dirName.str().c_str(),
"transient directory to host MuonErrorMatrix TProfile3D");
135 theD->SetWritable(
false);
139 theD =
new TFile(fileName.c_str(),
"recreate");
142 if (a ==
use && !madeFromCff) {
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) {
155 pf = (TProfile3D *)
theD->Get(pfname);
165 pftitle =
"#sigma_{" +
vars[
i] +
"}";
167 pftitle =
"#rho(" +
vars[
i] +
"," +
vars[
j] +
")";
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");
177 pf->GetXaxis()->Set(NPt, xBinsArray);
180 pf->GetYaxis()->Set(NEta, yBinsArray);
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) {
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++]);
208 if (tAction ==
"scale")
210 else if (tAction ==
"assign")
231 for (
int i = 0;
i != 15;
i++) {
245 if (
theD->IsWritable()) {
246 for (
int i = 0;
i != 15;
i++) {
261 for (
int i = 0;
i != 5;
i++) {
262 for (
int j =
i;
j != 5;
j++) {
274 double pT = momentum.
perp();
275 double eta = fabs(momentum.
eta());
276 double phi = momentum.
phi();
285 for (
int i = 0;
i != 5;
i++) {
286 for (
int j =
i;
j != 5;
j++) {
291 for (
int i = 0;
i != 5;
i++) {
292 for (
int j =
i;
j != 5;
j++) {
295 V(
i,
j) = values[
i][
j];
299 V(
i,
j) = values[
i][
i] * values[
j][
j] * values[
i][
j];
324 int result = axis->FindBin(value);
327 else if (result > axis->GetNbins())
328 result = axis->GetNbins();
334 TProfile3D *ij =
Index(i, j);
340 double pT = momentum.
perp();
341 double eta = fabs(momentum.
eta());
342 double phi = momentum.
phi();
344 int iBin_x =
findBin(ij->GetXaxis(),
pT);
362 int iBin_i_x =
findBin(ii->GetXaxis(),
pT);
365 int iBin_j_x =
findBin(jj->GetXaxis(),
pT);
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));
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 <<
", "
377 <<
"\nsigma[" << i <<
"," << i <<
"]: " << sigma_1 <<
"\nsigma[" << j <<
"," << j
378 <<
"]: " << sigma_2 <<
"Covariance[" << i <<
"," << j <<
"] is: " <<
result;
383 result = ij->GetBinContent(iBin_x, iBin_y, iBin_z);
385 LogDebug(
theCategory) <<
"for: (pT,eta,phi)=(" << pT <<
", " << eta <<
", " << phi <<
") sigma^2[" << i <<
","
386 << j <<
"] is: " <<
result;
391 result = ij->GetBinContent(iBin_x, iBin_y, iBin_z);
398 TProfile3D *ij =
Index(i, j);
403 double pT = momentum.
perp();
404 double eta = fabs(momentum.
eta());
405 double phi = momentum.
phi();
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);
412 LogDebug(
theCategory) <<
"for: (pT,eta,phi)=(" << pT <<
", " << eta <<
", " << phi <<
") error[" << i <<
"," << j
429 double si = curv(i, i);
430 double sj = curv(j, j);
431 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"
438 result = curv(i, j) /
sqrt(si * sj);
452 for (
int i = 0;
i != 5;
i++) {
453 for (
int j =
i;
j != 5;
j++) {
454 revised_matrix(
i,
j) *= scale_matrix(
i,
j);
465 for (
int i = 0;
i != 5;
i++) {
466 for (
int j =
i;
j != 5;
j++) {
467 if (denom_matrix(
i,
j) == 0)
469 num_matrix(
i,
j) /= denom_matrix(
i,
j);
477 for (
int i = 0;
i != 5;
i++) {
478 for (
int j =
i;
j != 5;
j++) {
488 for (
int i = 0;
i != 5;
i++) {
489 for (
int j =
i;
j != 5;
j++) {
508 for (
int i = 0;
i != 5;
i++) {
509 for (
int j =
i;
j != 5;
j++) {
513 simpleTerms(
i,
j) *= simpleValues(
i,
j);
517 simpleTerms(
i,
j) = simpleValues(
i,
j);
526 LogDebug(
theCategory +
"|Adjust") <<
"updated state sigma(i), rho(i,j): \n" << simpleTerms;
545 for (
int i = 0;
i != 5;
i++) {
546 for (
int j =
i;
j != 5;
j++) {
550 simpleTerms(
i,
j) *= simpleValues(
i,
j);
554 simpleTerms(
i,
j) = simpleValues(
i,
j);
563 LogDebug(
theCategory +
"|Adjust") <<
"updated state sigma(i), rho(i,j): \n" << simpleTerms;
Log< level::Info, true > LogVerbatim
void adjust(FreeTrajectoryState &state)
adjust the error matrix on the state
static bool divide(CurvilinearTrajectoryError &num_error, const CurvilinearTrajectoryError &denom_error)
divide term by term the two matrix
int findBin(TAxis *axis, double value)
method to get the bin index, taking care of under/overlow: first(1)/last(GetNbins())returned ...
const GlobalTrajectoryParameters & parameters() const
static const TString vars[5]
names of the variables of the 5x5 error matrix
const CurvilinearTrajectoryError & curvilinearError() const
double Value(GlobalVector &momentum, int i, int j, bool convolute=true)
internal method that retreives the value of the parametrization for term i,j
Geom::Phi< T > phi() const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
CurvilinearTrajectoryError get(GlobalVector momentum, bool convolute=true)
main method to be used. Retrieve a 5x5 symetrical matrix according to parametrization of error or sca...
~MuonErrorMatrix()
destructor
Log< level::Error, false > LogError
static double Term(const AlgebraicSymMatrix55 &curv, int i, int j)
provide the numerical value used. sigma or correlation factor
const CurvilinearTrajectoryError & curvilinearError() const
action
enum type to define if the class is used as a tool or to be created
static std::string const input
const SurfaceType & surface() const
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
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.
MuonErrorMatrix(const edm::ParameterSet &pset)
constructor from a parameter set
static void multiply(CurvilinearTrajectoryError &initial_error, const CurvilinearTrajectoryError &scale_error)
multiply term by term the two matrix
int Pindex(int i, int j)
internal methods to get the index of a matrix term.
GlobalVector momentum() const
TProfile3D * theData_fast[5][5]
Log< level::Info, false > LogInfo
const GlobalTrajectoryParameters & globalParameters() const
void simpleTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma2/COV -> sigma/rho
T getParameter(std::string const &) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double Rms(GlobalVector &momentum, int i, int j)
internal method that retreives the error on the value of the parametrization for term i...
char data[epos_bytes_allocation]
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
TDirectory * theD
the attached root file, where the parametrization is saved
std::string fullPath() const
CurvilinearTrajectoryError getFast(GlobalVector momentum)
TProfile3D * theData[15]
15 TProfile, each holding he parametrization of each term of the 5x5
std::string theCategory
log category: "MuonErrorMatrix"
void close()
close the root file attached to the class
TProfile3D * Index(int i, int j)
internal method to get access to the profiles