File: | /home/sdobbs/work/clang/halld_recon/src/libraries/HDDM/DEventSourceREST.cc |
Warning: | line 686, column 13 Value stored to 'mass' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | // |
2 | // Author: Richard Jones June 29, 2012 |
3 | // |
4 | // |
5 | // DEventSourceREST methods |
6 | // |
7 | |
8 | #include <iostream> |
9 | #include <iomanip> |
10 | #include <fstream> |
11 | #include <climits> |
12 | |
13 | #include <JANA/JFactory_base.h> |
14 | #include <JANA/JEventLoop.h> |
15 | #include <JANA/JEvent.h> |
16 | #include <DANA/DStatusBits.h> |
17 | |
18 | #include <DVector2.h> |
19 | #include <DEventSourceREST.h> |
20 | |
21 | //---------------- |
22 | // Constructor |
23 | //---------------- |
24 | DEventSourceREST::DEventSourceREST(const char* source_name) |
25 | : JEventSource(source_name) |
26 | { |
27 | /// Constructor for DEventSourceREST object |
28 | ifs = new ifstream(source_name); |
29 | ifs->get(); |
30 | ifs->unget(); |
31 | if (ifs->rdbuf()->in_avail() > 30) { |
32 | class nonstd_streambuf: public std::streambuf { |
33 | public: char *pub_gptr() {return gptr();} |
34 | }; |
35 | void *buf = (void*)ifs->rdbuf(); |
36 | std::stringstream sbuf(((nonstd_streambuf*)buf)->pub_gptr()); |
37 | std::string head; |
38 | std::getline(sbuf, head); |
39 | std::string expected = " class=\"r\" "; |
40 | if (head.find(expected) == head.npos) { |
41 | std::string msg("Unexpected header found in input REST stream: "); |
42 | throw std::runtime_error(msg + head + source_name); |
43 | } |
44 | } |
45 | |
46 | fin = new hddm_r::istream(*ifs); |
47 | |
48 | PRUNE_DUPLICATE_TRACKS = true; |
49 | gPARMS->SetDefaultParameter("REST:PRUNE_DUPLICATE_TRACKS", PRUNE_DUPLICATE_TRACKS, |
50 | "Turn on/off cleaning up multiple tracks with the same hypothesis from the same candidate. Set to \"0\" to turn off (it's on by default)"); |
51 | |
52 | RECO_DIRC_CALC_LUT = false; |
53 | gPARMS->SetDefaultParameter("REST:DIRC_CALC_LUT", RECO_DIRC_CALC_LUT, "Turn on/off DIRC LUT reconstruction (it's off by default)"); |
54 | |
55 | dDIRCMaxChannels = 108*64; |
56 | |
57 | // any other initialization which needs to happen |
58 | dBCALShowerFactory = nullptr; |
59 | dFCALShowerFactory = nullptr; |
60 | |
61 | USE_CCDB_BCAL_COVARIANCE = false; |
62 | gPARMS->SetDefaultParameter("REST:USE_CCDB_BCAL_COVARIANCE", USE_CCDB_BCAL_COVARIANCE, |
63 | "Load REST BCAL Shower covariance matrices from CCDB instead of the file."); |
64 | USE_CCDB_FCAL_COVARIANCE = false; |
65 | gPARMS->SetDefaultParameter("REST:USE_CCDB_FCAL_COVARIANCE", USE_CCDB_FCAL_COVARIANCE, |
66 | "Load REST BFAL Shower covariance matrices from CCDB instead of the file."); |
67 | } |
68 | |
69 | //---------------- |
70 | // Destructor |
71 | //---------------- |
72 | DEventSourceREST::~DEventSourceREST() |
73 | { |
74 | if (fin) { |
75 | delete fin; |
76 | } |
77 | if (ifs) { |
78 | delete ifs; |
79 | } |
80 | } |
81 | |
82 | //---------------- |
83 | // GetEvent |
84 | //---------------- |
85 | jerror_t DEventSourceREST::GetEvent(JEvent &event) |
86 | { |
87 | /// Implementation of JEventSource virtual function |
88 | |
89 | if (!fin) { |
90 | return EVENT_SOURCE_NOT_OPEN; |
91 | } |
92 | |
93 | // Each open hddm file takes up about 1M of memory so it's |
94 | // worthwhile to close it as soon as we can. |
95 | if (ifs->eof()) { |
96 | delete fin; |
97 | fin = NULL__null; |
98 | delete ifs; |
99 | ifs = NULL__null; |
100 | |
101 | return NO_MORE_EVENTS_IN_SOURCE; |
102 | } |
103 | |
104 | #if HDDM_SETPOSITION_EXAMPLE |
105 | static std::ifstream fevlist("events.list"); |
106 | static int events_to_go = 0; |
107 | if (events_to_go-- == 0 && fevlist.good()) { |
108 | uint64_t start; |
109 | uint32_t offset, status; |
110 | fevlist >> start >> offset >> status >> events_to_go; |
111 | if (fevlist.good()) |
112 | fin->setPosition(hddm_r::streamposition(start, offset, status)); |
113 | } |
114 | #endif |
115 | |
116 | #if HDDM_GETPOSITION_EXAMPLE |
117 | hddm_r::streamposition pos(fin->getPosition()); |
118 | // Later on below, if this event passes all of your selection cuts |
119 | // then you might want to write the event position to output, as in |
120 | // std::cout << "interesting event found at " |
121 | // << pos.start << "," << pos.offset << "," << pos.status |
122 | // << std::endl; |
123 | #endif |
124 | |
125 | hddm_r::HDDM *record = new hddm_r::HDDM(); |
126 | try{ |
127 | while (record->getReconstructedPhysicsEvents().size() == 0) { |
128 | if (! (*fin >> *record)) { |
129 | delete fin; |
130 | fin = NULL__null; |
131 | delete ifs; |
132 | ifs = NULL__null; |
133 | return NO_MORE_EVENTS_IN_SOURCE; |
134 | } |
135 | } |
136 | }catch(std::runtime_error &e){ |
137 | cerr << "Exception caught while trying to read REST file!" << endl; |
138 | cerr << e.what() << endl; |
139 | _DBG__std::cerr<<"libraries/HDDM/DEventSourceREST.cc"<< ":"<<139<<std::endl; |
140 | return NO_MORE_EVENTS_IN_SOURCE; |
141 | } |
142 | |
143 | // Copy the reference info into the JEvent object |
144 | while (true) { |
145 | hddm_r::ReconstructedPhysicsEvent &re |
146 | = record->getReconstructedPhysicsEvent(); |
147 | int runno = re.getRunNo(); |
148 | int eventno = re.getEventNo(); |
149 | if (runno == 0 && eventno == 0) { |
150 | // found a comment record, print comment strings and continue |
151 | const hddm_r::CommentList &comments = re.getComments(); |
152 | hddm_r::CommentList::iterator iter; |
153 | for (iter = comments.begin(); iter != comments.end(); ++iter) { |
154 | std::cout << " | " << iter->getText() << std::endl; |
155 | } |
156 | |
157 | //set version string |
158 | const hddm_r::DataVersionStringList& locVersionStrings = re.getDataVersionStrings(); |
159 | hddm_r::DataVersionStringList::iterator Versioniter; |
160 | for (Versioniter = locVersionStrings.begin(); Versioniter != locVersionStrings.end(); ++Versioniter) { |
161 | string HDDM_DATA_VERSION_STRING = Versioniter->getText(); |
162 | if(gPARMS->Exists("REST:DATAVERSIONSTRING")) |
163 | gPARMS->SetParameter("REST:DATAVERSIONSTRING", HDDM_DATA_VERSION_STRING); |
164 | else |
165 | gPARMS->SetDefaultParameter("REST:DATAVERSIONSTRING", HDDM_DATA_VERSION_STRING); |
166 | break; |
167 | } |
168 | |
169 | //set REST calib context |
170 | const hddm_r::CcdbContextList& locContextStrings = re.getCcdbContexts(); |
171 | hddm_r::CcdbContextList::iterator Contextiter; |
172 | for (Contextiter = locContextStrings.begin(); Contextiter != locContextStrings.end(); ++Contextiter) { |
173 | string REST_JANA_CALIB_CONTEXT = Contextiter->getText(); |
174 | gPARMS->SetDefaultParameter("REST:JANACALIBCONTEXT", REST_JANA_CALIB_CONTEXT); |
175 | } |
176 | |
177 | record->clear(); |
178 | while (record->getReconstructedPhysicsEvents().size() == 0) { |
179 | if (! (*fin >> *record)) { |
180 | delete fin; |
181 | fin = NULL__null; |
182 | delete ifs; |
183 | ifs = NULL__null; |
184 | return NO_MORE_EVENTS_IN_SOURCE; |
185 | } |
186 | } |
187 | |
188 | continue; |
189 | } |
190 | event.SetEventNumber(re.getEventNo()); |
191 | event.SetRunNumber(re.getRunNo()); |
192 | event.SetJEventSource(this); |
193 | event.SetRef(record); |
194 | event.SetStatusBit(kSTATUS_REST); |
195 | event.SetStatusBit(kSTATUS_FROM_FILE); |
196 | event.SetStatusBit(kSTATUS_PHYSICS_EVENT); |
197 | |
198 | ++Nevents_read; |
199 | break; |
200 | } |
201 | |
202 | return NOERROR; |
203 | } |
204 | |
205 | //---------------- |
206 | // FreeEvent |
207 | //---------------- |
208 | void DEventSourceREST::FreeEvent(JEvent &event) |
209 | { |
210 | hddm_r::HDDM *record = (hddm_r::HDDM*)event.GetRef(); |
211 | delete record; |
212 | } |
213 | |
214 | //---------------- |
215 | // GetObjects |
216 | //---------------- |
217 | jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory) |
218 | { |
219 | /// This gets called through the virtual method of the |
220 | /// JEventSource base class. It creates the objects of the type |
221 | /// on which factory is based. It uses the HDDM_Element object |
222 | /// kept in the ref field of the JEvent object passed. |
223 | |
224 | // We must have a factory to hold the data |
225 | if (!factory) { |
226 | throw RESOURCE_UNAVAILABLE; |
227 | } |
228 | |
229 | // The ref field of the JEvent is just the HDDM record pointer. |
230 | hddm_r::HDDM *record = (hddm_r::HDDM*)event.GetRef(); |
231 | if (!record) { |
232 | throw RESOURCE_UNAVAILABLE; |
233 | } |
234 | |
235 | JEventLoop* locEventLoop = event.GetJEventLoop(); |
236 | string dataClassName = factory->GetDataClassName(); |
237 | |
238 | //Get target center |
239 | //multiple reader threads can access this object: need lock |
240 | bool locNewRunNumber = false; |
241 | unsigned int locRunNumber = event.GetRunNumber(); |
242 | LockRead(); |
243 | { |
244 | locNewRunNumber = (dTargetCenterZMap.find(locRunNumber) == dTargetCenterZMap.end()); |
245 | } |
246 | UnlockRead(); |
247 | if(locNewRunNumber) |
248 | { |
249 | DApplication* dapp = dynamic_cast<DApplication*>(locEventLoop->GetJApplication()); |
250 | DGeometry* locGeometry = dapp->GetDGeometry(locEventLoop->GetJEvent().GetRunNumber()); |
251 | double locTargetCenterZ = 0.0; |
252 | locGeometry->GetTargetZ(locTargetCenterZ); |
253 | |
254 | map<string, double> beam_vals; |
255 | if (locEventLoop->GetCalib("PHOTON_BEAM/beam_spot",beam_vals)) |
256 | throw JException("Could not load CCDB table: PHOTON_BEAM/beam_spot"); |
257 | |
258 | vector<double> locBeamPeriodVector; |
259 | if(locEventLoop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector)) |
260 | throw JException("Could not load CCDB table: PHOTON_BEAM/RF/beam_period"); |
261 | double locBeamBunchPeriod = locBeamPeriodVector[0]; |
262 | |
263 | vector< vector <int> > locDIRCChannelStatus; |
264 | vector<int> new_dirc_status(dDIRCMaxChannels); |
265 | locDIRCChannelStatus.push_back(new_dirc_status); |
266 | locDIRCChannelStatus.push_back(new_dirc_status); |
267 | if(RECO_DIRC_CALC_LUT) { // get DIRC channel status from DB |
268 | if (locEventLoop->GetCalib("/DIRC/North/channel_status", locDIRCChannelStatus[0])) |
269 | jout << "Error loading /DIRC/North/channel_status !" << endl; |
270 | if (locEventLoop->GetCalib("/DIRC/South/channel_status", locDIRCChannelStatus[1])) |
271 | jout << "Error loading /DIRC/South/channel_status !" << endl; |
272 | } |
273 | |
274 | LockRead(); |
275 | { |
276 | dTargetCenterZMap[locRunNumber] = locTargetCenterZ; |
277 | dBeamBunchPeriodMap[locRunNumber] = locBeamBunchPeriod; |
278 | dDIRCChannelStatusMap[locRunNumber] = locDIRCChannelStatus; |
279 | |
280 | dBeamCenterMap[locRunNumber].Set(beam_vals["x"], |
281 | beam_vals["y"]); |
282 | dBeamDirMap[locRunNumber].Set(beam_vals["dxdz"], |
283 | beam_vals["dydz"]); |
284 | dBeamZ0Map[locRunNumber]=beam_vals["z"]; |
285 | |
286 | jout << "Run " << locRunNumber << " beam spot:" |
287 | << " x=" << dBeamCenterMap[locRunNumber].X() |
288 | << " y=" << dBeamCenterMap[locRunNumber].Y() |
289 | << " z=" << dBeamZ0Map[locRunNumber] |
290 | << " dx/dz=" << dBeamDirMap[locRunNumber].X() |
291 | << " dy/dz=" << dBeamDirMap[locRunNumber].Y() |
292 | << endl; |
293 | |
294 | } |
295 | UnlockRead(); |
296 | |
297 | // do multiple things to limit the number of locks |
298 | // make sure that we have a handle to the FCAL shower factory |
299 | if(USE_CCDB_FCAL_COVARIANCE) { |
300 | if(dFCALShowerFactory==nullptr) { |
301 | dFCALShowerFactory = static_cast<DFCALShower_factory*>(locEventLoop->GetFactory("DFCALShower")); |
302 | if(dFCALShowerFactory==nullptr) |
303 | throw JException("Couldn't find DFCALShower_factory???"); |
304 | } |
305 | dFCALShowerFactory->LoadCovarianceLookupTables(locEventLoop); |
306 | } |
307 | |
308 | // same with BCAL |
309 | if(USE_CCDB_BCAL_COVARIANCE) { |
310 | if(dBCALShowerFactory==nullptr) { |
311 | dBCALShowerFactory = static_cast<DBCALShower_factory_IU*>(locEventLoop->GetFactory("DBCALShower", "IU")); |
312 | if(dBCALShowerFactory==nullptr) |
313 | throw JException("Couldn't find DBCALShower_factory???"); |
314 | } |
315 | dBCALShowerFactory->LoadCovarianceLookupTables(locEventLoop); |
316 | } |
317 | |
318 | } |
319 | |
320 | if (dataClassName =="DMCReaction") { |
321 | return Extract_DMCReaction(record, |
322 | dynamic_cast<JFactory<DMCReaction>*>(factory), locEventLoop); |
323 | } |
324 | if (dataClassName =="DRFTime") { |
325 | return Extract_DRFTime(record, |
326 | dynamic_cast<JFactory<DRFTime>*>(factory), locEventLoop); |
327 | } |
328 | if (dataClassName =="DBeamPhoton") { |
329 | return Extract_DBeamPhoton(record, |
330 | dynamic_cast<JFactory<DBeamPhoton>*>(factory), |
331 | locEventLoop); |
332 | } |
333 | if (dataClassName =="DMCThrown") { |
334 | return Extract_DMCThrown(record, |
335 | dynamic_cast<JFactory<DMCThrown>*>(factory)); |
336 | } |
337 | if (dataClassName =="DTOFPoint") { |
338 | return Extract_DTOFPoint(record, |
339 | dynamic_cast<JFactory<DTOFPoint>*>(factory)); |
340 | } |
341 | if (dataClassName =="DSCHit") { |
342 | return Extract_DSCHit(record, |
343 | dynamic_cast<JFactory<DSCHit>*>(factory)); |
344 | } |
345 | if (dataClassName =="DFCALShower") { |
346 | return Extract_DFCALShower(record, |
347 | dynamic_cast<JFactory<DFCALShower>*>(factory)); |
348 | } |
349 | if (dataClassName =="DBCALShower") { |
350 | return Extract_DBCALShower(record, |
351 | dynamic_cast<JFactory<DBCALShower>*>(factory)); |
352 | } |
353 | if (dataClassName =="DCCALShower") { |
354 | return Extract_DCCALShower(record, |
355 | dynamic_cast<JFactory<DCCALShower>*>(factory)); |
356 | } |
357 | if (dataClassName =="DTrackTimeBased") { |
358 | return Extract_DTrackTimeBased(record, |
359 | dynamic_cast<JFactory<DTrackTimeBased>*>(factory), locEventLoop); |
360 | } |
361 | if (dataClassName =="DTrigger") { |
362 | return Extract_DTrigger(record, |
363 | dynamic_cast<JFactory<DTrigger>*>(factory)); |
364 | } |
365 | if (dataClassName =="DDIRCPmtHit") { |
366 | return Extract_DDIRCPmtHit(record, |
367 | dynamic_cast<JFactory<DDIRCPmtHit>*>(factory), locEventLoop); |
368 | } |
369 | if (dataClassName =="DDetectorMatches") { |
370 | return Extract_DDetectorMatches(locEventLoop, record, |
371 | dynamic_cast<JFactory<DDetectorMatches>*>(factory)); |
372 | } |
373 | if (dataClassName =="DEventHitStatistics") { |
374 | return Extract_DEventHitStatistics(record, |
375 | dynamic_cast<JFactory<DEventHitStatistics>*>(factory)); |
376 | } |
377 | |
378 | return OBJECT_NOT_AVAILABLE; |
379 | } |
380 | |
381 | //------------------ |
382 | // Extract_DMCReaction |
383 | //------------------ |
384 | jerror_t DEventSourceREST::Extract_DMCReaction(hddm_r::HDDM *record, |
385 | JFactory<DMCReaction> *factory, JEventLoop* locEventLoop) |
386 | { |
387 | /// Copies the data from the Reaction hddm class. This is called |
388 | /// from JEventSourceREST::GetObjects. If factory is NULL, this |
389 | /// returns OBJECT_NOT_AVAILABLE immediately. |
390 | |
391 | if (factory==NULL__null) { |
392 | return OBJECT_NOT_AVAILABLE; |
393 | } |
394 | std::string tag = (factory->Tag())? factory->Tag() : ""; |
395 | |
396 | double locTargetCenterZ = 0.0; |
397 | int locRunNumber = locEventLoop->GetJEvent().GetRunNumber(); |
398 | LockRead(); |
399 | { |
400 | locTargetCenterZ = dTargetCenterZMap[locRunNumber]; |
401 | } |
402 | UnlockRead(); |
403 | DVector3 locPosition(0.0, 0.0, locTargetCenterZ); |
404 | |
405 | vector<DMCReaction*> dmcreactions; |
406 | |
407 | // loop over reaction records |
408 | const hddm_r::ReactionList &reactions = record->getReactions(); |
409 | hddm_r::ReactionList::iterator iter; |
410 | for (iter = reactions.begin(); iter != reactions.end(); ++iter) { |
411 | if (iter->getJtag() != tag) { |
412 | continue; |
413 | } |
414 | DMCReaction *mcreaction = new DMCReaction; |
415 | dmcreactions.push_back(mcreaction); |
416 | mcreaction->type = iter->getType(); |
417 | mcreaction->weight = iter->getWeight(); |
418 | double Ebeam = iter->getEbeam(); |
419 | |
420 | hddm_r::Origin &origin = iter->getVertex().getOrigin(); |
421 | double torig = origin.getT(); |
422 | double zorig = origin.getVz(); |
423 | |
424 | mcreaction->beam.setPosition(locPosition); |
425 | mcreaction->beam.setMomentum(DVector3(0.0, 0.0, Ebeam)); |
426 | mcreaction->beam.setTime(torig - (zorig - locTargetCenterZ)/29.9792458); |
427 | mcreaction->beam.setPID(Gamma); |
428 | |
429 | mcreaction->target.setPosition(locPosition); |
430 | Particle_t ttype = iter->getTargetType(); |
431 | mcreaction->target.setPID((Particle_t)ttype); |
432 | mcreaction->target.setTime(torig - (zorig - locTargetCenterZ)/29.9792458); |
433 | } |
434 | |
435 | // Copy into factories |
436 | factory->CopyTo(dmcreactions); |
437 | |
438 | return NOERROR; |
439 | } |
440 | |
441 | //------------------ |
442 | // Extract_DRFTime |
443 | //------------------ |
444 | jerror_t DEventSourceREST::Extract_DRFTime(hddm_r::HDDM *record, |
445 | JFactory<DRFTime> *factory, JEventLoop* locEventLoop) |
446 | { |
447 | if (factory==NULL__null) |
448 | return OBJECT_NOT_AVAILABLE; |
449 | string tag = (factory->Tag())? factory->Tag() : ""; |
450 | |
451 | vector<DRFTime*> locRFTimes; |
452 | |
453 | // loop over RF-time records |
454 | const hddm_r::RFtimeList &rftimes = record->getRFtimes(); |
455 | hddm_r::RFtimeList::iterator iter; |
456 | for (iter = rftimes.begin(); iter != rftimes.end(); ++iter) |
457 | { |
458 | if (iter->getJtag() != tag) |
459 | continue; |
460 | DRFTime *locRFTime = new DRFTime; |
461 | locRFTime->dTime = iter->getTsync(); |
462 | locRFTime->dTimeVariance = 0.0; //SET ME!! |
463 | locRFTimes.push_back(locRFTime); |
464 | } |
465 | |
466 | if(!locRFTimes.empty()) |
467 | { |
468 | //found in the file, copy into factory and return |
469 | factory->CopyTo(locRFTimes); |
470 | return NOERROR; |
471 | } |
472 | |
473 | //Not found in the file, so either: |
474 | //Experimental data & it's missing: bail |
475 | //MC data: generate it |
476 | |
477 | vector<const DBeamPhoton*> locMCGENPhotons; |
478 | locEventLoop->Get(locMCGENPhotons, "MCGEN"); |
479 | if(locMCGENPhotons.empty()) |
480 | return OBJECT_NOT_AVAILABLE; //Experimental data & it's missing: bail |
481 | |
482 | //Is MC data. Either: |
483 | //No tag: return photon_time propagated by +/- n*locBeamBunchPeriod to get close to 0.0 |
484 | //TRUTH tag: get exact t from DBeamPhoton tag MCGEN |
485 | |
486 | if(tag == "TRUTH") |
487 | { |
488 | DRFTime *locRFTime = new DRFTime; |
489 | locRFTime->dTime = locMCGENPhotons[0]->time(); |
490 | locRFTime->dTimeVariance = 0.0; |
491 | locRFTimes.push_back(locRFTime); |
492 | } |
493 | else |
494 | { |
495 | double locBeamBunchPeriod = 0.0; |
496 | int locRunNumber = locEventLoop->GetJEvent().GetRunNumber(); |
497 | LockRead(); |
498 | { |
499 | locBeamBunchPeriod = dBeamBunchPeriodMap[locRunNumber]; |
500 | } |
501 | UnlockRead(); |
502 | |
503 | //start with true RF time, increment/decrement by multiples of locBeamBunchPeriod ns until closest to 0 |
504 | double locTime = locMCGENPhotons[0]->time(); |
505 | int locNumRFBuckets = int(locTime/locBeamBunchPeriod); |
506 | locTime -= double(locNumRFBuckets)*locBeamBunchPeriod; |
507 | while(locTime > 0.5*locBeamBunchPeriod) |
508 | locTime -= locBeamBunchPeriod; |
509 | while(locTime < -0.5*locBeamBunchPeriod) |
510 | locTime += locBeamBunchPeriod; |
511 | DRFTime *locRFTime = new DRFTime; |
512 | locRFTime->dTime = locTime; |
513 | locRFTime->dTimeVariance = 0.0; |
514 | locRFTimes.push_back(locRFTime); |
515 | } |
516 | |
517 | // Copy into factories |
518 | factory->CopyTo(locRFTimes); |
519 | |
520 | return NOERROR; |
521 | } |
522 | |
523 | //------------------ |
524 | // Extract_DBeamPhoton |
525 | //------------------ |
526 | jerror_t DEventSourceREST::Extract_DBeamPhoton(hddm_r::HDDM *record, |
527 | JFactory<DBeamPhoton> *factory, |
528 | JEventLoop *eventLoop) |
529 | { |
530 | /// This is called from JEventSourceREST::GetObjects. If factory is NULL, |
531 | /// return OBJECT_NOT_AVAILABLE immediately. If factory tag="MCGEN" then |
532 | /// copy the beam photon data from the Reaction hddm class. |
533 | |
534 | if (factory==NULL__null) |
535 | return OBJECT_NOT_AVAILABLE; |
536 | string tag = (factory->Tag())? factory->Tag() : ""; |
537 | |
538 | vector<DBeamPhoton*> dbeam_photons; |
539 | |
540 | // extract the TAGH geometry |
541 | vector<const DTAGHGeometry*> taghGeomVect; |
542 | eventLoop->Get(taghGeomVect); |
543 | if (taghGeomVect.empty()) |
544 | return OBJECT_NOT_AVAILABLE; |
545 | const DTAGHGeometry* taghGeom = taghGeomVect[0]; |
546 | |
547 | // extract the TAGM geometry |
548 | vector<const DTAGMGeometry*> tagmGeomVect; |
549 | eventLoop->Get(tagmGeomVect); |
550 | if (tagmGeomVect.empty()) |
551 | return OBJECT_NOT_AVAILABLE; |
552 | const DTAGMGeometry* tagmGeom = tagmGeomVect[0]; |
553 | |
554 | if(tag == "MCGEN") |
555 | { |
556 | vector<const DMCReaction*> dmcreactions; |
557 | eventLoop->Get(dmcreactions); |
558 | |
559 | for(size_t loc_i = 0; loc_i < dmcreactions.size(); ++loc_i) |
560 | { |
561 | DBeamPhoton *beamphoton = new DBeamPhoton; |
562 | *(DKinematicData*)beamphoton = dmcreactions[loc_i]->beam; |
563 | if(tagmGeom->E_to_column(beamphoton->energy(), beamphoton->dCounter)) |
564 | beamphoton->dSystem = SYS_TAGM; |
565 | else if(taghGeom->E_to_counter(beamphoton->energy(), beamphoton->dCounter)) |
566 | beamphoton->dSystem = SYS_TAGH; |
567 | else |
568 | beamphoton->dSystem = SYS_NULL; |
569 | dbeam_photons.push_back(beamphoton); |
570 | } |
571 | |
572 | // Copy into factories |
573 | factory->CopyTo(dbeam_photons); |
574 | |
575 | return NOERROR; |
576 | } |
577 | |
578 | double locTargetCenterZ = 0.0; |
579 | int locRunNumber = eventLoop->GetJEvent().GetRunNumber(); |
580 | LockRead(); |
581 | { |
582 | locTargetCenterZ = dTargetCenterZMap[locRunNumber]; |
583 | } |
584 | UnlockRead(); |
585 | |
586 | DVector3 pos(0.0, 0.0, locTargetCenterZ); |
587 | |
588 | //now get the objects |
589 | const hddm_r::TagmBeamPhotonList &locTagmBeamPhotonList = record->getTagmBeamPhotons(); |
590 | hddm_r::TagmBeamPhotonList::iterator locTAGMiter; |
591 | for(locTAGMiter = locTagmBeamPhotonList.begin(); locTAGMiter != locTagmBeamPhotonList.end(); ++locTAGMiter) |
592 | { |
593 | if (locTAGMiter->getJtag() != tag) |
594 | continue; |
595 | |
596 | DBeamPhoton* gamma = new DBeamPhoton(); |
597 | |
598 | DVector3 mom(0.0, 0.0, locTAGMiter->getE()); |
599 | gamma->setPID(Gamma); |
600 | gamma->setMomentum(mom); |
601 | gamma->setPosition(pos); |
602 | gamma->setTime(locTAGMiter->getT()); |
603 | gamma->dSystem = SYS_TAGM; |
604 | |
605 | auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
606 | locCovarianceMatrix->ResizeTo(7, 7); |
607 | locCovarianceMatrix->Zero(); |
608 | gamma->setErrorMatrix(locCovarianceMatrix); |
609 | |
610 | tagmGeom->E_to_column(locTAGMiter->getE(), gamma->dCounter); |
611 | dbeam_photons.push_back(gamma); |
612 | } |
613 | |
614 | const hddm_r::TaghBeamPhotonList &locTaghBeamPhotonList = record->getTaghBeamPhotons(); |
615 | hddm_r::TaghBeamPhotonList::iterator locTAGHiter; |
616 | for(locTAGHiter = locTaghBeamPhotonList.begin(); locTAGHiter != locTaghBeamPhotonList.end(); ++locTAGHiter) |
617 | { |
618 | if (locTAGHiter->getJtag() != tag) |
619 | continue; |
620 | |
621 | DBeamPhoton* gamma = new DBeamPhoton(); |
622 | |
623 | DVector3 mom(0.0, 0.0, locTAGHiter->getE()); |
624 | gamma->setPID(Gamma); |
625 | gamma->setMomentum(mom); |
626 | gamma->setPosition(pos); |
627 | gamma->setTime(locTAGHiter->getT()); |
628 | gamma->dSystem = SYS_TAGH; |
629 | |
630 | auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
631 | locCovarianceMatrix->ResizeTo(7, 7); |
632 | locCovarianceMatrix->Zero(); |
633 | gamma->setErrorMatrix(locCovarianceMatrix); |
634 | |
635 | taghGeom->E_to_counter(locTAGHiter->getE(), gamma->dCounter); |
636 | dbeam_photons.push_back(gamma); |
637 | } |
638 | |
639 | if((tag == "TAGGEDMCGEN") && dbeam_photons.empty()) |
640 | return OBJECT_NOT_AVAILABLE; //EITHER: didn't hit a tagger counter //OR: old MC data (pre-saving TAGGEDMCGEN): try using TAGGEDMCGEN factory |
641 | |
642 | // Copy into factories |
643 | factory->CopyTo(dbeam_photons); |
644 | |
645 | return NOERROR; |
646 | } |
647 | |
648 | //------------------ |
649 | // Extract_DMCThrown |
650 | //------------------ |
651 | jerror_t DEventSourceREST::Extract_DMCThrown(hddm_r::HDDM *record, |
652 | JFactory<DMCThrown> *factory) |
653 | { |
654 | /// Copies the data from the hddm vertex records. This is called |
655 | /// from JEventSourceREST::GetObjects. If factory is NULL, this |
656 | /// returns OBJECT_NOT_AVAILABLE immediately. |
657 | |
658 | if (factory==NULL__null) { |
659 | return OBJECT_NOT_AVAILABLE; |
660 | } |
661 | string tag = (factory->Tag())? factory->Tag() : ""; |
662 | |
663 | vector<DMCThrown*> data; |
664 | |
665 | // loop over vertex records |
666 | hddm_r::VertexList vertices = record->getVertices(); |
667 | hddm_r::VertexList::iterator iter; |
668 | for (iter = vertices.begin(); iter != vertices.end(); ++iter) { |
669 | if (iter->getJtag() != tag) { |
670 | continue; |
671 | } |
672 | const hddm_r::Origin &orig = iter->getOrigin(); |
673 | double vx = orig.getVx(); |
674 | double vy = orig.getVy(); |
675 | double vz = orig.getVz(); |
676 | double vt = orig.getT(); |
677 | const hddm_r::ProductList &products = iter->getProducts(); |
678 | hddm_r::ProductList::iterator piter; |
679 | for (piter = products.begin(); piter != products.end(); ++piter) { |
680 | double E = piter->getMomentum().getE(); |
681 | double px = piter->getMomentum().getPx(); |
682 | double py = piter->getMomentum().getPy(); |
683 | double pz = piter->getMomentum().getPz(); |
684 | double mass = sqrt(E*E - (px*px + py*py + pz*pz)); |
685 | if (!isfinite(mass)) { |
686 | mass = 0.0; |
Value stored to 'mass' is never read | |
687 | } |
688 | DMCThrown *mcthrown = new DMCThrown; |
689 | int pdgtype = piter->getPdgtype(); |
690 | Particle_t ptype = PDGtoPType(pdgtype); |
691 | mcthrown->type = ptype; |
692 | mcthrown->pdgtype = pdgtype; |
693 | mcthrown->myid = piter->getId(); |
694 | mcthrown->parentid = piter->getParentId(); |
695 | mcthrown->mech = 0; |
696 | mcthrown->setPID(ptype); |
697 | mcthrown->setMomentum(DVector3(px, py, pz)); |
698 | mcthrown->setPosition(DVector3(vx, vy, vz)); |
699 | mcthrown->setTime(vt); |
700 | data.push_back(mcthrown); |
701 | } |
702 | } |
703 | |
704 | // Copy into factory |
705 | factory->CopyTo(data); |
706 | |
707 | return NOERROR; |
708 | } |
709 | |
710 | //------------------ |
711 | // Extract_DTOFPoint |
712 | //------------------ |
713 | jerror_t DEventSourceREST::Extract_DTOFPoint(hddm_r::HDDM *record, |
714 | JFactory<DTOFPoint>* factory) |
715 | { |
716 | /// Copies the data from the tofPoint hddm record. This is called |
717 | /// from JEventSourceREST::GetObjects. If factory is NULL, this |
718 | /// returns OBJECT_NOT_AVAILABLE immediately. |
719 | |
720 | if (factory==NULL__null) { |
721 | return OBJECT_NOT_AVAILABLE; |
722 | } |
723 | string tag = (factory->Tag())? factory->Tag() : ""; |
724 | |
725 | vector<DTOFPoint*> data; |
726 | |
727 | // loop over tofPoint records |
728 | const hddm_r::TofPointList &tofs = record->getTofPoints(); |
729 | hddm_r::TofPointList::iterator iter; |
730 | for (iter = tofs.begin(); iter != tofs.end(); ++iter) { |
731 | if (iter->getJtag() != tag) { |
732 | continue; |
733 | } |
734 | DTOFPoint *tofpoint = new DTOFPoint(); |
735 | tofpoint->pos = DVector3(iter->getX(),iter->getY(),iter->getZ()); |
736 | tofpoint->t = iter->getT(); |
737 | tofpoint->dE = iter->getDE(); |
738 | tofpoint->tErr = iter->getTerr(); |
739 | |
740 | //Status |
741 | const hddm_r::TofStatusList& locTofStatusList = iter->getTofStatuses(); |
742 | hddm_r::TofStatusList::iterator locStatusIterator = locTofStatusList.begin(); |
743 | if(locStatusIterator == locTofStatusList.end()) |
744 | { |
745 | tofpoint->dHorizontalBar = 0; |
746 | tofpoint->dVerticalBar = 0; |
747 | tofpoint->dHorizontalBarStatus = 3; |
748 | tofpoint->dVerticalBarStatus = 3; |
749 | } |
750 | else //should only be 1 |
751 | { |
752 | for(; locStatusIterator != locTofStatusList.end(); ++locStatusIterator) |
753 | { |
754 | int locStatus = locStatusIterator->getStatus(); //horizontal_bar + 45*vertical_bar + 45*45*horizontal_status + 45*45*4*vertical_status |
755 | tofpoint->dVerticalBarStatus = locStatus/(45*45*4); |
756 | locStatus %= 45*45*4; //Assume compiler optimizes multiplication |
757 | tofpoint->dHorizontalBarStatus = locStatus/(45*45); |
758 | locStatus %= 45*45; |
759 | tofpoint->dVerticalBar = locStatus/45; |
760 | tofpoint->dHorizontalBar = locStatus % 45; |
761 | } |
762 | } |
763 | // Energy deposition |
764 | const hddm_r::TofEnergyDepositionList& locTofEnergyDepositionList = iter->getTofEnergyDepositions(); |
765 | hddm_r::TofEnergyDepositionList::iterator locEnergyDepositionIterator = locTofEnergyDepositionList.begin(); |
766 | if(locEnergyDepositionIterator == locTofEnergyDepositionList.end()) |
767 | { |
768 | tofpoint->dE1 = 0.; |
769 | tofpoint->dE2 = 0.; |
770 | } |
771 | else //should only be 1 |
772 | { |
773 | for(; locEnergyDepositionIterator != locTofEnergyDepositionList.end(); ++locEnergyDepositionIterator) |
774 | { |
775 | tofpoint->dE1 = locEnergyDepositionIterator->getDE1(); |
776 | tofpoint->dE2 = locEnergyDepositionIterator->getDE2(); |
777 | } |
778 | } |
779 | |
780 | data.push_back(tofpoint); |
781 | } |
782 | |
783 | // Copy into factory |
784 | factory->CopyTo(data); |
785 | |
786 | return NOERROR; |
787 | } |
788 | |
789 | //------------------ |
790 | // Extract_DSCHit |
791 | //------------------ |
792 | jerror_t DEventSourceREST::Extract_DSCHit(hddm_r::HDDM *record, |
793 | JFactory<DSCHit>* factory) |
794 | { |
795 | /// Copies the data from the startHit hddm record. This is called |
796 | /// from JEventSourceREST::GetObjects. If factory is NULL, this |
797 | /// returns OBJECT_NOT_AVAILABLE immediately. |
798 | |
799 | if (factory==NULL__null) { |
800 | return OBJECT_NOT_AVAILABLE; |
801 | } |
802 | string tag = (factory->Tag())? factory->Tag() : ""; |
803 | |
804 | vector<DSCHit*> data; |
805 | |
806 | // loop over startHit records |
807 | const hddm_r::StartHitList &starts = record->getStartHits(); |
808 | hddm_r::StartHitList::iterator iter; |
809 | for (iter = starts.begin(); iter != starts.end(); ++iter) { |
810 | if (iter->getJtag() != tag) { |
811 | continue; |
812 | } |
813 | DSCHit *start = new DSCHit(); |
814 | start->sector = iter->getSector(); |
815 | start->dE = iter->getDE(); |
816 | start->t = iter->getT(); |
817 | data.push_back(start); |
818 | } |
819 | |
820 | // Copy into factory |
821 | factory->CopyTo(data); |
822 | |
823 | return NOERROR; |
824 | } |
825 | |
826 | //----------------------- |
827 | // Extract_DTrigger |
828 | //----------------------- |
829 | jerror_t DEventSourceREST::Extract_DTrigger(hddm_r::HDDM *record, JFactory<DTrigger>* factory) |
830 | { |
831 | /// Copies the data from the trigger hddm record. This is |
832 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
833 | /// returns OBJECT_NOT_AVAILABLE immediately. |
834 | |
835 | if (factory==NULL__null) |
836 | return OBJECT_NOT_AVAILABLE; |
837 | string tag = (factory->Tag())? factory->Tag() : ""; |
838 | |
839 | vector<DTrigger*> data; |
840 | |
841 | // loop over trigger records |
842 | const hddm_r::TriggerList &triggers = record->getTriggers(); |
843 | hddm_r::TriggerList::iterator iter; |
844 | for (iter = triggers.begin(); iter != triggers.end(); ++iter) |
845 | { |
846 | if (iter->getJtag() != tag) |
847 | continue; |
848 | |
849 | DTrigger *locTrigger = new DTrigger(); |
850 | locTrigger->Set_L1TriggerBits(Convert_SignedIntToUnsigned(iter->getL1_trig_bits())); |
851 | locTrigger->Set_L1FrontPanelTriggerBits(Convert_SignedIntToUnsigned(iter->getL1_fp_trig_bits())); |
852 | |
853 | const hddm_r::TriggerEnergySumsList& locTriggerEnergySumsList = iter->getTriggerEnergySumses(); |
854 | hddm_r::TriggerEnergySumsList::iterator locTriggerEnergySumsIterator = locTriggerEnergySumsList.begin(); |
855 | if(locTriggerEnergySumsIterator == locTriggerEnergySumsList.end()) { |
856 | locTrigger->Set_GTP_BCALEnergy(0); |
857 | locTrigger->Set_GTP_FCALEnergy(0); |
858 | } else { //should only be 1 |
859 | for(; locTriggerEnergySumsIterator != locTriggerEnergySumsList.end(); ++locTriggerEnergySumsIterator) { |
860 | locTrigger->Set_GTP_BCALEnergy(locTriggerEnergySumsIterator->getBCALEnergySum()); |
861 | locTrigger->Set_GTP_FCALEnergy(locTriggerEnergySumsIterator->getFCALEnergySum()); |
862 | } |
863 | } |
864 | |
865 | data.push_back(locTrigger); |
866 | } |
867 | |
868 | // Copy into factory |
869 | factory->CopyTo(data); |
870 | |
871 | return NOERROR; |
872 | } |
873 | |
874 | //----------------------- |
875 | // Extract_DFCALShower |
876 | //----------------------- |
877 | jerror_t DEventSourceREST::Extract_DFCALShower(hddm_r::HDDM *record, |
878 | JFactory<DFCALShower>* factory) |
879 | { |
880 | /// Copies the data from the fcalShower hddm record. This is |
881 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
882 | /// returns OBJECT_NOT_AVAILABLE immediately. |
883 | |
884 | if (factory==NULL__null) { |
885 | return OBJECT_NOT_AVAILABLE; |
886 | } |
887 | string tag = (factory->Tag())? factory->Tag() : ""; |
888 | |
889 | vector<DFCALShower*> data; |
890 | |
891 | // loop over fcal shower records |
892 | const hddm_r::FcalShowerList &showers = |
893 | record->getFcalShowers(); |
894 | hddm_r::FcalShowerList::iterator iter; |
895 | for (iter = showers.begin(); iter != showers.end(); ++iter) { |
896 | if (iter->getJtag() != tag) |
897 | continue; |
898 | |
899 | DFCALShower *shower = new DFCALShower(); |
900 | shower->setPosition(DVector3(iter->getX(),iter->getY(),iter->getZ())); |
901 | shower->setEnergy(iter->getE()); |
902 | shower->setTime(iter->getT()); |
903 | |
904 | if(USE_CCDB_FCAL_COVARIANCE) { |
905 | dFCALShowerFactory->FillCovarianceMatrix(shower); |
906 | } else { |
907 | TMatrixFSym covariance(5); |
908 | covariance(0,0) = iter->getEerr()*iter->getEerr(); |
909 | covariance(1,1) = iter->getXerr()*iter->getXerr(); |
910 | covariance(2,2) = iter->getYerr()*iter->getYerr(); |
911 | covariance(3,3) = iter->getZerr()*iter->getZerr(); |
912 | covariance(4,4) = iter->getTerr()*iter->getTerr(); |
913 | covariance(1,2) = covariance(2,1) = iter->getXycorr()*iter->getXerr()*iter->getYerr(); |
914 | covariance(1,3) = covariance(3,1) = iter->getXzcorr()*iter->getXerr()*iter->getZerr(); |
915 | covariance(2,3) = covariance(3,2) = iter->getYzcorr()*iter->getYerr()*iter->getZerr(); |
916 | covariance(0,3) = covariance(3,0) = iter->getEzcorr()*iter->getEerr()*iter->getZerr(); |
917 | covariance(3,4) = covariance(4,3) = iter->getTzcorr()*iter->getTerr()*iter->getZerr(); |
918 | |
919 | // further correlations (an extension of REST format, so code is different.) |
920 | const hddm_r::FcalCorrelationsList& locFcalCorrelationsList = iter->getFcalCorrelationses(); |
921 | hddm_r::FcalCorrelationsList::iterator locFcalCorrelationsIterator = locFcalCorrelationsList.begin(); |
922 | if(locFcalCorrelationsIterator != locFcalCorrelationsList.end()) { |
923 | covariance(0,4) = covariance(4,0) = locFcalCorrelationsIterator->getEtcorr()*iter->getEerr()*iter->getTerr(); |
924 | covariance(0,1) = covariance(1,0) = locFcalCorrelationsIterator->getExcorr()*iter->getEerr()*iter->getXerr(); |
925 | covariance(0,2) = covariance(2,0) = locFcalCorrelationsIterator->getEycorr()*iter->getEerr()*iter->getYerr(); |
926 | covariance(1,4) = covariance(4,1) = locFcalCorrelationsIterator->getTxcorr()*iter->getTerr()*iter->getXerr(); |
927 | covariance(2,4) = covariance(4,2) = locFcalCorrelationsIterator->getTycorr()*iter->getTerr()*iter->getYerr(); |
928 | } |
929 | shower->ExyztCovariance = covariance; |
930 | } |
931 | |
932 | // MVA classifier output - this information is being calculated in DNeutralShower now! |
933 | //const hddm_r::FcalShowerClassificationList& locFcalShowerClassificationList = iter->getFcalShowerClassifications(); |
934 | //hddm_r::FcalShowerClassificationList::iterator locFcalShowerClassificationIterator = locFcalShowerClassificationList.begin(); |
935 | //if(locFcalShowerClassificationIterator != locFcalShowerClassificationList.end()) { |
936 | // shower->setClassifierOutput(locFcalShowerClassificationIterator->getClassifierOuput()); |
937 | //} |
938 | |
939 | // shower shape and other parameters. used e.g. as input to MVA classifier |
940 | const hddm_r::FcalShowerPropertiesList& locFcalShowerPropertiesList = iter->getFcalShowerPropertiesList(); |
941 | hddm_r::FcalShowerPropertiesList::iterator locFcalShowerPropertiesIterator = locFcalShowerPropertiesList.begin(); |
942 | if(locFcalShowerPropertiesIterator != locFcalShowerPropertiesList.end()) { |
943 | shower->setDocaTrack(locFcalShowerPropertiesIterator->getDocaTrack()); |
944 | shower->setTimeTrack(locFcalShowerPropertiesIterator->getTimeTrack()); |
945 | shower->setSumU(locFcalShowerPropertiesIterator->getSumU()); |
946 | shower->setSumV(locFcalShowerPropertiesIterator->getSumV()); |
947 | shower->setE1E9(locFcalShowerPropertiesIterator->getE1E9()); |
948 | shower->setE9E25(locFcalShowerPropertiesIterator->getE9E25()); |
949 | } |
950 | |
951 | const hddm_r::FcalShowerNBlocksList& locFcalShowerNBlocksList = iter->getFcalShowerNBlockses(); |
952 | hddm_r::FcalShowerNBlocksList::iterator locFcalShowerNBlocksIterator = locFcalShowerNBlocksList.begin(); |
953 | if(locFcalShowerNBlocksIterator != locFcalShowerNBlocksList.end()) { |
954 | shower->setNumBlocks(locFcalShowerNBlocksIterator->getNumBlocks()); |
955 | } |
956 | data.push_back(shower); |
957 | } |
958 | |
959 | // Copy into factory |
960 | factory->CopyTo(data); |
961 | |
962 | return NOERROR; |
963 | } |
964 | |
965 | //----------------------- |
966 | // Extract_DBCALShower |
967 | //----------------------- |
968 | jerror_t DEventSourceREST::Extract_DBCALShower(hddm_r::HDDM *record, |
969 | JFactory<DBCALShower>* factory) |
970 | { |
971 | /// Copies the data from the bcalShower hddm record. This is |
972 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
973 | /// returns OBJECT_NOT_AVAILABLE immediately. |
974 | |
975 | if (factory==NULL__null) { |
976 | return OBJECT_NOT_AVAILABLE; |
977 | } |
978 | string tag = (factory->Tag())? factory->Tag() : ""; |
979 | |
980 | vector<DBCALShower*> data; |
981 | |
982 | // loop over bcal shower records |
983 | const hddm_r::BcalShowerList &showers = |
984 | record->getBcalShowers(); |
985 | hddm_r::BcalShowerList::iterator iter; |
986 | for (iter = showers.begin(); iter != showers.end(); ++iter) { |
987 | if (iter->getJtag() != tag) |
988 | continue; |
989 | |
990 | DBCALShower *shower = new DBCALShower(); |
991 | shower->E = iter->getE(); |
992 | shower->E_raw = -1; |
993 | shower->x = iter->getX(); |
994 | shower->y = iter->getY(); |
995 | shower->z = iter->getZ(); |
996 | shower->t = iter->getT(); |
997 | shower->Q = 0; // Fix this to zero for now, can add to REST if it's ever used in higher-level analyses |
998 | |
999 | if(USE_CCDB_BCAL_COVARIANCE) { |
1000 | dBCALShowerFactory->FillCovarianceMatrix(shower); |
1001 | } else { |
1002 | TMatrixFSym covariance(5); |
1003 | covariance(0,0) = iter->getEerr()*iter->getEerr(); |
1004 | covariance(1,1) = iter->getXerr()*iter->getXerr(); |
1005 | covariance(2,2) = iter->getYerr()*iter->getYerr(); |
1006 | covariance(3,3) = iter->getZerr()*iter->getZerr(); |
1007 | covariance(4,4) = iter->getTerr()*iter->getTerr(); |
1008 | covariance(1,2) = covariance(2,1) = iter->getXycorr()*iter->getXerr()*iter->getYerr(); |
1009 | covariance(1,3) = covariance(3,1) = iter->getXzcorr()*iter->getXerr()*iter->getZerr(); |
1010 | covariance(2,3) = covariance(3,2) = iter->getYzcorr()*iter->getYerr()*iter->getZerr(); |
1011 | covariance(0,3) = covariance(3,0) = iter->getEzcorr()*iter->getEerr()*iter->getZerr(); |
1012 | covariance(3,4) = covariance(4,3) = iter->getTzcorr()*iter->getTerr()*iter->getZerr(); |
1013 | |
1014 | // further correlations (an extension of REST format, so code is different.) |
1015 | const hddm_r::BcalCorrelationsList& locBcalCorrelationsList = iter->getBcalCorrelationses(); |
1016 | hddm_r::BcalCorrelationsList::iterator locBcalCorrelationsIterator = locBcalCorrelationsList.begin(); |
1017 | if(locBcalCorrelationsIterator != locBcalCorrelationsList.end()) { |
1018 | covariance(0,4) = covariance(4,0) = locBcalCorrelationsIterator->getEtcorr()*iter->getEerr()*iter->getTerr(); |
1019 | covariance(0,1) = covariance(1,0) = locBcalCorrelationsIterator->getExcorr()*iter->getEerr()*iter->getXerr(); |
1020 | covariance(0,2) = covariance(2,0) = locBcalCorrelationsIterator->getEycorr()*iter->getEerr()*iter->getYerr(); |
1021 | covariance(1,4) = covariance(4,1) = locBcalCorrelationsIterator->getTxcorr()*iter->getTerr()*iter->getXerr(); |
1022 | covariance(2,4) = covariance(4,2) = locBcalCorrelationsIterator->getTycorr()*iter->getTerr()*iter->getYerr(); |
1023 | } |
1024 | shower->ExyztCovariance = covariance; |
1025 | } |
1026 | |
1027 | // preshower |
1028 | const hddm_r::PreshowerList& locPreShowerList = iter->getPreshowers(); |
1029 | hddm_r::PreshowerList::iterator locPreShowerIterator = locPreShowerList.begin(); |
1030 | if(locPreShowerIterator == locPreShowerList.end()) |
1031 | shower->E_preshower = 0.0; |
1032 | else //should only be 1 |
1033 | { |
1034 | for(; locPreShowerIterator != locPreShowerList.end(); ++locPreShowerIterator) |
1035 | shower->E_preshower = locPreShowerIterator->getPreshowerE(); |
1036 | } |
1037 | |
1038 | // width |
1039 | const hddm_r::WidthList& locWidthList = iter->getWidths(); |
1040 | hddm_r::WidthList::iterator locWidthIterator = locWidthList.begin(); |
1041 | if(locWidthIterator == locWidthList.end()) { |
1042 | shower->sigLong = -1.; |
1043 | shower->sigTrans = -1.; |
1044 | shower->sigTheta = -1.; |
1045 | } |
1046 | else //should only be 1 |
1047 | { |
1048 | for(; locWidthIterator != locWidthList.end(); ++locWidthIterator) { |
1049 | shower->sigLong = locWidthIterator->getSigLong(); |
1050 | shower->sigTrans = locWidthIterator->getSigTrans(); |
1051 | shower->sigTheta = locWidthIterator->getSigTheta(); |
1052 | } |
1053 | } |
1054 | |
1055 | const hddm_r::BcalClusterList& locBcalClusterList = iter->getBcalClusters(); |
1056 | hddm_r::BcalClusterList::iterator locBcalClusterIterator = locBcalClusterList.begin(); |
1057 | if(locBcalClusterIterator == locBcalClusterList.end()) |
1058 | shower->N_cell = -1; |
1059 | else //should only be 1 |
1060 | { |
1061 | for(; locBcalClusterIterator != locBcalClusterList.end(); ++locBcalClusterIterator) |
1062 | shower->N_cell = locBcalClusterIterator->getNcell(); |
1063 | } |
1064 | |
1065 | const hddm_r::BcalLayersList& locBcalLayersList = iter->getBcalLayerses(); |
1066 | hddm_r::BcalLayersList::iterator locBcalLayersIterator = locBcalLayersList.begin(); |
1067 | if(locBcalLayersIterator == locBcalLayersList.end()) { |
1068 | shower->E_L2 = 0.; |
1069 | shower->E_L3 = 0.; |
1070 | shower->E_L4 = 0.; |
1071 | shower->rmsTime = -1; |
1072 | } |
1073 | else //should only be 1 |
1074 | { |
1075 | for(; locBcalLayersIterator != locBcalLayersList.end(); ++locBcalLayersIterator) { |
1076 | shower->rmsTime = locBcalLayersIterator->getRmsTime(); |
1077 | shower->E_L2 = locBcalLayersIterator->getE_L2(); |
1078 | shower->E_L3 = locBcalLayersIterator->getE_L3(); |
1079 | shower->E_L4 = locBcalLayersIterator->getE_L4(); |
1080 | } |
1081 | } |
1082 | |
1083 | data.push_back(shower); |
1084 | } |
1085 | |
1086 | // Copy into factory |
1087 | factory->CopyTo(data); |
1088 | |
1089 | return NOERROR; |
1090 | } |
1091 | |
1092 | //----------------------- |
1093 | // Extract_DCCALShower |
1094 | //----------------------- |
1095 | jerror_t DEventSourceREST::Extract_DCCALShower(hddm_r::HDDM *record, |
1096 | JFactory<DCCALShower>* factory) |
1097 | { |
1098 | /// Copies the data from the ccalShower hddm record. This is |
1099 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
1100 | /// returns OBJECT_NOT_AVAILABLE immediately. |
1101 | |
1102 | if (factory==NULL__null) { |
1103 | return OBJECT_NOT_AVAILABLE; |
1104 | } |
1105 | string tag = (factory->Tag())? factory->Tag() : ""; |
1106 | |
1107 | vector<DCCALShower*> data; |
1108 | |
1109 | // loop over ccal shower records |
1110 | const hddm_r::CcalShowerList &showers = |
1111 | record->getCcalShowers(); |
1112 | hddm_r::CcalShowerList::iterator iter; |
1113 | for (iter = showers.begin(); iter != showers.end(); ++iter) { |
1114 | if (iter->getJtag() != tag) |
1115 | continue; |
1116 | |
1117 | DCCALShower *shower = new DCCALShower(); |
1118 | shower->E = iter->getE(); |
1119 | shower->x = iter->getX(); |
1120 | shower->y = iter->getY(); |
1121 | shower->z = iter->getZ(); |
1122 | shower->time = iter->getT(); |
1123 | shower->sigma_t = iter->getTerr(); |
1124 | shower->sigma_E = iter->getEerr(); |
1125 | shower->Emax = iter->getEmax(); |
1126 | shower->x1 = iter->getX1(); |
1127 | shower->y1 = iter->getY1(); |
1128 | shower->chi2 = iter->getChi2(); |
1129 | |
1130 | shower->type = iter->getType(); |
1131 | shower->dime = iter->getDime(); |
1132 | shower->id = iter->getId(); |
1133 | shower->idmax = iter->getIdmax(); |
1134 | |
1135 | data.push_back(shower); |
1136 | } |
1137 | |
1138 | // Copy into factory |
1139 | factory->CopyTo(data); |
1140 | |
1141 | return NOERROR; |
1142 | } |
1143 | |
1144 | //-------------------------------- |
1145 | // Extract_DTrackTimeBased |
1146 | //-------------------------------- |
1147 | jerror_t DEventSourceREST::Extract_DTrackTimeBased(hddm_r::HDDM *record, |
1148 | JFactory<DTrackTimeBased>* factory, JEventLoop* locEventLoop) |
1149 | { |
1150 | /// Copies the data from the chargedTrack hddm record. This is |
1151 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
1152 | /// returns OBJECT_NOT_AVAILABLE immediately. |
1153 | |
1154 | if (factory==NULL__null) { |
1155 | return OBJECT_NOT_AVAILABLE; |
1156 | } |
1157 | |
1158 | int locRunNumber = locEventLoop->GetJEvent().GetRunNumber(); |
1159 | DVector2 locBeamCenter,locBeamDir; |
1160 | double locBeamZ0=0.; |
1161 | LockRead(); |
1162 | { |
1163 | locBeamCenter = dBeamCenterMap[locRunNumber]; |
1164 | locBeamDir = dBeamDirMap[locRunNumber]; |
1165 | locBeamZ0 = dBeamZ0Map[locRunNumber]; |
1166 | } |
1167 | UnlockRead(); |
1168 | |
1169 | string tag = (factory->Tag())? factory->Tag() : ""; |
1170 | |
1171 | vector<DTrackTimeBased*> data; |
1172 | |
1173 | // loop over chargedTrack records |
1174 | const hddm_r::ChargedTrackList &tracks = record->getChargedTracks(); |
1175 | hddm_r::ChargedTrackList::iterator iter; |
1176 | for (iter = tracks.begin(); iter != tracks.end(); ++iter) { |
1177 | if (iter->getJtag() != tag) { |
1178 | continue; |
1179 | } |
1180 | DTrackTimeBased *tra = new DTrackTimeBased(); |
1181 | tra->trackid = 0; |
1182 | tra->candidateid = iter->getCandidateId(); |
1183 | Particle_t ptype = iter->getPtype(); |
1184 | tra->setPID(ptype); |
1185 | |
1186 | const hddm_r::TrackFit &fit = iter->getTrackFit(); |
1187 | tra->Ndof = fit.getNdof(); |
1188 | tra->chisq = fit.getChisq(); |
1189 | tra->FOM = TMath::Prob(tra->chisq, tra->Ndof); |
1190 | tra->setTime(fit.getT0()); |
1191 | DVector3 track_pos(fit.getX0(),fit.getY0(),fit.getZ0()); |
1192 | DVector3 track_mom(fit.getPx(),fit.getPy(),fit.getPz()); |
1193 | tra->setPosition(track_pos); |
1194 | tra->setMomentum(track_mom); |
1195 | |
1196 | auto loc5x5ErrorMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
1197 | loc5x5ErrorMatrix->ResizeTo(5, 5); |
1198 | (*loc5x5ErrorMatrix)(0,0) = fit.getE11(); |
1199 | (*loc5x5ErrorMatrix)(0,1) = (*loc5x5ErrorMatrix)(1,0) = fit.getE12(); |
1200 | (*loc5x5ErrorMatrix)(0,2) = (*loc5x5ErrorMatrix)(2,0) = fit.getE13(); |
1201 | (*loc5x5ErrorMatrix)(0,3) = (*loc5x5ErrorMatrix)(3,0) = fit.getE14(); |
1202 | (*loc5x5ErrorMatrix)(0,4) = (*loc5x5ErrorMatrix)(4,0) = fit.getE15(); |
1203 | (*loc5x5ErrorMatrix)(1,1) = fit.getE22(); |
1204 | (*loc5x5ErrorMatrix)(1,2) = (*loc5x5ErrorMatrix)(2,1) = fit.getE23(); |
1205 | (*loc5x5ErrorMatrix)(1,3) = (*loc5x5ErrorMatrix)(3,1) = fit.getE24(); |
1206 | (*loc5x5ErrorMatrix)(1,4) = (*loc5x5ErrorMatrix)(4,1) = fit.getE25(); |
1207 | (*loc5x5ErrorMatrix)(2,2) = fit.getE33(); |
1208 | (*loc5x5ErrorMatrix)(2,3) = (*loc5x5ErrorMatrix)(3,2) = fit.getE34(); |
1209 | (*loc5x5ErrorMatrix)(2,4) = (*loc5x5ErrorMatrix)(4,2) = fit.getE35(); |
1210 | (*loc5x5ErrorMatrix)(3,3) = fit.getE44(); |
1211 | (*loc5x5ErrorMatrix)(3,4) = (*loc5x5ErrorMatrix)(4,3) = fit.getE45(); |
1212 | (*loc5x5ErrorMatrix)(4,4) = fit.getE55(); |
1213 | tra->setTrackingErrorMatrix(loc5x5ErrorMatrix); |
1214 | |
1215 | // Convert from cartesian coordinates to the 5x1 state vector corresponding to the tracking error matrix. |
1216 | double vect[5]; |
1217 | DVector2 beam_pos=locBeamCenter+(track_pos.Z()-locBeamZ0)*locBeamDir; |
1218 | DVector2 diff(track_pos.X()-beam_pos.X(),track_pos.Y()-beam_pos.Y()); |
1219 | vect[2]=tan(M_PI_21.57079632679489661923 - track_mom.Theta()); |
1220 | vect[1]=track_mom.Phi(); |
1221 | double sinphi=sin(vect[1]); |
1222 | double cosphi=cos(vect[1]); |
1223 | vect[0]=tra->charge()/track_mom.Perp(); |
1224 | vect[4]=track_pos.Z(); |
1225 | vect[3]=diff.Mod(); |
1226 | |
1227 | if ((diff.X() > 0 && sinphi>0) || (diff.Y() <0 && cosphi>0) || (diff.Y() >0 && cosphi<0) || (diff.X() <0 && sinphi<0)) |
1228 | vect[3] *= -1.; |
1229 | tra->setTrackingStateVector(vect[0], vect[1], vect[2], vect[3], vect[4]); |
1230 | |
1231 | // Set the 7x7 covariance matrix. |
1232 | auto loc7x7ErrorMatrix = dResourcePool_TMatrixFSym->Get_SharedResource(); |
1233 | loc7x7ErrorMatrix->ResizeTo(7, 7); |
1234 | Get7x7ErrorMatrix(tra->mass(), vect, loc5x5ErrorMatrix.get(), loc7x7ErrorMatrix.get()); |
1235 | tra->setErrorMatrix(loc7x7ErrorMatrix); |
1236 | (*loc7x7ErrorMatrix)(6, 6) = fit.getT0err()*fit.getT0err(); |
1237 | |
1238 | // Track parameters at exit of tracking volume |
1239 | const hddm_r::ExitParamsList& locExitParamsList = iter->getExitParamses(); |
1240 | hddm_r::ExitParamsList::iterator locExitParamsIterator = locExitParamsList.begin(); |
1241 | if (locExitParamsIterator!=locExitParamsList.end()){ |
1242 | // Create the extrapolation vector |
1243 | vector<DTrackFitter::Extrapolation_t>myvector; |
1244 | tra->extrapolations.emplace(SYS_NULL,myvector); |
1245 | |
1246 | for(; locExitParamsIterator != locExitParamsList.end(); ++locExitParamsIterator){ |
1247 | DVector3 pos(locExitParamsIterator->getX1(), |
1248 | locExitParamsIterator->getY1(), |
1249 | locExitParamsIterator->getZ1()); |
1250 | DVector3 mom(locExitParamsIterator->getPx1(), |
1251 | locExitParamsIterator->getPy1(), |
1252 | locExitParamsIterator->getPz1()); |
1253 | tra->extrapolations[SYS_NULL].push_back(DTrackFitter::Extrapolation_t(pos,mom,locExitParamsIterator->getT1(),0.)); |
1254 | } |
1255 | } |
1256 | // Hit layers |
1257 | const hddm_r::ExpectedhitsList& locExpectedhitsList = iter->getExpectedhitses(); |
1258 | hddm_r::ExpectedhitsList::iterator locExpectedhitsIterator = locExpectedhitsList.begin(); |
1259 | if(locExpectedhitsIterator == locExpectedhitsList.end()) |
1260 | { |
1261 | tra->potential_cdc_hits_on_track = 0; |
1262 | tra->potential_fdc_hits_on_track = 0; |
1263 | tra->measured_cdc_hits_on_track = 0; |
1264 | tra->measured_fdc_hits_on_track = 0; |
1265 | //tra->cdc_hit_usage.total_hits = 0; |
1266 | //tra->fdc_hit_usage.total_hits = 0; |
1267 | } |
1268 | else //should only be 1 |
1269 | { |
1270 | for(; locExpectedhitsIterator != locExpectedhitsList.end(); ++locExpectedhitsIterator) |
1271 | { |
1272 | tra->potential_cdc_hits_on_track = locExpectedhitsIterator->getExpectedCDChits(); |
1273 | tra->potential_fdc_hits_on_track = locExpectedhitsIterator->getExpectedFDChits(); |
1274 | tra->measured_cdc_hits_on_track = locExpectedhitsIterator->getMeasuredCDChits(); |
1275 | tra->measured_fdc_hits_on_track = locExpectedhitsIterator->getMeasuredFDChits(); |
1276 | //tra->cdc_hit_usage.total_hits = locExpectedhitsIterator->getMeasuredCDChits(); |
1277 | //tra->fdc_hit_usage.total_hits = locExpectedhitsIterator->getMeasuredFDChits(); |
1278 | } |
1279 | } |
1280 | |
1281 | // Expected number of hits |
1282 | const hddm_r::HitlayersList& locHitlayersList = iter->getHitlayerses(); |
1283 | hddm_r::HitlayersList::iterator locHitlayersIterator = locHitlayersList.begin(); |
1284 | if(locHitlayersIterator == locHitlayersList.end()) |
1285 | { |
1286 | tra->dCDCRings = 0; |
1287 | tra->dFDCPlanes = 0; |
1288 | } |
1289 | else //should only be 1 |
1290 | { |
1291 | for(; locHitlayersIterator != locHitlayersList.end(); ++locHitlayersIterator) |
1292 | { |
1293 | tra->dCDCRings = locHitlayersIterator->getCDCrings(); |
1294 | tra->dFDCPlanes = locHitlayersIterator->getFDCplanes(); |
1295 | } |
1296 | } |
1297 | |
1298 | // MC match hit info |
1299 | const hddm_r::McmatchList& locMCMatchesList = iter->getMcmatchs(); |
1300 | hddm_r::McmatchList::iterator locMcmatchIterator = locMCMatchesList.begin(); |
1301 | if(locMcmatchIterator == locMCMatchesList.end()) |
1302 | { |
1303 | tra->dCDCRings = 0; |
1304 | tra->dFDCPlanes = 0; |
1305 | } |
1306 | else //should only be 1 |
1307 | { |
1308 | for(; locMcmatchIterator != locMCMatchesList.end(); ++locMcmatchIterator) |
1309 | { |
1310 | tra->dMCThrownMatchMyID = locMcmatchIterator->getIthrown(); |
1311 | tra->dNumHitsMatchedToThrown = locMcmatchIterator->getNumhitsmatch(); |
1312 | } |
1313 | } |
1314 | |
1315 | // add the drift chamber dE/dx information |
1316 | const hddm_r::DEdxDCList &el = iter->getDEdxDCs(); |
1317 | hddm_r::DEdxDCList::iterator diter = el.begin(); |
1318 | if (diter != el.end()) { |
1319 | tra->dNumHitsUsedFordEdx_FDC = diter->getNsampleFDC(); |
1320 | tra->dNumHitsUsedFordEdx_CDC = diter->getNsampleCDC(); |
1321 | tra->ddEdx_FDC = diter->getDEdxFDC(); |
1322 | tra->ddEdx_CDC = diter->getDEdxCDC(); |
1323 | tra->ddx_FDC = diter->getDxFDC(); |
1324 | tra->ddx_CDC = diter->getDxCDC(); |
1325 | const hddm_r::CDCAmpdEdxList &el2 = diter->getCDCAmpdEdxs(); |
1326 | hddm_r::CDCAmpdEdxList::iterator diter2 = el2.begin(); |
1327 | if (diter2 != el2.end()){ |
1328 | tra->ddx_CDC_amp= diter2->getDxCDCAmp(); |
1329 | tra->ddEdx_CDC_amp = diter2->getDEdxCDCAmp(); |
1330 | } |
1331 | else{ |
1332 | tra->ddx_CDC_amp=tra->ddx_CDC; |
1333 | tra->ddEdx_CDC_amp=tra->ddEdx_CDC; |
1334 | } |
1335 | } |
1336 | else { |
1337 | tra->dNumHitsUsedFordEdx_FDC = 0; |
1338 | tra->dNumHitsUsedFordEdx_CDC = 0; |
1339 | tra->ddEdx_FDC = 0.0; |
1340 | tra->ddEdx_CDC = 0.0; |
1341 | tra->ddx_FDC = 0.0; |
1342 | tra->ddx_CDC = 0.0; |
1343 | tra->ddEdx_CDC_amp = 0.0; |
1344 | tra->ddx_CDC_amp = 0.0; |
1345 | } |
1346 | |
1347 | data.push_back(tra); |
1348 | } |
1349 | |
1350 | if( PRUNE_DUPLICATE_TRACKS && (data.size() > 1) ) { |
1351 | vector< int > indices_to_erase; |
1352 | vector<DTrackTimeBased*>::iterator it = data.begin(); |
1353 | |
1354 | for( unsigned int i=0; i<data.size()-1; i++ ) { |
1355 | for( unsigned int j=i+1; j<data.size(); j++ ) { |
1356 | if(find(indices_to_erase.begin(), indices_to_erase.end(), j) != indices_to_erase.end()) |
1357 | continue; |
1358 | |
1359 | // look through the remaining tracks for duplicates |
1360 | // (1) if there is a track with the same candidate/PID and worse chi^2, reject that track |
1361 | // (2) if there is a track with the same candidate/PID and better chi^2, reject this track |
1362 | if( (data[i]->candidateid == data[j]->candidateid) |
1363 | && (data[i]->PID() == data[j]->PID()) ) { // is a duplicate track |
1364 | if(data[i]->chisq < data[j]->chisq) { |
1365 | indices_to_erase.push_back(j); |
1366 | } else { |
1367 | indices_to_erase.push_back(i); |
1368 | } |
1369 | } |
1370 | } |
1371 | } |
1372 | |
1373 | // create the new set of tracks |
1374 | vector<DTrackTimeBased*> new_data; |
1375 | for( unsigned int i=0; i<data.size(); i++ ) { |
1376 | if(find(indices_to_erase.begin(), indices_to_erase.end(), i) != indices_to_erase.end()) |
1377 | continue; |
1378 | |
1379 | new_data.push_back(data[i]); |
1380 | } |
1381 | data = new_data; // replace the set of tracks with the pruned one |
1382 | } |
1383 | |
1384 | // Copy into factory |
1385 | factory->CopyTo(data); |
1386 | |
1387 | return NOERROR; |
1388 | } |
1389 | |
1390 | //-------------------------------- |
1391 | // Extract_DDetectorMatches |
1392 | //-------------------------------- |
1393 | jerror_t DEventSourceREST::Extract_DDetectorMatches(JEventLoop* locEventLoop, hddm_r::HDDM *record, JFactory<DDetectorMatches>* factory) |
1394 | { |
1395 | /// Copies the data from the detectorMatches hddm record. This is |
1396 | /// called from JEventSourceREST::GetObjects. If factory is NULL, this |
1397 | /// returns OBJECT_NOT_AVAILABLE immediately. |
1398 | |
1399 | if(factory==NULL__null) |
1400 | return OBJECT_NOT_AVAILABLE; |
1401 | |
1402 | string tag = (factory->Tag())? factory->Tag() : ""; |
1403 | vector<DDetectorMatches*> data; |
1404 | |
1405 | vector<const DTrackTimeBased*> locTrackTimeBasedVector; |
1406 | locEventLoop->Get(locTrackTimeBasedVector); |
1407 | |
1408 | vector<const DSCHit*> locSCHits; |
1409 | locEventLoop->Get(locSCHits); |
1410 | |
1411 | vector<const DTOFPoint*> locTOFPoints; |
1412 | locEventLoop->Get(locTOFPoints); |
1413 | |
1414 | vector<const DBCALShower*> locBCALShowers; |
1415 | locEventLoop->Get(locBCALShowers); |
1416 | |
1417 | vector<const DFCALShower*> locFCALShowers; |
1418 | locEventLoop->Get(locFCALShowers); |
1419 | |
1420 | const DParticleID* locParticleID = NULL__null; |
1421 | vector<const DDIRCPmtHit*> locDIRCHits; |
1422 | vector<const DDIRCTruthBarHit*> locDIRCBarHits; |
1423 | if(RECO_DIRC_CALC_LUT) { |
1424 | locEventLoop->GetSingle(locParticleID); |
1425 | locEventLoop->Get(locDIRCHits); |
1426 | locEventLoop->Get(locDIRCBarHits); |
1427 | } |
1428 | |
1429 | const hddm_r::DetectorMatchesList &detectormatches = record->getDetectorMatcheses(); |
1430 | |
1431 | // loop over chargedTrack records |
1432 | hddm_r::DetectorMatchesList::iterator iter; |
1433 | for(iter = detectormatches.begin(); iter != detectormatches.end(); ++iter) |
1434 | { |
1435 | if(iter->getJtag() != tag) |
1436 | continue; |
1437 | |
1438 | DDetectorMatches *locDetectorMatches = new DDetectorMatches(); |
1439 | |
1440 | const hddm_r::DircMatchParamsList &dircList = iter->getDircMatchParamses(); |
1441 | hddm_r::DircMatchParamsList::iterator dircIter = dircList.begin(); |
1442 | const hddm_r::DircMatchHitList &dircMatchHitList = iter->getDircMatchHits(); |
1443 | |
1444 | for(; dircIter != dircList.end(); ++dircIter) |
1445 | { |
1446 | size_t locTrackIndex = dircIter->getTrack(); |
1447 | if(locTrackIndex >= locTrackTimeBasedVector.size()) continue; |
1448 | |
1449 | auto locTrackTimeBased = locTrackTimeBasedVector[locTrackIndex]; |
1450 | if( !locTrackTimeBased ) continue; |
1451 | |
1452 | auto locDIRCMatchParams = std::make_shared<DDIRCMatchParams>(); |
1453 | map<shared_ptr<const DDIRCMatchParams> ,vector<const DDIRCPmtHit*> > locDIRCTrackMatchParams; |
1454 | locDetectorMatches->Get_DIRCTrackMatchParamsMap(locDIRCTrackMatchParams); |
1455 | |
1456 | if(RECO_DIRC_CALC_LUT) { |
1457 | TVector3 locProjPos(dircIter->getX(),dircIter->getY(),dircIter->getZ()); |
1458 | TVector3 locProjMom(dircIter->getPx(),dircIter->getPy(),dircIter->getPz()); |
1459 | double locFlightTime = dircIter->getT(); |
1460 | |
1461 | if( locParticleID->Get_DIRCLut()->CalcLUT(locProjPos, locProjMom, locDIRCHits, locFlightTime, locTrackTimeBased->mass(), locDIRCMatchParams, locDIRCBarHits, locDIRCTrackMatchParams) ) |
1462 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], std::const_pointer_cast<const DDIRCMatchParams>(locDIRCMatchParams)); |
1463 | } |
1464 | else { |
1465 | // add hits to match list |
1466 | hddm_r::DircMatchHitList::iterator dircMatchHitIter = dircMatchHitList.begin(); |
1467 | for(; dircMatchHitIter != dircMatchHitList.end(); ++dircMatchHitIter) { |
1468 | size_t locMatchHitTrackIndex = dircMatchHitIter->getTrack(); |
1469 | if(locMatchHitTrackIndex == locTrackIndex) { |
1470 | size_t locMatchHitIndex = dircMatchHitIter->getHit(); |
1471 | locDIRCTrackMatchParams[locDIRCMatchParams].push_back(locDIRCHits[locMatchHitIndex]); |
1472 | } |
1473 | } |
1474 | |
1475 | locDIRCMatchParams->dExtrapolatedPos = DVector3(dircIter->getX(),dircIter->getY(),dircIter->getZ()); |
1476 | locDIRCMatchParams->dExtrapolatedMom = DVector3(dircIter->getPx(),dircIter->getPy(),dircIter->getPz()); |
1477 | locDIRCMatchParams->dExtrapolatedTime = dircIter->getT(); |
1478 | locDIRCMatchParams->dExpectedThetaC = dircIter->getExpectthetac(); |
1479 | locDIRCMatchParams->dThetaC = dircIter->getThetac(); |
1480 | locDIRCMatchParams->dDeltaT = dircIter->getDeltat(); |
1481 | locDIRCMatchParams->dLikelihoodElectron = dircIter->getLele(); |
1482 | locDIRCMatchParams->dLikelihoodPion = dircIter->getLpi(); |
1483 | locDIRCMatchParams->dLikelihoodKaon = dircIter->getLk(); |
1484 | locDIRCMatchParams->dLikelihoodProton = dircIter->getLp(); |
1485 | locDIRCMatchParams->dNPhotons = dircIter->getNphotons(); |
1486 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], std::const_pointer_cast<const DDIRCMatchParams>(locDIRCMatchParams)); |
1487 | } |
1488 | } |
1489 | |
1490 | const hddm_r::BcalMatchParamsList &bcalList = iter->getBcalMatchParamses(); |
1491 | hddm_r::BcalMatchParamsList::iterator bcalIter = bcalList.begin(); |
1492 | for(; bcalIter != bcalList.end(); ++bcalIter) |
1493 | { |
1494 | size_t locShowerIndex = bcalIter->getShower(); |
1495 | size_t locTrackIndex = bcalIter->getTrack(); |
1496 | |
1497 | auto locShowerMatchParams = std::make_shared<DBCALShowerMatchParams>(); |
1498 | locShowerMatchParams->dBCALShower = locBCALShowers[locShowerIndex]; |
1499 | locShowerMatchParams->dx = bcalIter->getDx(); |
1500 | locShowerMatchParams->dFlightTime = bcalIter->getTflight(); |
1501 | locShowerMatchParams->dFlightTimeVariance = bcalIter->getTflightvar(); |
1502 | locShowerMatchParams->dPathLength = bcalIter->getPathlength(); |
1503 | locShowerMatchParams->dDeltaPhiToShower = bcalIter->getDeltaphi(); |
1504 | locShowerMatchParams->dDeltaZToShower = bcalIter->getDeltaz(); |
1505 | |
1506 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], locBCALShowers[locShowerIndex], std::const_pointer_cast<const DBCALShowerMatchParams>(locShowerMatchParams)); |
1507 | } |
1508 | |
1509 | const hddm_r::FcalMatchParamsList &fcalList = iter->getFcalMatchParamses(); |
1510 | hddm_r::FcalMatchParamsList::iterator fcalIter = fcalList.begin(); |
1511 | for(; fcalIter != fcalList.end(); ++fcalIter) |
1512 | { |
1513 | size_t locShowerIndex = fcalIter->getShower(); |
1514 | size_t locTrackIndex = fcalIter->getTrack(); |
1515 | |
1516 | auto locShowerMatchParams = std::make_shared<DFCALShowerMatchParams>(); |
1517 | locShowerMatchParams->dFCALShower = locFCALShowers[locShowerIndex]; |
1518 | locShowerMatchParams->dx = fcalIter->getDx(); |
1519 | locShowerMatchParams->dFlightTime = fcalIter->getTflight(); |
1520 | locShowerMatchParams->dFlightTimeVariance = fcalIter->getTflightvar(); |
1521 | locShowerMatchParams->dPathLength = fcalIter->getPathlength(); |
1522 | locShowerMatchParams->dDOCAToShower = fcalIter->getDoca(); |
1523 | |
1524 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], locFCALShowers[locShowerIndex], std::const_pointer_cast<const DFCALShowerMatchParams>(locShowerMatchParams)); |
1525 | } |
1526 | |
1527 | const hddm_r::ScMatchParamsList &scList = iter->getScMatchParamses(); |
1528 | hddm_r::ScMatchParamsList::iterator scIter = scList.begin(); |
1529 | for(; scIter != scList.end(); ++scIter) |
1530 | { |
1531 | size_t locHitIndex = scIter->getHit(); |
1532 | size_t locTrackIndex = scIter->getTrack(); |
1533 | |
1534 | auto locSCHitMatchParams = std::make_shared<DSCHitMatchParams>(); |
1535 | locSCHitMatchParams->dSCHit = locSCHits[locHitIndex]; |
1536 | locSCHitMatchParams->dEdx = scIter->getDEdx(); |
1537 | locSCHitMatchParams->dHitTime = scIter->getThit(); |
1538 | locSCHitMatchParams->dHitTimeVariance = scIter->getThitvar(); |
1539 | locSCHitMatchParams->dHitEnergy = scIter->getEhit(); |
1540 | locSCHitMatchParams->dFlightTime = scIter->getTflight(); |
1541 | locSCHitMatchParams->dFlightTimeVariance = scIter->getTflightvar(); |
1542 | locSCHitMatchParams->dPathLength = scIter->getPathlength(); |
1543 | locSCHitMatchParams->dDeltaPhiToHit = scIter->getDeltaphi(); |
1544 | |
1545 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], locSCHits[locHitIndex], std::const_pointer_cast<const DSCHitMatchParams>(locSCHitMatchParams)); |
1546 | } |
1547 | |
1548 | const hddm_r::TofMatchParamsList &tofList = iter->getTofMatchParamses(); |
1549 | hddm_r::TofMatchParamsList::iterator tofIter = tofList.begin(); |
1550 | for(; tofIter != tofList.end(); ++tofIter) |
1551 | { |
1552 | size_t locHitIndex = tofIter->getHit(); |
1553 | size_t locTrackIndex = tofIter->getTrack(); |
1554 | |
1555 | auto locTOFHitMatchParams = std::make_shared<DTOFHitMatchParams>(); |
1556 | locTOFHitMatchParams->dTOFPoint = locTOFPoints[locHitIndex]; |
1557 | |
1558 | locTOFHitMatchParams->dHitTime = tofIter->getThit(); |
1559 | locTOFHitMatchParams->dHitTimeVariance = tofIter->getThitvar(); |
1560 | locTOFHitMatchParams->dHitEnergy = tofIter->getEhit(); |
1561 | |
1562 | locTOFHitMatchParams->dEdx = tofIter->getDEdx(); |
1563 | locTOFHitMatchParams->dFlightTime = tofIter->getTflight(); |
1564 | locTOFHitMatchParams->dFlightTimeVariance = tofIter->getTflightvar(); |
1565 | locTOFHitMatchParams->dPathLength = tofIter->getPathlength(); |
1566 | locTOFHitMatchParams->dDeltaXToHit = tofIter->getDeltax(); |
1567 | locTOFHitMatchParams->dDeltaYToHit = tofIter->getDeltay(); |
1568 | |
1569 | locDetectorMatches->Add_Match(locTrackTimeBasedVector[locTrackIndex], locTOFPoints[locHitIndex], std::const_pointer_cast<const DTOFHitMatchParams>(locTOFHitMatchParams)); |
1570 | |
1571 | // dE/dx per plane |
1572 | const hddm_r::TofDedxList& locTofDedxList = tofIter->getTofDedxs(); |
1573 | hddm_r::TofDedxList::iterator locTofDedxIterator = locTofDedxList.begin(); |
1574 | if(locTofDedxIterator == locTofDedxList.end()) |
1575 | { |
1576 | locTOFHitMatchParams->dEdx1 = 0.; |
1577 | locTOFHitMatchParams->dEdx2 = 0.; |
1578 | } |
1579 | else //should only be 1 |
1580 | { |
1581 | for(; locTofDedxIterator != locTofDedxList.end(); ++locTofDedxIterator) |
1582 | { |
1583 | locTOFHitMatchParams->dEdx1 = locTofDedxIterator->getDEdx1(); |
1584 | locTOFHitMatchParams->dEdx2 = locTofDedxIterator->getDEdx2(); |
1585 | } |
1586 | } |
1587 | |
1588 | } |
1589 | |
1590 | const hddm_r::BcalDOCAtoTrackList &bcaldocaList = iter->getBcalDOCAtoTracks(); |
1591 | hddm_r::BcalDOCAtoTrackList::iterator bcaldocaIter = bcaldocaList.begin(); |
1592 | for(; bcaldocaIter != bcaldocaList.end(); ++bcaldocaIter) |
1593 | { |
1594 | size_t locShowerIndex = bcaldocaIter->getShower(); |
1595 | double locDeltaPhi = bcaldocaIter->getDeltaphi(); |
1596 | double locDeltaZ = bcaldocaIter->getDeltaz(); |
1597 | locDetectorMatches->Set_DistanceToNearestTrack(locBCALShowers[locShowerIndex], locDeltaPhi, locDeltaZ); |
1598 | } |
1599 | |
1600 | const hddm_r::FcalDOCAtoTrackList &fcaldocaList = iter->getFcalDOCAtoTracks(); |
1601 | hddm_r::FcalDOCAtoTrackList::iterator fcaldocaIter = fcaldocaList.begin(); |
1602 | for(; fcaldocaIter != fcaldocaList.end(); ++fcaldocaIter) |
1603 | { |
1604 | size_t locShowerIndex = fcaldocaIter->getShower(); |
1605 | double locDOCA = fcaldocaIter->getDoca(); |
1606 | locDetectorMatches->Set_DistanceToNearestTrack(locFCALShowers[locShowerIndex], locDOCA); |
1607 | } |
1608 | |
1609 | const hddm_r::TflightPCorrelationList &correlationList = iter->getTflightPCorrelations(); |
1610 | hddm_r::TflightPCorrelationList::iterator correlationIter = correlationList.begin(); |
1611 | for(; correlationIter != correlationList.end(); ++correlationIter) |
1612 | { |
1613 | size_t locTrackIndex = correlationIter->getTrack(); |
1614 | DetectorSystem_t locDetectorSystem = (DetectorSystem_t)correlationIter->getSystem(); |
1615 | double locCorrelation = correlationIter->getCorrelation(); |
1616 | locDetectorMatches->Set_FlightTimePCorrelation(locTrackTimeBasedVector[locTrackIndex], locDetectorSystem, locCorrelation); |
1617 | } |
1618 | |
1619 | data.push_back(locDetectorMatches); |
1620 | } |
1621 | |
1622 | // Copy data to factory |
1623 | factory->CopyTo(data); |
1624 | |
1625 | return NOERROR; |
1626 | } |
1627 | |
1628 | // Transform the 5x5 tracking error matrix into a 7x7 error matrix in cartesian |
1629 | // coordinates. |
1630 | // This was copied and transformed from DKinFit.cc |
1631 | void DEventSourceREST::Get7x7ErrorMatrix(double mass, const double vec[5], const TMatrixFSym* C5x5, TMatrixFSym* loc7x7ErrorMatrix) |
1632 | { |
1633 | TMatrixF J(7,5); |
1634 | |
1635 | // State vector |
1636 | double q_over_pt=vec[0]; |
1637 | double phi=vec[1]; |
1638 | double tanl=vec[2]; |
1639 | double D=vec[3]; |
1640 | |
1641 | double pt=1./fabs(q_over_pt); |
1642 | double pt_sq=pt*pt; |
1643 | double cosphi=cos(phi); |
1644 | double sinphi=sin(phi); |
1645 | double q=(q_over_pt>0)?1.:-1.; |
1646 | |
1647 | J(0, 0)=-q*pt_sq*cosphi; |
1648 | J(0, 1)=-pt*sinphi; |
1649 | |
1650 | J(1, 0)=-q*pt_sq*sinphi; |
1651 | J(1, 1)=pt*cosphi; |
1652 | |
1653 | J(2, 0)=-q*pt_sq*tanl; |
1654 | J(2, 2)=pt; |
1655 | |
1656 | J(3, 1)=-D*cosphi; |
1657 | J(3, 3)=-sinphi; |
1658 | |
1659 | J(4, 1)=-D*sinphi; |
1660 | J(4, 3)=cosphi; |
1661 | |
1662 | J(5, 4)=1.; |
1663 | |
1664 | // C'= JCJ^T |
1665 | TMatrixFSym locTempMatrix(*C5x5); |
1666 | *loc7x7ErrorMatrix=locTempMatrix.Similarity(J); |
1667 | } |
1668 | |
1669 | uint32_t DEventSourceREST::Convert_SignedIntToUnsigned(int32_t locSignedInt) const |
1670 | { |
1671 | //Convert uint32_t to int32_t |
1672 | //Reverse scheme (from DEventWriterREST): |
1673 | //If is >= 0, then the int32_t is the same as the uint32_t (last bit not set) |
1674 | //If is the minimum int: bit 32 is 1, and all of the other bits are zero |
1675 | //Else, bit 32 is 1, then the uint32_t is -1 * int32_t, + add the last bit |
1676 | if(locSignedInt >= 0) |
1677 | return uint32_t(locSignedInt); //bit 32 is zero |
1678 | else if(locSignedInt == numeric_limits<int32_t>::min()) // -(2^31) |
1679 | return uint32_t(0x80000000); //bit 32 is 1, all others are 0 |
1680 | return uint32_t(-1*locSignedInt) + uint32_t(0x80000000); //bit 32 is 1, all others are negative of signed int (which was negative) |
1681 | } |
1682 | |
1683 | //----------------------- |
1684 | // Extract_DDIRCPmtHit |
1685 | //----------------------- |
1686 | jerror_t DEventSourceREST::Extract_DDIRCPmtHit(hddm_r::HDDM *record, |
1687 | JFactory<DDIRCPmtHit>* factory, JEventLoop* locEventLoop) |
1688 | { |
1689 | /// Copies the data from the fcalShower hddm record. This is |
1690 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
1691 | /// returns OBJECT_NOT_AVAILABLE immediately. |
1692 | |
1693 | if (factory==NULL__null) { |
1694 | return OBJECT_NOT_AVAILABLE; |
1695 | } |
1696 | string tag = (factory->Tag())? factory->Tag() : ""; |
1697 | |
1698 | vector<DDIRCPmtHit*> data; |
1699 | |
1700 | // loop over fcal shower records |
1701 | const hddm_r::DircHitList &hits = |
1702 | record->getDircHits(); |
1703 | hddm_r::DircHitList::iterator iter; |
1704 | for (iter = hits.begin(); iter != hits.end(); ++iter) { |
1705 | if (iter->getJtag() != tag) |
1706 | continue; |
1707 | |
1708 | // throw away hits from bad or noisy channels (after REST reconstruction) |
1709 | int locRunNumber = locEventLoop->GetJEvent().GetRunNumber(); |
1710 | int box = (iter->getCh() < dDIRCMaxChannels) ? 1 : 0; |
1711 | int channel = iter->getCh() % dDIRCMaxChannels; |
1712 | dirc_status_state status = static_cast<dirc_status_state>(dDIRCChannelStatusMap[locRunNumber][box][channel]); |
1713 | if ( (status==BAD) || (status==NOISY) ) { |
1714 | continue; |
1715 | } |
1716 | |
1717 | DDIRCPmtHit *hit = new DDIRCPmtHit(); |
1718 | hit->setChannel(iter->getCh()); |
1719 | hit->setTime(iter->getT()); |
1720 | hit->setTOT(iter->getTot()); |
1721 | |
1722 | data.push_back(hit); |
1723 | } |
1724 | |
1725 | // Copy into factory |
1726 | factory->CopyTo(data); |
1727 | |
1728 | return NOERROR; |
1729 | } |
1730 | |
1731 | //---------------------------- |
1732 | // Extract_DEventHitStatistics |
1733 | //---------------------------- |
1734 | jerror_t DEventSourceREST::Extract_DEventHitStatistics(hddm_r::HDDM *record, |
1735 | JFactory<DEventHitStatistics>* factory) |
1736 | { |
1737 | /// Copies the data from the hitStatistics hddm record. This is |
1738 | /// call from JEventSourceREST::GetObjects. If factory is NULL, this |
1739 | /// returns OBJECT_NOT_AVAILABLE immediately. |
1740 | |
1741 | if (factory==NULL__null) { |
1742 | return OBJECT_NOT_AVAILABLE; |
1743 | } |
1744 | string tag = (factory->Tag())? factory->Tag() : ""; |
1745 | |
1746 | vector<DEventHitStatistics*> data; |
1747 | |
1748 | hddm_r::HitStatisticsList slist = (hddm_r::HitStatisticsList)record->getHitStatisticses(); |
1749 | if (slist.size() != 0 && slist().getJtag() == tag) { |
1750 | DEventHitStatistics *stats = new DEventHitStatistics; |
1751 | hddm_r::StartCountersList starts = slist().getStartCounterses(); |
1752 | stats->start_counters = (starts.size() > 0)? starts().getCount() : 0; |
1753 | hddm_r::CdcStrawsList straws = slist().getCdcStrawses(); |
1754 | stats->cdc_straws = (straws.size() > 0)? straws().getCount() : 0; |
1755 | hddm_r::FdcPseudosList pseudos = slist().getFdcPseudoses(); |
1756 | stats->fdc_pseudos = (pseudos.size() > 0)? pseudos().getCount() : 0; |
1757 | hddm_r::BcalCellsList cells = slist().getBcalCellses(); |
1758 | stats->bcal_cells = (cells.size() > 0)? cells().getCount() : 0; |
1759 | hddm_r::FcalBlocksList blocks = slist().getFcalBlockses(); |
1760 | stats->fcal_blocks = (blocks.size() > 0)? blocks().getCount() : 0; |
1761 | hddm_r::CcalBlocksList bloccs = slist().getCcalBlockses(); |
1762 | stats->ccal_blocks = (bloccs.size() > 0)? bloccs().getCount() : 0; |
1763 | hddm_r::TofPaddlesList paddles = slist().getTofPaddleses(); |
1764 | stats->tof_paddles = (paddles.size() > 0)? paddles().getCount() : 0; |
1765 | hddm_r::DircPMTsList pmts = slist().getDircPMTses(); |
1766 | stats->dirc_PMTs = (pmts.size() > 0)? pmts().getCount() : 0; |
1767 | |
1768 | data.push_back(stats); |
1769 | } |
1770 | |
1771 | // Copy into factory |
1772 | factory->CopyTo(data); |
1773 | |
1774 | return NOERROR; |
1775 | } |