-
Notifications
You must be signed in to change notification settings - Fork 1
/
BiasPlots.C
268 lines (214 loc) · 11.1 KB
/
BiasPlots.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// Anthony Hillairet, April 2008
///
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Includes here
class BiasPlots : public ModuleClass{
public :
BiasPlots() {};
BiasPlots(string N, string T) {Name = N; Title = T;};
~BiasPlots() {};
bool Init(EventClass &E, HistogramFactory &H, ConfigFile &Conf, log4cpp::Category *TmpLog) ;
bool Process(EventClass &E, HistogramFactory &H);
private :
log4cpp::Category *Log;
string Name;
string Title;
int Nptotbins;
double minptot, maxptot, dptot;
int Trk;
float p, costh, t, invcosth;
float pdiff, cosdiff, wtdiff, dtdiff, thetadiff;
float pdiff_l, cosdiff_l, ptot_l, p_l, costh_l;
double binlow, binhigh;
string binlbl;
};
bool BiasPlots::Init(EventClass &E, HistogramFactory &H, ConfigFile &Conf, log4cpp::Category *TmpLog)
{
// -------- Name of the cut --------- //
Log = TmpLog;
if ( (not Conf.read<bool>("BiasPlots/Do")) || not ( E.Exists("nmctr") && E.Exists("nmcvtx") && Conf.read<bool>("TruthBank/Do")))
{
Log->info( "BiasPlots %s turned OFF",Title.c_str());
return false ;
}
Log->info( "Register Bias Plots %s", Title.c_str());
string N = Name;
string T = Title;
// --------- Parameters initialization --------- //
Nptotbins = Conf.read<int>("BiasPlots/Nptotbins");
minptot = Conf.read<double>("BiasPlots/minptot");
maxptot = Conf.read<double>("BiasPlots/maxptot");
dptot = (maxptot - minptot)/Nptotbins;
int Nbinscosth = Conf.read<int>("BiasPlots/Nbinscosth");
double mincosth = Conf.read<double>("BiasPlots/mincosth");
double maxcosth = Conf.read<double>("BiasPlots/maxcosth");
int Nbinsdp = Conf.read<int>("BiasPlots/Nbinsdp");
double mindp = Conf.read<int>("BiasPlots/mindp");
double maxdp = Conf.read<double>("BiasPlots/maxdp");
int Nbinsdcosth = Conf.read<int>("BiasPlots/Nbinsdcosth");
double mindcosth = Conf.read<double>("BiasPlots/mindcosth");
double maxdcosth = Conf.read<double>("BiasPlots/maxdcosth");
// --------- Histograms initialization --------- //
H.DefineTH2D( "BiasPlots","diff_dt_cos_"+N, "Fit - MC t vs. MC cos(theta) "+T, 100,-1.,1.,100,-20.,20.);
H.DefineTH2D( "BiasPlots","diff_wt_cos_"+N, "Win - MC t vs. MC cos(theta) "+T, 100,-1.,1.,100,-20.,20.);
H.DefineTH2D( "BiasPlots","diff_wt_mct_"+N, "Win - MC t vs. MC t "+T, 100,0.,10000.,100,-20.,20.);
H.DefineTH2D( "BiasPlots","diff_dt_mct_"+N, "Fit - MC t vs. MC t "+T, 100,0.,10000.,100,-20.,20.);
H.DefineTH2D( "BiasPlots","diff_p_cos_"+N, "Fit - MC p vs. Fit - MC cos(theta) "+T,200,-2.,2.,220,-55.,55.);
H.DefineTH1D( "BiasPlots","diff_cos_"+N, "Fit - MC cos(theta) "+T, 2000,-2.,2.);
H.DefineTH2D( "BiasPlots","diff_p_2d_"+N, "Fit - MC p vs. p "+T, 110,0.,55.,220,-55.,55.);
H.DefineTH2D( "BiasPlots","diff_p_2d2_"+N, "Fit - MC p vs. cos(theta) "+T, 100,-1.,1.,220,-55.,55.);
H.DefineTH2D( "BiasPlots","diff_cos_2d_"+N, "Fit - MC cos(theta) vs. cos(theta) "+T,100,-1.,1.,200,-2.,2.);
H.DefineTH2D( "BiasPlots","diff_cos_2d2_"+N,"Fit - MC cos(theta) vs. p "+T, 110,0.,55.,220,-2.,2.);
H.DefineTH1D( "BiasPlots","ndof_all_"+N, "Degrees of freedom "+T, 101,-0.5,100.5);
H.DefineTH1D( "BiasPlots","chi2_all_"+N, "chi square per degrees of freedom "+T, 100,0.,100.);
char Temp[200];
for(int istep=-20; istep<20; istep++)
{
binlow = istep/20.;
binhigh = binlow + 0.05;
if((-0.975 < binlow && binlow < -0.425) || (0.375 < binlow && binlow < 0.925))
{
// bin is in region to plot, 0.40 < abs(cos(theta)) < 0.95
binlbl = IntToStr(int(fabs(binlow)*100.+0.5));
if(binlow < 0.0)
binlbl = "neg" + binlbl;
sprintf(Temp,"ndof vs p for %f < cos(#theta) < %f %s;p [MeV];ndof", binlow,binhigh, T.c_str());
H.DefineTH2D( "BiasPlots", "ndof_p_"+binlbl+"_"+N, Temp, 22,0.,55.,101,-0.5,100.5);
sprintf(Temp,"chi2 per dof vs p for %f < cos(#theta) < %f %s;p [MeV];reduced #chi^{2}", binlow,binhigh, T.c_str());
H.DefineTH2D( "BiasPlots", "chi2_dof_p_"+binlbl+"_"+N, Temp, 22,0.,55.,200,0.,20.);
sprintf(Temp,"Fit - MC cos(#theta) vs. p for %f < cos(#theta) < %f %s;p [MeV];#Delta cos(#theta)", binlow,binhigh, T.c_str());
H.DefineTH2D( "BiasPlots", "dcos_p_"+binlbl+"_"+N, Temp, 22,0.,55.,2000,-0.2,0.2);
sprintf(Temp,"Fit - MC p vs. p for %f < cos(#theta) < %f %s;p [MeV];#Delta p [MeV]", binlow,binhigh, T.c_str());
H.DefineTH2D( "BiasPlots", "dp_p_"+binlbl+"_"+N, Temp, 22,0.,55.,2200,-55.,55.);
}
}
for(int i = 0; i < Nptotbins; i++)
{
binlow = minptot + i*dptot;
binhigh= minptot + (i + 1)*dptot;
binlbl = IntToStr(int(binlow));
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta p_{tot} (p^{US}_{rec} - p^{US}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dptot_invc_us_" +binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdp, mindp, maxdp);
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta cos#theta (cos#theta^{US}_{rec} - cos#theta^{US}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dcosth_invc_us_"+binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdcosth, mindcosth, maxdcosth);
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta #theta (#theta^{US}_{rec} - #theta^{US}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dtheta_invc_us_"+binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdcosth, mindcosth, maxdcosth);
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta p_{tot} (p^{DS}_{rec} - p^{DS}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dptot_invc_ds_" +binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdp, mindp, maxdp);
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta cos#theta (cos#theta^{DS}_{rec} - cos#theta^{DS}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dcosth_invc_ds_"+binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdcosth, mindcosth, maxdcosth);
sprintf( Temp, "%f < p_{tot} < %f; 1/cos#theta; #Delta #theta (#theta^{DS}_{rec} - #theta^{DS}_{MCTB})", binlow, binhigh);
H.DefineTH2D( "BiasPlots", "dtheta_invc_ds_"+binlbl+"_"+N, Temp, Nbinscosth, 1./maxcosth, 1./mincosth, Nbinsdcosth, mindcosth, maxdcosth);
}
if ( E.Exists("hefit_lastu") && E.Exists("hefit_lastpu") )
{
H.DefineTH2D( "BiasPlots", "dptot_firstvslast_"+N, "#Delta p (Fit - MC) at the last hit vs at the first hit;#Delta p at the first hit;#Delta p at the last hit", 1100,-55.,55.,1100,-55.,55.);
H.DefineTH2D( "BiasPlots", "dcosth_firstvslast_"+N, "#Delta cos#theta (Fit - MC) at the last hit vs at the first hit;#Delta cos#theta at the first hit;#Delta cos#theta at the last hit", 1000,-0.2,0.2,1000,-0.2,0.2);
H.DefineTH2D( "BiasPlots", "dptot_firstvslast_US_MatchZ_"+N, "#Delta p (Fit - MC) at the last hit vs at the first hit "+T+", Upstream;#Delta p at the first hit;#Delta p at the last hit", 1100,-55.,55.,1100,-55.,55.);
H.DefineTH2D( "BiasPlots", "dcosth_firstvslast_US_MatchZ_"+N, "#Delta cos#theta (Fit - MC) at the last hit vs at the first hit "+T+", Upstream;#Delta cos#theta at the first hit;#Delta cos#theta at the last hit", 1000,-0.2,0.2,1000,-0.2,0.2);
H.DefineTH2D( "BiasPlots", "dptot_firstvslast_DS_MatchZ_"+N, "#Delta p (Fit - MC) at the last hit vs at the first hit "+T+", Downstream;#Delta p at the first hit;#Delta p at the last hit", 1100,-55.,55.,1100,-55.,55.);
H.DefineTH2D( "BiasPlots", "dcosth_firstvslast_DS_MatchZ_"+N, "#Delta cos#theta (Fit - MC) at the last hit vs at the first hit "+T+", Downstream;#Delta cos#theta at the first hit;#Delta cos#theta at the last hit", 1000,-0.2,0.2,1000,-0.2,0.2);
}
return true;
}
bool BiasPlots::Process(EventClass &E, HistogramFactory &H)
{
// ____ ____ //
// There is no vertex bank !
if ( ! (E.Exists("nmctr") && E.Exists("nmcvtx") ) )
return true;
// If no decay positron, nothing to do.
if ( E.tb_e_trki < 0)
return true;
// The selected track
Trk = E.seltrack[0];
p = E.mcvertex_ptot[E.tb_e_firstdcvtx];
costh = E.mcvertex_costh[E.tb_e_firstdcvtx];
invcosth= 1./costh;
t = E.mcvertex_time[E.tb_e_firstdcvtx];
pdiff = E.ptot[Trk] - p;
cosdiff = E.costh[Trk] - costh;
thetadiff = acos(E.costh[Trk]) - acos(costh);
wtdiff = E.win_time[E.iewin] - t;
dtdiff = E.hefit_time[Trk] - t;
if(20.0 < p && p < 50.0)
{
H.Fill("diff_cos_" +Name, cosdiff );
H.Fill("diff_cos_2d_" +Name, costh, cosdiff );
H.Fill("diff_dt_cos_" +Name, costh, dtdiff );
H.Fill("diff_wt_cos_" +Name, costh, wtdiff );
H.Fill("diff_wt_mct_" +Name, t, wtdiff );
H.Fill("diff_dt_mct_" +Name, t, dtdiff );
}
if(0.54 < fabs(costh) && fabs(costh) < 0.80)
H.Fill("diff_p_2d_" +Name, p, pdiff );
H.Fill("diff_p_cos_"+Name, cosdiff, pdiff );
H.Fill("diff_p_2d2_"+Name, costh,pdiff );
H.Fill("diff_cos_2d2_"+Name, p, cosdiff );
H.Fill("ndof_all_"+Name, E.hefit_ndof[Trk] );
H.Fill("chi2_all_"+Name, E.hefit_chi2[Trk] );
for(int istep=-20; istep<20; istep++)
{
binlow = istep/20.;
if((-0.975 < binlow && binlow < -0.425) || (0.375 < binlow && binlow < 0.925) &&
(binlow < costh && costh < binlow + 0.05) )
{
// bin is in region to plot, 0.40 < abs(cos(theta)) < 0.95
binlbl = IntToStr(int(fabs(binlow)*100.+0.5));
if(binlow < 0.0)
binlbl = "neg" + binlbl;
H.Fill( "ndof_p_" +binlbl+"_"+Name, E.ptot[Trk], E.hefit_ndof[Trk]);
H.Fill( "chi2_dof_p_" +binlbl+"_"+Name, E.ptot[Trk], E.hefit_chi2[Trk]/E.hefit_ndof[Trk] );
H.Fill( "dcos_p_" +binlbl+"_"+Name, p, cosdiff);
H.Fill( "dp_p_" +binlbl+"_"+Name, p, pdiff);
}
}
for(int i = 0; i < Nptotbins; i++)
{
binlow = minptot + i*dptot;
binhigh= minptot + (i + 1)*dptot;
binlbl = IntToStr(int(binlow));
if( p > binlow && p <= binhigh)
{
if ( E.is_upstreamdk )
{
H.Fill( "dptot_invc_us_" +binlbl+"_"+Name, invcosth, pdiff);
H.Fill( "dcosth_invc_us_" +binlbl+"_"+Name, invcosth, cosdiff);
H.Fill( "dtheta_invc_us_" +binlbl+"_"+Name, invcosth, thetadiff);
}
else
{
H.Fill( "dptot_invc_ds_" +binlbl+"_"+Name, invcosth, pdiff);
H.Fill( "dcosth_invc_ds_" +binlbl+"_"+Name, invcosth, cosdiff);
H.Fill( "dtheta_invc_ds_" +binlbl+"_"+Name, invcosth, thetadiff);
}
}
}
if ( E.Exists("hefit_lastu") && E.Exists("hefit_lastpu") )
{
p_l = E.mcvertex_ptot[E.tb_e_lastdcvtx];
costh_l = E.mcvertex_costh[E.tb_e_lastdcvtx];
ptot_l = sqrt( (E.hefit_lastpu[Trk]*E.hefit_lastpu[Trk])+(E.hefit_lastpv[Trk]*E.hefit_lastpv[Trk]) +(E.hefit_lastpz[Trk]*E.hefit_lastpz[Trk]) );
pdiff_l = ptot_l - p_l;
cosdiff_l = (E.hefit_lastpz[Trk] / ptot_l) - costh_l;
H.Fill( "dptot_firstvslast_"+Name, pdiff, pdiff_l);
H.Fill( "dcosth_firstvslast_"+Name, cosdiff, cosdiff_l);
if ( fabs(E.mcvertex_vz[E.tb_e_firstdcvtx] - E.hefit_z[Trk]) < 0.8 &&
fabs(E.mcvertex_vz[E.tb_e_lastdcvtx] - E.hefit_lastz[Trk]) < 0.8 )
{
if ( E.is_upstreamdk )
{
H.Fill( "dptot_firstvslast_US_MatchZ_"+Name, pdiff, pdiff_l);
H.Fill( "dcosth_firstvslast_US_MatchZ_"+Name, cosdiff, cosdiff_l);
}
else
{
H.Fill( "dptot_firstvslast_DS_MatchZ_"+Name, pdiff, pdiff_l);
H.Fill( "dcosth_firstvslast_DS_MatchZ_"+Name, cosdiff, cosdiff_l);
}
}
}
return true;
}