1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include "JEventProcessor_ST_online_efficiency.h" |
9 | #include "TRIGGER/DTrigger.h" |
10 | using namespace jana; |
11 | using namespace std; |
12 | |
13 | |
14 | #include <JANA/JApplication.h> |
15 | #include <JANA/JFactory.h> |
16 | extern "C"{ |
17 | void InitPlugin(JApplication *app){ |
18 | InitJANAPlugin(app); |
19 | app->AddProcessor(new JEventProcessor_ST_online_efficiency()); |
20 | } |
21 | } |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | JEventProcessor_ST_online_efficiency::JEventProcessor_ST_online_efficiency() |
28 | { |
29 | |
30 | } |
31 | |
32 | |
33 | |
34 | |
35 | JEventProcessor_ST_online_efficiency::~JEventProcessor_ST_online_efficiency() |
36 | { |
37 | |
38 | } |
39 | |
40 | |
41 | |
42 | |
43 | jerror_t JEventProcessor_ST_online_efficiency::init(void) |
44 | { |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | int USE_SC_TIME = 0; |
55 | if(gPARMS){ |
56 | gPARMS->SetDefaultParameter("TRKFIT:USE_SC_TIME", USE_SC_TIME,"Do not reconstruct tracks with start counter time if set to 0!"); |
57 | } |
58 | |
59 | |
60 | if (USE_SC_TIME == 0) |
61 | { |
62 | cout << "=========================================================================="<< endl; |
63 | cout << "TRKFIT: USE_SC_TIME = 0; WARNING SC TIME WILL NOT BE USED IN TRACK FITTING"<< endl; |
64 | cout << "Which is required in this ST_online_efficiency plugin "<< endl; |
65 | cout << "=========================================================================="<< endl; |
66 | } |
67 | else |
68 | { |
69 | cout << "=========================================================================="<< endl; |
70 | cout << "TRKFIT: USE_SC_TIME = 1; "<< endl; |
71 | cout << "Which will render this publing ST_online_efficiency useless! "<< endl; |
72 | cout << "=========================================================================="<< endl; |
73 | } |
74 | |
75 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
76 | gDirectory(TDirectory::CurrentDirectory())->mkdir("st_efficiency")->cd(); |
77 | |
78 | h_N_trck_prd_All = new TH1D("h_N_trck_prd_All", "h_N_trck_prd_All; Sector; Predicted Hit Counts", 31, -0.5, 30.5); |
79 | h_N_recd_hit_All = new TH1D("h_N_recd_hit_All", "h_N_recd_hit_All; Sector; Recorded Hit Counts", 31, -0.5, 30.5); |
80 | |
81 | h_N_trck_prd_ss = new TH1D("h_N_trck_prd_ss", "h_N_trck_prd_ss; Sector; Predicted Hit Counts", 31, -0.5, 30.5); |
82 | h_N_recd_hit_ss = new TH1D("h_N_recd_hit_ss", "h_N_recd_hit_ss; Sector; Recorded Hit Counts", 31, -0.5, 30.5); |
83 | |
84 | h_N_trck_prd_bs = new TH1D("h_N_trck_prd_bs", "h_N_trck_prd_bs; Sector; Predicted Hit Counts", 31, -0.5, 30.5); |
85 | h_N_recd_hit_bs = new TH1D("h_N_recd_hit_bs", "h_N_recd_hit_bs; Sector; Recorded Hit Counts", 31, -0.5, 30.5); |
86 | |
87 | h_N_trck_prd_ns = new TH1D("h_N_trck_prd_ns", "h_N_trck_prd_ns; Sector; Predicted Hit Counts", 31, -0.5, 30.5); |
88 | h_N_recd_hit_ns = new TH1D("h_N_recd_hit_ns", "h_N_recd_hit_ns; Sector; Recorded Hit Counts", 31, -0.5, 30.5); |
89 | |
90 | h_ST_Eff_All= new TH1D("h_ST_Eff_All", " Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5); |
91 | h_ST_Eff_ss = new TH1D("h_ST_Eff_ss", " SS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5); |
92 | h_ST_Eff_bs = new TH1D("h_ST_Eff_bs", " BS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5); |
93 | h_ST_Eff_ns = new TH1D("h_ST_Eff_ns", " NS Efficiency; Sector; N_{RECD}/N_{TRCK}", 31, -0.5, 30.5); |
94 | |
95 | gDirectory(TDirectory::CurrentDirectory())->cd("../"); |
96 | main->cd(); |
97 | |
98 | |
99 | memset(N_trck_prd_All, 0, sizeof(N_trck_prd_All)); |
100 | memset(N_recd_hit_All, 0, sizeof(N_recd_hit_All)); |
101 | memset(N_trck_prd_ss, 0, sizeof(N_trck_prd_ss)); |
102 | memset(N_recd_hit_ss, 0, sizeof(N_recd_hit_ss)); |
103 | memset(N_trck_prd_bs, 0, sizeof(N_trck_prd_bs)); |
104 | memset(N_recd_hit_bs, 0, sizeof(N_recd_hit_bs)); |
105 | memset(N_trck_prd_ns, 0, sizeof(N_trck_prd_ns)); |
106 | memset(N_recd_hit_ns, 0, sizeof(N_recd_hit_ns)); |
107 | |
108 | return NOERROR; |
109 | } |
110 | |
111 | |
112 | |
113 | |
114 | jerror_t JEventProcessor_ST_online_efficiency::brun(JEventLoop *eventLoop, int32_t runnumber) |
115 | { |
116 | |
117 | |
118 | map<string,double> target_params; |
119 | if (eventLoop->GetCalib("/TARGET/target_parms", target_params)) |
| |
120 | jout << "Error loading /TARGET/target_parms/ !" << endl; |
121 | if (target_params.find("TARGET_Z_POSITION") != target_params.end()) |
| |
122 | z_target_center = target_params["TARGET_Z_POSITION"]; |
123 | else |
124 | jerr << "Unable to get TARGET_Z_POSITION from /TARGET/target_parms !" << endl; |
125 | |
126 | DApplication* dapp = dynamic_cast<DApplication*>(eventLoop->GetJApplication()); |
| 3 | | Calling 'JEventLoop::GetJApplication' | |
|
| 4 | | Returning from 'JEventLoop::GetJApplication' | |
|
| |
127 | if(!dapp) |
| |
| |
128 | _DBG_std::cerr<<"plugins/monitoring/ST_online_efficiency/JEventProcessor_ST_online_efficiency.cc" <<":"<<128<<" "<<"Cannot get DApplication from JEventLoop! (are you using a JApplication based program?)"<<endl; |
129 | DGeometry* locGeometry = dapp->GetDGeometry(eventLoop->GetJEvent().GetRunNumber()); |
| 8 | | Called C++ object pointer is null |
|
130 | locGeometry->GetStartCounterGeom(sc_pos, sc_norm); |
131 | return NOERROR; |
132 | } |
133 | |
134 | |
135 | |
136 | |
137 | jerror_t JEventProcessor_ST_online_efficiency::evnt(JEventLoop *eventLoop, uint64_t eventnumber) |
138 | { |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | const DTrigger* locTrigger = NULL__null; |
154 | eventLoop->GetSingle(locTrigger); |
155 | if(locTrigger->Get_L1FrontPanelTriggerBits() != 0) |
156 | return NOERROR; |
157 | |
158 | vector<const DSCDigiHit*> st_adc_digi_hits; |
159 | vector<const DParticleID*> pid_algorithm; |
160 | vector<const DSCHit*> st_hits; |
161 | vector<const DChargedTrack*> chargedTrackVector; |
162 | eventLoop->Get(st_adc_digi_hits); |
163 | eventLoop->Get(pid_algorithm); |
164 | eventLoop->Get(st_hits); |
165 | eventLoop->Get(chargedTrackVector); |
166 | |
167 | const DDetectorMatches* locDetectorMatches = NULL__null; |
168 | eventLoop->GetSingle(locDetectorMatches); |
169 | |
170 | |
171 | |
172 | japp->RootFillLock(this); |
173 | |
174 | |
175 | for (uint32_t i = 0; i < chargedTrackVector.size(); i++) |
176 | { |
177 | |
178 | const DChargedTrack *thisChargedTrack = chargedTrackVector[i]; |
179 | |
180 | |
181 | const DTrackTimeBased *timeBasedTrack = thisChargedTrack->Get_BestTrackingFOM()->Get_TrackTimeBased(); |
182 | |
183 | float trackingFOMCut = 0.0027; |
184 | if(timeBasedTrack->FOM < trackingFOMCut) continue; |
185 | |
186 | DVector3 vertex; |
187 | |
188 | vertex = timeBasedTrack->position(); |
189 | |
190 | double z_v = vertex.z(); |
191 | double r_v = vertex.Perp(); |
192 | bool z_vertex_cut = fabs(z_target_center - z_v) <= 15.0; |
193 | bool r_vertex_cut = r_v < 1.0; |
194 | |
195 | if (!z_vertex_cut) continue; |
196 | if (!r_vertex_cut) continue; |
197 | vector<DTrackFitter::Extrapolation_t>extrapolations=timeBasedTrack->extrapolations.at(SYS_START); |
198 | int st_pred_id = pid_algorithm[0]->PredictSCSector(extrapolations,&locProjPos,&Barrel); |
199 | int st_pred_id_index = st_pred_id - 1; |
200 | |
201 | locSCzIntersection = locProjPos.z(); |
202 | locSCrIntersection = locProjPos.Perp(); |
203 | |
204 | |
205 | DVector3 Momentum; |
206 | Momentum = timeBasedTrack->momentum(); |
207 | if (st_pred_id != 0) |
208 | { |
209 | |
210 | sc_index = st_pred_id_index; |
211 | |
212 | sc_pos_soss = sc_pos[sc_index][0].z(); |
213 | sc_pos_eoss = sc_pos[sc_index][1].z(); |
214 | sc_pos_eobs = sc_pos[sc_index][11].z(); |
215 | sc_pos_eons = sc_pos[sc_index][12].z(); |
216 | ss_interval = (sc_pos_eoss - sc_pos_soss)/Nof_ss_intervals; |
217 | bs_interval = (sc_pos_eobs - sc_pos_eoss)/Nof_bs_intervals; |
218 | ns_interval = (sc_pos_eons - sc_pos_eobs)/Nof_ns_intervals; |
219 | |
220 | |
221 | |
222 | |
223 | N_trck_prd_All[st_pred_id_index] += 1; |
224 | |
225 | for (uint32_t j = 0; j < st_hits.size(); j++) |
226 | { |
227 | int phi_sec_hit_sector = st_hits[j]->sector; |
228 | |
229 | |
230 | |
231 | if (st_pred_id == phi_sec_hit_sector){ |
232 | N_recd_hit_All[st_pred_id_index] += 1; |
233 | break; |
234 | } |
235 | } |
236 | |
237 | |
238 | |
239 | if ( sc_pos_soss <= locSCzIntersection && locSCzIntersection <= sc_pos_eoss) |
240 | { |
241 | N_trck_prd_ss[st_pred_id_index] += 1; |
242 | |
243 | for (uint32_t j = 0; j < st_hits.size(); j++) |
244 | { |
245 | int phi_sec_hit_sector = st_hits[j]->sector; |
246 | if (st_pred_id == phi_sec_hit_sector) |
247 | { |
248 | N_recd_hit_ss[st_pred_id_index] += 1; |
249 | break; |
250 | } |
251 | } |
252 | } |
253 | |
254 | |
255 | |
256 | if ( sc_pos_eoss < locSCzIntersection && locSCzIntersection <= sc_pos_eobs) |
257 | { |
258 | N_trck_prd_bs[st_pred_id_index] += 1; |
259 | |
260 | for (uint32_t j = 0; j < st_hits.size(); j++) |
261 | { |
262 | int phi_sec_hit_sector = st_hits[j]->sector; |
263 | if (st_pred_id == phi_sec_hit_sector) |
264 | { |
265 | N_recd_hit_bs[st_pred_id_index] += 1; |
266 | break; |
267 | } |
268 | } |
269 | } |
270 | |
271 | |
272 | |
273 | if ( sc_pos_eobs < locSCzIntersection && locSCzIntersection <= sc_pos_eons) |
274 | { |
275 | N_trck_prd_ns[st_pred_id_index] += 1; |
276 | |
277 | |
278 | for (uint32_t j = 0; j < st_hits.size(); j++) |
279 | { |
280 | int phi_sec_hit_sector = st_hits[j]->sector; |
281 | if (st_pred_id == phi_sec_hit_sector) |
282 | { |
283 | N_recd_hit_ns[st_pred_id_index] += 1; |
284 | break; |
285 | } |
286 | } |
287 | } |
288 | } |
289 | } |
290 | |
291 | japp->RootFillUnLock(this); |
292 | |
293 | return NOERROR; |
294 | } |
295 | |
296 | |
297 | |
298 | |
299 | jerror_t JEventProcessor_ST_online_efficiency::erun(void) |
300 | { |
301 | |
302 | |
303 | |
304 | return NOERROR; |
305 | } |
306 | |
307 | |
308 | |
309 | |
310 | jerror_t JEventProcessor_ST_online_efficiency::fini(void) |
311 | { |
312 | |
313 | for (uint32_t i = 0; i < NCHANNELS; i++) |
314 | { |
315 | |
316 | h_N_trck_prd_All->Fill(i+1,double(N_trck_prd_All[i])); |
317 | h_N_recd_hit_All->Fill(i+1,double(N_recd_hit_All[i])); |
318 | h_N_trck_prd_ss->Fill(i+1,double(N_trck_prd_ss[i])); |
319 | h_N_recd_hit_ss->Fill(i+1,double(N_recd_hit_ss[i])); |
320 | h_N_trck_prd_bs->Fill(i+1,double(N_trck_prd_bs[i])); |
321 | h_N_recd_hit_bs->Fill(i+1,double(N_recd_hit_bs[i])); |
322 | h_N_trck_prd_ns->Fill(i+1,double(N_trck_prd_ns[i])); |
323 | h_N_recd_hit_ns->Fill(i+1,double(N_recd_hit_ns[i])); |
324 | |
325 | double r_all=double(N_recd_hit_All[i])/double(N_trck_prd_All[i]); |
326 | double dr_all=r_all*sqrt(1./double(N_recd_hit_All[i]) |
327 | +1./double(N_trck_prd_All[i])); |
328 | h_ST_Eff_All->SetBinContent(i+1,r_all); |
329 | h_ST_Eff_All->SetBinError(i+1,dr_all); |
330 | |
331 | double r_ss=double(N_recd_hit_ss[i])/double(N_trck_prd_ss[i]); |
332 | double dr_ss=r_ss*sqrt(1./double(N_recd_hit_ss[i]) |
333 | +1./double(N_trck_prd_ss[i])); |
334 | h_ST_Eff_ss->SetBinContent(i+1,r_ss); |
335 | h_ST_Eff_ss->SetBinError(i+1,dr_ss); |
336 | |
337 | double r_ns=double(N_recd_hit_ns[i])/double(N_trck_prd_ns[i]); |
338 | double dr_ns=r_ns*sqrt(1./double(N_recd_hit_ns[i]) |
339 | +1./double(N_trck_prd_ns[i])); |
340 | h_ST_Eff_ns->SetBinContent(i+1,r_ns); |
341 | h_ST_Eff_ns->SetBinError(i+1,dr_ns); |
342 | |
343 | double r_bs=double(N_recd_hit_bs[i])/double(N_trck_prd_bs[i]); |
344 | double dr_bs=r_bs*sqrt(1./double(N_recd_hit_bs[i]) |
345 | +1./double(N_trck_prd_bs[i])); |
346 | h_ST_Eff_bs->SetBinContent(i+1,r_bs); |
347 | h_ST_Eff_bs->SetBinError(i+1,dr_bs); |
348 | |
349 | } |
350 | return NOERROR; |
351 | } |
352 | |