Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JAANET::JEvtWeightCorsika Struct Reference

Implementation of event weighting for Corsika data. More...

#include <JEvtWeightCorsika.hh>

Inheritance diagram for JAANET::JEvtWeightCorsika:
JAANET::JEvtWeightFactorHelper< JEvtWeightFactor_t > JLANG::JClonable< JClonable_t, JDerived_t > JLANG::JSharedPointer< JClass_t, JMemory_t > JLANG::JSharedCounter JLANG::JStorage< JClass_t, JMemory_t > JLANG::JPointer< JClass_t > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Public Types

typedef JPointer< JClass_t > pointer_type
 
typedef JStorage< JClass_t,
JMemory_t > 
storage_type
 
typedef JMemory_t< JClass_t > memory_type
 
typedef JClonable< JClonable_t >
::clone_type 
clone_type
 

Public Member Functions

 JEvtWeightCorsika ()
 Default Constructor. More...
 
 JEvtWeightCorsika (const JHead &header)
 Constructor. More...
 
 JEvtWeightCorsika (const JHead &header, const JFlux &flux)
 Constructor. More...
 
 JEvtWeightCorsika (const JEvtWeightCorsika &object)
 Copy constructor. More...
 
void configure (const JHead &header) override
 Weight configuration. More...
 
bool check (const JHead &header) const override
 Check whether header is consistent with this event weighter. More...
 
double getWeight (const Evt &evt) const override
 Get weight of given event. More...
 
void configure (const JEvtWeightFactor_t &factor)
 Configure event-weight factor. More...
 
double getFactor (const Evt &evt) const
 Get weight-factor of given event. More...
 
const JSharedPointergetSharedPointer () const
 Get shared pointer. More...
 
JSharedPointergetSharedPointer ()
 Get shared pointer. More...
 
void setSharedPointer (const JSharedPointer &object)
 Set shared 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...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
void initialise ()
 Initialise counter. More...
 
void attach (const JSharedCounter &object)
 Attach this counter to given shared counter object. More...
 
bool detach ()
 Detach. More...
 
const int getCount ()
 Get count. More...
 
void recreate ()
 Recreate object in memory. More...
 
void create ()
 Create object in memory. More...
 
void create (const unsigned int size)
 Create array of objects in memory. More...
 
virtual JClass_t * get () const override
 Get 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...
 
virtual clone_type clone () const override
 Get clone of this object. More...
 

Protected Member Functions

void set (const JSharedPointer &object)
 Set pointer. More...
 
virtual void set (JClass_t *p) override
 Set pointer. More...
 
void release ()
 Release memory. More...
 

Protected Attributes

int * counter
 
JClass_t * __p
 pointer to object More...
 

Detailed Description

Implementation of event weighting for Corsika data.

Definition at line 35 of file JEvtWeightCorsika.hh.

Member Typedef Documentation

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JPointer<JClass_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::pointer_type
inherited

Definition at line 34 of file JSharedPointer.hh.

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JStorage<JClass_t, JMemory_t> JLANG::JSharedPointer< JClass_t, JMemory_t >::storage_type
inherited

Definition at line 35 of file JSharedPointer.hh.

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JMemory_t<JClass_t> JLANG::JStorage< JClass_t, JMemory_t >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

template<class JClonable_t, class JDerived_t = JNullType>
typedef JClonable<JClonable_t>::clone_type JLANG::JClonable< JClonable_t, JDerived_t >::clone_type
inherited

Definition at line 61 of file JClonable.hh.

Constructor & Destructor Documentation

JAANET::JEvtWeightCorsika::JEvtWeightCorsika ( )
inline

Default Constructor.

Definition at line 42 of file JEvtWeightCorsika.hh.

42  :
43  JFluxHelper()
44  {}
JEvtWeightFactorHelper< JFlux > JFluxHelper
Type definition of event-weight factor helper for flux functions.
JAANET::JEvtWeightCorsika::JEvtWeightCorsika ( const JHead header)
inline

Constructor.

Parameters
headerheader

Definition at line 52 of file JEvtWeightCorsika.hh.

52  :
53  JFluxHelper()
54  {
55  configure(header);
56  }
void configure(const JHead &header) override
Weight configuration.
JEvtWeightFactorHelper< JFlux > JFluxHelper
Type definition of event-weight factor helper for flux functions.
JAANET::JEvtWeightCorsika::JEvtWeightCorsika ( const JHead header,
const JFlux flux 
)
inline

Constructor.

Parameters
headerheader
fluxflux

