test
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 //
3 
5 
6 
7 using namespace pat;
8 
9 
10 // constructor with path; default should not be used
11 ObjectResolutionCalc::ObjectResolutionCalc(const TString& resopath, bool useNN = false): useNN_(useNN) {
12  edm::LogVerbatim("ObjectResolutionCalc") << ("ObjectResolutionCalc") << "=== Constructing a TopObjectResolutionCalc...";
13  resoFile_ = new TFile(resopath);
14  if (!resoFile_) 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 = NULL;
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]; obsName += "_NN";
25  if(name.Contains(obsName)){
26  network_[ro] = (TMultiLayerPerceptron*) resoFile_->GetKey(name)->ReadObj();
27  }
28  }
29  }
30  else
31  {
32  if(name.Contains("etabin") && (!name.Contains("etbin"))) {
33  for(int p=0; p<8; p++){
34  if(name.Contains(resObsName[p])){
35  TString etabin = name; etabin.Remove(0,etabin.Index("_")+1); etabin.Remove(0,etabin.Index("_")+7);
36  int etaBin = etabin.Atoi();
37  TH1F *tmp = (TH1F*) (resoFile_->GetKey(name)->ReadObj());
38  fResVsEt_[p][etaBin] = (TF1)(*(tmp -> GetFunction("F_"+name)));
39  }
40  }
41  }
42  }
43  }
44  // find etabin values
45  TH1F *tmpEta = (TH1F*) (resoFile_->GetKey("hEtaBins")->ReadObj());
46  for(int b=1; b<=tmpEta->GetNbinsX(); b++) etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinLowEdge(b));
47  etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinUpEdge(tmpEta->GetNbinsX()));
48  edm::LogVerbatim("ObjectResolutionCalc") << "Found "<<etaBinVals_.size()-1 << " eta-bins with edges: ( ";
49  for(size_t u=0; u<etaBinVals_.size(); u++) edm::LogVerbatim("ObjectResolutionCalc") << etaBinVals_[u]<<", ";
50  edm::LogVerbatim("ObjectResolutionCalc") << "\b\b )"<<std::endl;
51 
52  edm::LogVerbatim("ObjectResolutionCalc") << "=== done." << std::endl;
53 }
54 
55 
56 // destructor
58  delete resoFile_;
59 }
60 
61 
62 float ObjectResolutionCalc::obsRes(int obs, int eta, float eT) {
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 
69 
71  int nrEtaBins = etaBinVals_.size()-1;
72  int bin = nrEtaBins-1;
73  for(int i=0; i<nrEtaBins; i++) {
74  if(fabs(eta) > etaBinVals_[i] && fabs(eta) < etaBinVals_[i+1]) 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 
106 
108  if (useNN_) {
109  double v[2];
110  v[0]=obj.et();
111  v[1]=obj.eta();
112  obj.setResolutionA( network_[0]->Evaluate(0,v ));
113  obj.setResolutionB( network_[1]->Evaluate(0,v ));
114  obj.setResolutionC( network_[2]->Evaluate(0,v ));
115  obj.setResolutionD( network_[3]->Evaluate(0,v ));
116  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
117  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
118  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
119  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
120  } else {
121  int bin = this->etaBin(obj.eta());
122  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
123  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
124  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
125  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
126  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
127  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
128  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
129  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
130  }
131 }
132 
133 
135  if (useNN_) {
136  double v[2];
137  v[0]=obj.et();
138  v[1]=obj.eta();
139  obj.setResolutionA( network_[0]->Evaluate(0,v ));
140  obj.setResolutionB( network_[1]->Evaluate(0,v ));
141  obj.setResolutionC( network_[2]->Evaluate(0,v ));
142  obj.setResolutionD( network_[3]->Evaluate(0,v ));
143  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
144  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
145  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
146  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
147  } else {
148  int bin = this->etaBin(obj.eta());
149  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
150  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
151  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
152  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
153  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
154  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
155  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
156  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
157  }
158 }
159 
160 
162  if (useNN_) {
163  double v[2];
164  v[0]=obj.et();
165  v[1]=obj.eta();
166  obj.setResolutionA( network_[0]->Evaluate(0,v ));
167  obj.setResolutionB( network_[1]->Evaluate(0,v ));
168  obj.setResolutionC( network_[2]->Evaluate(0,v ));
169  obj.setResolutionD( network_[3]->Evaluate(0,v ));
170  obj.setResolutionTheta( 1000000. ); // Total freedom
171  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
172  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
173  obj.setResolutionEta( 1000000. ); // Total freedom
174  } else {
175  obj.setResolutionA( this->obsRes(0,0,obj.et()) );
176  obj.setResolutionC( this->obsRes(1,0,obj.et()) );
177  obj.setResolutionB( this->obsRes(2,0,obj.et()) );
178  obj.setResolutionD( this->obsRes(3,0,obj.et()) );
179  obj.setResolutionTheta( 1000000. ); // Total freedom
180  obj.setResolutionPhi( this->obsRes(5,0,obj.et()) );
181  obj.setResolutionEt( this->obsRes(6,0,obj.et()) );
182  obj.setResolutionEta( 1000000. ); // Total freedom
183  }
184 }
185 
186 
188  if (useNN_) {
189  double v[2];
190  v[0]=obj.et();
191  v[1]=obj.eta();
192  obj.setResolutionA( network_[0]->Evaluate(0,v ));
193  obj.setResolutionB( network_[1]->Evaluate(0,v ));
194  obj.setResolutionC( network_[2]->Evaluate(0,v ));
195  obj.setResolutionD( network_[3]->Evaluate(0,v ));
196  obj.setResolutionTheta( network_[4]->Evaluate(0,v ));
197  obj.setResolutionPhi( network_[5]->Evaluate(0,v ));
198  obj.setResolutionEt( network_[6]->Evaluate(0,v ));
199  obj.setResolutionEta( network_[7]->Evaluate(0,v ));
200  } else {
201  int bin = this->etaBin(obj.eta());
202  obj.setResolutionA( this->obsRes(0,bin,obj.et()) );
203  obj.setResolutionB( this->obsRes(1,bin,obj.et()) );
204  obj.setResolutionC( this->obsRes(2,bin,obj.et()) );
205  obj.setResolutionD( this->obsRes(3,bin,obj.et()) );
206  obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );
207  obj.setResolutionPhi( this->obsRes(5,bin,obj.et()) );
208  obj.setResolutionEt( this->obsRes(6,bin,obj.et()) );
209  obj.setResolutionEta( this->obsRes(7,bin,obj.et()) );
210  }
211 }
212 #endif
Analysis-level MET class.
Definition: MET.h:43
int i
Definition: DBlmapReader.cc:9
TMultiLayerPerceptron * network_[10]
#define NULL
Definition: scimark2.h:8
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
Analysis-level tau class.
Definition: Tau.h:58
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:78
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
float obsRes(int obs, int eta, float eT)
virtual double et() const final
transverse energy
virtual double eta() const final
momentum pseudorapidity
Analysis-level muon class.
Definition: Muon.h:49