void TtipMelody::attemptChanged(int attNr) { if (attNr) { m_score->markMistakes(qa()->question()->attempt(attNr -1)->mistakes); if (qa()->question()->attemptsCount() > 1) m_attemptLabel->setText(QString("<b>%1: </b>").arg((attNr)) + tr("played", "a melody was played (and number follows)") + QString(" <b>%1</b>").arg(qa()->question()->attempt(attNr - 1)->playedCount()) + ", " + TexTrans::effectTxt().toLower() + QString(": <b>%1%</b>").arg(qa()->question()->attempt(attNr - 1)->effectiveness(), 0, 'f', 1, '0') + ", " + tr("time") + ": " + QString("<b> %1</b>").arg(Texam::formatReactTime(qa()->question()->attempt(attNr - 1)->totalTime(), true))); } else { m_score->clearMistakes(); m_attemptLabel->setText(""); } if (qa()->question()->attemptsCount() > 1) { if (attNr && attNr < qa()->question()->attemptsCount()) { QColor attemptColor = TquestionPoint::goodColor(); if (qa()->question()->attempt(attNr - 1)->summary()) { if (qa()->question()->attempt(attNr - 1)->summary() & TQAunit::e_wrongNote) attemptColor = TquestionPoint::wrongColor(); else attemptColor = TquestionPoint::notBadColor(); } m_resultLabel->setText(wasAnswerOKtext(qa()->question(), attemptColor, -1, attNr).replace("<br>", " ")); } else m_resultLabel->setText(wasAnswerOKtext(qa()->question(), qa()->color()).replace("<br>", " ")); } }
TtipMelody::TtipMelody(TquestionPoint *point) : TtipChart(point) { setBgColor(point->color()); setPlainText(" "); m_w = new QWidget(); m_w->setObjectName("m_melodyView"); m_w->setStyleSheet("QWidget#m_melodyView { background: transparent }"); QString txt; if (point->nr()) txt = QString(TquestionAsWdg::questionTxt() + " <big><b>%1.</b></big>").arg(point->nr()); if (point->question()->questionAsNote() && point->question()->answerAsSound()) txt += (" <b>" + TexTrans::playMelodyTxt() + "</b>"); else if (point->question()->questionAsSound() && point->question()->answerAsNote()) txt += (" <b>" + TexTrans::writeMelodyTxt() + "</b>"); QLabel *headLab = new QLabel(txt, m_w); headLab->setAlignment(Qt::AlignCenter); m_score = new TmelodyView(qa()->question()->melody(), m_w); m_score->setFixedHeight(qApp->desktop()->availableGeometry().height() / 12); if (point->question()->exam()) { if (point->question()->exam()->level()->showStrNr) m_score->showStringNumbers(true); } QSpinBox *spinAtt = new QSpinBox(m_w); spinAtt->setRange(0, qa()->question()->attemptsCount()); spinAtt->setPrefix(TexTrans::attemptTxt() + " "); spinAtt->setSuffix(" " + tr("of", "It will give text: 'Attempt x of y'") + QString(" %1").arg(qa()->question()->attemptsCount())); m_attemptLabel = new QLabel(m_w); m_resultLabel = new QLabel(wasAnswerOKtext(point->question(), point->color()).replace("<br>", " "), m_w); m_resultLabel->setAlignment(Qt::AlignCenter); // txt = wasAnswerOKtext(point->question(), point->color()).replace("<br>", " ") + "<br>"; txt = tr("Melody was played <b>%n</b> times", "", qa()->question()->totalPlayBacks()) + "<br>"; txt += TexTrans::effectTxt() + QString(": <big><b>%1%</b></big>, ").arg(point->question()->effectiveness(), 0, 'f', 1, '0'); txt += TexTrans::reactTimeTxt() + QString("<big><b> %1</b></big>").arg(Texam::formatReactTime(point->question()->time, true)); QLabel *sumLab = new QLabel(txt, m_w); sumLab->setAlignment(Qt::AlignCenter); QVBoxLayout *lay = new QVBoxLayout; lay->addWidget(headLab); lay->addWidget(m_score, 0, Qt::AlignCenter); QHBoxLayout *attLay = new QHBoxLayout; attLay->addStretch(); attLay->addWidget(spinAtt); attLay->addStretch(); lay->addLayout(attLay); lay->addWidget(m_attemptLabel); lay->addWidget(m_resultLabel); lay->addWidget(sumLab); m_w->setLayout(lay); m_widget = point->scene()->addWidget(m_w); m_widget->setParentItem(this); connect(spinAtt, SIGNAL(valueChanged(int)), this, SLOT(attemptChanged(int))); }
// replace with existing file with different case if possible // lol at brute force :) char* fix_path(const char* name, void* p) { char* rp = malloc(0x400); //malloc(strlen(p)+1); char pathbuf[0x400]; // buffer overflow, yay? char* path = (char *)p; strcpy(rp, path); // syscalls rely on this... int didfix = 0; //printf("%s: (%d) %s\n", name, qa(rp), rp); // do the magic if (rp[0] != '/') { getcwd(rp, 0x1000); strcat(rp, "/"); strcat(rp, path); } char* pathptr = rp+1; while (pathptr=strchr(pathptr,'/')) { memcpy(pathbuf, rp, pathptr-rp); pathbuf[pathptr-rp] = '\0'; //printf("checking %s: %d\n", pathbuf, qa(pathbuf)); if (qa(pathbuf) == 0) { if (find_replace(pathbuf) == 0) { goto done; } else { //printf("replacing...%s %s %d\n", rp, pathbuf, strlen(pathbuf)); memcpy(rp, pathbuf, strlen(pathbuf)); didfix = 1; } } pathptr++; } if (qa(rp) == 0) { if (find_replace(rp) == 1) { didfix = 1; } } done: if (didfix == 1) { //printf("%s: %s -> %s\n", name, path, rp); // logging if (cc_logfile != NULL) { fprintf(cc_logfile, "%s: %s -> %s\n", name, path, rp); fflush(cc_logfile); } } return rp; }
Real VisibilityGraphPlanner::Distance(const Vector2& a,const Vector2& b) { Config qa(2),qb(2); qa.copy(a); qb.copy(b); return Distance(qa,qb); }
double EuclidDistHeuristic::computeDistance( const Affine3& a, const Affine3& b) const { auto sqrd = [](double d) { return d * d; }; Vector3 diff = b.translation() - a.translation(); double dp2 = m_x_coeff * sqrd(diff.x()) + m_y_coeff * sqrd(diff.y()) + m_z_coeff * sqrd(diff.z()); Quaternion qb(b.rotation()); Quaternion qa(a.rotation()); double dot = qa.dot(qb); if (dot < 0.0) { qb = Quaternion(-qb.w(), -qb.x(), -qb.y(), -qb.z()); dot = qa.dot(qb); } double dr2 = angles::normalize_angle(2.0 * std::acos(dot)); dr2 *= (m_rot_coeff * dr2); SMPL_DEBUG_NAMED(LOG, "Compute Distance: sqrt(%f + %f)", dp2, dr2); return std::sqrt(dp2 + dr2); }
// replaces end with good and returns true if it did a good job int find_replace(char* path) { char pathbuf2[0x400]; // buffer overflow, yay? strcpy(pathbuf2, path); char* a = strrchr(pathbuf2, '/'); a[0] = '\0'; char* filename = a+1; //printf("trying to fix %s in directory %s\n", path, pathbuf2); DIR* dp = opendir(pathbuf2); struct dirent* ep; if (dp != NULL) { while (ep = readdir(dp)) { //printf(" %s\n", ep->d_name); if (strcasecmp(ep->d_name, filename) == 0) { //printf(" switch %s to %s\n", filename, ep->d_name); // i <3 pointer arithmetic strcpy(path + (filename-pathbuf2), ep->d_name); //printf(" new is %s\n", path); return qa(path); } } closedir(dp); } //printf(" can't be fixed\n"); return 0; }
void RagDoll::CreateHinge(Bone* parent, OBB* A, OBB *B, float upperLimit, float lowerLimit, D3DXVECTOR3 hingeAxisA, D3DXVECTOR3 hingeAxisB, bool ignoreCollisions) { if (parent == NULL || A == NULL || B == NULL) return; D3DXMATRIX &parentMat = parent->CombinedTransformationMatrix; btVector3 hingePos(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2)); D3DXVECTOR3 hingePosDX = D3DXVECTOR3(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2)); btRigidBody *a = A->m_pBody; btRigidBody *b = B->m_pBody; btTransform aTrans, bTrans; a->getMotionState()->getWorldTransform(aTrans); b->getMotionState()->getWorldTransform(bTrans); btVector3 aPos = aTrans.getOrigin(); btVector3 bPos = bTrans.getOrigin(); btQuaternion aRot = aTrans.getRotation(); btQuaternion bRot = bTrans.getRotation(); D3DXQUATERNION qa(aRot.x(), aRot.y(), aRot.z(), aRot.w()); D3DXQUATERNION qb(bRot.x(), bRot.y(), bRot.z(), bRot.w()); D3DXMATRIX matPosA, matPosB, matRotA, matRotB, worldA, worldB; D3DXMatrixTranslation(&matPosA, aPos.x(), aPos.y(), aPos.z()); D3DXMatrixTranslation(&matPosB, bPos.x(), bPos.y(), bPos.z()); D3DXMatrixRotationQuaternion(&matRotA, &qa); D3DXMatrixRotationQuaternion(&matRotB, &qb); D3DXMatrixMultiply(&worldA, &matRotA, &matPosA); D3DXMatrixMultiply(&worldB, &matRotB, &matPosB); D3DXVECTOR3 offA(0.0f, A->m_size.y * -0.5f, 0.0f); D3DXVECTOR3 offB(0.0f, B->m_size.y * 0.5f, 0.0f); D3DXMatrixInverse(&worldA, NULL, &worldA); D3DXMatrixInverse(&worldB, NULL, &worldB); D3DXVec3TransformCoord(&offA, &hingePosDX, &worldA); D3DXVec3TransformCoord(&offB, &hingePosDX, &worldB); // btVector3 offsetA(aPos.x() - hingePos.x(), aPos.y() - hingePos.y(), aPos.z() - hingePos.z()); // btVector3 offsetB(bPos.x() - hingePos.x(), bPos.y() - hingePos.y(), bPos.z() - hingePos.z()); btVector3 offsetA(offA.x, offA.y, offA.z); btVector3 offsetB(offB.x, offB.y, offB.z); aTrans.setIdentity(); bTrans.setIdentity(); aTrans.setOrigin(offsetA); bTrans.setOrigin(offsetB); aTrans.getBasis().setEulerZYX(hingeAxisA.x, hingeAxisA.y, hingeAxisA.z); bTrans.getBasis().setEulerZYX(hingeAxisB.x, hingeAxisB.y, hingeAxisB.z); btHingeConstraint *hingeC = new btHingeConstraint(*b, *a, bTrans, aTrans); hingeC->setLimit(lowerLimit, upperLimit); physicsEngine.GetWorld()->addConstraint(hingeC, ignoreCollisions); }
double compareT(Eigen::Isometry3d a, Eigen::Isometry3d b, Eigen::VectorXd weight) { Eigen::Quaterniond qa(a.rotation()); Eigen::Quaterniond qb(b.rotation()); Eigen::Vector3d pa = a.translation(); Eigen::Vector3d pb = b.translation(); Eigen::VectorXd va(7), vb(7), verr(7), vScaled(7); va << pa, qa.x(), qa.y(), qa.z(), qa.w(); vb << pb, qb.x(), qb.y(), qb.z(), qb.w(); verr = vb - va; vScaled = weight.cwiseProduct(verr); return vScaled.squaredNorm(); }
bool VisibilityGraphPlanner::Plan(const Vector2& a,const Vector2& b,vector<Vector2>& path) { Config qa(2),qb(2); qa.copy(a); qb.copy(b); MilestonePath mpath; if(!Plan(qa,qb,mpath)) { path.resize(0); return false; } path.resize(mpath.NumMilestones()); for(size_t i=0;i<path.size();i++) path[i].set(mpath.GetMilestone(i)); return true; }
void Camera::rotateAroundTarget(const quat4f &q) { // force update of transform matrix aff3f vm = viewMatrix(); vec3f t = viewM * target; viewM = Eigen::Translation3f(t) * q * Eigen::Translation3f(-t) * viewM; quat4f qa(viewM.linear()); qa = qa.conjugate(); setOrientation(qa); setPosition(- (qa * viewM.translation())); hasViewChanged = true; }
void StVKInternalForces::AddLinearTermsContribution(double * vertexDisplacements, double * forces, int elementLow, int elementHigh) { if (elementLow < 0) elementLow = 0; if (elementHigh < 0) elementHigh = volumetricMesh->getNumElements(); int * vertices = (int*) malloc (sizeof(int) * numElementVertices); void * elIter; precomputedIntegrals->AllocateElementIterator(&elIter); for(int el=elementLow; el < elementHigh; el++) { precomputedIntegrals->PrepareElement(el, elIter); for(int ver=0; ver<numElementVertices; ver++) vertices[ver] = volumetricMesh->getVertexIndex(el, ver); double lambda = lambdaLame[el]; double mu = muLame[el]; for (int c=0; c<numElementVertices; c++) // over all vertices of the voxel, computing force on vertex c { // linear terms for (int a=0; a<numElementVertices; a++) // over all vertices { Vec3d qa(vertexDisplacements[3*vertices[a]+0], vertexDisplacements[3*vertices[a]+1], vertexDisplacements[3*vertices[a]+2]); Vec3d force = lambda * (precomputedIntegrals->A(elIter,c,a) * qa) + (mu * precomputedIntegrals->B(elIter,a,c)) * qa + mu * (precomputedIntegrals->A(elIter,a,c) * qa); forces[3*vertices[c]+0] += force[0]; forces[3*vertices[c]+1] += force[1]; forces[3*vertices[c]+2] += force[2]; } } } free(vertices); precomputedIntegrals->ReleaseElementIterator(elIter); }
/** * Calculates the orientation of determined by linear interpolation between * q1 and q2. If alpha is 0, then q1 is returned. If alpha is 1, then * q2 is returned. * \param q1 the "initial" orientation * \param q2 the "final" orientation * \param alpha interpolation value (0 <= alpha <= 1) * \return the orientation linearly interpolated between q1 and q2 * \todo rewrite this function to avoid cancellation errors */ QUAT QUAT::slerp(const QUAT& q1, const QUAT& q2, REAL alpha) { if (alpha < (REAL) 0.0 || alpha > (REAL) 1.0) throw std::runtime_error("Attempting to interpolate using QUAT::slerp() with t not in interval [0,1]"); // compute q1'q2 REAL dot = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; // see whether we need to use the conjugate of q2 bool use_conj = (dot < (REAL) 0.0); // clip dot if (dot < (REAL) -1.0) dot = (REAL) -1.0; else if (dot > (REAL) 1.0) dot = (REAL) 1.0; // find the angle between the two REAL theta = std::acos(std::fabs(dot)); if (theta == 0.0) return q1; // do slerp REAL sin1at = std::sin((1-alpha)*theta); REAL sinat = std::sin(alpha*theta); REAL sint_i = (REAL) 1.0/std::sin(theta); QUAT qa(q1.x*sin1at, q1.y*sin1at, q1.z*sin1at, q1.w*sin1at); QUAT qb(q2.x*sinat, q2.y*sinat, q2.z*sinat, q2.w*sinat); if (use_conj) qb.conjugate(); QUAT qc = qa + qb; qc.x *= sint_i; qc.y *= sint_i; qc.z *= sint_i; qc.w *= sint_i; return qc; }
void number_of_particles_leaving_GEM_hits_boxgen(TString pre="", int nevts=0, double mom=4.1){ TDatabasePDG::Instance()-> AddParticle("pbarpSystem","pbarpSystem", 1.9, kFALSE, 0.1, 0,"", 88888); TStopwatch timer; if (pre==""){ //Output File TString OutputFile = "test_analysis_output.root"; TString outPath = ""; //Input simulation Files TString inPIDFile = "pid_complete.root"; TString inParFile = "simparams.root"; } else { //Output File TString outPath = pre + "_"; TString OutputFile = pre + "_test_analysis_output.root"; //Input simulation Files TString inPIDFile = pre + "_pid_complete.root"; TString inParFile = pre + "_simparams.root"; } TString PIDParFile = TString( gSystem->Getenv("VMCWORKDIR")) + "/macro/params/all.par"; //Initialization FairLogger::GetLogger()->SetLogToFile(kFALSE); FairRunAna* RunAna = new FairRunAna(); FairRuntimeDb* rtdb = RunAna->GetRuntimeDb(); RunAna->SetInputFile(inPIDFile); //setup parameter database FairParRootFileIo* parIo = new FairParRootFileIo(); parIo->open(inParFile); FairParAsciiFileIo* parIoPID = new FairParAsciiFileIo(); parIoPID->open(PIDParFile.Data(),"in"); rtdb->setFirstInput(parIo); rtdb->setSecondInput(parIoPID); rtdb->setOutput(parIo); RunAna->SetOutputFile(OutputFile); RunAna->Init(); /************************************************************************* * Create new ntuple and fill them with information ************************************************************************/ //*** create tuples RhoTuple * ntpPiMinus = new RhoTuple("ntpPiMinus", "PiMinus info"); RhoTuple * ntpPiPlus = new RhoTuple("ntpPiPlus", "PiPlus info"); RhoTuple * ntpKaonMinus = new RhoTuple("ntpKaonMinus", "KaonMinus info"); RhoTuple * ntpKaonPlus = new RhoTuple("ntpKaonPlus", "KaonPlus info"); RhoTuple * ntpProton = new RhoTuple("ntpProton", "Proton info"); RhoTuple * ntpAntiProton = new RhoTuple("ntpAntiProton", "Antiproton info"); //Create output file TFile *out = TFile::Open(outPath+"test_output_ana.root","RECREATE"); // data reader Object PndAnalysis* theAnalysis = new PndAnalysis(); if (nevts==0) nevts = theAnalysis->GetEntries(); //RhoCandLists for analysis RhoCandList piplus, piminus, proton, antiproton, kaonminus, kaonplus; RhoCandidate * dummyCand = new RhoCandidate(); //dummy candidate for empty candidate usage double p_m0 = TDatabasePDG::Instance()->GetParticle("proton")->Mass(); TLorentzVector ini (0,0, mom, sqrt(p_m0*p_m0+ mom*mom)+p_m0); TVector3 beamBoost = ini.BoostVector(); PndRhoTupleQA qa(theAnalysis, mom); int evt=-1; while (theAnalysis->GetEvent() && ++evt<nevts){ if ((evt%100)==0) cout << "evt "<< evt <<endl; TString PidSelection = "PidAlgoIdealCharged";//"PidAlgoMvd;PidAlgoStt;PidAlgoDrc"; to change from ideal PID to realistic PID uncomment this! //***Selection with no PID info theAnalysis->FillList(piminus, "PionBestMinus", PidSelection); theAnalysis->FillList(piplus, "PionBestPlus", PidSelection); theAnalysis->FillList(kaonminus, "KaonBestMinus", PidSelection); theAnalysis->FillList(kaonplus, "KaonBestPlus", PidSelection); theAnalysis->FillList(proton, "ProtonBestPlus", PidSelection); theAnalysis->FillList(antiproton, "ProtonBestMinus", PidSelection); //Get piminus information ntpPiMinus->Column("ev", (Float_t) evt); for (int j=0; j<piminus.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = piminus[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpPiMinus->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(piminus[j]); ntpPiMinus->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(piminus[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpPiMinus->Column("GemHit", (int) count, 0); } ntpPiMinus->DumpData(); //Get PiPlus information ntpPiPlus->Column("ev", (int) evt); for (int j=0; j<piplus.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = piplus[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpPiPlus->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(piplus[j]); ntpPiPlus->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(piplus[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpPiPlus->Column("GemHit", (int) count, 0); } ntpPiPlus->DumpData(); ntpKaonMinus->Column("ev", (int) evt); for (int j=0; j<kaonminus.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = kaonminus[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpKaonMinus->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(kaonminus[j]); ntpKaonMinus->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(kaonminus[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpKaonMinus->Column("GemHit", (int) count, 0); } ntpKaonMinus->DumpData(); ntpKaonPlus->Column("ev", (int) evt); for (int j=0; j<kaonplus.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = kaonplus[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpKaonPlus->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(kaonplus[j]); ntpKaonPlus->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(kaonplus[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpKaonPlus->Column("GemHit", (int) count, 0); } ntpKaonPlus->DumpData(); // Get Proton information ntpProton->Column("ev", (int) evt); for (int j=0; j<proton.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = proton[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpProton->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(proton[j]); ntpProton->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(proton[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpProton->Column("GemHit", (int) count, 0); } ntpProton->DumpData(); // Get Antiproton ntpAntiProton->Column("ev", (int) evt); for (int j=0; j<antiproton.GetLength(); ++j){ //information about the mother and MCTruth Candidate TLorentzVector l; float costheta = -999.; RhoCandidate * truth = antiproton[j]->GetMcTruth(); RhoCandidate * mother; if (truth) mother = truth->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpAntiProton->Column("Mother", (Int_t) moth); bool truthmatch = theAnalysis->McTruthMatch(antiproton[j]); ntpAntiProton->Column("MCTruthMatch", (bool) truthmatch); int gemhit = GemHits(antiproton[j]); int count = 0; if (moth==88888 && gemhit==1 && truthmatch==1) count=1; ntpAntiProton->Column("GemHit", (int) count, 0); } ntpAntiProton->DumpData(); } //Write output out->cd(); ntpPiMinus ->GetInternalTree()->Write(); ntpPiPlus->GetInternalTree()->Write(); ntpKaonMinus ->GetInternalTree()->Write(); ntpKaonPlus->GetInternalTree()->Write(); ntpProton->GetInternalTree()->Write(); ntpAntiProton->GetInternalTree()->Write(); out->Save(); timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); cout<<"Macro finisched successfully."<<endl; cout<<"Realtime: "<<rtime<<" s, CPU time: "<<ctime<<" s"<<endl; cout<<endl; exit(0); }
void StrandBlockSolver::gradQa(const int& mglevel) { if (mglevel == 0 && gradient != 0 && gradQaFlag == 0){ // compute nodal values nodalQa(mglevel); // initialize gradients for (int n=0; n<nFaces+nBedges; n++) for (int j=0; j<nPstr+2; j++) for (int k=0; k<ndim; k++) for (int m=0; m<nqa; m++) qax(m,k,j,n) = 0.; // loop through unstructured edges int c1,c2,n1,n2,jm,jp,k; double Ax,Ay,sqa; for (int n=0; n<nEdges; n++){ c1 = edge(0,n); c2 = edge(1,n); n1 = edgn(n); for (int j=1; j<nPstr+1; j++){ jm = j-1; Ax = facs(0,j,n); Ay = facs(1,j,n); for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); sqa = qap(k,jm,n1)+qap(k,j,n1); qax(k,0,j,c1) += Ax*sqa; qax(k,1,j,c1) += Ay*sqa; qax(k,0,j,c2) -= Ax*sqa; qax(k,1,j,c2) -= Ay*sqa; }}} // loop through structured edges for (int n=0; n<nFaces-nGfaces; n++){ n1 = face(0,n); n2 = face(1,n); for (int j=0; j<nPstr+1; j++){ jp = j+1; Ax = facu(0,j,n); Ay = facu(1,j,n); for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); sqa = qap(k,j,n1)+qap(k,j,n2); qax(k,0,j ,n) += Ax*sqa; qax(k,1,j ,n) += Ay*sqa; qax(k,0,jp,n) -= Ax*sqa; qax(k,1,jp,n) -= Ay*sqa; }}} // divide by twice the volume for the interior cells for (int n=0; n<nFaces-nGfaces; n++) for (int j=1; j<nPstr+1; j++) for (int m=0; m<ndim; m++) for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); qax(k,m,j,n) /= (2.*v(j,n)); } // surface, end, and boundary gradients double dx1,dy1,dx2,dy2,ds,l11,l12,l21,l22,sqa1,sqa2,eps=1.e-14; int j=0; jp = 1; for (int n=0; n<nFaces-nGfaces; n++){ n1 = face(0,n); n2 = face(1,n); dx1 = x (0,j ,n2)-x (0,j,n1); dy1 = x (1,j ,n2)-x (1,j,n1); dx2 = xc(0,jp,n )-xc(0,j,n ); dy2 = xc(1,jp,n )-xc(1,j,n ); ds = dx1*dy2-dx2*dy1; if (fabs(ds) < eps) ds = 0.; // on sharp corners qax = 0. else ds = 1./ds; l11 = ds*dy2; l12 =-ds*dy1; l21 =-ds*dx2; l22 = ds*dx1; for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); sqa1 = qap(k,j ,n2)-qap(k,j,n1); sqa2 = qa (k,jp,n )-qa (k,j,n ); qax(k,0,j,n) = l11*sqa1+l12*sqa2; qax(k,1,j,n) = l21*sqa1+l22*sqa2; }} j = nPstr+1; jm = nPstr; for (int n=0; n<nFaces-nGfaces; n++){ n1 = face(0,n); n2 = face(1,n); dx1 = x (0,j ,n2)-x (0,j,n1); dy1 = x (1,j ,n2)-x (1,j,n1); dx2 = xc(0,jm,n )-xc(0,j,n ); dy2 = xc(1,jm,n )-xc(1,j,n ); ds = dx1*dy2-dx2*dy1; if (fabs(ds) < eps) ds = 0.; else ds = 1./ds; l11 = ds*dy2; l12 =-ds*dy1; l21 =-ds*dx2; l22 = ds*dx1; for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); sqa1 = qap(k,j ,n2)-qap(k,j,n1); sqa2 = qa (k,jm,n )-qa (k,j,n ); qax(k,0,j,n) = l11*sqa1+l12*sqa2; qax(k,1,j,n) = l21*sqa1+l22*sqa2; }} for (int n=nEdges-nBedges; n<nEdges; n++){ c1 = edge(0,n); c2 = edge(1,n); n1 = edgn( n); for (int j=1; j<nPstr+1; j++){ jm = j-1; dx1 = x (0,j,n1)-x (0,jm,n1); dy1 = x (1,j,n1)-x (1,jm,n1); dx2 = xc(0,j,c1)-xc(0,j ,c2); dy2 = xc(1,j,c1)-xc(1,j ,c2); ds = dx1*dy2-dx2*dy1; if (fabs(ds) < eps) ds = 0.; else ds = 1./ds; l11 = ds*dy2; l12 =-ds*dy1; l21 =-ds*dx2; l22 = ds*dx1; for (int kk=0; kk<nqaGradQa; kk++){ k = iqagrad(kk); sqa1 = qap(k,j,n1)-qap(k,jm,n1); sqa2 = qa (k,j,c1)-qa (k,j ,c2); qax(k,0,j,c2) = l11*sqa1+l12*sqa2; qax(k,1,j,c2) = l21*sqa1+l22*sqa2; }}} gradQaFlag = 1; } }
void StrandBlockSolver::rhsViscousFine() { int c1,c2,n1,n2,fc,jm,jp,npts=1; double dx1,dy1,dx2,dy2,ds,dq1,dq2,eps=1.e-14, qxe[nq],qye[nq],qaxe[nqa],qaye[nqa],qe[nq],qae[nqa],fv[nq]; // unstructured faces for (int n=0; n<nEdges; n++){ c1 = edge(0,n); c2 = edge(1,n); n1 = edgn(n); fc = fClip(c1); if (fClip(c2) > fc) fc = fClip(c2); for (int j=1; j<fc+1; j++){ jm = j-1; dx1 = x (0,j,n1)-x (0,jm,n1); dy1 = x (1,j,n1)-x (1,jm,n1); dx2 = xc(0,j,c2)-xc(0,j ,c1); dy2 = xc(1,j,c2)-xc(1,j ,c1); ds = 1./(dx1*dy2-dx2*dy1); for (int k=0; k<nq; k++){ dq1 = qp(k,j,n1)-qp(k,jm,n1); dq2 = q (k,j,c2)-q (k,j ,c1); qxe[k] = ds*( dy2*dq1-dy1*dq2); qye[k] = ds*(-dx2*dq1+dx1*dq2); qe[k] = .5*(qp (k,j,n1)+qp (k,jm,n1)); } for (int k=0; k<nqa; k++){ dq1 = qap(k,j,n1)-qap(k,jm,n1); dq2 = qa (k,j,c2)-qa (k,j ,c1); qaxe[k] = ds*( dy2*dq1-dy1*dq2); qaye[k] = ds*(-dx2*dq1+dx1*dq2); qae[k] = .5*(qap(k,j,n1)+qap(k,jm,n1)); } sys->rhsVisFlux(npts,&facs(0,j,n),&qe[0],&qae[0],&qxe[0],&qye[0], &qaxe[0],&qaye[0],&fv[0]); for (int k=0; k<nq; k++){ r(k,j,c1) -= fv[k]; r(k,j,c2) += fv[k]; }}} // structured faces for (int n=0; n<nFaces-nGfaces; n++){ n1 = face(0,n); n2 = face(1,n); for (int j=0; j<fClip(n)+1; j++){ jp = j+1; dx1 = x (0,j ,n2)-x (0,j,n1); dy1 = x (1,j ,n2)-x (1,j,n1); dx2 = xc(0,jp,n )-xc(0,j,n ); dy2 = xc(1,jp,n )-xc(1,j,n ); ds = dx1*dy2-dx2*dy1; if (fabs(ds) < eps) for (int k=0; k<nq; k++) fv[k] = 0.; else{ ds = 1./ds; for (int k=0; k<nq; k++){ dq1 = qp(k,j ,n2)-qp(k,j,n1); dq2 = q (k,jp,n )-q (k,j,n ); qxe[k] = ds*( dy2*dq1-dy1*dq2); qye[k] = ds*(-dx2*dq1+dx1*dq2); qe[k] = .5*(qp (k,j,n1)+qp (k,j,n2)); } for (int k=0; k<nqa; k++){ dq1 = qap(k,j ,n2)-qap(k,j,n1); dq2 = qa (k,jp,n )-qa (k,j,n ); qaxe[k] = ds*( dy2*dq1-dy1*dq2); qaye[k] = ds*(-dx2*dq1+dx1*dq2); qae[k] = .5*(qap(k,j,n1)+qap(k,j,n2)); } sys->rhsVisFlux(npts,&facu(0,j,n),&qe[0],&qae[0],&qxe[0],&qye[0], &qaxe[0],&qaye[0],&fv[0]); } for (int k=0; k<nq; k++){ r(k,j ,n) -= fv[k]; r(k,jp,n) += fv[k]; }}} }
EllipsoidFitter::Calibration EllipsoidFitter::calculateFit(void) const { /********************************************************************* First step: Fit a quadric to the point set by least-squares minimization based on algebraic distance. *********************************************************************/ /* Create the least-squares system: */ Math::Matrix a(10,10,0.0); /* Process all points: */ for(Misc::ChunkedArray<Point>::const_iterator pIt=points.begin();pIt!=points.end();++pIt) { /* Create the point's associated linear equation: */ double eq[10]; eq[0]=(*pIt)[0]*(*pIt)[0]; eq[1]=2.0*(*pIt)[0]*(*pIt)[1]; eq[2]=2.0*(*pIt)[0]*(*pIt)[2]; eq[3]=2.0*(*pIt)[0]; eq[4]=(*pIt)[1]*(*pIt)[1]; eq[5]=2.0*(*pIt)[1]*(*pIt)[2]; eq[6]=2.0*(*pIt)[1]; eq[7]=(*pIt)[2]*(*pIt)[2]; eq[8]=2.0*(*pIt)[2]; eq[9]=1.0; /* Insert the equation into the least-squares system: */ for(unsigned int i=0;i<10;++i) for(unsigned int j=0;j<10;++j) a(i,j)+=eq[i]*eq[j]; } /* Find the least-squares system's smallest eigenvalue: */ std::pair<Math::Matrix,Math::Matrix> qe=a.jacobiIteration(); unsigned int minEIndex=0; double minE=Math::abs(qe.second(0,0)); for(unsigned int i=1;i<10;++i) { if(minE>Math::abs(qe.second(i,0))) { minEIndex=i; minE=Math::abs(qe.second(i,0)); } } /* Create the quadric's defining matrices: */ Math::Matrix qa(3,3); qa(0,0)=qe.first(0,minEIndex); qa(0,1)=qe.first(1,minEIndex); qa(0,2)=qe.first(2,minEIndex); qa(1,0)=qe.first(1,minEIndex); qa(1,1)=qe.first(4,minEIndex); qa(1,2)=qe.first(5,minEIndex); qa(2,0)=qe.first(2,minEIndex); qa(2,1)=qe.first(5,minEIndex); qa(2,2)=qe.first(7,minEIndex); Math::Matrix qb(3,1); qb(0)=qe.first(3,minEIndex); qb(1)=qe.first(6,minEIndex); qb(2)=qe.first(8,minEIndex); double qc=qe.first(9,minEIndex); /* Calculate the quadric's principal axes: */ qe=qa.jacobiIteration(); std::cout<<std::fixed<<std::setprecision(6); std::cout<<std::setw(9)<<qe.first<<std::endl; std::cout<<std::setw(9)<<qe.second<<std::endl<<std::endl; std::cout.unsetf(std::ios_base::floatfield); /* "Complete the square" to calculate the quadric's centroid and radii: */ Math::Matrix qbp=qb.divideFullPivot(qe.first); Math::Matrix cp(3,1); for(int i=0;i<3;++i) cp(i)=-qbp(i)/qe.second(i); Math::Matrix c=qe.first*cp; std::cout<<"Centroid: "<<c(0)<<", "<<c(1)<<", "<<c(2)<<std::endl; double rhs=-qc; for(int i=0;i<3;++i) rhs+=Math::sqr(qbp(i))/qe.second(i); double radii[3]; for(int i=0;i<3;++i) radii[i]=Math::sqrt(rhs/qe.second(i)); std::cout<<"Radii: "<<radii[0]<<", "<<radii[1]<<", "<<radii[2]<<std::endl; Scalar averageRadius=Math::pow(radii[0]*radii[1]*radii[2],1.0/3.0); std::cout<<"Average radius: "<<averageRadius<<std::endl; /* Calculate the calibration matrix: */ Math::Matrix ellP(4,4,1.0); for(int i=0;i<3;++i) for(int j=0;j<3;++j) ellP(i,j)=qe.first(i,j); Math::Matrix ellScale(4,4,1.0); for(int i=0;i<3;++i) ellScale(i,i)=averageRadius/radii[i]; Math::Matrix ell=ellP; ell.makePrivate(); for(int i=0;i<3;++i) ell(i,3)=c(i); Math::Matrix ellInv=ell.inverseFullPivot(); Math::Matrix calib=ellP*ellScale*ellInv; std::cout<<std::fixed<<std::setprecision(6); std::cout<<std::setw(9)<<calib<<std::endl; std::cout.unsetf(std::ios_base::floatfield); /* Calculate the calibration residual: */ double rms=0.0; for(Misc::ChunkedArray<Point>::const_iterator pIt=points.begin();pIt!=points.end();++pIt) { /* Calibrate the point: */ Math::Matrix p(4,1); for(int i=0;i<3;++i) p(i)=(*pIt)[i]; p(3)=1.0; Math::Matrix cp=calib*p; rms+=Math::sqr(Math::sqrt(Math::sqr(cp(0))+Math::sqr(cp(1))+Math::sqr(cp(2)))-averageRadius); } std::cout<<"Calibration residual: "<<Math::sqrt(rms/double(points.size()))<<std::endl; /* Create and return the calibration result: */ Matrix result; for(int i=0;i<3;++i) for(int j=0;j<4;++j) result(i,j)=calib(i,j); return Calibration(result,averageRadius); }
void Tri2dFCBlockSolver::rhsViscous() { if (order == 1 || order == 2){ // Galerkin int n1,n2,n3,nn; double xa,ya,xb,yb,xc,yc,vr,fv[nq],gv[nq]; Array2D<double> qc(3,nq),qac(3,nqa),cx(3,2); for (int n=0; n<nTri; n++){ n1 = tri(n,0); n2 = tri(n,1); n3 = tri(n,2); xa = x(n1,0); ya = x(n1,1); xb = x(n2,0); yb = x(n2,1); xc = x(n3,0); yc = x(n3,1); vr = xa*(yb-yc)+xb*(yc-ya)+xc*(ya-yb); vr = 2./vr; for (int i=0; i<3; i++){ for (int k=0; k<nq ; k++) qc (i,k) = q (n1,k); for (int k=0; k<nqa; k++) qac(i,k) = qa(n1,k); cx(i,0) = .5*(x(n3,1)-x(n2,1)); cx(i,1) = .5*(x(n2,0)-x(n3,0)); nn = n1; n1 = n2; n2 = n3; n3 = nn; } sys->rhsVisFluxGalerkin(1,&vr,&cx(0,0),&qc(0,0),&qac(0,0),&fv[0],&gv[0]); for (int k=0; k<nq ; k++) d(n1,k) -=(cx(0,0)*fv[k]+cx(0,1)*gv[k]); for (int k=0; k<nq ; k++) d(n2,k) -=(cx(1,0)*fv[k]+cx(1,1)*gv[k]); for (int k=0; k<nq ; k++) d(n3,k) -=(cx(2,0)*fv[k]+cx(2,1)*gv[k]); } qc.deallocate(); qac.deallocate(); cx.deallocate(); } else{// third-order scheme int m,l1,l2,n1,n2; double dx,dy,fk,Ax,Ay,cf,cg,a=.5; Array2D<double> qaxE(nne,nqaGradQa),qayE(nne,nqaGradQa); Array2D<double> f(nne,nq),g(nne,nq); Array2D<double> fx(nne,nq),gx(nne,nq),fy(nne,nq),gy(nne,nq); for (int n=0; n<nElem; n++){ qaxE.set(0.); qayE.set(0.); fx.set(0.); fy.set(0.); gx.set(0.); gy.set(0.); // compute local gradients at the nodes in this element for (int i=0; i<nne; i++) for (int j=0; j<nne; j++){ dx = dxg(n,i,j,0); dy = dxg(n,i,j,1); m = elem(n,j); for (int k=0; k<nqaGradQa; k++){ qaxE(i,k) += qa(m,iqagrad(k))*dx; qayE(i,k) += qa(m,iqagrad(k))*dy; }} // compute viscous fluxes at the nodes in this element for (int i=0; i<nne; i++){ m = elem(n,i); sys->rhsVisFlux(1,&q(m,0),&qa(m,0),&qaxE(i,0),&qayE(i,0), &f(i,0),&g(i,0)); } // compute gradients of viscous fluxes for (int i=0; i<nne; i++) for (int j=0; j<nne; j++){ dx = dxg(n,i,j,0); dy = dxg(n,i,j,1); for (int k=0; k<nq ; k++){ fx(i,k) += f(j,k)*dx; gx(i,k) += g(j,k)*dx; fy(i,k) += f(j,k)*dy; gy(i,k) += g(j,k)*dy; }} // compute directed viscous fluxes and corrections // at edges and distribute to nodes for (int i=0; i<nee; i++){ l1 = edgeE(i,0); l2 = edgeE(i,1); n1 = elem(n,l1); n2 = elem(n,l2); Ax = a*areaE(n,i,0); Ay = a*areaE(n,i,1); dx = .5*(x(n2,0)-x(n1,0)); dy = .5*(x(n2,1)-x(n1,1)); for (int k=0; k<nq; k++){ cf = dx*(fx(l2,k)-fx(l1,k))+ dy*(fy(l2,k)-fy(l1,k)); cg = dx*(gx(l2,k)-gx(l1,k))+ dy*(gy(l2,k)-gy(l1,k)); fk = Ax*(f(l1,k)+f(l2,k)-cf)+Ay*(g(l1,k)+g(l2,k)-cg); d(n1,k) -= fk; d(n2,k) += fk; }}} qaxE.deallocate(); qayE.deallocate(); f.deallocate(); g.deallocate(); fx.deallocate(); gx.deallocate(); fy.deallocate(); gy.deallocate(); } }
void VisibilityGraphPlanner::AllDistances(const Vector2& a,vector<Real>& distances) { Config qa(2); qa.copy(a); AllDistances(qa,distances); }
void analysis_pbarp_Xi_test(int nevts=0){ TDatabasePDG::Instance()-> AddParticle("pbarpSystem","pbarpSystem", 1.9, kFALSE, 0.1, 0,"", 88888); TStopwatch timer; //Output File TString Path = "/private/puetz/mysimulations/analysis/pbarp_Xiplus_Ximinus/idealtracking/10000_events/"; TString outPath = Path; TString OutputFile = outPath + "analysis_output_test.root"; //Input simulation Files TString inPIDFile = Path + "pid_complete.root"; TString inParFile = Path + "simparams.root"; TString PIDParFile = TString( gSystem->Getenv("VMCWORKDIR")) + "/macro/params/all.par"; //Initialization FairLogger::GetLogger()->SetLogToFile(kFALSE); FairRunAna* RunAna = new FairRunAna(); FairRuntimeDb* rtdb = RunAna->GetRuntimeDb(); RunAna->SetInputFile(inPIDFile); //setup parameter database FairParRootFileIo* parIo = new FairParRootFileIo(); parIo->open(inParFile); FairParAsciiFileIo* parIoPID = new FairParAsciiFileIo(); parIoPID->open(PIDParFile.Data(),"in"); rtdb->setFirstInput(parIo); rtdb->setSecondInput(parIoPID); rtdb->setOutput(parIo); RunAna->SetOutputFile(OutputFile); RunAna->Init(); //*** create tuples RhoTuple * ntpMC = new RhoTuple("ntpMC", "MCTruth info"); RhoTuple * ntpPiMinus = new RhoTuple("ntpPiMinus", "PiMinus info"); RhoTuple * ntpPiPlus = new RhoTuple("ntpPiPlus", "PiPlus info"); RhoTuple * ntpProton = new RhoTuple("ntpProton", "Proton info"); RhoTuple * ntpAntiProton = new RhoTuple("ntpAntiProton", "Antiproton info"); RhoTuple * ntpLambda0 = new RhoTuple("ntpLambda0", "Lambda0 info"); RhoTuple * ntpAntiLambda0 = new RhoTuple("ntpAntiLambda0", "AntiLambda0 info"); RhoTuple * ntpXiMinus = new RhoTuple("ntpXiMinus", "XiMinus info"); RhoTuple * ntpXiPlus = new RhoTuple("ntpXiPlus", "XiPlus info"); RhoTuple * ntpXiSys = new RhoTuple("ntpXiSys", "XiMinus XiPlus system info"); //Create output file TFile *out = TFile::Open(outPath+"output_ana_test.root","RECREATE"); // data reader Object PndAnalysis* theAnalysis = new PndAnalysis(); if (nevts==0) nevts = theAnalysis->GetEntries(); //RhoCandLists for analysis RhoCandList piplus, piminus, lambda0, antiLambda0, proton, antiProton, xiplus, ximinus, xiSys; RhoCandList NotCombinedPiMinus, CombinedPiMinus, CombinedPiPlus, NotCombinedPiPlus; RhoCandList SelectedProton, SelectedAntiProton, SelectedPiMinus, SelectedPiPlus; RhoCandList Lambda0Fit, AntiLambda0Fit, XiMinusFit, XiPlusFit; RhoCandList mclist, all; //Dummy RhoCandidate RhoCandidate * dummyCand = new RhoCandidate(); //***Mass selector double m0_lambda0= TDatabasePDG::Instance()->GetParticle("Lambda0")->Mass(); cout<<"Mass of Lambda0: "<<m0_lambda0<<endl; RhoMassParticleSelector * lambdaMassSelector = new RhoMassParticleSelector("lambda0", m0_lambda0, 0.3); double m0_Xi = TDatabasePDG::Instance()->GetParticle("Xi-")->Mass(); cout<<"Mass of Xi-: "<<m0_Xi<<endl; RhoMassParticleSelector * xiMassSelector = new RhoMassParticleSelector("Xi-", m0_Xi, 0.3); double m0_pbarpsystem = TDatabasePDG::Instance()->GetParticle("pbarpSystem")->Mass(); double pbarmom = 2.7; double p_m0 = TDatabasePDG::Instance()->GetParticle("proton")->Mass(); TLorentzVector ini (0,0, pbarmom, sqrt(p_m0*p_m0+ pbarmom*pbarmom)+p_m0); TVector3 beamBoost = ini.BoostVector(); PndRhoTupleQA qa(theAnalysis, pbarmom); int evt=-1; int index=0; while (theAnalysis->GetEvent() && ++evt<nevts){ if ((evt%100)==0) cout << "evt "<< evt <<endl; cout << "Running event " << evt << endl; //***get MC list and store info theAnalysis->FillList(mclist, "McTruth"); qa.qaMcList("", mclist, ntpMC); ntpMC->DumpData(); //if you want to print the hole MCTree uncomment the following /* for (int j=0;j<mclist.GetLength();++j) { RhoCandidate *mcmother = mclist[j]->TheMother(); // mother of mc particle int muid = (mcmother==0x0) ? -1 : mcmother->GetTrackNumber(); // track ID of mother, if existing cout << "Track "<< mclist[j]->GetTrackNumber()<<" (PDG:"<<mclist[j]->PdgCode() <<") has mother "<<muid; if (mclist[j]->NDaughters()>0) cout <<" and daughter(s) "; for (k=0;k<mclist[j]->NDaughters();++k) cout <<mclist[j]->Daughter(k)->GetTrackNumber()<<" "; cout<<endl; }*/ //***Setup event shape object TString PidSelection = "PidAlgoIdealCharged";//"PidAlgoMvd;PidAlgoStt;PidAlgoDrc"; theAnalysis->FillList(all, "All", PidSelection); PndEventShape evsh(all, ini, 0.05, 0.1); //***Selection with no PID info theAnalysis->FillList(piminus, "PionAllMinus", PidSelection); // theAnalysis->FillList(NotCombinedPiMinus, "PionAllMinus", PidSelection); // theAnalysis->FillList(NotCombinedPiPlus, "PionAllPlus", PidSelection); theAnalysis->FillList(piplus, "PionAllPlus", PidSelection); theAnalysis->FillList(proton, "ProtonAllPlus", PidSelection); theAnalysis->FillList(antiProton, "ProtonAllMinus", PidSelection); for (int pip=0; pip<piplus.GetLength(); ++pip){ ntpPiPlus->Column("ev", (Float_t) evt); ntpPiPlus->Column("cand", (Float_t) pip); ntpPiPlus->Column("ncand", (Float_t) piplus.GetLength()); ntpPiPlus->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(piplus[pip])); qa.qaP4("PiPlus_", piplus[pip]->P4(), ntpPiPlus); qa.qaCand("PiPlus_", piplus[pip], ntpPiPlus); jenny::numberOfHitsInSubdetector("PiPlus_", piplus[pip], ntpPiPlus); jenny::tagNHits("PiPlus_", piplus[pip], ntpPiPlus); int tag = jenny::tagHits(piplus[pip]); RhoCandidate * mother_pip = piplus[pip]->GetMcTruth()->TheMother(); int moth_pip = (0x0==mother_pip)? 88888 : mother_pip->PdgCode(); ntpPiPlus->Column("Mother", (Float_t) moth_pip); ntpPiPlus->Column("PiPlus_CosTheta", (Float_t) piplus[pip]->GetMomentum().CosTheta()); qa.qaP4("PiPlus_MC_", piplus[pip]->GetMcTruth()->P4(), ntpPiPlus); qa.qaCand("PiPlus_MC_", piplus[pip]->GetMcTruth(), ntpPiPlus); ntpPiPlus->Column("PiPlus_MC_CosTheta", (Float_t) piplus[pip]->GetMcTruth()->GetMomentum().CosTheta()); if(tag==1){ SelectedPiPlus.Append(piplus[pip]); NotCombinedPiPlus.Append(piplus[pip]); } ntpPiPlus->DumpData(); } for (int pim=0; pim<piminus.GetLength(); ++pim){ ntpPiMinus->Column("ev", (Float_t) evt); ntpPiMinus->Column("cand", (Float_t) pim); ntpPiMinus->Column("ncand", (Float_t) piminus.GetLength()); ntpPiMinus->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(piminus[pim])); qa.qaP4("piminus_", piminus[pim]->P4(), ntpPiMinus); qa.qaCand("piminus_", piminus[pim], ntpPiMinus); jenny::numberOfHitsInSubdetector("piminus_", piminus[pim], ntpPiMinus); jenny::tagNHits("piminus_", piminus[pim], ntpPiMinus); int tag = jenny::tagHits(piminus[pim]); RhoCandidate * mother_pim = piminus[pim]->GetMcTruth()->TheMother(); int moth_pim = (0x0==mother_pim)? 88888 : mother_pim->PdgCode(); ntpPiMinus->Column("Mother", (Float_t) moth_pim); ntpPiMinus->Column("PiMinus_CosTheta", (Float_t) piminus[pim]->GetMomentum().CosTheta()); qa.qaP4("piminus_MC_", piminus[pim]->GetMcTruth()->P4(), ntpPiMinus); qa.qaCand("piminus_MC_", piminus[pim]->GetMcTruth(), ntpPiMinus); ntpPiMinus->Column("piminus_MC_CosTheta", (Float_t) piminus[pim]->GetMcTruth()->GetMomentum().CosTheta()); ntpPiMinus->DumpData(); if(tag==1){ SelectedPiMinus.Append(piminus[pim]); NotCombinedPiMinus.Append(piminus[pim]); } } for (int prot=0; prot<proton.GetLength(); ++prot){ ntpProton->Column("ev", (Float_t) evt); ntpProton->Column("cand", (Float_t) prot); ntpProton->Column("ncand", (Float_t) proton.GetLength()); ntpProton->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(proton[prot])); qa.qaP4("proton_", proton[prot]->P4(), ntpProton); qa.qaCand("proton_", proton[prot], ntpProton); jenny::numberOfHitsInSubdetector("proton_", proton[prot], ntpProton); // jenny::tagNHits("proton_", proton[prot], ntpProton); int tag = jenny::tagHits(proton[prot]); RhoCandidate * mother_prot = proton[prot]->GetMcTruth()->TheMother(); int moth_prot = (0x0==mother_prot)? 88888 : mother_prot->PdgCode(); ntpProton->Column("Mother", (Float_t) moth_prot); ntpProton->Column("proton_CosTheta", (Float_t) proton[prot]->GetMomentum().CosTheta()); qa.qaP4("proton_MC_", proton[prot]->GetMcTruth()->P4(), ntpProton); qa.qaCand("proton_", proton[prot]->GetMcTruth(), ntpProton); ntpProton->Column("proton_MC_CosTheta", (Float_t) proton[prot]->GetMcTruth()->GetMomentum().CosTheta()); ntpProton->DumpData(); if(tag==1) SelectedProton.Append(proton[prot]); } for (int aProt=0; aProt<antiProton.GetLength(); ++aProt){ ntpAntiProton->Column("ev", (Float_t) evt); ntpAntiProton->Column("cand", (Float_t) aProt); ntpAntiProton->Column("ncand", (Float_t) antiProton.GetLength()); ntpAntiProton->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(antiProton[aProt])); qa.qaP4("antiProton_", antiProton[aProt]->P4(), ntpAntiProton); qa.qaCand("antiProton_", antiProton[aProt], ntpAntiProton); jenny::numberOfHitsInSubdetector("antiProton_", antiProton[aProt], ntpAntiProton); // jenny::tagNHits("antiProton_", antiProton[aProt], ntpAntiProton); int tag = jenny::tagHits(antiProton[aProt]); RhoCandidate * mother_aProt = antiProton[aProt]->GetMcTruth()->TheMother(); int moth_aProt = (0x0==mother_aProt)? 88888 : mother_aProt->PdgCode(); ntpAntiProton->Column("Mother", (Float_t) moth_aProt); ntpAntiProton->Column("antiProton_CosTheta", (Float_t) antiProton[aProt]->GetMomentum().CosTheta()); qa.qaP4("antiProton_MC_", antiProton[aProt]->GetMcTruth()->P4(), ntpAntiProton); qa.qaCand("antiProton_", antiProton[aProt]->GetMcTruth(), ntpAntiProton); ntpAntiProton->Column("antiProton_MC_CosTheta", (Float_t) antiProton[aProt]->GetMcTruth()->GetMomentum().CosTheta()); ntpAntiProton->DumpData(); if(tag==1) SelectedAntiProton.Append(antiProton[aProt]); } //***Lambda0 -> PiMinus + Proton lambda0.Combine(SelectedPiMinus,SelectedProton); lambda0.Select(lambdaMassSelector); lambda0.SetType(kl0); std::map<int,int> bestVtxFitLambda0, bestMassFitLambda0; bestVtxFitLambda0 = jenny::VertexQaIndex(&lambda0); bestMassFitLambda0 = jenny::MassFitQaIndex(&lambda0, m0_lambda0); for (int j=0; j<lambda0.GetLength(); ++j){ //general info about event ntpLambda0->Column("ev", (Float_t) evt); ntpLambda0->Column("cand", (Float_t) j); ntpLambda0->Column("ncand", (Float_t) lambda0.GetLength()); ntpLambda0->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(lambda0[j])); ntpLambda0->Column("Lambda0_Pdg", (Float_t) lambda0[j]->PdgCode()); RhoCandidate * mother = lambda0[j]->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpLambda0->Column("Mother", (Float_t) moth); qa.qaP4("Lambda0_", lambda0[j]->P4(), ntpLambda0); qa.qaComp("Lambda0_", lambda0[j], ntpLambda0); // do vertex fit PndKinVtxFitter vertexfitterLambda0 (lambda0[j]); vertexfitterLambda0.Fit(); RhoCandidate * lambda0Fit = lambda0[j]->GetFit(); // store info of vertex fit qa.qaFitter("VtxFit_", &vertexfitterLambda0, ntpLambda0); ntpLambda0->Column("VtxFit_HowGood", (Int_t) bestVtxFitLambda0[j]); qa.qaVtx("VtxFit_", lambda0Fit, ntpLambda0); // differenz to MCTruth qa.qaMcDiff("fvtxMcDiff_", lambda0Fit, ntpLambda0); // do mass fit PndKinFitter massFitterLambda0(lambda0Fit); massFitterLambda0.AddMassConstraint(m0_lambda0); massFitterLambda0.Fit(); RhoCandidate * lambda0Fit_mass = lambda0Fit->GetFit(); qa.qaFitter("MassFit_", &massFitterLambda0, ntpLambda0); ntpLambda0->Column("MassFit_HowGood", (Int_t) bestMassFitLambda0[j]); RhoCandidate * truth = lambda0[j]->GetMcTruth(); RhoCandidate * truthDaughter = lambda0[j]->Daughter(0)->GetMcTruth(); TLorentzVector l; TVector3 dl; if(0x0 != truth){ l = truth->P4(); qa.qaVtx("McTruth_", truth, ntpLambda0); dl = truth->Daughter(0)->Pos(); } else{ qa.qaVtx("McTruth_", dummyCand, ntpLambda0); } jenny::qaP3("McTruth_", dl, ntpLambda0); qa.qaP4("McTruth_", l, ntpLambda0); //*** use for Xi only bestChi2Cand if (bestVtxFitLambda0[j]==1 && bestMassFitLambda0[j]>0){ Lambda0Fit.Append(lambda0Fit); jenny::CombinedList(lambda0Fit, &CombinedPiMinus, -211); } //***information of boosted particle lambda0Fit->Boost(-beamBoost); qa.qaComp("boost_", lambda0Fit, ntpLambda0); ntpLambda0->DumpData(); } jenny::GetNotCombinedList(CombinedPiMinus, &NotCombinedPiMinus); // Lambda0Fit.Cleanup(); CombinedPiMinus.Cleanup(); SelectedPiMinus.Cleanup(); SelectedProton.Cleanup(); // NotCombinedPiMinus.Cleanup(); bestVtxFitLambda0.clear(); bestMassFitLambda0.clear(); //***AntiLambda0 -> PiPlus + AntiProton antiLambda0.Combine(SelectedPiPlus,SelectedAntiProton); antiLambda0.Select(lambdaMassSelector); antiLambda0.SetType(kal0); std::map<int,int> bestVtxFitAntiLambda0, bestMassFitAntiLambda0; bestVtxFitAntiLambda0 = jenny::VertexQaIndex(&antiLambda0); bestMassFitAntiLambda0 = jenny::MassFitQaIndex(&antiLambda0, m0_lambda0); for (int j=0; j<antiLambda0.GetLength(); ++j){ //general info about event ntpAntiLambda0->Column("ev", (Float_t) evt); ntpAntiLambda0->Column("cand", (Float_t) j); ntpAntiLambda0->Column("ncand", (Float_t) antiLambda0.GetLength()); ntpAntiLambda0->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(antiLambda0[j])); ntpAntiLambda0->Column("AntiLambda0_Pdg", (Float_t) antiLambda0[j]->PdgCode()); RhoCandidate * mother = antiLambda0[j]->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpAntiLambda0->Column("Mother", (Float_t) moth); qa.qaP4("AntiLambda0_", antiLambda0[j]->P4(), ntpAntiLambda0); qa.qaComp("AntiLambda0_", antiLambda0[j], ntpAntiLambda0); // do vertex fit PndKinVtxFitter vertexfitterAntiLambda0 (antiLambda0[j]); vertexfitterAntiLambda0.Fit(); RhoCandidate * antiLambda0Fit = antiLambda0[j]->GetFit(); // store info of vertex fit qa.qaFitter("VtxFit_", &vertexfitterAntiLambda0, ntpAntiLambda0); qa.qaVtx("VtxFit_", antiLambda0Fit, ntpAntiLambda0); ntpAntiLambda0->Column("VtxFit_HowGood", (Int_t) bestVtxFitAntiLambda0[j]); // do mass fit PndKinFitter massFitterAntiLambda0(antiLambda0Fit); massFitterAntiLambda0.AddMassConstraint(m0_lambda0); massFitterAntiLambda0.Fit(); RhoCandidate * antiLambda0Fit_mass = antiLambda0Fit->GetFit(); qa.qaFitter("MassFit_", &massFitterAntiLambda0, ntpAntiLambda0); ntpAntiLambda0->Column("MassFit_HowGood", (Int_t) bestMassFitAntiLambda0[j]); RhoCandidate * truth = antiLambda0[j]->GetMcTruth(); TLorentzVector l; if(0x0 != truth){ l = truth->P4(); qa.qaVtx("MCTruth_", truth, ntpAntiLambda0); } else{ qa.qaVtx("McTruth_", dummyCand, ntpAntiLambda0); } qa.qaP4("MCTruth_", l, ntpAntiLambda0); //***information of boosted particle antiLambda0Fit->Boost(-beamBoost); qa.qaComp("boost_", antiLambda0Fit, ntpAntiLambda0); if(bestVtxFitAntiLambda0[j]==1 && bestMassFitAntiLambda0[j]>0){ AntiLambda0Fit.Append(antiLambda0Fit); jenny::CombinedList(antiLambda0Fit, &CombinedPiPlus, 211); } ntpAntiLambda0->DumpData(); } jenny::GetNotCombinedList(CombinedPiPlus, &NotCombinedPiPlus); CombinedPiPlus.Cleanup(); SelectedPiPlus.Cleanup(); SelectedAntiProton.Cleanup(); bestVtxFitAntiLambda0.clear(); bestMassFitAntiLambda0.clear(); //*** Xi- -> Lambda0 + Pi- ximinus.Combine(Lambda0Fit, NotCombinedPiMinus); ximinus.Select(xiMassSelector); ximinus.SetType(kXim); std::map<int,int> BestVtxFitXiMinus, BestMassFitXiMinus; BestVtxFitXiMinus = jenny::VertexQaIndex(&ximinus); BestMassFitXiMinus = jenny::MassFitQaIndex(&ximinus, m0_Xi); for (int j=0; j<ximinus.GetLength(); ++j){ //general info about event ntpXiMinus->Column("ev", (Float_t) evt); ntpXiMinus->Column("cand", (Float_t) j); ntpXiMinus->Column("ncand", (Float_t) ximinus.GetLength()); ntpXiMinus->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(ximinus[j])); ntpXiMinus->Column("XiMinus_Pdg", (Float_t) ximinus[j]->PdgCode()); RhoCandidate * mother = ximinus[j]->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpXiMinus->Column("Mother", (Float_t) moth); qa.qaP4("XiMinus_", ximinus[j]->P4(), ntpXiMinus); qa.qaComp("XiMinus_", ximinus[j], ntpXiMinus); qa.qaPoca("XiMinus_", ximinus[j], ntpXiMinus); // do vertex-fit PndKinVtxFitter vertexfitterXiMinus (ximinus[j]); vertexfitterXiMinus.Fit(); RhoCandidate * ximinusFit = ximinus[j]->GetFit(); // store info of vertex-fit qa.qaFitter("VtxFit_", &vertexfitterXiMinus, ntpXiMinus); ntpXiMinus->Column("VtxFit_HowGood", (Int_t) BestVtxFitXiMinus[j]); qa.qaVtx("VtxFit_", ximinusFit, ntpXiMinus); // qa.Cand("VtxFit_", ximinusFit, ntpXiMinus); // difference to MCTruth qa.qaMcDiff("VtxFit_", ximinusFit, ntpXiMinus); // do mass fit PndKinFitter massFitterXiMinus(ximinusFit); massFitterXiMinus.AddMassConstraint(m0_lambda0); massFitterXiMinus.Fit(); RhoCandidate * ximinusFit_mass = ximinusFit->GetFit(); qa.qaFitter("MassFit_", &massFitterXiMinus, ntpXiMinus); ntpXiMinus->Column("MassFit_HowGood", (Int_t) BestMassFitXiMinus[j]); qa.qaMcDiff("MassFit_", ximinusFit_mass, ntpXiMinus); RhoCandidate * truth = ximinus[j]->GetMcTruth(); TLorentzVector l; if(0x0 != truth){ l = truth->P4(); qa.qaVtx("MCTruth_", truth, ntpXiMinus); } else{ qa.qaVtx("MCTruth_", dummyCand, ntpXiMinus); } qa.qaP4("MCTruth_", l, ntpXiMinus); if (BestVtxFitXiMinus[j]==1 && BestMassFitXiMinus[j]>0){ XiMinusFit.Append(ximinusFit); } //***information of boosted particle ximinusFit->Boost(-beamBoost); qa.qaComp("boost_", ximinusFit, ntpXiMinus); ntpXiMinus->DumpData(); } Lambda0Fit.Cleanup(); NotCombinedPiMinus.Cleanup(); BestVtxFitXiMinus.clear(); BestMassFitXiMinus.clear(); //*** Xi+ -> AntiLambda0 + Pi+ xiplus.Combine(AntiLambda0Fit,piplus); xiplus.Select(xiMassSelector); xiplus.SetType(kaXip); std::map<int,int> BestVtxFitXiPlus, BestMassFitXiPlus; BestVtxFitXiPlus = jenny::VertexQaIndex(&xiplus); BestMassFitXiPlus = jenny::MassFitQaIndex(&xiplus, m0_Xi); for (int j=0; j<xiplus.GetLength(); ++j){ //general info about event ntpXiPlus->Column("ev", (Float_t) evt); ntpXiPlus->Column("cand", (Float_t) j); ntpXiPlus->Column("ncand", (Float_t) xiplus.GetLength()); ntpXiPlus->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(xiplus[j])); RhoCandidate * mother = xiplus[j]->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpXiPlus->Column("Mother", (Float_t) moth); qa.qaP4("Xiplus_", xiplus[j]->P4(), ntpXiPlus); qa.qaComp("Xiplus_", xiplus[j], ntpXiPlus); // int tag = 0; // int dtag[2] = {0,0}; // // for (int dau=0; dau<xiplus[j]->NDaughters(); dau++){ // // RhoCandidate * daughter = xiplus[j]->Daughter(dau); // if(daughter->IsComposite()){ // int dtag1 = jenny::tagHits(daughter->Daughter(0)); // int dtag2 = jenny::tagHits(daughter->Daughter(1)); // if(dtag1==1 && dtag2==1) dtag[dau]=1; // } // else{ // dtag[dau] = jenny::tagHits(daughter); // } // } // // if(dtag[0]==1 && dtag[1]==1) tag=1; // // ntpXiPlus->Column("XiPlus_HitTag", (Int_t) tag); //******** do vertex-fit PndKinVtxFitter vertexfitterxiplus (xiplus[j]); vertexfitterxiplus.Fit(); RhoCandidate * xiplusFit = xiplus[j]->GetFit(); // store info of vertex-fit qa.qaFitter("VtxFit_", &vertexfitterxiplus, ntpXiPlus); ntpXiPlus->Column("VtxFit_HowGood", (Int_t) BestVtxFitXiPlus[j]); qa.qaVtx("VtxFit_", xiplusFit, ntpXiPlus); // difference to MCTruth qa.qaMcDiff("VtxFit_", xiplusFit, ntpXiPlus); //****** do mass fit PndKinFitter massFitterxiplus(xiplusFit); massFitterxiplus.AddMassConstraint(m0_lambda0); massFitterxiplus.Fit(); RhoCandidate * xiplusFit_mass = xiplusFit->GetFit(); qa.qaFitter("MassFit_", &massFitterxiplus, ntpXiPlus); ntpXiPlus->Column("MassFit_HowGood", (float) BestMassFitXiPlus[j]); qa.qaVtx("MassFit_", xiplusFit_mass, ntpXiPlus); qa.qaMcDiff("MassFit_", xiplusFit_mass, ntpXiPlus); RhoCandidate * truth = xiplus[j]->GetMcTruth(); TLorentzVector l; if(0x0 != truth){ l = truth->P4(); qa.qaVtx("MCTruth_", truth, ntpXiPlus); } else{ qa.qaVtx("MCTruth_", dummyCand, ntpXiPlus); } qa.qaP4("MCTruth_", l, ntpXiPlus); if(BestVtxFitXiPlus[j]==1 && BestMassFitXiPlus[j]>0){ XiPlusFit.Append(xiplusFit); } //***information of boosted particle xiplusFit->Boost(-beamBoost); qa.qaComp("boost_", xiplusFit, ntpXiPlus); ntpXiPlus->DumpData(); } AntiLambda0Fit.Cleanup(); // BestCandAntiLambda0.Cleanup(); BestVtxFitXiPlus.clear(); BestMassFitXiPlus.clear(); //******* Xi+ Xi- System***************************** xiSys.Combine(XiPlusFit, XiMinusFit); xiSys.SetType(88888); for (int syscand=0; syscand<xiSys.GetLength(); ++syscand){ ntpXiSys->Column("ev", (Float_t) evt); ntpXiSys->Column("cand", (Float_t) j); ntpXiSys->Column("ncand", (Float_t) ximinus.GetLength()); ntpXiSys->Column("McTruthMatch", (bool) theAnalysis->McTruthMatch(xiSys[syscand])); RhoCandidate * mother = xiSys[syscand]->TheMother(); int moth = (mother==0x0) ? 88888 : mother->PdgCode(); ntpXiSys->Column("Mother", (Float_t) moth); qa.qaP4("XiSys_", xiSys[syscand]->P4(), ntpXiSys); qa.qaComp("XiSys_", xiSys[syscand], ntpXiSys); qa.qaPoca("XiSys_", xiSys[syscand], ntpXiSys); RhoCandidate * truth = xiSys[syscand]->GetMcTruth(); TLorentzVector l; if (truth != 0x0){ // qa.qaComp("McTruth_", truth, ntpXiSys); qa.qaVtx("McTruth_", truth, ntpXiSys); l = truth->P4(); } else{ // qa.qaComp("McTruth_", dummyCand, ntpXiSys); qa.qaVtx("McTruth_", dummyCand, ntpXiSys); } qa.qaP4("McTruth_", l, ntpXiSys); //4C-Fitter PndKinFitter fitter4c (xiSys[syscand]); fitter4c.Add4MomConstraint(ini); fitter4c.Fit(); RhoCandidate * xiSysFit4c = xiSys[syscand]->GetFit(); qa.qaFitter("4CFit_", &fitter4c, ntpXiSys); qa.qaComp("4cFit_", xiSysFit4c, ntpXiSys); qa.qaVtx("4CFit_", xiSysFit4c, ntpXiSys); ntpXiSys->DumpData(); } XiMinusFit.Cleanup(); XiPlusFit.Cleanup(); } //Write output out->cd(); ntpMC -> GetInternalTree()->Write(); ntpPiMinus ->GetInternalTree()->Write(); ntpPiPlus->GetInternalTree()->Write(); ntpProton->GetInternalTree()->Write(); ntpAntiProton->GetInternalTree()->Write(); ntpLambda0->GetInternalTree()->Write(); ntpAntiLambda0->GetInternalTree()->Write(); ntpXiMinus->GetInternalTree()->Write(); ntpXiPlus->GetInternalTree()->Write(); ntpXiSys->GetInternalTree()->Write(); out->Save(); timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); cout<<endl<<endl; cout<<"Macro finisched successfully."<<endl; cout<<"Realtime: "<<rtime<<" s, CPU time: "<<ctime<<" s"<<endl; cout<<endl; exit(0); }
void StrandBlockSolver::lhsTime(const int& step, const int& pseudoStep) { // compute inviscid and viscous spectral radius specRadi(); specRadv(); // add physical time derivative to LHS if (step > 0){ int jj=1,m; double tj[nq*nq],a=1.5/dtUnsteady,b; for (int n=0; n<nFaces-nGfaces; n++) for (int j=1; j<fClip(n)+1; j++){ b = a*v(j,n); sys->lhsConsVarJacobian(jj,&q(0,j,n),&qa(0,j,n),&tj[0]); for (int k=0; k<nq; k++){ m = k*nq; for (int l=0; l<nq; l++) dd(l,k,j,n) = tj[m+l]*b; }}} // compute the pseudo time step using sum of face areas around a cell // in place of volume, and add to LHS int j=nPstr+2,k=nFaces+nBedges,c1,c2,m; double Ax,Ay,A; Array2D<double> ll(j,k); for (int n=0; n<nFaces+nBedges; n++) for (int j=0; j<nPstr+2; j++) ll(j,n) = 0.; for (int n=0; n<nEdges; n++){ c1 = edge(0,n); c2 = edge(1,n); m = fClip(c1); if (fClip(c2) > m) m = fClip(c2); for (int j=1; j<m+1; j++){ Ax = facs(0,j,n); Ay = facs(1,j,n); A = Ax*Ax+Ay*Ay; ll(j,c1)+= A; ll(j,c2)+= A; }} int jp; for (int n=0; n<nFaces-nGfaces; n++){ for (int j=0; j<fClip(n)+1; j++){ jp = j+1; Ax = facu(0,j,n); Ay = facu(1,j,n); A = Ax*Ax+Ay*Ay; ll(j ,n)+= A; ll(jp,n)+= A; }} // CFL and VNN ramping double cflT,vnnT; if (pseudoStep > nRamp){ cflT = cfl; vnnT = vnn; } else{ cflT = cfl0+(cfl-cfl0)/((double)nRamp)*((double)pseudoStep); vnnT = vnn0+(vnn-vnn0)/((double)nRamp)*((double)pseudoStep); } for (int n=0; n<nFaces+nBedges; n++) for (int j=0; j<nPstr+2; j++) dt(j,n) = 0; if (inviscid == 1){ for (int n=0; n<nFaces-nGfaces; n++) for (int j=0; j<fClip(n)+1; j++) dt(j,n) = radi(j,n)/cflT; } if (viscous == 1){ double a; for (int n=0; n<nFaces-nGfaces; n++) for (int j=0; j<fClip(n)+1; j++){ a = radv(j,n)/vnnT; if (a > dt(j,n)) dt(j,n) = a; } } for (int n=0; n<nFaces-nGfaces; n++) //for (int j=0; j<fClip(n)+1; j++) dt(j,n) = ll(j,n)/dt(j,n); for (int j=0; j<fClip(n)+1; j++) dt(j,n) = v(j,n)/dt(j,n); int jj=1; double pj[nq*nq],a; for (int n=0; n<nFaces-nGfaces; n++) for (int j=0; j<fClip(n)+1; j++){ sys->lhsPreconJacobian(jj,&q(0,j,n),&qa(0,j,n),&pj[0]); a = v(j,n)/dt(j,n); for (int k=0; k<nq; k++){ m = k*nq; for (int l=0; l<nq; l++) dd(l,k,j,n) += pj[m+l]*a; }} ll.deallocate(); }
void Strand2dFCBlockSolver::rhsSource(const int& j) { // gradients of qa in n-direction and s-direction int j1,nj,nm; double dnr=1./deltaN; Array2D<double> qan(nSurfNode,nqa); Array3D<double> qas(nSurfElem,meshOrder+1,nqa); Array3D<double> ss(nSurfElem,meshOrder+1,nq); qan.set(0.); for (int n=0; n<nSurfNode; n++){ j1 = icn2[j][0]; nj = icn2[j][1]; for (int m=0; m<nj; m++){ for (int k=0; k<nqa; k++) qan(n,k) += dnr*icn1[j][m]*qa(n,j1,k); j1++; }} qas.set(0.); for (int n=0; n<nSurfElem; n++) for (int i=0; i<meshOrder+1; i++) // ith point in the element for (int m=0; m<meshOrder+1; m++){ // mth Lagrange poly. in mapping nm = surfElem(n,m); for (int k=0; k<nqa; k++) qas(n,i,k) += ls(i,m)*qa(nm,j,k); } // source computation int ni; double jac1,xs1,ys1,xn1,yn1,qax[nqa],qay[nqa],f[nq]; for (int n=0; n<nSurfElem; n++) for (int i=0; i<meshOrder+1; i++){ ni = surfElem(n,i); jac1 = 1./jac(n,i,j); xs1 = xs(n,i,j)*jac1; ys1 = ys(n,i,j)*jac1; xn1 = xn(ni,j)*jac1; yn1 = yn(ni,j)*jac1; for (int k=0; k<nqa; k++){ qax[k] = yn1*qas(n,i,k)-ys1*qan(ni,k); qay[k] =-xn1*qas(n,i,k)+xs1*qan(ni,k); } sys->rhsSource(1,&q(ni,j,0),&qa(ni,j,0),&qax[0],&qay[0],&f[0]); for (int k=0; k<nq; k++) ss(n,i,k) =-f[k]/jac1; } // source treatment int ne; double ns; for (int n=0; n<nSurfNode; n++) for (int i=psp2S(n); i<psp2S(n+1); i++){ ne = psp1S(i,0); ni = psp1S(i,1); ns = wsp1S(i); for (int k=0; k<nq; k++) r(n,j,k) += ns*ss(ne,ni,k); } // clean up qan.deallocate(); qas.deallocate(); ss.deallocate(); }
void MainWindow::openArchive() { QString buffer; QuestionItem * q_item; QStringList qa_flaglist; bool qa_flaglist_found; QStringList qa_anslist; bool qa_anslist_found; QStringList qa_correctanslist; bool qa_correctanslist_found; QStringList qa_diflist; bool qa_diflist_found; QStringList qa_selectiontypelist; bool qa_selectiontypelist_found; ArchivedSession * archived_session; bool rearchive; QSettings archive(QSettings::IniFormat, QSettings::UserScope, "Michal Tomlein", "iTest"); QStringList dbs = archive.value("databases").toStringList(); if (!dbs.contains(current_db_name)) { return; } QStringList sns = archive.value(QString("%1/sessions").arg(current_db_name)).toStringList(); for (int i = 0; i < sns.count(); ++i) { buffer = archive.value(QString("%1/%2").arg(current_db_name).arg(sns.at(i))).toString(); if (buffer.isEmpty()) { continue; } archived_session = new ArchivedSession(this, buffer); current_db_archivedsessions.insert(archived_session->dateTime(), archived_session); QListWidgetItem * item = new QListWidgetItem(QString("%1 - %2").arg(archived_session->dateTimeToString()).arg(archived_session->name())); SVLASListWidget->insertItem(0, item); item->setData(Qt::UserRole, archived_session->dateTime()); rearchive = false; buffer = archive.value(QString("%1/%2/PassMark").arg(current_db_name).arg(sns.at(i))).toString(); if (!buffer.isEmpty()) { archived_session->loadPassMark(buffer); } else { rearchive = true; } buffer = archive.value(QString("%1/%2/StudentsPassed").arg(current_db_name).arg(sns.at(i))).toString(); if (buffer.length() == archived_session->numStudents()) { for (int i = 0; i < archived_session->numStudents(); ++i) { archived_session->student(i)->setPassed(buffer.at(i) == '+'); } } else { for (int i = 0; i < archived_session->numStudents(); ++i) { archived_session->student(i)->setPassed(archived_session->passMark().check(archived_session->student(i)->results(), ¤t_db_questions, archived_session->scoringSystem())); } rearchive = true; } int numres = 0; for (int s = 0; s < archived_session->numStudents(); ++s) { numres += archived_session->student(s)->results()->count(); } qa_flaglist = archive.value(QString("%1/%2/QAFlags").arg(current_db_name).arg(sns.at(i))).toString().split(";"); qa_flaglist_found = qa_flaglist.count() == numres; qa_anslist = archive.value(QString("%1/%2/QAAnswers").arg(current_db_name).arg(sns.at(i))).toString().split(";"); qa_anslist_found = qa_anslist.count() == numres; qa_correctanslist = archive.value(QString("%1/%2/QACorrectAnswers").arg(current_db_name).arg(sns.at(i))).toString().split(";"); qa_correctanslist_found = qa_correctanslist.count() == numres; qa_diflist = archive.value(QString("%1/%2/QADifs").arg(current_db_name).arg(sns.at(i))).toString().split(";"); qa_diflist_found = qa_diflist.count() == numres; qa_selectiontypelist = archive.value(QString("%1/%2/QASeletionTypes").arg(current_db_name).arg(sns.at(i))).toString().split(";"); qa_selectiontypelist_found = qa_selectiontypelist.count() == numres; if (!qa_flaglist_found || !qa_anslist_found || !qa_correctanslist_found || !qa_diflist_found || !qa_selectiontypelist_found) { rearchive = true; } int x = 0; for (int s = 0; s < archived_session->numStudents(); ++s) { QMapIterator<QString, QuestionAnswer> qa(*(archived_session->student(s)->results())); QuestionAnswer qans; while (qa.hasNext()) { qa.next(); q_item = NULL; qans = qa.value(); if (qa_flaglist_found) { qans.setFlag(qa_flaglist.at(x).toInt()); } if (qa_anslist_found) { qans.setAnswered((Question::Answer)qa_anslist.at(x).toInt()); } if (qa_correctanslist_found) { qans.setCorrectAnswer((Question::Answer)qa_correctanslist.at(x).toInt()); } if (qa_diflist_found) { qans.setDifficulty(qa_diflist.at(x).toInt()); } if (qa_selectiontypelist_found) { qans.setSelectionType((Question::SelectionType)qa_selectiontypelist.at(x).toInt()); } if (!qa_flaglist_found || !qa_correctanslist_found || !qa_diflist_found || !qa_selectiontypelist_found) { QMapIterator<QListWidgetItem *, QuestionItem *> q(current_db_questions); while (q.hasNext()) { q.next(); if (q.value()->name() == qa.key()) { q_item = q.value(); break; } } if (q_item == NULL) { if (!qa_flaglist_found) { qans.setFlag(-1); } } else { if (!qa_flaglist_found) { qans.setFlag(q_item->flag()); } if (!qa_correctanslist_found) { qans.setCorrectAnswer(q_item->correctAnswer()); } if (!qa_diflist_found) { qans.setDifficulty(q_item->difficulty()); } if (!qa_selectiontypelist_found) { qans.setSelectionType(q_item->selectionType()); } } } archived_session->student(s)->results()->insert(qa.key(), qans); x++; } } buffer = archive.value(QString("%1/%2/ScoringSystem").arg(current_db_name).arg(sns.at(i))).toString(); if (!buffer.isEmpty()) { ScoringSystem sys(buffer); archived_session->setScoringSystem(sys); } else { archived_session->setScoringSystem(ScoringSystem()); rearchive = true; } if (rearchive) { archived_session->archive(); } } hideArchive(); }
void Tri2dFCBlockSolver::output(const int& nBlocks, const int& step) { // create output directory for this unsteady step stringstream a; a.str(""); a.clear(); a << "mkdir -p output." << step; system(a.str().c_str()); a.str(""); a.clear(); // output solution file if (nOutputVars > 0){ // determine error at the plotting points Array2D<double> qe(nNode,nq),er(nNode,nq); sys->initFlow(nNode, &x(0,0), &qe(0,0)); for (int n=0; n<nNode; n++) for (int k=0; k<nq; k++) er(n,k) =(q(n,k)-qe(n,k))/rmsNorm(k); // output the step header information if on block 0 if (ID == 0){ ofstream ffile; a << "triSolution" << step << ".pvtu"; ffile.open (a.str().c_str()); a.str(""); a.clear(); ffile.setf(ios::scientific); ffile.precision(14); ffile << "<?xml version=\"1.0\"?>" << endl << "<VTKFile type=\"PUnstructuredGrid\" " << "version=\"0.1\" byte_order=\"LittleEndian\">" << endl << "<PUnstructuredGrid GhostLevel=\"0\">" << endl << "<PPointData "; if (nOutputScalars > 0){ ffile << "Scalars=\""; int k=0; for (int n=0; n<nOutputVars; n++) if (outputVarLength(n) == 1){ if (k != 0) ffile << " "; k++; ffile << outputVars(n); } ffile << "\""; if (nOutputVectors > 0) ffile << " "; } if (nOutputVectors > 0){ ffile << "Vectors=\""; int k=0; for (int n=0; n<nOutputVars; n++) if (outputVarLength(n) == 3){ if (k != 0) ffile << " "; k++; ffile << outputVars(n); } ffile << "\""; } ffile << ">" << endl; for (int n=0; n<nOutputVars; n++){ ffile << "<PDataArray type=\"Float32\" Name=\"" << outputVars(n) << "\""; if (outputVarLength(n) == 3) ffile << " NumberOfComponents=\"3\""; ffile << "/>" << endl; } ffile << "</PPointData>" << endl << "<PPoints>" << endl << "<PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>" << endl << "</PPoints>" << endl; for (int n=0; n<nBlocks; n++){ a << "<Piece Source=\"output." << step << "/triSolutionBlock" << n << ".vtu\"/>"; ffile << a.str() << endl; a.str(""); a.clear(); } ffile << "</PUnstructuredGrid>" << endl << "</VTKFile>" << endl; ffile.close(); } // write data to file for this block ofstream ffile; a << "triSolutionBlock" << ID << ".vtu"; ffile.open (a.str().c_str()); ffile.setf(ios::scientific); ffile.precision(14); a.str(""); a.clear(); ffile << "<?xml version=\"1.0\"?>" << endl << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1" <<"\" byte_order=\"LittleEndian\">" << endl << "<UnstructuredGrid>" << endl << "<Piece NumberOfPoints=\"" << nNode <<"\" NumberOfCells=\"" << nTri << "\">" << endl << "<PointData "; if (nOutputScalars > 0){ ffile << "Scalars=\""; int k=0; for (int n=0; n<nOutputVars; n++) if (outputVarLength(n) == 1){ if (k != 0) ffile << " "; k++; ffile << outputVars(n); } ffile << "\""; if (nOutputVectors > 0) ffile << " "; } if (nOutputVectors > 0){ ffile << "Vectors=\""; int k=0; for (int n=0; n<nOutputVars; n++) if (outputVarLength(n) == 3){ if (k != 0) ffile << " "; k++; ffile << outputVars(n); } ffile << "\""; } ffile << ">" << endl; for (int n=0; n<nOutputVars; n++){ if (outputVarLength(n) == 1){ ffile << "<DataArray type=\"Float32\" Name=\"" << outputVars(n) << "\" format=\"ascii\">" << endl; } else{ ffile << "<DataArray type=\"Float32\" Name=\"" << outputVars(n) << "\" NumberOfComponents=\"3\" format=\"ascii\">" << endl; } sys->outputSolution(nNode, ffile, outputVars(n), &q(0,0), &qa(0,0), &er(0,0), &r(0,0)); ffile << "</DataArray>" << endl; } ffile << "</PointData>" << endl << "<Points>" << endl << "<DataArray type=\"Float32\" NumberOfComponents" << "=\"3\" format=\"ascii\">" << endl; double xn,yn,eps=1.e-14; for (int n=0; n<nNode; n++){ xn = x(n,0); yn = x(n,1); if (fabs(x(n,0)) < eps) xn = 0.; if (fabs(x(n,1)) < eps) yn = 0.; ffile << xn << "\t" << yn << "\t" << 0. << endl; } ffile << "</DataArray>" << endl << "</Points>" << endl << "<Cells>" << endl << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << endl; for (int n=0; n<nTri; n++) ffile << tri(n,0) << "\t" << tri(n,1) << "\t" << tri(n,2) << endl; ffile << "</DataArray>" << endl <<"<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << endl; int k = 0; for (int n=0; n<nTri; n++){ k += 3; ffile << k << endl; } ffile << "</DataArray>" << endl << "<DataArray type=\"Int32\" Name=\"types\" format=\"ascii\">" << endl; for (int n=0; n<nTri; n++) ffile << 5 << endl; ffile << "</DataArray>" << endl << "</Cells>" << endl << "</Piece>" << endl << "</UnstructuredGrid>" << endl << "</VTKFile>" << endl; ffile.close(); a << "mv triSolutionBlock" << ID << ".vtu output." << step; system(a.str().c_str()); a.str(""); a.clear(); // output L2 norm of solution error if (iErrFile != 0){ ofstream efile; //a << "triErrorBlock" << ID << ".dat"; a << "error.dat"; efile.open(a.str().c_str(),ios::app); efile.setf(ios::scientific); efile.precision(14); a.str(""); a.clear(); double erms[nq]; for (int k=0; k<nq; k++) erms[k] = 0.; for (int n=0; n<nNode; n++) for (int k=0; k<nq; k++) erms[k] += pow(er(n,k),2); for (int k=0; k<nq; k++) erms[k] = sqrt(erms[k]/(double)nNode); efile << sqrt((double)nNode) << "\t"; for (int k=0; k<nq; k++) efile << erms[k] << "\t"; efile << endl; efile.close(); //a << "mv triErrorBlock" << ID << ".dat output." << step; //system(a.str().c_str()); //a.str(""); //a.clear(); cout.setf(ios::scientific); cout << "\nError statistics: " << endl; cout << sqrt((double)nNode) << "\t"; for (int k=0; k<nq; k++) cout << erms[k] << "\t"; cout << endl; } // deallocate work arrays qe.deallocate(); er.deallocate(); } // output surface data to file if (iSurfFile != 0){ ofstream sfile; a << "triSurfaceBlock" << ID << ".dat"; if (step == 0) sfile.open (a.str().c_str()); else sfile.open (a.str().c_str(),ios::app); sfile.setf(ios::scientific); sfile.precision(14); a.str(""); a.clear(); Array3D<double> qax; qax.allocate(nNode,2,nqa); gradient(nq,&q(0,0),&qx(0,0,0)); gradient(nqa,&qa(0,0),&qax(0,0,0)); int m=0; for (int n=nNode-nNodeBd; n<nNode; n++) sys->outputSurfaceSolution(1, sfile, &nodeBd(m++), &x(n,0), &x(n,1), &q(n,0), &qa(n,0), &qx(n,0,0), &qx(n,1,0), &qax(n,0,0), &qax(n,1,0)); qax.deallocate(); a << "mv triSurfaceBlock" << ID << ".dat output." << step; system(a.str().c_str()); a.str(""); a.clear(); ofstream ffile; //force file a << "forces.dat"; if (step == 0) ffile.open (a.str().c_str()); else ffile.open (a.str().c_str(),ios::app); ffile.setf(ios::scientific); ffile.precision(14); a.str(""); a.clear(); forcex = 0.; forcey = 0.; int jj,nn,tag; double dd,dx,dy, qQ[nq],qxQ[nq],qyQ[nq],qaQ[nqa],qaxQ[nqa],qayQ[nqa],force[ndim]; for (int n=0; n<nEdgeQ; n++){ nn = edgeQ(n,0); // element on which lies this edge jj = edgeQ(n,1); // edge number on the element tag = edgeQ(n,2); // boundary tag for the edge for (int i=0; i<nsq; i++){ //for each surface quadrature point // interpolate solution and gradients to the quadrature points for (int k=0; k<nq ; k++) qQ[k] = 0.; for (int k=0; k<nq ; k++) qxQ[k] = 0.; for (int k=0; k<nq ; k++) qyQ[k] = 0.; for (int k=0; k<nqa; k++) qaQ[k] = 0.; for (int k=0; k<nqa; k++) qaxQ[k] = 0.; for (int k=0; k<nqa; k++) qayQ[k] = 0.; for (int j=0; j<nne; j++){ dd = gxS(n,i,j,0); dx = gxS(n,i,j,1); dy = gxS(n,i,j,2); m = elem(nn,j); for (int k=0; k<nq ; k++){ qQ [k] += q (m,k)*dd; qxQ [k] += q (m,k)*dx; qyQ [k] += q (m,k)*dy; } for (int k=0; k<nqa; k++){ qaQ [k] += qa(m,k)*dd; qaxQ[k] += qa(m,k)*dx; qayQ[k] += qa(m,k)*dy; }} // compute surface force contribution sys->outputSurfaceForces(1, &tag, &nxQ(n,i,0), &qQ[0], &qxQ[0], &qyQ[0], &qaQ[0], &qaxQ[0], &qayQ[0], &force[0]); forcex += force[0]; forcey += force[1]; }} cout << "\nx-component force: " << forcex << endl; cout << "y-component force: " << forcey << endl; cout << "\n"; ffile << step << " " << double(step)*dtUnsteady << " " << forcex << " " << forcey << endl; ffile.close(); } }