Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JFIT::JShowerEnergyCorrection Class Reference

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

#include <JShowerEnergyCorrection.hh>

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

Public Member Functions

 JShowerEnergyCorrection ()
 Default constructor.
 
 JShowerEnergyCorrection (const std::string &formula)
 Constructor.
 
 JShowerEnergyCorrection (const TFormula *fcn)
 Constructor.
 
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.
 
virtual JClass_t * get () const override
 Get pointer.
 
virtual void set (JClass_t *p) override
 Set pointer.
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer.
 
virtual void reset () override
 Reset pointer.
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer.
 
void reset (JClass_t *p)
 Reset pointer.
 
JClass_t *const & getReference () const
 Get rereference to internal pointer.
 
JClass_t *& getReference ()
 Get rereference to internal pointer.
 
virtual bool equals (const JAbstractPointer &object) const
 Equals.
 
bool is_valid () const
 Check validity of pointer.
 
JClass_t * operator-> () const
 Smart pointer operator.
 
 operator JClass_t * () const
 Type conversion operator.
 

Static Public Member Functions

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

Protected Attributes

JClass_t * __p
 pointer to object
 

Friends

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

Detailed Description

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

Definition at line 38 of file JShowerEnergyCorrection.hh.

Constructor & Destructor Documentation

◆ JShowerEnergyCorrection() [1/3]

JFIT::JShowerEnergyCorrection::JShowerEnergyCorrection ( )
inline

Default constructor.

No correction is applied to the energy.

Definition at line 46 of file JShowerEnergyCorrection.hh.

47 {}

◆ JShowerEnergyCorrection() [2/3]

JFIT::JShowerEnergyCorrection::JShowerEnergyCorrection ( const std::string & formula)
inline

Constructor.

Parameters
formulaformula

Definition at line 55 of file JShowerEnergyCorrection.hh.

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

◆ JShowerEnergyCorrection() [3/3]

JFIT::JShowerEnergyCorrection::JShowerEnergyCorrection ( const TFormula * fcn)
inline

Constructor.

Parameters
fcnpointer to ROOT formula

Definition at line 66 of file JShowerEnergyCorrection.hh.

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

Member Function Documentation

◆ getFormula()

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

Get formula.

Returns
formula

Definition at line 76 of file JShowerEnergyCorrection.hh.

77 {
78 if (is_valid())
79 return get()->GetExpFormula();
80 else
81 return TString();
82 }
bool is_valid() const
Check validity of pointer.
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64

◆ setFormula()

void JFIT::JShowerEnergyCorrection::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 95 of file JShowerEnergyCorrection.hh.

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

◆ operator()()

double JFIT::JShowerEnergyCorrection::operator() ( const double E) const
inline

Get corrected energy.

Parameters
Eenergy [GeV]
Returns
corrected energy [GeV]

Definition at line 120 of file JShowerEnergyCorrection.hh.

121 {
122 if (is_valid()) {
123
124 const double y = get()->Eval(E);
125
126 return y;
127 }
128
129 return E;
130 }

◆ getName()

static const char * JFIT::JShowerEnergyCorrection::getName ( )
inlinestatic

Get name of energy correction formula.

Returns
name of formula

Definition at line 138 of file JShowerEnergyCorrection.hh.

139 {
140 return "energy_correction";
141 }

◆ load()

void JFIT::JShowerEnergyCorrection::load ( const char * file_name)
inline

Load formula from file.

Supported file formats:

  • ROOT file (extension .root) containing TFormula object with name JShowerEnergyCorrection::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 156 of file JShowerEnergyCorrection.hh.

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

Store formula to file.

Supported file formats:

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

Definition at line 220 of file JShowerEnergyCorrection.hh.

221 {
222 using namespace std;
223 using namespace JLANG;
224 using namespace JEEP;
225
226 if (is_valid()) {
227
228 const TString buffer(file_name);
229
230 if (buffer.EndsWith(".root")) {
231
232 TFile out(file_name, "RECREATE");
233
234 out.WriteObject(get(), JShowerEnergyCorrection::getName());
235
236 out.Write();
237 out.Close();
238
239 } else if (buffer.EndsWith(".txt")) {
240
241 ofstream out(file_name);
242
243 out << *this;
244
245 out.close();
246
247 } else {
248
249 THROW(JProtocolException, "Protocol not defined.");
250 }
251 }
252 }

◆ get()

template<class JClass_t >
virtual JClass_t * JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited

◆ set() [1/2]

template<class JClass_t >
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t * p)
inlineoverridevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

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

Definition at line 75 of file JPointer.hh.

76 {
77 this->__p = p;
78 }

◆ set() [2/2]

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 void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75

◆ reset() [1/3]

template<class JClass_t >
virtual void JLANG::JPointer< JClass_t >::reset ( )
inlineoverridevirtualinherited

