30 {
31
32 std::cout << "Making histograms..." << std::endl;
33
34
35 std::string overwrite;
36 struct stat buffer;
37 if( stat (outfilename.Data(), &buffer) == 0 ){
38 TFile* testfile = new TFile(outfilename);
39 if( testfile && testfile->GetListOfKeys()->IsEmpty() == false ){
40 std::cout << outfilename << " exists. Are you sure you want to overwrite it (y/n)? ";
41 std::cin >> overwrite;
42 if( overwrite == "n" ) return;
43 testfile->Close();
44 }
45 }
46
47
48 TFile* outfile = new TFile(outfilename,"RECREATE");
49
50 std::cout << "Making histograms..." << std::endl;
51
52
53 for( int i = 0; i < filenames.size(); ++i ){
54 TFile* infile = new TFile(filenames[i]);
55 TTree* intree = (TTree*)infile->Get("track");
56 infile->cd();
57
58 TString cuts = TString::Format("dedxsat>0&&costh==costh");
59
60 if( m_type == 0 )
61 cuts += TString::Format("&&numGoodHits>=0&&numGoodHits<=100");
62 if( m_type == 1 )
63 cuts += TString::Format("&&lNHitsUsed>=0&&lNHitsUsed<=100");
64
65
66 TString name;
67 if( i == 0 ){
68 name = "pion";
69 cuts += "&&eopst<0.75";
70 }
71 else if( i == 1 ){
72 name = "kaon";
73 cuts += "&&dedx>=0.4/TMath::Abs(pF)";
74 }
75 else if( i == 2 ){
76 name = "proton";
77 cuts += "&&dedx>0&&dedx<100&&dedx>0.85/TMath::Abs(pF)";
78 }
79 else if( i == 3 ) name = "muon";
80 else if( i == 4 ) name = "electron";
81
82
83 intree->Project(TString::Format("hp(100,0,%f)",m_upperp[i]),"abs(pF)",cuts);
84 TH1F* hp = (TH1F*)infile->Get("hp");
85 hp->SetName(name+"_hp");
86 hp->SetTitle(""); hp->SetStats(0);
87 hp->SetXTitle("p [GeV/c]"); hp->SetYTitle("Events");
88
89
90 intree->Project("hcosth(100,-1,1)","costh",cuts);
91 TH1F* hcosth = (TH1F*)infile->Get("hcosth");
92 hcosth->SetName(name+"_hcosth");
93 hcosth->SetTitle(""); hcosth->SetStats(0);
94 hcosth->SetXTitle("cos(#theta)"); hcosth->SetYTitle("Events");
95
96
97 if( i == 1 || i == 2 ) intree->Project(TString::Format("dedx_p(100,0,%f,100,0,10)",m_upperp[i]+(m_upperp[i]-m_lowerp[i])*0.1),"dedx:abs(pF)",cuts);
98 else intree->Project(TString::Format("dedx_p(100,0,%f,100,0,3)",m_upperp[i]+(m_upperp[i]-m_lowerp[i])*0.1),"dedx:abs(pF)",cuts);
99 TH2F* dedx_p = (TH2F*)infile->Get("dedx_p");
100 dedx_p->SetName(name+"_dedx_p");
101 dedx_p->SetTitle(""); dedx_p->SetStats(0);
102 dedx_p->SetXTitle("p [GeV/c]"); dedx_p->SetYTitle("dE/dx");
103
104
105 intree->Project(TString::Format("p_costh(100,-1,1,100,0,%f)",m_upperp[i]+(m_upperp[i]-m_lowerp[i])*0.1),"abs(pF):costh",cuts);
106 TH2F* p_costh = (TH2F*)infile->Get("p_costh");
107 p_costh->SetName(name+"_p_costh");
108 p_costh->SetTitle(""); p_costh->SetStats(0);
109 p_costh->SetYTitle("p [GeV/c]"); p_costh->SetXTitle("cos(#theta)");
110
111
112 if( m_type == 1 )
113 intree->Project("nhit_pt(100,0,2.0,60,0,60)","lNHitsUsed:abs(pF)*sqrt(1-costh*costh)",cuts);
114
115 else
116 intree->Project("nhit_pt(100,0,2.0,60,0,60)","numGoodHits:abs(pF)*sqrt(1-costh*costh)",cuts);
117
118 TH2F* nhit_pt = (TH2F*)infile->Get("nhit_pt");
119 nhit_pt->SetName(name+"_nhit_pt");
120 nhit_pt->SetTitle(""); nhit_pt->SetStats(0);
121 nhit_pt->SetXTitle("p_t [GeV/c]"); nhit_pt->SetYTitle("Number of Hits");
122
123
124 outfile->cd();
125 hp->Write();
126 hcosth->Write();
127 dedx_p->Write();
128 p_costh->Write();
129 nhit_pt->Write();
130
131 infile->Close();
132 }
133
134 outfile->Close();
135}