Esempio n. 1
0
// solve a 4x4 linear system
// i.e. Ay=x where A is a 4x4 matrix, x is a length 4 vector
//
// USED for: solving the correct light source direction after rotation.
//  i.e. A : current modelview matrix,
//       x : initial light source
//    return x: current light source
void Solve4(double * A, double* x)
{
	double B[16];
	int i,j;
	double y[4];
	double det, dem;

	det = det4( A[0], A[4], A[8], A[12],
				A[1], A[5], A[9], A[13],
				A[2], A[6], A[10], A[14],
				A[3], A[7], A[11], A[15]);

	for(i=0;i<4;i++) {
		for(j=0;j<16;j++)
			B[j] = A[j];
		
		for(j=0;j<4;j++) 
			B[i*4+j] = x[j];

		dem = det4( B[0], B[4], B[8], B[12],
				B[1], B[5], B[9], B[13],
				B[2], B[6], B[10], B[14],
				B[3], B[7], B[11], B[15]);
		y[i] = dem/det;
	}

	for(i=0;i<4;i++)
		x[i] = y[i];
}
Esempio n. 2
0
bool Delaunay::isInCircle(HHandle hh, VHandle vh1, VHandle vh2)
{
    // boundary edge
    // an edge is boundary edge, when one of its halfedges
    // is boundary. Next line is equl functioanally.
    // if(mesh.is_boundary(mesh.edge_handle(hh)))
    if (mesh.is_boundary(hh) ||
            mesh.is_boundary(mesh.opposite_halfedge_handle(hh)))
        return false;

    Point pt[4];
    pt[0] = mesh.point(mesh.from_vertex_handle(hh));
    pt[1] = mesh.point(mesh.to_vertex_handle(hh));
    pt[2] = mesh.point(vh1);
    pt[3] = mesh.point(vh2);

    // deal with infinite point
    if (isInfinite(pt[3]))
    {
        if (!(isInfinite(pt[0])|| isInfinite(pt[1])))
            return false;
    }

    for (int i = 0; i < 4; i++)
    {
		pt[i][2] = calcZ(pt[i][0], pt[i][1]);
    }

    return det4(pt)> 0;
}
Esempio n. 3
0
  Matrix4x4 inverse(const Matrix4x4& m)
  {
    Matrix4x4 inverse;
    ElVisFloat det = det4(m);

    inverse[0] = det3(mm(1, 1), mm(1, 2), mm(1, 3), mm(2, 1), mm(2, 2),
                      mm(2, 3), mm(3, 1), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[1] = -det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(2, 1), mm(2, 2),
                       mm(2, 3), mm(3, 1), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[2] = det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(1, 1), mm(1, 2),
                      mm(1, 3), mm(3, 1), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[3] = -det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(1, 1), mm(1, 2),
                       mm(1, 3), mm(2, 1), mm(2, 2), mm(2, 3)) /
                 det;

    inverse[4] = -det3(mm(1, 0), mm(1, 2), mm(1, 3), mm(2, 0), mm(2, 2),
                       mm(2, 3), mm(3, 0), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[5] = det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(2, 0), mm(2, 2),
                      mm(2, 3), mm(3, 0), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[6] = -det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(1, 0), mm(1, 2),
                       mm(1, 3), mm(3, 0), mm(3, 2), mm(3, 3)) /
                 det;
    inverse[7] = det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(1, 0), mm(1, 2),
                      mm(1, 3), mm(2, 0), mm(2, 2), mm(2, 3)) /
                 det;

    inverse[8] = det3(mm(1, 0), mm(1, 1), mm(1, 3), mm(2, 0), mm(2, 1),
                      mm(2, 3), mm(3, 0), mm(3, 1), mm(3, 3)) /
                 det;
    inverse[9] = -det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(2, 0), mm(2, 1),
                       mm(2, 3), mm(3, 0), mm(3, 1), mm(3, 3)) /
                 det;
    inverse[10] = det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(1, 0), mm(1, 1),
                       mm(1, 3), mm(3, 0), mm(3, 1), mm(3, 3)) /
                  det;
    inverse[11] = -det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(1, 0), mm(1, 1),
                        mm(1, 3), mm(2, 0), mm(2, 1), mm(2, 3)) /
                  det;

    inverse[12] = -det3(mm(1, 0), mm(1, 1), mm(1, 2), mm(2, 0), mm(2, 1),
                        mm(2, 2), mm(3, 0), mm(3, 1), mm(3, 2)) /
                  det;
    inverse[13] = det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(2, 0), mm(2, 1),
                       mm(2, 2), mm(3, 0), mm(3, 1), mm(3, 2)) /
                  det;
    inverse[14] = -det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(1, 0), mm(1, 1),
                        mm(1, 2), mm(3, 0), mm(3, 1), mm(3, 2)) /
                  det;
    inverse[15] = det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(1, 0), mm(1, 1),
                       mm(1, 2), mm(2, 0), mm(2, 1), mm(2, 2)) /
                  det;

    return inverse;
  }