Reset pointer.

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< Evt > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JNullType > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JNET::JControlHost >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRadiation >, JLANG::JSharedPointer< JRewindableObjectIterator< const event_type > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >, JLANG::JSharedPointer< JTRIGGER::JDAQHitSelector >, JLANG::JSharedPointer< JTRIGGER::JMatch >, JLANG::JSharedPointer< match_type >, JLANG::JStorage< JClass_t, JMemory_t >, JLANG::JStorage< JAbstractAutoPointer< JBase_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< Evt >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JDAQSummaryslice >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTail_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTypeList< JDAQEvent, JNullType > >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< KM3NETDAQ::JDAQEvent >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< T >, JNew >, JLANG::JStorage< JAccessibleObjectOutput< T >, JNew >, JLANG::JStorage< JBase_t, JNew >, JLANG::JStorage< JClass_t, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JTDC, JNew >, JLANG::JStorage< JDETECTOR::JCLBSimulator, JNew >, JLANG::JStorage< JDETECTOR::JK40Simulator, JNew >, JLANG::JStorage< JDETECTOR::JModuleRouter, JNew >, JLANG::JStorage< JDETECTOR::JPMTSimulator, JNew >, JLANG::JStorage< JFIT::JMEstimator, JNew >, JLANG::JStorage< JIO::JReader, JNew >, JLANG::JStorage< JIO::JWriter, JNew >, JLANG::JStorage< JLANG::JMultiPipe< T, N >, JNew >, JLANG::JStorage< JLOGGER::JLogger, JNew >, JLANG::JStorage< JNET::JControlHost, JNew >, JLANG::JStorage< JNET::JControlHostObjectOutput, JNew >, JLANG::JStorage< JNET::JServerSocket, JNew >, JLANG::JStorage< JObjectIterator< T >, JNew >, JLANG::JStorage< JObjectOutput< JHead_t >, JNew >, JLANG::JStorage< JObjectOutput< JTail_t >, JNew >, JLANG::JStorage< JObjectOutput< T >, JNew >, JLANG::JStorage< JParserElementInterface, JNew >, JLANG::JStorage< JPropertiesElementInterface, JNew >, JLANG::JStorage< JRadiation, JNew >, JLANG::JStorage< JRewindableObjectIterator< const event_type >, JNew >, JLANG::JStorage< JRewindableObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JRewindableObjectIterator< JTail_t >, JNew >, JLANG::JStorage< JRewindableObjectIterator< T >, JNew >, JLANG::JStorage< JTOOLS::JFunction1D, JNew >, JLANG::JStorage< JTOOLS::JMultiMapTransformer, JNew >, JLANG::JStorage< JTRIGGER::JBuildL1, JNew >, JLANG::JStorage< JTRIGGER::JBuildL2, JNew >, JLANG::JStorage< JTRIGGER::JDAQHitSelector, JNew >, JLANG::JStorage< JTRIGGER::JMatch, JNew >, JLANG::JStorage< JTRIGGER::JTimesliceRouter, JNew >, JLANG::JStorage< JTRIGGER::JTrigger3DMuon, JNew >, JLANG::JStorage< JTRIGGER::JTrigger3DShower, JNew >, JLANG::JStorage< JTRIGGER::JTriggerMXShower, JNew >, JLANG::JStorage< JTRIGGER::JTriggerNB, JNew >, JLANG::JStorage< match_type, JNew >, and JLANG::JStorage< TFile >.

Definition at line 84 of file JPointer.hh.

85 {
86 this->__p = NULL;
87 }

◆ reset() [2/3]

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 }

◆ reset() [3/3]

template<class JClass_t >
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t * p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95 {
96 if (this->get() != p) {
97
98 this->reset();
99
100 if (p != NULL) {
101 this->set(p);
102 }
103 }
104 }
virtual void set(JClass_t *p)=0
Set pointer.
virtual JClass_t * get() const =0
Get pointer.
virtual void reset()=0
Reset pointer.

◆ getReference() [1/2]

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 }

◆ getReference() [2/2]

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 }

◆ equals()

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 50 of file JAbstractPointer.hh.

51 {
52 return this->get() == object.get();
53 }

◆ is_valid()

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 83 of file JAbstractPointer.hh.

84 {
85 return this->get() != NULL;
86 }

◆ operator->()

template<class JClass_t >
JClass_t * JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113 {
114 if (!is_valid())
115 THROW(JNullPointerException, "JAbstractPointer::operator->()");
116 else
117 return this->get();
118 }

◆ operator JClass_t *()

template<class JClass_t >
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127 {
128 return this->get();
129 }

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JShowerEnergyCorrection & 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 265 of file JShowerEnergyCorrection.hh.

266 {
267 std::string buffer;
268
269 getline(in, buffer);
270
271 object.setFormula(buffer);
272
273 return in;
274 }
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 JShowerEnergyCorrection & object )
friend

Write energy correction to output.

Parameters
outoutput stream
objectenergy correction
Returns
output stream

Definition at line 284 of file JShowerEnergyCorrection.hh.

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

Member Data Documentation

◆ __p

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: