Ejemplo n.º 1
0
float CCamera::GetProbWrtArea(const SceneSample& ss)
{
	const SceneSample cam = GetCameraAsSceneSample();
	const glm::vec3 d = ss.position - cam.position;
	
	const float temp = powf(glm::dot(cam.normal, d), 3.f)/glm::dot(ss.normal, -d) * GetRho();
	return 1.f/temp;
}
Ejemplo n.º 2
0
// Decribe for debugging use or output on some errors
void MPMBase::Describe(void)
{	cout << "# pt: pos=(" << pos.x << "," << pos.y << "," << pos.z << ") mass=" << mp << 
                " matl=" << matnum << " elem=" << inElem << endl;
    cout << "#     vel=(" << vel.x << "," << vel.y << "," << vel.z << ") " << UnitsController::Label(CUVELOCITY_UNITS) << endl;
    Matrix3 pF = GetDeformationGradientMatrix();
    cout << "#       F=" << pF << ", |F|=" << pF.determinant() << endl;
    double rho0=GetRho();
    double rho = rho0*UnitsController::Scaling(1.e-6)/theMaterials[MatID()]->GetCurrentRelativeVolume(this,0);
    cout << "#       P= " << pressure*rho << " " << UnitsController::Label(PRESSURE_UNITS) << endl;
    cout << "# sigmaii=(" << sp.xx*rho << "," << sp.yy*rho << "," << sp.zz << ") " << UnitsController::Label(PRESSURE_UNITS) << endl;
    cout << "#   tauij=(" << sp.xy*rho << "," << sp.xz*rho << "," << sp.yz << ") " << UnitsController::Label(PRESSURE_UNITS) << endl;
	cout << "#       T= " << pTemperature << " prev T=" << pPreviousTemperature << endl;
}
Ejemplo n.º 3
0
 constexpr SCALAR Norm(void) const {return GetRho();}
