22 #include <TLorentzVector.h>
24 #include <TDatabasePDG.h>
36 const Double_t
C = 29.9792458;
117 _savefname(
"mbdstudy.root" ),
131 _tree =
new TTree(
"t",
"MBD Study");
132 _tree->Branch(
"evt",&
f_evt,
"evt/I");
133 _tree->Branch(
"bimp",&
f_bimp,
"bimp/F");
134 _tree->Branch(
"ncoll",&
f_ncoll,
"ncoll/I");
135 _tree->Branch(
"npart",&
f_npart,
"npart/I");
136 _tree->Branch(
"vx",&
f_vx,
"vx/F");
137 _tree->Branch(
"vy",&
f_vy,
"vy/F");
138 _tree->Branch(
"vz",&
f_vz,
"vz/F");
139 _tree->Branch(
"bns",&
f_mbdn[0],
"bns/S");
140 _tree->Branch(
"bnn",&
f_mbdn[1],
"bnn/S");
141 _tree->Branch(
"bqs",&
f_mbdq[0],
"bqs/F");
142 _tree->Branch(
"bqn",&
f_mbdq[1],
"bqn/F");
143 _tree->Branch(
"bts",&
f_mbdt[0],
"bts/F");
144 _tree->Branch(
"btn",&
f_mbdt[1],
"btn/F");
145 _tree->Branch(
"btes",&
f_mbdte[0],
"btes/F");
146 _tree->Branch(
"bten",&
f_mbdte[1],
"bten/F");
147 _tree->Branch(
"bz",&
f_mbdz,
"bz/F");
148 _tree->Branch(
"bt0",&
f_mbdt0,
"bt0/F");
150 _pdg = TDatabasePDG::Instance();
151 _rndm =
new TRandom3(0);
154 for (
int ipmt=0; ipmt<128; ipmt++)
156 name =
"h_mbdq"; name += ipmt;
157 title =
"mbd charge, ch "; title += ipmt;
158 h_mbdq[ipmt] =
new TH1F(name,title,1200,0,120*90);
167 for (
int iarm=0; iarm<2; iarm++)
169 name =
"h_mbdqtot"; name += iarm;
170 title =
"mbd charge, arm "; title += iarm;
171 h_mbdqtot[iarm] =
new TH1F(name,title,1200,0,120*60);
174 name =
"hevt_mbdt"; name += iarm;
175 title =
"mbd times, arm "; title += iarm;
176 hevt_mbdt[iarm] =
new TH1F(name,title,200,7.5,11.5);
179 h2_mbdqtot =
new TH2F(
"h2_mbdqtot",
"north MBDQ vs South MBDQ",300,0,120*900,300,0,120*900);
181 h_ztrue =
new TH1F(
"h_ztrue",
"true z-vtx",600,-30,30);
182 h_tdiff =
new TH1F(
"h_tdiff",
"dt (measured - true_time)",6000,-3,3);
183 h2_tdiff_ch =
new TH2F(
"h2_tdiff_ch",
"dt (measured - true time) vs ch",128,-0.5,127.5,200,-2,2);
185 gaussian =
new TF1(
"gaussian",
"gaus",0,20);
188 c_mbdt =
new TCanvas(
"c_mbdt",
"MBD Times",1200,800);
270 cout <<
"VTXP " <<
"\t" <<
f_vx <<
"\t" <<
f_vy <<
"\t" <<
f_vz <<
"\t" <<
f_vt << endl;
280 unsigned int nvtx = 0;
309 float len[128] = {0.};
310 float edep[128] = {0.};
311 float first_time[128];
312 std::fill_n(first_time, 128, 1e12);
315 unsigned int nhits = 0;
321 for (
auto hit_iter = mbd_hit_range.first; hit_iter != mbd_hit_range.second; hit_iter++)
323 PHG4Hit *this_hit = hit_iter->second;
329 if ( trkid>0 &&
f_evt<20 ) cout <<
"TRKID " << trkid << endl;
335 TParticlePDG *partinfo =
_pdg->GetParticle( pid );
339 charge = partinfo->Charge()/3;
341 else if ( part->
isIon() )
346 Double_t beta = v4.Beta();
359 float tube_x = xsign*
TubeLoc[ch%64][0];
360 float tube_y = TubeLoc[ch%64][1];
361 float tube_z = zsign*253.;
362 float flight_z = fabs(tube_z - vtxp->
get_z());
364 float flight_time = sqrt( tube_x*tube_x + tube_y*tube_y + flight_z*flight_z )/
C;
365 float tdiff = this_hit->
get_t(1) - ( vtxp->
get_t() + flight_time );
368 if ( this_hit->
get_t(1) < first_time[ch] )
370 if ( fabs( this_hit->
get_t(1) ) < 106.5 )
372 first_time[ch] = this_hit->
get_t(1) - vtxp->
get_t();
373 Float_t dt =
static_cast<float>(
_rndm->Gaus( 0,
_tres ) );
374 first_time[ch] += dt;
378 cout <<
"BAD " << ch <<
"\t" << this_hit->
get_t(1) << endl;
384 cout <<
"hit " << ch <<
"\t" << trkid <<
"\t" << pid
392 <<
"\t" << this_hit->
get_x(1)
393 <<
"\t" << this_hit->
get_y(1)
394 <<
"\t" << this_hit->
get_z(1)
395 <<
"\t" << this_hit->
get_t(1)
406 if ( beta >
v_ckov && charge != 0. )
422 cout <<
"ERROR " << endl;
430 cout <<
"******** " <<
f_evt <<
" **************" << endl;
435 for (
int iarm=0; iarm<2; iarm++)
440 vector<float> hit_times[2];
442 for (
int ich=0; ich<128; ich++)
453 cout <<
"ich " << ich <<
"\t" << len[ich] <<
"\t" << edep[ich] << endl;
457 float npe = len[ich]*(120/3.0);
458 float dnpe =
static_cast<float>(
_rndm->Gaus( 0, sqrt(npe) ) );
468 if ( first_time[ich] < 9999. )
472 hit_times[arm].push_back( first_time[ich] );
474 f_mbdt[arm] += first_time[ich];
480 cout <<
"ERROR, have hit but no time" << endl;
491 for (
int iarm=0; iarm<2; iarm++)
496 float earliest = hit_times[iarm][0];
499 gaussian->SetParameter(1, earliest);
500 gaussian->SetRange(6, earliest+ 5*0.05);
527 cout <<
"Event " <<
f_evt <<
" ? ";
530 TString
name =
"evt_"; name +=
f_evt; name +=
".png";
549 _truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
553 _mbdhits = findNode::getClass<PHG4HitContainer> (topNode,
"G4HIT_MBD");
556 _evtheader = findNode::getClass<EventHeaderv1>(topNode,
"EventHeader");
569 cout <<
"PIDs of Particles that hit MBD" << endl;
570 unsigned int ipid = 0;
576 for (
auto &
pid : _pids)
578 cout <<
pid.first <<
"\t" <<
pid.second <<
"\t" <<
pid.second/npart << endl;
581 cout <<
"There were " << ipid <<
" different particle types" << endl;
589 MbdOut *_mbdout = findNode::getClass<MbdOut>(topNode,
"MbdOut");
590 if(!_mbdout &&
f_evt<10) cout <<
PHWHERE <<
" MbdOut node not found on node tree" << endl;
595 cout <<
"ERROR, f_mbdz != mbdz, " <<
f_mbdz <<
"\t" << mbdz << endl;
598 for (
int iarm=0; iarm<2; iarm++)
602 cout <<
"ERROR, f_mbdq != mbdq, arm " << iarm <<
"\t" <<
f_mbdq[iarm] <<
"\t" << _mbdout->
get_q(iarm) << endl;