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