1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | #include "DEventProcessor_pid_dirc.h" |
8 | #include "TCanvas.h" |
9 | #include "TH1.h" |
10 | |
11 | |
12 | |
13 | extern "C" { |
14 | void InitPlugin(JApplication *app) { |
15 | InitJANAPlugin(app); |
16 | app->AddProcessor(new DEventProcessor_pid_dirc()); |
17 | } |
18 | } |
19 | |
20 | DEventProcessor_pid_dirc::DEventProcessor_pid_dirc() { |
21 | fTree = NULL__null; |
22 | fEvent = NULL__null; |
23 | } |
24 | |
25 | DEventProcessor_pid_dirc::~DEventProcessor_pid_dirc() {} |
26 | |
27 | jerror_t DEventProcessor_pid_dirc::init(void) { |
28 | string locOutputFileName = "hd_root.root"; |
29 | if(gPARMS->Exists("OUTPUT_FILENAME")) |
30 | gPARMS->GetParameter("OUTPUT_FILENAME", locOutputFileName); |
31 | |
32 | |
33 | TFile* locFile = (TFile*)gROOT(ROOT::GetROOT())->FindObject(locOutputFileName.c_str()); |
34 | if(locFile != NULL__null) |
35 | locFile->cd(""); |
36 | else |
37 | gDirectory(TDirectory::CurrentDirectory())->Cd("/"); |
38 | |
39 | fTree = new TTree("dirc", "dirc tree"); |
40 | fcEvent = new TClonesArray("DrcEvent"); |
41 | fTree->Branch("DrcEvent",&fcEvent,256000,1); |
42 | return NOERROR; |
43 | } |
44 | |
45 | jerror_t DEventProcessor_pid_dirc::brun(jana::JEventLoop *loop, int32_t runnumber) |
46 | { |
47 | |
48 | DApplication* dapp=dynamic_cast<DApplication*>(loop->GetJApplication()); |
49 | DGeometry *geom = dapp->GetDGeometry(runnumber); |
50 | |
51 | |
52 | vector<double>tof_face; |
53 | geom->Get("//section/composition/posXYZ[@volume='ForwardTOF']/@X_Y_Z", tof_face); |
54 | vector<double>tof_plane; |
55 | geom->Get("//composition[@name='ForwardTOF']/posXYZ[@volume='forwardTOF']/@X_Y_Z/plane[@value='0']", tof_plane); |
56 | double dTOFz=tof_face[2]+tof_plane[2]; |
57 | geom->Get("//composition[@name='ForwardTOF']/posXYZ[@volume='forwardTOF']/@X_Y_Z/plane[@value='1']", tof_plane); |
58 | dTOFz+=tof_face[2]+tof_plane[2]; |
59 | dTOFz*=0.5; |
| Value stored to 'dTOFz' is never read |
60 | |
61 | double dDIRCz; |
62 | vector<double>dirc_face; |
63 | vector<double>dirc_plane; |
64 | vector<double>dirc_shift; |
65 | vector<double>bar_plane; |
66 | geom->Get("//section/composition/posXYZ[@volume='DIRC']/@X_Y_Z", dirc_face); |
67 | geom->Get("//composition[@name='DRCC']/posXYZ[@volume='DCML10']/@X_Y_Z/plane[@value='1']", dirc_plane); |
68 | geom->Get("//composition[@name='DIRC']/posXYZ[@volume='DRCC']/@X_Y_Z", dirc_shift); |
69 | |
70 | dDIRCz=dirc_face[2]+dirc_plane[2]+dirc_shift[2] + 0.8625; |
71 | std::cout<<"dDIRCz "<<dDIRCz<<std::endl; |
72 | |
73 | return NOERROR; |
74 | } |
75 | |
76 | |
77 | |
78 | jerror_t DEventProcessor_pid_dirc::evnt(JEventLoop *loop, uint64_t eventnumber) { |
79 | |
80 | vector<const DMCThrown*> mcthrowns; |
81 | vector<const DMCTrackHit*> mctrackhits; |
82 | vector<const DDIRCTruthBarHit*> dircBarHits; |
83 | vector<const DDIRCTruthPmtHit*> dircPmtHits; |
84 | vector<const DDIRCTDCDigiHit*> dataDigiHits; |
85 | vector<const DDIRCPmtHit*> dataPmtHits; |
86 | vector<const DL1Trigger*> trig; |
87 | |
88 | loop->Get(mcthrowns); |
89 | loop->Get(mctrackhits); |
90 | loop->Get(dircPmtHits); |
91 | loop->Get(dircBarHits); |
92 | loop->Get(dataDigiHits); |
93 | loop->Get(dataPmtHits); |
94 | loop->Get(trig); |
95 | |
96 | |
97 | japp->RootWriteLock(); |
98 | |
99 | |
100 | int trigger = 0; |
101 | if (trig.size() > 0) { |
102 | |
103 | if (trig[0]->fp_trig_mask & 0x4000) trigger = 1; |
104 | |
105 | if (trig[0]->trig_mask & 0x1) trigger = 2; |
106 | } |
107 | |
108 | |
109 | |
110 | double locLEDRefTime = 0; |
111 | |
112 | |
113 | if(trigger==1) { |
114 | vector<const DDIRCLEDRef*> dircLEDRefs; |
115 | loop->Get(dircLEDRefs); |
116 | for(uint i=0; i<dircLEDRefs.size(); i++) { |
117 | const DDIRCLEDRef* dircLEDRef = (DDIRCLEDRef*)dircLEDRefs[i]; |
118 | |
119 | |
120 | locLEDRefTime = dircLEDRef->t_TDC; |
121 | break; |
122 | } |
123 | } |
124 | |
125 | |
126 | TClonesArray& cevt = *fcEvent; |
127 | cevt.Clear(); |
128 | for (unsigned int m = 0; m < mcthrowns.size(); m++){ |
129 | if(dircPmtHits.size() > 0.){ |
130 | fEvent = new DrcEvent(); |
131 | fEvent->SetType(trigger); |
132 | DrcHit hit; |
133 | |
134 | |
135 | for (unsigned int h = 0; h < dircPmtHits.size(); h++){ |
136 | int relevant(0); |
137 | |
138 | for (unsigned int j = 0; j < dircBarHits.size(); j++){ |
139 | |
140 | if(mcthrowns[m]->myid == dircBarHits[j]->track){ |
141 | |
142 | |
143 | |
144 | |
145 | double px = dircBarHits[j]->px; |
146 | double py = dircBarHits[j]->py; |
147 | double pz = dircBarHits[j]->pz; |
148 | |
149 | fEvent->SetMomentum(TVector3(px,py,pz)); |
150 | fEvent->SetPdg(mcthrowns[m]->pdgtype); |
151 | fEvent->SetTime(dircBarHits[j]->t); |
152 | fEvent->SetParent(mcthrowns[m]->parentid); |
153 | fEvent->SetId(dircBarHits[j]->bar); |
154 | fEvent->SetPosition(TVector3(dircBarHits[j]->x, dircBarHits[j]->y, dircBarHits[j]->z)); |
155 | relevant++; |
156 | } |
157 | } |
158 | |
159 | if(relevant<1) continue; |
160 | int ch=dircPmtHits[h]->ch; |
161 | int pmt=ch/64; |
162 | int pix=ch%64; |
163 | |
164 | hit.SetChannel(dircPmtHits[h]->ch); |
165 | hit.SetPmtId(pmt); |
166 | hit.SetPixelId(pix); |
167 | hit.SetPosition(TVector3(dircPmtHits[h]->x,dircPmtHits[h]->y,dircPmtHits[h]->z)); |
168 | hit.SetEnergy(dircPmtHits[h]->E); |
169 | hit.SetLeadTime(dircPmtHits[h]->t); |
170 | hit.SetPathId(dircPmtHits[h]->path); |
171 | hit.SetNreflections(dircPmtHits[h]->refl); |
172 | fEvent->AddHit(hit); |
173 | } |
174 | |
175 | if(fEvent->GetHitSize()>0) new (cevt[ cevt.GetEntriesFast()]) DrcEvent(*fEvent); |
176 | } |
177 | } |
178 | |
179 | |
180 | if(dataPmtHits.size()>0){ |
181 | fEvent = new DrcEvent(); |
182 | fEvent->SetType(trigger); |
183 | fEvent->SetTime(locLEDRefTime); |
184 | |
185 | DrcHit hit; |
186 | for (const auto dhit : dataPmtHits) { |
187 | int ch=dhit->ch; |
188 | int pmt=ch/64; |
189 | int pix=ch%64; |
190 | |
191 | hit.SetChannel(ch); |
192 | hit.SetPmtId(pmt); |
193 | hit.SetPixelId(pix); |
194 | hit.SetLeadTime(dhit->t); |
195 | hit.SetTotTime(dhit->tot); |
196 | fEvent->AddHit(hit); |
197 | } |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | if(fEvent->GetHitSize()>0) new (cevt[ cevt.GetEntriesFast()]) DrcEvent(*fEvent); |
214 | } |
215 | |
216 | if(cevt.GetEntriesFast()>0) fTree->Fill(); |
217 | japp->RootUnLock(); |
218 | |
219 | return NOERROR; |
220 | } |
221 | |
222 | jerror_t DEventProcessor_pid_dirc::erun(void) { |
223 | return NOERROR; |
224 | } |
225 | |
226 | jerror_t DEventProcessor_pid_dirc::fini(void) { |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | return NOERROR; |
233 | } |