// $Id$ // // Author: David Lawrence June 24, 2004 // // // DEventSourceHDDM methods // #include #include using namespace std; #include #include #include #include "DEventSourceHDDM.h" #include "FDC/DFDCGeometry.h" #include "FCAL/DFCALGeometry.h" //------------------------------------------------------------------ // Binary predicate used to sort hits //------------------------------------------------------------------ class MCTrackHitSort{ public: bool operator()(DMCTrackHit* const &thit1, DMCTrackHit* const &thit2) const { return thit1->z < thit2->z; } }; bool MCTrackHitSort_C(DMCTrackHit* const &thit1, DMCTrackHit* const &thit2) { return thit1->z < thit2->z; } //---------------- // Constructor //---------------- DEventSourceHDDM::DEventSourceHDDM(const char* source_name):JEventSource(source_name) { /// Constructor for DEventSourceHDDM object fin = open_s_HDDM((char*)source_name); hddm_s = NULL; if(fin)source_is_open = 1; flush_on_free = true; } //---------------- // Destructor //---------------- DEventSourceHDDM::~DEventSourceHDDM() { // Close file and set pointers to NULL if(fin)close_s_HDDM(fin); hddm_s = NULL; fin = NULL; } //---------------- // GetEvent //---------------- jerror_t DEventSourceHDDM::GetEvent(JEvent &event) { /// Implementation of JEventSource virtual function if(!fin){ return EVENT_SOURCE_NOT_OPEN; } hddm_s = read_s_HDDM(fin); // each open HDDM file takes up about 1M of memory so it's // worthwhile to close it as soon as we can if(!hddm_s){ if(fin)close_s_HDDM(fin); fin = NULL; return NO_MORE_EVENTS_IN_SOURCE; } ++Nevents_read; int event_number = -1; int run_number = -1; // Get event/run numbers from HDDM s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(PE && PE->mult>0){ event_number = PE->in[0].eventNo; run_number = PE->in[0].runNo; } // Copy the reference info into the JEvent object event.SetJEventSource(this); event.SetEventNumber(event_number); event.SetRunNumber(run_number); event.SetRef(hddm_s); return NOERROR; } //---------------- // FreeEvent //---------------- void DEventSourceHDDM::FreeEvent(JEvent &event) { s_HDDM_t *my_hddm_s = (s_HDDM_t*)event.GetRef(); if(flush_on_free && my_hddm_s!=NULL)flush_s_HDDM(my_hddm_s, 0); } //---------------- // GetObjects //---------------- jerror_t DEventSourceHDDM::GetObjects(JEvent &event, JFactory_base *factory) { /// This gets called through the virtual method of the /// JEventSource base class. It creates the objects of the type /// on which factory is based. It uses the s_HDDM_t object /// kept in the ref field of the JEvent object passed. // We must have a factory to hold the data if(!factory)throw RESOURCE_UNAVAILABLE; // HDDM doesn't support tagged factories if(strcmp(factory->Tag(), ""))return OBJECT_NOT_AVAILABLE; // The ref field of the JEvent is just the s_HDDM_t pointer. s_HDDM_t *my_hddm_s = (s_HDDM_t*)event.GetRef(); if(!my_hddm_s)throw RESOURCE_UNAVAILABLE; // Get name of data class we're trying to extract string dataClassName = factory->dataClassName(); if(dataClassName =="DMCTrackHit") return Extract_DMCTrackHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DMCThrown") return Extract_DMCThrown(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DBCALHit") return Extract_DBCALHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DCDCHit") return Extract_DCDCHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DFDCHit") return Extract_DFDCHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName == "DFCALTruthShower" ) return Extract_DFCALTruthShower(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName == "DFCALHit" ) return Extract_DFCALHit(my_hddm_s, dynamic_cast*>(factory), event.GetJEventLoop() ); if(dataClassName =="DUPVHit") return Extract_DUPVHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DUPVTruthHit") return Extract_DUPVTruthHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DMCTrajectoryPoint") return Extract_DMCTrajectoryPoint(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DTOFTruth") return Extract_DTOFTruth(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DHDDMTOFHit") return Extract_DHDDMTOFHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DSCHit") return Extract_DSCHit(my_hddm_s, dynamic_cast*>(factory)); if(dataClassName =="DSCTruthHit") return Extract_DSCTruthHit(my_hddm_s, dynamic_cast*>(factory)); return OBJECT_NOT_AVAILABLE; } //------------------ // Extract_DMCTrackHit //------------------ jerror_t DEventSourceHDDM::Extract_DMCTrackHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; // The following routines will create DMCTrackHit objects and add them // to data. vector data; GetCDCTruthHits(hddm_s, data); GetFDCTruthHits(hddm_s, data); GetBCALTruthHits(hddm_s, data); GetTOFTruthHits(hddm_s, data); GetCherenkovTruthHits(hddm_s, data); GetFCALTruthHits(hddm_s, data); GetUPVTruthHits(hddm_s, data); // sort hits by z sort(data.begin(), data.end(), MCTrackHitSort_C); // Some systems will use negative phis. Force them all to // be in the 0 to 2pi range for(unsigned int i=0;iphi<0.0)mctrackhit->phi += 2.0*M_PI; } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------- // GetCDCTruthHits //------------------- jerror_t DEventSourceHDDM::GetCDCTruthHits(s_HDDM_t *hddm_s, vector& data) { // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->centralDC == HDDM_NULL || hits->centralDC->cdcTruthPoints == HDDM_NULL)continue; s_CdcTruthPoints_t *cdctruthpoints = hits->centralDC->cdcTruthPoints; s_CdcTruthPoint_t *cdctruthpoint = cdctruthpoints->in; for(unsigned int j=0; jmult; j++, cdctruthpoint++){ DMCTrackHit *mctrackhit = new DMCTrackHit; mctrackhit->r = cdctruthpoint->r; mctrackhit->phi = cdctruthpoint->phi; mctrackhit->z = cdctruthpoint->z; mctrackhit->track = cdctruthpoint->track; mctrackhit->primary = cdctruthpoint->primary; mctrackhit->system = SYS_CDC; data.push_back(mctrackhit); } } return NOERROR; } //------------------- // GetFDCTruthHits //------------------- jerror_t DEventSourceHDDM::GetFDCTruthHits(s_HDDM_t *hddm_s, vector& data) { // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardDC == HDDM_NULL || hits->forwardDC->fdcChambers == HDDM_NULL)continue; s_FdcChambers_t* fdcChambers = hits->forwardDC->fdcChambers; s_FdcChamber_t *fdcChamber = fdcChambers->in; for(unsigned int j=0; jmult; j++, fdcChamber++){ s_FdcTruthPoints_t *fdcTruthPoints = fdcChamber->fdcTruthPoints; if(fdcTruthPoints == HDDM_NULL)continue; s_FdcTruthPoint_t *truth = fdcTruthPoints->in; for(unsigned int k=0; kmult; k++, truth++){ float x = truth->x; float y = truth->y; DMCTrackHit *mctrackhit = new DMCTrackHit; mctrackhit->r = sqrt(x*x + y*y); mctrackhit->phi = atan2(y,x); mctrackhit->z = truth->z; mctrackhit->track = truth->track; mctrackhit->primary = truth->primary; mctrackhit->system = SYS_FDC; data.push_back(mctrackhit); } } } return NOERROR; } //------------------- // GetBCALTruthHits //------------------- jerror_t DEventSourceHDDM::GetBCALTruthHits(s_HDDM_t *hddm_s, vector& data) { // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->barrelEMcal == HDDM_NULL || hits->barrelEMcal->bcalTruthShowers == HDDM_NULL)continue; s_BcalTruthShowers_t *bcalTruthShowers = hits->barrelEMcal->bcalTruthShowers; s_BcalTruthShower_t *bcalTruthShower = bcalTruthShowers->in; for(unsigned int j=0; jmult; j++, bcalTruthShower++){ DMCTrackHit *mctrackhit = new DMCTrackHit; mctrackhit->r = bcalTruthShower->r; mctrackhit->phi = bcalTruthShower->phi; mctrackhit->z = bcalTruthShower->z; mctrackhit->track = bcalTruthShower->track; mctrackhit->primary = bcalTruthShower->primary; mctrackhit->system = SYS_BCAL; data.push_back(mctrackhit); } } return NOERROR; } //------------------- // GetTOFTruthHits //------------------- jerror_t DEventSourceHDDM::GetTOFTruthHits(s_HDDM_t *hddm_s, vector& data) { // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardTOF == HDDM_NULL || hits->forwardTOF->ftofTruthPoints == HDDM_NULL)continue; s_FtofTruthPoints_t *ftoftruthpoints = hits->forwardTOF->ftofTruthPoints; s_FtofTruthPoint_t *ftoftruthpoint = ftoftruthpoints->in; for(unsigned int j=0; jmult; j++, ftoftruthpoint++){ float x = ftoftruthpoint->x; float y = ftoftruthpoint->y; DMCTrackHit *mctrackhit = new DMCTrackHit; mctrackhit->r = sqrt(x*x + y*y); mctrackhit->phi = atan2(y,x); mctrackhit->z = ftoftruthpoint->z; mctrackhit->track = ftoftruthpoint->track; mctrackhit->primary = ftoftruthpoint->primary; mctrackhit->system = SYS_TOF; data.push_back(mctrackhit); } } return NOERROR; } //------------------- // GetCherenkovTruthHits //------------------- jerror_t DEventSourceHDDM::GetCherenkovTruthHits(s_HDDM_t *hddm_s, vector& data) { return NOERROR; } //------------------- // GetFCALTruthHits //------------------- jerror_t DEventSourceHDDM::GetFCALTruthHits(s_HDDM_t *hddm_s, vector& data) { // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardEMcal == HDDM_NULL || hits->forwardEMcal->fcalTruthShowers == HDDM_NULL)continue; s_FcalTruthShowers_t *fcalTruthShowers = hits->forwardEMcal->fcalTruthShowers; s_FcalTruthShower_t *fcalTruthShower = fcalTruthShowers->in; for(unsigned int j=0; jmult; j++, fcalTruthShower++){ float x = fcalTruthShower->x; float y = fcalTruthShower->y; DMCTrackHit *mctrackhit = new DMCTrackHit; mctrackhit->r = sqrt(x*x + y*y); mctrackhit->phi = atan2(y,x); mctrackhit->z = fcalTruthShower->z; mctrackhit->track = fcalTruthShower->track; mctrackhit->primary = fcalTruthShower->primary; mctrackhit->system = SYS_FCAL; data.push_back(mctrackhit); } } return NOERROR; } //------------------- // GetUPVTruthHits //------------------- jerror_t DEventSourceHDDM::GetUPVTruthHits(s_HDDM_t *hddm_s, vector& data) { return NOERROR; } //------------------ // Extract_DBCALHit //------------------ jerror_t DEventSourceHDDM::Extract_DBCALHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->barrelEMcal == HDDM_NULL || hits->barrelEMcal->bcalCells == HDDM_NULL)continue; // Loop over BCAL cells s_BcalCells_t *cells = hits->barrelEMcal->bcalCells; for(unsigned int j=0;jmult;j++){ s_BcalCell_t *cell = &cells->in[j]; if(cell->bcalUpstreamHits != HDDM_NULL){ for(unsigned int k=0; kbcalUpstreamHits->mult; k++){ s_BcalUpstreamHit_t *upstreamhit = &cell->bcalUpstreamHits->in[k]; DBCALHit *bcalhit = new DBCALHit(); bcalhit->module = cell->module; bcalhit->layer = cell->layer; bcalhit->sector = cell->sector; bcalhit->end = DBCALHit::UPSTREAM; bcalhit->E = upstreamhit->E; bcalhit->t = upstreamhit->t; data.push_back(bcalhit); } } if(cell->bcalDownstreamHits != HDDM_NULL){ for(unsigned int k=0; kbcalDownstreamHits->mult; k++){ s_BcalDownstreamHit_t *downstreamhit = &cell->bcalDownstreamHits->in[k]; DBCALHit *bcalhit = new DBCALHit(); bcalhit->module = cell->module; bcalhit->layer = cell->layer; bcalhit->sector = cell->sector; bcalhit->end = DBCALHit::DOWNSTREAM; bcalhit->E = downstreamhit->E; bcalhit->t = downstreamhit->t; data.push_back(bcalhit); } } } // j (cells) } // i (physicsEvents) // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DMCThrown //------------------ jerror_t DEventSourceHDDM::Extract_DMCThrown(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ // ------------ Reactions -------------- s_Reactions_t *reactions=PE->in[i].reactions; if(!reactions)continue; for(unsigned int j=0; jmult; j++){ s_Vertices_t *vertices = reactions->in[j].vertices; if(vertices){ for(unsigned int k=0; kmult; k++){ s_Origin_t *origin = vertices->in[k].origin; s_Products_t *products = vertices->in[k].products; if(products && origin){ for(unsigned int m=0;mmult;m++){ s_Product_t *product = &products->in[m]; DMCThrown *mcthrown = new DMCThrown; mcthrown->x = origin->vx; mcthrown->y = origin->vy; mcthrown->z = origin->vz; mcthrown->type = product->type; mcthrown->q = (float)ParticleCharge(product->type); mcthrown->mass = ParticleMass(product->type); mcthrown->E = product->momentum->E; double px = product->momentum->px; double py = product->momentum->py; double pz = product->momentum->pz; mcthrown->p = sqrt(px*px + py*py + pz*pz); mcthrown->phi = atan2(py, px); if(mcthrown->phi<0.0)mcthrown->phi += 2.0*M_PI; mcthrown->theta = acos(pz/mcthrown->p); data.push_back(mcthrown); } } } } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DCDCHit //------------------ jerror_t DEventSourceHDDM::Extract_DCDCHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Acquire the pointer to the physics events s_PhysicsEvents_t* allEvents = hddm_s->physicsEvents; if(!allEvents)return NOERROR; for (unsigned int m=0; m < allEvents->mult; m++) { // Acquire the pointer to the overall hits section of the data s_HitView_t *hits = allEvents->in[m].hitView; if (hits == HDDM_NULL)return NOERROR; if (hits->centralDC == HDDM_NULL)return NOERROR; if (hits->centralDC->cdcStraws == HDDM_NULL)return NOERROR; for(unsigned int k=0; kcentralDC->cdcStraws->mult; k++){ s_CdcStraw_t *cdcstraw = &hits->centralDC->cdcStraws->in[k]; for(unsigned int j=0; jcdcStrawHits->mult; j++){ s_CdcStrawHit_t *strawhit = &cdcstraw->cdcStrawHits->in[j]; DCDCHit *hit = new DCDCHit; hit->ring = cdcstraw->ring; hit->straw = cdcstraw->straw; hit->dE = strawhit->dE; hit->t = strawhit->t; data.push_back(hit); } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DFDCHit //------------------ jerror_t DEventSourceHDDM::Extract_DFDCHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Acquire the pointer to the physics events s_PhysicsEvents_t* allEvents = hddm_s->physicsEvents; if(!allEvents) { //throw JException("Attempt to get physics events from HDDM source failed."); return NOERROR; } for (unsigned int m=0; m < allEvents->mult; m++) { // Acquire the pointer to the overall hits section of the data s_HitView_t *hits = allEvents->in[m].hitView; if (hits == HDDM_NULL) { //throw JException("HDDM source has no hits."); return NOERROR; } if (hits->forwardDC == HDDM_NULL) { //throw JException("HDDM source has no forwardDC information."); return NOERROR; } if (hits->forwardDC->fdcChambers == HDDM_NULL) { // throw JException("HDDM source has no hits in the FDC."); return NOERROR; } // Acquire the pointer to the beginning of the FDC hit tree s_FdcChambers_t* fdcChamberSet = hits->forwardDC->fdcChambers; for (unsigned int i=0; i < fdcChamberSet->mult; i++) { // Each chamber in the ChamberSet has a wire set and a strip set s_FdcChamber_t &fdcChamber = fdcChamberSet->in[i]; s_FdcAnodeWires_t* wireSet = fdcChamber.fdcAnodeWires; s_FdcCathodeStrips_t* stripSet = fdcChamber.fdcCathodeStrips; // Each set of wires has (obviously) wires inside of it, and each wire // may have one or more hits on it. Make a DFDCHit object for each one // of these hits. for (unsigned int j=0; j < wireSet->mult; j++) { s_FdcAnodeWire_t anodeWire = wireSet->in[j]; s_FdcAnodeHits_t* wireHitSet = anodeWire.fdcAnodeHits; for (unsigned int k=0; k < wireHitSet->mult; k++) { s_FdcAnodeHit_t wireHit = wireHitSet->in[k]; DFDCHit* newHit = new DFDCHit(); newHit->layer = fdcChamber.layer; newHit->module = fdcChamber.module; newHit->element = anodeWire.wire; newHit->q = wireHit.dE; newHit->t = wireHit.t; newHit->plane = 2; newHit->type = 0; newHit->gPlane = DFDCGeometry::gPlane(newHit); newHit->gLayer = DFDCGeometry::gLayer(newHit); newHit->r = DFDCGeometry::getWireR(newHit); data.push_back(newHit); } } // Ditto for the cathodes. for (unsigned int j=0; j < stripSet->mult; j++) { s_FdcCathodeStrip_t cathodeStrip = stripSet->in[j]; s_FdcCathodeHits_t* stripHitSet = cathodeStrip.fdcCathodeHits; for (unsigned int k=0; k < stripHitSet->mult; k++) { s_FdcCathodeHit_t stripHit = stripHitSet->in[k]; DFDCHit* newHit = new DFDCHit(); newHit->layer = fdcChamber.layer; newHit->module = fdcChamber.module; newHit->element = cathodeStrip.strip; newHit->plane = cathodeStrip.plane; newHit->q = stripHit.q; newHit->t = stripHit.t; newHit->type = 1; newHit->gPlane = DFDCGeometry::gPlane(newHit); newHit->gLayer = DFDCGeometry::gLayer(newHit); newHit->r = DFDCGeometry::getStripR(newHit); data.push_back(newHit); } } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DFCALTruthShower //------------------ jerror_t DEventSourceHDDM::Extract_DFCALTruthShower(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; oid_t id=1; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardEMcal == HDDM_NULL || hits->forwardEMcal->fcalTruthShowers == HDDM_NULL)continue; s_FcalTruthShowers_t *showers = hits->forwardEMcal->fcalTruthShowers; for(unsigned int j=0; jmult; j++){ s_FcalTruthShower_t *shower = &showers->in[j]; DFCALTruthShower *dfcaltruthshower = new DFCALTruthShower( id++, shower->x, shower->y, shower->z, shower->E, shower->t, shower->primary, shower->track ); data.push_back(dfcaltruthshower); } } // i (physicsEvents) // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DFCALHit //------------------ jerror_t DEventSourceHDDM::Extract_DFCALHit(s_HDDM_t *hddm_s, JFactory *factory, JEventLoop* eventLoop ) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // extract the FCAL Geometry vector fcalGeomVect; eventLoop->Get( fcalGeomVect ); if(fcalGeomVect.size() != 1){ cerr<<__FILE__<<":"<<__LINE__<<" Bad number of DFCALGeometry objects ("<physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardEMcal == HDDM_NULL || hits->forwardEMcal->fcalBlocks == HDDM_NULL)continue; s_FcalBlocks_t *blocks = hits->forwardEMcal->fcalBlocks; for(unsigned int j=0; jmult; j++){ s_FcalBlock_t *block = &blocks->in[j]; for(unsigned int k=0; kfcalHits->mult; k++){ s_FcalHit_t *fcalhit = &block->fcalHits->in[k]; TVector2 position = fcalGeom.positionOnFace(block->row, block->column); DFCALHit *dfcalhit = new DFCALHit(); dfcalhit->column = block->column; dfcalhit->row = block->row; dfcalhit->x = position.X(); dfcalhit->y = position.Y(); dfcalhit->E = fcalhit->E; dfcalhit->t = fcalhit->t; data.push_back(dfcalhit); } // k (fcalhits) } // j (blocks) } // i (physicsEvents) // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DUPVHit //------------------ jerror_t DEventSourceHDDM::Extract_DUPVHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Acquire the pointer to the physics events s_PhysicsEvents_t* allEvents = hddm_s->physicsEvents; if(!allEvents) { //throw JException("Attempt to get physics events from HDDM source failed."); return NOERROR; } for (unsigned int m=0; m < allEvents->mult; m++) { // Acquire the pointer to the overall hits section of the data s_HitView_t *hits = allEvents->in[m].hitView; if (hits == HDDM_NULL) { //throw JException("HDDM source has no hits."); return NOERROR; } if (hits->upstreamEMveto == HDDM_NULL) { //throw JException("HDDM source has no forwardDC information."); return NOERROR; } if (hits->upstreamEMveto->upvPaddles == HDDM_NULL) { // throw JException("HDDM source has no hits in the UPV."); return NOERROR; } // Acquire the pointer to the beginning of the UPV hit tree s_UpvPaddles_t* upvPaddles = hits->upstreamEMveto->upvPaddles; for (unsigned int i=0; i < upvPaddles->mult; i++) { // Each chamber in the ChamberSet has a wire set and a strip set s_UpvPaddle_t &upvPaddle = upvPaddles->in[i]; s_UpvLeftHits_t* upvLeftHits = upvPaddle.upvLeftHits; s_UpvRightHits_t* upvRightHits = upvPaddle.upvRightHits; int &layer = upvPaddle.layer; int &row = upvPaddle.row; // Loop over "left" hits for (unsigned int j=0; j < upvLeftHits->mult; j++) { s_UpvLeftHit_t &hit = upvLeftHits->in[j]; DUPVHit* newHit = new DUPVHit(); newHit->layer = layer; newHit->row = row; newHit->E = hit.E; newHit->t = hit.t; newHit->side = DUPVHit::UPV_LEFT; data.push_back(newHit); } // Loop over "right" hits for (unsigned int j=0; j < upvRightHits->mult; j++) { s_UpvRightHit_t &hit = upvRightHits->in[j]; DUPVHit* newHit = new DUPVHit(); newHit->layer = layer; newHit->row = row; newHit->E = hit.E; newHit->t = hit.t; newHit->side = DUPVHit::UPV_RIGHT; data.push_back(newHit); } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DUPVTruthHit //------------------ jerror_t DEventSourceHDDM::Extract_DUPVTruthHit(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Acquire the pointer to the physics events s_PhysicsEvents_t* allEvents = hddm_s->physicsEvents; if(!allEvents) { //throw JException("Attempt to get physics events from HDDM source failed."); return NOERROR; } for (unsigned int m=0; m < allEvents->mult; m++) { // Acquire the pointer to the overall hits section of the data s_HitView_t *hits = allEvents->in[m].hitView; if (hits == HDDM_NULL)return NOERROR; if (hits->upstreamEMveto == HDDM_NULL)return NOERROR; if (hits->upstreamEMveto->upvTruthShowers == HDDM_NULL)return NOERROR; // Acquire the pointer to the beginning of the UPV hit tree s_UpvTruthShowers_t* upvTruthShowers = hits->upstreamEMveto->upvTruthShowers; for (unsigned int i=0; i < upvTruthShowers->mult; i++) { s_UpvTruthShower_t &shower = upvTruthShowers->in[i]; DUPVTruthHit *hit = new DUPVTruthHit(); hit->E = shower.E; hit->primary = shower.primary; hit->t = shower.t; hit->track = shower.track; hit->x = shower.x; hit->y = shower.y; hit->z = shower.z; data.push_back(hit); } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DMCTrajectoryPoint //------------------ jerror_t DEventSourceHDDM::Extract_DMCTrajectoryPoint(s_HDDM_t *hddm_s, JFactory *factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->mcTrajectory == HDDM_NULL || hits->mcTrajectory->mcTrajectoryPoints == HDDM_NULL)continue; s_McTrajectoryPoints_t *points = hits->mcTrajectory->mcTrajectoryPoints; for(unsigned int i=0; imult; i++){ DMCTrajectoryPoint *p = new DMCTrajectoryPoint; p->x = points->in[i].x; p->y = points->in[i].y; p->z = points->in[i].z; p->t = points->in[i].t; p->px = points->in[i].px; p->py = points->in[i].py; p->pz = points->in[i].pz; p->E = points->in[i].E; p->dE = points->in[i].dE; p->track = points->in[i].track; p->part = points->in[i].part; p->radlen = points->in[i].radlen; p->step = points->in[i].step; data.push_back(p); } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DTOFTruth //------------------ jerror_t DEventSourceHDDM::Extract_DTOFTruth(s_HDDM_t *hddm_s, JFactory* factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; // Loop over Physics Events s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; int id = 0; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardTOF == HDDM_NULL || hits->forwardTOF->ftofTruthPoints == HDDM_NULL)continue; s_FtofTruthPoints_t* ftofTruthPoints = hits->forwardTOF->ftofTruthPoints; // Loop truth hits s_FtofTruthPoint_t *ftofTruthPoint = ftofTruthPoints->in; for(unsigned int j=0;jmult; j++, ftofTruthPoint++){ DTOFTruth *toftruth = new DTOFTruth; toftruth->id = id++; toftruth->primary = ftofTruthPoint->primary; toftruth->track = ftofTruthPoint->track; toftruth->x = ftofTruthPoint->x; toftruth->y = ftofTruthPoint->y; toftruth->z = ftofTruthPoint->z; toftruth->t = ftofTruthPoint->t; data.push_back(toftruth); } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DHDDMTOFHit //------------------ jerror_t DEventSourceHDDM::Extract_DHDDMTOFHit( s_HDDM_t *hddm_s, JFactory* factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; int id = 0; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->forwardTOF == HDDM_NULL || hits->forwardTOF->ftofCounters == HDDM_NULL)continue; s_FtofCounters_t* ftofCounters = hits->forwardTOF->ftofCounters; // Loop over counters s_FtofCounter_t *ftofCounter = ftofCounters->in; for(unsigned int j=0;jmult; j++, ftofCounter++){ // Loop over north hits s_FtofNorthHits_t *ftofNorthHits = ftofCounter->ftofNorthHits; s_FtofNorthHit_t *ftofNorthHit = ftofNorthHits->in; for(unsigned int k=0;kmult; k++, ftofNorthHit++){ DHDDMTOFHit *tofhit = new DHDDMTOFHit; tofhit->bar = ftofCounter->bar; tofhit->plane = ftofCounter->plane; tofhit->end = 0; tofhit->t = ftofNorthHit->t; tofhit->dE = ftofNorthHit->dE; tofhit->id = id++; data.push_back(tofhit); } // Loop over south hits s_FtofSouthHits_t *ftofSouthHits = ftofCounter->ftofSouthHits; s_FtofSouthHit_t *ftofSouthHit = ftofSouthHits->in; for(unsigned int k=0;kmult; k++, ftofSouthHit++){ DHDDMTOFHit *tofhit = new DHDDMTOFHit; tofhit->bar = ftofCounter->bar; tofhit->plane = ftofCounter->plane; tofhit->end = 1; tofhit->t = ftofSouthHit->t; tofhit->dE = ftofSouthHit->dE; tofhit->id = id++; data.push_back(tofhit); } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DSCHit //------------------ jerror_t DEventSourceHDDM::Extract_DSCHit( s_HDDM_t *hddm_s, JFactory* factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->startCntr == HDDM_NULL)continue; s_StcPaddles_t* stcPaddles = hits->startCntr->stcPaddles; if(stcPaddles==HDDM_NULL)continue; //s_StcTruthPoints_t* stcTruthPoints = hits->startCntr->stcTruthPoints; // Loop over counters s_StcPaddle_t *stcPaddle = stcPaddles->in; for(unsigned int j=0;jmult; j++, stcPaddle++){ s_StcHits_t *stcHits = stcPaddle->stcHits; if(stcHits==HDDM_NULL)continue; s_StcHit_t *stchit = stcHits->in; for(unsigned int k=0; kmult; k++, stchit++){ DSCHit *hit = new DSCHit; hit->sector = stcPaddle->sector; hit->dE = stchit->dE; hit->t = stchit->t; data.push_back(hit); } } } // Copy into factory factory->CopyTo(data); return NOERROR; } //------------------ // Extract_DSCTruthHit //------------------ jerror_t DEventSourceHDDM::Extract_DSCTruthHit( s_HDDM_t *hddm_s, JFactory* factory) { /// Copies the data from the given hddm_s structure. This is called /// from JEventSourceHDDM::GetObjects. If factory is NULL, this /// returns OBJECT_NOT_AVAILABLE immediately. if(factory==NULL)return OBJECT_NOT_AVAILABLE; vector data; s_PhysicsEvents_t* PE = hddm_s->physicsEvents; if(!PE) return NOERROR; for(unsigned int i=0; imult; i++){ s_HitView_t *hits = PE->in[i].hitView; if (hits == HDDM_NULL || hits->startCntr == HDDM_NULL)continue; s_StcTruthPoints_t* stcTruthPoints = hits->startCntr->stcTruthPoints; if(stcTruthPoints==HDDM_NULL)continue; // Loop over counters s_StcTruthPoint_t *stcTruthPoint = stcTruthPoints->in; for(unsigned int j=0;jmult; j++, stcTruthPoint++){ DSCTruthHit *hit = new DSCTruthHit; hit->dEdx = stcTruthPoint->dEdx; hit->phi = stcTruthPoint->phi; hit->primary = stcTruthPoint->primary; hit->r = stcTruthPoint->r; hit->t = stcTruthPoint->t; hit->z = stcTruthPoint->z; hit->track = stcTruthPoint->track; data.push_back(hit); } } // Copy into factory factory->CopyTo(data); return NOERROR; }