Jpp  18.2.1
the software that should make you happy
 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::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. More...
 
 JShowerEnergyCorrection (const std::string &formula)
 Constructor. More...
 
 JShowerEnergyCorrection (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 override
 Get pointer. More...
 
virtual void set (JClass_t *p) override
 Set pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
virtual void reset () override
 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, JShowerEnergyCorrection &object)
 Read energy correction from input. More...
 
std::ostream & operator<< (std::ostream &out, const JShowerEnergyCorrection &object)
 Write energy correction to output. More...
 

Detailed Description

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

Definition at line 38 of file JShowerEnergyCorrection.hh.

Constructor & Destructor Documentation

JFIT::JShowerEnergyCorrection::JShowerEnergyCorrection ( )
inline

Default constructor.

No correction is applied to the energy.

Definition at line 46 of file JShowerEnergyCorrection.hh.

47  {}
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.
JFIT::JShowerEnergyCorrection::JShowerEnergyCorrection ( const TFormula *  fcn)
inline

Constructor.

Parameters
fcnpointer to ROOT formula

Definition at line 66 of file JShowerEnergyCorrection.hh.

Member Function Documentation

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.
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  }
void load(const char *file_name)
Load formula from file.
static const char * getName()
Get name of energy correction formula.
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
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  }
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
bool is_valid() const
Check validity of pointer.
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  }
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  }
Exception for opening of file.
Definition: JException.hh:358
static const char *const LD_LIBRARY_PATH
Nick names of environment variables.
Definition: JeepToolkit.hh:34
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:712
static const char * getName()
Get name of energy correction formula.
Protocol exception.
Definition: JException.hh:664
std::string getFullFilename(const std::string &variable, const std::string &file_name)
Get full file name (see JEEP::getPath).
Definition: JeepToolkit.hh:253
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
static const char * getName()
Get name of energy correction formula.
Protocol exception.
Definition: JException.hh:664
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited
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< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< const TFormula >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JRewindableObjectIterator< const event_type > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JEvtWeight >, JLANG::JSharedPointer< JTRIGGER::JDAQHitSelector >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JDiffuseFlux >, JLANG::JSharedPointer< JEvtWeightFactor_t >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JOscProb >, 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< JTRIGGER::JMatch >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JEvtWeightFactor >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >, and JLANG::JSharedPointer< JRadiation >.

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 void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
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< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< const TFormula >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JRewindableObjectIterator< const event_type > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JEvtWeight >, JLANG::JSharedPointer< JTRIGGER::JDAQHitSelector >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JDiffuseFlux >, JLANG::JSharedPointer< JEvtWeightFactor_t >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JOscProb >, 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< JTRIGGER::JMatch >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JEvtWeightFactor >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >, JLANG::JSharedPointer< JRadiation >, JLANG::JStorage< JClass_t, JMemory_t >, JLANG::JStorage< JDETECTOR::JK40Simulator, JNew >, JLANG::JStorage< JBuildL2_t, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTail_t >, JNew >, JLANG::JStorage< JRewindableObjectIterator< const event_type >, 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< JModuleRouter, JNew >, JLANG::JStorage< JTOOLS::JMultiMapTransformer, JNew >, JLANG::JStorage< JTriggerNB, JNew >, JLANG::JStorage< JRewindableObjectIterator< const T >, JNew >, JLANG::JStorage< JBase_t, JNew >, JLANG::JStorage< const TFormula, JNew >, JLANG::JStorage< JTrigger3DMuon, JNew >, JLANG::JStorage< JTrigger3DShower, JNew >, JLANG::JStorage< JParserElementInterface, JNew >, JLANG::JStorage< JFIT::JMEstimator, JNew >, JLANG::JStorage< JAbstractAutoPointer< JBase_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JEvtWeight, JNew >, JLANG::JStorage< JTRIGGER::JDAQHitSelector, JNew >, JLANG::JStorage< JTRIGGER::JMatch, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JTDC, JNew >, JLANG::JStorage< JEvtWeightFactor_t, JNew >, JLANG::JStorage< JLANG::JMultiPipe< T, N >, JNew >, JLANG::JStorage< JServerSocket, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JDAQSummaryslice >, JNew >, JLANG::JStorage< JObjectOutput< JHead_t >, JNew >, JLANG::JStorage< JExceptionHandler, JNew >, JLANG::JStorage< TFile >, JLANG::JStorage< JTimesliceRouter, JNew >, JLANG::JStorage< JControlHost_t, JNew >, JLANG::JStorage< JRadiation, JNew >, JLANG::JStorage< JRewindableObjectIterator< T >, JNew >, JLANG::JStorage< JPropertiesElementInterface, JNew >, JLANG::JStorage< JRewindableObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JBuildL1_t, JNew >, JLANG::JStorage< JObjectOutput< T >, JNew >, JLANG::JStorage< JIO::JWriter, JNew >, JLANG::JStorage< JNET::JControlHost, JNew >, JLANG::JStorage< JAccessibleObjectOutput< T >, JNew >, JLANG::JStorage< JOscProb, JNew >, JLANG::JStorage< JIO::JReader, JNew >, JLANG::JStorage< JLOGGER::JLogger, JNew >, JLANG::JStorage< JTriggerMXShower, JNew >, JLANG::JStorage< JEvtWeightFactor, JNew >, and JLANG::JStorage< JDiffuseFlux, 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 JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
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 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 50 of file JAbstractPointer.hh.

51  {
52  return this->get() == object.get();
53  }
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  }
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:232
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 Function Documentation

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  }
then awk string
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
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

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: