BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
WidgetQuality Class Reference

#include <WidgetQuality.h>

Public Member Functions

 WidgetQuality ()
 
 WidgetQuality (int type, double *bgmax, double *bgmin)
 
virtual ~WidgetQuality ()
 
void makeHistograms (std::vector< TString > filenames, TString outfilename)
 
void plotHistograms (TString outfilename)
 

Detailed Description

Definition at line 35 of file WidgetQuality.h.

Constructor & Destructor Documentation

◆ WidgetQuality() [1/2]

WidgetQuality::WidgetQuality ( )

Definition at line 3 of file WidgetQuality.cc.

3 {
4 m_type = 0;
5 m_mass[0] = Widget::mpion;
6 m_mass[1] = Widget::mkaon;
7 m_mass[2] = Widget::mproton;
8 m_mass[3] = Widget::mmuon;
9 m_mass[4] = Widget::melectron;
10 for( int i = 0; i < 5; ++i ){
11 m_upperp[i] = 3.0;
12 m_lowerp[i] = 0.0;
13 }
14}

◆ WidgetQuality() [2/2]

WidgetQuality::WidgetQuality ( int  type,
double *  bgmax,
double *  bgmin 
)

Definition at line 16 of file WidgetQuality.cc.

16 {
17 m_type = type;
18 m_mass[0] = Widget::mpion;
19 m_mass[1] = Widget::mkaon;
20 m_mass[2] = Widget::mproton;
21 m_mass[3] = Widget::mmuon;
22 m_mass[4] = Widget::melectron;
23 for( int i = 0; i < 5; ++i ){
24 m_upperp[i] = bgmax[i]*m_mass[i];
25 m_lowerp[i] = bgmin[i]*m_mass[i];
26 }
27}

◆ ~WidgetQuality()

virtual WidgetQuality::~WidgetQuality ( )
inlinevirtual

Definition at line 41 of file WidgetQuality.h.

41{};

Member Function Documentation

◆ makeHistograms()

void WidgetQuality::makeHistograms ( std::vector< TString >  filenames,
TString  outfilename 
)

Definition at line 30 of file WidgetQuality.cc.

30 {
31
32 std::cout << "Making histograms..." << std::endl;
33
34 // check if the output file exists, do not overwrite it by default
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 // create the output file
48 TFile* outfile = new TFile(outfilename,"RECREATE");
49
50 std::cout << "Making histograms..." << std::endl;
51
52 // for each file, create and save the various quality histograms
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 // cuts += TString::Format("&&numGoodLayerHits>=0&&numGoodLayerHits<=100");
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 // make a histogram of momentum
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 // make a histogram of cos(theta)
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 // make a histogram of dE/dx vs. momentum
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 // make a histogram of momentum vs. cos(theta)
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 // make a histogram of nhit vs. pt
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 // intree->Project("nhit_pt(100,0,2.0,40,0,40)","numGoodLayerHits:abs(pF)*sqrt(1-costh*costh)",cuts);
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 // save it to the output file
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}

Referenced by HadronInterface::QualityCheck().

◆ plotHistograms()

void WidgetQuality::plotHistograms ( TString  outfilename)

Definition at line 138 of file WidgetQuality.cc.

138 {
139
140 std::cout << "Plotting histograms..." << std::endl;
141
142 TFile* f = new TFile(filename);
143
144 // five different histograms are plotted for each particle type
145 TString varname[5];
146 varname[0] = "_hp";
147 varname[1] = "_hcosth";
148 varname[2] = "_dedx_p";
149 varname[3] = "_p_costh";
150 varname[4] = "_nhit_pt";
151
152 TCanvas* can = new TCanvas("can","Quality plots",800,800);
153 for( int i = 0; i < 5; ++i ){
154
155 TString name;
156 if( i == 0 ) name = "pion";
157 else if( i == 1 ) name = "kaon";
158 else if( i == 2 ) name = "proton";
159 else if( i == 3 ) name = "muon";
160 else if( i == 4 ) name = "electron";
161
162 // plot 5 histograms for each particle type
163 for( int j = 0; j < 5; ++j ){
164 TString histname = name+varname[j];
165 TH1F* h1 = (TH1F*)f->Get(histname);
166 if(j<2) h1->DrawCopy("e");
167 else h1->DrawCopy("colz");
168 if( j == 2 ){
169 // draw lines that define the momentum range
170 double max = 3.0; if( i == 1 || i == 2 ) max = 10.0;
171 TLine* upper = new TLine(m_upperp[i],0,m_upperp[i],max);
172 TLine* lower = new TLine(m_lowerp[i],0,m_lowerp[i],max);
173 upper->SetLineColor(kRed); upper->SetLineStyle(kDashed);
174 lower->SetLineColor(kRed); lower->SetLineStyle(kDashed);
175 upper->DrawClone("same");
176 lower->DrawClone("same");
177 delete upper;
178 delete lower;
179 }
180 can->SaveAs("plots/"+histname+".eps");
181 }
182 }
183
184 f->Close();
185 delete can;
186}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

Referenced by HadronInterface::QualityCheck().


The documentation for this class was generated from the following files: