CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ObjectResolutionCalc.cc
Go to the documentation of this file.
1 //
2 // $Id: ObjectResolutionCalc.cc,v 1.5 2008/10/08 19:19:25 gpetrucc Exp $
3 //
4 
6 
7 
8 using namespace pat;
9 
10 
11 // constructor with path; default should not be used
12 ObjectResolutionCalc::ObjectResolutionCalc(TString resopath, bool useNN = false): useNN_(useNN) {
13  edm::LogVerbatim("ObjectResolutionCalc") << ("ObjectResolutionCalc") << "=== Constructing a TopObjectResolutionCalc...";
14  resoFile_ = new TFile(resopath);
15  if (!resoFile_) edm::LogError("ObjectResolutionCalc") << "No resolutions fits for this file available: "<<resopath<<"...";
16  TString resObsName[8] = {"_ares","_bres","_cres","_dres","_thres","_phres","_etres","_etares"};
17 
18  TList* keys = resoFile_->GetListOfKeys();
19  TIter nextitem(keys);
20  TKey* key = NULL;
21  while((key = (TKey*)nextitem())) {
22  TString name = key->GetName();
23  if(useNN_) {
24  for(Int_t ro=0; ro<8; ro++) {
25  TString obsName = resObsName[ro]; obsName += "_NN";
26  if(name.Contains(obsName)){
27  network_[ro] = (TMultiLayerPerceptron*) resoFile_->GetKey(name)->ReadObj();
28  }
29  }
30  }
31  else
32  {
33  if(name.Contains("etabin") && (!name.Contains("etbin"))) {
34  for(int p=0; p<8; p++){
35  if(name.Contains(resObsName[p])){
36  TString etabin = name; etabin.Remove(0,etabin.Index("_")+1); 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++) etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinLowEdge(b));
48  etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinUpEdge(tmpEta->GetNbinsX()));
49  edm::LogVerbatim("ObjectResolutionCalc") << "Found "<<etaBinVals_.size()-1 << " eta-bins with edges: ( ";
50  for(size_t u=0; u<etaBinVals_.size(); u++) edm::LogVerbatim("ObjectResolutionCalc") << etaBinVals_[u]<<", ";
51  edm::LogVerbatim("ObjectResolutionCalc") << "\b\b )"<<std::endl;
52 
53  edm::LogVerbatim("ObjectResolutionCalc") << "=== done." << std::endl;
54 }
55 
56 
57 // destructor
59  delete resoFile_;
60 }
61 
62 
63 float ObjectResolutionCalc::obsRes(int obs, int eta, float eT) {
65  "TopObjectResolutionCalc::obsRes should never be called when using a NN for resolutions." );
66  float res = fResVsEt_[obs][eta].Eval(eT);
67  return res;
68 }
69 
70 
72  int nrEtaBins = etaBinVals_.size()-1;
73  int bin = nrEtaBins-1;
74  for(int i=0; i<nrEtaBins; i++) {
75  if(fabs(eta) > etaBinVals_[i] && fabs(eta) < etaBinVals_[i+1]) bin = i;
76  }
77  return bin;
78 }
79 
80 #if OBSOLETE
82  if (useNN_) {
83  double v[2];
84  v[0]=obj.et();
85  v[1]=obj.eta();
86  obj.setResolutionA( network_[0]->Evaluate(0,v ));
87  obj.setResolutionB( network_[1]->Evaluate(0,v ));
88  obj.setResolutionC( network_[2]->Evaluate(0,v ));
89  obj.setResolutionD( network_[3]->Evaluate(0,v ));
90  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
91  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
92  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
93  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
94  } else {
95  int bin = this->etaBin(obj.eta());
96  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
97  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
98  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
99  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
100  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
101  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
102  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
103  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
104  }
105 }
106 
107 
109  if (useNN_) {
110  double v[2];
111  v[0]=obj.et();
112  v[1]=obj.eta();
113  obj.setResolutionA( network_[0]->Evaluate(0,v ));
114  obj.setResolutionB( network_[1]->Evaluate(0,v ));
115  obj.setResolutionC( network_[2]->Evaluate(0,v ));
116  obj.setResolutionD( network_[3]->Evaluate(0,v ));
117  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
118  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
119  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
120  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
121  } else {
122  int bin = this->etaBin(obj.eta());
123  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
124  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
125  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
126  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
127  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
128  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
129  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
130  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
131  }
132 }
133 
134 
136  if (useNN_) {
137  double v[2];
138  v[0]=obj.et();
139  v[1]=obj.eta();
140  obj.setResolutionA( network_[0]->Evaluate(0,v ));
141  obj.setResolutionB( network_[1]->Evaluate(0,v ));
142  obj.setResolutionC( network_[2]->Evaluate(0,v ));
143  obj.setResolutionD( network_[3]->Evaluate(0,v ));
144  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
145  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
146  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
147  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
148  } else {
149  int bin = this->etaBin(obj.eta());
150  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
151  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
152  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
153  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
154  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
155  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
156  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
157  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
158  }
159 }
160 
161 
163  if (useNN_) {
164  double v[2];
165  v[0]=obj.et();
166  v[1]=obj.eta();
167  obj.setResolutionA( network_[0]->Evaluate(0,v ));
168  obj.setResolutionB( network_[1]->Evaluate(0,v ));
169  obj.setResolutionC( network_[2]->Evaluate(0,v ));
170  obj.setResolutionD( network_[3]->Evaluate(0,v ));
171  obj.setResolutionTheta( 1000000. ); // Total freedom
172  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
173  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
174  obj.setResolutionEta( 1000000. ); // Total freedom
175  } else {
176  obj.setResolutionA( this->obsRes(0,0,obj.et()) );
177  obj.setResolutionC( this->obsRes(1,0,obj.et()) );
178  obj.setResolutionB( this->obsRes(2,0,obj.et()) );
179  obj.setResolutionD( this->obsRes(3,0,obj.et()) );
180  obj.setResolutionTheta( 1000000. ); // Total freedom
181  obj.setResolutionPhi( this->obsRes(5,0,obj.et()) );
182  obj.setResolutionEt( this->obsRes(6,0,obj.et()) );
183  obj.setResolutionEta( 1000000. ); // Total freedom
184  }
185 }
186 
187 
189  if (useNN_) {
190  double v[2];
191  v[0]=obj.et();
192  v[1]=obj.eta();
193  obj.setResolutionA( network_[0]->Evaluate(0,v ));
194  obj.setResolutionB( network_[1]->Evaluate(0,v ));
195  obj.setResolutionC( network_[2]->Evaluate(0,v ));
196  obj.setResolutionD( network_[3]->Evaluate(0,v ));
197  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
198  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
199  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
200  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
201  } else {
202  int bin = this->etaBin(obj.eta());
203  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
204  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
205  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
206  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
207  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
208  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
209  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
210  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
211  }
212 }
213 #endif
Analysis-level MET class.
Definition: MET.h:42
virtual double et() const GCC11_FINAL
transverse energy
int i
Definition: DBlmapReader.cc:9
TMultiLayerPerceptron * network_[10]
#define NULL
Definition: scimark2.h:8
T eta() const
Analysis-level tau class.
Definition: Tau.h:50
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
std::vector< float > etaBinVals_
double b
Definition: hdecay.h:120
Analysis-level electron class.
Definition: Electron.h:52
Analysis-level calorimeter jet class.
Definition: Jet.h:71
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
list key
Definition: combine.py:13
float obsRes(int obs, int eta, float eT)
Analysis-level muon class.
Definition: Muon.h:51