Exemplo n.º 1
0
	vector<double> getDistances( DataPoint * x, DataPoint * y )
	{
		vector<double> distances;
		vector<string> xListOfNames = x->GetAllNames();
		vector<string> yListOfNames = y->GetAllNames();
		vector<string>::iterator xIter = xListOfNames.begin();
		vector<string>::iterator yIter = yListOfNames.begin();
		Observable * xVar = 0;
		Observable * yVar = 0;
		while ( (xVar = x->GetObservable( *xIter ) ) && (yVar = y->GetObservable( *yIter ) ) ) {
			if ( (*xIter == "time" ) || (*xIter == "mass" )) {
				//cout << fabs(xVar->GetValue() - yVar->GetValue() ) << endl;
				distances.push_back( fabs(xVar->GetValue() - yVar->GetValue() ) );
			}
			else if ( (*xIter == "cosTheta") ) {
				distances.push_back( fabs(xVar->GetValue() - yVar->GetValue()) );
			}
			/*
			   else if(  (*xIter == "cosPsi") ) {
			   distances.push_back( fabs( xVar->GetValue() - yVar->GetValue() ) );
			   }
			   else if ( (*xIter == "phi") ) {
			   double diff = diffmod2pi( xVar->GetValue() - yVar->GetValue() );
			   distances.push_back( diff );
			   }
			 */
			++xIter, ++yIter;
			if ( xIter == xListOfNames.end() || yIter == yListOfNames.end() ) break;
		}
		return distances;
	}
Exemplo n.º 2
0
//Use accept/reject method to create data
int Foam::GenerateData( int DataAmount )
{
	//if( newDataSet->GetDataNumber() < DataAmount ) newDataSet->ReserveDataSpace( DataAmount );
	for( int dataIndex = 0; dataIndex < DataAmount; ++dataIndex )
	{
		//Generate the discrete observables, and select the correct Foam generator to use
		int combinationIndex = 0;
		int incrementValue = 1;
		DataPoint * temporaryDataPoint = new DataPoint(allNames);
		for( int discreteIndex = int(discreteNames.size() - 1); discreteIndex >= 0; --discreteIndex )
		{
			//Create the discrete observable
			Observable * temporaryObservable = generationBoundary->GetConstraint( *discreteNames_ref[unsigned(discreteIndex)] )->CreateObservable(rootRandom);
			double currentValue = temporaryObservable->GetValue();
			temporaryDataPoint->SetObservable( *discreteNames_ref2[unsigned(discreteIndex)], temporaryObservable );
			delete temporaryObservable;

			//Calculate the index
			for (unsigned int valueIndex = 0; valueIndex < discreteValues[unsigned(discreteIndex)].size(); ++valueIndex )
			{
				if ( fabs( discreteValues[unsigned(discreteIndex)][valueIndex] - currentValue ) < DOUBLE_TOLERANCE )
				{
					combinationIndex += ( incrementValue * int(valueIndex) );
					incrementValue *= int(discreteValues[unsigned(discreteIndex)].size());
					break;
				}
			}
		}

		//Use the index calculated to select a Foam generator and generate an event with it
		Double_t* generatedEvent = new Double_t[ continuousNames.size() ];
		foamGenerators[unsigned(combinationIndex)]->MakeEvent();
		foamGenerators[unsigned(combinationIndex)]->GetMCvect(generatedEvent);

		//Store the continuous observables
		for (unsigned int continuousIndex = 0; continuousIndex < continuousNames.size(); ++continuousIndex )
		{
			string unit = generationBoundary->GetConstraint( *continuousNames_ref[continuousIndex] )->GetUnit();
			double newValue = minima[continuousIndex] + ( ranges[continuousIndex] * generatedEvent[continuousIndex] );
			temporaryDataPoint->SetObservable( *continuousNames_ref2[continuousIndex], newValue, unit );
			//cout << continuousNames[continuousIndex] << "\t" << newValue << "\t" << 0.0 << "\t" << unit << endl;
		}

		delete[] generatedEvent;
		//	Store the event
		temporaryDataPoint->SetDiscreteIndex(dataIndex);
		newDataSet->AddDataPoint(temporaryDataPoint);
	}

	//cout << "Destroying Generator(s)" << endl;
	//this->RemoveGenerator();
	return DataAmount;
}
Exemplo n.º 3
0
		double getDistance(DataPoint * x, DataPoint * y)
		{
			double distance = 0.;
			double diff = 0.;	(void) diff;	//	Unused
			vector<string> xListOfNames = x->GetAllNames();
			vector<string> yListOfNames = y->GetAllNames();
			vector<string>::iterator xIter = xListOfNames.begin();
			vector<string>::iterator yIter = yListOfNames.begin();
			Observable * xVar = 0;
			Observable * yVar = 0;
			double xVal = 0.;
			double yVal = 0.;
			char buffer[100];	(void) buffer;	//	Unused
			while ( (xVar = x->GetObservable( *xIter ) ) && (yVar = y->GetObservable( *yIter ) ) ) {
				//cout << *xIter << endl;
				//if ( (*xIter == "time") ) {
				//	xVal = ( xVar->GetValue() - 1.6 )/1.2;
			    //	yVal = ( yVar->GetValue() - 1.6 )/1.2;
				//}
				if ( (*xIter == "mass") ) {
					xVal = ( xVar->GetValue() - 5200. )/350.;
					yVal = ( yVar->GetValue() - 5200. )/350.;
				}
				else if ( (*xIter == "cosTheta1") ) {
					xVal = ( xVar->GetValue() );
					yVal = ( yVar->GetValue() );
				}
				else if(  (*xIter == "cosTheta2") ) {
					xVal = ( xVar->GetValue() );
					yVal = ( yVar->GetValue() );
				}
				else if ( (*xIter == "phi") ) {
					xVal = ( xVar->GetValue() )/3.14159;
					yVal = ( yVar->GetValue() )/3.14159;
				}
				else {
					xVal = 0.;
					yVal = 0.;
				}
				distance += ( (xVal - yVal)*(xVal - yVal) );
				//sprintf(buffer, " %f %f %f", xVar->GetValue(), yVar->GetValue(), sqrt(distance));
				//cout << (*xIter) << buffer << endl;
				++xIter, ++yIter;
				if ( xIter == xListOfNames.end() || yIter == yListOfNames.end() ) break;
			}
			return sqrt(distance);
		}
