13 #include <JANA/JApplication.h>
14 #include <JANA/JFactory.h>
52 int NoBins_time = 200;
54 double time_lower_limit = -10.0;
55 double time_upper_limit = 10.0;
56 double z_lower_limit = 0.0;
57 double z_upper_limit = 60.0;
58 Photonspeed = 29.9792458;
63 TDirectory *
main = gDirectory;
64 gDirectory->mkdir(
"ST_Propagation_Time")->cd();
66 h2_PropTime_z_SS_chan =
new TH2I*[
NCHANNELS];
67 h2_PropTime_z_BS_chan =
new TH2I*[
NCHANNELS];
68 h2_PropTime_z_NS_chan =
new TH2I*[
NCHANNELS];
70 h2_PropTimeCorr_z_SS_chan =
new TH2I*[
NCHANNELS];
71 h2_PropTimeCorr_z_BS_chan =
new TH2I*[
NCHANNELS];
72 h2_PropTimeCorr_z_NS_chan =
new TH2I*[
NCHANNELS];
73 h2_CorrectedTime_z =
new TH2I*[
NCHANNELS];
76 h2_PropTime_z_SS_chan[i] =
new TH2I(Form(
"h2_PropTime_z_SS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
77 h2_PropTime_z_BS_chan[i] =
new TH2I(Form(
"h2_PropTime_z_BS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
78 h2_PropTime_z_NS_chan[i] =
new TH2I(Form(
"h2_PropTime_z_NS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
79 h2_PpropTime_z[i] =
new TH2I(Form(
"h2_PpropTime_z_%i", i+1),
"Propagation Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
82 h2_PropTimeCorr_z_SS_chan[i] =
new TH2I(Form(
"h2_PropTimeCorr_z_SS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
83 h2_PropTimeCorr_z_BS_chan[i] =
new TH2I(Form(
"h2_PropTimeCorr_z_BS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
84 h2_PropTimeCorr_z_NS_chan[i] =
new TH2I(Form(
"h2_PropTimeCorr_z_NS_chan_%i", i+1),
"Prop Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
85 h2_CorrectedTime_z[i] =
new TH2I(Form(
"h2_CorrectedTime_z_%i", i+1),
"Corrected Time vs. Path length along the paddle; Path length along the paddle (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
101 vector<const DParticleID *> dParticleID_algos;
102 eventLoop->Get(dParticleID_algos);
103 if(dParticleID_algos.size() < 1)
105 _DBG_<<
"Unable to get a DParticleID object! NO PID will be done!"<<endl;
106 return RESOURCE_UNAVAILABLE;
108 dParticleID = dParticleID_algos[0];
113 vector<const DRFTime*> locRFTimes;
114 eventLoop->Get(locRFTimes);
116 vector<double> locRFPeriodVector;
117 eventLoop->GetCalib(
"PHOTON_BEAM/RF/rf_period", locRFPeriodVector);
118 dRFBunchPeriod = locRFPeriodVector[0];
121 map<string,double> target_params;
122 if (eventLoop->GetCalib(
"/TARGET/target_parms", target_params))
123 jout <<
"Error loading /TARGET/target_parms/ !" << endl;
124 if (target_params.find(
"TARGET_Z_POSITION") != target_params.end())
125 z_target_center = target_params[
"TARGET_Z_POSITION"];
127 jerr <<
"Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
131 _DBG_<<
"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
135 double theta = sc_norm[0][sc_norm[0].size()-2].Theta();
136 sc_angle_corr = 1./cos(M_PI_2 - theta);
140 if(eventLoop->GetCalib(
"START_COUNTER/propagation_time_corr", propagation_time_corr))
141 jout <<
"Error loading /START_COUNTER/propagation_time_corr !" << endl;
143 if(eventLoop->GetCalib(
"START_COUNTER/PTC_Boundary", PTC_Boundary))
144 jout <<
"Error loading /START_COUNTER/PTC_Boundary !" << endl;
147 trackingFOMCut = 0.0027;
175 loop->GetSingle(locTrigger);
180 vector<const DSCHit *> scHitVector;
181 loop->Get(scHitVector);
184 const DRFTime* thisRFTime = NULL;
185 vector <const DRFTime*> RFTimeVector;
186 loop->Get(RFTimeVector);
187 if (RFTimeVector.size() != 0)
188 thisRFTime = RFTimeVector[0];
191 vector<const DChargedTrack *> chargedTrackVector;
192 loop->Get(chargedTrackVector);
196 loop->GetSingle(locDetectorMatches);
200 loop->GetSingle(thisRFBunch);
202 double locTOFRFShiftedTime = 9.9E+9;
204 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
206 shared_ptr<const DSCHitMatchParams> locSCHitMatchParams;
207 shared_ptr<const DTOFHitMatchParams> locTOFHitMatchParams;
210 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
215 if(timeBasedTrack->
FOM < trackingFOMCut)
continue;
219 double z_v = vertex.z();
220 double r_v = vertex.Perp();
221 bool z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
222 bool r_vertex_cut = r_v < 0.5;
224 if (!z_vertex_cut)
continue;
225 if (!r_vertex_cut)
continue;
229 bool foundTOF = dParticleID->Get_BestTOFMatchParams(timeBasedTrack, locDetectorMatches, locTOFHitMatchParams);
230 if (!foundTOF)
continue;
233 bool foundSCandTOF = dParticleID->Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locSCHitMatchParams);
234 if (foundSCandTOF)
continue;
239 double locTOFHitTime = locTOFHitMatchParams->dHitTime;
240 double locTOFTrackFlightTime = locTOFHitMatchParams->dFlightTime;
241 double locFlightTimeCorrectedTOFTime = locTOFHitTime - locTOFTrackFlightTime;
244 double locCenteredRFTime = thisRFTime->
dTime;
245 double locCenterToVertexRFTime = (timeBasedTrack->
z() - z_target_center)*(1.0/Photonspeed);
246 double locVertexRFTime = locCenteredRFTime + locCenterToVertexRFTime;
249 if (locTOFRFShiftedTime != 9.9E+9)
252 if (locTOFRFShiftedTime != 9.9E+9)
255 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
257 shared_ptr<DSCHitMatchParams> locSCHitMatchParams;
258 shared_ptr<const DSCHitMatchParams> locBestSCHitMatchParams;
262 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
268 if(timeBasedTrack->
FOM < trackingFOMCut)
continue;
272 double z_v = vertex.z();
273 double r_v = vertex.Perp();
274 bool z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
275 bool r_vertex_cut = r_v < 0.5;
277 if (!z_vertex_cut)
continue;
278 if (!r_vertex_cut)
continue;
280 bool foundSC = dParticleID->Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locBestSCHitMatchParams);
281 if (!foundSC)
continue;
284 int sc_index = locBestSCHitMatchParams->dSCHit->sector - 1;
286 double sc_pos_soss = sc_pos[sc_index][0].z();
287 double sc_pos_eoss = sc_pos[sc_index][1].z();
288 double sc_pos_eobs = sc_pos[sc_index][11].z();
289 double sc_pos_eons = sc_pos[sc_index][12].z();
291 vector<shared_ptr<const DSCHitMatchParams>> st_params;
292 bool sc_match = locDetectorMatches->
Get_SCMatchParams(timeBasedTrack, st_params);
294 if (!sc_match)
continue;
295 DVector3 IntersectionPoint, IntersectionMomentum;
297 bool sc_match_pid = dParticleID->Cut_MatchDistance(extrapolations, st_params[0]->dSCHit, st_params[0]->dSCHit->t, locSCHitMatchParams,
true, &IntersectionPoint, &IntersectionMomentum);
299 if(!sc_match_pid)
continue;
304 double locSCHitTime = st_params[0]->dSCHit->t;
305 double locSCTrackFlightTime = locSCHitMatchParams->dFlightTime;
306 double locFlightTimeCorrectedSCTime = locSCHitTime - locSCTrackFlightTime;
308 double locSCPropTime = locFlightTimeCorrectedSCTime - locTOFRFShiftedTime;
310 double locSCzIntersection = IntersectionPoint.z();
312 double path_ss=0.,path_bs=0.,path_ns=0.;
313 double SS_Length = sc_pos_eoss - sc_pos_soss;
320 japp->RootFillLock(
this);
323 if (locSCzIntersection > sc_pos_soss && locSCzIntersection <= sc_pos_eoss)
325 path_ss = IntersectionPoint.z() - sc_pos_soss;
326 h2_PropTime_z_SS_chan[sc_index]->Fill(path_ss,locSCPropTime);
327 h2_PpropTime_z[sc_index]->Fill(path_ss,locSCPropTime);
330 if(locSCzIntersection > sc_pos_eoss && locSCzIntersection <= sc_pos_eobs)
332 path_bs = SS_Length + (locSCzIntersection - sc_pos_eoss)*sc_angle_corr;;
333 h2_PropTime_z_BS_chan[sc_index]->Fill(path_bs,locSCPropTime);
334 h2_PpropTime_z[sc_index]->Fill(path_bs,locSCPropTime);
337 if(locSCzIntersection > sc_pos_eobs && locSCzIntersection <= sc_pos_eons)
339 path_ns = SS_Length + (locSCzIntersection - sc_pos_eoss)*sc_angle_corr;;
340 h2_PropTime_z_NS_chan[sc_index]->Fill(path_ns,locSCPropTime);
341 h2_PpropTime_z[sc_index]->Fill(path_ns,locSCPropTime);
347 double incpt_ss = propagation_time_corr[sc_index][0];
348 double slope_ss = propagation_time_corr[sc_index][1];
349 double incpt_bs = propagation_time_corr[sc_index][2];
350 double slope_bs = propagation_time_corr[sc_index][3];
351 double incpt_ns = propagation_time_corr[sc_index][4];
352 double slope_ns = propagation_time_corr[sc_index][5];
354 double Bound1 = PTC_Boundary[0][0];
355 double Bound2 = PTC_Boundary[1][0];
357 if (sc_pos_soss < locSCzIntersection && locSCzIntersection <= sc_pos_eoss)
359 double Corr_Time_ss = locSCPropTime - (incpt_ss + (slope_ss * path_ss));
360 h2_PropTimeCorr_z_SS_chan[sc_index]->Fill(path_ss,Corr_Time_ss);
361 h2_CorrectedTime_z[sc_index]->Fill(path_ss,Corr_Time_ss);
365 if( sc_pos_eoss < locSCzIntersection && locSCzIntersection <= sc_pos_eobs)
367 double Corr_Time_bs = locSCPropTime - (incpt_ss + (slope_ss * path_bs));
368 h2_PropTimeCorr_z_BS_chan[sc_index]->Fill(path_bs,Corr_Time_bs);
369 h2_CorrectedTime_z[sc_index]->Fill(path_bs,Corr_Time_bs);
372 if(sc_pos_eobs < locSCzIntersection && locSCzIntersection <= sc_pos_eons)
375 if (path_ns <= Bound1)
377 double Corr_Time_ns = locSCPropTime - (incpt_ss + (slope_ss * path_ns));
378 h2_PropTimeCorr_z_NS_chan[sc_index]->Fill(path_ns,Corr_Time_ns);
379 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns);
382 else if ((Bound1 < path_ns)&&(path_ns <= Bound2))
384 double Corr_Time_ns = locSCPropTime - (incpt_bs + (slope_bs * path_ns));
385 h2_PropTimeCorr_z_NS_chan[sc_index]->Fill(path_ns,Corr_Time_ns);
386 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns);
390 double Corr_Time_ns = locSCPropTime - (incpt_ns + (slope_ns * path_ns));
391 h2_PropTimeCorr_z_NS_chan[sc_index]->Fill(path_ns,Corr_Time_ns);
392 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns);
395 japp->RootFillUnLock(
this);
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool Get_SCMatchParams(const DTrackingData *locTrack, vector< shared_ptr< const DSCHitMatchParams > > &locMatchParams) const
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.
const DChargedTrackHypothesis * Get_BestTrackingFOM(void) const
const DVector3 & position(void) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
uint32_t Get_L1FrontPanelTriggerBits(void) const
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DGeometry * GetDGeometry(unsigned int run_number)
~JEventProcessor_ST_Propagation_Time()
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
unsigned int dNumParticleVotes
double Step_TimeToNearInputTime(double locTimeToStep, double locTimeToStepTo) const
JEventProcessor_ST_Propagation_Time()
DRFTime_factory * dRFTimeFactory
int main(int argc, char *argv[])
bool GetStartCounterGeom(vector< vector< DVector3 > > &pos, vector< vector< DVector3 > > &norm) const