Esempio n. 4
0
void inverse4( LWFMatrix4 m, LWFMatrix4 inv )
{
   float det;

   det = det4( m );
   if ( fabs( det ) < EPSILON_F ) return;

   adjoint4( m, inv );
   scalem4( inv, 1.0f / det );
}
Esempio n. 5
0
/* compute the curvatures using the derivatives 
 * 
 * curvatures are saved into an array: crv_result
 *     in order of: Gauss, Mean, Max, Min
 */
double krv(vector v00, vector Deriv[3][3], real* crv_result)
{
    double x,y,z,d;
    double xu,yu,zu,du, xv,yv,zv,dv;
    double xuu,yuu,zuu,duu, xvv,yvv,zvv,dvv;
    double xuv,yuv,zuv,duv;
    double kes, m1, m2, m3;
    double L, M, N;
    double E, G, F;
    double K, H, Max, Min; // results
    double disc;

	double special_curvature;

    x = v00[0]; y = v00[1];
    z = v00[2]; d = v00[3];

    xu = Deriv[1][0][0]; yu = Deriv[1][0][1];
    zu = Deriv[1][0][2]; du = Deriv[1][0][3];

    xuu = Deriv[2][0][0]; yuu = Deriv[2][0][1];
    zuu = Deriv[2][0][2]; duu = Deriv[2][0][3];

    xv = Deriv[0][1][0]; yv = Deriv[0][1][1];
    zv = Deriv[0][1][2]; dv = Deriv[0][1][3];

    xvv = Deriv[0][2][0]; yvv = Deriv[0][2][1];
    zvv = Deriv[0][2][2]; dvv = Deriv[0][2][3];

    xuv = Deriv[1][1][0]; yuv = Deriv[1][1][1];
    zuv = Deriv[1][1][2]; duv = Deriv[1][1][3];

    L=det4(xuu,yuu,zuu,duu,
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);
    N=det4(xvv,yvv,zvv,dvv, 
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);
    M=det4(xuv,yuv,zuv,duv,
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);

    E = (xu*d-x*du)*(xu*d-x*du) + (yu*d-y*du)*(yu*d-y*du) +
		(zu*d-z*du)*(zu*d-z*du);
    G = (xv*d-x*dv)*(xv*d-x*dv) + (yv*d-y*dv)*(yv*d-y*dv) +
		(zv*d-z*dv)*(zv*d-z*dv);
    F = (xu*d-x*du)*(xv*d-x*dv) + (yu*d-y*du)*(yv*d-y*dv) +
		(zu*d-z*du)*(zv*d-z*dv);

    m1=det3(y,z,d,yu,zu,du,yv,zv,dv);
    m2=det3(x,z,d,xu,zu,du,xv,zv,dv);
    m3=det3(x,y,d,xu,yu,du,xv,yv,dv);
    kes=m1*m1+m2*m2+m3*m3;

	if(0) {//fabs(kes) < tol*tol) {  // temp for Jorg & Kestas & me class A
		K = H = Max = Min = 0;
	}
	else {
		K = d*d*d*d*(L*N-M*M)/(kes*kes);  // Gaussian curvature
		H = d*(L*G-2*M*F+N*E) / sqrt(kes*kes*kes) /2;  // Mean curvature
		disc = H*H - K;
		if (disc < 0) {
			if (disc < -tol)
				printf("[krv] disc %f H %f \n",disc, H);
			Max = Min = H;
		}
		else {
			disc = sqrt(disc);
			Max = H + disc;
			Min = H - disc;
		}
	}

	if(0) {  // scale the result by log?
    	K = scalebylog(K);
    	H = scalebylog(H);
    	Max = scalebylog(Max);
    	Min = scalebylog(Min);
	}

    crv_result[0] = K; // Gaussian curvature
    crv_result[1] = H; // Mean curvature
    crv_result[2] = Max; // max curvature
    crv_result[3] = Min; // min curvature

	// a special 
	special_curvature =  ratio_a*K + ratio_b*H*H;
//	printf("special_curvature : %f\n", special_curvature);

    if( freshObject )
		min_crv_value[4] = max_crv_value[4] = special_curvature;
	else {
		if(special_curvature<min_crv_value[4]) min_crv_value[4] = special_curvature;
		if(special_curvature>max_crv_value[4]) max_crv_value[4] = special_curvature;
	}

	// set the maximum or minimum value of all four curvatures
	minmax(crv_result, GAUSS_CRV, 4);


    return K;
}
Int_t r3b_sim_and_rclass(){

   // Load the Main Simulation macro
   gROOT->LoadMacro("r3ball.C");

   //-------------------------------------------------
   // Monte Carlo type     |    fMC        (TString)
   //-------------------------------------------------
   //   Geant3:                 "TGeant3"
   //   Geant4:                 "TGeant4"
   //   Fluka :                 "TFluka"

   TString fMC ="TGeant3";

   //-------------------------------------------------
   // Primaries generation
   // Event Generator Type |   fGene       (TString)
   //-------------------------------------------------
   // Box generator:             "box"
   // Ascii generator:           "ascii"
   // R3B spec. generator:       "r3b"

   TString fGene="box";

   //-------------------------------------------------
   // Secondaries  generation (G4 only)
   // R3B Spec. PhysicList |     fUserPList (Bool_t)
   // ----------------------------------------------
   //     VMC Standard           kFALSE
   //     R3B Special            kTRUE;

   Bool_t fUserPList= kTRUE;

   // Target type
   TString target1="LeadTarget";
   TString target2="Para";
   TString target3="Para45";
   TString target4="LiH";

   //-------------------------------------------------
   //- Geometrical Setup Definition
   //-  Non Sensitiv        |    fDetName (String)
   //-------------------------------------------------
   //   Target:                  TARGET
   //   Magnet:                  ALADIN
   //
   //-------------------------------------------------
   //-  Sensitiv            |    fDetName
   //-------------------------------------------------
   //   Calorimeter:             CALIFA
   //                            CRYSTALBALL
   //
   //   Tof:                     TOF
   //                            MTOF
   //
   //   Tracker:                 DCH
   //                            TRACKER
   //                            GFI
   //
   //   Neutron Detector
   //   Plastic                  LAND
   //   RPC                      
   //                            RPCFLAND
   //                            RPCMLAND

    TObjString det1("TARGET");
    TObjString det2("ALADIN");
    TObjString det3("CALIFA");
    TObjString det4("CRYSTALBALL");
    TObjString det5("TOF");
    TObjString det6("MTOF");
    TObjString det7("DCH");
    TObjString det8("TRACKER");
    TObjString det9("GFI");
    TObjString det10("LAND");
    TObjString det11("RPCMLAND");
    TObjString det12("RPCFLAND");
    TObjString det13("SCINTNEULAND");

    TObjArray fDetList;
//    fDetList.Add(&det1);
    fDetList.Add(&det2);
//    fDetList.Add(&det4);
//    fDetList.Add(&det5);
//    fDetList.Add(&det6);
//    fDetList.Add(&det7);
//    fDetList.Add(&det8);
//    fDetList.Add(&det9);
    fDetList.Add(&det10);
//    fDetList.Add(&det11);


   //-------------------------------------------------
   //- N# of Sim. Events   |    nEvents     (Int_t)
   //-------------------------------------------------

   Int_t nEvents = 1;

   //-------------------------------------------------
   //- EventDisplay        |    fEventDisplay (Bool_t)
   //-------------------------------------------------
   //   connected:              kTRUE
   //   not connected:          kFALSE

   Bool_t fEventDisplay=kTRUE;

    // Magnet Field definition
   Bool_t fR3BMagnet = kTRUE;

   // Main Sim function call
   r3ball(  nEvents,
            fDetList,
            target1,
	    fEventDisplay,
	    fMC,
	    fGene,
	    fUserPList,
            fR3BMagnet
          );

//------------------- Read Data from LMD-ROOT file -------------------------------------
// the ROOT files (simulated and experimental) are the same but, for testing purpose, show how to use two quantities for comparison
   R3BLandData* LandData1 = new R3BLandData("s318_172.root", "h309"); // file input and tree name
   R3BLandData* LandData2 = new R3BLandData("s318_172.root", "h309"); // file input and tree name
// Define diferent options for TCanvas
   TCanvas* c = new TCanvas("Compare quantities from ROOT files","ROOT Canvas");
   c->Divide(2,1);                                                                 // Divide a canvas in two ...or more
   int entries1 = LandData1->GetEntries();                                         // entries number of first TTree
   int entries2 = LandData2->GetEntries();                                         // entries number of first TTree
   TLeaf* leaf1;
//   TLeaf* leaf11;                                                                  // define one leaf...
   TLeaf* leaf2;
//   TLeaf* leaf22;                                                                  // define another leaf
   cout<<"Entries number in  first TTree = "<<entries1<<endl;
   cout<<"Entries number in second TTree = "<<entries2<<endl;
//  Reprezentation of 1D histogram from ROOT files
   for (int i=0; i < entries1; i++)
      {
         leaf1 = LandData1->GetLeaf("Nte",i);                                      // Accessing TLeaf informations
//         leaf11 = LandData1->GetLeaf("Nhe",i);                                   // Accessing TLeaf informations
       LandData1->FillHisto1D(leaf1);                                              // Fill 1D histogram ... automatical bin width
//         LandData1->FillHisto2D(leaf1,leaf11);                                   // Fill 2D histogram ... automatical bin width
      }
      c->cd(1);
      LandData1->Draw1D();                                                         // Plotting 1D histogram ... automatical bin width
//      LandData1->Draw2D();                                                         // Plotting 2D histogram ... automatical bin width

   for (int i=0; i < entries2; i++)
      {
         leaf2 = LandData2->GetLeaf("Nhe",i);                                      // Accessing TLeaf informations
//         leaf22 = LandData2->GetLeaf("Nte",i);                                     // Accessing TLeaf informations
         LandData2->FillHisto1D(leaf2);                                            // Fill 1D histogram ... automatical bin width
//         LandData2->FillHisto2D(leaf2,leaf22);                                     // Fill 2D histogram ... automatical bin width
      }
      c->cd(2);
      LandData2->Draw1D();                                                         // Plotting 1D histogram ... automatical bin width
//      LandData2->Draw2D();                                                        // Plotting 2D histogram ... automatical bin width
      // ... or you can plot on the same histogram by comment the precedent two line and comment out the next line
//      LandData2->Draw1Dsame();                                                        // Plotting 1D histogram ... automatical bin width
// ... The same things for 2D histograming

   //####### for diferent TLeaf analysis ###############
/*
   Int_t len = leaf1->GetLen();
   for(Int_t j=0; j<len ; j++)
      {
       leaf1->GetValue(j);                                              // TLeaf Value for different analysis
      }
*/
    
}
Esempio n. 7
0
Int_t r3bsim_batch(Double_t fEnergyP, Int_t fMult, Int_t nEvents, Int_t fGeoVer, Double_t fNonUni){
	
	cout << "Running r3bsim_batch with arguments:" <<endl;
	cout << "Primary energy: " << fEnergyP << " MeV" <<endl;
	cout << "Multiplicity: " << fEnergyP <<endl;
	cout << "Number of events: " << nEvents <<endl;
	cout << "CALIFA geo version: " << fGeoVer <<endl;
	cout << "Non uniformity: " << fNonUni <<endl<<endl;

	// Load the Main Simulation macro
	gROOT->LoadMacro("r3ball_batch.C");
	
	//-------------------------------------------------
	// Monte Carlo type     |    fMC        (TString)
	//-------------------------------------------------
	//   Geant3:                 "TGeant3"
	//   Geant4:                 "TGeant4"
	//   Fluka :                 "TFluka"
	
	TString fMC ="TGeant4";
	
	//-------------------------------------------------
	// Primaries generation
	// Event Generator Type |   fGene       (TString)
	//-------------------------------------------------
	// Box generator:             "box"
	// CALIFA generator:          "gammas"
	// R3B spec. generator:       "r3b"
	
	TString fGene="gammas";
	
	//-------------------------------------------------
	// Secondaries  generation (G4 only)
	// R3B Spec. PhysicList |     fUserPList (Bool_t)
	// ----------------------------------------------
	//     VMC Standard           kFALSE
	//     R3B Special            kTRUE;
	
	Bool_t fUserPList= kTRUE;
	
	// Target type
	TString target1="LeadTarget";
	TString target2="Para";
	TString target3="Para45";
	TString target4="LiH";
	
	//-------------------------------------------------
	//- Geometrical Setup Definition
	//-  Non Sensitiv        |    fDetName (String)
	//-------------------------------------------------
	//   Target:                  TARGET
	//   Magnet:                  ALADIN
	//                            GLAD
	//-------------------------------------------------
	//-  Sensitiv            |    fDetName
	//-------------------------------------------------
	//   Calorimeter:             CALIFA
	//                            CRYSTALBALL
	//
	//   Tof:                     TOF
	//                            MTOF
	//
	//   Tracker:                 DCH
	//                            TRACKER
	//                            GFI
	//
	//   Neutron:                 LAND
	
    TObjString det0("TARGET");
    TObjString det1("ALADIN");
    TObjString det2("GLAD");
    TObjString det3("CALIFA");
    TObjString det4("CRYSTALBALL");
    TObjString det5("TOF");
    TObjString det6("MTOF");
    TObjString det7("DCH");
    TObjString det8("TRACKER");
    TObjString det9("GFI");
    TObjString det10("LAND");
	
    TObjArray fDetList;
    fDetList.Add(&det0);
    //fDetList.Add(&det2);
    fDetList.Add(&det3);
    //fDetList.Add(&det5);
    //fDetList.Add(&det6);
    //fDetList.Add(&det7);
    fDetList.Add(&det8);
    //fDetList.Add(&det9);
    //fDetList.Add(&det10);
	
	
	//-------------------------------------------------
	//- N# of Sim. Events   |    nEvents     (Int_t)
	//-------------------------------------------------
	
	//NOW GIVEN AS AN ARGUMENT!
	//Int_t nEvents = 100;
	
	//-------------------------------------------------
	//- EventDisplay        |    fEventDisplay (Bool_t)
	//-------------------------------------------------
	//   connected:              kTRUE
	//   not connected:          kFALSE
	
	Bool_t fEventDisplay=kFALSE;
	
    // Magnet Field definition
	//Bool_t fR3BMagnet = kTRUE;
	Bool_t fR3BMagnet = kFALSE;
	
	
	// Main Sim function call
	r3ball_batch(  nEvents,
		   fDetList,
		   target2,
		   fEventDisplay,
		   fMC,
		   fGene,
		   fUserPList,
		   fR3BMagnet,
		   fEnergyP,
		   fMult,
		   fGeoVer, 
		   fNonUni
		   );     
	cout << "... Work done! " <<endl;
	
}