Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mapper.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file mapper.C
1 #include <iostream>
2 using namespace std;
3 
4 #include "TFile.h"
5 #include "TTree.h"
6 #include "TChain.h"
7 #include "TLegend.h"
8 #include "math.h"
9 #include "TH1.h"
10 #include "TH2.h"
11 #include "TEfficiency.h"
12 #include "TLine.h"
13 #include "TGraphAsymmErrors.h"
14 
15 TChain* handleFile(string name, string extension, string treename, unsigned int filecount){
16  TChain *all = new TChain(treename.c_str());
17  string temp;
18  for (int i = 0; i < filecount; ++i)
19  {
20 
21  ostringstream s;
22  s<<i;
23  temp = name+string(s.str())+extension;
24  all->Add(temp.c_str());
25  }
26  return all;
27 }
28 
29 void makeMaps(TChain* ttree,TFile* out_file){
30  float vtxR;
31  float tvtxR;
32  float vtx_phi;
33  float tvtx_phi;
34  ttree->SetBranchAddress("vtx_radius",&vtxR);
35  ttree->SetBranchAddress("tvtx_radius",&tvtxR);
36  ttree->SetBranchAddress("vtx_phi",&vtx_phi);
37  ttree->SetBranchAddress("tvtx_phi",&tvtx_phi);
38 
39  TH2F *map = new TH2F("recoMap","",100,-30,30,100,-30,30);
40  TH2F *tmap = new TH2F("truthMap","",100,-30,30,100,-30,30);
41  map->Sumw2();
42  tmap->Sumw2();
43 
44  for (int event = 0; event < ttree->GetEntries(); ++event)
45  {
46  ttree->GetEvent(event);
47  map->Fill(vtxR*TMath::Cos(vtx_phi),vtxR*TMath::Sin(vtx_phi));
48  tmap->Fill(tvtxR*TMath::Cos(tvtx_phi),tvtxR*TMath::Sin(tvtx_phi));
49  }
50  out_file->Write();
51 }
52 
53 void makeDists(TChain *vtxTree, TChain *mainTree, TFile *outf){
54  TH1F *tmap = new TH1F("truthDist","",60,0,30);
55  TH1F *rmap = new TH1F("recoDist","",90,0,45);
56  TH1F *cmap = new TH1F("correctedDist","",60,0,30);
57  tmap->Sumw2();
58  rmap->Sumw2();
59  cmap->Sumw2();
60 
61  float tvtx,rvtx,cvtx;
62  vtxTree->SetBranchAddress("vtx_radius",&rvtx);
63  vtxTree->SetBranchAddress("tvtx_radius",&tvtx);
64  mainTree->SetBranchAddress("vtx_radius",&cvtx);
65 
66  for (int event = 0; event < vtxTree->GetEntries(); ++event)
67  {
68  vtxTree->GetEvent(event);
69  tmap->Fill(tvtx);
70  rmap->Fill(rvtx);
71  }
72  for (int event = 0; event < mainTree->GetEntries(); ++event)
73  {
74  mainTree->GetEvent(event);
75  cmap->Fill(cvtx);
76  }
77  cmap->Scale(1./mainTree->GetEntries());
78  tmap->Scale(1./vtxTree->GetEntries());
79  rmap->Scale(1./vtxTree->GetEntries());
80  outf->Write();
81 }
82 
83 void mapper()
84 {
85  TFile *out_file = new TFile("maps.root","RECREATE");
86  string treePath = "/sphenix/user/vassalli/gammasample/truthconversionembededanalysis";
87  string treeExtension = ".root";
88  unsigned int nFiles=1000;
89  TChain *vtx_tree = handleFile(treePath,treeExtension,"vtxingTree",nFiles);
90  TChain *main_tree = handleFile(treePath,treeExtension,"cutTreeSignal",nFiles);
91  cout<<"mapping with "<<vtx_tree->GetEntries()<<" verticies"<<endl;
92  makeMaps(main_tree,out_file);
93 // makeDists(vtx_tree,main_tree,out_file);
94 }