Exemplo n.º 4
0
        double getWeight( DataPoint * x )
        {
       		vector<string> xListOfNames = x->GetAllNames();
			vector<string>::iterator xIter = xListOfNames.begin();
			Observable * xVar = 0;
			double xVal = 1.;
			while ( ( xVar = x->GetObservable( *xIter ) ) ) {
                if ( (*xIter == "fsig_sw") ) {
					xVal = xVar->GetValue();
				}
				++xIter;
				if ( xIter == xListOfNames.end() ) break;
            }
            return xVal;
        }
Exemplo n.º 5
0
	void updatePhaseSpaceBoundary( DataPoint * x, PhaseSpaceBoundary * newPhase, PhaseSpaceBoundary * oldPhase, vector<double> distances )
	{
		vector<string> xListOfNames = x->GetAllNames();
		vector<string>::iterator xIter = xListOfNames.begin();
		Observable * xVar = 0;
		double min = 0., max = 0.;
		int i = 0;
		char buffer[100];	(void) buffer;//	Unused

		while ( ( xVar = x->GetObservable( *xIter ) ) ) {
			if ( *xIter == "time" || *xIter == "cosTheta" || *xIter == "mass"){//|| *xIter == "cosPsi" || *xIter == "phi") {
				min = xVar->GetValue() - distances[ (unsigned)i ];
				max = xVar->GetValue() + distances[ (unsigned)i ];
				if ( min > oldPhase->GetConstraint( *xIter )->GetMinimum() ) ((ObservableContinuousConstraint *)newPhase->GetConstraint( *xIter ))->SetMinimum( min );
				if ( max < oldPhase->GetConstraint( *xIter )->GetMaximum() ) ((ObservableContinuousConstraint *)newPhase->GetConstraint( *xIter ))->SetMaximum( max );
				//cout << *xIter << " " << buffer << endl;
			}
			++xIter;
			if ( xIter == xListOfNames.end() ) break;
			i++;
			}
		}
Exemplo n.º 6
0
//Returns whether a point is within the boundary
bool PhaseSpaceBoundary::IsPointInBoundary( DataPoint * TestDataPoint, bool silence )
{
	for (unsigned int nameIndex = 0; nameIndex < allNames.size(); ++nameIndex )
	{
		//Check if test Observable exists in the DataPoint
		Observable * testObservable = TestDataPoint->GetObservable( allNames[nameIndex], silence );
		if ( testObservable->GetUnit() == "NameNotFoundError" )
		{
			cerr << "Observable \"" << allNames[nameIndex] << "\" expected but not found" << endl;
			return false;
		}
		else
		{
			//Check if the Observable fits
			if ( !allConstraints[nameIndex]->CheckObservable(testObservable) )
			{
				return false;
			}
			else if( allConstraints[nameIndex]->IsDiscrete() )
			{
				vector<double> temp_vec = allConstraints[nameIndex]->GetValues();
				for( unsigned int i=0; i< temp_vec.size(); ++i )
				{
					if( fabs( testObservable->GetValue() - temp_vec[i] ) < DOUBLE_TOLERANCE_PHASE )
					{
						Observable* temp = new Observable( testObservable->GetName(), temp_vec[i], testObservable->GetUnit() );
						TestDataPoint->SetObservable( testObservable->GetName(), temp );
						delete temp;
					}
				}
			}
		}
	}

	//Point is within the boundary
	return true;
}