Definition at line 65 of file JEvtWeightCorsika.hh.

67  {
68  configure(header);
70  }
void configure(const JHead &header) override
Weight configuration.
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.
JAANET::JEvtWeightCorsika::JEvtWeightCorsika ( const JEvtWeightCorsika object)
inline

Copy constructor.

Parameters
objectoriginal object

Definition at line 78 of file JEvtWeightCorsika.hh.

79  {
80  this->norm = object.norm;
81 
82  if (object.is_valid()) {
83  JFluxHelper::configure(*(object.get()));
84  }
85  }
bool is_valid() const
Check validity of pointer.
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.

Member Function Documentation

void JAANET::JEvtWeightCorsika::configure ( const JHead header)
inlineoverride

Weight configuration.

Parameters
headerheader

Definition at line 93 of file JEvtWeightCorsika.hh.

94  {
95  using namespace JPP;
96 
97  if (check(header)) {
98 
99  norm = 1.0 / header.genvol.numberOfEvents;
100 
101  } else {
102 
103  THROW(JValueOutOfRange, "JEvtWeightCorsika::configure(): Provided header is inconsistent with Corsika.");
104  }
105  }
double numberOfEvents
Number of events.
Definition: JHead.hh:721
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
JAANET::genvol genvol
Definition: JHead.hh:1597
bool JAANET::JEvtWeightCorsika::check ( const JHead header) const
inlineoverride

Check whether header is consistent with this event weighter.

Parameters
headerheader
Returns
true if consistent; else false

Definition at line 114 of file JEvtWeightCorsika.hh.

115  {
116  return is_gseagen(header);
117  }
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
double JAANET::JEvtWeightCorsika::getWeight ( const Evt evt) const
inlineoverride

Get weight of given event.

Parameters
evtevent
Returns
weight [Hz]

Definition at line 126 of file JEvtWeightCorsika.hh.

127  {
128  using namespace JPP;
129 
130  const double& Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
131 
132  if (is_valid() && evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
133 
134  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt) / (1 + Nretries);
135 
136  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
137 
138  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
139 
140  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
141 
142  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt) / (1 + Nretries);
143 
144  } else {
145 
146  if (!is_valid()) {
147  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
148  } else {
149  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
150  }
151  }
152  }
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
static const int WEIGHTLIST_EVENT_RATE
Event rate [s-1].
Definition: weightlist.hh:15
bool is_valid() const
Check validity of pointer.
static const int W2LIST_GSEAGEN_N_RETRIES
Number of extra chances given to each CORSIKA shower to hit the can.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:43
template<class JEvtWeightFactor_t>
void JAANET::JEvtWeightFactorHelper< JEvtWeightFactor_t >::configure ( const JEvtWeightFactor_t &  factor)
inlineinherited

Configure event-weight factor.

Parameters
factorevent-weight factor

Definition at line 63 of file JEvtWeightFactorHelper.hh.

