14 #include <JANA/JApplication.h>
15 #include <JANA/JFactory.h>
56 TDirectory *
main = gDirectory;
57 gDirectory->mkdir(
"ST_Tresolution")->cd();
59 h2_CorrectedTime_z =
new TH2I*[
NCHANNELS];
61 int NoBins_time = 200;
63 double time_lower_limit = -10.0;
64 double time_upper_limit = 10.0;
65 double z_lower_limit = 0.0;
66 double z_upper_limit = 60.0;
69 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);
86 vector<double> locRFPeriodVector;
87 eventLoop->GetCalib(
"PHOTON_BEAM/RF/rf_period", locRFPeriodVector);
88 dRFBunchPeriod = locRFPeriodVector[0];
91 map<string,double> target_params;
92 if (eventLoop->GetCalib(
"/TARGET/target_parms", target_params))
93 jout <<
"Error loading /TARGET/target_parms/ !" << endl;
94 if (target_params.find(
"TARGET_Z_POSITION") != target_params.end())
95 z_target_center = target_params[
"TARGET_Z_POSITION"];
97 jerr <<
"Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
102 _DBG_<<
"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
106 double theta = sc_norm[0][sc_norm[0].size()-2].Theta();
107 sc_angle_corr = 1./cos(M_PI_2 - theta);
111 if(eventLoop->GetCalib(
"START_COUNTER/propagation_time_corr", propagation_time_corr))
112 jout <<
"Error loading /START_COUNTER/propagation_time_corr !" << endl;
115 if(eventLoop->GetCalib(
"START_COUNTER/PTC_Boundary", PTC_Boundary))
116 jout <<
"Error loading /START_COUNTER/PTC_Boundary !" << endl;
119 trackingFOMCut = 0.0027;
146 loop->GetSingle(locTrigger);
150 double speed_light = 29.9792458;
152 vector<const DSCHit *> scHitVector;
153 loop->Get(scHitVector);
156 const DRFTime* thisRFTime = NULL;
157 vector <const DRFTime*> RFTimeVector;
159 if (RFTimeVector.size() != 0)
160 thisRFTime = RFTimeVector[0];
163 vector<const DChargedTrack *> chargedTrackVector;
164 loop->Get(chargedTrackVector);
168 loop->GetSingle(locDetectorMatches);
172 loop->GetSingle(thisRFBunch);
176 loop->GetSingle(dParticleID);
178 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
181 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
188 if(timeBasedTrack->
FOM < trackingFOMCut)
continue;
191 shared_ptr<const DSCHitMatchParams> locBestSCHitMatchParams;
192 bool foundSC = dParticleID->
Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locBestSCHitMatchParams);
193 if (!foundSC)
continue;
197 double z_v = vertex.z();
198 double r_v = vertex.Perp();
200 bool z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
201 bool r_vertex_cut = r_v < 0.5;
203 if (!z_vertex_cut)
continue;
204 if (!r_vertex_cut)
continue;
205 vector<shared_ptr<const DSCHitMatchParams>> st_params;
206 bool st_match = locDetectorMatches->
Get_SCMatchParams(timeBasedTrack, st_params);
208 if (!st_match)
continue;
210 DVector3 IntersectionPoint, IntersectionMomentum;
211 shared_ptr<DSCHitMatchParams> locSCHitMatchParams;
213 bool sc_match_pid = dParticleID->
Cut_MatchDistance(extrapolations, st_params[0]->dSCHit, st_params[0]->dSCHit->t, locSCHitMatchParams,
true, &IntersectionPoint, &IntersectionMomentum);
215 if(!sc_match_pid)
continue;
221 double locCenteredRFTime = thisRFTime->
dTime;
223 double locCenterToVertexRFTime = (timeBasedTrack->
z() - z_target_center)*(1.0/speed_light);
224 double locVertexRFTime = locCenteredRFTime + locCenterToVertexRFTime;
225 int sc_index= locSCHitMatchParams->dSCHit->sector - 1;
227 double sc_pos_soss = sc_pos[sc_index][0].z();
228 double sc_pos_eoss = sc_pos[sc_index][1].z();
229 double sc_pos_eobs = sc_pos[sc_index][11].z();
230 double sc_pos_eons = sc_pos[sc_index][12].z();
232 double st_time = st_params[0]->dSCHit->t;
234 double FlightTime = locSCHitMatchParams->dFlightTime;
236 double st_corr_FlightTime = st_time - FlightTime;
239 double locSCzIntersection = IntersectionPoint.z();
244 double incpt_ss = propagation_time_corr[sc_index][0];
245 double slope_ss = propagation_time_corr[sc_index][1];
246 double incpt_bs = propagation_time_corr[sc_index][2];
247 double slope_bs = propagation_time_corr[sc_index][3];
248 double incpt_ns = propagation_time_corr[sc_index][4];
249 double slope_ns = propagation_time_corr[sc_index][5];
251 double Bound1 = PTC_Boundary[0][0];
252 double Bound2 = PTC_Boundary[1][0];
261 double SS_Length = sc_pos_eoss - sc_pos_soss;
267 japp->RootFillLock(
this);
270 if (sc_pos_soss < locSCzIntersection && locSCzIntersection <= sc_pos_eoss)
272 double path_ss = locSCzIntersection - sc_pos_soss;
273 double Corr_Time_ss = st_corr_FlightTime - (incpt_ss + (slope_ss * path_ss));
275 h2_CorrectedTime_z[sc_index]->Fill(path_ss, Corr_Time_ss -SC_RFShiftedTime);
278 if(sc_pos_eoss < locSCzIntersection && locSCzIntersection <= sc_pos_eobs)
281 double path_bs = SS_Length + (locSCzIntersection - sc_pos_eoss)*sc_angle_corr;
282 double Corr_Time_bs = st_corr_FlightTime - (incpt_ss + (slope_ss * path_bs));
284 h2_CorrectedTime_z[sc_index]->Fill(path_bs,Corr_Time_bs - SC_RFShiftedTime);
287 if(sc_pos_eobs < locSCzIntersection && locSCzIntersection <= sc_pos_eons)
290 double path_ns = SS_Length + (locSCzIntersection - sc_pos_eoss)*sc_angle_corr;
291 if (path_ns <= Bound1)
293 double Corr_Time_ns = st_corr_FlightTime - (incpt_ss + (slope_ss * path_ns));
295 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns - SC_RFShiftedTime);
297 else if ((Bound1 < path_ns)&&(path_ns <= Bound2))
299 double Corr_Time_ns = st_corr_FlightTime - (incpt_bs + (slope_bs * path_ns));
301 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns - SC_RFShiftedTime);
305 double Corr_Time_ns = st_corr_FlightTime - (incpt_ns + (slope_ns * path_ns));
307 h2_CorrectedTime_z[sc_index]->Fill(path_ns,Corr_Time_ns - SC_RFShiftedTime);
311 japp->RootFillUnLock(
this);
bool Get_SCMatchParams(const DTrackingData *locTrack, vector< shared_ptr< const DSCHitMatchParams > > &locMatchParams) const
const DChargedTrackHypothesis * Get_BestTrackingFOM(void) const
const DVector3 & position(void) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
uint32_t Get_L1FrontPanelTriggerBits(void) const
~JEventProcessor_ST_Tresolution()
bool Get_BestSCMatchParams(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches, shared_ptr< const DSCHitMatchParams > &locBestMatchParams) const
JEventProcessor_ST_Tresolution()
DGeometry * GetDGeometry(unsigned int run_number)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool Cut_MatchDistance(const DReferenceTrajectory *rt, const DBCALShower *locBCALShower, double locInputStartTime, shared_ptr< DBCALShowerMatchParams > &locShowerMatchParams, DVector3 *locOutputProjPos=nullptr, DVector3 *locOutputProjMom=nullptr) const
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
unsigned int dNumParticleVotes
double Step_TimeToNearInputTime(double locTimeToStep, double locTimeToStepTo) const
DRFTime_factory * dRFTimeFactory
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
int main(int argc, char *argv[])
bool GetStartCounterGeom(vector< vector< DVector3 > > &pos, vector< vector< DVector3 > > &norm) const