Jpp test-rotations-old
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 E) const
 Get corrected energy.
 
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 38 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 46 of file JEnergyCorrection.hh.

47 {}

◆ JEnergyCorrection() [2/3]

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

Constructor.

Parameters
formulaformula

Definition at line 55 of file JEnergyCorrection.hh.

56 {
57 setFormula(formula);
58 }
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 66 of file JEnergyCorrection.hh.

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

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 76 of file JEnergyCorrection.hh.

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

◆ getFormula()

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

Get formula.

Returns
formula

Definition at line 87 of file JEnergyCorrection.hh.

88 {
89 if (is_valid())
90 return get()->GetExpFormula();
91 else
92 return TString();
93 }
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 106 of file JEnergyCorrection.hh.

107 {
108 if (formula != "") {
109
110 TString buffer(formula.c_str());
111
112 if (buffer.EndsWith(".root") ||
113 buffer.EndsWith(".txt")) {
114
115 load(buffer);
116
117 } else {
118
119 reset(new TFormula(JEnergyCorrection::getName(), buffer));
120 }
121 }
122 }
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 E) const
inline

Get corrected energy.

Parameters
Eenergy [GeV]
Returns
corrected energy [GeV]

Definition at line 131 of file JEnergyCorrection.hh.

132 {
133 if (is_valid()) {
134
135 const double y = get()->Eval(log10(E));
136
137 return pow(10.0, y);
138 }
139
140 return E;
141 }
T pow(const T &x, const double y)
Power .
Definition JMath.hh:97

◆ getName()

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

Get name of energy correction formula.

Returns
name of formula

Definition at line 149 of file JEnergyCorrection.hh.

150 {
151 return "energy_correction";
152 }

◆ 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 167 of file JEnergyCorrection.hh.

168 {
169 using namespace std;
170 using namespace JLANG;
171 using namespace JEEP;
172
173 TString buffer(getFullFilename(LD_LIBRARY_PATH, file_name).c_str());
174
175 if (buffer.EndsWith(".root")) {
176
177 TFile in(buffer, "READ");
178
179 if (in.IsOpen()) {
180
181 TFormula* f1;
182
183 in.GetObject(JEnergyCorrection::getName(), f1);
184
185 reset(f1);
186
187 in.Close();
188
189 } else {
190
191 THROW(JFileOpenException, "Error opening file " << buffer);
192 }
193
194 } else if (buffer.EndsWith(".txt")) {
195
196 ifstream in(buffer);
197
198 if (in) {
199
200 buffer.ReadFile(in);
201
202 // remove control characters
203
204 for (Ssiz_t i = 0; i != buffer.Length(); ++i) {
205 if (iscntrl(buffer[i])) {
206 buffer[i] = ' ';
207 }
208 }
209
210 in.close();
211
212 reset(new TFormula(JEnergyCorrection::getName(), buffer));
213
214 } else {
215
216 THROW(JFileOpenException, "Error opening file " << buffer);
217 }
218
219 } else {
220
221 THROW(JProtocolException, "Protocol not defined.");
222 }
223 }
#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 235 of file JEnergyCorrection.hh.

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

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 280 of file JEnergyCorrection.hh.

281 {
282 std::string buffer;
283
284 getline(in, buffer);
285
286 object.setFormula(buffer);
287
288 return in;
289 }
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 299 of file JEnergyCorrection.hh.

300 {
301 return out << object.getFormula();
302 }

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