CMS 3D CMS Logo

ObjectResolutionCalc.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
6 using namespace pat;
7 
8 // constructor with path; default should not be used
9 ObjectResolutionCalc::ObjectResolutionCalc(const TString& resopath, bool useNN = false) : useNN_(useNN) {
10  edm::LogVerbatim("ObjectResolutionCalc")
11  << ("ObjectResolutionCalc") << "=== Constructing a TopObjectResolutionCalc...";
12  resoFile_ = new TFile(resopath);
13  if (!resoFile_)
14  edm::LogError("ObjectResolutionCalc") << "No resolutions fits for this file available: " << resopath << "...";
15  TString resObsName[8] = {"_ares", "_bres", "_cres", "_dres", "_thres", "_phres", "_etres", "_etares"};
16 
17  TList* keys = resoFile_->GetListOfKeys();
18  TIter nextitem(keys);
19  TKey* key = nullptr;
20  while ((key = (TKey*)nextitem())) {
21  TString name = key->GetName();
22  if (useNN_) {
23  for (Int_t ro = 0; ro < 8; ro++) {
24  TString obsName = resObsName[ro];
25  obsName += "_NN";
26  if (name.Contains(obsName)) {
27  network_[ro] = (TMultiLayerPerceptron*)resoFile_->GetKey(name)->ReadObj();
28  }
29  }
30  } else {
31  if (name.Contains("etabin") && (!name.Contains("etbin"))) {
32  for (int p = 0; p < 8; p++) {
33  if (name.Contains(resObsName[p])) {
34  TString etabin = name;
35  etabin.Remove(0, etabin.Index("_") + 1);
36  etabin.Remove(0, etabin.Index("_") + 7);
37  int etaBin = etabin.Atoi();
38  TH1F* tmp = (TH1F*)(resoFile_->GetKey(name)->ReadObj());
39  fResVsEt_[p][etaBin] = (TF1)(*(tmp->GetFunction("F_" + name)));
40  }
41  }
42  }
43  }
44  }
45  // find etabin values
46  TH1F* tmpEta = (TH1F*)(resoFile_->GetKey("hEtaBins")->ReadObj());
47  for (int b = 1; b <= tmpEta->GetNbinsX(); b++)
48  etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinLowEdge(b));
49  etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinUpEdge(tmpEta->GetNbinsX()));
50  edm::LogVerbatim("ObjectResolutionCalc") << "Found " << etaBinVals_.size() - 1 << " eta-bins with edges: ( ";
51  for (size_t u = 0; u < etaBinVals_.size(); u++)
52  edm::LogVerbatim("ObjectResolutionCalc") << etaBinVals_[u] << ", ";
53  edm::LogVerbatim("ObjectResolutionCalc") << "\b\b )" << std::endl;
54 
55  edm::LogVerbatim("ObjectResolutionCalc") << "=== done." << std::endl;
56 }
57 
58 // destructor
60 
61 float ObjectResolutionCalc::obsRes(int obs, int eta, float eT) {
62  if (useNN_)
64  "TopObjectResolutionCalc::obsRes should never be called when using a NN for resolutions.");
65  float res = fResVsEt_[obs][eta].Eval(eT);
66  return res;
67 }
68 
70  int nrEtaBins = etaBinVals_.size() - 1;
71  int bin = nrEtaBins - 1;
72  for (int i = 0; i < nrEtaBins; i++) {
73  if (fabs(eta) > etaBinVals_[i] && fabs(eta) < etaBinVals_[i + 1])
74  bin = i;
75  }
76  return bin;
77 }
78 
79 #if OBSOLETE
81  if (useNN_) {
82  double v[2];
83  v[0] = obj.et();
84  v[1] = obj.eta();
85  obj.setResolutionA(network_[0]->Evaluate(0, v));
86  obj.setResolutionB(network_[1]->Evaluate(0, v));
87  obj.setResolutionC(network_[2]->Evaluate(0, v));
88  obj.setResolutionD(network_[3]->Evaluate(0, v));
89  obj.setResolutionTheta(network_[4]->Evaluate(0, v));
90  obj.setResolutionPhi(network_[5]->Evaluate(0, v));
91  obj.setResolutionEt(network_[6]->Evaluate(0, v));
92  obj.setResolutionEta(network_[7]->Evaluate(0, v));
93  } else {
94  int bin = this->etaBin(obj.eta());
95  obj.setResolutionA(this->obsRes(0, bin, obj.et()));
96  obj.setResolutionB(this->obsRes(1, bin, obj.et()));
97  obj.setResolutionC(this->obsRes(2, bin, obj.et()));
98  obj.setResolutionD(this->obsRes(3, bin, obj.et()));
99  obj.setResolutionTheta(this->obsRes(4, bin, obj.et()));
100  obj.setResolutionPhi(this->obsRes(5, bin, obj.et()));
101  obj.setResolutionEt(this->obsRes(6, bin, obj.et()));
102  obj.setResolutionEta(this->obsRes(7, bin, obj.et()));
103  }
104 }
105 
107  if (useNN_) {
108  double v[2];
109  v[0] = obj.et();
110  v[1] = obj.eta();
111  obj.setResolutionA(network_[0]->Evaluate(0, v));
112  obj.setResolutionB(network_[1]->Evaluate(0, v));
113  obj.setResolutionC(network_[2]->Evaluate(0, v));
114  obj.setResolutionD(network_[3]->Evaluate(0, v));
115  obj.setResolutionTheta(network_[4]->Evaluate(0, v));
116  obj.setResolutionPhi(network_[5]->Evaluate(0, v));
117  obj.setResolutionEt(network_[6]->Evaluate(0, v));
118  obj.setResolutionEta(network_[7]->Evaluate(0, v));
119  } else {
120  int bin = this->etaBin(obj.eta());
121  obj.setResolutionA(this->obsRes(0, bin, obj.et()));
122  obj.setResolutionB(this->obsRes(1, bin, obj.et()));
123  obj.setResolutionC(this->obsRes(2, bin, obj.et()));
124  obj.setResolutionD(this->obsRes(3, bin, obj.et()));
125  obj.setResolutionTheta(this->obsRes(4, bin, obj.et()));
126  obj.setResolutionPhi(this->obsRes(5, bin, obj.et()));
127  obj.setResolutionEt(this->obsRes(6, bin, obj.et()));
128  obj.setResolutionEta(this->obsRes(7, bin, obj.et()));
129  }
130 }
131 
133  if (useNN_) {
134  double v[2];
135  v[0] = obj.et();
136  v[1] = obj.eta();
137  obj.setResolutionA(network_[0]->Evaluate(0, v));
138  obj.setResolutionB(network_[1]->Evaluate(0, v));
139  obj.setResolutionC(network_[2]->Evaluate(0, v));
140  obj.setResolutionD(network_[3]->Evaluate(0, v));
141  obj.setResolutionTheta(network_[4]->Evaluate(0, v));
142  obj.setResolutionPhi(network_[5]->Evaluate(0, v));
143  obj.setResolutionEt(network_[6]->Evaluate(0, v));
144  obj.setResolutionEta(network_[7]->Evaluate(0, v));
145  } else {
146  int bin = this->etaBin(obj.eta());
147  obj.setResolutionA(this->obsRes(0, bin, obj.et()));
148  obj.setResolutionB(this->obsRes(1, bin, obj.et()));
149  obj.setResolutionC(this->obsRes(2, bin, obj.et()));
150  obj.setResolutionD(this->obsRes(3, bin, obj.et()));
151  obj.setResolutionTheta(this->obsRes(4, bin, obj.et()));
152  obj.setResolutionPhi(this->obsRes(5, bin, obj.et()));
153  obj.setResolutionEt(this->obsRes(6, bin, obj.et()));
154  obj.setResolutionEta(this->obsRes(7, bin, obj.et()));
155  }
156 }
157 
159  if (useNN_) {
160  double v[2];
161  v[0] = obj.et();
162  v[1] = obj.eta();
163  obj.setResolutionA(network_[0]->Evaluate(0, v));
164  obj.setResolutionB(network_[1]->Evaluate(0, v));
165  obj.setResolutionC(network_[2]->Evaluate(0, v));
166  obj.setResolutionD(network_[3]->Evaluate(0, v));
167  obj.setResolutionTheta(1000000.); // Total freedom
168  obj.setResolutionPhi(network_[5]->Evaluate(0, v));
169  obj.setResolutionEt(network_[6]->Evaluate(0, v));
170  obj.setResolutionEta(1000000.); // Total freedom
171  } else {
172  obj.setResolutionA(this->obsRes(0, 0, obj.et()));
173  obj.setResolutionC(this->obsRes(1, 0, obj.et()));
174  obj.setResolutionB(this->obsRes(2, 0, obj.et()));
175  obj.setResolutionD(this->obsRes(3, 0, obj.et()));
176  obj.setResolutionTheta(1000000.); // Total freedom
177  obj.setResolutionPhi(this->obsRes(5, 0, obj.et()));
178  obj.setResolutionEt(this->obsRes(6, 0, obj.et()));
179  obj.setResolutionEta(1000000.); // Total freedom
180  }
181 }
182 
184  if (useNN_) {
185  double v[2];
186  v[0] = obj.et();
187  v[1] = obj.eta();
188  obj.setResolutionA(network_[0]->Evaluate(0, v));
189  obj.setResolutionB(network_[1]->Evaluate(0, v));
190  obj.setResolutionC(network_[2]->Evaluate(0, v));
191  obj.setResolutionD(network_[3]->Evaluate(0, v));
192  obj.setResolutionTheta(network_[4]->Evaluate(0, v));
193  obj.setResolutionPhi(network_[5]->Evaluate(0, v));
194  obj.setResolutionEt(network_[6]->Evaluate(0, v));
195  obj.setResolutionEta(network_[7]->Evaluate(0, v));
196  } else {
197  int bin = this->etaBin(obj.eta());
198  obj.setResolutionA(this->obsRes(0, bin, obj.et()));
199  obj.setResolutionB(this->obsRes(1, bin, obj.et()));
200  obj.setResolutionC(this->obsRes(2, bin, obj.et()));
201  obj.setResolutionD(this->obsRes(3, bin, obj.et()));
202  obj.setResolutionTheta(this->obsRes(4, bin, obj.et()));
203  obj.setResolutionPhi(this->obsRes(5, bin, obj.et()));
204  obj.setResolutionEt(this->obsRes(6, bin, obj.et()));
205  obj.setResolutionEta(this->obsRes(7, bin, obj.et()));
206  }
207 }
208 #endif
mps_fire.i
i
Definition: mps_fire.py:355
edm::errors::LogicError
Definition: EDMException.h:37
Electron
Definition: Electron.py:1
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
Tau
Definition: Tau.py:1
findQualityFiles.v
v
Definition: findQualityFiles.py:179
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
tools.TF1
TF1
Definition: tools.py:23
pat::ObjectResolutionCalc::resoFile_
TFile * resoFile_
Definition: ObjectResolutionCalc.h:57
Muon
Definition: Muon.py:1
pat::ObjectResolutionCalc::fResVsEt_
TF1 fResVsEt_[10][10]
Definition: ObjectResolutionCalc.h:59
Jet
Definition: Jet.py:1
PVValHelper::eta
Definition: PVValidationHelpers.h:69
pat::ObjectResolutionCalc::ObjectResolutionCalc
ObjectResolutionCalc()
b
double b
Definition: hdecay.h:118
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::LogError
Definition: MessageLogger.h:183
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
ObjectResolutionCalc.h
pat::ObjectResolutionCalc::~ObjectResolutionCalc
~ObjectResolutionCalc()
Definition: ObjectResolutionCalc.cc:59
pat::ObjectResolutionCalc::operator()
void operator()(T &obj)
Definition: ObjectResolutionCalc.h:53
edm::LogVerbatim
Definition: MessageLogger.h:297
pat::MET
Analysis-level MET class.
Definition: MET.h:40
pat
Definition: HeavyIon.h:7
res
Definition: Electron.h:6
pat::ObjectResolutionCalc::useNN_
bool useNN_
Definition: ObjectResolutionCalc.h:61
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
pat::ObjectResolutionCalc::etaBin
int etaBin(float eta)
Definition: ObjectResolutionCalc.cc:69
pat::ObjectResolutionCalc::obsRes
float obsRes(int obs, int eta, float eT)
Definition: ObjectResolutionCalc.cc:61
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
pat::ObjectResolutionCalc::network_
TMultiLayerPerceptron * network_[10]
Definition: ObjectResolutionCalc.h:60
pat::ObjectResolutionCalc::etaBinVals_
std::vector< float > etaBinVals_
Definition: ObjectResolutionCalc.h:58
crabWrapper.key
key
Definition: crabWrapper.py:19