clas12root
Loading...
Searching...
No Matches
mcparticle.h
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/*
8 * File: mcparticle.h
9 * Author: dglazier
10 *
11 */
12
13#ifndef MCPARTICLE_H
14#define MCPARTICLE_H
15
16#include <hipo4/bank.h>
17#include "mcmatch.h"
18#include <cmath>
19#include <memory>
20
21namespace clas12 {
22
23 class mcparticle : public hipo::bank {
24
25
26 public:
27
28 mcparticle() = default;
29
30 mcparticle(hipo::schema aschema);
31 mcparticle(hipo::schema aschema,hipo::schema schmatch);
32
33 virtual ~mcparticle() = default;
34
35
36 int getPid(int index) const noexcept { return getInt(_pid_order,index);}
37 float getPx(int index) const noexcept { return getFloat(_px_order,index);}
38 float getPy(int index) const noexcept { return getFloat(_py_order,index);}
39 float getPz(int index) const noexcept { return getFloat(_pz_order,index);}
40 float getVx(int index) const noexcept { return getFloat(_vx_order,index);}
41 float getVy(int index) const noexcept { return getFloat(_vy_order,index);}
42 float getVz(int index) const noexcept { return getFloat(_vz_order,index);}
43 float getMass(int index) const noexcept { return getFloat(_mass_order,index);}
44 int getIndex(int index) const noexcept { return getByte(_index_order,index);}
45 int getType(int index) const noexcept { return getByte(_type_order,index);}
46 int getParent(int index) const noexcept { return getByte(_parent_order,index);}
47 int getDaughter(int index) const noexcept { return getByte(_daughter_order,index);}
48 float getLifetime(int index) const noexcept { return getFloat(_life_order,index);}
49
50 int getPid() const noexcept { return _entry==-1 ? 0: getInt(_pid_order,_entry);}
51 float getPx() const noexcept { return _entry==-1 ? 0: getFloat(_px_order,_entry);}
52 float getPy() const noexcept { return _entry==-1 ? 0: getFloat(_py_order,_entry);}
53 float getPz() const noexcept { return _entry==-1 ? 0: getFloat(_pz_order,_entry);}
54 float getVx() const noexcept { return _entry==-1 ? 0: getFloat(_vx_order,_entry);}
55 float getVy() const noexcept { return _entry==-1 ? 0: getFloat(_vy_order,_entry);}
56 float getVz() const noexcept { return _entry==-1 ? 0: getFloat(_vz_order,_entry);}
57 float getMass() const noexcept { return _entry==-1 ? 0: getFloat(_mass_order,_entry);}
58 int getIndex() const noexcept { return _entry==-1 ? 0: getByte(_index_order,_entry);}
59 int getType() const noexcept { return _entry==-1 ? 0: getByte(_type_order,_entry);}
60 int getParent() const noexcept { return _entry==-1 ? 0: getByte(_parent_order,_entry);}
61 int getDaughter() const noexcept { return _entry==-1 ? 0: getByte(_daughter_order,_entry);}
62 float getLifetime() const noexcept { return _entry==-1 ? 0: getFloat(_life_order,_entry);}
63
64
65 float getP() const noexcept{
66 auto x= getFloat(_px_order,_entry);
67 auto y= getFloat(_py_order,_entry);
68 auto z= getFloat(_pz_order,_entry);
69 return sqrt(x*x+y*y+z*z);
70 }
71 float getTheta() const noexcept{
72 auto x= getFloat(_px_order,_entry);
73 auto y= getFloat(_py_order,_entry);
74 auto z= getFloat(_pz_order,_entry);
75 return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0
76 : atan2(sqrt(x*x+y*y),z);
77 }
78 float getPhi() const noexcept{
79 auto x= getFloat(_px_order,_entry);
80 auto y= getFloat(_py_order,_entry);
81 return atan2(y,x);
82 }
83
84 void setEntry(short i) const{
85 if( i<getRows() )_entry=i;
86 else _entry = -1;
87
88 }
89 void setMatchEntry(short ip,short imc) const{
90 _entry=imc;
91 _matched_pindex=ip;
92 if(_match.get())_match->setEntry(_matched_pindex);
93 }
94 void setBankEntry(short i){
95 _entry=i;
96 } //faster for BankHist
97 short getEntry() const noexcept{return _entry;}
103 void notify() final {
104 _entry=-1;
105 _matched_pindex=-1;
106 bank::notify();
107 }
108 int match_to(int pindex) const{//pindex is index of reconstructed particle
109 _matched_pindex=pindex;
110 return _match.get()!=nullptr ?
111 _entry=_match->getMCindex(pindex) : _entry=-1 ;
112 }
113 bool isMatched() const noexcept{return _entry>=0;}
114
115 //mcmatch* getParticleMatch()const {return _match.get();}
116
117 //if matched
119 return _match.get();
120 }
121
122 private:
123
124 int _pid_order{-1};
125 int _px_order{-1};
126 int _py_order{-1};
127 int _pz_order{-1};
128 int _vx_order{-1};
129 int _vy_order{-1};
130 int _vz_order{-1};
131 int _mass_order{-1};
132
133 int _type_order{-1};
134 int _life_order{-1};
135 int _index_order{-1};
136 int _parent_order{-1};
137 int _daughter_order{-1};
138
139 mutable short _entry={0};
140 mutable short _matched_pindex;
141 mcmatch_uptr _match;
142 };
143
145 using mcpar_uptr=std::unique_ptr<clas12::mcparticle>;
146
147}
148
149#endif /* UTILS_H */
Definition mcmatch.h:22
Definition mcparticle.h:23
mcmatch * getMatch() const
Definition mcparticle.h:118
float getMass(int index) const noexcept
Definition mcparticle.h:43
float getPz(int index) const noexcept
Definition mcparticle.h:39
void setEntry(short i) const
Definition mcparticle.h:84
int getIndex() const noexcept
Definition mcparticle.h:58
void setBankEntry(short i)
Definition mcparticle.h:94
void notify() final
Definition mcparticle.h:103
float getPx(int index) const noexcept
Definition mcparticle.h:37
float getP() const noexcept
Definition mcparticle.h:65
float getPz() const noexcept
Definition mcparticle.h:53
int getParent(int index) const noexcept
Definition mcparticle.h:46
short getEntry() const noexcept
Definition mcparticle.h:97
int getIndex(int index) const noexcept
Definition mcparticle.h:44
bool isMatched() const noexcept
Definition mcparticle.h:113
float getTheta() const noexcept
Definition mcparticle.h:71
float getVz(int index) const noexcept
Definition mcparticle.h:42
float getLifetime(int index) const noexcept
Definition mcparticle.h:48
float getPy() const noexcept
Definition mcparticle.h:52
float getVx() const noexcept
Definition mcparticle.h:54
float getPy(int index) const noexcept
Definition mcparticle.h:38
float getVy(int index) const noexcept
Definition mcparticle.h:41
float getPx() const noexcept
Definition mcparticle.h:51
int match_to(int pindex) const
Definition mcparticle.h:108
mcparticle()=default
float getLifetime() const noexcept
Definition mcparticle.h:62
int getType() const noexcept
Definition mcparticle.h:59
float getPhi() const noexcept
Definition mcparticle.h:78
float getVy() const noexcept
Definition mcparticle.h:55
float getMass() const noexcept
Definition mcparticle.h:57
int getType(int index) const noexcept
Definition mcparticle.h:45
int getParent() const noexcept
Definition mcparticle.h:60
int getDaughter(int index) const noexcept
Definition mcparticle.h:47
float getVx(int index) const noexcept
Definition mcparticle.h:40
void setMatchEntry(short ip, short imc) const
Definition mcparticle.h:89
virtual ~mcparticle()=default
int getDaughter() const noexcept
Definition mcparticle.h:61
float getVz() const noexcept
Definition mcparticle.h:56
int getPid(int index) const noexcept
Definition mcparticle.h:36
int getPid() const noexcept
Definition mcparticle.h:50
Definition calextras.cpp:10
clas12::mcparticle * mcpar_ptr
Definition mcparticle.h:144
std::unique_ptr< clas12::mcparticle > mcpar_uptr
Definition mcparticle.h:145
std::unique_ptr< clas12::mcmatch > mcmatch_uptr
Definition mcmatch.h:111