Bug Summary

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