1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include "JEventProcessor_ST_online_Tresolution.h" |
9 | #include "TRIGGER/DTrigger.h" |
10 | using namespace jana; |
11 | |
12 | |
13 | |
14 | #include <JANA/JApplication.h> |
15 | #include <JANA/JFactory.h> |
16 | |
17 | #include "RF/DRFTime.h" |
18 | |
19 | extern "C"{ |
20 | void InitPlugin(JApplication *app){ |
21 | InitJANAPlugin(app); |
22 | app->AddProcessor(new JEventProcessor_ST_online_Tresolution()); |
23 | } |
24 | } |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | JEventProcessor_ST_online_Tresolution::JEventProcessor_ST_online_Tresolution() |
31 | { |
32 | |
33 | } |
34 | |
35 | |
36 | |
37 | |
38 | JEventProcessor_ST_online_Tresolution::~JEventProcessor_ST_online_Tresolution() |
39 | { |
40 | |
41 | } |
42 | |
43 | |
44 | |
45 | |
46 | jerror_t JEventProcessor_ST_online_Tresolution::init(void) |
47 | { |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
59 | gDirectory(TDirectory::CurrentDirectory())->mkdir("st_Tresolution")->cd(); |
60 | h2_CorrectedTime_z = new TH2I*[NCHANNELS]; |
61 | |
62 | |
63 | NoBins_time = 80; |
64 | NoBins_z = 1300; |
65 | time_lower_limit = -4.0; |
66 | time_upper_limit = 4.0; |
67 | z_lower_limit = 35.0; |
68 | z_upper_limit = 100.0; |
69 | for (Int_t i = 0; i < NCHANNELS; i++) |
70 | { |
71 | 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); |
72 | } |
73 | |
74 | gDirectory(TDirectory::CurrentDirectory())->cd("../"); |
75 | main->cd(); |
76 | |
77 | return NOERROR; |
78 | } |
79 | |
80 | |
81 | |
82 | |
83 | jerror_t JEventProcessor_ST_online_Tresolution::brun(JEventLoop *eventLoop, int32_t runnumber) |
84 | { |
85 | |
86 | |
87 | |
88 | vector<double> locRFPeriodVector; |
89 | eventLoop->GetCalib("PHOTON_BEAM/RF/rf_period", locRFPeriodVector); |
90 | dRFBunchPeriod = locRFPeriodVector[0]; |
91 | |
92 | |
93 | map<string,double> target_params; |
94 | if (eventLoop->GetCalib("/TARGET/target_parms", target_params)) |
| |
95 | jout << "Error loading /TARGET/target_parms/ !" << endl; |
96 | if (target_params.find("TARGET_Z_POSITION") != target_params.end()) |
| |
97 | z_target_center = target_params["TARGET_Z_POSITION"]; |
98 | else |
99 | jerr << "Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl; |
100 | |
101 | |
102 | DApplication* dapp = dynamic_cast<DApplication*>(eventLoop->GetJApplication()); |
| 3 | | Calling 'JEventLoop::GetJApplication' | |
|
| 4 | | Returning from 'JEventLoop::GetJApplication' | |
|
| |
103 | if(!dapp) |
| |
| |
104 | _DBG_std::cerr<<"plugins/monitoring/ST_online_Tresolution/JEventProcessor_ST_online_Tresolution.cc" <<":"<<104<<" "<<"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl; |
105 | DGeometry* locGeometry = dapp->GetDGeometry(eventLoop->GetJEvent().GetRunNumber()); |
| 8 | | Called C++ object pointer is null |
|
106 | locGeometry->GetStartCounterGeom(sc_pos, sc_norm); |
107 | |
108 | if(eventLoop->GetCalib("START_COUNTER/propagation_time_corr", propagation_time_corr)) |
109 | jout << "Error loading /START_COUNTER/propagation_time_corr !" << endl; |
110 | return NOERROR; |
111 | } |
112 | |
113 | |
114 | |
115 | |
116 | jerror_t JEventProcessor_ST_online_Tresolution::evnt(JEventLoop *loop, uint64_t eventnumber) |
117 | { |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | double speed_light = 29.9792458; |
132 | |
133 | const DTrigger* locTrigger = NULL__null; |
134 | loop->GetSingle(locTrigger); |
135 | if(locTrigger->Get_L1FrontPanelTriggerBits() != 0) |
136 | return NOERROR; |
137 | |
138 | |
139 | |
140 | vector<const DParticleID *> locParticleID_algos; |
141 | loop->Get(locParticleID_algos); |
142 | if(locParticleID_algos.size() < 1) |
143 | { |
144 | _DBG_std::cerr<<"plugins/monitoring/ST_online_Tresolution/JEventProcessor_ST_online_Tresolution.cc" <<":"<<144<<" "<<"Unable to get a DParticleID object! NO PID will be done!"<<endl; |
145 | return RESOURCE_UNAVAILABLE; |
146 | } |
147 | auto locParticleID = locParticleID_algos[0]; |
148 | |
149 | |
150 | |
151 | vector<const DRFTime *> locRFTimes; |
152 | loop->Get(locRFTimes); |
153 | auto locRFTimeFactory = static_cast<DRFTime_factory*>(loop->GetFactory("DRFTime")); |
154 | |
155 | |
156 | |
157 | vector<const DSCHit *> scHitVector; |
158 | loop->Get(scHitVector); |
159 | |
160 | |
161 | const DRFTime* thisRFTime = NULL__null; |
162 | vector <const DRFTime*> RFTimeVector; |
163 | loop->Get(RFTimeVector); |
164 | if (RFTimeVector.size() != 0) |
165 | thisRFTime = RFTimeVector[0]; |
166 | |
167 | |
168 | vector<const DChargedTrack *> chargedTrackVector; |
169 | loop->Get(chargedTrackVector); |
170 | |
171 | |
172 | const DDetectorMatches* locDetectorMatches = NULL__null; |
173 | loop->GetSingle(locDetectorMatches); |
174 | |
175 | |
176 | const DEventRFBunch *thisRFBunch = NULL__null; |
177 | loop->GetSingle(thisRFBunch, "Calibrations"); |
178 | |
179 | |
180 | |
181 | japp->RootFillLock(this); |
182 | |
183 | for (uint32_t i = 0; i < chargedTrackVector.size(); i++) |
184 | { |
185 | |
186 | const DChargedTrack *thisChargedTrack = chargedTrackVector[i]; |
187 | |
188 | const DTrackTimeBased *timeBasedTrack = thisChargedTrack->Get_BestTrackingFOM()->Get_TrackTimeBased(); |
189 | |
190 | trackingFOMCut = 0.0027; |
191 | |
192 | if(timeBasedTrack->FOM < trackingFOMCut) continue; |
193 | |
194 | |
195 | shared_ptr<const DSCHitMatchParams> locBestSCHitMatchParams; |
196 | foundSC = locParticleID->Get_BestSCMatchParams(timeBasedTrack, locDetectorMatches, locBestSCHitMatchParams); |
197 | if (!foundSC) continue; |
198 | |
199 | |
200 | vertex = timeBasedTrack->position(); |
201 | z_v = vertex.z(); |
202 | r_v = vertex.Perp(); |
203 | |
204 | z_vertex_cut = fabs(z_target_center - z_v) <= 15.0; |
205 | r_vertex_cut = r_v < 0.5; |
206 | |
207 | if (!z_vertex_cut) continue; |
208 | if (!r_vertex_cut) continue; |
209 | bool st_match = locDetectorMatches->Get_SCMatchParams(timeBasedTrack, st_params); |
210 | |
211 | if (!st_match) continue; |
212 | |
213 | DVector3 IntersectionPoint, IntersectionMomentum; |
214 | shared_ptr<DSCHitMatchParams> locSCHitMatchParams; |
215 | vector<DTrackFitter::Extrapolation_t>extrapolations=timeBasedTrack->extrapolations.at(SYS_START); |
216 | bool sc_match_pid = locParticleID->Cut_MatchDistance(extrapolations, st_params[0]->dSCHit, st_params[0]->dSCHit->t, locSCHitMatchParams, true, &IntersectionPoint, &IntersectionMomentum); |
217 | |
218 | if(!sc_match_pid) continue; |
219 | |
220 | if (thisRFBunch->dNumParticleVotes < 2) continue; |
221 | |
222 | |
223 | |
224 | locCenteredRFTime = thisRFTime->dTime; |
225 | |
226 | locCenterToVertexRFTime = (timeBasedTrack->z() - z_target_center)*(1.0/speed_light); |
227 | locVertexRFTime = locCenteredRFTime + locCenterToVertexRFTime; |
228 | sc_index= locSCHitMatchParams->dSCHit->sector - 1; |
229 | |
230 | sc_pos_soss = sc_pos[sc_index][0].z(); |
231 | sc_pos_eoss = sc_pos[sc_index][1].z(); |
232 | sc_pos_eobs = sc_pos[sc_index][11].z(); |
233 | sc_pos_eons = sc_pos[sc_index][12].z(); |
234 | |
235 | st_time = st_params[0]->dSCHit->t; |
236 | |
237 | FlightTime = locSCHitMatchParams->dFlightTime; |
238 | |
239 | st_corr_FlightTime = st_time - FlightTime; |
240 | |
241 | |
242 | locSCzIntersection = IntersectionPoint.z(); |
243 | |
244 | |
245 | |
246 | |
247 | double incpt_ss = propagation_time_corr[sc_index][0]; |
248 | double slope_ss = propagation_time_corr[sc_index][1]; |
249 | double incpt_bs = propagation_time_corr[sc_index][2]; |
250 | double slope_bs = propagation_time_corr[sc_index][3]; |
251 | double incpt_ns = propagation_time_corr[sc_index][4]; |
252 | double slope_ns = propagation_time_corr[sc_index][5]; |
253 | |
254 | if (locSCzIntersection > sc_pos_soss && locSCzIntersection <= sc_pos_eoss) |
255 | { |
256 | Corr_Time_ss = st_corr_FlightTime - (incpt_ss + (slope_ss * locSCzIntersection)); |
257 | SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_ss); |
258 | h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ss -SC_RFShiftedTime); |
259 | } |
260 | |
261 | if(locSCzIntersection > sc_pos_eoss && locSCzIntersection <= sc_pos_eobs) |
262 | { |
263 | Corr_Time_bs = st_corr_FlightTime - (incpt_bs + (slope_bs * locSCzIntersection)); |
264 | SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_bs); |
265 | h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_bs - SC_RFShiftedTime); |
266 | } |
267 | |
268 | if(locSCzIntersection > sc_pos_eobs && locSCzIntersection <= sc_pos_eons) |
269 | { |
270 | Corr_Time_ns = st_corr_FlightTime - (incpt_ns + (slope_ns * locSCzIntersection)); |
271 | SC_RFShiftedTime = locRFTimeFactory->Step_TimeToNearInputTime(locVertexRFTime, Corr_Time_ns); |
272 | h2_CorrectedTime_z[sc_index]->Fill(locSCzIntersection,Corr_Time_ns - SC_RFShiftedTime); |
273 | } |
274 | } |
275 | |
276 | japp->RootFillUnLock(this); |
277 | |
278 | return NOERROR; |
279 | } |
280 | |
281 | |
282 | |
283 | |
284 | jerror_t JEventProcessor_ST_online_Tresolution::erun(void) |
285 | { |
286 | |
287 | |
288 | |
289 | return NOERROR; |
290 | } |
291 | |
292 | |
293 | |
294 | |
295 | jerror_t JEventProcessor_ST_online_Tresolution::fini(void) |
296 | { |
297 | |
298 | return NOERROR; |
299 | } |
300 | |