14 #include <JANA/JApplication.h>
15 #include <JANA/JFactory.h>
55 TDirectory *
main = gDirectory;
56 gDirectory->mkdir(
"st_Tresolution")->cd();
57 h2_CorrectedTime_z =
new TH2I*[
NCHANNELS];
62 time_lower_limit = -4.0;
63 time_upper_limit = 4.0;
65 z_upper_limit = 100.0;
68 h2_CorrectedTime_z[i] =
new TH2I(Form(
"h2_CorrectedTime_z_%i", i+1),
"Corrected Time vs. Z; Z (cm); Propagation Time (ns)", NoBins_z,z_lower_limit,z_upper_limit, NoBins_time, time_lower_limit, time_upper_limit);
71 gDirectory->cd(
"../");
85 vector<double> locRFPeriodVector;
86 eventLoop->GetCalib(
"PHOTON_BEAM/RF/rf_period", locRFPeriodVector);
87 dRFBunchPeriod = locRFPeriodVector[0];
90 map<string,double> target_params;
91 if (eventLoop->GetCalib(
"/TARGET/target_parms", target_params))
92 jout <<
"Error loading /TARGET/target_parms/ !" << endl;
93 if (target_params.find(
"TARGET_Z_POSITION") != target_params.end())
94 z_target_center = target_params[
"TARGET_Z_POSITION"];
96 jerr <<
"Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl;
101 _DBG_<<
"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl;
105 if(eventLoop->GetCalib(
"START_COUNTER/propagation_time_corr", propagation_time_corr))
106 jout <<
"Error loading /START_COUNTER/propagation_time_corr !" << endl;
128 double speed_light = 29.9792458;
131 loop->GetSingle(locTrigger);
137 vector<const DParticleID *> locParticleID_algos;
138 loop->Get(locParticleID_algos);
139 if(locParticleID_algos.size() < 1)
141 _DBG_<<
"Unable to get a DParticleID object! NO PID will be done!"<<endl;
142 return RESOURCE_UNAVAILABLE;
144 auto locParticleID = locParticleID_algos[0];
152 vector<const DSCHit *> scHitVector;
153 loop->Get(scHitVector);
156 const DRFTime* thisRFTime = NULL;
157 vector <const DRFTime*> RFTimeVector;
158 loop->Get(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,
"Calibrations");
176 japp->RootFillLock(
this);
178 for (uint32_t i = 0; i < chargedTrackVector.size(); i++)
181 const DChargedTrack *thisChargedTrack = chargedTrackVector[i];
185 trackingFOMCut = 0.0027;
187 if(timeBasedTrack->
FOM < trackingFOMCut)
continue;
190 shared_ptr<const DSCHitMatchParams> locBestSCHitMatchParams;
191 foundSC = locParticleID->Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locBestSCHitMatchParams);
192 if (!foundSC)
continue;
195 vertex = timeBasedTrack->
position();
199 z_vertex_cut = fabs(z_target_center - z_v) <= 15.0;
200 r_vertex_cut = r_v < 0.5;
202 if (!z_vertex_cut)
continue;
203 if (!r_vertex_cut)
continue;
204 bool st_match = locDetectorMatches->
Get_SCMatchParams(timeBasedTrack, st_params);
206 if (!st_match)
continue;
208 DVector3 IntersectionPoint, IntersectionMomentum;
209 shared_ptr<DSCHitMatchParams> locSCHitMatchParams;
211 bool sc_match_pid = locParticleID->Cut_MatchDistance(extrapolations, st_params[0]->dSCHit, st_params[0]->dSCHit->t, locSCHitMatchParams,
true, &IntersectionPoint, &IntersectionMomentum);
213 if(!sc_match_pid)
continue;
219 locCenteredRFTime = thisRFTime->
dTime;
221 locCenterToVertexRFTime = (timeBasedTrack->
z() - z_target_center)*(1.0/speed_light);
222 locVertexRFTime = locCenteredRFTime + locCenterToVertexRFTime;
223 sc_index= locSCHitMatchParams->dSCHit->sector - 1;
225 sc_pos_soss = sc_pos[sc_index][0].z();
226 sc_pos_eoss = sc_pos[sc_index][1].z();
227 sc_pos_eobs = sc_pos[sc_index][11].z();
228 sc_pos_eons = sc_pos[sc_index][12].z();
230 st_time = st_params[0]->dSCHit->t;
232 FlightTime = locSCHitMatchParams->dFlightTime;
234 st_corr_FlightTime =
st_time - FlightTime;
237 locSCzIntersection = IntersectionPoint.z();
242 double incpt_ss = propagation_time_corr[sc_index][0];
243 double slope_ss = propagation_time_corr[sc_index][1];
244 double incpt_bs = propagation_time_corr[sc_index][2];
245 double slope_bs = propagation_time_corr[sc_index][3];
246 double incpt_ns = propagation_time_corr[sc_index][4];
247 double slope_ns = propagation_time_corr[sc_index][5];
249 if (locSCzIntersection > sc_pos_soss && locSCzIntersection <= sc_pos_eoss)
251 Corr_Time_ss = st_corr_FlightTime - (incpt_ss + (slope_ss * locSCzIntersection));
253 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ss -SC_RFShiftedTime);
256 if(locSCzIntersection > sc_pos_eoss && locSCzIntersection <= sc_pos_eobs)
258 Corr_Time_bs = st_corr_FlightTime - (incpt_bs + (slope_bs * locSCzIntersection));
260 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_bs - SC_RFShiftedTime);
263 if(locSCzIntersection > sc_pos_eobs && locSCzIntersection <= sc_pos_eons)
265 Corr_Time_ns = st_corr_FlightTime - (incpt_ns + (slope_ns * locSCzIntersection));
267 h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ns - SC_RFShiftedTime);
271 japp->RootFillUnLock(
this);
jerror_t init(void)
Called once at program start.
DRFTime_factory * locRFTimeFactory
bool Get_SCMatchParams(const DTrackingData *locTrack, vector< shared_ptr< const DSCHitMatchParams > > &locMatchParams) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
const DChargedTrackHypothesis * Get_BestTrackingFOM(void) const
const DVector3 & position(void) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
JEventProcessor_ST_online_Tresolution()
uint32_t Get_L1FrontPanelTriggerBits(void) const
~JEventProcessor_ST_online_Tresolution()
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DGeometry * GetDGeometry(unsigned int run_number)
jerror_t fini(void)
Called after last event of last event source has been processed.
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
unsigned int dNumParticleVotes
double Step_TimeToNearInputTime(double locTimeToStep, double locTimeToStepTo) const
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int main(int argc, char *argv[])
bool GetStartCounterGeom(vector< vector< DVector3 > > &pos, vector< vector< DVector3 > > &norm) const