Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
JFIT::JEnergyCorrection Class Reference

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

#include <JEnergyCorrection.hh>

Inheritance diagram for JFIT::JEnergyCorrection:
JLANG::JPointer< JClass_t > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Public Member Functions

 JEnergyCorrection ()
 Default constructor. More...
 
 JEnergyCorrection (const std::string &formula)
 Constructor. More...
 
 JEnergyCorrection (const TFormula *fcn)
 Constructor. More...
 
TString getFormula () const
 Get formula. More...
 
void setFormula (const std::string &formula)
 Set formula. More...
 
double operator() (const double E) const
 Get corrected energy. More...
 
void load (const char *file_name)
 Load formula from file. More...
 
void store (const char *file_name)
 Store formula to file. More...
 
virtual JClass_t * get () const
 Get pointer. More...
 
virtual void set (JClass_t *p)
 Set pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
virtual void reset ()
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JClass_t *p)
 Reset pointer. More...
 
JClass_t *const & getReference () const
 Get rereference to internal pointer. More...
 
JClass_t *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
JClass_t * operator-> () const
 Smart pointer operator. More...
 
 operator JClass_t * () const
 Type conversion operator. More...
 

Static Public Member Functions

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

Protected Attributes

JClass_t * __p
 pointer to object More...
 

Friends

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

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

Constructor & Destructor Documentation

JFIT::JEnergyCorrection::JEnergyCorrection ( )
inline

Default constructor.

No correction is applied to the energy.

Definition at line 47 of file JEnergyCorrection.hh.

48  {}
JFIT::JEnergyCorrection::JEnergyCorrection ( const std::string &  formula)
inline

Constructor.

Parameters
formulaformula

Definition at line 56 of file JEnergyCorrection.hh.

57  {
58  setFormula(formula);
59  }
void setFormula(const std::string &formula)
Set formula.
JFIT::JEnergyCorrection::JEnergyCorrection ( const TFormula *  fcn)
inline

Constructor.

Parameters
fcnpointer to ROOT formula

Definition at line 67 of file JEnergyCorrection.hh.

Member Function Documentation

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

Get formula.

Returns
formula

Definition at line 77 of file JEnergyCorrection.hh.

78  {
79  if (is_valid())
80  return get()->GetExpFormula();
81  else
82  return TString();
83  }
bool is_valid() const
Check validity of pointer.
void JFIT::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 96 of file JEnergyCorrection.hh.

97  {
98  if (formula != "") {
99 
100  TString buffer(formula.c_str());
101 
102  if (buffer.EndsWith(".root") ||
103  buffer.EndsWith(".txt")) {
104 
105  load(buffer);
106 
107  } else {
108 
109  reset(new TFormula(JEnergyCorrection::getName(), buffer));
110  }
111  }
112  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
void load(const char *file_name)
Load formula from file.
static const char * getName()
Get name of energy correction formula.
double JFIT::JEnergyCorrection::operator() ( const double  E) const
inline

Get corrected energy.

Parameters
Eenergy [GeV]
Returns
corrected energy [GeV]

Definition at line 121 of file JEnergyCorrection.hh.

122  {
123  if (is_valid()) {
124 
125  const double y = get()->Eval(log10(E));
126 
127  return pow(10.0, y);
128  }
129 
130  return E;
131  }
bool is_valid() const
Check validity of pointer.
static const char* JFIT::JEnergyCorrection::getName ( )
inlinestatic

Get name of energy correction formula.

Returns
name of formula

Definition at line 139 of file JEnergyCorrection.hh.

140  {
141  return "energy_correction";
142  }
void JFIT::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 157 of file JEnergyCorrection.hh.

158  {
159  using namespace std;
160  using namespace JLANG;
161  using namespace JEEP;
162 
163  TString buffer(getFullFilename(LD_LIBRARY_PATH, file_name).c_str());
164 
165  if (buffer.EndsWith(".root")) {
166 
167  TFile in(buffer, "READ");
168 
169  if (in.IsOpen()) {
170 
171  in.GetObject(JEnergyCorrection::getName(), getReference());
172 
173  in.Close();
174 
175  } else {
176 
177  THROW(JFileOpenException, "Error opening file " << buffer);
178  }
179 
180  } else if (buffer.EndsWith(".txt")) {
181 
182  ifstream in(buffer);
183 
184  if (in) {
185 
186  buffer.ReadFile(in);
187 
188  // remove control characters
189 
190  for (Ssiz_t i = 0; i != buffer.Length(); ++i) {
191  if (iscntrl(buffer[i])) {
192  buffer[i] = ' ';
193  }
194  }
195 
196  in.close();
197 
198  reset(new TFormula(JEnergyCorrection::getName(), buffer));
199 
200  } else {
201 
202  THROW(JFileOpenException, "Error opening file " << buffer);
203  }
204 
205  } else {
206 
207  throw JProtocolException("Protocol not defined.");
208  }
209  }
Exception for opening of file.
Definition: JException.hh:324
static const char *const LD_LIBRARY_PATH
Nick names of environment variables.
Definition: JeepToolkit.hh:29
JClass_t *const & getReference() const
Get rereference to internal pointer.
Definition: JPointer.hh:119
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
static const char * getName()
Get name of energy correction formula.
Protocol exception.
Definition: JException.hh:612
std::string getFullFilename(const std::string &variable, const std::string &file_name)
Get full file name (see JEEP::getPath).
Definition: JeepToolkit.hh:195
void JFIT::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 221 of file JEnergyCorrection.hh.

222  {
223  using namespace std;
224  using namespace JLANG;
225  using namespace JEEP;
226 
227  if (is_valid()) {
228 
229  const TString buffer(file_name);
230 
231  if (buffer.EndsWith(".root")) {
232 
233  TFile out(file_name, "RECREATE");
234 
235  out.WriteObject(get(), JEnergyCorrection::getName());
236 
237  out.Write();
238  out.Close();
239 
240  } else if (buffer.EndsWith(".txt")) {
241 
242  ofstream out(file_name);
243 
244  out << *this;
245 
246  out.close();
247 
248  } else {
249 
250  throw JProtocolException("Protocol not defined.");
251  }
252  }
253  }
bool is_valid() const
Check validity of pointer.
static const char * getName()
Get name of energy correction formula.
Protocol exception.
Definition: JException.hh:612
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlinevirtualinherited
template<class JClass_t>
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t *  p)
inlinevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, and JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >.

