23 #include <trackbase_historic/SvtxVertex.h>
24 #include <trackbase_historic/SvtxVertexMap.h>
27 #include <calobase/RawClusterContainer.h>
28 #include <calobase/RawCluster.h>
29 #include <calobase/RawClusterv1.h>
38 #include "trackpidassoc/TrackPidAssoc.h"
45 #include "TMVA/Tools.h"
46 #include "TMVA/Reader.h"
47 #include "TMVA/MethodCuts.h"
48 #include "TMVA/Factory.h"
49 #include "TMVA/DataLoader.h"
53 #include <gsl/gsl_randist.h>
54 #include <gsl/gsl_rng.h>
57 #include <TMatrixFfwd.h>
110 std::cout <<
"PairMaker::Init: output file " <<
OutputFileName.c_str() <<
" opened." << endl;
111 ntpBDTresponse =
new TNtuple(
"ntpbeforecut",
"",
"select_p:select_n");
113 ntpbeforecut =
new TNtuple(
"ntpbeforecut",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:cemce3x3overp:hcaline3x3overcemce3x3:hcale3x3overp:charge:pid:quality:e_cluster:EventNumber:z:vtxid:nmvtx:nintt:ntpc:cemc_prob:cemc_ecore:cemc_chi2");
114 ntpcutEMOP =
new TNtuple(
"ntpcutEMOP",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:cemc_prob:cemc_ecore");
115 ntpcutHOP =
new TNtuple(
"ntpcutHOP",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:cemc_prob:cemc_ecore");
116 ntpcutEMOP_HinOEM =
new TNtuple(
"ntpcutEMOP_HinOEM",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:cemc_prob:cemc_ecore");
117 ntpcutEMOP_HinOEM_Pt =
new TNtuple(
"ntpcutEMOP_HinOEM_Pt",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:cemc_prob:cemc_ecore");
118 ntpcutEMOP_HinOEM_Pt_read =
new TNtuple(
"ntpcutEMOP_HinOEM_Pt_read",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:trackid:cemc_prob:cemc_ecore");
119 ntpcutBDT_read =
new TNtuple(
"ntpcutBDT_read",
"",
"p:pt:cemce3x3:hcaline3x3:hcaloute3x3:charge:pid:quality:e_cluster:EventNumber:z:vtxid:trackid:cemc_prob:cemc_ecore:EOP:HOM:cemc_chi2");
126 cerr <<
PHWHERE <<
" ERROR: Can not find DST node." << endl;
148 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
150 cerr <<
PHWHERE <<
" ERROR: Can not find SvtxTrackMap node." << endl;
154 cout<<
"EventNumber ===================== " <<
EventNumber-1 << endl;
157 SvtxVertexMap *vtxmap = findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
159 cout <<
"SvtxVertexMap node not found!" << endl;
164 RawClusterContainer* cemc_cluster_container = findNode::getClass<RawClusterContainer>(topNode,
"CLUSTER_CEMC");
165 if(!cemc_cluster_container) {
166 cerr <<
PHWHERE <<
" ERROR: Can not find CLUSTER_CEMC node." << endl;
172 PHG4TruthInfoContainer* truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
173 if(!truth_container) {
174 cerr <<
PHWHERE <<
" ERROR: Can not find G4TruthInfo node." << endl;
189 double gpt = sqrt(gpx*gpx+gpy*gpy);
190 double phi = atan2(gpy,gpx);
191 double eta = asinh(gpz/gpt);
195 if(trackid>truth_container->
GetNumPrimaryVertexParticles()-50) cout << trackid <<
" " << parentid <<
" " << primid <<
" " << gflavor <<
" " << gpt <<
" " << phi <<
" " << eta << endl;
197 cout <<
"mycount = " << mycount << endl;
204 TMVA::Tools::Instance();
207 std::map<std::string,int> Use_p;
208 std::map<std::string,int> Use_n;
215 TMVA::Reader *reader_positive =
new TMVA::Reader(
"!Color:!Silent" );
216 TMVA::Reader *reader_negative =
new TMVA::Reader(
"!Color:!Silent" );
220 Float_t var1_p, var2_p, var3_p;
221 Float_t var1_n, var2_n, var3_n;
222 reader_positive->AddVariable(
"var1_p", &var1_p );
223 reader_positive->AddVariable(
"var2_p", &var2_p );
224 reader_positive->AddVariable(
"var3_p", &var3_p );
226 reader_negative->AddVariable(
"var1_n", &var1_n );
227 reader_negative->AddVariable(
"var2_n", &var2_n );
228 reader_negative->AddVariable(
"var3_n", &var3_n );
231 TString dir_p, dir_n;
232 dir_p =
"dataset/Weights_positive/";
233 dir_n =
"dataset/Weights_negative/";
234 TString
prefix =
"TMVAClassification";
237 for (std::map<std::string,int>::iterator
it = Use_p.begin();
it != Use_p.end();
it++) {
239 TString methodName_p = TString(
it->first) + TString(
" method");
240 TString weightfile_p = dir_p + prefix + TString(
"_") + TString(
it->first) + TString(
".weights.xml");
241 reader_positive->BookMVA( methodName_p, weightfile_p );
245 for (std::map<std::string,int>::iterator
it = Use_n.begin();
it != Use_n.end();
it++) {
247 TString methodName_n = TString(
it->first) + TString(
" method");
248 TString weightfile_n = dir_n + prefix + TString(
"_") + TString(
it->first) + TString(
".weights.xml");
249 reader_negative->BookMVA( methodName_n, weightfile_n );
266 if(gflavor==0)
continue;
277 if(trackerid==0) nmvtx++;
278 if(trackerid==1) nintt++;
279 if(trackerid==2) ntpc++;
287 double px = track->
get_px();
288 double py = track->
get_py();
290 double z = track->
get_z();
294 double mom = track->
get_p();
295 double pt = sqrt(px*px + py*py);
307 double cemc_prob = 0.;
308 double cemc_ecore = 0.;
309 double cemc_chi2 = 99999.;
310 if(cemc_clusid<99999) {
312 cemc_prob = cemc_cluster->
get_prob();
314 cemc_chi2 = cemc_cluster->
get_chi2();
318 double cemceoverp = e_cemc_3x3 / mom;
321 double hcalineovercemce = e_hcal_in_3x3 / e_cemc_3x3;
323 double hcaleoverp = (e_hcal_in_3x3 + e_hcal_out_3x3) / mom;
326 if(cemceoverp>0.0 && cemceoverp<10.0 && hcalineovercemce>0.0 && hcalineovercemce<10.0){
329 var2_p = hcalineovercemce;
334 var2_n = hcalineovercemce;
340 float select_p=reader_positive->EvaluateMVA(
"BDT method");
341 float select_n=reader_negative->EvaluateMVA(
"BDT method");
356 ntp[3] = e_hcal_in_3x3;
357 ntp[4] = e_hcal_out_3x3;
359 ntp[6] = hcalineovercemce;
372 ntp[19] = cemc_ecore;
386 ntp[3] = e_hcal_in_3x3;
387 ntp[4] = e_hcal_out_3x3;
396 ntp[13] = cemc_ecore;
405 ntp[3] = e_hcal_in_3x3;
406 ntp[4] = e_hcal_out_3x3;
415 ntp[13] = cemc_ecore;
424 ntp[3] = e_hcal_in_3x3;
425 ntp[4] = e_hcal_out_3x3;
434 ntp[13] = cemc_ecore;
438 std::cout <<
" Track " <<
it->first <<
" identified as electron " <<
" mom " << mom <<
" e_cemc_3x3 " << e_cemc_3x3 <<
" cemceoverp " << cemceoverp <<
" e_hcal_in_3x3 " << e_hcal_in_3x3 <<
" e_hcal_out_3x3 " << e_hcal_out_3x3 << std::endl;
457 ntp[3] = e_hcal_in_3x3;
458 ntp[4] = e_hcal_out_3x3;
467 ntp[13] = cemc_ecore;
471 std::cout <<
" Track " <<
it->first <<
" identified as hadron " <<
" mom " << mom <<
" e_cemc_3x3 " << e_cemc_3x3 <<
" hcaleoverp " << hcaleoverp <<
" e_hcal_in_3x3 " << e_hcal_in_3x3 <<
" e_hcal_out_3x3 " << e_hcal_out_3x3 << std::endl;
481 delete reader_positive;
482 delete reader_negative;
486 std::cout <<
"Read back the association map electron entries" << std::endl;
488 for(
auto it = electrons.first;
it != electrons.second; ++
it)
494 double mom = tr->
get_p();
497 double pt = sqrt(px*px + py*py);
500 int tr_id =
it->second;
509 double EOP = e_cemc_3x3/mom;
510 double HOM = e_hcal_in_3x3/e_cemc_3x3;
514 double cemc_prob = 0.;
515 double cemc_ecore = 0.;
516 double cemc_chi2 = 99999.;
517 if(cemc_clusid<99999) {
519 cemc_prob = cemc_cluster->
get_prob();
521 cemc_chi2 = cemc_cluster->
get_chi2();
527 ntp[3] = e_hcal_in_3x3;
528 ntp[4] = e_hcal_out_3x3;
538 ntp[14] = cemc_ecore;
546 std::cout <<
" pid " <<
it->first <<
" track ID " <<
it->second <<
" mom " << mom << std::endl;
550 std::cout <<
"Read back the association map hadron entries" << std::endl;
552 for(
auto it = hadrons.first;
it != hadrons.second; ++
it)
558 std::cout <<
" pid " <<
it->first <<
" track ID " <<
it->second <<
" mom " << p << std::endl;
568 _track_map = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
571 _track_pid_assoc = findNode::getClass<TrackPidAssoc>(topNode,
"TrackPidAssoc");
572 if(!_track_pid_assoc)
578 cerr <<
PHWHERE <<
"DST Node missing, quit!" << endl;
588 cout <<
PHWHERE <<
"SVTX node missing, quit!" << endl;
597 cout <<
PHWHERE <<
"Svtx/TrackPidAssoc node added" << endl;
606 double px = track->
get_px();
607 double py = track->
get_py();
608 double pz = track->
get_pz();
609 double pt = sqrt(px*px+py*py);
610 double phi = atan2(py,px);
611 double eta = asinh(pz/pt);
615 double thedistance = 9999.;
622 if(trackid<=truth_container->GetNumPrimaryVertexParticles()-50)
continue;
627 double gpt = sqrt(gpx*gpx+gpy*gpy);
628 double gphi = atan2(gpy,gpx);
629 double geta = asinh(gpz/gpt);
632 if(sqrt(pow(gphi-phi,2)+pow(geta-eta,2))<thedistance) {
633 thedistance = sqrt(pow(gphi-phi,2)+pow(geta-eta,2));
634 matchedMC = g4particle;
650 cout <<
"************END************" << endl;