#include #include "fileManager.h" fileManager::fileManager(string filename) { char filenameC[128]; strcpy(filenameC, filename.c_str()); if (!(filePtr = open_fitter_HDDM(filenameC))) { cerr << "Error - could not open input file" << endl; exit(1); } } fileManager::~fileManager() { close_fitter_HDDM(filePtr); } int fileManager::getNextEvent(int &runNumber, int &eventNumber) { bufferPtr = read_fitter_HDDM(filePtr); if (! bufferPtr) return(1); event = bufferPtr->events->in[0]; runNumber = event.run; eventNumber = event.number; fdchitsPtr = 0; if (event.fdcdata) { fdchitsPtr = (event.fdcdata)->fdchits; fdchitAry = fdchitsPtr->in; } cdchitsPtr = 0; if (event.cdcdata) { cdchitsPtr = (event.cdcdata)->cdchits; cdchitAry = cdchitsPtr->in; } tracksPtr = 0; if (event.tracks) { tracksPtr = event.tracks; trackAry = tracksPtr->in; } return(0); } void fileManager::readFDCData(hitInfoFDC_t *hitsFDC, int &nhitsFDC) { nhitsFDC = 0; if (! fdchitsPtr) return; for (int i = 0; i < fdchitsPtr->mult; i++) { hitsFDC[nhitsFDC].index = fdchitAry[i].id; hitsFDC[nhitsFDC].x = fdchitAry[i].x; hitsFDC[nhitsFDC].y = fdchitAry[i].y; hitsFDC[nhitsFDC].z = fdchitAry[i].z; hitsFDC[nhitsFDC].xWire = fdchitAry[i].xWire; hitsFDC[nhitsFDC].yWire = fdchitAry[i].yWire; hitsFDC[nhitsFDC].zWire = fdchitAry[i].zWire; hitsFDC[nhitsFDC].theta = fdchitAry[i].theta; hitsFDC[nhitsFDC].phi = fdchitAry[i].phi; hitsFDC[nhitsFDC].L = fdchitAry[i].L; // cout << hitsFDC[nhitsFDC].index << ' ' << hitsFDC[nhitsFDC].x << ' ' << hitsFDC[nhitsFDC].y << ' ' << hitsFDC[nhitsFDC].z << endl; nhitsFDC++; // increment hit counter } } void fileManager::readCDCData(hitInfoCDC_t *hitsCDC, int &nhitsCDC) { nhitsCDC = 0; if (! cdchitsPtr) return; for (int i = 0; i < cdchitsPtr->mult; i++) { hitsCDC[nhitsCDC].index = cdchitAry[i].id; hitsCDC[nhitsCDC].x = cdchitAry[i].x; hitsCDC[nhitsCDC].y = cdchitAry[i].y; hitsCDC[nhitsCDC].z = cdchitAry[i].z; hitsCDC[nhitsCDC].theta = cdchitAry[i].theta; // cout << "readCDCData: i=" << i << " id=" << cdchitAry[i].id << " y=" << cdchitAry[i].y << " theta=" << cdchitAry[i].theta << endl; hitsCDC[nhitsCDC].phi = cdchitAry[i].phi; hitsCDC[nhitsCDC].L = cdchitAry[i].L; nhitsCDC++; // increment hit counter } } void fileManager::readResiduals(residInfoCDC_t *residsCDC, int &nresidsCDC, residInfoFDC_t *residsFDC, int &nresidsFDC) { nresidsCDC = 0; nresidsFDC = 0; if (! cdchitsPtr && ! fdchitsPtr) return; if (! tracksPtr) return; fitter_Trajectorys_t* trajectorysPtr; fitter_Trajectory_t* trajectoryAry; fitter_Residuals_t* residualsPtr; fitter_Residual_t* residualAry; fitter_ResidInfoCdc_t* infoCdcPtr; fitter_ResidInfoFdc_t* infoFdcPtr; for (int it = 0; it < tracksPtr->mult; it++){ trajectorysPtr = trackAry[it].trajectorys; trajectoryAry = trajectorysPtr->in; for (int itrj = 0; itrj < trajectorysPtr->mult; itrj++) { residualsPtr = trajectoryAry[itrj].residuals; residualAry = residualsPtr->in; for (int ir = 0; ir < residualsPtr->mult; ir++) { if (residualAry[ir].detector_index == 0) { infoCdcPtr = residualAry[ir].residInfoCdc; int id = infoCdcPtr->id; residsCDC[nresidsCDC].index = id; residsCDC[nresidsCDC].x = infoCdcPtr->xWire; residsCDC[nresidsCDC].y = infoCdcPtr->yWire; residsCDC[nresidsCDC].z = infoCdcPtr->zWire; residsCDC[nresidsCDC].xTraj = infoCdcPtr->xTraj; residsCDC[nresidsCDC].yTraj = infoCdcPtr->yTraj; residsCDC[nresidsCDC].zTraj = infoCdcPtr->zTraj; residsCDC[nresidsCDC].theta = cdchitAry[id].theta; // cout << "readResiduals: nresidsCDC=" << nresidsCDC << "it=" << it << " itrj=" << itrj << " ir=" << ir << " id=" << id << " y=" << infoCdcPtr->yWire << " theta=" << cdchitAry[id].theta << endl; residsCDC[nresidsCDC].phi = cdchitAry[id].phi; residsCDC[nresidsCDC].dist = infoCdcPtr->dist; residsCDC[nresidsCDC].idTraj = trajectoryAry[itrj].index; nresidsCDC++; // increment hit counter } else if (residualAry[ir].detector_index == 1) { infoFdcPtr = residualAry[ir].residInfoFdc; int id = infoFdcPtr->id; residsFDC[nresidsFDC].index = id; residsFDC[nresidsFDC].x = infoFdcPtr->xCorr; residsFDC[nresidsFDC].y = infoFdcPtr->yCorr; residsFDC[nresidsFDC].z = infoFdcPtr->zCorr; residsFDC[nresidsFDC].xTraj = infoFdcPtr->xTraj; residsFDC[nresidsFDC].yTraj = infoFdcPtr->yTraj; residsFDC[nresidsFDC].zTraj = infoFdcPtr->zTraj; residsFDC[nresidsFDC].idTraj = trajectoryAry[itrj].index; nresidsFDC++; // increment hit counter } else { int error = BAD_DETECTOR_INDEX; throw error; } } } } } void fileManager::readTrajectoryData(pointInfo_t *points, int &npoints) { npoints = 0; if (! tracksPtr) return; if (tracksPtr->mult == 1) { fitter_Trajectorys_t* trajectorysPtr = trackAry[0].trajectorys; fitter_Trajectory_t* trajectoryAry = trajectorysPtr->in; for (int j = 0; j < trajectorysPtr->mult; j++) { fitter_Trajectory_t trajectory = trajectoryAry[j]; fitter_Points_t* pointsPtr = trajectory.points; fitter_Point_t* pointAry = pointsPtr->in; for (int i = 0; i < pointsPtr->mult; i++) { points[npoints].trajId = trajectory.index; points[npoints].index = npoints; points[npoints].x = pointAry[i].x; points[npoints].y = pointAry[i].y; points[npoints].z = pointAry[i].z; npoints++; // increment point counter } } } } #define NPARAMS 5 #define BAD_DOUBLE -1.0e10 #define TRAJECTORY_THROWN 2 #define TRAJECTORY_FIT 1 void fileManager::readInfo(eventInfo_t* info) { info->event = event.number; info->chisq = BAD_DOUBLE; for (int ip = 0; ip < NPARAMS; ip++) { info->paramsTrue[ip] = BAD_DOUBLE; info->paramsFit[ip] = BAD_DOUBLE; } if (! tracksPtr) return; fitter_Trajectorys_t* trajectorysPtr; fitter_Trajectory_t* trajectoryPtr; fitter_Trajectory_t* trajectoryAry; for (int it = 0; it < tracksPtr->mult; it++){ info->chisq = trackAry[it].chisq; // specialized for one track! trajectorysPtr = trackAry[it].trajectorys; trajectoryAry = trajectorysPtr->in; for (int itrj = 0; itrj < trajectorysPtr->mult; itrj++) { //save the trajectory pointer trajectoryPtr = trajectorysPtr->in + itrj; // is this the thrown trajectory? if (trajectoryPtr->index == TRAJECTORY_THROWN) { // check for a parameters pointer if (trajectoryPtr->parameters != HDDM_NULL) { // copy the parameters to the info structure for (int ip = 0; ip < NPARAMS; ip++) { info->paramsTrue[ip] = trajectoryPtr->parameters->in[ip].value; } } } // is this the fit trajectory? if (trajectoryPtr->index == TRAJECTORY_FIT) { // check for a parameters pointer if (trajectoryPtr->parameters != HDDM_NULL) { // copy the parameters to the info structure for (int ip = 0; ip < NPARAMS; ip++) { info->paramsFit[ip] = trajectoryPtr->parameters->in[ip].value; } } } } } }