source: branches/Mars_McMismatchStudy/MMCComp/MMCComp.cpp@ 19084

Last change on this file since 19084 was 18091, checked in by ghughes, 10 years ago
sharedlib MC quickfix
File size: 7.4 KB
Line 
1#include "MMCComp.h"
2
3
4MMCComp::MMCComp()
5{
6}
7
8void MMCComp::Print() const
9{
10
11/*
12 for( int i = 0 ; i < cDATA->GetEntries() ; i++ )
13 {
14 cDATA->GetEntry(i);
15 cout << i << " ";
16 cout << time->GetTime() << " ";
17 cout << time->GetMjd() << " ";
18 cout << endl;
19 }
20*/
21
22}
23
24
25void MMCComp::loadData( string sDataDir )
26{
27
28 string sDataFiles = sDataDir + "2*summary.root";
29 cDATA = new TChain("Events");
30
31 cDATA->Add( sDataFiles.c_str() );
32 cout << "Adding " << sDataFiles.c_str() << endl;
33 cout << "Number of Data Events = " << cDATA->GetEntries() << endl;
34
35 timeDATA = new MTime();
36 hillasDATA = new MHillas();
37 imageparDATA = new MImagePar();
38 newimageparDATA = new MNewImagePar();;
39
40 cDATA->SetBranchStatus("MTime.*",1);
41 cDATA->SetBranchAddress("MTime.",&timeDATA);
42
43 cDATA->SetBranchStatus("MHillas.*",1);
44 cDATA->SetBranchAddress("MHillas.",&hillasDATA);
45
46 cDATA->SetBranchStatus("MImagePar.*",1);
47 cDATA->SetBranchAddress("MImagePar.",&imageparDATA);
48
49 cDATA->SetBranchStatus("MNewImagePar.*",1);
50 cDATA->SetBranchAddress("MNewImagePar.",&newimageparDATA);
51
52}
53
54void MMCComp::loadMC( string sMCDir )
55{
56
57 string sMCFiles = sMCDir + "/gan*analysis.root";
58 cMC = new TChain("Events");
59
60 cMC->Add( sMCFiles.c_str() );
61 cout << "Adding " << sMCFiles.c_str() << endl;
62 cout << "Number of MC Events = " << cMC->GetEntries() << endl;
63
64 //mcEvent = new MMcEvtBasic();
65 hillasMC = new MHillas();
66 imageparMC = new MImagePar();
67 newimageparMC = new MNewImagePar();;
68
69 //cMC->SetBranchStatus("MMcEvtBasic.*",1);
70 //cMC->SetBranchAddress("MMcEvtBasic.",&mcEvent);
71
72 cMC->SetBranchStatus("MHillas.*",1);
73 cMC->SetBranchAddress("MHillas.",&hillasMC);
74
75 cMC->SetBranchStatus("MImagePar.*",1);
76 cMC->SetBranchAddress("MImagePar.",&imageparMC);
77
78 cMC->SetBranchStatus("MNewImagePar.*",1);
79 cMC->SetBranchAddress("MNewImagePar.",&newimageparMC);
80
81
82}
83
84void MMCComp::compareSize( int N_Size, double MIN_Size, double MAX_Size )
85{
86
87 double min,max;
88
89 min = 9999999.0;
90 max = -9999999.0;
91
92 TH1F *hSizeDATA = new TH1F("hSizeDATA","",N_Size,MIN_Size,MAX_Size);
93 TH1F *hSizeMC = new TH1F("hSizeMC","",N_Size,MIN_Size,MAX_Size);
94 TH1F *hSizeRATIO = new TH1F("hSizeRATIO","",N_Size,MIN_Size,MAX_Size);
95
96 for( int i = 0 ; i < cDATA->GetEntries() ; i++ )
97 {
98 cDATA->GetEntry(i);
99 hSizeDATA->Fill( log10(hillasDATA->GetSize()) );
100 if( log10(hillasDATA->GetSize()) < min ) min = log10(hillasDATA->GetSize());
101 if( log10(hillasDATA->GetSize()) > max ) max = log10(hillasDATA->GetSize());
102 }
103
104 for( int i = 0 ; i < cMC->GetEntries() ; i++ )
105 {
106 cMC->GetEntry(i);
107 hSizeMC->Fill( log10(hillasMC->GetSize()) );
108 }
109
110 hSizeMC->Scale( hSizeDATA->GetEntries()/hSizeMC->GetEntries() );
111
112 for( int i = 0 ; i < hSizeDATA->GetNbinsX() ; i++ )
113 if( hSizeMC->GetBinContent(i) > 0. && hSizeDATA->GetBinContent(i) > 0. )
114 {
115 hSizeRATIO->Fill((double)hSizeDATA->GetBinCenter(i),hSizeDATA->GetBinContent(i)/hSizeMC->GetBinContent(i));
116 hSizeRATIO->SetBinError((double)hSizeDATA->GetBinCenter(i),1./( 1./hSizeDATA->GetBinContent(i) + 1./hSizeMC->GetBinContent(i)) );
117 }
118
119 hSizeRATIO->SetMaximum(2.);
120 hSizeRATIO->SetMinimum(0.);
121 hSizeRATIO->SetMarkerStyle(7);
122
123 hSizeDATA->SetMarkerStyle(7);
124 hSizeDATA->SetMarkerColor(1);
125
126 hSizeMC->SetLineColor(2);
127
128 TCanvas *canSize = new TCanvas("canSize","canSize",0,0,500,500);
129 canSize->Divide(1,2);
130 canSize->cd(1);
131 canSize->cd(1)->SetLogy();
132
133 hSizeDATA->Draw("e");
134 hSizeMC->Draw("same");
135
136 canSize->cd(2);
137 hSizeRATIO->Draw("e");
138 hSizeRATIO->Fit("pol1","","same");
139
140 cout << "Data Size min = " << min << " max = " << max << endl;
141
142}
143
144void MMCComp::compareLength( int N_Length, double MIN_Length, double MAX_Length )
145{
146
147 double min,max;
148
149 min = 9999999.0;
150 max = -9999999.0;
151
152 TH1F *hLengthDATA = new TH1F("hLengthDATA","",N_Length,MIN_Length,MAX_Length);
153 TH1F *hLengthMC = new TH1F("hLengthMC","",N_Length,MIN_Length,MAX_Length);
154 TH1F *hLengthRATIO = new TH1F("hLengthRATIO","",N_Length,MIN_Length,MAX_Length);
155
156 for( int i = 0 ; i < cDATA->GetEntries() ; i++ )
157 {
158 cDATA->GetEntry(i);
159 hLengthDATA->Fill( log10(hillasDATA->GetLength()) );
160 if( log10(hillasDATA->GetLength()) < min ) min = log10(hillasDATA->GetLength());
161 if( log10(hillasDATA->GetLength()) > max ) max = log10(hillasDATA->GetLength());
162 }
163
164 for( int i = 0 ; i < cMC->GetEntries() ; i++ )
165 {
166 cMC->GetEntry(i);
167 hLengthMC->Fill( log10(hillasMC->GetLength()) );
168 }
169
170 hLengthMC->Scale( hLengthDATA->GetEntries()/hLengthMC->GetEntries() );
171
172 for( int i = 0 ; i < hLengthDATA->GetNbinsX() ; i++ )
173 if( hLengthMC->GetBinContent(i) > 0. && hLengthDATA->GetBinContent(i) > 0. )
174 {
175 hLengthRATIO->Fill((double)hLengthDATA->GetBinCenter(i),hLengthDATA->GetBinContent(i)/hLengthMC->GetBinContent(i));
176 hLengthRATIO->SetBinError((double)hLengthDATA->GetBinCenter(i),1./( 1./hLengthDATA->GetBinContent(i) + 1./hLengthMC->GetBinContent(i)) );
177 }
178
179 hLengthRATIO->SetMaximum(2.);
180 hLengthRATIO->SetMinimum(0.);
181 hLengthRATIO->SetMarkerStyle(7);
182
183 hLengthDATA->SetMarkerStyle(7);
184 hLengthDATA->SetMarkerColor(1);
185
186 hLengthMC->SetLineColor(2);
187
188 TCanvas *canLength = new TCanvas("canLength","canLength",0,0,500,500);
189 canLength->Divide(1,2);
190 canLength->cd(1);
191 canLength->cd(1)->SetLogy();
192
193 hLengthDATA->Draw("e");
194 hLengthMC->Draw("same");
195
196 canLength->cd(2);
197 hLengthRATIO->Draw("e");
198 hLengthRATIO->Fit("pol1","","same");
199
200 cout << "Data Length min = " << min << " max = " << max << endl;
201
202}
203
204void MMCComp::compareWidth( int N_Width, double MIN_Width, double MAX_Width )
205{
206
207 double min,max;
208
209 min = 9999999.0;
210 max = -9999999.0;
211
212 TH1F *hWidthDATA = new TH1F("hWidthDATA","",N_Width,MIN_Width,MAX_Width);
213 TH1F *hWidthMC = new TH1F("hWidthMC","",N_Width,MIN_Width,MAX_Width);
214 TH1F *hWidthRATIO = new TH1F("hWidthRATIO","",N_Width,MIN_Width,MAX_Width);
215
216 for( int i = 0 ; i < cDATA->GetEntries() ; i++ )
217 {
218 cDATA->GetEntry(i);
219 hWidthDATA->Fill( log10(hillasDATA->GetWidth()) );
220 if( log10(hillasDATA->GetWidth()) < min ) min = log10(hillasDATA->GetWidth());
221 if( log10(hillasDATA->GetWidth()) > max ) max = log10(hillasDATA->GetWidth());
222 }
223
224 for( int i = 0 ; i < cMC->GetEntries() ; i++ )
225 {
226 cMC->GetEntry(i);
227 hWidthMC->Fill( log10(hillasMC->GetWidth()) );
228 }
229
230 hWidthMC->Scale( hWidthDATA->GetEntries()/hWidthMC->GetEntries() );
231
232 for( int i = 0 ; i < hWidthDATA->GetNbinsX() ; i++ )
233 if( hWidthMC->GetBinContent(i) > 0. && hWidthDATA->GetBinContent(i) > 0. )
234 {
235 hWidthRATIO->Fill((double)hWidthDATA->GetBinCenter(i),hWidthDATA->GetBinContent(i)/hWidthMC->GetBinContent(i));
236 hWidthRATIO->SetBinError((double)hWidthDATA->GetBinCenter(i),1./( 1./hWidthDATA->GetBinContent(i) + 1./hWidthMC->GetBinContent(i)) );
237 }
238
239 hWidthRATIO->SetMaximum(2.);
240 hWidthRATIO->SetMinimum(0.);
241 hWidthRATIO->SetMarkerStyle(7);
242
243 hWidthDATA->SetMarkerStyle(7);
244 hWidthDATA->SetMarkerColor(1);
245
246 hWidthMC->SetLineColor(2);
247
248 TCanvas *canWidth = new TCanvas("canWidth","canWidth",0,0,500,500);
249 canWidth->Divide(1,2);
250 canWidth->cd(1);
251 canWidth->cd(1)->SetLogy();
252
253 hWidthDATA->Draw("e");
254 hWidthMC->Draw("same");
255
256 canWidth->cd(2);
257 hWidthRATIO->Draw("e");
258 hWidthRATIO->Fit("pol1","","same");
259
260 cout << "Data Width min = " << min << " max = " << max << endl;
261
262}
263
Note: See TracBrowser for help on using the repository browser.