//////////////////////////////////////////////////////////////////////////////// // SoftShadowsRenderer::updateLightCamera() //////////////////////////////////////////////////////////////////////////////// void SoftShadowsRenderer::updateLightCamera() { nv::matrix4f view = m_camera.getModelViewMat(NvCameraXformType::SECONDARY); nv::matrix4f inverseView = nv::inverse(view); nv::vec3f lightCenterWorld = transformCoord(inverseView, nv::vec3f(0.0f, 0.0f, 0.0f)); static nv::vec3f s_rot; static nv::vec3f s_trans; static float s_scale; // If the light source is high enough above the ground plane if (lightCenterWorld.y > 1.0f) { s_rot = m_camera.getRotationVec(NvCameraXformType::SECONDARY); s_trans = m_camera.getTranslationVec(NvCameraXformType::SECONDARY); s_scale = m_camera.getScale(NvCameraXformType::SECONDARY); } else { m_camera.setRotationVec(s_rot, NvCameraXformType::SECONDARY); m_camera.setTranslationVec(s_trans, NvCameraXformType::SECONDARY); m_camera.setScale(s_scale, NvCameraXformType::SECONDARY); m_camera.update(0.0f); } updateLightCamera(m_camera.getModelViewMat(NvCameraXformType::SECONDARY)); }
void Camera::update() { Vec3 up, pos, rot; Matrix rotationMatrix; float radianConv = (float)(PI)/180; //Used to convert from degree to radians //Setup up-, pos- and look-vectors up = Vec3(0,1,0); pos = position; //Set yaw, pitch and roll rotations in radians rot.x = rotation.x * radianConv; rot.y = rotation.y * radianConv; rot.z = rotation.z * radianConv; //Create rotation matrix rotationMatrix = yawPitchRoll(rot); //Transform lookAt and up vector by rotation matrix transformCoord(lookAt, lookAt, rotationMatrix); transformCoord(up, up, rotationMatrix); //Translate rotated camera position to location of viewer lookAt = pos + Vec3(0,0,1); //Create view matrix from vectors lookAtLHP(viewMatrix, lookAt, up, pos); MatrixInversion(viewInv, viewMatrix); #ifdef _WIN32 CBCameraMove cb; cb.cameraPos = pos; cb.cameraDir = lookAt - pos; cb.View = viewMatrix; cb.ViewInv = viewInv; GraphicsDX11::getInstance()->updateCBCameraMove(cb); #endif }
void hitForwardEMcal (float xin[4], float xout[4], float pin[5], float pout[5], float dEsum, int track, int stack, int history, int ipart) { float x[3], t; float xfcal[3]; if (!initialized) { mystr_t strings[50]; float values[50]; int nvalues = 50; int status = GetConstants("FCAL/fcal_parms", &nvalues, values, strings); if (!status) { int ncounter = 0; int i; for ( i=0; i<(int)nvalues; i++) { //printf("%d %s \n",i,strings[i].str); if (!strcmp(strings[i].str,"FCAL_ATTEN_LENGTH")) { ATTEN_LENGTH = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_C_EFFECTIVE")) { C_EFFECTIVE = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_WIDTH_OF_BLOCK")) { WIDTH_OF_BLOCK = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_LENGTH_OF_BLOCK")) { LENGTH_OF_BLOCK = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_TWO_HIT_RESOL")) { TWO_HIT_RESOL = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_MAX_HITS")) { FCAL_MAX_HITS = (int)values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_THRESH_MEV")) { THRESH_MEV = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_ACTIVE_RADIUS")) { ACTIVE_RADIUS = values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_CENTRAL_ROW")) { CENTRAL_ROW = (int)values[i]; ncounter++; } if (!strcmp(strings[i].str,"FCAL_CENTRAL_COLUMN")) { CENTRAL_COLUMN = (int)values[i]; ncounter++; } } const int nparams=10; if (ncounter==nparams) { printf("FCAL: ALL parameters loaded from Data Base\n"); } else if (ncounter<nparams) { printf("FCAL: NOT ALL necessary parameters found in Data Base %d out of %d\n",ncounter,nparams); } else { printf("FCAL: SOME parameters found more than once in Data Base\n"); } } initialized = 1; } x[0] = (xin[0] + xout[0])/2; x[1] = (xin[1] + xout[1])/2; x[2] = (xin[2] + xout[2])/2; t = (xin[3] + xout[3])/2 * 1e9; transformCoord(x,"global",xfcal,"FCAL"); /* post the hit to the truth tree */ if ((history == 0) && (pin[3] > THRESH_MEV/1e3)) { s_FcalTruthShowers_t* showers; int mark = (1<<30) + showerCount; void** twig = getTwig(&forwardEMcalTree, mark); if (*twig == 0) { s_ForwardEMcal_t* cal = *twig = make_s_ForwardEMcal(); cal->fcalTruthShowers = showers = make_s_FcalTruthShowers(1); int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; showers->in[0].primary = (stack <= a); showers->in[0].track = track; showers->in[0].t = xin[3]*1e9; showers->in[0].x = xin[0]; showers->in[0].y = xin[1]; showers->in[0].z = xin[2]; showers->in[0].px = pin[0]*pin[4]; showers->in[0].py = pin[1]*pin[4]; showers->in[0].pz = pin[2]*pin[4]; showers->in[0].E = pin[3]; showers->in[0].ptype = ipart; showers->in[0].trackID = make_s_TrackID(); showers->in[0].trackID->itrack = gidGetId(track); showers->mult = 1; showerCount++; } } /* post the hit to the hits tree, mark block as hit */ if (dEsum > 0) { int nhit; s_FcalTruthHits_t* hits; int row = getrow_wrapper_(); int column = getcolumn_wrapper_(); float dist = 0.5*LENGTH_OF_BLOCK-xfcal[2]; float dEcorr = dEsum * exp(-dist/ATTEN_LENGTH); float tcorr = t + dist/C_EFFECTIVE; int mark = ((row+1)<<16) + (column+1); void** twig = getTwig(&forwardEMcalTree, mark); if (*twig == 0) { s_ForwardEMcal_t* cal = *twig = make_s_ForwardEMcal(); s_FcalBlocks_t* blocks = make_s_FcalBlocks(1); blocks->mult = 1; blocks->in[0].row = row; blocks->in[0].column = column; blocks->in[0].fcalTruthHits = hits = make_s_FcalTruthHits(MAX_HITS); cal->fcalBlocks = blocks; blockCount++; } else { s_ForwardEMcal_t* cal = *twig; hits = cal->fcalBlocks->in[0].fcalTruthHits; } for (nhit = 0; nhit < hits->mult; nhit++) { if (fabs(hits->in[nhit].t - tcorr) < TWO_HIT_RESOL) { break; } } if (nhit < hits->mult) /* merge with former hit */ { hits->in[nhit].t = (hits->in[nhit].t * hits->in[nhit].E + tcorr*dEcorr) / (hits->in[nhit].E + dEcorr); hits->in[nhit].E += dEcorr; } else if (nhit < MAX_HITS) /* create new hit */ { hits->in[nhit].t = tcorr; hits->in[nhit].E = dEcorr; hits->mult++; } else { fprintf(stderr,"HDGeant error in hitforwardEMcal: "); fprintf(stderr,"max hit count %d exceeded, truncating!\n",MAX_HITS); exit(2); } } }
//////////////////////////////////////////////////////////////////////////////// // SoftShadowsRenderer::updateLightCamera() //////////////////////////////////////////////////////////////////////////////// void SoftShadowsRenderer::updateLightCamera(const nv::matrix4f &view) { // Assuming that the bbox of mesh1 contains everything nv::vec3f center = m_knightMesh->getWorldCenter(); nv::vec3f extents = m_knightMesh->getExtents(); nv::vec3f box[2]; box[0] = center - extents; box[1] = center + extents; nv::vec3f bbox[2]; transformBoundingBox(bbox, box, view); float frustumWidth = std::max(fabs(bbox[0][0]), fabs(bbox[1][0])) * 2.0f; float frustumHeight = std::max(fabs(bbox[0][1]), fabs(bbox[1][1])) * 2.0f; float zNear = -bbox[1][2]; float zFar = LIGHT_ZFAR; nv::matrix4f proj; perspectiveFrustum(proj, frustumWidth, frustumHeight, zNear, zFar); m_lightViewProj = proj * view; nv::matrix4f clip2Tex; clip2Tex.set_scale(nv::vec3f(0.5f, 0.5f, 0.5f)); clip2Tex.set_translate(nv::vec3f(0.5f, 0.5f, 0.5f)); nv::matrix4f viewProjClip2Tex = clip2Tex * m_lightViewProj; nv::matrix4f inverseView = nv::inverse(view); nv::vec3f lightCenterWorld = transformCoord(inverseView, nv::vec3f(0.0f, 0.0f, 0.0f)); if (m_shadowMapShader) { m_shadowMapShader->enable(); m_shadowMapShader->setViewProjMatrix(m_lightViewProj); m_shadowMapShader->disable(); CHECK_GL_ERROR(); } if (m_visTexShader) { m_visTexShader->enable(); m_visTexShader->setLightZNear(zNear); m_visTexShader->setLightZFar(zFar); m_visTexShader->disable(); CHECK_GL_ERROR(); } if (m_pcssShader) { m_pcssShader->enable(); m_pcssShader->setLightViewMatrix(view); m_pcssShader->setLightViewProjClip2TexMatrix(viewProjClip2Tex); m_pcssShader->setLightZNear(zNear); m_pcssShader->setLightZFar(zFar); m_pcssShader->setLightPosition(lightCenterWorld); m_pcssShader->disable(); CHECK_GL_ERROR(); } updateLightSize(frustumWidth, frustumHeight); CHECK_GL_ERROR(); }
void hitStartCntr (float xin[4], float xout[4], float pin[5], float pout[5], float dEsum, int track, int stack, int history, int ipart) { float x[3], t; float dx[3], dr; float dEdx; float xlocal[3]; if (!initialized) { mystr_t strings[50]; float values[50]; int nvalues = 50; int status = GetConstants("START_COUNTER/start_parms", &nvalues, values, strings); if (!status) { int ncounter = 0; int i; for ( i=0;i<(int)nvalues;i++){ //printf("%d %s \n", i, strings[i].str); if (!strcmp(strings[i].str,"START_ATTEN_LENGTH")) { ATTEN_LENGTH = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_C_EFFECTIVE")) { C_EFFECTIVE = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_TWO_HIT_RESOL")) { TWO_HIT_RESOL = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_MAX_HITS")) { START_MAX_HITS = (int)values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_THRESH_MEV")) { THRESH_MEV = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_LIGHT_GUIDE")) { LIGHT_GUIDE = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_ANGLE_COR")) { ANGLE_COR = values[i]; ncounter++; } if (!strcmp(strings[i].str,"START_BENT_REGION")) { BENT_REGION = values[i]; ncounter++; } } if (ncounter==8){ printf("START: ALL parameters loaded from Data Base\n"); } else if (ncounter<8){ printf("START: NOT ALL necessary parameters found in Data Base %d out of 8\n",ncounter); } else { printf("START: SOME parameters found more than once in Data Base\n"); } } // Attenuations correction constants for straight section int sc_straight_attenuation_a = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_STRAIGHT_ATTENUATION_A, "SC_STRAIGHT_ATTENUATION_A"); if (sc_straight_attenuation_a) printf("ERROR LOADING SC_STRAIGHT_ATTENUATION_A from START_COUNTER/attenuation_factor"); int sc_straight_attenuation_b = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_STRAIGHT_ATTENUATION_B, "SC_STRAIGHT_ATTENUATION_B"); if (sc_straight_attenuation_b) printf("ERROR LOADING SC_STRAIGHT_ATTENUATION_B from START_COUNTER/attenuation_factor"); int sc_straight_attenuation_c = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_STRAIGHT_ATTENUATION_C, "SC_STRAIGHT_ATTENUATION_C"); if (sc_straight_attenuation_c) printf("ERROR LOADING SC_STRAIGHT_ATTENUATION_C from START_COUNTER/attenuation_factor"); // Attenuation correction constants for bend/nose section int sc_bendnose_attenuation_a = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_BENDNOSE_ATTENUATION_A, "SC_BENDNOSE_ATTENUATION_A"); if (sc_bendnose_attenuation_a) printf("ERROR LOADING SC_BENDNOSE_ATTENUATION_A from START_COUNTER/attenuation_factor"); int sc_bendnose_attenuation_b = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_BENDNOSE_ATTENUATION_B, "SC_BENDNOSE_ATTENUATION_B"); if (sc_bendnose_attenuation_b) printf("ERROR LOADING SC_BENDNOSE_ATTENUATION_B from START_COUNTER/attenuation_factor"); int sc_bendnose_attenuation_c = GetColumn("START_COUNTER/attenuation_factor", &NCHANNELS, SC_BENDNOSE_ATTENUATION_C, "SC_BENDNOSE_ATTENUATION_C"); if (sc_bendnose_attenuation_c) printf("ERROR LOADING SC_BENDNOSE_ATTENUATION_C from START_COUNTER/attenuation_factor"); // Propagation time correction constants for straight section int sc_straight_propagation_a = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_STRAIGHT_PROPAGATION_A, "SC_STRAIGHT_PROPAGATION_A"); if (sc_straight_propagation_a) printf("ERROR LOADING SC_STRAIGHT_PROPAGATION_A from START_COUNTER/propagation_speed"); int sc_straight_propagation_b = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_STRAIGHT_PROPAGATION_B, "SC_STRAIGHT_PROPAGATION_B"); if (sc_straight_propagation_b) printf("ERROR LOADING SC_STRAIGHT_PROPAGATION_B from START_COUNTER/propagation_speed"); // Propagation time correction constants for bend section int sc_bend_propagation_a = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_BEND_PROPAGATION_A, "SC_BEND_PROPAGATION_A"); if (sc_bend_propagation_a) printf("ERROR LOADING SC_BEND_PROPAGATION_A from START_COUNTER/propagation_speed"); int sc_bend_propagation_b = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_BEND_PROPAGATION_B, "SC_BEND_PROPAGATION_B"); if (sc_bend_propagation_b) printf("ERROR LOADING SC_BEND_PROPAGATION_B from START_COUNTER/propagation_speed"); // Propagation time correction constants for nose section int sc_nose_propagation_a = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_NOSE_PROPAGATION_A, "SC_NOSE_PROPAGATION_A"); if (sc_nose_propagation_a) printf("ERROR LOADING SC_NOSE_PROPAGATION_A from START_COUNTER/propagation_speed"); int sc_nose_propagation_b = GetColumn("START_COUNTER/propagation_speed", &NCHANNELS, SC_NOSE_PROPAGATION_B, "SC_NOSE_PROPAGATION_B"); if (sc_nose_propagation_b) printf("ERROR LOADING SC_NOSE_PROPAGATION_B from START_COUNTER/propagation_speed"); initialized = 1; } x[0] = (xin[0] + xout[0])/2; x[1] = (xin[1] + xout[1])/2; x[2] = (xin[2] + xout[2])/2; t = (xin[3] + xout[3])/2 * 1e9; transformCoord(x,"global",xlocal,"local"); dx[0] = xin[0] - xout[0]; dx[1] = xin[1] - xout[1]; dx[2] = xin[2] - xout[2]; dr = sqrt(dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2]); if (dr > 1e-3) { dEdx = dEsum/dr; } else { dEdx = 0; } /* float dbent = 0.0; */ /* float dpath = 0.0; */ /* if(xlocal[2] >= BENT_REGION){ */ /* dbent = ( xlocal[2] - BENT_REGION )*ANGLE_COR; */ /* dpath = BENT_REGION + dbent; */ /* } else { */ /* dpath = xlocal[2]; */ /* } */ /* float dEcorr = dEsum * exp(-dpath/ATTEN_LENGTH); */ /* float tcorr = t + dpath/C_EFFECTIVE; */ // printf("x_gl, z_gl, x_l, z_l %f %f %f\n", // xin[0],xin[1],xin[2]); // printf("x_gl, z_gl, x_l, z_l %f %f %f %f %f %f %f\n", // x[0],x[1],x[2], xlocal[0],xlocal[1],xlocal[2],dpath); /* post the hit to the truth tree */ if (history == 0) { int mark = (1<<30) + pointCount; void** twig = getTwig(&startCntrTree, mark); if (*twig == 0) { s_StartCntr_t* stc = *twig = make_s_StartCntr(); s_StcTruthPoints_t* points = make_s_StcTruthPoints(1); stc->stcTruthPoints = points; int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; points->in[0].primary = (stack <= a); points->in[0].track = track; points->in[0].t = t; points->in[0].z = x[2]; points->in[0].r = sqrt(x[0]*x[0]+x[1]*x[1]); points->in[0].phi = atan2(x[1],x[0]); points->in[0].px = pin[0]*pin[4]; points->in[0].py = pin[1]*pin[4]; points->in[0].pz = pin[2]*pin[4]; points->in[0].E = pin[3]; points->in[0].dEdx = dEdx; points->in[0].ptype = ipart; points->in[0].sector = getsector_wrapper_(); points->in[0].trackID = make_s_TrackID(); points->in[0].trackID->itrack = gidGetId(track); points->mult = 1; pointCount++; } } /* post the hit to the hits tree, mark sector as hit */ // if( (ipart==8) && (x[2]<90.)){ // printf("x_gl, z_gl, x_l, z_l %f %f %f %f %f %f\n", // x[0],x[1],x[2], xlocal[0],xlocal[1],xlocal[2]); // } if (dEsum > 0) { int nhit; s_StcTruthHits_t* hits; int sector = getsector_wrapper_(); // printf("x_gl, z_gl, x_l, z_l %f %f %f %f %f %f\n", // x[0],x[1],x[2], xlocal[0],xlocal[1],xlocal[2]); float dbent = 0.0; float dpath = 0.0; if(xlocal[2] >= BENT_REGION){ dbent = ( xlocal[2] - BENT_REGION )*ANGLE_COR; dpath = BENT_REGION + dbent; } else { dpath = xlocal[2]; } /* float dEcorr = dEsum * exp(-dpath/ATTEN_LENGTH); */ /* float tcorr = t + dpath/C_EFFECTIVE; */ /* printf("\n Sector %d Fired \n t = %.5f \n dEsum = %.5f \n dpath = %.5f \n", */ /* sector, t, dEsum, dpath); */ int sector_index = sector - 1; float dEcorr = 9.9E+9; float tcorr = 9.9E+9; if (xlocal[2] <= STRAIGHT_LENGTH) { dEcorr = dEsum * exp(dpath*SC_STRAIGHT_ATTENUATION_B[sector_index]); tcorr = t + dpath * SC_STRAIGHT_PROPAGATION_B[sector_index] + SC_STRAIGHT_PROPAGATION_A[sector_index]; /* printf("HIT OCCURED IN STRAIGHT SECTION \n"); */ /* printf("Attenuation Corrections: A = %.5f, B = %.5f, C = %.5f \n", SC_STRAIGHT_ATTENUATION_A[sector_index], SC_STRAIGHT_ATTENUATION_B[sector_index], SC_STRAIGHT_ATTENUATION_C[sector_index]); */ /* printf("Time Corrections: B = %.5f, A = %.5f \n", SC_STRAIGHT_PROPAGATION_B[sector_index], SC_STRAIGHT_PROPAGATION_A[sector_index]); */ } else if (xlocal[2] > STRAIGHT_LENGTH && xlocal[2] <= (STRAIGHT_LENGTH + BEND_LENGTH)) { dEcorr = dEsum * ((SC_BENDNOSE_ATTENUATION_A[sector_index] * exp(dpath*SC_BENDNOSE_ATTENUATION_B[sector_index]) + SC_BENDNOSE_ATTENUATION_C[sector_index]) / SC_STRAIGHT_ATTENUATION_A[sector_index]); tcorr = t + dpath * SC_BEND_PROPAGATION_B[sector_index] + SC_BEND_PROPAGATION_A[sector_index]; /* printf("HIT OCCURED IN BEND SECTION \n"); */ /* printf("Attenuation Corrections: A = %.5f, B = %.5f, C = %.5f \n", SC_BENDNOSE_ATTENUATION_A[sector_index], SC_BENDNOSE_ATTENUATION_B[sector_index], SC_BENDNOSE_ATTENUATION_C[sector_index]); */ /* printf("Time Corrections: B = %.5f, A = %.5f \n", SC_BEND_PROPAGATION_B[sector_index], SC_BEND_PROPAGATION_A[sector_index]); */ } else if (xlocal[2] > (STRAIGHT_LENGTH + BEND_LENGTH) && xlocal[2] <= (STRAIGHT_LENGTH + BEND_LENGTH + NOSE_LENGTH)) { dEcorr = dEsum * ((SC_BENDNOSE_ATTENUATION_A[sector_index] * exp(dpath*SC_BENDNOSE_ATTENUATION_B[sector_index]) + SC_BENDNOSE_ATTENUATION_C[sector_index]) / SC_STRAIGHT_ATTENUATION_A[sector_index]); tcorr = t + dpath * SC_NOSE_PROPAGATION_B[sector_index] + SC_NOSE_PROPAGATION_A[sector_index]; /* printf("HIT OCCURED IN NOSE SECTION \n"); */ /* printf("Attenuation Corrections: A = %.5f, B = %.5f, C = %.5f \n", SC_BENDNOSE_ATTENUATION_A[sector_index], SC_BENDNOSE_ATTENUATION_B[sector_index], SC_BENDNOSE_ATTENUATION_C[sector_index]); */ /* printf("Time Corrections: B = %.5f, A = %.5f \n", SC_NOSE_PROPAGATION_B[sector_index], SC_NOSE_PROPAGATION_A[sector_index]); */ } else return; /* printf("tcorr = %.5f \n dEcorr = %.5f \n", tcorr, dEcorr); */ // float dpath = xlocal[2]+(10.2-xlocal[0])*0.4; // float tcorr = t + dpath/C_EFFECTIVE; // float dEcorr = dEsum * exp(-dpath/ATTEN_LENGTH); int mark = sector; void** twig = getTwig(&startCntrTree, mark); if (*twig == 0) { s_StartCntr_t* stc = *twig = make_s_StartCntr(); s_StcPaddles_t* paddles = make_s_StcPaddles(1); paddles->mult = 1; paddles->in[0].sector = sector; paddles->in[0].stcTruthHits = hits = make_s_StcTruthHits(MAX_HITS); stc->stcPaddles = paddles; paddleCount++; } else { s_StartCntr_t* stc = *twig; hits = stc->stcPaddles->in[0].stcTruthHits; } for (nhit = 0; nhit < hits->mult; nhit++) { if (fabs(hits->in[nhit].t - tcorr) < TWO_HIT_RESOL) { break; } } if (nhit < hits->mult) /* merge with former hit */ { if (tcorr < hits->in[nhit].t) { hits->in[nhit].ptype = ipart; hits->in[nhit].itrack = gidGetId(track); } hits->in[nhit].t = (hits->in[nhit].t * hits->in[nhit].dE + tcorr * dEcorr) / (hits->in[nhit].dE + dEcorr); hits->in[nhit].dE += dEcorr; } else if (nhit < MAX_HITS) /* create new hit */ { hits->in[nhit].t = tcorr ; hits->in[nhit].dE = dEcorr; hits->in[nhit].ptype = ipart; hits->in[nhit].itrack = gidGetId(track); hits->mult++; } else { fprintf(stderr,"HDGeant error in hitStart: "); fprintf(stderr,"max hit count %d exceeded, truncating!\n",MAX_HITS); exit(2); } } }
void hitPS(float xin[4], float xout[4],float pin[5], float pout[5], float dEsum, int track, int stack, int history, int ipart) { float x[3], t; float dx[3], dr; float dEdx; float xlocal[3]; if (!initialized) { // Get calibration constants ... initialized = 1; } x[0] = (xin[0] + xout[0])/2; x[1] = (xin[1] + xout[1])/2; x[2] = (xin[2] + xout[2])/2; t = (xin[3] + xout[3])/2 * 1e9; transformCoord(x,"global",xlocal,"local"); dx[0] = xin[0] - xout[0]; dx[1] = xin[1] - xout[1]; dx[2] = xin[2] - xout[2]; dr = sqrt(dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2]); if (dr > 1e-3) { dEdx = dEsum/dr; } else { dEdx = 0; } if (history == 0) { int mark = (1<<30) + pointCount; void** twig = getTwig(&psTree, mark); if (*twig == 0) { s_PairSpectrometerFine_t* ps = *twig = make_s_PairSpectrometerFine(); s_PsTruthPoints_t* points = make_s_PsTruthPoints(1); ps->psTruthPoints = points; int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; points->in[0].primary = (stack <= a); points->in[0].track = track; points->in[0].t = t; points->in[0].z = x[2]; points->in[0].x = x[0]; points->in[0].y = x[1]; points->in[0].phi = atan2(x[1],x[0]); points->in[0].px = pin[0]*pin[4]; points->in[0].py = pin[1]*pin[4]; points->in[0].pz = pin[2]*pin[4]; points->in[0].E = pin[3]; points->in[0].dEdx = dEdx; points->in[0].ptype = ipart; // the fine PS has two arms: North/South (0/1) points->in[0].arm = getcolumn_wrapper_() / NUM_COLUMN_PER_ARM; points->in[0].column = getcolumn_wrapper_() % NUM_COLUMN_PER_ARM; points->in[0].trackID = make_s_TrackID(); points->in[0].trackID->itrack = gidGetId(track); points->mult = 1; pointCount++; } } /* post the hit to the hits tree, mark column as hit */ if (dEsum > 0) { int nhit; s_PsTruthHits_t* hits; int column = getcolumn_wrapper_(); int mark = column; void** twig = getTwig(&psTree, mark); if (*twig == 0) { s_PairSpectrometerFine_t* ps = *twig = make_s_PairSpectrometerFine(); s_PsTiles_t* tiles = make_s_PsTiles(1); tiles->mult = 1; // the fine PS has two arms: North/South (0/1) tiles->in[0].arm = column / NUM_COLUMN_PER_ARM; tiles->in[0].column = column % NUM_COLUMN_PER_ARM; tiles->in[0].psTruthHits = hits = make_s_PsTruthHits(MAX_HITS); ps->psTiles = tiles; tileCount++; } else { s_PairSpectrometerFine_t* ps = *twig; hits = ps->psTiles->in[0].psTruthHits; } for (nhit = 0; nhit < hits->mult; nhit++) { if (fabs(hits->in[nhit].t - t) < TWO_HIT_RESOL) { break; } } if (nhit < hits->mult) /* merge with former hit */ { if (t < hits->in[nhit].t) { hits->in[nhit].ptype = ipart; hits->in[nhit].itrack = gidGetId(track); } hits->in[nhit].t = (hits->in[nhit].t * hits->in[nhit].dE + t * dEsum) / (hits->in[nhit].dE + dEsum); hits->in[nhit].dE += dEsum; } else if (nhit < MAX_HITS) /* create new hit */ { hits->in[nhit].t = t; hits->in[nhit].dE = dEsum; hits->in[nhit].ptype = ipart; hits->in[nhit].itrack = gidGetId(track); hits->mult++; } else { fprintf(stderr,"HDGeant error in hitPS: "); fprintf(stderr,"max hit count %d exceeded, truncating!\n",MAX_HITS); exit(2); } } }
void hitComptonEMcal (float xin[4], float xout[4], float pin[5], float pout[5], float dEsum, int track, int stack, int history, int ipart) { float x[3], t; float xccal[3]; x[0] = (xin[0] + xout[0])/2; x[1] = (xin[1] + xout[1])/2; x[2] = (xin[2] + xout[2])/2; t = (xin[3] + xout[3])/2 * 1e9; transformCoord(x,"global",xccal,"CCAL"); /* post the hit to the truth tree */ if ((history == 0) && (pin[3] > THRESH_MEV/1e3)) { s_CcalTruthShowers_t* showers; int mark = (1<<30) + showerCount; void** twig = getTwig(&ComptonCalTree, mark); if (*twig == 0) { s_ComptonEMcal_t* cal = *twig = make_s_ComptonEMcal(); cal->ccalTruthShowers = showers = make_s_CcalTruthShowers(1); int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; showers->in[0].primary = (stack <= a); showers->in[0].track = track; showers->in[0].t = xin[3]*1e9; showers->in[0].x = xin[0]; showers->in[0].y = xin[1]; showers->in[0].z = xin[2]; showers->in[0].px = pin[0]*pin[4]; showers->in[0].py = pin[1]*pin[4]; showers->in[0].pz = pin[2]*pin[4]; showers->in[0].E = pin[3]; showers->in[0].ptype = ipart; showers->in[0].trackID = make_s_TrackID(); showers->in[0].trackID->itrack = gidGetId(track); showers->mult = 1; showerCount++; } } /* post the hit to the hits tree, mark block as hit */ if (dEsum > 0) { int nhit; s_CcalTruthHits_t* hits; int row = getrow_wrapper_(); int column = getcolumn_wrapper_(); float dist = 0.5*LENGTH_OF_BLOCK-xccal[2]; float dEcorr = dEsum * exp(-dist/ATTEN_LENGTH); float tcorr = t + dist/C_EFFECTIVE; int mark = ((row+1)<<16) + (column+1); void** twig = getTwig(&ComptonCalTree, mark); if (*twig == 0) { s_ComptonEMcal_t* cal = *twig = make_s_ComptonEMcal(); s_CcalBlocks_t* blocks = make_s_CcalBlocks(1); blocks->mult = 1; blocks->in[0].row = row; blocks->in[0].column = column; blocks->in[0].ccalTruthHits = hits = make_s_CcalTruthHits(MAX_HITS); cal->ccalBlocks = blocks; blockCount++; } else { s_ComptonEMcal_t* cal = *twig; hits = cal->ccalBlocks->in[0].ccalTruthHits; } for (nhit = 0; nhit < hits->mult; nhit++) { if (fabs(hits->in[nhit].t - tcorr) < TWO_HIT_RESOL) { break; } } if (nhit < hits->mult) /* merge with former hit */ { /* unclear if the intent here was to add dEcorr to hits->in[nhit].E */ /* in the numerator as well as denominator. This caused a compiler */ /* warning so I chose for it not to. (I'm pretty sure that's right) */ /* 10/28/2015 DL */ /* hits->in[nhit].t = (hits->in[nhit].t * hits->in[nhit].E + tcorr*dEcorr) / (hits->in[nhit].E += dEcorr); */ hits->in[nhit].t = (hits->in[nhit].t * hits->in[nhit].E + tcorr*dEcorr) / (hits->in[nhit].E + dEcorr); hits->in[nhit].E += dEcorr; } else if (nhit < MAX_HITS) /* create new hit */ { hits->in[nhit].t = tcorr; hits->in[nhit].E = dEcorr; hits->mult++; } else { fprintf(stderr,"HDGeant error in hitComptonEMcal: "); fprintf(stderr,"max hit count %d exceeded, truncating!\n",MAX_HITS); exit(2); } } }