All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
LowMomentumMuPiSeparationPID_BDTG.cc
Go to the documentation of this file.
1 /*
2 --------------- implement Particle Identification for low momentum muon pion separation -------------
3 
4 This code includes class for Particle ID.
5 
6 Boosted Decision Tree with Gradient Boosting is used for separation.
7 In the training, pure muon and pion samples generated using Particle Gun are used.
8 In total 19 different low momenta are investigated starting from 0.2 GeV to 2 GeV.
9 
10 The samples are generated as following:
11 - shoot the particles directly to ECAL (keep Z position fixed) and
12 - change the position of the gun with a defined step size (changes depending on the number of particles generated) and
13 - smear them over the polar and azimuthal angles uniformly
14 
15 ============== G4macro for particle gun:=====================
16 /generator/generator particleGun
17 /gun/position 400 400 2450 mm
18 /gun/positionStep 0.075 0.075 0.0 mm
19 /gun/direction 0 0 1
20 /gun/directionSmearingMode uniform
21 /gun/phiSmearing 360 deg
22 /gun/thetaSmearing 90 deg
23 /gun/particle mu-
24 /gun/momentum 1.0 GeV
25 /run/beamOn 20000
26 /gun/info
27 =============================================================
28 
29 Four discriminative varibales are used in the separation;
30 - depth of the cluster
31 - mean value of the radius of hits wrt cluster cog
32 - RMS value of the radius of hits wrt cluster cog
33 - cluster energy over track momentum
34 
35 For any comments or questions: hale.sert@desy.de
36 */
37 
38 #include <vector>
39 #include <string>
40 
41 #include <EVENT/LCCollection.h>
42 
43 #include <sstream>
44 #include "TROOT.h"
45 #include "TFile.h"
46 #include "TH1.h"
47 
48 #include "EVENT/ReconstructedParticle.h"
49 #include "IMPL/ClusterImpl.h"
50 #include <lcio.h>
51 
53 
54 #include "TMVA/Tools.h"
55 #include "TMVA/Reader.h"
56 
57 
58 using namespace std;
59 
61 
62  reader = new TMVA::Reader("Silent");
63 
64  //Add variables to Reader
65  reader->AddVariable( "Dclus", &Dclus);
66  reader->AddVariable( "EclOvPtr", &EclOvPtr);
67  reader->AddVariable( "Rmean", &Rmean);
68  reader->AddVariable( "Rrms", &Rrms);
69 
70  // Book method(s) with weight file
71  std::vector<std::string> Pvalue;
72  Pvalue.push_back("02GeVP");
73  Pvalue.push_back("03GeVP");
74  Pvalue.push_back("04GeVP");
75  Pvalue.push_back("05GeVP");
76  Pvalue.push_back("06GeVP");
77  Pvalue.push_back("07GeVP");
78  Pvalue.push_back("08GeVP");
79  Pvalue.push_back("09GeVP");
80  Pvalue.push_back("10GeVP");
81  Pvalue.push_back("11GeVP");
82  Pvalue.push_back("12GeVP");
83  Pvalue.push_back("13GeVP");
84  Pvalue.push_back("14GeVP");
85  Pvalue.push_back("15GeVP");
86  Pvalue.push_back("16GeVP");
87  Pvalue.push_back("17GeVP");
88  Pvalue.push_back("18GeVP");
89  Pvalue.push_back("19GeVP");
90  Pvalue.push_back("20GeVP");
91 
92 
93  TString myMethod;
94 
95  for(int i=0; i < 19; i++){
96  myMethod = "BDTG_"+ Pvalue[i]+ "_clusterinfo";
97  weightfile = fname[i];
98  reader->BookMVA( myMethod, weightfile );
99  }
100 }
101 
102 Int_t LowMomentumMuPiSeparationPID_BDTG::MuPiSeparation(TLorentzVector pp, EVENT::Track* trk, EVENT::ClusterVec& cluvec){
103 
104  double tmpid=-1;
105  // std::cout << "==> start ClassApplication" << std::endl;
106 
107  Dclus=0;
108  EclOvPtr=0;
109  Rmean=0;
110  Rrms=0;
111 
112  // BDTG cut values obtained after training
113  Float_t cut02 = -0.0093; // S/sqrt(S+B) = 87.8137
114  Float_t cut03 = -0.1344; // S/sqrt(S+B) = 86.6146
115  Float_t cut04 = -0.0118; // S/sqrt(S+B) = 87.5220
116  Float_t cut05 = -0.0965 ; // S/sqrt(S+B) = 87.4062
117  Float_t cut06 = -0.2278; // S/sqrt(S+B) = 89.0582
118  Float_t cut07 = 0.0030; // S/sqrt(S+B) = 90.5962
119  Float_t cut08 = -0.1708; // S/sqrt(S+B) = 91.3660
120  Float_t cut09 = 0.0060; // S/sqrt(S+B) = 92.1172
121  Float_t cut10 = -0.1957; // S/sqrt(S+B) = 93.3845
122  Float_t cut11 = -0.3255; // S/sqrt(S+B) = 93.5227
123  Float_t cut12 = -0.1523; // S/sqrt(S+B) = 94.2114
124  Float_t cut13 = -0.1290; // S/sqrt(S+B) = 94.0152
125  Float_t cut14 = -0.1301; // S/sqrt(S+B) = 94.5915
126  Float_t cut15 = -0.1729; // S/sqrt(S+B) = 95.0980
127  Float_t cut16 = -0.1704; // S/sqrt(S+B) = 95.6708
128  Float_t cut17 = -0.1978; // S/sqrt(S+B) = 95.7158
129  Float_t cut18 = -0.0110; // S/sqrt(S+B) = 95.7112
130  Float_t cut19 = -0.1871; // S/sqrt(S+B) = 95.8019
131  Float_t cut20 = -0.2328; // S/sqrt(S+B) = 95.7793
132 
133 
134  // get variables used low momentum muon and pion separation --
135  // cluster shape parameters
136  if(cluvec.size()!=0){
137  shapes=cluvec[0]->getShape();
138  }
139 
140  float clene=0;
141  float clpox=0;
142  float clpoy=0;
143  float clpoz=0;
144  float chene[10000]={0};
145  float chpox[10000]={0};
146  float chpoy[10000]={0};
147  float chpoz[10000]={0};
148 
149  int nhit=0;
150 
151  float Rhits_clu = 0;
152  float Rhits2_clu = 0;
153  float rsum_2cluster =0;
154  float r2sum_2cluster =0;
155  float isum_2cluster =0;
156  int m_clu=0;
157  float cosalphacluster=0;
158  unsigned nch=0;
159 
160  const EVENT::TrackStateVec & tss = trk->getTrackStates() ;
161 
162  const lcio::TrackState* ts ;
163 
164  ts = trk->getTrackState( lcio::TrackState::AtCalorimeter ) ;
165 
166  float tscpx = ts->getReferencePoint()[0] ;
167  float tscpy = ts->getReferencePoint()[1] ;
168  float tscpz = ts->getReferencePoint()[2] ;
169 
170  for(size_t iclu=0; iclu < cluvec.size(); iclu++){
171 
172  float Eclu=0;
173  if(cluvec[iclu]->getEnergy() > Eclu){
174  Eclu=cluvec[iclu]->getEnergy();
175  clene = cluvec[iclu]->getEnergy();
176  clpox = cluvec[iclu]->getPosition()[0];
177  clpoy = cluvec[iclu]->getPosition()[1];
178  clpoz = cluvec[iclu]->getPosition()[2];
179 
180  EVENT::CalorimeterHitVec tempvec= cluvec[iclu]->getCalorimeterHits();
181 
182  nch =tempvec.size();
183  for( unsigned jhit=0; jhit < nch ; ++jhit ) {
184  nhit = tempvec.size();
185  chene[jhit] = tempvec[jhit]->getEnergy();
186  chpox[jhit] = tempvec[jhit]->getPosition()[0];
187  chpoy[jhit] = tempvec[jhit]->getPosition()[1];
188  chpoz[jhit] = tempvec[jhit]->getPosition()[2];
189  }
190  }
191  }
192  for(size_t iclu=0; iclu < cluvec.size(); iclu++){
193  for( unsigned jhit=0; jhit < nch ; ++jhit ) {
194 
195  Rhits_clu=sqrt(pow(chpox[jhit]-clpox,2)+pow(chpoy[jhit]-clpoy,2));
196  Rhits2_clu=pow(chpox[jhit]-clpox,2)+pow(chpoy[jhit]-clpoy,2);
197 
198  rsum_2cluster +=Rhits_clu;
199  r2sum_2cluster += Rhits2_clu;
200  isum_2cluster = m_clu++;
201  }
202 
203  // if cluster cog is at endcap
204  _isValid=false;
205  if(abs(clpoz) > 2450){
206  _isValid=true;
207  cosalphacluster = (clpoz - tscpz)/(sqrt(pow(clpox -tscpx,2)+pow(clpoy - tscpy,2)+pow(clpoz- tscpz,2)));
208  Dclus = (clpoz - tscpz)/cosalphacluster;
209  EclOvPtr = clene/pp.P(); //truemom;
210  Rmean = rsum_2cluster/isum_2cluster;
211  Rrms = sqrt(r2sum_2cluster/isum_2cluster);
212  }
213  else {
214  Dclus=0;
215  EclOvPtr=0;
216  Rmean=0;
217  Rrms=0;
218  }
219  }
220 
221  if(shapes.size()!=0){
222  if(Dclus!=0 && EclOvPtr!=0 && Rmean !=0 && Rrms!=0){
223  if(0.15< pp.P() && pp.P()<= 0.25){
224  mvaout = reader->EvaluateMVA("BDTG_02GeVP_clusterinfo");
225  if(mvaout > cut02) tmpid=1;
226  else tmpid=2;
227  }
228  else if(0.25< pp.P() && pp.P()<=0.35){
229  mvaout = reader->EvaluateMVA("BDTG_03GeVP_clusterinfo");
230  if(mvaout > cut03) tmpid=1;
231  else tmpid=2;
232  }
233  else if(0.35< pp.P() && pp.P()<=0.45){
234  mvaout = reader->EvaluateMVA("BDTG_04GeVP_clusterinfo");
235  if(mvaout > cut04) tmpid=1;
236  else tmpid=2;
237  }
238  else if(0.45< pp.P() && pp.P()<=0.55){
239  mvaout = reader->EvaluateMVA("BDTG_05GeVP_clusterinfo");
240  if(mvaout > cut05) tmpid=1;
241  else tmpid=2;
242  }
243  else if(0.55< pp.P() && pp.P()<=0.65){
244  mvaout = reader->EvaluateMVA("BDTG_06GeVP_clusterinfo");
245  if(mvaout > cut06) tmpid=1;
246  else tmpid=2;
247  }
248  else if(0.65< pp.P() && pp.P()<=0.75){
249  mvaout = reader->EvaluateMVA("BDTG_07GeVP_clusterinfo");
250  if(mvaout > cut07) tmpid=1;
251  else tmpid=2;
252  }
253  else if(0.75< pp.P() && pp.P()<=0.85){
254  mvaout = reader->EvaluateMVA("BDTG_08GeVP_clusterinfo");
255  if(mvaout > cut08) tmpid=1;
256  else tmpid=2;
257  }
258  else if(0.85< pp.P() && pp.P()<=0.95){
259  mvaout = reader->EvaluateMVA("BDTG_09GeVP_clusterinfo");
260  if(mvaout > cut09) tmpid=1;
261  else tmpid=2;
262  }
263  else if(0.95< pp.P() && pp.P()<=1.05){
264  mvaout = reader->EvaluateMVA("BDTG_10GeVP_clusterinfo");
265  if(mvaout > cut10) tmpid=1;
266  else tmpid=2;
267  }
268  else if(1.05< pp.P() && pp.P()<=1.15){
269  mvaout = reader->EvaluateMVA("BDTG_11GeVP_clusterinfo");
270  if(mvaout > cut11) tmpid=1;
271  else tmpid=2;
272  }
273  else if(1.15< pp.P() && pp.P()<=1.25){
274  mvaout = reader->EvaluateMVA("BDTG_12GeVP_clusterinfo");
275  if(mvaout > cut12) tmpid=1;
276  else tmpid=2;
277  }
278  else if(1.25< pp.P() && pp.P()<=1.35){
279  mvaout = reader->EvaluateMVA("BDTG_13GeVP_clusterinfo");
280  if(mvaout > cut13) tmpid=1;
281  else tmpid=2;
282  }
283  else if(1.35< pp.P() && pp.P()<=1.45){
284  mvaout = reader->EvaluateMVA("BDTG_14GeVP_clusterinfo");
285  if(mvaout > cut14) tmpid=1;
286  else tmpid=2;
287  }
288  else if(1.45< pp.P() && pp.P()<=1.55){
289  mvaout = reader->EvaluateMVA("BDTG_15GeVP_clusterinfo");
290  if(mvaout > cut15) tmpid=1;
291  else tmpid=2;
292  }
293  else if(1.55< pp.P() && pp.P()<=1.65){
294  mvaout = reader->EvaluateMVA("BDTG_16GeVP_clusterinfo");
295  if(mvaout > cut16) tmpid=1;
296  else tmpid=2;
297  }
298  else if(1.65< pp.P() && pp.P()<=1.75){
299  mvaout = reader->EvaluateMVA("BDTG_17GeVP_clusterinfo");
300  if(mvaout > cut17) tmpid=1;
301  else tmpid=2;
302  }
303  else if(1.75< pp.P() && pp.P()<=1.85){
304  mvaout = reader->EvaluateMVA("BDTG_18GeVP_clusterinfo");
305  if(mvaout > cut18) tmpid=1;
306  else tmpid=2;
307  }
308  else if(1.85< pp.P() && pp.P()<=1.95){
309  mvaout = reader->EvaluateMVA("BDTG_19GeVP_clusterinfo");
310  if(mvaout > cut19) tmpid=1;
311  else tmpid=2;
312  }
313  else if(1.95< pp.P() && pp.P()<=2.05){
314  mvaout = reader->EvaluateMVA("BDTG_20GeVP_clusterinfo");
315  if(mvaout > cut20) tmpid=1;
316  else tmpid=2;
317  }
318  else mvaout = -100.0;
319  }
320  } // shape size
321 
322 return tmpid;
323 
324 }// end of loop
325 
326 
328  return mvaout;
329 }
330 
332  return _isValid;
333 }
334 
336  delete reader;
337 }
LowMomentumMuPiSeparationPID_BDTG(const LowMomentumMuPiSeparationPID_BDTG &)=delete
Int_t MuPiSeparation(TLorentzVector pp, EVENT::Track *trk, EVENT::ClusterVec &cluvec)