Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeAmpToolsFlat_gen.C
Go to the documentation of this file.
1 #define MakeAmpToolsFlat_gen_cxx
2 #include "MakeAmpToolsFlat_gen.h"
3 #include <TH2.h>
4 #include <TStyle.h>
5 #include <TCanvas.h>
6 
8 {
9  // This file was created in the following way
10  // root> TFile *f = TFile::Open("treeFlat_DSelector_Z2pi_trees.root")
11  // root> TTree *t = (TTree *) f->Get("pippimmisspb208_TreeFlat")
12  // root> t->MakeClass("MakeAmpToolsFlat_gen")
13  //
14 // In a ROOT session, you can do:
15 // root> .L MakeAmpToolsFlat_gen.C
16 // root> MakeAmpToolsFlat_gen t
17 // root> t.GetEntry(12); // Fill t data members with entry number 12
18 // root> t.Show(); // Show values of entry 12
19 // root> t.Show(16); // Read and show values of entry 16
20 // root> t.Loop(); // Loop on all entries
21 //
22 
23 // This is the loop skeleton where:
24 // jentry is the global entry number in the chain
25 // ientry is the entry number in the current Tree
26 // Note that the argument to GetEntry must be:
27 // jentry for TChain::GetEntry
28 // ientry for TTree::GetEntry and TBranch::GetEntry
29 //
30 // To read only selected branches, Insert statements like:
31 // METHOD1:
32 // fChain->SetBranchStatus("*",0); // disable all branches
33 // fChain->SetBranchStatus("branchname",1); // activate branchname
34 // METHOD2: replace line
35 // fChain->GetEntry(jentry); //read all branches
36 //by b_branchname->GetEntry(ientry); //read only this branch
37  if (fChain == 0) return;
38 
39  // Initialize output Tree
40 
41  outFile = new TFile("AmpToolsInputTree.root", "RECREATE");
42  m_OutTree = new TTree("kin", "kin2");
43 
44  static size_t locNumFinalStateParticles = 3;
45 
46  m_OutTree->Branch("Weight", new float, "Weight/F");
47  m_OutTree->Branch("E_Beam", new float, "E_Beam/F");
48  m_OutTree->Branch("Px_Beam", new float, "Px_Beam/F");
49  m_OutTree->Branch("Py_Beam", new float, "Py_Beam/F");
50  m_OutTree->Branch("Pz_Beam", new float, "Pz_Beam/F");
51  m_OutTree->Branch("Target_Mass", new float, "Target_Mass/F");
52  m_OutTree->Branch("NumFinalState", new int, "NumFinalState/I");
53  m_OutTree->Branch("PID_FinalState", new int[locNumFinalStateParticles], "PID_FinalState[NumFinalState]/I");
54  m_OutTree->Branch("E_FinalState", new float[locNumFinalStateParticles], "E_FinalState[NumFinalState]/F");
55  m_OutTree->Branch("Px_FinalState", new float[locNumFinalStateParticles], "Px_FinalState[NumFinalState]/F");
56  m_OutTree->Branch("Py_FinalState", new float[locNumFinalStateParticles], "Py_FinalState[NumFinalState]/F");
57  m_OutTree->Branch("Pz_FinalState", new float[locNumFinalStateParticles], "Pz_FinalState[NumFinalState]/F");
58 
59  m_OutTree->SetBranchAddress("NumFinalState", &m_nPart);
60  m_nPart = 3;
61 
62  m_OutTree->SetBranchAddress("Target_Mass", &m_TargetMass);
63  m_TargetMass = 208*0.931494; // Pb mass in GeV.
64 
65  m_OutTree->SetBranchAddress("PID_FinalState", m_PID);
66  m_PID[0] = 8; m_PID[1] = 9; m_PID[2] = 111;
67 
68  m_OutTree->SetBranchAddress("E_FinalState", m_e);
69  m_OutTree->SetBranchAddress("Px_FinalState", m_px);
70  m_OutTree->SetBranchAddress("Py_FinalState", m_py);
71  m_OutTree->SetBranchAddress("Pz_FinalState", m_pz);
72  m_OutTree->SetBranchAddress("E_Beam", &m_eBeam);
73  m_OutTree->SetBranchAddress("Px_Beam", &m_pxBeam);
74  m_OutTree->SetBranchAddress("Py_Beam", &m_pyBeam);
75  m_OutTree->SetBranchAddress("Pz_Beam", &m_pzBeam);
76  m_OutTree->SetBranchAddress("Weight", &m_weight);
77 
78 
79  // Process entries in Tree
80 
81 
82  Long64_t nentries = fChain->GetEntriesFast();
83 
84  Long64_t nbytes = 0, nb = 0;
85  for (Long64_t jentry=0; jentry<nentries;jentry++) {
86  Long64_t ientry = LoadTree(jentry);
87  if (ientry < 0) break;
88  nb = fChain->GetEntry(jentry); nbytes += nb;
89  // if (Cut(ientry) < 0) continue;
90 
91  /*cout<< "jentry=" << jentry << " Beam x=" << Px_Beam << " Beam y=" << Py_Beam << " pz=" << Pz_Beam << " Beam E=" << E_Beam << endl;
92 
93  cout<< "jentry=" << jentry << " pi+ px=" << Px_FinalState[0] << " py=" << Px_FinalState[0] << " pz=" << Px_FinalState[0] << " E=" << E_FinalState[0] << endl;
94  cout<< "jentry=" << jentry << " pi- px=" << Px_FinalState[1] << " py=" << Px_FinalState[1] << " pz=" << Px_FinalState[1] << " E=" << E_FinalState[1] << endl;
95  cout<< "jentry=" << jentry << " misspb px=" << Px_FinalState[2] << " py=" << Px_FinalState[2] << " pz=" << Px_FinalState[2] << " E=" << E_FinalState[2] << endl << endl;*/
96 
97  m_e[0] = E_FinalState[0];
98  m_px[0] = Px_FinalState[0];
99  m_py[0] = Py_FinalState[0];
100  m_pz[0] = Pz_FinalState[0];
101  m_e[1] = E_FinalState[1];
102  m_px[1] = Px_FinalState[1];
103  m_py[1] = Py_FinalState[1];
104  m_pz[1] = Pz_FinalState[1];
105  m_e[2] = E_FinalState[2];
106  m_px[2] = Px_FinalState[2];
107  m_py[2] = Py_FinalState[2];
108  m_pz[2] = Pz_FinalState[2];
109  m_eBeam = E_Beam;
110  m_pxBeam = Px_Beam;
111  m_pyBeam = Py_Beam;
112  m_pzBeam = Pz_Beam;
113  m_weight = 1;
114 
115  m_OutTree->Fill();
116 
117  }
118 
119  // write out tree
120 
121  cout << "Completed loop: nbytes =" << nbytes << " nentries=" << nentries << endl;
122  m_OutTree->Write();
123  outFile->Close();
124 }
virtual Long64_t LoadTree(Long64_t entry)