21 bool madeFromCff=iConfig.
exists(
"errorMatrixValuesPSet");
30 std::vector<double> xBins;
31 double * xBinsArray =
nullptr;
35 std::vector<double> yBins;
36 double * yBinsArray =
nullptr;
51 xBins = iConfig.
getParameter<std::vector<double> >(
"PtBins");
54 xBinsArray = &(xBins.front());
55 minPt = xBins.front();
56 maxPt = xBins.back();}
63 yBins = iConfig.
getParameter<std::vector<double> >(
"EtaBins");
65 NEta = yBins.size()-1;
66 yBinsArray = &(yBins.front());
67 minPt = yBins.front();
68 maxPt = yBins.back();}
72 if (
get.
str() ==
"-Pi")
74 else if(
get.
str() ==
"Pi")
78 if (
get.
str() ==
"-Pi")
80 else if(
get.
str() ==
"Pi")
84 else if (madeFromCff){
86 xBins = errorMatrixValuesPSet.
getParameter<std::vector<double> >(
"xAxis");
88 xBinsArray = &(xBins.front());
89 minPt = xBins.front();
92 yBins = errorMatrixValuesPSet.
getParameter<std::vector<double> >(
"yAxis");
93 NEta = yBins.size()-1;
94 yBinsArray = &(yBins.front());
95 minPt = yBins.front();
98 std::vector<double> zBins = errorMatrixValuesPSet.
getParameter<std::vector<double> >(
"zAxis");
100 if (zBins.size()!=2){
102 minPhi=zBins.front();
113 theD =
new TFile(fullpath.c_str());
114 theD->SetWritable(
false);
116 static std::atomic<unsigned int> neverTheSame{0};
117 std::stringstream
dirName(
"MuonErrorMatrixDirectory");
118 dirName<<neverTheSame++;
119 edm::LogInfo(
theCategory)<<
"using an error matrix object from configuration file. putting memory histograms to: "<<dirName.str();
121 theD =
new TDirectory(dirName.str().c_str(),
"transient directory to host MuonErrorMatrix TProfile3D");
122 theD->SetWritable(
false);
127 theD =
new TFile(fileName.c_str(),
"recreate");
130 if (a==
use && !madeFromCff ){gROOT->cd();}
133 for (
int i=0;
i!=5;
i++){
for (
int j=
i;j!=5;j++){
134 TString pfname(Form(
"pf3_V%1d%1d",
i+1,j+1));
135 TProfile3D *
pf =
nullptr;
136 if (a==
use && !madeFromCff ){
139 pf = (TProfile3D *)
theD->Get(pfname);
148 if (
i==j){pftitle=
"#sigma_{"+
vars[
i]+
"}";}
149 else{pftitle=
"#rho("+
vars[
i]+
","+
vars[j]+
")";}
151 pf =
new TProfile3D(pfname,pftitle,NPt,minPt,maxPt,NEta,minEta,maxEta,NPhi,minPhi,maxPhi,
"S");
152 pf->SetXTitle(
"muon p_{T} [GeV]");
153 pf->SetYTitle(
"muon |#eta|");
154 pf->SetZTitle(
"muon #varphi");
158 pf->GetXaxis()->Set(NPt,xBinsArray);}
160 pf->GetYaxis()->Set(NEta,yBinsArray);}
166 unsigned int iX=pf->GetNbinsX();
167 unsigned int iY=pf->GetNbinsY();
168 unsigned int iZ=pf->GetNbinsZ();
169 unsigned int continuous_i=0;
170 for(
unsigned int ix=1;ix<=iX;++ix){
171 for(
unsigned int iy=1;iy<=iY;++iy){
172 for(
unsigned int iz=1;iz<=iZ;++iz){
174 <<
"\n pt (x)= "<<pf->GetXaxis()->GetBinCenter(ix)
175 <<
"\n eta (y)= "<<pf->GetYaxis()->GetBinCenter(iy)
176 <<
"\n phi (z)= "<<pf->GetZaxis()->GetBinCenter(iz)
177 <<
"\n value= "<<values[continuous_i];
178 pf->Fill(pf->GetXaxis()->GetBinCenter(ix),
179 pf->GetYaxis()->GetBinCenter(iy),
180 pf->GetZaxis()->GetBinCenter(iz),
181 values[continuous_i++]);
185 if (tAction ==
"scale")
187 else if (tAction ==
"assign")
207 for (
int i=0;
i!=15;
i++){
209 <<
" "<<
theData[
i]->GetTitle()<<std::endl;}}
220 if (
theD->IsWritable()){
234 for (
int i=0;
i!=5;
i++){
for (
int j=
i;j!=5;j++){
235 V(
i,j) =
Value(momentum,
i,j,convolute);}}
243 double pT = momentum.
perp();
244 double eta = fabs(momentum.
eta());
245 double phi = momentum.
phi();
254 for (
int i=0;
i!=5;
i++){
for (
int j=
i;j!=5;j++){
255 values[
i][j]=
theData_fast[
i][j]->GetBinContent(iBin_x, iBin_y, iBin_z);
258 for (
int i=0;
i!=5;
i++){
for (
int j=
i;j!=5;j++){
261 V(
i,j) = values[
i][j];
266 V(
i,j) = values[
i][
i] * values[j][j] * values[
i][j];
291 int result = axis->FindBin(value);
292 if (result <= 0) result=1;
293 else if (result > axis->GetNbins() ) result = axis->GetNbins();
299 TProfile3D * ij =
Index(i,j);
302 double pT = momentum.
perp();
303 double eta = fabs(momentum.
eta());
304 double phi = momentum.
phi();
319 int iBin_i_x =
findBin(ii->GetXaxis(),
pT);
322 int iBin_j_x =
findBin(jj->GetXaxis(),
pT);
326 double corr = ij->GetBinContent(iBin_x,iBin_y,iBin_z);
327 double sigma_1 = (ii->GetBinContent(iBin_i_x,iBin_i_y,iBin_i_z));
328 double sigma_2 = (jj->GetBinContent(iBin_j_x,iBin_j_y,iBin_j_z));
331 result=corr*sigma_1*sigma_2;
333 <<
"\nrho["<<i<<
","<<j<<
"]: "<<corr<<
" ["<< iBin_x<<
", "<<iBin_y<<
", "<<iBin_z<<
"]" 334 <<
"\nsigma["<<i<<
","<<i<<
"]: "<< sigma_1
335 <<
"\nsigma["<<j<<
","<<j<<
"]: "<< sigma_2
336 <<
"Covariance["<<i<<
","<<j<<
"] is: "<<
result;
342 result=ij->GetBinContent(iBin_x,iBin_y,iBin_z);
349 result=ij->GetBinContent(iBin_x,iBin_y,iBin_z);
356 TProfile3D * ij =
Index(i,j);
358 double pT = momentum.
perp();
359 double eta = fabs(momentum.
eta());
360 double phi = momentum.
phi();
362 int iBin_x= ij->GetXaxis()->FindBin(pT);
363 int iBin_y= ij->GetYaxis()->FindBin(eta);
364 int iBin_z= ij->GetZaxis()->FindBin(phi);
365 result=ij->GetBinError(iBin_x,iBin_y,iBin_z);
380 return sqrt(result);}
382 double si = curv(i,i);
383 double sj = curv(j,j);
386 edm::LogError(
"MuonErrorMatrix")<<
"invalid term in the error matrix.\n si: " 387 <<si<<
" sj: "<<sj<<
". result will be corrupted\n"<<curv;
394 return result = curv(i,j)/(si*sj);}
406 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
407 revised_matrix(
i,j)*=scale_matrix(
i,j);
417 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
418 if (denom_matrix(
i,j)==0)
return false;
419 num_matrix(
i,j)/=denom_matrix(
i,j);
426 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
436 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
457 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
462 simpleTerms(
i,j) *= simpleValues(
i,j);
467 simpleTerms(
i,j) = simpleValues(
i,j);
498 for(
int i = 0;
i!=5;
i++){
for(
int j =
i;j!=5;j++){
503 simpleTerms(
i,j) *= simpleValues(
i,j);
508 simpleTerms(
i,j) = simpleValues(
i,j);
T getParameter(std::string const &) const
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...
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
~MuonErrorMatrix()
destructor
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
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]
const GlobalTrajectoryParameters & globalParameters() const
void simpleTerm(const AlgebraicSymMatrix55 &input, AlgebraicSymMatrix55 &output)
convert sigma2/COV -> sigma/rho
NEta
set NEta=0 and the vector of double for variable size binning
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