Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:14:08

0001 #include <iostream>
0002 using namespace std;
0003 
0004 #include "TFile.h"
0005 #include "TTree.h"
0006 #include "TChain.h"
0007 #include "TLegend.h"
0008 #include "math.h"
0009 #include "TH1.h"
0010 #include "TH2.h"
0011 #include "TEfficiency.h"
0012 #include "TLine.h"
0013 #include "TGraphAsymmErrors.h"
0014 
0015 TChain* handleFile(string name, string extension, string treename, unsigned int filecount){
0016   TChain *all = new TChain(treename.c_str());
0017   string temp;
0018   for (int i = 0; i < filecount; ++i)
0019   {
0020 
0021     ostringstream s;
0022     s<<i;
0023     temp = name+string(s.str())+extension;
0024     all->Add(temp.c_str());
0025   }
0026   return all;
0027 }
0028 
0029 void makeMaps(TChain* ttree,TFile* out_file){
0030   float vtxR;
0031   float tvtxR;
0032   float vtx_phi;
0033   float tvtx_phi;
0034   ttree->SetBranchAddress("vtx_radius",&vtxR);
0035   ttree->SetBranchAddress("tvtx_radius",&tvtxR);
0036   ttree->SetBranchAddress("vtx_phi",&vtx_phi);
0037   ttree->SetBranchAddress("tvtx_phi",&tvtx_phi);
0038 
0039   TH2F *map = new TH2F("recoMap","",100,-30,30,100,-30,30);
0040   TH2F *tmap = new TH2F("truthMap","",100,-30,30,100,-30,30);
0041   map->Sumw2();
0042   tmap->Sumw2();
0043 
0044   for (int event = 0; event < ttree->GetEntries(); ++event)
0045   {
0046     ttree->GetEvent(event);
0047     map->Fill(vtxR*TMath::Cos(vtx_phi),vtxR*TMath::Sin(vtx_phi));
0048     tmap->Fill(tvtxR*TMath::Cos(tvtx_phi),tvtxR*TMath::Sin(tvtx_phi));
0049   }
0050   out_file->Write();
0051 }
0052 
0053 void makeDists(TChain *vtxTree, TChain *mainTree, TFile *outf){
0054   TH1F *tmap = new TH1F("truthDist","",60,0,30);
0055   TH1F *rmap = new TH1F("recoDist","",90,0,45);
0056   TH1F *cmap = new TH1F("correctedDist","",60,0,30);
0057   tmap->Sumw2();
0058   rmap->Sumw2();
0059   cmap->Sumw2();
0060 
0061   float tvtx,rvtx,cvtx;
0062   vtxTree->SetBranchAddress("vtx_radius",&rvtx);
0063   vtxTree->SetBranchAddress("tvtx_radius",&tvtx);
0064   mainTree->SetBranchAddress("vtx_radius",&cvtx);
0065 
0066   for (int event = 0; event < vtxTree->GetEntries(); ++event)
0067   {
0068     vtxTree->GetEvent(event);
0069     tmap->Fill(tvtx);
0070     rmap->Fill(rvtx);
0071   }
0072   for (int event = 0; event < mainTree->GetEntries(); ++event)
0073   {
0074     mainTree->GetEvent(event);
0075     cmap->Fill(cvtx);
0076   }
0077   cmap->Scale(1./mainTree->GetEntries());
0078   tmap->Scale(1./vtxTree->GetEntries());
0079   rmap->Scale(1./vtxTree->GetEntries());
0080   outf->Write();
0081 }
0082 
0083 void mapper()
0084 {
0085   TFile *out_file = new TFile("maps.root","RECREATE");
0086   string treePath = "/sphenix/user/vassalli/gammasample/truthconversionembededanalysis";
0087   string treeExtension = ".root";
0088   unsigned int nFiles=1000;
0089   TChain *vtx_tree = handleFile(treePath,treeExtension,"vtxingTree",nFiles);
0090   TChain *main_tree = handleFile(treePath,treeExtension,"cutTreeSignal",nFiles);
0091   cout<<"mapping with "<<vtx_tree->GetEntries()<<" verticies"<<endl;
0092   makeMaps(main_tree,out_file);
0093 //  makeDists(vtx_tree,main_tree,out_file);
0094 }