CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
MucPID.cxx
Go to the documentation of this file.
1#include <fstream>
2#include <cmath>
3#include <cstdlib>
4
5#include "TFile.h"
6#include "TTree.h"
7#include "TMultiLayerPerceptron.h"
8#include "TMLPAnalyzer.h"
9
10#include "ParticleID/MucPID.h"
11
12#ifndef BEAN
16#endif
17
18void CALG(double Px, double& e2); // see "calg.cxx"
19
20MucPID * MucPID::m_pointer = 0;
21
23
24 if(!m_pointer) m_pointer = new MucPID();
25 return m_pointer;
26}
27
28MucPID::MucPID():ParticleIDBase() {
29 m_trainFile_muc = 0;
30 m_trainTree_muc = 0;
31 m_mlp_muc = 0;
32 m_mlpa_muc = 0;
33 //std::string pi_muc_file = "$PARTICLEIDROOT/share/pion_muc_hist.txt";
34 // std::string pi_muc_file = "/ihepbatch/bes/huangb/boss610/Analysis/ParticleID/ParticleID-00-02-03/share/pion_muc_hist.txt";
35 std::string pi_muc_file = path + "/share/pion_muc_hist.txt";
36
37 ifstream input1(pi_muc_file.c_str(),std::ios_base::in);
38 if ( !input1 ) {
39 cout << " can not open: " << pi_muc_file << endl;
40 exit(1);
41 }
42 for(int i=0; i<13; i++) {
43 for(int j=0; j<300; j++) {
44 input1>>m_p_h[i][j];
45 }
46 }
47
48 std::string mu_muc_file = path + "/share/muon_muc_hist.txt";
49 //std::string mu_muc_file = "$PARTICLEIDROOT/share/muon_muc_hist.txt";
50 // std::string mu_muc_file = "/ihepbatch/bes/huangb/boss610/Analysis/ParticleID/ParticleID-00-02-03/share/muon_muc_hist.txt";
51 ifstream input2(mu_muc_file.c_str(),std::ios_base::in);
52 if ( !input2 ) {
53 cout << " can not open: " << mu_muc_file << endl;
54 exit(1);
55 }
56 for(int i=0; i<13; i++) {
57 for(int j=0; j<300; j++) {
58 input2>>m_m_h[i][j];
59 }
60 }
61
62
63
64
65}
66
68 for(int i = 0; i < 5; i++) {
69 m_chi[i] = 99.0;
70 m_prob[i] = -1.0;
71 }
72 m_chimin = 99.;
73 m_ndof = 0;
74 m_hits = -99;
75 m_depth = -999;
76 m_val_muc=-99;
77
78 std::string neural = path + "/share/neural.root";
79 std::string muc = path + "/share/muc.txt";
80 double ptrk,phi,theta,depth,hits,chi2,distance,muc_delta_phi;
81 int type;
82 if(!m_trainTree_muc) {
83 m_trainTree_muc = new TTree("m_trainTree_muc","m_trainTree_muc");
84 m_trainTree_muc->Branch("ptrk",&ptrk,"ptrk/D");
85 m_trainTree_muc->Branch("phi",&phi,"phi/D");
86 m_trainTree_muc->Branch("theta",&theta,"theta/D");
87 m_trainTree_muc->Branch("depth",&depth,"depth/D");
88 m_trainTree_muc->Branch("hits",&hits,"hits/D");
89 m_trainTree_muc->Branch("chi2",&chi2,"chi2/D");
90 m_trainTree_muc->Branch("distance",&distance,"distance/D");
91 m_trainTree_muc->Branch("muc_delta_phi",&muc_delta_phi,"muc_delta_phi/D");
92 m_trainTree_muc->Branch("type",&type,"type/I");
93 }
94 if(!m_mlp_muc) {
95 m_mlp_muc = new TMultiLayerPerceptron("@ptrk,@phi,@theta,@depth,@hits,@chi2,@distance,@muc_delta_phi:16:type",m_trainTree_muc);
96 m_mlp_muc->LoadWeights(muc.c_str());
97 }
98}
99
100
102 if(particleIDCalculation() == 0) m_ndof = 1;
103}
104
106 int irc = -1;
107 EvtRecTrack* recTrk = PidTrk();
108 if(!(recTrk->isMdcTrackValid())) return irc;
109 RecMdcTrack* mdcTrk = recTrk->mdcTrack();
110
111 m_depth = -99;
112 m_hits = -99;
113 m_chi2 =-99;
114 m_distance =-99;
115 m_muc_delta_phi =-99;
116
117 double ptrk = mdcTrk->p();
118 double m_ptrk = ptrk;
119 double m_pt = mdcTrk->pxy();
120 double phi = mdcTrk->phi();
121 double theta = mdcTrk->theta();
122 double cost = cos(mdcTrk->theta());
123 if(ptrk<0.5) return irc;
124 if(fabs(cost)>0.83) return irc;
125 if(!(recTrk->isExtTrackValid())) return irc;
126 RecExtTrack* extTrk = recTrk->extTrack();
127 if(extTrk->mucVolumeNumber() == -1) return irc;
128 if (!(recTrk->isMucTrackValid())) return irc;
129 RecMucTrack* mucTrk = recTrk->mucTrack();
130
131 // if(mucTrk->maxHitsInLayer()< 0) return irc;
132 if(mucTrk->depth()>100000) return irc;
133
134 m_hits = mucTrk->maxHitsInLayer();
135 m_depth = mucTrk->depth();
136 m_distance = mucTrk->distance();
137 m_chi2 = mucTrk->chi2();
138 /* Hep3Vector phi_muc;
139 phi_muc.set(mucTrk->xPos(),mucTrk->yPos(),0);
140 Hep3Vector phi_mdc;
141 phi_mdc.set(mdcTrk->px(),mdcTrk->py(),0);
142 m_muc_delta_phi = phi_muc.angle(phi_mdc);
143 if(m_muc_delta_phi<0) m_muc_delta_phi = -m_muc_delta_phi; */
144 m_muc_delta_phi= mucTrk->deltaPhi();
145 m_muc_delta_phi=3.14159-m_muc_delta_phi;
146 theta = cos(theta);
147 params_muc1[0] = m_ptrk;
148 params_muc1[1] = phi;
149 params_muc1[2] = theta;
150 params_muc1[3] = m_depth;
151 params_muc1[4] = m_hits;
152 params_muc1[5] = m_chi2;
153 params_muc1[6] = m_distance;
154 params_muc1[7] = m_muc_delta_phi;
155
156 m_val_muc = m_mlp_muc->Evaluate(0,params_muc1);
157 if(m_pt<0) m_pt = -m_pt;
158 int pindex = int((m_ptrk-0.5)/0.1);
159 int bindex = int((m_val_muc-0.5)/0.01);
160 if(bindex>300||bindex<0) return irc;
161 if(pindex>11) pindex=11;
162 if(pindex<0) pindex=0;
163 m_prob[0] = m_p_h[pindex][bindex];;
164 m_prob[1] = m_m_h[pindex][bindex];
165 m_prob[2] = m_p_h[pindex][bindex];
166 m_prob[3] = m_p_h[pindex][bindex];
167 m_prob[4] = m_p_h[pindex][bindex];
168 for(int i =0; i<5; i++) {
169 if(m_prob[i]==0) m_prob[i] = 0.001;
170 }
171 float ppp[5];
172 for(int i =0; i<5; i++) {
173 ppp[i] = 0.0;
174 }
175
176 for(int j=0; j<bindex; j++) {
177 ppp[1]+= m_m_h[pindex][j]*0.01;
178 ppp[2]+= m_p_h[pindex][j]*0.01;
179 }
180 if(ppp[1]>0&&ppp[1]<1)
181 CALG(ppp[1],m_chi[1]);
182 if(ppp[2]>0&&ppp[2]<1)
183 CALG(ppp[2],m_chi[2]);
184 if(ppp[1]<=0||ppp[1]>=1)
185 m_chi[1]=-99;
186 if(ppp[2]<=0||ppp[2]>=1)
187 m_chi[2]=-99;
188
189 m_chi[3]=m_chi[2];
190 m_chi[4]=m_chi[2];
191 m_chi[0] =m_chi[2];
192 m_ndof = 1;
193 irc = 0;
194 return irc;
195}
double cos(const BesAngle a)
Definition: BesAngle.h:213
double Px(RecMdcKalTrack *trk)
Double_t e2
NTuple::Item< double > m_pt
Definition: MdcHistItem.h:76
void CALG(double Px, double &e2)
Definition: calg.cxx:31
void CALG(double Px, double &e2)
Definition: calg.cxx:31
const int mucVolumeNumber() const
Definition: DstExtTrack.h:160
const double theta() const
Definition: DstMdcTrack.h:59
const double phi() const
Definition: DstMdcTrack.h:60
const double pxy() const
Definition: DstMdcTrack.h:54
const double p() const
Definition: DstMdcTrack.h:58
double deltaPhi() const
Definition: DstMucTrack.h:63
int maxHitsInLayer() const
Definition: DstMucTrack.h:43
double distance() const
Definition: DstMucTrack.h:62
double depth() const
Definition: DstMucTrack.h:45
double chi2() const
Definition: DstMucTrack.h:46
RecMucTrack * mucTrack()
Definition: EvtRecTrack.h:71
bool isExtTrackValid()
Definition: EvtRecTrack.h:57
RecExtTrack * extTrack()
Definition: EvtRecTrack.h:68
bool isMucTrackValid()
Definition: EvtRecTrack.h:56
bool isMdcTrackValid()
Definition: EvtRecTrack.h:47
RecMdcTrack * mdcTrack()
Definition: EvtRecTrack.h:61
Definition: MucPID.h:20
double distance() const
Definition: MucPID.h:35
double depth() const
Definition: MucPID.h:33
double chi2() const
Definition: MucPID.h:34
void init()
Definition: MucPID.cxx:67
int particleIDCalculation()
Definition: MucPID.cxx:105
static MucPID * instance()
Definition: MucPID.cxx:22
void calculate()
Definition: MucPID.cxx:101
double hits() const
Definition: MucPID.h:32
EvtRecTrack * PidTrk() const
static std::string path
std::ifstream ifstream
Definition: bpkt_streams.h:44