Definition at line 75 of file JPointer.hh.

76  {
77  this->__p = p;
78  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::set ( const JPointer< T > &  pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97  {
98  this->set(pointer.get());
99  }
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
virtual void set(JClass_t *p)
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t>
virtual void JLANG::JPointer< JClass_t >::reset ( )
inlinevirtualinherited

Reset pointer.

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >, JLANG::JStorage< JClass_t, JMemory_t >, JLANG::JStorage< JDETECTOR::JK40Simulator, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTail_t >, JNew >, JLANG::JStorage< match_type, JNew >, JLANG::JStorage< JObjectOutput< JTail_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JNullType >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine, JNew >, JLANG::JStorage< JDETECTOR::JPMTSimulator, JNew >, JLANG::JStorage< JObjectIterator< T >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< T >, JNew >, JLANG::JStorage< JRewindableObjectIterator< JTail_t >, JNew >, JLANG::JStorage< JTOOLS::JFunction1D, JNew >, JLANG::JStorage< JDETECTOR::JCLBSimulator, JNew >, JLANG::JStorage< JTOOLS::JMultiMapTransformer, JNew >, JLANG::JStorage< JRewindableObjectIterator< const T >, JNew >, JLANG::JStorage< JBase_t, JNew >, JLANG::JStorage< JParserElementInterface, JNew >, JLANG::JStorage< JFIT::JMEstimator, JNew >, JLANG::JStorage< JAbstractAutoPointer< JBase_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JPHYSICS::JRadiation, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JTDC, JNew >, JLANG::JStorage< JLANG::JMultiPipe< T, N >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JDAQSummaryslice >, JNew >, JLANG::JStorage< JObjectOutput< JHead_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > >, JNew >, JLANG::JStorage< JExceptionHandler, JNew >, JLANG::JStorage< TFile >, JLANG::JStorage< JRewindableObjectIterator< T >, JNew >, JLANG::JStorage< JPropertiesElementInterface, JNew >, JLANG::JStorage< JRewindableObjectIterator< JHead_t >, JNew >, JLANG::JStorage< const JDETECTOR::JModuleRouter, JNew >, JLANG::JStorage< JObjectOutput< T >, JNew >, JLANG::JStorage< JIO::JWriter, JNew >, JLANG::JStorage< JNET::JControlHost, JNew >, JLANG::JStorage< JAccessibleObjectOutput< T >, JNew >, JLANG::JStorage< JIO::JReader, JNew >, and JLANG::JStorage< JLOGGER::JLogger, JNew >.

Definition at line 84 of file JPointer.hh.

85  {
86  this->__p = NULL;
87  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
template<class JClass_t>
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 92 of file JAbstractPointer.hh.

93  {
94  if (this->get() != p) {
95 
96  this->reset();
97 
98  if (p != NULL) {
99  this->set(p);
100  }
101  }
102  }
virtual void reset()=0
Reset pointer.
virtual void set(JClass_t *p)=0
Set pointer.
template<class JClass_t>
JClass_t* const& JLANG::JPointer< JClass_t >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120  {
121  return __p;
122  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
JClass_t* & JLANG::JPointer< JClass_t >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131  {
132  return __p;
133  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
virtual bool JLANG::JAbstractPointer< JClass_t >::equals ( const JAbstractPointer< JClass_t > &  object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 48 of file JAbstractPointer.hh.

49  {
50  return this->get() == object.get();
51  }
template<class JClass_t>
bool JLANG::JAbstractPointer< JClass_t >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 81 of file JAbstractPointer.hh.

82  {
83  return this->get() != NULL;
84  }
template<class JClass_t>
JClass_t* JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 110 of file JAbstractPointer.hh.

111  {
112  if (!is_valid())
113  throw JNullPointerException("JAbstractPointer::operator->()");
114  else
115  return this->get();
116  }
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:198
template<class JClass_t>
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 124 of file JAbstractPointer.hh.

125  {
126  return this->get();
127  }

Friends And Related Function Documentation

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

267  {
268  std::string buffer;
269 
270  getline(in, buffer);
271 
272  object.setFormula(buffer);
273 
274  return in;
275  }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
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 285 of file JEnergyCorrection.hh.

286  {
287  return out << object.getFormula();
288  }

Member Data Documentation

template<class JClass_t>
JClass_t* JLANG::JPointer< JClass_t >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.


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