Jpp 19.3.0-rc.5
the software that should make you happy
Loading...
Searching...
No Matches
JRECONSTRUCTION::JEnergyCorrection Class Reference

Auxiliary class for correction of energy determined by JEnergy.cc. More...

#include <JEnergyCorrection.hh>

Inheritance diagram for JRECONSTRUCTION::JEnergyCorrection:

Public Member Functions

 JEnergyCorrection ()
 Default constructor.
 
 JEnergyCorrection (const std::string &formula)
 Constructor.
 
 JEnergyCorrection (const TFormula *fcn)
 Constructor.
 
bool is_valid () const
 Check validity of pointer.
 
TString getFormula () const
 Get formula.
 
void setFormula (const std::string &formula)
 Set formula.
 
double operator() (const double x) const
 Get corrected value.
 
void load (const char *file_name)
 Load formula from file.
 
void store (const char *file_name)
 Store formula to file.
 

Static Public Member Functions

static const char * getName ()
 Get name of energy correction formula.
 

Friends

std::istream & operator>> (std::istream &in, JEnergyCorrection &object)
 Read energy correction from input.
 
std::ostream & operator<< (std::ostream &out, const JEnergyCorrection &object)
 Write energy correction to output.
 

Detailed Description

Auxiliary class for correction of energy determined by JEnergy.cc.

Note that the correction is applied to 10log(E) with E in GeV.

Definition at line 37 of file JEnergyCorrection.hh.

Constructor & Destructor Documentation

◆ JEnergyCorrection() [1/3]

JRECONSTRUCTION::JEnergyCorrection::JEnergyCorrection ( )
inline

Default constructor.

No correction is applied to the energy.

Definition at line 45 of file JEnergyCorrection.hh.

46 {}

◆ JEnergyCorrection() [2/3]

JRECONSTRUCTION::JEnergyCorrection::JEnergyCorrection ( const std::string & formula)
inline

Constructor.

Parameters
formulaformula

Definition at line 54 of file JEnergyCorrection.hh.

55 {
56 setFormula(formula);
57 }
void setFormula(const std::string &formula)
Set formula.

◆ JEnergyCorrection() [3/3]

JRECONSTRUCTION::JEnergyCorrection::JEnergyCorrection ( const TFormula * fcn)
inline

Constructor.

Parameters
fcnpointer to ROOT formula

Definition at line 65 of file JEnergyCorrection.hh.

65 :
66 std::shared_ptr<const TFormula>(fcn)
67 {}

Member Function Documentation

◆ is_valid()

bool JRECONSTRUCTION::JEnergyCorrection::is_valid ( ) const
inline

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 75 of file JEnergyCorrection.hh.

76 {
77 return (bool) std::shared_ptr<const TFormula>(*this);
78 }

◆ getFormula()

TString JRECONSTRUCTION::JEnergyCorrection::getFormula ( ) const
inline

Get formula.

Returns
formula

Definition at line 86 of file JEnergyCorrection.hh.

87 {
88 if (is_valid())
89 return get()->GetExpFormula();
90 else
91 return TString();
92 }
bool is_valid() const
Check validity of pointer.

◆ setFormula()

void JRECONSTRUCTION::JEnergyCorrection::setFormula ( const std::string & formula)
inline

Set formula.

The input can be:

  • TFormula compatible expression;
  • name of ROOT file (extension .root);
  • name of ASCII file (extension .txt);
Parameters
formulaformula

Definition at line 105 of file JEnergyCorrection.hh.

106 {
107 if (formula != "") {
108
109 TString buffer(formula.c_str());
110
111 if (buffer.EndsWith(".root") ||
112 buffer.EndsWith(".txt")) {
113
114 load(buffer);
115
116 } else {
117
118 reset(new TFormula(JEnergyCorrection::getName(), buffer));
119 }
120 }
121 }
void load(const char *file_name)
Load formula from file.
static const char * getName()
Get name of energy correction formula.
void reset(T &value)
Reset value.

◆ operator()()

double JRECONSTRUCTION::JEnergyCorrection::operator() ( const double x) const
inline

Get corrected value.

Parameters
xvalue
Returns
corrected value

Definition at line 130 of file JEnergyCorrection.hh.

131 {
132 if (is_valid())
133 return get()->Eval(x);
134 else
135 return x;
136 }

