Bug Summary

File:/volatile/halld/gluex/nightly/2024-05-01/Linux_CentOS7.7-x86_64-gcc4.8.5/halld_recon/src/libraries/HDDM/DEventSourceHDDM.cc
Location:line 1257, column 13
Description:Value stored to 'mass' is never read

Annotated Source Code

1// $Id: DEventSourceHDDM.cc 19023 2015-07-14 20:23:27Z beattite $
2//
3// Author: David Lawrence June 24, 2004
4//
5// changes: Wed Jun 20 17:08:13 EDT 2007 B. Zihlmann
6// modify TOF section to add several new variables incuding the
7// GEANT particle type to the Truth hits and the hit and track-hit
8// list.
9//
10// Oct 3, 2012 Yi Qiang: add functions for Cherenkov RICH detector
11// Oct 11, 2012 Yi Qiang: complete functions for Cherenkov detector
12// Oct 8, 2013 Yi Qiang: added dedicated object for RICH Truth Hit
13// July 5, 2014 R.T.Jones: changed over from c to c++ API for hddm
14// June 22, 2015 J. Stevens: changed RICH -> DIRC and remove CERE
15// May 7, 2017 R. Dzhygadlo: added DDIRCTruthPmtHit DDIRCTruthBarHit
16// Oct 20, 2017 A. Somov: Added fields for the DPSHit/DPSCHit
17// Jan 16, 2024 A. Somov: Added functions for ECAL
18//
19// DEventSourceHDDM methods
20//
21
22#include <iostream>
23#include <iomanip>
24#include <cmath>
25using namespace std;
26
27#include <JANA/JFactory_base.h>
28#include <JANA/JEventLoop.h>
29#include <JANA/JEvent.h>
30#include <DANA/DStatusBits.h>
31
32#include <JANA/JGeometryXML.h>
33#include "BCAL/DBCALGeometry.h"
34#include "PAIR_SPECTROMETER/DPSGeometry.h"
35
36#include <DVector2.h>
37#include <DEventSourceHDDM.h>
38#include <FDC/DFDCGeometry.h>
39#include <FCAL/DFCALGeometry.h>
40#include <FCAL/DFCALHit.h>
41#include <CCAL/DCCALGeometry.h>
42#include <CCAL/DCCALHit.h>
43#include <ECAL/DECALGeometry.h>
44#include <ECAL/DECALHit.h>
45
46
47//------------------------------------------------------------------
48// Binary predicate used to sort hits
49//------------------------------------------------------------------
50class MCTrackHitSort{
51 public:
52 bool operator()(DMCTrackHit* const &thit1,
53 DMCTrackHit* const &thit2) const {
54 return thit1->z < thit2->z;
55 }
56};
57
58bool MCTrackHitSort_C(DMCTrackHit* const &thit1,
59 DMCTrackHit* const &thit2) {
60 return thit1->z < thit2->z;
61}
62
63
64//----------------
65// Constructor
66//----------------
67DEventSourceHDDM::DEventSourceHDDM(const char* source_name)
68: JEventSource(source_name)
69{
70 /// Constructor for DEventSourceHDDM object
71 ifs = new ifstream(source_name);
72 ifs->get();
73 ifs->unget();
74 if (ifs->rdbuf()->in_avail() > 30) {
75 class nonstd_streambuf: public std::streambuf {
76 public: char *pub_gptr() {return gptr();}
77 };
78 void *buf = (void*)ifs->rdbuf();
79 std::string head(((nonstd_streambuf*)buf)->pub_gptr(), 30);
80 std::string expected = " class=\"s\" ";
81 std::string also_supported = " class=\"mc_s\" ";
82 if (head.find(expected) == head.npos &&
83 head.find(also_supported) == head.npos)
84 {
85 std::string msg("Unexpected header found in input HDDM stream: ");
86 throw std::runtime_error(msg + head + source_name);
87 }
88 }
89
90 fin = new hddm_s::istream(*ifs);
91 initialized = false;
92 dapp = NULL__null;
93 bfield = NULL__null;
94 geom = NULL__null;
95
96 dRunNumber = -1;
97
98 if( (!gPARMS->Exists("JANA_CALIB_CONTEXT")) && (getenv("JANA_CALIB_CONTEXT")==NULL__null) ){
99 cout << "============================================================" << endl;
100 cout << " WARNING: JANA_CALIB_CONTEXT not set. " << endl;
101 cout << "You are reading from an HDDM file which is most likely" << endl;
102 cout << "MC data. In most cases, you will want to set this parameter" << endl;
103 cout << "to get proper reconstruction." << endl;
104 cout << "(usually something like \"variation=mc\")" << endl;
105 cout << "============================================================" << endl;
106 }
107}
108
109//----------------
110// Destructor
111//----------------
112DEventSourceHDDM::~DEventSourceHDDM()
113{
114 if (fin)
115 delete fin;
116 if (ifs)
117 delete ifs;
118}
119
120//----------------
121// GetEvent
122//----------------
123jerror_t DEventSourceHDDM::GetEvent(JEvent &event)
124{
125 /// Implementation of JEventSource virtual function
126
127 if (!fin)
128 return EVENT_SOURCE_NOT_OPEN;
129
130 // Each open HDDM file takes up about 1M of memory so it's
131 // worthwhile to close it as soon as we can.
132 else if (!ifs->good()) {
133 delete fin;
134 fin = NULL__null;
135 delete ifs;
136 ifs = NULL__null;
137 return NO_MORE_EVENTS_IN_SOURCE;
138 }
139
140 hddm_s::HDDM *record = new hddm_s::HDDM();
141 while (record->getPhysicsEvents().size() == 0) {
142 if (! (*fin >> *record)) {
143 delete fin;
144 fin = NULL__null;
145 delete ifs;
146 ifs = NULL__null;
147 return NO_MORE_EVENTS_IN_SOURCE;
148 }
149 }
150
151 ++Nevents_read;
152
153 int event_number = -1;
154 int run_number = -1;
155
156 if(!record->getPhysicsEvents().empty()) {
157 // Get event/run numbers from HDDM
158 hddm_s::PhysicsEvent &pe = record->getPhysicsEvent(0);
159 event_number = pe.getEventNo();
160 run_number = pe.getRunNo();
161 }
162
163 // Copy the reference info into the JEvent object
164 event.SetJEventSource(this);
165 event.SetEventNumber(event_number);
166 event.SetRunNumber(run_number);
167 event.SetRef(record);
168 event.SetStatusBit(kSTATUS_HDDM);
169 event.SetStatusBit(kSTATUS_FROM_FILE);
170 event.SetStatusBit(kSTATUS_PHYSICS_EVENT);
171
172 return NOERROR;
173}
174
175//----------------
176// FreeEvent
177//----------------
178void DEventSourceHDDM::FreeEvent(JEvent &event)
179{
180 hddm_s::HDDM *record = (hddm_s::HDDM*)event.GetRef();
181 delete record;
182}
183
184//----------------
185// GetObjects
186//----------------
187jerror_t DEventSourceHDDM::GetObjects(JEvent &event, JFactory_base *factory)
188{
189 /// This gets called through the virtual method of the
190 /// JEventSource base class. It creates the objects of the type
191 /// on which factory is based. It uses the hddm_s::HDDM* object
192 /// kept in the ref field of the JEvent object passed.
193
194 // We must have a factory to hold the data
195 if (!factory)
196 throw RESOURCE_UNAVAILABLE;
197
198 // HDDM doesn't exactly support tagged factories, but the tag
199 // can be used to direct filling of the correct factory.
200 string tag = (factory->Tag()==NULL__null)? "" : factory->Tag();
201
202 // The ref field of the JEvent is just the HDDM object pointer.
203 hddm_s::HDDM *record = (hddm_s::HDDM*)event.GetRef();
204 if (!record)
205 throw RESOURCE_UNAVAILABLE;
206
207 // Get pointer to the B-field object and Geometry object
208 JEventLoop *loop = event.GetJEventLoop();
209 if (initialized == false && loop) {
210 initialized = true;
211 dRunNumber = event.GetRunNumber();
212 dapp = dynamic_cast<DApplication*>(loop->GetJApplication());
213 if (dapp) {
214 jcalib = dapp->GetJCalibration(event.GetRunNumber());
215 // Make sure jcalib is set
216 if (!jcalib) {
217 _DBG_std::cerr<<"libraries/HDDM/DEventSourceHDDM.cc"<<
":"<<217<<" "
<< "ERROR - no jcalib set!" <<endl;
218 return RESOURCE_UNAVAILABLE;
219 }
220 // Get constants and do basic check on number of elements
221 vector< map<string, float> > tvals;
222 if(jcalib->Get("FDC/strip_calib", tvals))
223 throw JException("Could not load CCDB table: FDC/strip_calib");
224
225 if (tvals.size() != 192) {
226 _DBG_std::cerr<<"libraries/HDDM/DEventSourceHDDM.cc"<<
":"<<226<<" "
<< "ERROR - strip calibration vectors are not the right size!"
227 << endl;
228 return VALUE_OUT_OF_RANGE;
229 }
230 map<string,float>::iterator iter;
231 for (iter=tvals[0].begin(); iter!=tvals[0].end(); iter++) {
232 // Copy values into tables. We preserve the order since
233 // that is how it was originally done in hitFDC.c
234 for (unsigned int i=0; i<tvals.size(); i++) {
235 map<string, float> &row = tvals[i];
236 uscale[i]=row["qru"];
237 vscale[i]=row["qrv"];
238 }
239 }
240 }
241 // load BCAL geometry
242 vector<const DBCALGeometry *> BCALGeomVec;
243 loop->Get(BCALGeomVec);
244 if(BCALGeomVec.size() == 0)
245 throw JException("Could not load DBCALGeometry object!");
246 dBCALGeom = BCALGeomVec[0];
247
248 // load PS geometry
249 vector<const DPSGeometry*> psGeomVect;
250 loop->Get(psGeomVect);
251 if (psGeomVect.size() < 1)
252 return OBJECT_NOT_AVAILABLE;
253 psGeom = psGeomVect[0];
254
255
256 }
257
258 // Warning: This class is not completely thread-safe and can fail if running
259 // running in multithreaded mode over files with events from multiple runs
260 // It is expected that simulated data will rarely contain events from multiple
261 // runs, as this is an intermediate format in the simulation chain, so for
262 // now we just insert a sanity check, and push the problem to the future
263 if(dRunNumber != event.GetRunNumber()) {
264 jerr << endl
265 << "WARNING: DEventSourceHDDM cannot currently handle HDDM files containing" << endl
266 << "events with multiple runs! If you encounter this error message," << endl
267 << "please contact the GlueX Offline Software Group: halld-offline@jlab.org" << endl
268 << endl;
269 exit(-1);
270 }
271
272 //Get target center
273 //multiple reader threads can access this object: need lock
274 bool locNewRunNumber = false;
275 unsigned int locRunNumber = event.GetRunNumber();
276 LockRead();
277 {
278 locNewRunNumber = (dTargetCenterZMap.find(locRunNumber) == dTargetCenterZMap.end());
279 }
280 UnlockRead();
281 if(locNewRunNumber)
282 {
283 DApplication* dapp = dynamic_cast<DApplication*>(loop->GetJApplication());
284 DGeometry* locGeometry = dapp->GetDGeometry(loop->GetJEvent().GetRunNumber());
285 double locTargetCenterZ = 0.0;
286 locGeometry->GetTargetZ(locTargetCenterZ);
287
288 JGeometryXML *jgeom = dynamic_cast<JGeometryXML *>(locGeometry);
289 hddm_s::GeometryList geolist = record->getGeometrys();
290 if (jgeom != 0 && geolist.size() > 0) {
291 std::string md5sim = geolist(0).getMd5simulation();
292 std::string md5smear = geolist(0).getMd5smear();
293 std::string md5recon = jgeom->GetChecksum();
294 geolist(0).setMd5reconstruction(md5recon);
295 if (md5sim != md5smear) {
296 jerr << std::endl
297 << "WARNING: simulation geometry checksum does not match"
298 << " that shown for the mcsmear step."
299 << std::endl;
300 }
301 else if (md5sim != md5recon) {
302 jerr << endl
303 << "WARNING: simulation geometry checksum does not match"
304 << " the geometry being used for reconstruction."
305 << std::endl;
306 }
307 }
308
309 vector<double> locBeamPeriodVector;
310 if(loop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector))
311 throw runtime_error("Could not load CCDB table: PHOTON_BEAM/RF/beam_period");
312 double locBeamBunchPeriod = locBeamPeriodVector[0];
313
314 LockRead();
315 {
316 dTargetCenterZMap[locRunNumber] = locTargetCenterZ;
317 dBeamBunchPeriodMap[locRunNumber] = locBeamBunchPeriod;
318 }
319 UnlockRead();
320 }
321
322 // Get name of data class we're trying to extract
323 string dataClassName = factory->GetDataClassName();
324
325 if (dataClassName == "DPSHit")
326 return Extract_DPSHit(record,
327 dynamic_cast<JFactory<DPSHit>*>(factory), tag);
328
329 if (dataClassName == "DPSTruthHit")
330 return Extract_DPSTruthHit(record,
331 dynamic_cast<JFactory<DPSTruthHit>*>(factory), tag);
332
333 if (dataClassName == "DPSCHit")
334 return Extract_DPSCHit(record,
335 dynamic_cast<JFactory<DPSCHit>*>(factory), tag);
336
337 if (dataClassName == "DPSCTruthHit")
338 return Extract_DPSCTruthHit(record,
339 dynamic_cast<JFactory<DPSCTruthHit>*>(factory), tag);
340
341 if (dataClassName == "DRFTime")
342 return Extract_DRFTime(record,
343 dynamic_cast<JFactory<DRFTime>*>(factory), loop);
344
345 if (dataClassName == "DTAGMHit")
346 return Extract_DTAGMHit(record,
347 dynamic_cast<JFactory<DTAGMHit>*>(factory), tag);
348
349 if (dataClassName == "DTAGHHit")
350 return Extract_DTAGHHit(record,
351 dynamic_cast<JFactory<DTAGHHit>*>(factory), tag);
352
353 if (dataClassName == "DMCTrackHit")
354 return Extract_DMCTrackHit(record,
355 dynamic_cast<JFactory<DMCTrackHit>*>(factory), tag);
356
357 if (dataClassName == "DMCReaction")
358 return Extract_DMCReaction(record,
359 dynamic_cast<JFactory<DMCReaction>*>(factory), tag, loop);
360
361 if (dataClassName == "DMCThrown")
362 return Extract_DMCThrown(record,
363 dynamic_cast<JFactory<DMCThrown>*>(factory), tag);
364
365 if (dataClassName == "DBCALTruthShower")
366 return Extract_DBCALTruthShower(record,
367 dynamic_cast<JFactory<DBCALTruthShower>*>(factory), tag);
368
369 if (dataClassName == "DBCALSiPMSpectrum")
370 return Extract_DBCALSiPMSpectrum(record,
371 dynamic_cast<JFactory<DBCALSiPMSpectrum>*>(factory), tag);
372
373 if (dataClassName == "DBCALTruthCell")
374 return Extract_DBCALTruthCell(record,
375 dynamic_cast<JFactory<DBCALTruthCell>*>(factory), tag);
376
377 if (dataClassName == "DBCALSiPMHit")
378 return Extract_DBCALSiPMHit(record,
379 dynamic_cast<JFactory<DBCALSiPMHit>*>(factory), tag);
380
381 if (dataClassName == "DBCALDigiHit")
382 return Extract_DBCALDigiHit(record,
383 dynamic_cast<JFactory<DBCALDigiHit>*>(factory), tag);
384
385 if (dataClassName == "DBCALIncidentParticle")
386 return Extract_DBCALIncidentParticle(record,
387 dynamic_cast<JFactory<DBCALIncidentParticle>*>(factory), tag);
388
389 if (dataClassName == "DBCALTDCDigiHit")
390 return Extract_DBCALTDCDigiHit(record,
391 dynamic_cast<JFactory<DBCALTDCDigiHit>*>(factory), tag);
392
393 if (dataClassName == "DCDCHit")
394 return Extract_DCDCHit(loop, record,
395 dynamic_cast<JFactory<DCDCHit>*>(factory) , tag);
396
397 if (dataClassName == "DFDCHit")
398 return Extract_DFDCHit(record,
399 dynamic_cast<JFactory<DFDCHit>*>(factory), tag);
400
401 if (dataClassName == "DFCALTruthShower")
402 return Extract_DFCALTruthShower(record,
403 dynamic_cast<JFactory<DFCALTruthShower>*>(factory), tag);
404
405 if (dataClassName == "DFCALHit")
406 return Extract_DFCALHit(record,
407 dynamic_cast<JFactory<DFCALHit>*>(factory), tag,
408 event.GetJEventLoop());
409
410 if (dataClassName == "DECALTruthShower")
411 return Extract_DECALTruthShower(record,
412 dynamic_cast<JFactory<DECALTruthShower>*>(factory), tag);
413
414 if (dataClassName == "DECALHit")
415 return Extract_DECALHit(record,
416 dynamic_cast<JFactory<DECALHit>*>(factory), tag,
417 event.GetJEventLoop());
418
419 if (dataClassName == "DCCALTruthShower")
420 return Extract_DCCALTruthShower(record,
421 dynamic_cast<JFactory<DCCALTruthShower>*>(factory), tag);
422
423 if (dataClassName == "DCCALHit")
424 return Extract_DCCALHit(record,
425 dynamic_cast<JFactory<DCCALHit>*>(factory), tag,
426 event.GetJEventLoop());
427
428 if (dataClassName == "DMCTrajectoryPoint" && tag == "")
429 return Extract_DMCTrajectoryPoint(record,
430 dynamic_cast<JFactory<DMCTrajectoryPoint>*>(factory), tag);
431
432 if (dataClassName == "DTOFTruth")
433 return Extract_DTOFTruth(record,
434 dynamic_cast<JFactory<DTOFTruth>*>(factory), tag);
435
436 // TOF is a special case: TWO factories are needed at the same time
437 // DTOFHit and DTOFHitMC
438 if (dataClassName == "DTOFHit") {
439 JFactory_base* factory2 = loop->GetFactory("DTOFHitMC", tag.c_str());
440 return Extract_DTOFHit(record,
441 dynamic_cast<JFactory<DTOFHit>*>(factory),
442 dynamic_cast<JFactory<DTOFHitMC>*>(factory2), tag);
443 }
444 if (dataClassName == "DTOFHitMC") {
445 JFactory_base* factory2 = loop->GetFactory("DTOFHit", tag.c_str());
446 return Extract_DTOFHit(record,
447 dynamic_cast<JFactory<DTOFHit>*>(factory2),
448 dynamic_cast<JFactory<DTOFHitMC>*>(factory), tag);
449 }
450
451 if (dataClassName == "DSCHit")
452 return Extract_DSCHit(record,
453 dynamic_cast<JFactory<DSCHit>*>(factory), tag);
454
455 if (dataClassName == "DSCTruthHit")
456 return Extract_DSCTruthHit(record,
457 dynamic_cast<JFactory<DSCTruthHit>*>(factory), tag);
458
459 if (dataClassName == "DFMWPCTruthHit")
460 return Extract_DFMWPCTruthHit(record,
461 dynamic_cast<JFactory<DFMWPCTruthHit>*>(factory), tag);
462
463 if (dataClassName == "DFMWPCTruth")
464 return Extract_DFMWPCTruth(record,
465 dynamic_cast<JFactory<DFMWPCTruth>*>(factory), tag);
466
467 if (dataClassName == "DFMWPCHit")
468 return Extract_DFMWPCHit(record,
469 dynamic_cast<JFactory<DFMWPCHit>*>(factory), tag);
470
471 if (dataClassName == "DCTOFTruth")
472 return Extract_DCTOFTruth(record,
473 dynamic_cast<JFactory<DCTOFTruth>*>(factory), tag);
474
475 if (dataClassName == "DCTOFHit")
476 return Extract_DCTOFHit(record,
477 dynamic_cast<JFactory<DCTOFHit>*>(factory), tag);
478
479 if (dataClassName == "DDIRCTruthBarHit")
480 return Extract_DDIRCTruthBarHit(record,
481 dynamic_cast<JFactory<DDIRCTruthBarHit>*>(factory), tag);
482
483 if (dataClassName == "DDIRCTruthPmtHit")
484 return Extract_DDIRCTruthPmtHit(record,
485 dynamic_cast<JFactory<DDIRCTruthPmtHit>*>(factory), tag);
486
487 if (dataClassName == "DDIRCPmtHit")
488 return Extract_DDIRCPmtHit(record,
489 dynamic_cast<JFactory<DDIRCPmtHit>*>(factory), tag, event.GetJEventLoop());
490
491 // extract CereTruth and CereRichHit hits, yqiang Oct 3, 2012
492 // removed CereTruth (merged into MCThrown), added CereHit, yqiang Oct 10 2012
493 if (dataClassName == "DCereHit")
494 return Extract_DCereHit(record,
495 dynamic_cast<JFactory<DCereHit>*>(factory), tag);
496
497 if (dataClassName == "DTPOLHit")
498 return Extract_DTPOLHit(record,
499 dynamic_cast<JFactory<DTPOLHit>*>(factory), tag);
500
501 if (dataClassName == "DTPOLTruthHit")
502 return Extract_DTPOLTruthHit(record,
503 dynamic_cast<JFactory<DTPOLTruthHit>*>(factory), tag);
504
505 return OBJECT_NOT_AVAILABLE;
506}
507
508//------------------
509// Extract_DRFTime
510//------------------
511jerror_t DEventSourceHDDM::Extract_DRFTime(hddm_s::HDDM *record,
512 JFactory<DRFTime> *factory, JEventLoop* locEventLoop)
513{
514 if (factory==NULL__null)
515 return OBJECT_NOT_AVAILABLE;
516 string tag = (factory->Tag())? factory->Tag() : "";
517
518 vector<DRFTime*> locRFTimes;
519
520 // loop over RF-time records
521 const hddm_s::RFtimeList &rftimes = record->getRFtimes();
522 hddm_s::RFtimeList::iterator iter;
523 for (iter = rftimes.begin(); iter != rftimes.end(); ++iter)
524 {
525 if (iter->getJtag() != tag)
526 continue;
527 DRFTime *locRFTime = new DRFTime;
528 locRFTime->dTime = iter->getTsync();
529 locRFTime->dTimeVariance = 0.0; //SET ME!!
530 locRFTimes.push_back(locRFTime);
531 }
532
533 if(!locRFTimes.empty())
534 {
535 //found in the file, copy into factory and return
536 factory->CopyTo(locRFTimes);
537 return NOERROR;
538 }
539
540 //Not found in the file, so either:
541 //Experimental data & it's missing: bail
542 //MC data: generate it
543
544 vector<const DBeamPhoton*> locMCGENPhotons;
545 locEventLoop->Get(locMCGENPhotons, "MCGEN");
546 if(locMCGENPhotons.empty())
547 return OBJECT_NOT_AVAILABLE; //Experimental data & it's missing: bail
548
549 //Is MC data. Either:
550 //No tag: return t = 0.0, but true t is 0.0 +/- n*locBeamBunchPeriod: must select the correct beam bunch
551 //TRUTH tag: get exact t from DBeamPhoton tag MCGEN
552
553 if(tag == "TRUTH")
554 {
555 DRFTime *locRFTime = new DRFTime;
556 locRFTime->dTime = locMCGENPhotons[0]->time();
557 locRFTime->dTimeVariance = 0.0;
558 locRFTimes.push_back(locRFTime);
559 }
560 else
561 {
562 double locBeamBunchPeriod = 0.0;
563 int locRunNumber = locEventLoop->GetJEvent().GetRunNumber();
564 LockRead();
565 {
566 locBeamBunchPeriod = dBeamBunchPeriodMap[locRunNumber];
567 }
568 UnlockRead();
569
570 //start with true RF time, increment/decrement by multiples of locBeamBunchPeriod ns until closest to 0
571 double locTime = locMCGENPhotons[0]->time();
572 int locNumRFBuckets = int(locTime/locBeamBunchPeriod);
573 locTime -= double(locNumRFBuckets)*locBeamBunchPeriod;
574 while(locTime > 0.5*locBeamBunchPeriod)
575 locTime -= locBeamBunchPeriod;
576 while(locTime < -0.5*locBeamBunchPeriod)
577 locTime += locBeamBunchPeriod;
578
579 DRFTime *locRFTime = new DRFTime;
580 locRFTime->dTime = locTime;
581 locRFTime->dTimeVariance = 0.0;
582 locRFTimes.push_back(locRFTime);
583 }
584
585 // Copy into factories
586 factory->CopyTo(locRFTimes);
587
588 return NOERROR;
589}
590
591//------------------
592// Extract_DMCTrackHit
593//------------------
594jerror_t DEventSourceHDDM::Extract_DMCTrackHit(hddm_s::HDDM *record,
595 JFactory<DMCTrackHit> *factory, string tag)
596{
597 /// Copies the data from the given hddm_s structure. This is called
598 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
599 /// returns OBJECT_NOT_AVAILABLE immediately.
600
601 if (factory == NULL__null)
602 return OBJECT_NOT_AVAILABLE;
603 if (tag != "")
604 return OBJECT_NOT_AVAILABLE;
605
606 // The following routines will create DMCTrackHit objects and add them
607 // to data.
608 vector<DMCTrackHit*> data;
609 GetCDCTruthHits(record, data);
610 GetFDCTruthHits(record, data);
611 GetBCALTruthHits(record, data);
612 GetTOFTruthHits(record, data);
613 GetCherenkovTruthHits(record, data);
614 GetFCALTruthHits(record, data);
615 GetECALTruthHits(record, data);
616 GetSCTruthHits(record, data);
617
618 // It has happened that some CDC hits have "nan" for the drift time
619 // in a peculiar event Alex Somov came across. This ultimately caused
620 // a seg. fault in MCTrackHitSort_C. I hate doing this since it
621 // is treating the symptom rather than the cause, but nonetheless,
622 // it patches up the problem for now until there is time to revisit
623 // it later.
624 for (unsigned int i=0; i < data.size(); i++)
625 if (!isfinite(data[i]->z))
626 data[i]->z = -1000.0;
627
628 // sort hits by z
629 sort(data.begin(), data.end(), MCTrackHitSort_C);
630
631 // Some systems will use negative phis. Force them all to
632 // be in the 0 to 2pi range
633 for (unsigned int i=0; i < data.size(); i++) {
634 DMCTrackHit *mctrackhit = data[i];
635 if (mctrackhit->phi < 0.0)
636 mctrackhit->phi += 2.0*M_PI3.14159265358979323846;
637 }
638
639 // Copy into factory
640 factory->CopyTo(data);
641
642 return NOERROR;
643}
644
645//-------------------
646// GetCDCTruthHits
647//-------------------
648jerror_t DEventSourceHDDM::GetCDCTruthHits(hddm_s::HDDM *record,
649 vector<DMCTrackHit*>& data)
650{
651 const hddm_s::CdcTruthPointList &points = record->getCdcTruthPoints();
652 hddm_s::CdcTruthPointList::iterator iter;
653 for (iter = points.begin(); iter != points.end(); ++iter) {
654 DMCTrackHit *mctrackhit = new DMCTrackHit;
655 mctrackhit->r = iter->getR();
656 mctrackhit->phi = iter->getPhi();
657 mctrackhit->z = iter->getZ();
658 mctrackhit->track = iter->getTrack();
659 mctrackhit->primary = iter->getPrimary();
660 mctrackhit->ptype = iter->getPtype();
661 mctrackhit->system = SYS_CDC;
662 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
663 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
664 data.push_back(mctrackhit);
665 }
666
667 return NOERROR;
668}
669
670//-------------------
671// GetFDCTruthHits
672//-------------------
673jerror_t DEventSourceHDDM::GetFDCTruthHits(hddm_s::HDDM *record,
674 vector<DMCTrackHit*>& data)
675{
676 const hddm_s::FdcTruthPointList &points = record->getFdcTruthPoints();
677 hddm_s::FdcTruthPointList::iterator iter;
678 for (iter = points.begin(); iter != points.end(); ++iter) {
679 float x = iter->getX();
680 float y = iter->getY();
681 DMCTrackHit *mctrackhit = new DMCTrackHit;
682 mctrackhit->r = sqrt(x*x + y*y);
683 mctrackhit->phi = atan2(y,x);
684 mctrackhit->z = iter->getZ();
685 mctrackhit->track = iter->getTrack();
686 mctrackhit->primary = iter->getPrimary();
687 mctrackhit->ptype = iter->getPtype();
688 mctrackhit->system = SYS_FDC;
689 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
690 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
691 data.push_back(mctrackhit);
692 }
693
694 return NOERROR;
695}
696
697//-------------------
698// GetBCALTruthHits
699//-------------------
700jerror_t DEventSourceHDDM::GetBCALTruthHits(hddm_s::HDDM *record,
701 vector<DMCTrackHit*>& data)
702{
703 const hddm_s::BcalTruthShowerList &showers = record->getBcalTruthShowers();
704 hddm_s::BcalTruthShowerList::iterator iter;
705 for (iter = showers.begin(); iter != showers.end(); ++iter) {
706 DMCTrackHit *mctrackhit = new DMCTrackHit;
707 mctrackhit->r = iter->getR();
708 mctrackhit->phi = iter->getPhi();
709 mctrackhit->z = iter->getZ();
710 mctrackhit->track = iter->getTrack();
711 mctrackhit->primary = iter->getPrimary();
712 mctrackhit->ptype = iter->getPtype();
713 mctrackhit->system = SYS_BCAL;
714 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
715 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
716 data.push_back(mctrackhit);
717 }
718
719 return NOERROR;
720}
721
722//-------------------
723// GetTOFTruthHits
724//-------------------
725jerror_t DEventSourceHDDM::GetTOFTruthHits(hddm_s::HDDM *record,
726 vector<DMCTrackHit*>& data)
727{
728 const hddm_s::FtofTruthPointList &points = record->getFtofTruthPoints();
729 hddm_s::FtofTruthPointList::iterator iter;
730 for (iter = points.begin(); iter != points.end(); ++iter) {
731 float x = iter->getX();
732 float y = iter->getY();
733 DMCTrackHit *mctrackhit = new DMCTrackHit;
734 mctrackhit->r = sqrt(x*x + y*y);
735 mctrackhit->phi = atan2(y,x);
736 mctrackhit->z = iter->getZ();
737 mctrackhit->track = iter->getTrack();
738 mctrackhit->primary = iter->getPrimary();
739 mctrackhit->ptype = iter->getPtype(); // save GEANT particle type
740 mctrackhit->system = SYS_TOF;
741 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
742 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
743 data.push_back(mctrackhit);
744 }
745
746 return NOERROR;
747}
748
749//-------------------
750// GetCherenkovTruthHits
751// modified by yqiang, Oct 10 2012
752//-------------------
753jerror_t DEventSourceHDDM::GetCherenkovTruthHits(hddm_s::HDDM *record,
754 vector<DMCTrackHit*>& data)
755{
756 const hddm_s::CereTruthPointList &points = record->getCereTruthPoints();
757 hddm_s::CereTruthPointList::iterator iter;
758 for (iter = points.begin(); iter != points.end(); ++iter) {
759 float x = iter->getX();
760 float y = iter->getY();
761 DMCTrackHit *mctrackhit = new DMCTrackHit;
762 mctrackhit->r = sqrt(x*x + y*y);
763 mctrackhit->phi = atan2(y,x);
764 mctrackhit->z = iter->getZ();
765 mctrackhit->track = iter->getTrack();
766 mctrackhit->primary = iter->getPrimary();
767 mctrackhit->ptype = iter->getPtype(); // save GEANT particle typ()e
768 mctrackhit->system = SYS_CHERENKOV;
769 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
770 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
771 data.push_back(mctrackhit);
772 }
773
774 return NOERROR;
775}
776
777//-------------------
778// GetFCALTruthHits
779//-------------------
780jerror_t DEventSourceHDDM::GetFCALTruthHits(hddm_s::HDDM *record,
781 vector<DMCTrackHit*>& data)
782{
783 const hddm_s::FcalTruthShowerList &points = record->getFcalTruthShowers();
784 hddm_s::FcalTruthShowerList::iterator iter;
785 for (iter = points.begin(); iter != points.end(); ++iter) {
786 float x = iter->getX();
787 float y = iter->getY();
788 DMCTrackHit *mctrackhit = new DMCTrackHit;
789 mctrackhit->r = sqrt(x*x + y*y);
790 mctrackhit->phi = atan2(y,x);
791 mctrackhit->z = iter->getZ();
792 mctrackhit->track = iter->getTrack();
793 mctrackhit->primary = iter->getPrimary();
794 mctrackhit->ptype = iter->getPtype();
795 mctrackhit->system = SYS_FCAL;
796 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
797 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
798 data.push_back(mctrackhit);
799 }
800
801 return NOERROR;
802}
803
804//-------------------
805// GetECALTruthHits
806//-------------------
807jerror_t DEventSourceHDDM::GetECALTruthHits(hddm_s::HDDM *record,
808 vector<DMCTrackHit*>& data)
809{
810 const hddm_s::EcalTruthShowerList &points = record->getEcalTruthShowers();
811 hddm_s::EcalTruthShowerList::iterator iter;
812 for (iter = points.begin(); iter != points.end(); ++iter) {
813 float x = iter->getX();
814 float y = iter->getY();
815 DMCTrackHit *mctrackhit = new DMCTrackHit;
816 mctrackhit->r = sqrt(x*x + y*y);
817 mctrackhit->phi = atan2(y,x);
818 mctrackhit->z = iter->getZ();
819 mctrackhit->track = iter->getTrack();
820 mctrackhit->primary = iter->getPrimary();
821 mctrackhit->ptype = iter->getPtype();
822 mctrackhit->system = SYS_ECAL;
823 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
824 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
825 data.push_back(mctrackhit);
826 }
827
828 return NOERROR;
829}
830
831//-------------------
832// GetCCALTruthHits
833//-------------------
834jerror_t DEventSourceHDDM::GetCCALTruthHits(hddm_s::HDDM *record,
835 vector<DMCTrackHit*>& data)
836{
837 const hddm_s::CcalTruthShowerList &points = record->getCcalTruthShowers();
838 hddm_s::CcalTruthShowerList::iterator iter;
839 for (iter = points.begin(); iter != points.end(); ++iter) {
840 float x = iter->getX();
841 float y = iter->getY();
842 DMCTrackHit *mctrackhit = new DMCTrackHit;
843 mctrackhit->r = sqrt(x*x + y*y);
844 mctrackhit->phi = atan2(y,x);
845 mctrackhit->z = iter->getZ();
846 mctrackhit->track = iter->getTrack();
847 mctrackhit->primary = iter->getPrimary();
848 mctrackhit->ptype = iter->getPtype();
849 mctrackhit->system = SYS_CCAL;
850 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
851 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
852 data.push_back(mctrackhit);
853 }
854
855 return NOERROR;
856}
857
858
859//-------------------
860// GetSCTruthHits
861//-------------------
862jerror_t DEventSourceHDDM::GetSCTruthHits(hddm_s::HDDM *record,
863 vector<DMCTrackHit*>& data)
864{
865 const hddm_s::StcTruthPointList &points = record->getStcTruthPoints();
866 hddm_s::StcTruthPointList::iterator iter;
867 for (iter = points.begin(); iter != points.end(); ++iter) {
868 DMCTrackHit *mctrackhit = new DMCTrackHit;
869 mctrackhit->r = iter->getR();
870 mctrackhit->phi = iter->getPhi();
871 mctrackhit->z = iter->getZ();
872 mctrackhit->track = iter->getTrack();
873 mctrackhit->primary = iter->getPrimary();
874 mctrackhit->ptype = iter->getPtype(); // save GEANT particle type
875 mctrackhit->system = SYS_START;
876 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
877 mctrackhit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
878 data.push_back(mctrackhit);
879 }
880
881 return NOERROR;
882}
883
884//------------------
885// Extract_DBCALSiPMHit
886//------------------
887jerror_t DEventSourceHDDM::Extract_DBCALSiPMHit(hddm_s::HDDM *record,
888 JFactory<DBCALSiPMHit> *factory, string tag)
889{
890 /// Copies the data from the given hddm_s structure. This is called
891 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
892 /// returns OBJECT_NOT_AVAILABLE immediately.
893
894 if (factory == NULL__null)
895 return OBJECT_NOT_AVAILABLE;
896 if (tag != "")
897 return OBJECT_NOT_AVAILABLE;
898
899 vector<DBCALSiPMHit*> data;
900
901 const hddm_s::BcalSiPMUpHitList &uphits = record->getBcalSiPMUpHits();
902 hddm_s::BcalSiPMUpHitList::iterator uiter;
903 for (uiter = uphits.begin(); uiter != uphits.end(); ++uiter) {
904 DBCALSiPMHit *response = new DBCALSiPMHit;
905 response->module = uiter->getModule();
906 response->layer = uiter->getLayer();
907 response->sector = uiter->getSector();
908 response->E = uiter->getE();
909 response->t = uiter->getT();
910 response->end = DBCALGeometry::kUpstream;
911 response->cellId = dBCALGeom->cellId(uiter->getModule(),
912 uiter->getLayer(),
913 uiter->getSector());
914 data.push_back(response);
915 }
916
917 const hddm_s::BcalSiPMDownHitList &downhits = record->getBcalSiPMDownHits();
918 hddm_s::BcalSiPMDownHitList::iterator diter;
919 for (diter = downhits.begin(); diter != downhits.end(); ++diter) {
920 DBCALSiPMHit *response = new DBCALSiPMHit;
921 response->module = diter->getModule();
922 response->layer = diter->getLayer();
923 response->sector = diter->getSector();
924 response->E = diter->getE();
925 response->t = diter->getT();
926 response->end = DBCALGeometry::kDownstream;
927 response->cellId = dBCALGeom->cellId(diter->getModule(),
928 diter->getLayer(),
929 diter->getSector());
930 data.push_back(response);
931 }
932
933 // Copy into factory
934 factory->CopyTo(data);
935
936 return NOERROR;
937}
938
939//------------------
940// Extract_DBCALDigiHit
941//------------------
942jerror_t DEventSourceHDDM::Extract_DBCALDigiHit(hddm_s::HDDM *record,
943 JFactory<DBCALDigiHit> *factory, string tag)
944{
945 /// Copies the data from the given hddm_s structure. This is called
946 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
947 /// returns OBJECT_NOT_AVAILABLE immediately.
948
949 if (factory == NULL__null)
950 return OBJECT_NOT_AVAILABLE;
951 if (tag != "")
952 return OBJECT_NOT_AVAILABLE;
953
954 vector<DBCALDigiHit*> data;
955
956 const hddm_s::BcalfADCDigiHitList &digihits = record->getBcalfADCDigiHits();
957 hddm_s::BcalfADCDigiHitList::iterator iter;
958 for (iter = digihits.begin(); iter != digihits.end(); ++iter) {
959 DBCALDigiHit *response = new DBCALDigiHit;
960 response->module = iter->getModule();
961 response->layer = iter->getLayer();
962 response->sector = iter->getSector();
963 response->pulse_integral = (uint32_t)iter->getPulse_integral();
964 response->pulse_peak = 0;
965 if(iter->getBcalfADCPeaks().size() > 0) {
966 response->pulse_peak = iter->getBcalfADCPeak().getPeakAmp();
967 }
968 response->pulse_time = (uint32_t)iter->getPulse_time();
969 response->pedestal = 1;
970 response->QF = 1;
971 response->nsamples_integral = 1;
972 response->nsamples_pedestal = 1;
973 response->datasource = 3;
974 response->end = (iter->getEnd() == 0)? DBCALGeometry::kUpstream :
975 DBCALGeometry::kDownstream;
976 data.push_back(response);
977 }
978
979 // Copy into factory
980 factory->CopyTo(data);
981
982 return NOERROR;
983}
984
985//------------------
986// Extract_DBCALIncidentParticle
987//------------------
988jerror_t DEventSourceHDDM::Extract_DBCALIncidentParticle(hddm_s::HDDM *record,
989 JFactory<DBCALIncidentParticle> *factory,
990 string tag)
991{
992 /// Copies the data from the given hddm_s structure. This is called
993 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
994 /// returns OBJECT_NOT_AVAILABLE immediately.
995
996 if (factory == NULL__null)
997 return OBJECT_NOT_AVAILABLE;
998 if (tag != "")
999 return OBJECT_NOT_AVAILABLE;
1000
1001 vector<DBCALIncidentParticle*> data;
1002
1003 const hddm_s::BcalTruthIncidentParticleList &plist =
1004 record->getBcalTruthIncidentParticles();
1005 hddm_s::BcalTruthIncidentParticleList::iterator iter;
1006 for (iter = plist.begin(); iter != plist.end(); ++iter) {
1007 DBCALIncidentParticle *part = new DBCALIncidentParticle;
1008 part->ptype = iter->getPtype();
1009 part->px = iter->getPx();
1010 part->py = iter->getPy();
1011 part->pz = iter->getPz();
1012 part->x = iter->getX();
1013 part->y = iter->getY();
1014 part->z = iter->getZ();
1015 data.push_back(part);
1016 }
1017
1018 factory->CopyTo(data);
1019
1020 return NOERROR;
1021}
1022
1023//------------------
1024// Extract_DBCALSiPMSpectrum
1025//------------------
1026jerror_t DEventSourceHDDM::Extract_DBCALSiPMSpectrum(hddm_s::HDDM *record,
1027 JFactory<DBCALSiPMSpectrum> *factory,
1028 string tag)
1029{
1030 /// Copies the data from the given hddm_s structure. This is called
1031 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1032 /// returns OBJECT_NOT_AVAILABLE immediately.
1033
1034 if (factory == NULL__null)
1035 return OBJECT_NOT_AVAILABLE;
1036 if (tag != "" && tag != "TRUTH")
1037 return OBJECT_NOT_AVAILABLE;
1038
1039 vector<DBCALSiPMSpectrum*> data;
1040
1041 const hddm_s::BcalSiPMSpectrumList &specs = record->getBcalSiPMSpectrums();
1042 hddm_s::BcalSiPMSpectrumList::iterator iter;
1043 for (iter = specs.begin(); iter != specs.end(); ++iter) {
1044 DBCALSiPMSpectrum *dana_spectrum = new DBCALSiPMSpectrum;
1045 dana_spectrum->module = iter->getModule();
1046 dana_spectrum->layer = iter->getLayer();
1047 dana_spectrum->sector = iter->getSector();
1048 dana_spectrum->end = (iter->getEnd()==0)?
1049 DBCALGeometry::kUpstream :
1050 DBCALGeometry::kDownstream;
1051 if (tag == "")
1052 dana_spectrum->incident_id = 0;
1053 else if (tag == "TRUTH") {
1054 const hddm_s::BcalSiPMTruthList &truths = iter->getBcalSiPMTruths();
1055 if (truths.size() > 0)
1056 dana_spectrum->incident_id = truths.begin()->getIncident_id();
1057 else
1058 dana_spectrum->incident_id = 0;
1059 }
1060
1061 double t = iter->getTstart();
1062 double bin_width = iter->getBin_width();
1063 stringstream ss(iter->getVals());
1064
1065 // Extract values and use them to fill histo
1066 string entry;
1067 while (ss >> entry) {
1068 if (entry[0] == 'X') {
1069 // get rid of the X, the rest of the entry is the number of zeroes to add
1070 stringstream sss(entry.substr(1));
1071 int num_zeros;
1072 sss >> num_zeros;
1073
1074 for(int i=0; i<num_zeros; i++) {
1075 dana_spectrum->spectrum.Fill(t, 0.0);
1076 t += bin_width;
1077 }
1078 } else {
1079 stringstream sss(entry);
1080 double dE;
1081 sss >> dE;
1082 dana_spectrum->spectrum.Fill(t, dE);
1083 t += bin_width;
1084 }
1085 }
1086
1087 data.push_back(dana_spectrum);
1088 }
1089
1090 // Copy into factory
1091 factory->CopyTo(data);
1092
1093 return NOERROR;
1094}
1095
1096//------------------
1097// Extract_DBCALTDCDigiHit
1098//------------------
1099jerror_t DEventSourceHDDM::Extract_DBCALTDCDigiHit(hddm_s::HDDM *record,
1100 JFactory<DBCALTDCDigiHit> *factory, string tag)
1101{
1102 /// Copies the data from the given hddm_s structure. This is called
1103 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1104 /// returns OBJECT_NOT_AVAILABLE immediately.
1105
1106 if (factory == NULL__null)
1107 return OBJECT_NOT_AVAILABLE;
1108 if (tag != "")
1109 return OBJECT_NOT_AVAILABLE;
1110
1111 vector<DBCALTDCDigiHit*> data;
1112
1113 const hddm_s::BcalTDCDigiHitList &hits = record->getBcalTDCDigiHits();
1114 hddm_s::BcalTDCDigiHitList::iterator iter;
1115 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1116 DBCALTDCDigiHit *bcaltdchit = new DBCALTDCDigiHit;
1117 bcaltdchit->module = iter->getModule();
1118 bcaltdchit->layer = iter->getLayer();
1119 bcaltdchit->sector = iter->getSector();
1120 bcaltdchit->end = (iter->getEnd() == 0)? DBCALGeometry::kUpstream :
1121 DBCALGeometry::kDownstream;
1122 bcaltdchit->time = (uint32_t)iter->getTime();
1123 data.push_back(bcaltdchit);
1124 }
1125
1126 // Copy into factory
1127 factory->CopyTo(data);
1128
1129 return NOERROR;
1130}
1131
1132//------------------
1133// Extract_DMCReaction
1134//------------------
1135jerror_t DEventSourceHDDM::Extract_DMCReaction(hddm_s::HDDM *record,
1136 JFactory<DMCReaction> *factory, string tag,
1137 JEventLoop *loop)
1138{
1139 /// Copies the data from the given hddm_s structure. This is called
1140 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1141 /// returns OBJECT_NOT_AVAILABLE immediately.
1142
1143 if (tag != "")
1144 return OBJECT_NOT_AVAILABLE;
1145
1146 if (factory == NULL__null)
1147 return OBJECT_NOT_AVAILABLE;
1148
1149 double locTargetCenterZ = 0.0;
1150 int locRunNumber = loop->GetJEvent().GetRunNumber();
1151 LockRead();
1152 {
1153 locTargetCenterZ = dTargetCenterZMap[locRunNumber];
1154 }
1155 UnlockRead();
1156 DVector3 locPosition(0.0, 0.0, locTargetCenterZ);
1157
1158 vector<DMCReaction*> dmcreactions;
1159
1160 const hddm_s::ReactionList &reacts = record->getReactions();
1161 hddm_s::ReactionList::iterator iter;
1162 for (iter = reacts.begin(); iter != reacts.end(); ++iter) {
1163 DMCReaction *mcreaction = new DMCReaction;
1164 dmcreactions.push_back(mcreaction);
1165 mcreaction->type = iter->getType();
1166 mcreaction->weight = iter->getWeight();
1167 hddm_s::Origin &origin = iter->getVertex().getOrigin();
1168 double torig = origin.getT();
1169 double zorig = origin.getVz();
1170
1171 const hddm_s::BeamList &beams = record->getBeams();
1172 if (beams.size() > 0) {
1173 hddm_s::Beam &beam = iter->getBeam();
1174 DVector3 mom(beam.getMomentum().getPx(),
1175 beam.getMomentum().getPy(),
1176 beam.getMomentum().getPz());
1177 mcreaction->beam.setPosition(locPosition);
1178 mcreaction->beam.setMomentum(mom);
1179 mcreaction->beam.setPID(Gamma);
1180 mcreaction->target.setPID(IDTrack(mcreaction->beam.charge(),
1181 mcreaction->beam.mass()));
1182 mcreaction->beam.setTime(torig - (zorig - locTargetCenterZ)/29.9792458);
1183 }
1184 else {
1185 // fake values for DMCReaction
1186 mcreaction->beam.setPosition(locPosition);
1187 mcreaction->beam.setPID(Gamma);
1188 }
1189
1190 const hddm_s::TargetList &targets = record->getTargets();
1191 if (targets.size() > 0) {
1192 hddm_s::Target &target = iter->getTarget();
1193 DKinematicData target_kd;
1194 DVector3 mom(target.getMomentum().getPx(),
1195 target.getMomentum().getPy(),
1196 target.getMomentum().getPz());
1197 mcreaction->target.setPosition(locPosition);
1198 mcreaction->target.setMomentum(mom);
1199 hddm_s::PropertiesList &properties = target.getPropertiesList();
1200 if (properties.size() > 0) {
1201 mcreaction->target.setPID(IDTrack(properties(0).getCharge(),
1202 properties(0).getMass()));
1203 }
1204 mcreaction->target.setTime(torig - (zorig - locTargetCenterZ)/29.9792458);
1205 }
1206 else {
1207 // fake values for DMCReaction
1208 mcreaction->target.setPosition(locPosition);
1209 }
1210 }
1211
1212 // Copy into factories
1213 //_DBG_<<"Creating "<<dmcreactions.size()<<" DMCReaction objects"<<endl;
1214
1215 factory->CopyTo(dmcreactions);
1216
1217 return NOERROR;
1218}
1219
1220//------------------
1221// Extract_DMCThrown
1222//------------------
1223jerror_t DEventSourceHDDM::Extract_DMCThrown(hddm_s::HDDM *record,
1224 JFactory<DMCThrown> *factory, string tag)
1225{
1226 /// Copies the data from the given hddm_s structure. This is called
1227 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1228 /// returns OBJECT_NOT_AVAILABLE immediately.
1229
1230 if (factory == NULL__null)
1231 return OBJECT_NOT_AVAILABLE;
1232 if (tag != "")
1233 return OBJECT_NOT_AVAILABLE;
1234
1235 vector<DMCThrown*> data;
1236
1237 const hddm_s::VertexList &verts = record->getVertices();
1238 hddm_s::VertexList::iterator iter;
1239 for (iter = verts.begin(); iter != verts.end(); ++iter) {
1240 const hddm_s::OriginList &origs = iter->getOrigins();
1241 const hddm_s::ProductList &prods = iter->getProducts();
1242 double vertex[4] = {0., 0., 0., 0.};
1243 if (origs.size() > 0) {
1244 vertex[0] = iter->getOrigin().getT();
1245 vertex[1] = iter->getOrigin().getVx();
1246 vertex[2] = iter->getOrigin().getVy();
1247 vertex[3] = iter->getOrigin().getVz();
1248 }
1249 hddm_s::ProductList::iterator piter;
1250 for (piter = prods.begin(); piter != prods.end(); ++piter) {
1251 double E = piter->getMomentum().getE();
1252 double px = piter->getMomentum().getPx();
1253 double py = piter->getMomentum().getPy();
1254 double pz = piter->getMomentum().getPz();
1255 double mass = sqrt(E*E - (px*px + py*py + pz*pz));
1256 if (!isfinite(mass))
1257 mass = 0.0;
Value stored to 'mass' is never read
1258 DMCThrown *mcthrown = new DMCThrown;
1259 mcthrown->type = piter->getType(); // GEANT partcile type
1260 mcthrown->myid = piter->getId();
1261 mcthrown->parentid = piter->getParentid();
1262 mcthrown->mech = piter->getMech();
1263 mcthrown->pdgtype = piter->getPdgtype(); // PDG particle type
1264 // Ensure consistency of GEANT type and PDG type information
1265 const Particle_t pTypeFromPdgType = PDGtoPType(mcthrown->pdgtype);
1266 if (mcthrown->type != (int)pTypeFromPdgType) {
1267 // GEANT type and PDG type information are inconsistent
1268 if ((mcthrown->type == 0) and (pTypeFromPdgType != Unknown)) {
1269 // Workaround for cases where `type` is 0, i.e. Unknown, but the `pgdtype` is valid
1270 // This may happen, for example, when EvtGen is used to decay particles
1271 // Assume that the PDG type info is correct and set the GEANT type accordingly
1272 mcthrown->type = (int)pTypeFromPdgType;
1273 } else if ((pTypeFromPdgType == Unknown) and (PDGtype((Particle_t)mcthrown->type) != 0)) {
1274 // Workaround for cases where the `pgdtype` is Unknown, but `type` is not Unknown
1275 // Assume that the GEANT type info is correct and set the PDG type accordingly
1276 mcthrown->pdgtype = PDGtype((Particle_t)mcthrown->type);
1277 } else {
1278 // Both types inconsistent but also not Unknown; not clear which is correct
1279 jerr << std::endl
1280 << "WARNING: type mismatch for MC-thrown particle with myid = " << mcthrown->myid
1281 << ": GEANT type = " << mcthrown->type
1282 << " vs. PDG type = " << mcthrown->pdgtype << "."
1283 << std::endl;
1284 }
1285 }
1286 mcthrown->setPID((Particle_t)mcthrown->type);
1287 mcthrown->setMomentum(DVector3(px, py, pz));
1288 mcthrown->setPosition(DVector3(vertex[1], vertex[2], vertex[3]));
1289 mcthrown->setTime(vertex[0]);
1290 data.push_back(mcthrown);
1291 }
1292 }
1293
1294 // Copy into factory
1295 factory->CopyTo(data);
1296
1297 return NOERROR;
1298}
1299
1300//------------------
1301// Extract_DCDCHit
1302//------------------
1303jerror_t DEventSourceHDDM::Extract_DCDCHit(JEventLoop* locEventLoop, hddm_s::HDDM *record,
1304 JFactory<DCDCHit> *factory, string tag)
1305{
1306 /// Copies the data from the given hddm_s structure. This is called
1307 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1308 /// returns OBJECT_NOT_AVAILABLE immediately.
1309
1310 if (factory == NULL__null)
1311 return OBJECT_NOT_AVAILABLE;
1312
1313 // Since we are writing out CDC hits with the new "Calib" tag by default
1314 // assume that is what we are reading in, so that we don't support the
1315 // default tag anymore
1316 // sdobbs -- 3/13/2018
1317 //if (tag != "" && tag != "TRUTH" && tag != "Calib")
1318 if (tag != "TRUTH" && tag != "Calib")
1319 return OBJECT_NOT_AVAILABLE;
1320
1321 vector<DCDCHit*> data;
1322
1323 if ( tag == "" || tag == "Calib" ) {
1324 vector<const DCDCHit*> locTruthHits;
1325 locEventLoop->Get(locTruthHits, "TRUTH");
1326
1327 //pre-sort truth hits
1328 map<pair<int, int>, vector<const DCDCHit*>> locTruthHitMap; //key pair: ring, straw
1329 for(auto& locTruthHit : locTruthHits)
1330 locTruthHitMap[std::make_pair(locTruthHit->ring, locTruthHit->straw)].push_back(locTruthHit);
1331
1332 const hddm_s::CdcStrawHitList &hits = record->getCdcStrawHits();
1333 hddm_s::CdcStrawHitList::iterator iter;
1334 int locIndex = 0;
1335 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1336 DCDCHit *hit = new DCDCHit;
1337 hit->ring = iter->getRing();
1338 hit->straw = iter->getStraw();
1339 hit->q = iter->getQ();
1340 hit->t = iter->getT();
1341 if(iter->getCdcDigihits().size() > 0) {
1342 hit->amp = iter->getCdcDigihit().getPeakAmp();
1343 }
1344 else{
1345 // for generated events (not folded-in background events) for which we
1346 // have no digi hits return q
1347 hit->amp=hit->q;
1348 }
1349 hit->QF = 0;
1350 if(iter->getCdcHitQFs().size() > 0) {
1351 hit->QF = iter->getCdcHitQF().getQF();
1352 }
1353 hit->d = 0.; // initialize to zero to avoid any NaN
1354 hit->itrack = 0; // track information is in TRUTH tag
1355 hit->ptype = 0; // ditto
1356
1357 //match hit between truth & recon
1358 auto& locPotentialTruthHits = locTruthHitMap[std::make_pair(hit->ring, hit->straw)];
1359 double locBestDeltaT = 9.9E99;
1360 const DCDCHit* locBestTruthHit = nullptr;
1361 for(auto& locTruthHit : locPotentialTruthHits)
1362 {
1363 auto locDeltaT = fabs(hit->t - locTruthHit->t);
1364 if(locDeltaT >= locBestDeltaT)
1365 continue;
1366 locBestDeltaT = locDeltaT;
1367 locBestTruthHit = locTruthHit;
1368 }
1369 if(locBestTruthHit != nullptr)
1370 hit->AddAssociatedObject(locBestTruthHit);
1371
1372 data.push_back(hit);
1373 ++locIndex;
1374 }
1375 }
1376 else if (tag == "TRUTH") {
1377 const hddm_s::CdcStrawTruthHitList &thits = record->getCdcStrawTruthHits();
1378 hddm_s::CdcStrawTruthHitList::iterator iter;
1379 for (iter = thits.begin(); iter != thits.end(); ++iter) {
1380 DCDCHit *hit = new DCDCHit;
1381 hit->ring = iter->getRing();
1382 hit->straw = iter->getStraw();
1383 hit->q = iter->getQ();
1384 hit->t = iter->getT();
1385 hit->d = iter->getD();
1386 hit->itrack = iter->getItrack();
1387 hit->ptype = iter->getPtype();
1388 data.push_back(hit);
1389 }
1390 }
1391
1392 // Copy into factory
1393 factory->CopyTo(data);
1394
1395 return NOERROR;
1396}
1397
1398
1399//------------------
1400// Extract_DFDCHit
1401//------------------
1402jerror_t DEventSourceHDDM::Extract_DFDCHit(hddm_s::HDDM *record,
1403 JFactory<DFDCHit> *factory, string tag)
1404{
1405 /// Copies the data from the given hddm_s structure. This is called
1406 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1407 /// returns OBJECT_NOT_AVAILABLE immediately.
1408
1409 if (factory == NULL__null)
1410 return OBJECT_NOT_AVAILABLE;
1411 if (tag != "" && tag != "TRUTH" && tag != "CALIB")
1412 return OBJECT_NOT_AVAILABLE;
1413
1414 vector<DFDCHit*> data;
1415
1416 if (tag == "") {
1417 const hddm_s::FdcAnodeHitList &ahits = record->getFdcAnodeHits();
1418 hddm_s::FdcAnodeHitList::iterator ahiter;
1419 for (ahiter = ahits.begin(); ahiter != ahits.end(); ++ahiter) {
1420 DFDCHit* newHit = new DFDCHit();
1421 newHit->layer = ahiter->getLayer();
1422 newHit->module = ahiter->getModule();
1423 newHit->element = ahiter->getWire();
1424 newHit->q = ahiter->getDE();
1425 newHit->pulse_height = 0.; // not measured
1426 newHit->t = ahiter->getT();
1427 newHit->d = 0.; // initialize to zero to avoid any NaN
1428 newHit->itrack = 0; // track information is in TRUTH tag
1429 newHit->ptype = 0; // ditto
1430 newHit->plane = 2;
1431 newHit->type = 0;
1432 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1433 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1434 newHit->r = DFDCGeometry::getWireR(newHit);
1435 data.push_back(newHit);
1436 }
1437
1438 // Ditto for the cathodes.
1439 const hddm_s::FdcCathodeHitList &chits = record->getFdcCathodeHits();
1440 hddm_s::FdcCathodeHitList::iterator chiter;
1441 for (chiter = chits.begin(); chiter != chits.end(); ++chiter) {
1442 DFDCHit* newHit = new DFDCHit();
1443 newHit->layer = chiter->getLayer();
1444 newHit->module = chiter->getModule();
1445 newHit->element = chiter->getStrip();
1446 if (newHit->element > 1000)
1447 newHit->element -= 1000;
1448 newHit->plane = chiter->getPlane();
1449 newHit->q = chiter->getQ();
1450 newHit->pulse_height = newHit->q;
1451 if(chiter->getFdcDigihits().size() > 0) {
1452 newHit->pulse_height = chiter->getFdcDigihit().getPeakAmp();
1453 }
1454 newHit->t = chiter->getT();
1455 newHit->d = 0.; // initialize to zero to avoid any NaN
1456 newHit->itrack = 0; // track information is in TRUTH tag
1457 newHit->ptype = 0; // ditto
1458 newHit->type = 1;
1459 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1460 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1461 newHit->r = DFDCGeometry::getStripR(newHit);
1462 data.push_back(newHit);
1463 }
1464 }
1465
1466 else if (tag == "TRUTH"){
1467 const hddm_s::FdcAnodeTruthHitList &aths = record->getFdcAnodeTruthHits();
1468 hddm_s::FdcAnodeTruthHitList::iterator atiter;
1469 for (atiter = aths.begin(); atiter != aths.end(); ++atiter) {
1470 DFDCHit* newHit = new DFDCHit();
1471 newHit->layer = atiter->getLayer();
1472 newHit->module = atiter->getModule();
1473 newHit->element = atiter->getWire();
1474 newHit->q = atiter->getDE();
1475 newHit->pulse_height=0.; // not measured
1476 newHit->t = atiter->getT();
1477 newHit->d = atiter->getD();
1478 newHit->itrack = atiter->getItrack();
1479 newHit->ptype = atiter->getPtype();
1480 newHit->plane = 2;
1481 newHit->type = 0;
1482 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1483 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1484 newHit->r = DFDCGeometry::getWireR(newHit);
1485 data.push_back(newHit);
1486 }
1487
1488 // Ditto for the cathodes.
1489 const hddm_s::FdcCathodeTruthHitList &cths =
1490 record->getFdcCathodeTruthHits();
1491 hddm_s::FdcCathodeTruthHitList::iterator ctiter;
1492 for (ctiter = cths.begin(); ctiter != cths.end(); ++ctiter) {
1493 DFDCHit* newHit = new DFDCHit();
1494 newHit->layer = ctiter->getLayer();
1495 newHit->module = ctiter->getModule();
1496 newHit->element = ctiter->getStrip();
1497 if (newHit->element > 1000)
1498 newHit->element -= 1000;
1499 newHit->plane = ctiter->getPlane();
1500 newHit->q = ctiter->getQ();
1501 newHit->pulse_height = newHit->q;
1502 newHit->t = ctiter->getT();
1503 newHit->d = 0.; // initialize to zero to avoid any NaN
1504 newHit->itrack = ctiter->getItrack();
1505 newHit->ptype = ctiter->getPtype();
1506 newHit->type = 1;
1507 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1508 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1509 newHit->r = DFDCGeometry::getStripR(newHit);
1510 data.push_back(newHit);
1511 }
1512 }
1513
1514 else if (tag == "CALIB") {
1515 // Deal with the wires
1516 const hddm_s::FdcAnodeHitList &ahits = record->getFdcAnodeHits();
1517 hddm_s::FdcAnodeHitList::iterator ahiter;
1518 for (ahiter = ahits.begin(); ahiter != ahits.end(); ++ahiter) {
1519 DFDCHit* newHit = new DFDCHit();
1520 newHit->layer = ahiter->getLayer();
1521 newHit->module = ahiter->getModule();
1522 newHit->element = ahiter->getWire();
1523 newHit->q = ahiter->getDE();
1524 newHit->t = ahiter->getT();
1525 newHit->d = 0.; // initialize to zero to avoid any NaN
1526 newHit->itrack = 0; // track information is in TRUTH tag
1527 newHit->ptype = 0; // ditto
1528 newHit->plane = 2;
1529 newHit->type = 0;
1530 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1531 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1532 newHit->r = DFDCGeometry::getWireR(newHit);
1533 data.push_back(newHit);
1534 }
1535
1536 // Ditto for the cathodes.
1537 const hddm_s::FdcCathodeHitList &chits = record->getFdcCathodeHits();
1538 hddm_s::FdcCathodeHitList::iterator chiter;
1539 for (chiter = chits.begin(); chiter != chits.end(); ++chiter) {
1540 DFDCHit* newHit = new DFDCHit();
1541 newHit->layer = chiter->getLayer();
1542 newHit->module = chiter->getModule();
1543 newHit->element = chiter->getStrip();
1544 if (newHit->element > 1000)
1545 newHit->element-=1000;
1546 newHit->plane = chiter->getPlane();
1547 if (newHit->plane == 1) // v
1548 newHit->q = chiter->getQ()*vscale[newHit->element-1];
1549 else // u
1550 newHit->q = chiter->getQ()*uscale[newHit->element-1];
1551 newHit->t = chiter->getT();
1552 newHit->d = 0.; // initialize to zero to avoid any NaN
1553 newHit->itrack = 0; // track information is in TRUTH tag
1554 newHit->ptype = 0; // ditto
1555 newHit->type = 1;
1556 newHit->gPlane = DFDCGeometry::gPlane(newHit);
1557 newHit->gLayer = DFDCGeometry::gLayer(newHit);
1558 newHit->r = DFDCGeometry::getStripR(newHit);
1559 data.push_back(newHit);
1560 }
1561 }
1562
1563 // Copy into factory
1564 factory->CopyTo(data);
1565
1566 return NOERROR;
1567}
1568
1569//------------------
1570// Extract_DBCALTruthShower
1571//------------------
1572jerror_t DEventSourceHDDM::Extract_DBCALTruthShower(hddm_s::HDDM *record,
1573 JFactory<DBCALTruthShower> *factory,
1574 string tag)
1575{
1576 /// Copies the data from the given hddm_s structure. This is called
1577 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1578 /// returns OBJECT_NOT_AVAILABLE immediately.
1579
1580 if (factory == NULL__null)
1581 return OBJECT_NOT_AVAILABLE;
1582 if (tag != "")
1583 return OBJECT_NOT_AVAILABLE;
1584
1585 vector<DBCALTruthShower*> data;
1586
1587 const hddm_s::BcalTruthShowerList &shows = record->getBcalTruthShowers();
1588 hddm_s::BcalTruthShowerList::iterator iter;
1589 for (iter = shows.begin(); iter != shows.end(); ++iter) {
1590 DBCALTruthShower *bcaltruth = new DBCALTruthShower;
1591 bcaltruth->track = iter->getTrack();
1592 bcaltruth->ptype = iter->getPtype();
1593 bcaltruth->primary = (iter->getPrimary())? 1 : 0;
1594 bcaltruth->phi = iter->getPhi();
1595 bcaltruth->r = iter->getR();
1596 bcaltruth->z = iter->getZ();
1597 bcaltruth->t = iter->getT();
1598 bcaltruth->E = iter->getE();
1599 bcaltruth->px = iter->getPx();
1600 bcaltruth->py = iter->getPy();
1601 bcaltruth->pz = iter->getPz();
1602 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
1603 bcaltruth->itrack = (ids.size())? ids.begin()->getItrack() : 0;
1604 data.push_back(bcaltruth);
1605 }
1606
1607 // Copy into factory
1608 factory->CopyTo(data);
1609
1610 return NOERROR;
1611}
1612
1613//------------------
1614// Extract_DBCALTruthCell
1615//------------------
1616jerror_t DEventSourceHDDM::Extract_DBCALTruthCell(hddm_s::HDDM *record,
1617 JFactory<DBCALTruthCell> *factory,
1618 string tag)
1619{
1620 /// Copies the data from the given hddm_s structure. This is called
1621 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1622 /// returns OBJECT_NOT_AVAILABLE immediately.
1623
1624 if (factory == NULL__null)
1625 return OBJECT_NOT_AVAILABLE;
1626 if (tag != "")
1627 return OBJECT_NOT_AVAILABLE;
1628
1629 vector<DBCALTruthCell*> data;
1630
1631 const hddm_s::BcalTruthHitList &hits = record->getBcalTruthHits();
1632 hddm_s::BcalTruthHitList::iterator hiter;
1633 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
1634 DBCALTruthCell *truthcell = new DBCALTruthCell();
1635 truthcell->module = hiter->getModule();
1636 truthcell->layer = hiter->getLayer();
1637 truthcell->sector = hiter->getSector();
1638 truthcell->E = hiter->getE();
1639 truthcell->t = hiter->getT();
1640 truthcell->zLocal = hiter->getZLocal();
1641 data.push_back(truthcell);
1642 }
1643
1644 // Copy into factory
1645 factory->CopyTo(data);
1646
1647 return NOERROR;
1648}
1649
1650//------------------
1651// Extract_DFCALTruthShower
1652//------------------
1653jerror_t DEventSourceHDDM::Extract_DFCALTruthShower(hddm_s::HDDM *record,
1654 JFactory<DFCALTruthShower> *factory,
1655 string tag)
1656{
1657 /// Copies the data from the given hddm_s structure. This is called
1658 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1659 /// returns OBJECT_NOT_AVAILABLE immediately.
1660
1661 if (factory == NULL__null)
1662 return OBJECT_NOT_AVAILABLE;
1663 if (tag != "")
1664 return OBJECT_NOT_AVAILABLE;
1665
1666 vector<DFCALTruthShower*> data;
1667 JObject::oid_t id=1;
1668
1669 const hddm_s::FcalTruthShowerList &shows = record->getFcalTruthShowers();
1670 hddm_s::FcalTruthShowerList::iterator iter;
1671 for (iter = shows.begin(); iter != shows.end(); ++iter) {
1672 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
1673 int itrack = (ids.size())? ids.begin()->getItrack() : 0;
1674 DFCALTruthShower *dfcaltruthshower = new DFCALTruthShower(
1675 id++,
1676 iter->getX(),
1677 iter->getY(),
1678 iter->getZ(),
1679 iter->getPx(),
1680 iter->getPy(),
1681 iter->getPz(),
1682 iter->getE(),
1683 iter->getT(),
1684 iter->getPrimary(),
1685 iter->getTrack(),
1686 iter->getPtype(),
1687 itrack
1688 );
1689 data.push_back(dfcaltruthshower);
1690 }
1691
1692 // Copy into factory
1693 factory->CopyTo(data);
1694
1695 return NOERROR;
1696}
1697
1698//------------------
1699// Extract_DFCALHit
1700//------------------
1701jerror_t DEventSourceHDDM::Extract_DFCALHit(hddm_s::HDDM *record,
1702 JFactory<DFCALHit> *factory, string tag,
1703 JEventLoop* eventLoop)
1704{
1705 /// Copies the data from the given hddm_s structure. This is called
1706 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1707 /// returs OBJECT_NOT_AVAILABLE immediately.
1708
1709 if (factory == NULL__null)
1710 return OBJECT_NOT_AVAILABLE;
1711 if (tag != "" && tag != "TRUTH")
1712 return OBJECT_NOT_AVAILABLE;
1713
1714 // extract the FCAL Geometry (for isBlockActive() and positionOnFace())
1715 vector<const DFCALGeometry*> fcalGeomVect;
1716 eventLoop->Get( fcalGeomVect );
1717 if (fcalGeomVect.size() < 1)
1718 return OBJECT_NOT_AVAILABLE;
1719 const DFCALGeometry& fcalGeom = *(fcalGeomVect[0]);
1720
1721 vector<DFCALHit*> data;
1722
1723 if (tag == "") {
1724 const hddm_s::FcalHitList &hits = record->getFcalHits();
1725 hddm_s::FcalHitList::iterator iter;
1726 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1727 int row = iter->getRow();
1728 int column = iter->getColumn();
1729
1730 // Filter out non-physical blocks here
1731 if (!fcalGeom.isBlockActive(row, column))
1732 continue;
1733
1734 // Get position of blocks on front face. (This should really come from
1735 // hdgeant directly so the positions can be shifted in mcsmear.)
1736 DVector2 pos = fcalGeom.positionOnFace(row, column);
1737
1738 DFCALHit *mchit = new DFCALHit();
1739 mchit->row = row;
1740 mchit->column = column;
1741 mchit->x = pos.X();
1742 mchit->y = pos.Y();
1743 mchit->E = iter->getE();
1744 mchit->t = iter->getT();
1745 mchit->intOverPeak = 6.;
1746 if(iter->getFcalDigihits().size() > 0) {
1747 mchit->intOverPeak = iter->getFcalDigihit().getIntegralOverPeak();
1748 }
1749 data.push_back(mchit);
1750 }
1751 }
1752 else if (tag == "TRUTH") {
1753 const hddm_s::FcalTruthHitList &hits = record->getFcalTruthHits();
1754 hddm_s::FcalTruthHitList::iterator iter;
1755 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1756 int row = iter->getRow();
1757 int column = iter->getColumn();
1758
1759 // Filter out non-physical blocks here
1760 if (!fcalGeom.isBlockActive(row, column))
1761 continue;
1762
1763 // Get position of blocks on front face. (This should really come from
1764 // hdgeant directly so the positions can be shifted in mcsmear.)
1765 DVector2 pos = fcalGeom.positionOnFace(row, column);
1766
1767 DFCALHit *mchit = new DFCALHit();
1768 mchit->row = row;
1769 mchit->column = column;
1770 mchit->x = pos.X();
1771 mchit->y = pos.Y();
1772 mchit->E = iter->getE();
1773 mchit->t = iter->getT();
1774 mchit->intOverPeak = 6.;
1775 data.push_back(mchit);
1776 }
1777 }
1778
1779 // Copy into factory
1780 factory->CopyTo(data);
1781
1782 return NOERROR;
1783}
1784
1785
1786///------------------
1787// Extract_DECALTruthShower
1788//------------------
1789jerror_t DEventSourceHDDM::Extract_DECALTruthShower(hddm_s::HDDM *record,
1790 JFactory<DECALTruthShower> *factory,
1791 string tag)
1792{
1793 /// Copies the data from the given hddm_s structure. This is called
1794 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1795 /// returns OBJECT_NOT_AVAILABLE immediately.
1796
1797 if (factory == NULL__null)
1798 return OBJECT_NOT_AVAILABLE;
1799 if (tag != "")
1800 return OBJECT_NOT_AVAILABLE;
1801
1802 vector<DECALTruthShower*> data;
1803 JObject::oid_t id=1;
1804
1805 const hddm_s::EcalTruthShowerList &shows = record->getEcalTruthShowers();
1806 hddm_s::EcalTruthShowerList::iterator iter;
1807 for (iter = shows.begin(); iter != shows.end(); ++iter) {
1808 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
1809 int itrack = (ids.size())? ids.begin()->getItrack() : 0;
1810 DECALTruthShower *decaltruthshower = new DECALTruthShower(
1811 id++,
1812 iter->getX(),
1813 iter->getY(),
1814 iter->getZ(),
1815 iter->getPx(),
1816 iter->getPy(),
1817 iter->getPz(),
1818 iter->getE(),
1819 iter->getT(),
1820 iter->getPrimary(),
1821 iter->getTrack(),
1822 iter->getPtype(),
1823 itrack
1824 );
1825 data.push_back(decaltruthshower);
1826 }
1827
1828 // Copy into factory
1829 factory->CopyTo(data);
1830
1831 return NOERROR;
1832}
1833
1834
1835//------------------
1836// Extract_DECALHit
1837//------------------
1838jerror_t DEventSourceHDDM::Extract_DECALHit(hddm_s::HDDM *record,
1839 JFactory<DECALHit> *factory, string tag,
1840 JEventLoop* eventLoop)
1841{
1842 /// Copies the data from the given hddm_s structure. This is called
1843 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1844 /// returs OBJECT_NOT_AVAILABLE immediately.
1845
1846 if (factory == NULL__null)
1847 return OBJECT_NOT_AVAILABLE;
1848 if (tag != "" && tag != "TRUTH")
1849 return OBJECT_NOT_AVAILABLE;
1850
1851 // extract the ECAL Geometry (for isBlockActive() and positionOnFace())
1852 vector<const DECALGeometry*> ecalGeomVect;
1853 eventLoop->Get( ecalGeomVect );
1854 if (ecalGeomVect.size() < 1)
1855 return OBJECT_NOT_AVAILABLE;
1856 const DECALGeometry& ecalGeom = *(ecalGeomVect[0]);
1857
1858 vector<DECALHit*> data;
1859 int hitId = 0;
1860
1861 if (tag == "") {
1862
1863 const hddm_s::EcalHitList &hits = record->getEcalHits();
1864 hddm_s::EcalHitList::iterator iter;
1865 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1866 int row = iter->getRow();
1867 int column = iter->getColumn();
1868
1869 // Filter out non-physical blocks here
1870 if (!ecalGeom.isBlockActive(row, column))
1871 continue;
1872
1873 // Get position of blocks on front face. (This should really come from
1874 // hdgeant directly so the poisitions can be shifted in mcsmear.)
1875 DVector2 pos = ecalGeom.positionOnFace(row, column);
1876
1877 DECALHit *mchit = new DECALHit();
1878 mchit->row = row;
1879 mchit->column = column;
1880 mchit->x = pos.X();
1881 mchit->y = pos.Y();
1882 mchit->E = iter->getE();
1883 mchit->t = iter->getT();
1884 mchit->id = hitId++;
1885 mchit->intOverPeak = 5.;
1886 data.push_back(mchit);
1887 }
1888 }
1889
1890 else if (tag == "TRUTH") {
1891 const hddm_s::EcalTruthHitList &hits = record->getEcalTruthHits();
1892 hddm_s::EcalTruthHitList::iterator iter;
1893 for (iter = hits.begin(); iter != hits.end(); ++iter) {
1894 int row = iter->getRow();
1895 int column = iter->getColumn();
1896
1897 // Filter out non-physical blocks here
1898 if (!ecalGeom.isBlockActive(row, column))
1899 continue;
1900
1901 // Get position of blocks on front face. (This should really come from
1902 // hdgeant directly so the poisitions can be shifted in mcsmear.)
1903 DVector2 pos = ecalGeom.positionOnFace(row, column);
1904
1905 DECALHit *mchit = new DECALHit();
1906 mchit->row = row;
1907 mchit->column = column;
1908 mchit->x = pos.X();
1909 mchit->y = pos.Y();
1910 mchit->E = iter->getE();
1911 mchit->t = iter->getT();
1912 mchit->id = hitId++;
1913 mchit->intOverPeak = 5.;
1914 data.push_back(mchit);
1915 }
1916 }
1917
1918 // Copy into factory
1919 factory->CopyTo(data);
1920
1921 return NOERROR;
1922}
1923
1924
1925//------------------
1926// Extract_DCCALTruthShower
1927//------------------
1928jerror_t DEventSourceHDDM::Extract_DCCALTruthShower(hddm_s::HDDM *record,
1929 JFactory<DCCALTruthShower> *factory,
1930 string tag)
1931{
1932 /// Copies the data from the given hddm_s structure. This is called
1933 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1934 /// returns OBJECT_NOT_AVAILABLE immediately.
1935
1936 if (factory == NULL__null)
1937 return OBJECT_NOT_AVAILABLE;
1938 if (tag != "")
1939 return OBJECT_NOT_AVAILABLE;
1940
1941 vector<DCCALTruthShower*> data;
1942 JObject::oid_t id=1;
1943
1944 const hddm_s::CcalTruthShowerList &shows = record->getCcalTruthShowers();
1945 hddm_s::CcalTruthShowerList::iterator iter;
1946 for (iter = shows.begin(); iter != shows.end(); ++iter) {
1947 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
1948 int itrack = (ids.size())? ids.begin()->getItrack() : 0;
1949 DCCALTruthShower *dccaltruthshower = new DCCALTruthShower(
1950 id++,
1951 iter->getX(),
1952 iter->getY(),
1953 iter->getZ(),
1954 iter->getPx(),
1955 iter->getPy(),
1956 iter->getPz(),
1957 iter->getE(),
1958 iter->getT(),
1959 iter->getPrimary(),
1960 iter->getTrack(),
1961 iter->getPtype(),
1962 itrack
1963 );
1964 data.push_back(dccaltruthshower);
1965 }
1966
1967 // Copy into factory
1968 factory->CopyTo(data);
1969
1970 return NOERROR;
1971}
1972
1973//------------------
1974// Extract_DCCALHit
1975//------------------
1976jerror_t DEventSourceHDDM::Extract_DCCALHit(hddm_s::HDDM *record,
1977 JFactory<DCCALHit> *factory, string tag,
1978 JEventLoop* eventLoop)
1979{
1980 /// Copies the data from the given hddm_s structure. This is called
1981 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
1982 /// returs OBJECT_NOT_AVAILABLE immediately.
1983
1984 if (factory == NULL__null)
1985 return OBJECT_NOT_AVAILABLE;
1986 if (tag != "" && tag != "TRUTH")
1987 return OBJECT_NOT_AVAILABLE;
1988
1989 // extract the CCAL Geometry (for isBlockActive() and positionOnFace())
1990 vector<const DCCALGeometry*> ccalGeomVect;
1991 eventLoop->Get( ccalGeomVect );
1992 if (ccalGeomVect.size() < 1)
1993 return OBJECT_NOT_AVAILABLE;
1994 const DCCALGeometry& ccalGeom = *(ccalGeomVect[0]);
1995
1996 vector<DCCALHit*> data;
1997 int hitId = 0;
1998
1999 if (tag == "") {
2000 const hddm_s::CcalHitList &hits = record->getCcalHits();
2001 hddm_s::CcalHitList::iterator iter;
2002 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2003 int row = iter->getRow();
2004 int column = iter->getColumn();
2005
2006 // Filter out non-physical blocks here
2007 if (!ccalGeom.isBlockActive(row, column))
2008 continue;
2009
2010 // Get position of blocks on front face. (This should really come from
2011 // hdgeant directly so the poisitions can be shifted in mcsmear.)
2012 DVector2 pos = ccalGeom.positionOnFace(row, column);
2013
2014 DCCALHit *mchit = new DCCALHit();
2015 mchit->row = row;
2016 mchit->column = column;
2017 mchit->x = pos.X();
2018 mchit->y = pos.Y();
2019 mchit->E = iter->getE();
2020 mchit->t = iter->getT();
2021 mchit->id = hitId++;
2022 data.push_back(mchit);
2023 }
2024 }
2025
2026 else if (tag == "TRUTH") {
2027 const hddm_s::CcalTruthHitList &hits = record->getCcalTruthHits();
2028 hddm_s::CcalTruthHitList::iterator iter;
2029 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2030 int row = iter->getRow();
2031 int column = iter->getColumn();
2032
2033 // Filter out non-physical blocks here
2034 if (!ccalGeom.isBlockActive(row, column))
2035 continue;
2036
2037 // Get position of blocks on front face. (This should really come from
2038 // hdgeant directly so the poisitions can be shifted in mcsmear.)
2039 DVector2 pos = ccalGeom.positionOnFace(row, column);
2040
2041 DCCALHit *mchit = new DCCALHit();
2042 mchit->row = row;
2043 mchit->column = column;
2044 mchit->x = pos.X();
2045 mchit->y = pos.Y();
2046 mchit->E = iter->getE();
2047 mchit->t = iter->getT();
2048 mchit->id = hitId++;
2049 data.push_back(mchit);
2050 }
2051 }
2052
2053 // Copy into factory
2054 factory->CopyTo(data);
2055
2056 return NOERROR;
2057}
2058
2059//------------------
2060// Extract_DMCTrajectoryPoint
2061//------------------
2062jerror_t DEventSourceHDDM::Extract_DMCTrajectoryPoint(hddm_s::HDDM *record,
2063 JFactory<DMCTrajectoryPoint> *factory,
2064 string tag)
2065{
2066 /// Copies the data from the given hddm_s structure. This is called
2067 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2068 /// returns OBJECT_NOT_AVAILABLE immediately.
2069
2070 if (factory == NULL__null)
2071 return OBJECT_NOT_AVAILABLE;
2072 if (tag != "")
2073 return OBJECT_NOT_AVAILABLE;
2074
2075 vector<DMCTrajectoryPoint*> data;
2076
2077 const hddm_s::McTrajectoryPointList &pts = record->getMcTrajectoryPoints();
2078 hddm_s::McTrajectoryPointList::iterator iter;
2079 for (iter = pts.begin(); iter != pts.end(); ++iter) {
2080 DMCTrajectoryPoint *p = new DMCTrajectoryPoint;
2081 p->x = iter->getX();
2082 p->y = iter->getY();
2083 p->z = iter->getZ();
2084 p->t = iter->getT();
2085 p->px = iter->getPx();
2086 p->py = iter->getPy();
2087 p->pz = iter->getPz();
2088 p->E = iter->getE();
2089 p->dE = iter->getDE();
2090 p->primary_track = iter->getPrimary_track();
2091 p->track = iter->getTrack();
2092 p->part = iter->getPart();
2093 p->radlen = iter->getRadlen();
2094 p->step = iter->getStep();
2095 p->mech = iter->getMech();
2096 data.push_back(p);
2097 }
2098
2099 // Copy into factory
2100 factory->CopyTo(data);
2101
2102 return NOERROR;
2103}
2104
2105//------------------
2106// Extract_DTOFTruth
2107//------------------
2108jerror_t DEventSourceHDDM::Extract_DTOFTruth(hddm_s::HDDM *record,
2109 JFactory<DTOFTruth>* factory, string tag)
2110{
2111 /// Copies the data from the given hddm_s structure. This is called
2112 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2113 /// returns OBJECT_NOT_AVAILABLE immediately.
2114
2115 if (factory == NULL__null)
2116 return OBJECT_NOT_AVAILABLE;
2117 if (tag != "")
2118 return OBJECT_NOT_AVAILABLE;
2119
2120 vector<DTOFTruth*> data;
2121
2122 const hddm_s::FtofTruthPointList &points = record->getFtofTruthPoints();
2123 hddm_s::FtofTruthPointList::iterator iter;
2124 for (iter = points.begin(); iter != points.end(); ++iter) {
2125 DTOFTruth *toftruth = new DTOFTruth;
2126 toftruth->primary = iter->getPrimary();
2127 toftruth->track = iter->getTrack();
2128 toftruth->x = iter->getX();
2129 toftruth->y = iter->getY();
2130 toftruth->z = iter->getZ();
2131 toftruth->t = iter->getT();
2132 toftruth->px = iter->getPx();
2133 toftruth->py = iter->getPy();
2134 toftruth->pz = iter->getPz();
2135 toftruth->E = iter->getE();
2136 toftruth->ptype = iter->getPtype();
2137 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2138 toftruth->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2139 data.push_back(toftruth);
2140 }
2141
2142 // Copy into factory
2143 factory->CopyTo(data);
2144
2145 return NOERROR;
2146}
2147
2148//------------------
2149// Extract_DTOFHit
2150//------------------
2151jerror_t DEventSourceHDDM::Extract_DTOFHit( hddm_s::HDDM *record,
2152 JFactory<DTOFHit>* factory,
2153 JFactory<DTOFHitMC> *factoryMC,
2154 string tag)
2155{
2156 /// Copies the data from the given hddm_s structure. This is called
2157 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2158 /// returns OBJECT_NOT_AVAILABLE immediately.
2159
2160 if (factory == NULL__null)
2161 return OBJECT_NOT_AVAILABLE;
2162 if (tag != "" && tag != "TRUTH")
2163 return OBJECT_NOT_AVAILABLE;
2164
2165 vector<DTOFHit*> data;
2166 vector<DTOFHitMC*> dataMC;
2167
2168 const hddm_s::FtofCounterList &ctrs = record->getFtofCounters();
2169 hddm_s::FtofCounterList::iterator iter;
2170 for (iter = ctrs.begin(); iter != ctrs.end(); ++iter) {
2171 if (tag == "") {
2172 vector<DTOFHit*> north_hits;
2173 vector<DTOFHit*> south_hits;
2174
2175 // Loop over north AND south hits
2176 const hddm_s::FtofHitList &hits = iter->getFtofHits();
2177 hddm_s::FtofHitList::iterator hiter;
2178 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
2179 DTOFHit *tofhit = new DTOFHit;
2180 tofhit->bar = hiter->getBar();
2181 tofhit->plane = hiter->getPlane();
2182 tofhit->end = hiter->getEnd();
2183 tofhit->dE = hiter->getDE();
2184 tofhit->Amp = 0.;
2185 if(hiter->getFtofDigihits().size() > 0) {
2186 tofhit->Amp = hiter->getFtofDigihit().getPeakAmp();
2187 }
2188 tofhit->t = hiter->getT();
2189 tofhit->t_TDC = tofhit->t;
2190 tofhit->t_fADC= tofhit->t;
2191 tofhit->has_TDC=true;
2192 tofhit->has_fADC=true;
2193 data.push_back(tofhit);
2194 if (tofhit->end == 0)
2195 north_hits.push_back(tofhit);
2196 else
2197 south_hits.push_back(tofhit);
2198 }
2199
2200 // return truth hits in a different factory
2201 const hddm_s::FtofTruthHitList &truths = iter->getFtofTruthHits();
2202 hddm_s::FtofTruthHitList::iterator titer;
2203 unsigned int north_mchits = 0;
2204 unsigned int south_mchits = 0;
2205 for (titer = truths.begin(); titer != truths.end(); ++titer) {
2206 DTOFHitMC *tofmchit = new DTOFHitMC;
2207 tofmchit->bar = titer->getBar();
2208 tofmchit->plane = titer->getPlane();
2209 tofmchit->end = titer->getEnd();
2210 tofmchit->itrack = titer->getFtofTruthExtra(0).getItrack();
2211 tofmchit->ptype = titer->getFtofTruthExtra(0).getPtype();
2212 tofmchit->dist = titer->getFtofTruthExtra(0).getDist();
2213 tofmchit->x = titer->getFtofTruthExtra(0).getX();
2214 tofmchit->y = titer->getFtofTruthExtra(0).getY();
2215 tofmchit->z = titer->getFtofTruthExtra(0).getZ();
2216 tofmchit->px = titer->getFtofTruthExtra(0).getPx();
2217 tofmchit->py = titer->getFtofTruthExtra(0).getPy();
2218 tofmchit->pz = titer->getFtofTruthExtra(0).getPz();
2219 tofmchit->E = titer->getFtofTruthExtra(0).getE();
2220 dataMC.push_back(tofmchit);
2221
2222 // best-guess at tofhit-tofMChit association, not exact
2223 if (tofmchit->end == 0) {
2224 if (north_mchits < north_hits.size()) {
2225 north_hits[north_mchits]->AddAssociatedObject(tofmchit);
2226 }
2227 north_mchits++;
2228 }
2229 else {
2230 if (south_mchits < south_hits.size()) {
2231 south_hits[south_mchits]->AddAssociatedObject(tofmchit);
2232 }
2233 south_mchits++;
2234 }
2235 }
2236 }
2237
2238 else if (tag == "TRUTH") {
2239 const hddm_s::FtofTruthHitList &truths = iter->getFtofTruthHits();
2240 hddm_s::FtofTruthHitList::iterator titer;
2241 for (titer = truths.begin(); titer != truths.end(); ++titer) {
2242 DTOFHit *tofhit = new DTOFHit;
2243 tofhit->bar = titer->getBar();
2244 tofhit->plane = titer->getPlane();
2245 tofhit->end = titer->getEnd();
2246 tofhit->dE = titer->getDE();
2247 tofhit->t = titer->getT();
2248 tofhit->t_fADC= tofhit->t;
2249 tofhit->t_TDC = tofhit->t;
2250 tofhit->has_TDC=true;
2251 tofhit->has_fADC=true;
2252 data.push_back(tofhit);
2253
2254 DTOFHitMC *tofmchit = new DTOFHitMC;
2255 tofmchit->bar = tofhit->bar;
2256 tofmchit->plane = tofhit->plane;
2257 tofmchit->end = tofhit->end;
2258 tofmchit->itrack = titer->getFtofTruthExtra().getItrack();
2259 tofmchit->ptype = titer->getFtofTruthExtra().getPtype();
2260 tofmchit->dist = titer->getFtofTruthExtra().getDist();
2261 tofmchit->x = titer->getFtofTruthExtra().getX();
2262 tofmchit->y = titer->getFtofTruthExtra().getY();
2263 tofmchit->z = titer->getFtofTruthExtra().getZ();
2264 tofmchit->px = titer->getFtofTruthExtra().getPx();
2265 tofmchit->py = titer->getFtofTruthExtra().getPy();
2266 tofmchit->pz = titer->getFtofTruthExtra().getPz();
2267 tofmchit->E = titer->getFtofTruthExtra().getE();
2268 dataMC.push_back(tofmchit);
2269 tofhit->AddAssociatedObject(tofmchit);
2270 }
2271 }
2272 }
2273
2274 // Copy into factory
2275 factory->CopyTo(data);
2276 factoryMC->CopyTo(dataMC);
2277
2278 return NOERROR;
2279}
2280
2281//------------------
2282// Extract_DSCHit
2283//------------------
2284jerror_t DEventSourceHDDM::Extract_DSCHit(hddm_s::HDDM *record,
2285 JFactory<DSCHit>* factory, string tag)
2286{
2287 /// Copies the data from the given hddm_s structure. This is called
2288 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2289 /// returns OBJECT_NOT_AVAILABLE immediately.
2290
2291 if (factory == NULL__null)
2292 return OBJECT_NOT_AVAILABLE;
2293 if (tag != "" && tag != "TRUTH")
2294 return OBJECT_NOT_AVAILABLE;
2295
2296 vector<DSCHit*> data;
2297
2298 if (tag == "") {
2299 const hddm_s::StcHitList &hits = record->getStcHits();
2300 hddm_s::StcHitList::iterator iter;
2301 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2302 DSCHit *hit = new DSCHit;
2303 hit->sector = iter->getSector();
2304 hit->dE = iter->getDE();
2305 hit->t = iter->getT();
2306 hit->t_TDC=hit->t;
2307 hit->t_fADC=hit->t;
2308 hit->pulse_height = 0.;
2309 if(iter->getStcDigihits().size() > 0) {
2310 hit->pulse_height = iter->getStcDigihit().getPeakAmp();
2311 }
2312 hit->has_TDC=true;
2313 hit->has_fADC=true;
2314 data.push_back(hit);
2315 }
2316 }
2317 else if (tag == "TRUTH") {
2318 const hddm_s::StcTruthHitList &hits = record->getStcTruthHits();
2319 hddm_s::StcTruthHitList::iterator iter;
2320 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2321 DSCHit *hit = new DSCHit;
2322 hit->sector = iter->getSector();
2323 hit->dE = iter->getDE();
2324 hit->t = iter->getT();
2325 hit->t_TDC=hit->t;
2326 hit->t_fADC=hit->t;
2327 hit->has_TDC=true;
2328 hit->has_fADC=true;
2329 data.push_back(hit);
2330 }
2331 }
2332
2333 // Copy into factory
2334 factory->CopyTo(data);
2335
2336 return NOERROR;
2337}
2338
2339//------------------
2340// Extract_DSCTruthHit
2341//------------------
2342jerror_t DEventSourceHDDM::Extract_DSCTruthHit(hddm_s::HDDM *record,
2343 JFactory<DSCTruthHit>* factory, string tag)
2344{
2345 /// Copies the data from the given hddm_s structure. This is called
2346 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2347 /// returns OBJECT_NOT_AVAILABLE immediately.
2348
2349 if (factory == NULL__null)
2350 return OBJECT_NOT_AVAILABLE;
2351 if (tag != "")
2352 return OBJECT_NOT_AVAILABLE;
2353
2354 vector<DSCTruthHit*> data;
2355
2356 const hddm_s::StcTruthPointList &points = record->getStcTruthPoints();
2357 hddm_s::StcTruthPointList::iterator iter;
2358 for (iter = points.begin(); iter != points.end(); ++iter) {
2359 DSCTruthHit *hit = new DSCTruthHit;
2360 hit->dEdx = iter->getDEdx();
2361 hit->phi = iter->getPhi();
2362 hit->primary = iter->getPrimary();
2363 hit->ptype = iter->getPtype();
2364 hit->r = iter->getR();
2365 hit->t = iter->getT();
2366 hit->z = iter->getZ();
2367 hit->track = iter->getTrack();
2368 hit->sector = iter->getSector();
2369 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2370 hit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2371 data.push_back(hit);
2372 }
2373
2374 // Copy into factory
2375 factory->CopyTo(data);
2376
2377 return NOERROR;
2378}
2379
2380//------------------
2381// Extract_DTrackTimeBased
2382//------------------
2383jerror_t DEventSourceHDDM::Extract_DTrackTimeBased(hddm_s::HDDM *record,
2384 JFactory<DTrackTimeBased> *factory,
2385 string tag, int32_t runnumber, JEventLoop* locEventLoop)
2386{
2387 // Note: Since this is a reconstructed factory, we want to generally return OBJECT_NOT_AVAILABLE
2388 // rather than NOERROR. The reason being that the caller interprets "NOERROR" to mean "yes I
2389 // usually can provide objects of that type, but this event has none." This will cause it to
2390 // skip any attempt at reconstruction. On the other hand, a value of "OBJECT_NOT_AVAILABLE" tells
2391 // it "I cannot provide those type of objects for this event."
2392
2393 if (factory == NULL__null)
2394 return OBJECT_NOT_AVAILABLE;
2395 if (tag != "")
2396 return OBJECT_NOT_AVAILABLE;
2397
2398 vector<DTrackTimeBased*> data;
2399 vector<DReferenceTrajectory*> rts;
2400
2401 const hddm_s::TracktimebasedList &ttbs = record->getTracktimebaseds();
2402 hddm_s::TracktimebasedList::iterator iter;
2403 for (iter = ttbs.begin(); iter != ttbs.end(); ++iter) {
2404 DVector3 mom(iter->getMomentum().getPx(),
2405 iter->getMomentum().getPy(),
2406 iter->getMomentum().getPz());
2407 DVector3 pos(iter->getOrigin().getVx(),
2408 iter->getOrigin().getVy(),
2409 iter->getOrigin().getVz());
2410 DTrackTimeBased *track = new DTrackTimeBased();
2411 track->setMomentum(mom);
2412 track->setPosition(pos);
2413 track->setPID(IDTrack(iter->getProperties().getCharge(),
2414 iter->getProperties().getMass()));
2415 track->chisq = iter->getChisq();
2416 track->Ndof = iter->getNdof();
2417 track->FOM = iter->getFOM();
2418 track->candidateid = iter->getCandidateid();
2419 track->id = iter->getId();
2420
2421 // Reconstitute errorMatrix
2422 auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
2423 locCovarianceMatrix->ResizeTo(7, 7);
2424 string str_vals = iter->getErrorMatrix().getVals();
2425 StringToTMatrixFSym(str_vals, locCovarianceMatrix.get(),
2426 iter->getErrorMatrix().getNrows(),
2427 iter->getErrorMatrix().getNcols());
2428 track->setErrorMatrix(locCovarianceMatrix);
2429
2430 // Reconstitute TrackingErrorMatrix
2431 str_vals = iter->getTrackingErrorMatrix().getVals();
2432 auto TrackingErrorMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
2433 TrackingErrorMatrix->ResizeTo(5, 5);
2434 StringToTMatrixFSym(str_vals, TrackingErrorMatrix.get(),
2435 iter->getTrackingErrorMatrix().getNrows(),
2436 iter->getTrackingErrorMatrix().getNcols());
2437 track->setTrackingErrorMatrix(TrackingErrorMatrix);
2438
2439 data.push_back(track);
2440 }
2441
2442 // Copy into factory
2443 if (ttbs.size() > 0){
2444 factory->CopyTo(data);
2445
2446 // If the event had a s_Tracktimebased_t pointer, then report
2447 // back that we read them in from the file. Otherwise, report
2448 // OBJECT_NOT_AVAILABLE
2449 return NOERROR;
2450 }
2451
2452 // If we get to here then there was not even a placeholder in the HDDM file.
2453 // Return OBJECT_NOT_AVAILABLE to indicate reconstruction should be tried.
2454 return OBJECT_NOT_AVAILABLE;
2455}
2456
2457
2458//-------------------------------
2459// StringToTMatrixFSym
2460//-------------------------------
2461string DEventSourceHDDM::StringToTMatrixFSym(string &str_vals, TMatrixFSym* mat,
2462 int Nrows, int Ncols)
2463{
2464 /// This is the inverse of the DMatrixDSymToString method in the
2465 /// danahddm plugin.
2466
2467 // Convert the given string into a symmetric matrix
2468 mat->ResizeTo(Nrows, Ncols);
2469 stringstream ss(str_vals);
2470 for (int irow=0; irow<mat->GetNrows(); irow++) {
2471 for (int icol=irow; icol<mat->GetNcols(); icol++) {
2472 ss >> (*mat)[irow][icol];
2473 (*mat)[icol][irow] = (*mat)[irow][icol];
2474 }
2475 }
2476
2477 return ss.str();
2478}
2479
2480//------------------
2481// Extract_DTAGMHit
2482//------------------
2483jerror_t DEventSourceHDDM::Extract_DTAGMHit(hddm_s::HDDM *record,
2484 JFactory<DTAGMHit>* factory,
2485 string tag)
2486{
2487 /// Copies the data from the given hddm_s structure. This is called
2488 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2489 /// returns OBJECT_NOT_AVAILABLE immediately.
2490
2491 if (factory == NULL__null)
2492 return OBJECT_NOT_AVAILABLE;
2493 if (tag != "" && tag != "TRUTH")
2494 return OBJECT_NOT_AVAILABLE;
2495
2496 vector<DTAGMHit*> data;
2497
2498 // loop over microChannel/taggerHit records
2499 const hddm_s::MicroChannelList &tags = record->getMicroChannels();
2500 hddm_s::MicroChannelList::iterator iter;
2501 for (iter = tags.begin(); iter != tags.end(); ++iter) {
2502 if (tag == "") {
2503 const hddm_s::TaggerHitList &hits = iter->getTaggerHits();
2504 hddm_s::TaggerHitList::iterator hiter;
2505 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
2506 DTAGMHit *taghit = new DTAGMHit();
2507 taghit->E = hiter->getE();
2508 taghit->t = hiter->getT();
2509 taghit->npix_fadc = hiter->getNpe();
2510 taghit->time_fadc = hiter->getTADC();
2511 taghit->column = hiter->getColumn();
2512 taghit->row = hiter->getRow();
2513 taghit->has_fADC = true;
2514 taghit->has_TDC = true;
2515 data.push_back(taghit);
2516 }
2517 }
2518 else if (tag == "TRUTH") {
2519 const hddm_s::TaggerTruthHitList &hits = iter->getTaggerTruthHits();
2520 hddm_s::TaggerTruthHitList::iterator hiter;
2521 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
2522 DTAGMHit *taghit = new DTAGMHit();
2523 taghit->E = hiter->getE();
2524 taghit->t = hiter->getT();
2525 taghit->npix_fadc = hiter->getDE() * 1e5; // ~1e5 pixels/GeV
2526 taghit->time_fadc = hiter->getT();
2527 taghit->column = hiter->getColumn();
2528 taghit->row = hiter->getRow();
2529 taghit->has_fADC = true;
2530 taghit->has_TDC = true;
2531 taghit->bg = hiter->getBg();
2532 data.push_back(taghit);
2533 }
2534 }
2535 }
2536
2537 // Copy into factory
2538 factory->CopyTo(data);
2539
2540 return NOERROR;
2541}
2542
2543//------------------
2544// Extract_DTAGHHit
2545//------------------
2546jerror_t DEventSourceHDDM::Extract_DTAGHHit( hddm_s::HDDM *record,
2547 JFactory<DTAGHHit>* factory,
2548 string tag)
2549{
2550 /// Copies the data from the given hddm_s structure. This is called
2551 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2552 /// returns OBJECT_NOT_AVAILABLE immediately.
2553
2554 if (factory == NULL__null)
2555 return OBJECT_NOT_AVAILABLE;
2556 if (tag != "" && tag != "TRUTH")
2557 return OBJECT_NOT_AVAILABLE;
2558
2559 vector<DTAGHHit*> data;
2560
2561 // loop over hodoChannel/taggerHit records
2562 const hddm_s::HodoChannelList &tags = record->getHodoChannels();
2563 hddm_s::HodoChannelList::iterator iter;
2564 for (iter = tags.begin(); iter != tags.end(); ++iter) {
2565 if (tag == "") {
2566 const hddm_s::TaggerHitList &hits = iter->getTaggerHits();
2567 hddm_s::TaggerHitList::iterator hiter;
2568 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
2569 DTAGHHit *taghit = new DTAGHHit();
2570 taghit->E = hiter->getE();
2571 taghit->t = hiter->getT();
2572 taghit->npe_fadc = hiter->getNpe();
2573 taghit->time_fadc = hiter->getTADC();
2574 taghit->counter_id = hiter->getCounterId();
2575 taghit->has_fADC = true;
2576 taghit->has_TDC = true;
2577 data.push_back(taghit);
2578 }
2579 }
2580 else if (tag == "TRUTH") {
2581 const hddm_s::TaggerTruthHitList &hits = iter->getTaggerTruthHits();
2582 hddm_s::TaggerTruthHitList::iterator hiter;
2583 for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
2584 DTAGHHit *taghit = new DTAGHHit();
2585 taghit->E = hiter->getE();
2586 taghit->t = hiter->getT();
2587 taghit->npe_fadc = hiter->getDE() * 5e5; // ~5e5 pe/GeV
2588 taghit->time_fadc = hiter->getT();
2589 taghit->counter_id = hiter->getCounterId();
2590 taghit->has_fADC = true;
2591 taghit->has_TDC = true;
2592 taghit->bg = hiter->getBg();
2593
2594 data.push_back(taghit);
2595 }
2596 }
2597 }
2598
2599 // Copy into factory
2600 factory->CopyTo(data);
2601
2602 return NOERROR;
2603}
2604
2605//------------------
2606// Extract_DPSHit
2607//------------------
2608jerror_t DEventSourceHDDM::Extract_DPSHit(hddm_s::HDDM *record,
2609 JFactory<DPSHit>* factory, string tag)
2610{
2611 /// Copies the data from the given hddm_s structure. This is called
2612 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2613 /// returns OBJECT_NOT_AVAILABLE immediately.
2614
2615 if (factory == NULL__null)
2616 return OBJECT_NOT_AVAILABLE;
2617 if (tag != "" && tag != "TRUTH")
2618 return OBJECT_NOT_AVAILABLE;
2619
2620 vector<DPSHit*> data;
2621
2622 if (tag == "") {
2623 const hddm_s::PsHitList &hits = record->getPsHits();
2624 hddm_s::PsHitList::iterator iter;
2625 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2626 DPSHit *hit = new DPSHit;
2627 if(iter->getArm() == 0)
2628 hit->arm = DPSGeometry::Arm::kNorth;
2629 else
2630 hit->arm = DPSGeometry::Arm::kSouth;
2631 hit->column = iter->getColumn();
2632 double npix_fadc = iter->getDE()*0.5e5; // 100 pixels in 2 MeV
2633 hit->npix_fadc = npix_fadc;
2634 hit->t = iter->getT();
2635
2636 hit->E = 0.5*(psGeom->getElow(hit->arm,hit->column) + psGeom->getEhigh(hit->arm,hit->column));
2637 hit->pulse_peak = npix_fadc*21; // 1 pixel 21 fadc counts
2638 hit->integral = npix_fadc*21*5.1; // integral/peak = 5.1
2639 data.push_back(hit);
2640 }
2641 }
2642 else if (tag == "TRUTH") {
2643 const hddm_s::PsTruthHitList &hits = record->getPsTruthHits();
2644 hddm_s::PsTruthHitList::iterator iter;
2645 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2646 DPSHit *hit = new DPSHit;
2647 if(iter->getArm() == 0)
2648 hit->arm = DPSGeometry::Arm::kNorth;
2649 else
2650 hit->arm = DPSGeometry::Arm::kSouth;
2651 hit->column = iter->getColumn();
2652 hit->npix_fadc = iter->getDE() * 1e5; // ~1e5 pixels/GeV
2653 hit->t = iter->getT();
2654 data.push_back(hit);
2655 }
2656 }
2657
2658 // Copy into factory
2659 factory->CopyTo(data);
2660
2661 return NOERROR;
2662}
2663
2664//------------------
2665// Extract_DPSTruthHit
2666//------------------
2667jerror_t DEventSourceHDDM::Extract_DPSTruthHit(hddm_s::HDDM *record,
2668 JFactory<DPSTruthHit>* factory, string tag)
2669{
2670 /// Copies the data from the given hddm_s structure. This is called
2671 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2672 /// returns OBJECT_NOT_AVAILABLE immediately.
2673
2674 if (factory == NULL__null)
2675 return OBJECT_NOT_AVAILABLE;
2676 if (tag != "")
2677 return OBJECT_NOT_AVAILABLE;
2678
2679 vector<DPSTruthHit*> data;
2680
2681 const hddm_s::PsTruthPointList &points = record->getPsTruthPoints();
2682 hddm_s::PsTruthPointList::iterator iter;
2683 for (iter = points.begin(); iter != points.end(); ++iter) {
2684 DPSTruthHit *hit = new DPSTruthHit;
2685 hit->dEdx = iter->getDEdx();
2686 hit->primary = iter->getPrimary();
2687 hit->ptype = iter->getPtype();
2688 hit->t = iter->getT();
2689 hit->x = iter->getX();
2690 hit->y = iter->getY();
2691 hit->z = iter->getZ();
2692 hit->track = iter->getTrack();
2693 hit->column = iter->getColumn();
2694 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2695 hit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2696 data.push_back(hit);
2697 }
2698
2699 // Copy into factory
2700 factory->CopyTo(data);
2701
2702 return NOERROR;
2703}
2704
2705//------------------
2706// Extract_DPSCHit
2707//------------------
2708jerror_t DEventSourceHDDM::Extract_DPSCHit(hddm_s::HDDM *record,
2709 JFactory<DPSCHit>* factory, string tag)
2710{
2711 /// Copies the data from the given hddm_s structure. This is called
2712 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2713 /// returns OBJECT_NOT_AVAILABLE immediately.
2714
2715 if (factory == NULL__null)
2716 return OBJECT_NOT_AVAILABLE;
2717 if (tag != "" && tag != "TRUTH")
2718 return OBJECT_NOT_AVAILABLE;
2719
2720 vector<DPSCHit*> data;
2721
2722 if (tag == "") {
2723 const hddm_s::PscHitList &hits = record->getPscHits();
2724 hddm_s::PscHitList::iterator iter;
2725 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2726 DPSCHit *hit = new DPSCHit;
2727 if(iter->getArm() == 0)
2728 hit->arm = DPSGeometry::Arm::kNorth;
2729 else
2730 hit->arm = DPSGeometry::Arm::kSouth;
2731 hit->module = iter->getModule();
2732
2733 double npe_fadc = iter->getDE()*2.5e5;
2734 hit->npe_fadc = npe_fadc;
2735 hit->pulse_peak = npe_fadc*0.4; // 1000 pe - 400 fadc count
2736 hit->integral = npe_fadc*0.4*3; // integral/peak = 3.
2737
2738 hit->t = iter->getT();
2739 hit->time_tdc = iter->getT();
2740 hit->time_fadc = iter->getT();
2741
2742 hit->has_fADC = true;
2743 hit->has_TDC = true;
2744
2745 data.push_back(hit);
2746 }
2747 }
2748 else if (tag == "TRUTH") {
2749 const hddm_s::PscTruthHitList &hits = record->getPscTruthHits();
2750 hddm_s::PscTruthHitList::iterator iter;
2751 for (iter = hits.begin(); iter != hits.end(); ++iter) {
2752 DPSCHit *hit = new DPSCHit;
2753 if(iter->getArm() == 0)
2754 hit->arm = DPSGeometry::Arm::kNorth;
2755 else
2756 hit->arm = DPSGeometry::Arm::kSouth;
2757 hit->module = iter->getModule();
2758 hit->npe_fadc = iter->getDE() * 5e5; // ~5e5 pe/GeV
2759 hit->t = iter->getT();
2760 data.push_back(hit);
2761 }
2762 }
2763
2764 // Copy into factory
2765 factory->CopyTo(data);
2766
2767 return NOERROR;
2768}
2769
2770//------------------
2771// Extract_DPSCTruthHit
2772//------------------
2773jerror_t DEventSourceHDDM::Extract_DPSCTruthHit(hddm_s::HDDM *record,
2774 JFactory<DPSCTruthHit>* factory, string tag)
2775{
2776 /// Copies the data from the given hddm_s structure. This is called
2777 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2778 /// returns OBJECT_NOT_AVAILABLE immediately.
2779
2780 if (factory == NULL__null)
2781 return OBJECT_NOT_AVAILABLE;
2782 if (tag != "")
2783 return OBJECT_NOT_AVAILABLE;
2784
2785 vector<DPSCTruthHit*> data;
2786
2787 const hddm_s::PscTruthPointList &points = record->getPscTruthPoints();
2788 hddm_s::PscTruthPointList::iterator iter;
2789 for (iter = points.begin(); iter != points.end(); ++iter) {
2790 DPSCTruthHit *hit = new DPSCTruthHit;
2791 hit->dEdx = iter->getDEdx();
2792 hit->primary = iter->getPrimary();
2793 hit->ptype = iter->getPtype();
2794 hit->t = iter->getT();
2795 hit->x = iter->getX();
2796 hit->y = iter->getY();
2797 hit->z = iter->getZ();
2798 hit->track = iter->getTrack();
2799 hit->column = iter->getModule();
2800 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2801 hit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2802 data.push_back(hit);
2803 }
2804
2805 // Copy into factory
2806 factory->CopyTo(data);
2807
2808 return NOERROR;
2809}
2810
2811//------------------
2812// Etract_DTPOLHit
2813//------------------
2814jerror_t DEventSourceHDDM::Extract_DTPOLHit(hddm_s::HDDM *record,
2815 JFactory<DTPOLHit>* factory, string tag)
2816{
2817 if (factory == NULL__null)
2818 return OBJECT_NOT_AVAILABLE;
2819 if (tag != "")
2820 return OBJECT_NOT_AVAILABLE;
2821
2822 vector<DTPOLHit*> data;
2823
2824 if (tag == "")
2825 {
2826 const hddm_s::TpolHitList &hits = record->getTpolHits();
2827 hddm_s::TpolHitList::iterator iter;
2828 for (iter = hits.begin(); iter != hits.end(); ++iter)
2829 {
2830 DTPOLHit *hit = new DTPOLHit;
2831 hit->sector = iter->getSector();
2832 hit->ring = iter->getRing();
2833 hit->dE = iter->getDE();
2834 hit->t = iter->getT();
2835
2836 data.push_back(hit);
2837 }
2838 }
2839 else if (tag == "Truth")
2840 {
2841 const hddm_s::TpolTruthHitList &truthHits = record->getTpolTruthHits();
2842 hddm_s::TpolTruthHitList::iterator iter;
2843 for (iter = truthHits.begin(); iter != truthHits.end(); ++iter)
2844 {
2845 DTPOLHit *hit = new DTPOLHit;
2846 hit->sector = iter->getSector();
2847 hit->t = iter->getT();
2848
2849 data.push_back(hit);
2850 }
2851 }
2852
2853 factory->CopyTo(data);
2854
2855 return NOERROR;
2856}
2857
2858//------------------------
2859// Extract_DTPOLTruthHit
2860//------------------------
2861jerror_t DEventSourceHDDM::Extract_DTPOLTruthHit(hddm_s::HDDM *record, JFactory<DTPOLTruthHit>* factory, string tag)
2862{
2863 if (factory == NULL__null)
2864 return OBJECT_NOT_AVAILABLE;
2865 if (tag != "")
2866 return OBJECT_NOT_AVAILABLE;
2867
2868 vector<DTPOLTruthHit*> data;
2869
2870 const hddm_s::TpolTruthPointList &points = record->getTpolTruthPoints();
2871 hddm_s::TpolTruthPointList::iterator iter;
2872 for (iter = points.begin(); iter != points.end(); ++iter)
2873 {
2874 DTPOLTruthHit *hit = new DTPOLTruthHit;
2875 hit->dEdx = iter->getDEdx();
2876 hit->primary = iter->getPrimary();
2877 hit->track = iter->getTrack();
2878 hit->ptype = iter->getPtype();
2879 hit->r = iter->getR();
2880 hit->phi = iter->getPhi();
2881 hit->t = iter->getT();
2882 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2883 hit->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2884
2885 data.push_back(hit);
2886 }
2887
2888 factory->CopyTo(data);
2889
2890 return NOERROR;
2891}
2892
2893Particle_t DEventSourceHDDM::IDTrack(float locCharge, float locMass) const
2894{
2895 float locMassTolerance = 0.010;
2896 if (locCharge > 0.1) // Positive particles
2897 {
2898 if (fabs(locMass - ParticleMass(Proton)) < locMassTolerance) return Proton;
2899 if (fabs(locMass - ParticleMass(PiPlus)) < locMassTolerance) return PiPlus;
2900 if (fabs(locMass - ParticleMass(KPlus)) < locMassTolerance) return KPlus;
2901 if (fabs(locMass - ParticleMass(Positron)) < locMassTolerance) return Positron;
2902 if (fabs(locMass - ParticleMass(MuonPlus)) < locMassTolerance) return MuonPlus;
2903 }
2904 else if(locCharge < -0.1) // Negative particles
2905 {
2906 if (fabs(locMass - ParticleMass(PiMinus)) < locMassTolerance) return PiMinus;
2907 if (fabs(locMass - ParticleMass(KMinus)) < locMassTolerance) return KMinus;
2908 if (fabs(locMass - ParticleMass(MuonMinus)) < locMassTolerance) return MuonMinus;
2909 if (fabs(locMass - ParticleMass(Electron)) < locMassTolerance) return Electron;
2910 if (fabs(locMass - ParticleMass(AntiProton)) < locMassTolerance) return AntiProton;
2911 }
2912 else //Neutral Track
2913 {
2914 if (fabs(locMass - ParticleMass(Gamma)) < locMassTolerance) return Gamma;
2915 if (fabs(locMass - ParticleMass(Neutron)) < locMassTolerance) return Neutron;
2916 }
2917 return Unknown;
2918}
2919
2920//------------------
2921// Extract_DFMWPCTruthHit
2922//------------------
2923jerror_t DEventSourceHDDM::Extract_DFMWPCTruthHit(hddm_s::HDDM *record, JFactory<DFMWPCTruthHit> *factory, string tag)
2924{
2925 /// Copies the data from the given hddm_s record. This is called
2926 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2927 /// returns OBJECT_NOT_AVAILABLE immediately.
2928
2929 if (factory == NULL__null) return OBJECT_NOT_AVAILABLE;
2930 if (tag != "") return OBJECT_NOT_AVAILABLE;
2931
2932 vector<DFMWPCTruthHit*> data;
2933
2934 const hddm_s::FmwpcTruthHitList &points = record->getFmwpcTruthHits();
2935 hddm_s::FmwpcTruthHitList::iterator iter;
2936 for (iter = points.begin(); iter != points.end(); ++iter) {
2937 DFMWPCTruthHit *hit = new DFMWPCTruthHit;
2938 hit->layer = iter->getLayer();
2939 hit->wire = iter->getWire();
2940 hit->dE = iter->getDE();
2941 hit->t = iter->getT();
2942 const hddm_s::FmwpcTruthHitQList &charges=iter->getFmwpcTruthHitQs();
2943 hit->q = (charges.size()) ? charges.begin()->getQ() : 0.;
2944 hit->d = (charges.size()) ? charges.begin()->getD() : 0.;
2945 data.push_back(hit);
2946 }
2947
2948 // Copy into factory
2949 factory->CopyTo(data);
2950
2951 return NOERROR;
2952}
2953
2954
2955//------------------
2956// Extract_DFMWPCTruth
2957//------------------
2958jerror_t DEventSourceHDDM::Extract_DFMWPCTruth(hddm_s::HDDM *record,
2959 JFactory<DFMWPCTruth>* factory, string tag)
2960{
2961 /// Copies the data from the given hddm_s structure. This is called
2962 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
2963 /// returns OBJECT_NOT_AVAILABLE immediately.
2964
2965 if (factory == NULL__null)
2966 return OBJECT_NOT_AVAILABLE;
2967 if (tag != "")
2968 return OBJECT_NOT_AVAILABLE;
2969
2970 vector<DFMWPCTruth*> data;
2971
2972 const hddm_s::FmwpcTruthPointList &points = record->getFmwpcTruthPoints();
2973 hddm_s::FmwpcTruthPointList::iterator iter;
2974 for (iter = points.begin(); iter != points.end(); ++iter) {
2975 DFMWPCTruth *fmwpctruth = new DFMWPCTruth;
2976 fmwpctruth->primary = iter->getPrimary();
2977 fmwpctruth->track = iter->getTrack();
2978 fmwpctruth->x = iter->getX();
2979 fmwpctruth->y = iter->getY();
2980 fmwpctruth->z = iter->getZ();
2981 fmwpctruth->t = iter->getT();
2982 fmwpctruth->px = iter->getPx();
2983 fmwpctruth->py = iter->getPy();
2984 fmwpctruth->pz = iter->getPz();
2985 fmwpctruth->E = iter->getE();
2986 fmwpctruth->ptype = iter->getPtype();
2987 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
2988 fmwpctruth->itrack = (ids.size())? ids.begin()->getItrack() : 0;
2989 data.push_back(fmwpctruth);
2990 }
2991
2992 // Copy into factory
2993 factory->CopyTo(data);
2994
2995 return NOERROR;
2996}
2997
2998//------------------
2999// Extract_DFMWPCHit
3000//------------------
3001jerror_t DEventSourceHDDM::Extract_DFMWPCHit(hddm_s::HDDM *record, JFactory<DFMWPCHit> *factory, string tag)
3002{
3003 /// Copies the data from the given hddm_s record. This is called
3004 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3005 /// returns OBJECT_NOT_AVAILABLE immediately.
3006
3007 if (factory == NULL__null) return OBJECT_NOT_AVAILABLE;
3008 if (tag != "") return OBJECT_NOT_AVAILABLE;
3009
3010 vector<DFMWPCHit*> data;
3011
3012 const hddm_s::FmwpcHitList &points = record->getFmwpcHits();
3013 hddm_s::FmwpcHitList::iterator iter;
3014 for (iter = points.begin(); iter != points.end(); ++iter) {
3015 DFMWPCHit *hit = new DFMWPCHit;
3016 hit->layer = iter->getLayer();
3017 hit->wire = iter->getWire();
3018 hit->t = iter->getT();
3019 const hddm_s::FmwpcHitQList &charges=iter->getFmwpcHitQs();
3020 hit->q = (charges.size()) ? charges.begin()->getQ() : 0.;
3021 hit->amp = (charges.size()) ? hit->q/28.8 : 0.; // copied from CDC
3022 data.push_back(hit);
3023 }
3024
3025 // Copy into factory
3026 factory->CopyTo(data);
3027
3028 return NOERROR;
3029}
3030
3031
3032//------------------
3033// Extract_DCTOFTruth
3034//------------------
3035jerror_t DEventSourceHDDM::Extract_DCTOFTruth(hddm_s::HDDM *record,
3036 JFactory<DCTOFTruth>* factory, string tag)
3037{
3038 /// Copies the data from the given hddm_s structure. This is called
3039 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3040 /// returns OBJECT_NOT_AVAILABLE immediately.
3041
3042 if (factory == NULL__null)
3043 return OBJECT_NOT_AVAILABLE;
3044 if (tag != "")
3045 return OBJECT_NOT_AVAILABLE;
3046
3047 vector<DCTOFTruth*> data;
3048
3049 const hddm_s::CtofTruthPointList &points = record->getCtofTruthPoints();
3050 hddm_s::CtofTruthPointList::iterator iter;
3051 for (iter = points.begin(); iter != points.end(); ++iter) {
3052 DCTOFTruth *ctoftruth = new DCTOFTruth;
3053 ctoftruth->primary = iter->getPrimary();
3054 ctoftruth->track = iter->getTrack();
3055 ctoftruth->x = iter->getX();
3056 ctoftruth->y = iter->getY();
3057 ctoftruth->z = iter->getZ();
3058 ctoftruth->t = iter->getT();
3059 ctoftruth->px = iter->getPx();
3060 ctoftruth->py = iter->getPy();
3061 ctoftruth->pz = iter->getPz();
3062 ctoftruth->E = iter->getE();
3063 ctoftruth->ptype = iter->getPtype();
3064 const hddm_s::TrackIDList &ids = iter->getTrackIDs();
3065 ctoftruth->itrack = (ids.size())? ids.begin()->getItrack() : 0;
3066 data.push_back(ctoftruth);
3067 }
3068
3069 // Copy into factory
3070 factory->CopyTo(data);
3071
3072 return NOERROR;
3073}
3074
3075
3076//------------------
3077// Extract_DCTOFHit
3078//------------------
3079jerror_t DEventSourceHDDM::Extract_DCTOFHit(hddm_s::HDDM *record, JFactory<DCTOFHit> *factory, string tag)
3080{
3081 /// Copies the data from the given hddm_s record. This is called
3082 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3083 /// returns OBJECT_NOT_AVAILABLE immediately.
3084
3085 if (factory == NULL__null) return OBJECT_NOT_AVAILABLE;
3086 if (tag != "") return OBJECT_NOT_AVAILABLE;
3087
3088 vector<DCTOFHit*> data;
3089
3090 const hddm_s::CtofHitList &points = record->getCtofHits();
3091 hddm_s::CtofHitList::iterator iter;
3092 for (iter = points.begin(); iter != points.end(); ++iter) {
3093 DCTOFHit *hit = new DCTOFHit;
3094 hit->bar = iter->getBar();
3095 hit->end = iter->getEnd();
3096 hit->dE = iter->getDE();
3097 hit->t = iter->getT();
3098 hit->t_adc = hit->t;
3099 data.push_back(hit);
3100 }
3101
3102 // Copy into factory
3103 factory->CopyTo(data);
3104
3105 return NOERROR;
3106}
3107
3108//------------------
3109// Extract_DDIRCPmtHit
3110//------------------
3111jerror_t DEventSourceHDDM::Extract_DDIRCPmtHit(hddm_s::HDDM *record,
3112 JFactory<DDIRCPmtHit> *factory, string tag,
3113 JEventLoop* eventLoop)
3114{
3115 /// Copies the data from the given hddm_s structure. This is called
3116 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3117 /// returs OBJECT_NOT_AVAILABLE immediately.
3118
3119 if (factory == NULL__null)
3120 return OBJECT_NOT_AVAILABLE;
3121 if (tag != "")
3122 return OBJECT_NOT_AVAILABLE;
3123
3124 vector<DDIRCPmtHit*> data;
3125
3126 if (tag == "") {
3127 vector<const DDIRCTruthPmtHit*> locDIRCTruthPmtHit;
3128 eventLoop->Get(locDIRCTruthPmtHit);
3129
3130 const hddm_s::DircPmtHitList &hits = record->getDircPmtHits();
3131 hddm_s::DircPmtHitList::iterator iter;
3132 for (iter = hits.begin(); iter != hits.end(); ++iter) {
3133 double time = iter->getT();
3134 int channel = iter->getCh();
3135
3136 DDIRCPmtHit *hit = new DDIRCPmtHit();
3137 hit->t = time;
3138 hit->ch = channel;
3139
3140 for (auto& iterTruth : locDIRCTruthPmtHit) { //.begin(); iterTruth != locDIRCTruthPmtHit.end(); ++iterTruth) {
3141
3142 // must match channel and time
3143 if(channel == iterTruth->ch && fabs(time-iterTruth->t) < 5.0) {
3144
3145 hit->AddAssociatedObject(iterTruth);
3146
3147 break;
3148 }
3149 }
3150
3151 data.push_back(hit);
3152 }
3153 }
3154
3155 // Copy into factory
3156 factory->CopyTo(data);
3157
3158 return NOERROR;
3159}
3160
3161//------------------
3162// Extract_DCereHit
3163// added by yqiang Oct 11, 2012
3164//------------------
3165jerror_t DEventSourceHDDM::Extract_DCereHit(hddm_s::HDDM *record,
3166 JFactory<DCereHit>* factory, string tag)
3167{
3168 if (factory == NULL__null)
3169 return OBJECT_NOT_AVAILABLE;
3170 if (tag != "" && tag != "TRUTH")
3171 return OBJECT_NOT_AVAILABLE;
3172
3173 vector<DCereHit*> data;
3174
3175 if (tag == "") {
3176 const hddm_s::CereHitList &hits = record->getCereHits();
3177 hddm_s::CereHitList::iterator iter;
3178 for (iter = hits.begin(); iter != hits.end(); ++iter) {
3179 DCereHit *hit = new DCereHit;
3180 hit->sector = iter->getSector();
3181 hit->pe = iter->getPe();
3182 hit->t = iter->getT();
3183 data.push_back(hit);
3184 }
3185 }
3186 else if (tag == "TRUTH") {
3187 const hddm_s::CereTruthHitList &hits = record->getCereTruthHits();
3188 hddm_s::CereTruthHitList::iterator iter;
3189 for (iter = hits.begin(); iter != hits.end(); ++iter) {
3190 DCereHit *hit = new DCereHit;
3191 hit->sector = iter->getSector();
3192 hit->pe = iter->getPe();
3193 hit->t = iter->getT();
3194 data.push_back(hit);
3195 }
3196 }
3197
3198 // copy into factory
3199 factory->CopyTo(data);
3200
3201 return NOERROR;
3202}
3203
3204//------------------
3205// Extract_DDIRCTruthBarHit
3206//------------------
3207jerror_t DEventSourceHDDM::Extract_DDIRCTruthBarHit(hddm_s::HDDM *record,
3208 JFactory<DDIRCTruthBarHit>* factory, string tag)
3209{
3210 /// Copies the data from the given hddm_s structure. This is called
3211 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3212 /// returns OBJECT_NOT_AVAILABLE immediately.
3213
3214 if (factory == NULL__null)
3215 return OBJECT_NOT_AVAILABLE;
3216 if (tag != "")
3217 return OBJECT_NOT_AVAILABLE;
3218
3219 vector<DDIRCTruthBarHit*> data;
3220
3221 const hddm_s::DircTruthBarHitList &hits = record->getDircTruthBarHits();
3222 hddm_s::DircTruthBarHitList::iterator iter;
3223 for (iter = hits.begin(); iter != hits.end(); ++iter) {
3224 DDIRCTruthBarHit *hit = new DDIRCTruthBarHit;
3225 hit->x = iter->getX();
3226 hit->y = iter->getY();
3227 hit->z = iter->getZ();
3228 hit->px = iter->getPx();
3229 hit->py = iter->getPy();
3230 hit->pz = iter->getPz();
3231 hit->t = iter->getT();
3232 hit->E = iter->getE();
3233 hit->pdg = iter->getPdg();
3234 hit->bar = iter->getBar();
3235 hit->track = iter->getTrack();
3236 data.push_back(hit);
3237 }
3238
3239 // Copy into factory
3240 factory->CopyTo(data);
3241
3242 return NOERROR;
3243}
3244
3245//------------------
3246// Extract_DDIRCTruthPmtHit
3247//------------------
3248jerror_t DEventSourceHDDM::Extract_DDIRCTruthPmtHit(hddm_s::HDDM *record,
3249 JFactory<DDIRCTruthPmtHit>* factory, string tag)
3250{
3251 /// Copies the data from the given hddm_s structure. This is called
3252 /// from JEventSourceHDDM::GetObjects. If factory is NULL, this
3253 /// returns OBJECT_NOT_AVAILABLE immediately.
3254
3255 if (factory == NULL__null)
3256 return OBJECT_NOT_AVAILABLE;
3257 if (tag != "")
3258 return OBJECT_NOT_AVAILABLE;
3259
3260 vector<DDIRCTruthPmtHit*> data;
3261
3262
3263 const hddm_s::DircTruthPmtHitList &hits = record->getDircTruthPmtHits();
3264 hddm_s::DircTruthPmtHitList::iterator iter;
3265 for (iter = hits.begin(); iter != hits.end(); ++iter) {
3266 DDIRCTruthPmtHit *hit = new DDIRCTruthPmtHit;
3267 hit->x = iter->getX();
3268 hit->y = iter->getY();
3269 hit->z = iter->getZ();
3270 hit->t = iter->getT();
3271 hit->E = iter->getE();
3272 hit->ch = iter->getCh();
3273 hit->key_bar = iter->getKey_bar();
3274 hddm_s::DircTruthPmtHitExtraList &hitextras = iter->getDircTruthPmtHitExtras();
3275 if(hitextras.size() > 0) {
3276 hit->t_fixed = hitextras(0).getT_fixed();
3277 hit->path = hitextras(0).getPath();
3278 hit->refl = hitextras(0).getRefl();
3279 hit->bbrefl = hitextras(0).getBbrefl();
3280 }
3281 data.push_back(hit);
3282 }
3283
3284 // Copy into factory
3285 factory->CopyTo(data);
3286
3287 return NOERROR;
3288}