Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MachineLearning.CSV.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MachineLearning.CSV.C
1 #include "TROOT.h"
2 #include "TClass.h"
3 #include "TGraph.h"
4 #include "TF1.h"
5 #include "TH1F.h"
6 #include "TH2F.h"
7 #include "TH3F.h"
8 #include "TH3D.h"
9 #include "TTree.h"
10 #include "TCanvas.h"
11 #include "TBranch.h"
12 #include "Riostream.h"
13 #include "TStyle.h"
14 #include "TFile.h"
15 #include "TString.h"
16 #include "TLegend.h"
17 #include "TRandom3.h"
18 #include "TMath.h"
19 #include "math.h"
20 #include "TColor.h"
21 #include <vector>
22 #include <sstream>
23 #include <algorithm>
24 
25 #include <cstdlib>
26 #include "TMath.h"
27 #include <iostream>
28 #include <fstream>
29 #include <string>
30 #include <math.h>
31 #include <cmath>
32 #include "TGraph.h"
33 #include "TGraph2D.h"
34 #include <algorithm>
35 
36 
37 /*
38  Write out jet variables to csv file
39  to be used for machine learning
40 
41  written by sean.jeffas@stonybrook.edu
42 */
43 
45 {
46 
47 
48  ofstream myfile;
49 
50  string filename;
51 
52  // Names to loop over different types of files
53  string seed[10] = {"1","2","3","4","5","6","7","8","9","10"};
54  string type[3] = {"3pion","DISneutral","DIScharged"};
55 
56  filename = "./data/JetSummary_p250_e20_1000events_r05.csv";
57  myfile.open(filename.c_str());
58 
59  // Loop over all LQ, NC, and CC geant files
60  for(int a = 0; a<10; a++){
61  for(int b=0; b<3; b++){
62 
63  const std::string inFile = "LeptoAna_p250_e20_1000events_"+seed[a]+"seed_"+type[b]+"_r05.root";
64  const std::string inDirectory = "/gpfs/mnt/gpfs02/phenix/scratch/spjeffas/data/";
65  std::string inputFile = inDirectory+inFile;
66 
67  TFile *f = TFile::Open(inputFile.c_str());
68  TTree *t = (TTree*)f->Get("event");
69 
70  const int Nevent = t->GetEntries();
71 
72  // Variables for different jet characteristics
73  vector<float> * tracks_rmax;
74  vector<float> * tracks_count;
75  vector<float> * tracks_chargesum;
76  vector<float> * tracks_vertex;
77  vector<float> * jetshape_radius;
78  vector<float> * jetshape_econe_1;
79  vector<float> * jetshape_econe_2;
80  vector<float> * jetshape_econe_5;
81  vector<float> * jet_eta;
82  vector<float> * jet_minv;
83  vector<float> * jet_etotal;
84  vector<float> * jet_ptrans;
85  vector<int> * evtgen_pid;
86 
87  //point to variables in tree
88  t->SetBranchAddress("tracks_rmax_R",&tracks_rmax);
89  t->SetBranchAddress("tracks_count_R",&tracks_count);
90  t->SetBranchAddress("tracks_chargesum_R",&tracks_chargesum);
91  t->SetBranchAddress("tracks_vertex",&tracks_vertex);
92  t->SetBranchAddress("jetshape_radius",&jetshape_radius);
93  t->SetBranchAddress("jetshape_econe_r01",&jetshape_econe_1);
94  t->SetBranchAddress("jetshape_econe_r02",&jetshape_econe_2);
95  t->SetBranchAddress("jetshape_econe_r05",&jetshape_econe_5);
96  t->SetBranchAddress("jet_eta",&jet_eta);
97  t->SetBranchAddress("jet_minv",&jet_minv);
98  t->SetBranchAddress("jet_etotal",&jet_etotal);
99  t->SetBranchAddress("evtgen_pid",&evtgen_pid);
100  t->SetBranchAddress("jet_ptrans",&jet_ptrans);
101 
102 
103  //loop over all events
104  for(int i = 0; i < Nevent; i++)
105  {
106  //Get entry for each event
107  t->GetEntry(i);
108 
109  for(int l=0; l < tracks_rmax->size(); l++){
110 
111  // Get variables for each jet in event
112  double rmax = (*tracks_rmax)[l];
113  int count = (*tracks_count)[l];
114  int chargesum = (*tracks_chargesum)[l];
115  double vertex = (*tracks_vertex)[l];
116  double radius = (*jetshape_radius)[l];
117  double econe_1 = (*jetshape_econe_1)[l];
118  double econe_2 = (*jetshape_econe_2)[l];
119  double econe_5 = (*jetshape_econe_5)[l];
120  double eta = (*jet_eta)[l];
121  double minv = (*jet_minv)[l];
122  double etotal = (*jet_etotal)[l];
123  double ptrans = (*jet_ptrans)[l];
124  int pid = (*evtgen_pid)[l];
125 
126  // If LQ then tag as LQ in csv file
127  if(b == 0 && pid == 15 && vertex == vertex) myfile << count << "," << chargesum << "," << eta << "," << vertex << "," << "tau" << endl;
128 
129  //If SM then tag as SM in csv file
130  if(b != 0 && pid != 15 && pid != 11 && vertex == vertex) myfile << count << "," << chargesum << "," << eta << "," << vertex << "," << "DIS" << endl;
131  }
132  }
133  }
134  }
135 
136  myfile.close();
137 
138 
139 
140 
141  return 0;
142 }