double
NewDiscretizedRandomProcessSeries::getFactorSensitivity(double time)
{
	// The parameterID has been set to the number of 
	// the random variable in question

	// So, do the same thing as above, just set x(i-1) equal to 1.0
	// for i==parameterID

	if (time == 0.0 || parameterID<0) {
		return 0.0;
	}
	else if (randomVariables == 0 || kickInTimes == 0) {
		opserr << "ERROR in DiscretizedRandomProcessSeries::getFactorSensitivity(): " << endln
			<< " random variables or kick-in times vector(s) do not exist. " << endln;
		return 0.0;
	}
	else if (kickInTimes->Size() != randomVariables->Size() ) {
		opserr << "ERROR in DiscretizedRandomProcessSeries::getFactorSensitivity(): " << endln
			<< " number of random variables is not the same as kick-in times. " << endln;
		return 0.0;
	}
	else {

		double sum1;
		double sum2;
//		int nrv = 0;
		double modFuncAmplitude;
		Filter *theFilter;

		// Loop over all modulating functions
		double dtime;
		sum1 = 0.0;
		for (int k=0; k<numModFuncs; k++) {

			// Get value of modulating function number k at time t
			modFuncAmplitude = theModulatingFunctions[k]->getAmplitude(time);
			theFilter = theModulatingFunctions[k]->getFilter();

			// Number of discretizing random variables
			//nrv = randomVariables->Size();

			// Loop over all rv's (even though some may be zero at this time)
			dtime=time-(*kickInTimes)(parameterID);
//			if(fabs(dtime)<=1.0e-7) dtime=0.0;
			sum2 = theFilter->getAmplitude(dtime, 0.0);
			sum1 += sum2*modFuncAmplitude;
		}

//		double result=0.0;
//		if(fabs(time-(*kickInTimes)(parameterID-1))<= 1.0e-8) result=1.0;
		double result = mean + c*sum1;
		return result;
	}
}
double
NewDiscretizedRandomProcessSeries::getFactor(double time)
{
  if (time == 0.0) {
    return 0.0;
  }
  else if (randomVariables == 0 || kickInTimes == 0) {
    opserr << "ERROR in DiscretizedRandomProcessSeries::getFactor(): " << endln
	   << " random variables or kick-in times vector(s) do not exist. " << endln;
    return 0.0;
  }
  else if (kickInTimes->Size() != randomVariables->Size() ) {
    opserr << "ERROR in DiscretizedRandomProcessSeries::getFactor(): " << endln
	   << " number of random variables is not the same as kick-in times. " << endln;
    return 0.0;
  }
  else {
    double sum1;
    double sum2;
    //		int nrv = 0;
    double modFuncAmplitude, filterAmplitude;
    Filter *theFilter;
    
    //		nrv = randomVariables->Size();
    for (int i=0; i<numRandVar; i++) {
      active[i]=false;
      if(time>(*kickInTimes)(i)-1.0e-7){
	active[i]=true;
      }
    }
    
    // Loop over all modulating functions
    sum1 = 0.0;
    double dtime;
    for (int k=0; k<numModFuncs; k++) {
      
      // Get value of modulating function number k at time t
      modFuncAmplitude = theModulatingFunctions[k]->getAmplitude(time);
      theFilter = theModulatingFunctions[k]->getFilter();
      
      // Number of discretizing random variables
      //			nrv = randomVariables->Size();
      
      // Loop over all active rv's 
      sum2 = 0.0;
      for (int i=0; i<numRandVar; i++) {
	
	// Get value of filter for argument (t-ti)
	dtime=time-(*kickInTimes)(i);
	theFilter->setKickTime((*kickInTimes)(i));
	filterAmplitude = theFilter->getAmplitude(dtime, 0.0);
	
	// Add contribution 'ui * hi'
	sum2 += (*randomVariables)(i) * filterAmplitude;
	
	// Break when we get to inactive rv's
	if (dtime <= -1.0e-7) {
	  break;
	}
      }
      
      sum1 += sum2*modFuncAmplitude;
    }
    
    double result = mean + c*sum1;
    
    output << "time... ," << time << ","<< "value.. ," << sum1 << "\n"; 
    output.flush();
    
    return result;
  }
}