returnValue ShootingMethod::differentiateBackward( const int &idx , const Matrix &seed, Matrix &Gx , Matrix &Gp , Matrix &Gu , Matrix &Gw ){ uint run1; Gx.init( seed.getNumRows(), nx ); Gp.init( seed.getNumRows(), np ); Gu.init( seed.getNumRows(), nu ); Gw.init( seed.getNumRows(), nw ); for( run1 = 0; run1 < seed.getNumRows(); run1++ ){ Vector tmp = seed.getRow( run1 ); Vector tmpX( nx ); Vector tmpP( np ); Vector tmpU( nu ); Vector tmpW( nw ); ACADO_TRY( integrator[idx]->setBackwardSeed( 1, tmp ) ); ACADO_TRY( integrator[idx]->integrateSensitivities( ) ); ACADO_TRY( integrator[idx]->getBackwardSensitivities( tmpX, tmpP, tmpU, tmpW , 1 ) ); Gx.setRow( run1, tmpX ); Gp.setRow( run1, tmpP ); Gu.setRow( run1, tmpU ); Gw.setRow( run1, tmpW ); } return SUCCESSFUL_RETURN; }
void CBoxProxyView::drawUnitAxes() { // 实线部分 glPointSize(1.0f); glBegin(GL_POINTS); for (int i=0;i<points.size();i++) { Vector3d tmpP=points.at(i); Vector3d tmpC=pColors.at(i); //glColor3f(tmpC(2)/255,tmpC(1)/255,tmpC(0)/255); if (gettingDepth) { glVertexAttrib4d(ColorPos,tmpC(2)/255,tmpC(1)/255,tmpC(0)/255,0.0); glVertexAttrib4d(VertexPos,tmpP(0),tmpP(1),tmpP(2),1.0); } else glColor3f(tmpC(2)/255,tmpC(1)/255,tmpC(0)/255); glVertex3f(tmpP(0),tmpP(1),tmpP(2)); } glEnd(); }
void CBoxProxyView::GetDepthAfter() { z=new float[640*480]; glReadPixels(0, 0,//y坐标 640,480,//读取一个像素 GL_RED,//获得深度信息 GL_FLOAT,//数据类型为浮点型 z);//获得的深度值保存在winZ中 for (int y=0;y<240;y++) { for (int x=0;x<640;x++) { float tmp; int index1=y*640+x; int index2=(479-y)*640+x; tmp=z[index1]; z[index1]=z[index2]*10; z[index2]=tmp*10; } } if (testMode) { testDepthMap=new MyDepthMap(z,480,640); free(z); sd.removeShader(); resize(width,height); updateCam(); testRes=0; for (int x=0;x<640;x++) { for (int y=0;y<480;y++) { float tmp=fabs(testDepthMap->getDepth(x,y)-viewDepthMap->getDepth(x,y)); if (tmp>0) { testRes+=1; } } } delete testDepthMap; CString c; c.Format("%f",testRes); //MessageBox(c); } else { viewDepthMap=new MyDepthMap(z,480,640); float z1=viewDepthMap->getDepth(289,50); free(z); sd.removeShader(); gettingDepth=false; resize(width,height); updateCam(); float dz=0; for (int x=0;x<640;x++) { for (int y=0;y<480;y++) { float tmp=fabs(myDepthMap->getDepth(x,y)-viewDepthMap->getDepth(x,y)); if (tmp>0) { dz+=tmp; } if (tmp>0.08) { float tz=viewDepthMap->getDepth(x,y); Vector3d p1(x*tz,y*tz,tz); Vector3d p2; Vector4d tmpP=cam.unproject(p1); for (int i=0;i<3;i++) { p2(i)=tmpP(i)/tmpP(3); } Dpoints.push_back(p2); Vector3d p3=cam.project_homo(p2); float tz1=p3(2); tz1=tz1; } } } dz/=480*640; dz=dz; CString c; c.Format("%f",dz); //MessageBox(c); CPaintDC dc(this); OnDraw(&dc); } }
/* TODO: possible to save four-momentum for CHCAL, NHCAL and others into a root file */ void PTCut::ParticleLoop() { for ( unsigned int j = 0; j != jetParts.size(); ++j ) { int absId = jetParts[j].user_index(); int isNHCAL = std::find(neutrals,neutrals+neutrSize,absId)!=(neutrals+neutrSize); int isCHCAL = std::find(chargeds,chargeds+chargSize,absId)!=(chargeds+chargSize); TLorentzVector tmpP( jetParts[j].px(), jetParts[j].py(), jetParts[j].pz(), jetParts[j].e() ); double RHCALf = 1; // In case of hadrons, set initial values for temporary containers if ( isNHCAL || isCHCAL ) { RHCALf = fp1->Eval(max(7.0,tmpP.Perp())); RHCAL->Fill( tmpP.Perp(), RHCALf ); // Record fractions } if ( isCHCAL ) { /* Charged hadrons */ // In 50 % (tracking) of the cases 50 % of charged hadr. receive a worse response (0.7) double cutTrackAndHighPt = 1; if ( tmpP.Perp() > 100 ){ cutTrackAndHighPt = 0.925; } else { cutTrackAndHighPt = 0.97; } double response = (fECAL+fHCAL*((tmpP.Perp()<3) ? 1 : RHCALf) ); double lowECut = ( tmpP.Perp() < 3 ) ? 0 : 1; // 3 GeV cut sumHistPt += cutTrackAndHighPt*tmpP; histCh += cutTrackAndHighPt*tmpP; sumP3GeV += tmpP; sumCaloP3GeV += lowECut*tmpP; sumPHCAL += tmpP; sumCaloPHCAL += response*tmpP; sumPPt += cutTrackAndHighPt*tmpP; sumCaloPPt += cutTrackAndHighPt*lowECut*response*tmpP; sumPHi += cutTrackAndHighPt*tmpP; } else if ( isNHCAL ) { /* Neutral hadrons */ double response = (fECAL+fHCAL*((tmpP.Perp()<3) ? 1 : RHCALf) ); double lowECut = ( tmpP.Perp() < 3 ) ? 0 : 1; // 3 GeV cut double respHCAL = fhr->Eval( tmpP.Perp() ); double respECAL = fer->Eval( tmpP.Perp() ); double respEHHCAL = frh->Eval( tmpP.Perp() ); double respEHECAL = fre->Eval( tmpP.Perp() ); respHCAL = (respHCAL > 0) ? respHCAL : 0; respECAL = (respECAL > 0) ? respECAL : 0; respEHHCAL = (respEHHCAL > 0) ? respEHHCAL : 0; respEHECAL = (respEHECAL > 0) ? respEHECAL : 0; double histResp = HistResp(tmpP, respHCAL, respECAL, respEHHCAL, respEHECAL); histResp = ( (histResp > 0) ? histResp : 0 ); RHCAL->Fill(tmpP.Perp(),histResp); sumHistPt += lowECut*histResp*tmpP; histNh += lowECut*histResp*tmpP; sumP3GeV += lowECut*tmpP; sumCaloP3GeV += lowECut*tmpP; sumPHCAL += response*tmpP; sumCaloPHCAL += response*tmpP; sumPPt += lowECut*response*tmpP; sumCaloPPt += lowECut*response*tmpP; sumPHi += tmpP; } else { /* Others */ bool known = true; if ( absId == 22 ){ histPh += tmpP; } else if ( absId == 11 ){ histE += tmpP; } else if ( absId == 13 ){ histMu += tmpP; } else { known = false; } if (known) sumHistPt += tmpP; sumP3GeV += tmpP; sumCaloP3GeV += tmpP; sumPHCAL += tmpP; sumCaloPHCAL += tmpP; sumPPt += tmpP; sumCaloPPt += tmpP; sumPHi += tmpP; } } }
void DfEriX_Parallel::getK_D_BG(const TlDenseSymmetricMatrix_Scalapack& P, TlDenseSymmetricMatrix_Scalapack* pK) { this->log_.info("background transportation for density matrix."); assert(pK != NULL); const index_type numOfAOs = this->m_nNumOfAOs; pK->resize(numOfAOs); const TlOrbitalInfo orbitalInfo((*(this->pPdfParam_))["coordinates"], (*(this->pPdfParam_))["basis_set"]); const TlSparseSymmetricMatrix schwarzTable = this->makeSchwarzTable(orbitalInfo); TlSparseSymmetricMatrix tmpP(this->m_nNumOfAOs); bool isSetTempP = false; // TlSparseSymmetricMatrix tmpK(this->m_nNumOfAOs); DfTaskCtrl* pDfTaskCtrl = this->getDfTaskCtrlObject(); std::vector<DfTaskCtrl::Task4> taskList; std::vector<index_type> procIndexPQ; std::vector<double> procValues; this->createEngines(); { bool hasTask = pDfTaskCtrl->getQueue4(orbitalInfo, schwarzTable, this->grainSize_, &taskList, true); static const int maxElements = 5 * 5 * 5 * 5 * 4; // means (d * d * d * d * 4-type) index_type* pTaskIndexPairs = new index_type[maxElements * this->grainSize_ * 2]; double* pTaskValues = new double[maxElements * this->grainSize_]; while (hasTask == true) { if (isSetTempP != true) { const int numOfTasks = taskList.size(); for (int task = 0; task < numOfTasks; ++task) { const index_type shellIndexP = taskList[task].shellIndex1; const index_type shellIndexQ = taskList[task].shellIndex2; const index_type shellIndexR = taskList[task].shellIndex3; const index_type shellIndexS = taskList[task].shellIndex4; const int shellTypeP = orbitalInfo.getShellType(shellIndexP); const int shellTypeQ = orbitalInfo.getShellType(shellIndexQ); const int shellTypeR = orbitalInfo.getShellType(shellIndexR); const int shellTypeS = orbitalInfo.getShellType(shellIndexS); const int maxStepsP = 2 * shellTypeP + 1; const int maxStepsQ = 2 * shellTypeQ + 1; const int maxStepsR = 2 * shellTypeR + 1; const int maxStepsS = 2 * shellTypeS + 1; for (int i = 0; i < maxStepsQ; ++i) { const index_type indexQ = shellIndexQ + i; for (int j = 0; j < maxStepsS; ++j) { const index_type indexS = shellIndexS + j; tmpP.set(indexQ, indexS, 0.0); } for (int j = 0; j < maxStepsR; ++j) { const index_type indexR = shellIndexR + j; tmpP.set(indexQ, indexR, 0.0); } } for (int i = 0; i < maxStepsP; ++i) { const index_type indexP = shellIndexP + i; for (int j = 0; j < maxStepsS; ++j) { const index_type indexS = shellIndexS + j; tmpP.set(indexP, indexS, 0.0); } for (int j = 0; j < maxStepsR; ++j) { const index_type indexR = shellIndexR + j; tmpP.set(indexP, indexR, 0.0); } } } isSetTempP = true; } if (P.getSparseMatrix(&tmpP, false) == true) { const int numOfTaskElements = this->getK_integralDriven_part( orbitalInfo, taskList, tmpP, pTaskIndexPairs, pTaskValues); { const std::size_t baseIndexPQ = procIndexPQ.size(); procIndexPQ.resize(baseIndexPQ + numOfTaskElements * 2); std::copy(pTaskIndexPairs, pTaskIndexPairs + numOfTaskElements * 2, procIndexPQ.begin() + baseIndexPQ); const std::size_t baseValues = procValues.size(); procValues.resize(baseValues + numOfTaskElements); std::copy(pTaskValues, pTaskValues + numOfTaskElements, procValues.begin() + baseValues); } tmpP.zeroClear(); isSetTempP = false; hasTask = pDfTaskCtrl->getQueue4(orbitalInfo, schwarzTable, this->grainSize_, &taskList); } P.getSparseMatrix(NULL, false); } delete[] pTaskIndexPairs; pTaskIndexPairs = NULL; delete[] pTaskValues; pTaskValues = NULL; } this->log_.warn("DfEriX_Parallel::getK_D() loop end"); // waiting another proc this->waitAnotherProcs(P); P.getSparseMatrix(NULL, true); this->log_.info("finalize"); TlMatrixUtils::addByList(&(procIndexPQ[0]), &(procValues[0]), procValues.size(), pK); this->destroyEngines(); pDfTaskCtrl->cutoffReport(); delete pDfTaskCtrl; pDfTaskCtrl = NULL; }
void DfEriX_Parallel::getJ_D_BG(const TlDenseSymmetricMatrix_Scalapack& P, TlDenseVector_Scalapack* pRho) { this->log_.info(" background transportation for density matrix."); assert(pRho != NULL); // this->clearCutoffStats(); TlCommunicate& rComm = TlCommunicate::getInstance(); // カットオフ値の設定 const double maxDeltaP = P.getMaxAbsoluteElement(); if (maxDeltaP < 1.0) { this->cutoffThreshold_ /= std::fabs(maxDeltaP); this->log_.info( TlUtils::format("new cutoff threshold = % e", this->cutoffThreshold_)); } const TlOrbitalInfo orbitalInfo((*(this->pPdfParam_))["coordinates"], (*(this->pPdfParam_))["basis_set"]); const TlOrbitalInfo_Density orbitalInfo_Density( (*(this->pPdfParam_))["coordinates"], (*(this->pPdfParam_))["basis_set_j"]); const ShellArrayTable shellArrayTable_Density = this->makeShellArrayTable(orbitalInfo_Density); TlSparseSymmetricMatrix tmpP(this->m_nNumOfAOs); bool isSetTempP = false; TlDenseVector_Lapack tmpRho(this->m_nNumOfAux); this->createEngines(); DfTaskCtrl* pDfTaskCtrl = this->getDfTaskCtrlObject(); std::vector<DfTaskCtrl::Task2> taskList; bool hasTask = pDfTaskCtrl->getQueue2(orbitalInfo, false, this->grainSize_, &taskList, true); while (hasTask == true) { if (isSetTempP != true) { const int numOfTasks = taskList.size(); for (int task = 0; task < numOfTasks; ++task) { const index_type shellIndexP = taskList[task].shellIndex1; const index_type shellIndexQ = taskList[task].shellIndex2; const int shellTypeP = orbitalInfo.getShellType(shellIndexP); const int shellTypeQ = orbitalInfo.getShellType(shellIndexQ); const int maxStepsP = 2 * shellTypeP + 1; const int maxStepsQ = 2 * shellTypeQ + 1; for (int i = 0; i < maxStepsP; ++i) { const index_type indexP = shellIndexP + i; for (int j = 0; j < maxStepsQ; ++j) { const index_type indexQ = shellIndexQ + j; tmpP.set(indexP, indexQ, 0.0); } } } isSetTempP = true; } if (P.getSparseMatrix(&tmpP, false) == true) { this->getJ_part(orbitalInfo, orbitalInfo_Density, shellArrayTable_Density, taskList, tmpP, &tmpRho); tmpP.zeroClear(); isSetTempP = false; hasTask = pDfTaskCtrl->getQueue2(orbitalInfo, false, this->grainSize_, &taskList); // const std::string TF = ((hasTask == true) ? "true" : "false"); // this->log_.warn(TlUtils::format("DfEriX_Parallel::getJ_D() hasTask=%s", // TF.c_str())); } P.getSparseMatrix(NULL, false); } // int allProcFinished = 0; // if (rComm.isMaster() == true) { // const int numOfProcs = rComm.getNumOfProcs(); // for (int proc = 1; proc < numOfProcs; ++proc) { // rComm.sendData(allProcFinished, proc, TAG_ALL_PROC_FINISHED); // } // } else { // rComm.iReceiveData(allProcFinished, 0, TAG_ALL_PROC_FINISHED); // while (true) { // P.getSparseMatrixX(NULL, false); // if (rComm.test(&allProcFinished) == true) { // rComm.wait(&allProcFinished); // break; // } // } // } this->waitAnotherProcs(P); P.getSparseMatrix(NULL, true); // std::cerr << TlUtils::format("[%d] DfEriX_Parallel::getJ_D() end", // rComm.getRank()) // << std::endl; pDfTaskCtrl->cutoffReport(); delete pDfTaskCtrl; pDfTaskCtrl = NULL; this->destroyEngines(); // finalize // this->finalize(pRho); rComm.allReduce_SUM(&tmpRho); *pRho = TlDenseVector_Scalapack(tmpRho); }