CMS 3D CMS Logo

CovarianceParameterization.cc
Go to the documentation of this file.
5 #include <boost/format.hpp>
6 #include <iostream>
7 #include <TParameter.h>
8 #include <TVector.h>
9 #include <TFolder.h>
10 
11 uint16_t CompressionElement::pack(float value, float ref) const {
12  float toCompress = 0;
13  switch (target) {
14  case (realValue):
15  toCompress = value;
16  break;
17  case (ratioToRef):
18  toCompress = value / ref;
19  break;
20  case (differenceToRef):
21  toCompress = value - ref;
22  break;
23  }
24  switch (method) {
25  case (float16):
26  return MiniFloatConverter::float32to16(toCompress * params[0]);
27  break;
28  case (reduceMantissa):
30  break;
31  case (zero):
32  return 0;
33  break;
34  case (one):
35  return 1.0;
36  break;
37  case (tanLogPack):
38  return 0; //FIXME: should be implemented
39  break;
40  case (logPack):
41  int16_t r = logintpack::pack16log(toCompress, params[0], params[1], bits);
42  return *reinterpret_cast<uint16_t *>(&r);
43  break;
44  }
45  return 0;
46 }
47 float CompressionElement::unpack(uint16_t packed, float ref) const {
48  float unpacked = 0;
49  switch (method) {
50  case (float16):
51  unpacked = MiniFloatConverter::float16to32(packed) / params[0];
52  break;
53  case (reduceMantissa):
54  unpacked = packed;
55  break;
56  case (logPack):
57  unpacked = logintpack::unpack16log(*reinterpret_cast<int16_t *>(&packed), params[0], params[1], bits);
58  break;
59  case (zero):
60  unpacked = 0;
61  break;
62  case (one):
63  case (tanLogPack):
64  unpacked = 1; //FIXME: should be implemented
65  }
66  switch (target) {
67  case (realValue):
68  return unpacked;
69  case (ratioToRef):
70  return unpacked * ref;
71  case (differenceToRef):
72  return unpacked + ref;
73  }
74 
75  return ref;
76 }
77 
79  edm::FileInPath fip(
80  (boost::format("DataFormats/PatCandidates/data/CovarianceParameterization_version%d.root") % version).str());
81  fileToRead_ = TFile::Open(fip.fullPath().c_str());
82  TFile &fileToRead = *fileToRead_;
83  //Read files from here fip.fullPath().c_str();
84  if (fileToRead.IsOpen()) {
85  readFile(fileToRead);
86 
87  TIter next(((TDirectoryFile *)fileToRead.Get("schemas"))->GetListOfKeys());
88  TKey *key;
89  while ((key = (TKey *)next())) {
90  TClass *cl = gROOT->GetClass(key->GetClassName());
91  if (!cl->InheritsFrom("TDirectoryFile"))
92  continue;
93  std::string schemaNumber = key->ReadObj()->GetName();
94  uint16_t schemaN = std::stoi(schemaNumber);
95  //for (int folderNumber = 0; folderNumber < 6 ; folderNumber++) {
96  CompressionSchema schema;
97  for (int i = 0; i < 5; i++) {
98  for (int j = i; j < 5; j++) { //FILLING ONLY THE SCHEMA OF SOME ELEMENTS
99  std::string folder = "schemas/" + schemaNumber + "/" + char(48 + i) + char(48 + j);
100  std::string methodString = folder + "/method";
101  std::string targetString = folder + "/target";
102  std::string bitString = folder + "/bit";
103  std::vector<float> vParams;
104  TVector *p = (TVector *)fileToRead.Get((folder + "/param").c_str());
105  for (int k = 0; k < p->GetNoElements(); k++) {
106  vParams.push_back((*p)[k]);
107  }
108 
109  schema(i, j) = CompressionElement(
110  (CompressionElement::Method)((TParameter<int> *)fileToRead.Get(methodString.c_str()))->GetVal(),
111  (CompressionElement::Target)((TParameter<int> *)fileToRead.Get(targetString.c_str()))->GetVal(),
112  (int)((TParameter<int> *)fileToRead.Get(bitString.c_str()))->GetVal(),
113  vParams);
114  }
115  }
116  schemas[schemaN] = schema;
117  }
118 
120  } else {
121  loadedVersion_ = -1;
122  }
123 }
124 
126  for (int i = 0; i < 5; i++) {
127  for (int j = i; j < 5; j++) {
128  std::string String_first_positive = "_pixel_";
129  std::string String_second_positive = "_noPixel_";
130 
131  addTheHistogram(&cov_elements_pixelHit, String_first_positive, i, j, f);
132  addTheHistogram(&cov_elements_noPixelHit, String_second_positive, i, j, f);
133  }
134  }
135 }
136 
138  std::vector<TH3D *> *HistoVector, std::string StringToAddInTheName, int i, int j, TFile &fileToRead) {
139  std::string List_covName[5] = {"qoverp", "lambda", "phi", "dxy", "dsz"};
140 
141  std::string histoNameString = "covariance_" + List_covName[i] + "_" + List_covName[j] + StringToAddInTheName +
142  "parametrization"; // + "_entries";
143  TH3D *matrixElememtHistogramm = (TH3D *)fileToRead.Get(histoNameString.c_str());
144  HistoVector->push_back(matrixElememtHistogramm);
145 }
146 
148  int i, int j, int sign, float pt, float eta, int nHits, int pixelHits, float cii, float cjj) const {
149  int hitNumberToUse = nHits;
150  if (hitNumberToUse < 2)
151  hitNumberToUse = 2;
152  if (hitNumberToUse > 32)
153  hitNumberToUse = 32;
154  int ptBin = cov_elements_pixelHit[0]->GetXaxis()->FindBin(pt);
155  int etaBin = cov_elements_pixelHit[0]->GetYaxis()->FindBin(std::abs(eta));
156  int hitBin = cov_elements_pixelHit[0]->GetZaxis()->FindBin(hitNumberToUse);
157  int min_idx = i;
158  int max_idx = j;
159 
160  if (i > j) {
161  min_idx = j;
162  max_idx = i;
163  }
164 
165  int indexOfTheHitogramInTheList = ((9 - min_idx) * min_idx) / 2 + max_idx;
166 
167  double meanValue = 0.;
168  if (pixelHits > 0) {
169  meanValue = sign * cov_elements_pixelHit[indexOfTheHitogramInTheList]->GetBinContent(ptBin, etaBin, hitBin);
170  } else {
171  meanValue = sign * cov_elements_noPixelHit[indexOfTheHitogramInTheList]->GetBinContent(ptBin, etaBin, hitBin);
172  }
173  return meanValue;
174 }
175 
177  float value, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii, float cjj) const {
178  if (i > j)
179  std::swap(i, j);
180  float ref = meanValue(i, j, 1., pt, eta, nHits, pixelHits, cii, cjj);
181  if (ref == 0) {
182  schema = 0;
183  }
184  if (schema == 0 && i == j && (i == 2 || i == 0))
185  ref = 1. / (pt * pt);
186  /* //Used for debugging, to be later removed
187  uint16_t p=(*schemas.find(schema)).second(i,j).pack(value,ref);
188  float up=(*schemas.find(schema)).second(i,j).unpack(p,ref);
189  std::cout << "check " << i << " " << j << " " << value << " " << up << " " << p << " " << ref << " " << schema<< std::endl;*/
190  return (*schemas.find(schema)).second(i, j).pack(value, ref);
191 }
193  uint16_t packed, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii, float cjj)
194  const {
195  if (i > j)
196  std::swap(i, j);
197  float ref = meanValue(i, j, 1., pt, eta, nHits, pixelHits, cii, cjj);
198  if (ref == 0) {
199  schema = 0;
200  }
201  if (schema == 0 && i == j && (i == 2 || i == 0))
202  ref = 1. / (pt * pt);
203  if (i == j && (*schemas.find(schema)).second(i, j).unpack(packed, ref) == 0)
204  return 1e-9;
205  else
206  return (*schemas.find(schema)).second(i, j).unpack(packed, ref);
207 }
logintpack::pack16log
int16_t pack16log(double x, double lmin, double lmax, uint16_t base=32768)
Definition: liblogintpack.h:27
mps_fire.i
i
Definition: mps_fire.py:355
CovarianceParameterization::readFile
void readFile(TFile &)
Definition: CovarianceParameterization.cc:125
etaBin
int etaBin(const l1t::HGCalMulticluster *cl)
Definition: L1EGammaEEProducer.cc:19
CompressionElement::target
Target target
Definition: CovarianceParameterization.h:17
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
CompressionElement::params
std::vector< float > params
Definition: CovarianceParameterization.h:19
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
printsummarytable.folder
folder
Definition: printsummarytable.py:7
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CompressionElement::method
Method method
Definition: CovarianceParameterization.h:16
liblogintpack.h
CompressionElement::realValue
Definition: CovarianceParameterization.h:12
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
CompressionElement::Method
Method
Definition: CovarianceParameterization.h:11
MiniFloatConverter::reduceMantissaToNbits
static float reduceMantissaToNbits(const float &f)
Definition: libminifloat.h:49
CovarianceParameterization::pack
float pack(float value, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
Definition: CovarianceParameterization.cc:176
CompressionElement::ratioToRef
Definition: CovarianceParameterization.h:12
muonRecoAnalyzer_cfi.ptBin
ptBin
Definition: muonRecoAnalyzer_cfi.py:45
CovarianceParameterization::loadedVersion_
int loadedVersion_
Definition: CovarianceParameterization.h:69
CompressionElement::tanLogPack
Definition: CovarianceParameterization.h:11
FileInPath.h
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
edm::FileInPath
Definition: FileInPath.h:64
CovarianceParameterization::meanValue
float meanValue(int i, int j, int sign, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
Definition: CovarianceParameterization.cc:147
CovarianceParameterization::cov_elements_pixelHit
std::vector< TH3D * > cov_elements_pixelHit
Definition: CovarianceParameterization.h:72
libminifloat.h
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
PVValHelper::eta
Definition: PVValidationHelpers.h:69
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
CompressionElement::unpack
float unpack(uint16_t packed, float ref=0.) const
Definition: CovarianceParameterization.cc:47
str
#define str(s)
Definition: TestProcessor.cc:48
CovarianceParameterization::schemas
std::unordered_map< uint16_t, CompressionSchema > schemas
Definition: CovarianceParameterization.h:71
CovarianceParameterization::cov_elements_noPixelHit
std::vector< TH3D * > cov_elements_noPixelHit
Definition: CovarianceParameterization.h:73
CompressionElement
Definition: CovarianceParameterization.h:9
logintpack::unpack16log
double unpack16log(int16_t i, double lmin, double lmax, uint16_t base=32768)
Definition: liblogintpack.h:62
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CompressionElement::pack
uint16_t pack(float value, float ref=0.) const
Definition: CovarianceParameterization.cc:11
CompressionElement::Target
Target
Definition: CovarianceParameterization.h:12
CovarianceParameterization::unpack
float unpack(uint16_t packed, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
Definition: CovarianceParameterization.cc:192
CovarianceParameterization::addTheHistogram
void addTheHistogram(std::vector< TH3D * > *HistoVector, std::string StringToAddInTheName, int i, int j, TFile &fileToRead)
Definition: CovarianceParameterization.cc:137
CompressionElement::reduceMantissa
Definition: CovarianceParameterization.h:11
MiniFloatConverter::float16to32
static float float16to32(uint16_t h)
Definition: libminifloat.h:12
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
CompressionElement::bits
int bits
Definition: CovarianceParameterization.h:18
alignCSCRings.r
r
Definition: alignCSCRings.py:93
CompressionElement::zero
Definition: CovarianceParameterization.h:11
CompressionElement::one
Definition: CovarianceParameterization.h:11
CompressionElement::float16
Definition: CovarianceParameterization.h:11
CovarianceParameterization::fileToRead_
TFile * fileToRead_
Definition: CovarianceParameterization.h:70
relativeConstraints.value
value
Definition: relativeConstraints.py:53
CovarianceParameterization::CompressionSchema
Definition: CovarianceParameterization.h:32
CovarianceParameterization::load
void load(int version)
Definition: CovarianceParameterization.cc:78
CompressionElement::logPack
Definition: CovarianceParameterization.h:11
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
CompressionElement::differenceToRef
Definition: CovarianceParameterization.h:12
crabWrapper.key
key
Definition: crabWrapper.py:19
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
MiniFloatConverter::float32to16
static uint16_t float32to16(float x)
Definition: libminifloat.h:20
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
CovarianceParameterization.h