Ejemplo n.º 4
0
// get unscaled volume for use only in contact and imperfect interface calculations
// return result in mm^3
double MPMBase::GetUnscaledVolume(void)
{	return mp/GetRho();
}
Ejemplo n.º 5
0
void CalcForces(float box, float rcut, float a, float c, float m, float n){
  //Variables to calculate
  float r2 = 0, rcut2, Vcalc = 0, tmp_f, a_r = 0;
    
  // Clear forces from previous calculations
  // Use the same loop to calculate rho's for each and all particles
  for (int h=0; h<num_replicas; h++) {
    for (int i = 0; i < N; i++){
      for (int j = 0; j < 3; j++){
	force[h][i][j] = 0.0;
      }
      rho_all[h][i] = GetRho(i, box, a, m, h);
    }
  }

  for (int h=0; h<num_replicas; h++) {  
    potential_energy[h] = 0.0;

    for (int i = 0; i < N; i++){
      Vcalc = 0.0;

      for (int j = 0; j < N; j++){

	if (j != i){
	  float deltaX = (position[h][i][0] - position[h][j][0]);
	  float deltaY = (position[h][i][1] - position[h][j][1]);
	  float deltaZ = (position[h][i][2] - position[h][j][2]);
				
	  deltaX -= (box * round(deltaX/box));
	  deltaY -= (box * round(deltaY/box));
	  deltaZ -= (box * round(deltaZ/box));
		
	  r2 = ( ( deltaX*deltaX ) +  ( deltaY*deltaY ) + ( deltaZ*deltaZ) );
	  rcut2 = rcut * rcut;

	  if (r2 < rcut2){
	    // Do calculation
	    a_r = a / sqrt(r2);
	    Vcalc += pow(a_r, n);
	    
	    tmp_f = ( n*pow(a_r, n) - (c/2.0)*m*(pow(rho_all[h][i],-0.5) + pow(rho_all[h][j],-0.5))*pow(a_r, m) ) / r2;

	    force[h][i][0] += deltaX * tmp_f;
	    force[h][i][1] += deltaY * tmp_f;
	    force[h][i][2] += deltaZ * tmp_f;
	    // remove double-counting
	    //force[h][j][0] -= deltaX * tmp_f;
	    //force[h][j][1] -= deltaY * tmp_f;
	    //force[h][j][2] -= deltaZ * tmp_f;
	  }
	}
      }
      potential_energy[h] += 0.5*Vcalc - c * sqrt(rho_all[h][i]);
    }
  }

  /*
    // moved double-counting up
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 3; j++){
      force[i][j] /= 2.0;
    }
  }
  */
}
Ejemplo n.º 6
0
TTree *ToyTree(TString dirname="test/dato/fitres/Hgg_Et-toys/0.01-0.00", TString fname="outProfile-scaleStep2smearing_7-Et_25-trigger-noPF-EB.root", TString opt="", int nSmooth=10){
  TString outDir=dirname; outDir.ReplaceAll("fitres","img");
  outDir="tmp/";
  //std::map<TString, TH2F *> deltaNLL_map;

  //bool smooth=false;
  //if(opt.Contains("smooth")) smooth=true;
  

  /*------------------------------ Plotto */
  TCanvas c("ctoy","c");
  
  
  TTree *toys = new TTree("toys","");
  toys->SetDirectory(0);
  Double_t constTerm_tree, constTermTrue_tree;
  Double_t alpha_tree, alphaTrue_tree;
  char catName[100]; 
  Int_t catIndex;
  toys->Branch("constTerm", &constTerm_tree, "constTerm/D");
  toys->Branch("alpha", &alpha_tree, "alpha/D");
  toys->Branch("constTermTrue", &constTermTrue_tree, "constTermTrue/D");
  toys->Branch("alphaTrue", &alphaTrue_tree, "alphaTrue/D");

  toys->Branch("catName", catName, "catName/C");
  toys->Branch("catIndex", &catIndex, "catIndex/I");
  std::map<TString, Int_t> catIndexMap;

  ///1/
  for(int itoy =2; itoy <= 50; itoy++){
    TString filename=dirname+"/"; filename+=itoy; filename+="/"+fname;
    TString fout=dirname+"/"; fout+=itoy; fout+="/";    
    TFile f_in(filename, "read");
    if(f_in.IsZombie()){
      std::cerr << "File opening error: " << filename << std::endl;
      continue; //return NULL;
    }
    //std::cout << filename << std::endl;
    TList *KeyList = f_in.GetListOfKeys();
    //std::cout << KeyList->GetEntries() << std::endl;
    for(int i =0; i <  KeyList->GetEntries(); i++){
      c.Clear();
      TKey *key = (TKey *)KeyList->At(i);
      if(TString(key->GetClassName())!="RooDataSet") continue;
      RooDataSet *dataset = (RooDataSet *) key->ReadObj();
    
      TString constTermName = dataset->GetName();
      TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha");
      if(constTermName.Contains("scale")) continue;
      if(constTermName.Contains("alpha")) continue;
      if(constTermName.Contains("1.4442-gold")) continue;
      TTree *tree = dataset2tree(dataset);

      TGraph *rhoGraph = GetRho(tree, alphaName, constTermName);

      rhoGraph->SaveAs(fout+"rhoGraph-"+constTermName+".root");


      TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName);
      //TString binning="(241,-0.0005,0.2405,61,-0.00025,0.03025)"; //"(40,0.00025,0.02025,61,-0.0022975,0.1401475)";
      TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; 

      TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true, nSmooth, opt);
      //hist->SaveAs("myhist.root");
      
      Int_t iBinX, iBinY;
      hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001);
	
      //      if(iBinX!=0 && iBinY!=0 && iBinX < 41 && iBinY < 62){
      {
	TString catName_=constTermName; catName_.ReplaceAll("constTerm_",""); catName_.ReplaceAll("-","_");
	if(catIndexMap.count(catName_)==0) catIndexMap.insert(std::pair<TString,Int_t>(catName_,catIndexMap.size()));
	catIndex=catIndexMap[catName_];	
	constTerm_tree =  hist->GetYaxis()->GetBinCenter(iBinY);
	alpha_tree = hist->GetXaxis()->GetBinCenter(iBinX);
	sprintf(catName,"%s", catName_.Data());
	bestFit_.GetPoint(0, constTermTrue_tree,alphaTrue_tree);
// 	std::cout << constTerm_tree << " " << constTermTrue_tree 
// 		  << "\t" << alpha_tree << " " << alphaTrue_tree 
// 		  << std::endl;

	if(opt.Contains("scandiff")){
	  constTermTrue_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_"));
	} else       if(opt.Contains("scan")){
	  constTerm_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_"));
	}
	//std::cout << iBinX << "\t" << iBinY << "\t" << constTerm_tree - getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")) << std::endl;
	
	toys->Fill();
//       }else{
// 	hist->SaveAs("myhist.root");
// 	exit(0);
      }

      
      delete tree;
      delete hist;
    
    }
    f_in.Close();
  }
  //toys->SaveAs("tmp/toysTree.root");
  

  return toys;
}
Ejemplo n.º 7
0
// THE NEW FORCE AND ENERGY FUNCTIONS
void CalcForces(float box, float rcut, float a, float c, float m, float n){
	//Variables to calculate
        float r2 = 0, r6 = 0, r12  = 0, rcut2, Vcalc = 0, Vcorrection = 0, tmp_f, a_r = 0;
    
	        // Clear forces from previous calculations
	        // Use the same loop to calculate rho's for each and all particles
		for (int i = 0; i < N; i++){
			for (int j = 0; j < 3; j++){
				force[i][j] = 0.0;
			}
			rho_all[i] = GetRho(i, box, a, c, m);
		}
			
		for (int i = 0; i < N; i++){
		  for (int j = 0; j < N; j++){
			if (j != i){
		                float deltaX = (position[i][0] - position[j][0]);
				float deltaY = (position[i][1] - position[j][1]);
				float deltaZ = (position[i][2] - position[j][2]);
				
				deltaX -= (box * round(deltaX/box));
				deltaY -= (box * round(deltaY/box));
				deltaZ -= (box * round(deltaZ/box));
		
				r2 = ( ( deltaX*deltaX ) +  ( deltaY*deltaY ) + ( deltaZ*deltaZ) );
				rcut2 = rcut * rcut;

				if (r2 < rcut2){
				  // Do calculation
				  a_r = a / sqrt(r2);
				  Vcalc += pow(a_r, n);
				  
				  // Reduced units, no e needed?
                  //tmp_f = e * ( n*pow(a_r, n) - c*m*(pow(GetRho(i),-0.5) + pow(GetRho(j),-0.5))*pow(a_r, m)/2.0 ) / r2;
				  tmp_f = ( n*pow(a_r, n) - (c/2.0)*m*(pow(rho_all[i],-0.5) + pow(rho_all[j],-0.5))*pow(a_r, m) ) / r2;

				  force[i][0] += deltaX * tmp_f;
				  force[i][1] += deltaY * tmp_f;
				  force[i][2] += deltaZ * tmp_f;
				  force[j][0] -= deltaX * tmp_f;
				  force[j][1] -= deltaY * tmp_f;
				  force[j][2] -= deltaZ * tmp_f;
				}
			}
		  }
		  Vcalc = 0.5*Vcalc - c * sqrt(rho_all[i]) ;
		}

		for (int i = 0; i < N; i++){
		  for (int j = 0; j < 3; j++){
		    force[i][j] /= 2.0;
		  }
		}
		
		
		//~ float rcut3 = rcut * rcut * rcut;
		//~ float rcut9 = rcut3 * rcut3 * rcut3;
		//~ Vcorrection = 8 * 3.1415926535 * N * density * (1.0/(9 * rcut9) - 1.0/(3 * rcut3));
		//~ Vfinal = Vcalc + Vcorrection;
		Vfinal = Vcalc;
        
        
        
}
Ejemplo n.º 8
0
glm::vec4 CCamera::GetWeight(const SceneSample& ss)
{
	SceneSample cam;
	cam.position = GetPosition();
	cam.normal = GetViewDirection();
	
	glm::vec3 d_10 = ss.position - cam.position;
	glm::vec3 d_01 = cam.position - ss.position;

	float w = G(ss, cam) * powf(glm::dot(GetViewDirection(), d_10), 3.f)/glm::dot(ss.normal, d_01) * GetRho();

	return glm::vec4(w);
}