◆ getName()

static const char * JRECONSTRUCTION::JEnergyCorrection::getName ( )
inlinestatic

Get name of energy correction formula.

Returns
name of formula

Definition at line 144 of file JEnergyCorrection.hh.

145 {
146 return "energy_correction";
147 }

◆ load()

void JRECONSTRUCTION::JEnergyCorrection::load ( const char * file_name)
inline

Load formula from file.

Supported file formats:

  • ROOT file (extension .root) containing TFormula object with name JEnergyCorrection::getName();
  • ASCII file (extension .txt) containing TFormula compatible expression;

Note that the method JEEP::getFullFilename() is used to search for a possible location of a file with the given name in the LD_LIBRARY_PATH environment variable.

Parameters
file_namefile name

Definition at line 162 of file JEnergyCorrection.hh.

163 {
164 using namespace std;
165 using namespace JLANG;
166 using namespace JEEP;
167
168 TString buffer(getFullFilename(LD_LIBRARY_PATH, file_name).c_str());
169
170 if (buffer.EndsWith(".root")) {
171
172 TFile in(buffer, "READ");
173
174 if (in.IsOpen()) {
175
176 TFormula* f1 = NULL;
177
178 in.GetObject(JEnergyCorrection::getName(), f1);
179
180 reset(new TFormula(JEnergyCorrection::getName(), f1->GetExpFormula("P")));
181 //reset((TFormula*) f1->Clone(JEnergyCorrection::getName()));
182
183 in.Close();
184
185 } else {
186
187 THROW(JFileOpenException, "Error opening file " << buffer);
188 }
189
190 } else if (buffer.EndsWith(".txt")) {
191
192 ifstream in(buffer);
193
194 if (in) {
195
196 buffer.ReadFile(in);
197
198 // remove control characters
199
200 for (Ssiz_t i = 0; i != buffer.Length(); ++i) {
201 if (iscntrl(buffer[i])) {
202 buffer[i] = ' ';
203 }
204 }
205
206 in.close();
207
208 reset(new TFormula(JEnergyCorrection::getName(), buffer));
209
210 } else {
211
212 THROW(JFileOpenException, "Error opening file " << buffer);
213 }
214
215 } else {
216
217 THROW(JProtocolException, "Protocol not defined.");
218 }
219 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for opening of file.
Protocol exception.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
General puprpose classes and methods.
std::string getFullFilename(const std::string &variable, const std::string &file_name)
Get full file name (see JEEP::getPath).
Auxiliary classes and methods for language specific functionality.

◆ store()

void JRECONSTRUCTION::JEnergyCorrection::store ( const char * file_name)
inline

Store formula to file.

Supported file formats:

  • ROOT file (extension .root) containing TFormula object with name JEnergyCorrection::getName;
  • ASCII file (extension .txt) containing TFormula compatible expression;
Parameters
file_namefile name

Definition at line 231 of file JEnergyCorrection.hh.

232 {
233 using namespace std;
234 using namespace JLANG;
235 using namespace JEEP;
236
237 if (is_valid()) {
238
239 const TString buffer(file_name);
240
241 if (buffer.EndsWith(".root")) {
242
243 TFile out(file_name, "RECREATE");
244
245 out.WriteObject(get(), JEnergyCorrection::getName());
246
247 out.Write();
248 out.Close();
249
250 } else if (buffer.EndsWith(".txt")) {
251
252 ofstream out(file_name);
253
254 out << *this;
255
256 out.close();
257
258 } else {
259
260 THROW(JProtocolException, "Protocol not defined.");
261 }
262 }
263 }

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JEnergyCorrection & object )
friend

Read energy correction from input.

In case a file name is specified, the method load() is used to read the energy correction from the corresponding file.

Parameters
ininput stream
objectenergy correction
Returns
input stream

Definition at line 276 of file JEnergyCorrection.hh.

277 {
278 std::string buffer;
279
280 getline(in, buffer);
281
282 object.setFormula(buffer);
283
284 return in;
285 }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JEnergyCorrection & object )
friend

Write energy correction to output.

Parameters
outoutput stream
objectenergy correction
Returns
output stream

Definition at line 295 of file JEnergyCorrection.hh.

296 {
297 return out << object.getFormula();
298 }

The documentation for this class was generated from the following file: