13 #include <JANA/JApplication.h>
14 #include <JANA/JEventLoop.h>
17 extern JApplication *
japp;
42 pthread_mutex_init(&mutex, NULL);
61 TDirectory *
dir =
new TDirectoryFile(
"RADLEN",
"RADLEN");
65 dE_vs_r =
new TH2F(
"dE_vs_r",
"dE (keV) vs r", 300, 0.0, 65.0,1000, 0.0, 1000.0);
66 dE_vs_z =
new TH2F(
"dE_vs_z",
"dE (keV) vs z", 650, 0.0, 650.0, 1000, 0.0, 1000.0);
68 int Ntheta_bins = 480;
69 double theta_min = 0.0;
70 double theta_max = 120.0;
71 theta_nevents =
new TH1F(
"theta_nevents",
"Number of events per #theta bin in int_radlen_vs_z_vs_theta", Ntheta_bins, theta_min, theta_max);
72 nXo_vs_z_vs_theta =
new TH2F(
"nXo_vs_z_vs_theta",
"Radiation lengths vs. z and #theta", 650, 0.0, 650.0, Ntheta_bins, theta_min, theta_max);
73 nXo_vs_z_vs_theta->SetXTitle(
"z-position along beamline (cm)");
74 nXo_vs_z_vs_theta->SetYTitle(
"Thrown #theta angle (deg)");
75 inXo_vs_z_vs_theta =
new TH2F(
"inXo_vs_z_vs_theta",
"Integrated radiation lengths vs. z and #theta", 650, 0.0, 650.0, Ntheta_bins, theta_min, theta_max);
76 inXo_vs_z_vs_theta->SetXTitle(
"z-position along beamline (cm)");
77 inXo_vs_z_vs_theta->SetYTitle(
"Thrown #theta angle (deg)");
79 nXo_vs_r_vs_theta =
new TH2F(
"nXo_vs_r_vs_theta",
"Radiation lengths vs. r and #theta", 180, 0.0, 90.0, Ntheta_bins, theta_min, theta_max);
80 nXo_vs_r_vs_theta->SetXTitle(
"Radial distance from beamline (cm)");
81 nXo_vs_r_vs_theta->SetYTitle(
"Thrown #theta angle (deg)");
82 inXo_vs_r_vs_theta =
new TH2F(
"inXo_vs_r_vs_theta",
"Integrated radiation lengths vs. r and #theta", 180, 0.0, 90.0, Ntheta_bins, theta_min, theta_max);
83 inXo_vs_r_vs_theta->SetXTitle(
"Radial distance from beamline (cm)");
84 inXo_vs_r_vs_theta->SetYTitle(
"Thrown #theta angle (deg)");
86 nXo_vs_z =
new TH1F(
"nXo_vs_z",
"Radiation lengths vs. z", 650, 0.0, 650.0);
87 inXo_vs_z =
new TH1F(
"inXo_vs_z",
"Integrated radiation lengths vs. z", 650, 0.0, 650.0);
88 nXo_vs_r =
new TH1F(
"nXo_vs_r",
"Radiation lengths vs. r", 1000, 0.0, 90.0);
89 inXo_vs_r =
new TH1F(
"inXo_vs_r",
"Integrated radiation lengths vs. r", 1000, 0.0, 90.0);
91 nXo_vs_z->SetStats(0);
92 nXo_vs_z->SetFillStyle(3000);
93 nXo_vs_z->SetFillColor(kMagenta);
94 inXo_vs_z->SetStats(0);
95 inXo_vs_z->SetFillStyle(3000);
96 inXo_vs_z->SetFillColor(kMagenta);
97 nXo_vs_r->SetStats(0);
98 nXo_vs_r->SetFillStyle(3000);
99 nXo_vs_r->SetFillColor(kMagenta);
100 inXo_vs_r->SetStats(0);
101 inXo_vs_r->SetFillStyle(3000);
102 inXo_vs_r->SetFillColor(kMagenta);
106 tradstep =
new TTree(
"radstep",
"Radlen steps");
107 tradstep->Branch(
"R",
"radstep",&rstep_ptr);
133 vector<const DMCTrajectoryPoint*> trajpoints;
134 vector<const DMCThrown*> throwns;
135 loop->Get(trajpoints);
140 if(throwns.size()!=1){
141 _DBG_<<
"Event doesn't have exactly 1 thrown (has"<<throwns.size()<<
"). Skipping..."<<endl;
144 theta = throwns[0]->momentum().Theta()*57.3;
145 theta_nevents->Fill(theta);
148 japp->RootWriteLock();
151 rstep.ix_over_Xo = 0.0;
152 rstep.iB_cross_p_dl = 0.0;
154 DVector3 tmp = throwns[0]->momentum();
155 rstep.pthrown.SetXYZ(tmp.X(), tmp.Y(), tmp.Z());
156 for(
unsigned int i=0;i<trajpoints.size();i++){
159 double dE = traj->
dE*1.0E6;
160 double r =
sqrt(pow((
double)traj->
x,2.0) + pow((
double)traj->
y,2.0));
161 dE_vs_r->Fill( r, dE);
162 dE_vs_z->Fill( traj->
z, dE);
165 nXo_vs_r_vs_theta->Fill(r, theta, dnXo);
166 nXo_vs_z_vs_theta->Fill(traj->
z, theta, dnXo);
167 nXo_vs_r->Fill(r, dnXo);
168 nXo_vs_z->Fill(traj->
z, dnXo);
171 bfield->GetField(traj->
x, traj->
y, traj->
z, Bx, By, Bz);
172 rstep.B.SetXYZ(Bx, By, Bz);
173 TVector3 mom(traj->
px, traj->
py, traj->
pz);
174 TVector3 B_cross_p = rstep.B.Cross(mom);
175 rstep.iB_cross_p_dl += B_cross_p.Mag() * traj->
step/mom.Mag();
176 rstep.iB_dl += rstep.B.Mag()*traj->
step;
178 rstep.pos.SetXYZ(traj->
x, traj->
y, traj->
z);
179 rstep.s = traj->
step;
180 rstep.stot += (double)traj->
step;
182 rstep.ix_over_Xo += dnXo;
186 pthread_mutex_unlock(&mutex);
197 japp->RootFillLock(
this);
203 TH2F *
h = nXo_vs_r_vs_theta;
204 for(
int i=1; i<=h->GetNbinsY(); i++){
205 double N = theta_nevents->GetBinContent(i);
206 double nXo_vs_r_sum=0.0;
207 for(
int j=1; j<=h->GetNbinsX(); j++){
208 double v = nXo_vs_r_vs_theta->GetBinContent(j,i);
209 double nXo = N==0.0 ? 0.0:v/N;
211 nXo_vs_r_vs_theta->SetBinContent(j,i, nXo);
212 inXo_vs_r_vs_theta->SetBinContent(j,i, nXo_vs_r_sum);
216 h = nXo_vs_z_vs_theta;
217 for(
int i=1; i<=h->GetNbinsY(); i++){
218 double N = theta_nevents->GetBinContent(i);
220 for(
int j=1; j<=h->GetNbinsX(); j++){
221 double v = nXo_vs_z_vs_theta->GetBinContent(j,i);
222 double nXo = N==0.0 ? 0.0:v/N;
224 nXo_vs_z_vs_theta->SetBinContent(j,i, nXo);
225 inXo_vs_z_vs_theta->SetBinContent(j,i, nXo_vs_z);
229 double N = theta_nevents->Integral();
230 _DBG_<<
"N="<<N<<endl;
231 nXo_vs_r->Scale(1.0/N);
232 nXo_vs_z->Scale(1.0/N);
233 inXo_vs_r->SetBinContent(1,nXo_vs_r->GetBinContent(1));
234 for(
int j=2; j<=nXo_vs_r->GetNbinsX(); j++){
235 inXo_vs_r->SetBinContent(j, nXo_vs_r->GetBinContent(j)+inXo_vs_r->GetBinContent(j-1));
237 inXo_vs_z->SetBinContent(1,nXo_vs_z->GetBinContent(1));
238 for(
int j=2; j<=nXo_vs_z->GetNbinsX(); j++){
239 inXo_vs_z->SetBinContent(j, nXo_vs_z->GetBinContent(j)+inXo_vs_z->GetBinContent(j-1));
242 japp->RootFillUnLock(
this);
260 int Nbins = hin->GetNbinsX();
261 double min_nXo = 1.0E-7;
263 while(hin->GetBinContent(bin)<min_nXo)
if(++bin>=Nbins)
break;
269 double left = hin->GetBinCenter(bin);
271 while((nXo=hin->GetBinContent(bin))>=min_nXo){
273 right = hin->GetBinCenter(bin);
274 pos += nXo*hin->GetBinCenter(bin);
275 if(++bin>=Nbins)
break;
283 int bin_left = hout->FindBin(left);
284 int bin_right = hout->FindBin(right);
285 for(
int i=bin_left; i<=bin_right; i++)hout->SetBinContent(i, nXotot);
DMagneticFieldMap * GetBfield(unsigned int run_number=1)
jerror_t evnt(JEventLoop *loop, uint64_t eventnumber)
Invoked via DEventProcessor virtual method.
jerror_t erun(void)
Invoked via DEventProcessor virtual method.
void GapIntegration(TH1F *hin, TH1F *hout)
jerror_t brun(JEventLoop *loop, int32_t runnumber)
Invoked via DEventProcessor virtual method.
~DEventProcessor_radlen_hists()
jerror_t fini(void)
Invoked via DEventProcessor virtual method.
DEventProcessor_radlen_hists()
jerror_t init(void)
Invoked via DEventProcessor virtual method.