64  {
65  using namespace JPP;
66 
67  JEvtWeightFactor_t* p = dynamic_cast<JEvtWeightFactor_t*>(factor.clone());
68 
69  if (p != NULL) {
70  reset(p);
71  } else {
72  THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor.");
73  }
74  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
virtual void reset() override
Reset pointer.
template<class JEvtWeightFactor_t>
double JAANET::JEvtWeightFactorHelper< JEvtWeightFactor_t >::getFactor ( const Evt evt) const
inlineinherited

Get weight-factor of given event.

Parameters
evtevent
Returns
event-weight factor

Definition at line 83 of file JEvtWeightFactorHelper.hh.

84  {
85  using namespace JPP;
86 
87  if (is_valid()) {
88  return get()->getFactor(evt);
89  } else {
90  THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Unspecified event-weighting factor.");
91  }
92  }
#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.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
template<class JClass_t, template< class > class JMemory_t = JNew>
const JSharedPointer& JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( ) const
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 95 of file JSharedPointer.hh.

96  {
97  return static_cast<const JSharedPointer&>(*this);
98  }
The template JSharedPointer class can be used to share a pointer to an object.
template<class JClass_t, template< class > class JMemory_t = JNew>
JSharedPointer& JLANG::JSharedPointer< JClass_t, JMemory_t >::getSharedPointer ( )
inlineinherited

Get shared pointer.

Returns
this shared pointer

Definition at line 106 of file JSharedPointer.hh.

107  {
108  return static_cast<JSharedPointer&>(*this);
109  }
The template JSharedPointer class can be used to share a pointer to an object.
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::setSharedPointer ( const JSharedPointer< JClass_t, JMemory_t > &  object)
inlineinherited

Set shared pointer.

Parameters
objectshared pointer

Definition at line 117 of file JSharedPointer.hh.

118  {
119  if (this->get() != object.get()) {
120 
121  this->reset();
122 
123  if (object.is_valid()) {
124  this->set(object);
125  }
126  }
127  }
void set(const JSharedPointer &object)
Set pointer.
bool is_valid() const
Check validity of pointer.
virtual void reset() override
Reset pointer.
template<class JClass_t, template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::reset ( )
inlineoverridevirtualinherited

Reset pointer.

The reference counter is decremented by one and the object pointed to previously is deleted when its reference counter is zero.

Reimplemented from JLANG::JStorage< JClass_t, JMemory_t >.

Definition at line 171 of file JSharedPointer.hh.

172  {
173  if (this->detach()) {
175  }
176 
178  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
bool detach()
Detach.
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
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, template< class > class JMemory_t = JNew>
void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( const JSharedPointer< JClass_t, JMemory_t > &  object)
inlineprotectedinherited

Set pointer.

The reference counter of the shared object pointed to is incremented by one.

Parameters
objectshared pointer

Definition at line 188 of file JSharedPointer.hh.

189  {
190  pointer_type::set(object.get());
191 
192  this->attach(object);
193  }
void attach(const JSharedCounter &object)
Attach this counter to given shared counter object.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t, template< class > class JMemory_t = JNew>
virtual void JLANG::JSharedPointer< JClass_t, JMemory_t >::set ( JClass_t *  p)
inlineoverrideprotectedvirtualinherited

Set pointer.

The reference counter of the shared object pointed to is initialised to one.

Parameters
ppointer to derived class object

Reimplemented from JLANG::JPointer< JClass_t >.

Definition at line 202 of file JSharedPointer.hh.

203  {
205 
206  this->initialise();
207  }
void initialise()
Initialise counter.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
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
void JLANG::JSharedCounter::initialise ( )
inlineinherited

Initialise counter.

Definition at line 33 of file JSharedCounter.hh.

34  {
35  detach();
36 
37  counter = new int(1);
38  }
bool detach()
Detach.
void JLANG::JSharedCounter::attach ( const JSharedCounter object)
inlineinherited

Attach this counter to given shared counter object.

Parameters
objectshared counter

Definition at line 46 of file JSharedCounter.hh.

47  {
48  detach();
49 
50  counter = object.counter;
51 
52  if (counter != NULL) {
53  ++(*counter);
54  }
55  }
bool detach()
Detach.
bool JLANG::JSharedCounter::detach ( )
inlineinherited

Detach.

Returns
true if counter at zero; else false

Definition at line 63 of file JSharedCounter.hh.

64  {
65  if (counter != NULL) {
66 
67  if (--(*counter) == 0) {
68 
69  delete counter;
70 
71  counter = NULL;
72 
73  return true;
74  }
75 
76  counter = NULL;
77  }
78 
79  return false;
80  }
const int JLANG::JSharedCounter::getCount ( )
inlineinherited

Get count.

Returns
count

Definition at line 88 of file JSharedCounter.hh.

89  {
90  return (counter != NULL ? *counter : 0);
91  }
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::recreate ( )
inlineinherited

Recreate object in memory.

A new object is created if no memory is allocated yet, else the previously created object is maintained.

Definition at line 57 of file JStorage.hh.

58  {
59  if (!this->is_valid()) {
60  this->set(memory_type::create());
61  }
62  }
bool is_valid() const
Check validity of pointer.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( )
inlineinherited

Create object in memory.

The memory allocated by a previously created object will be released.

Definition at line 69 of file JStorage.hh.

70  {
71  this->reset(memory_type::create());
72  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( const unsigned int  size)
inlineinherited

Create array of objects in memory.

The memory allocated by previously created objects will be released.

Parameters
sizenumber of elements

Definition at line 81 of file JStorage.hh.

82  {
83  this->reset(memory_type::create(size));
84  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92  {
93  memory_type::release(this->get());
94  }
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited
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  }
template<class JClonable_t, class JDerived_t = JNullType>
virtual clone_type JLANG::JClonable< JClonable_t, JDerived_t >::clone ( ) const
inlineoverridevirtualinherited

Member Data Documentation

int* JLANG::JSharedCounter::counter
protectedinherited

Definition at line 94 of file JSharedCounter.hh.

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 struct was generated from the following file: