pair<Float_t, Float_t> TPedestalCalculation::calculateFirstPedestalDiaCMN(int ch, deque<Float_t> adcQueue, float meanCMN, float sigmaCMN, int iterations, float maxSigma) {
	diaSUMCmn[ch]=0;
	diaSUM2Cmn[ch]=0;
	diaEventsInSumCMN[ch]=0;
	//  if(ch==7)cout<<"calcFirstPedCMN:"<<ch<<" "<<meanCMN<<" "<<sigmaCMN<<" "<<diaEventsInSumCMN[ch]<<endl;
	this->diaEventUsedCMN[ch].clear();
	for(nEvent=0;nEvent<adcQueue.size();nEvent++){
		Float_t adc = adcQueue.at(nEvent);
		if(   (adc >= getLowLimitPedestal(meanCMN,sigmaCMN,maxSigma))
				&& (adc <= getHighLimitPedestal(meanCMN,sigmaCMN,maxSigma)) ){
			diaEventUsedCMN[ch].push_back(true);
			diaSUMCmn[ch]+=adc;
			diaSUM2Cmn[ch]+=adc*adc;
			diaEventsInSumCMN[ch]++;
		}//end if
		else
			diaEventUsedCMN[ch].push_back(false);
	}//end for nEvent
	//TODO!!! FIX!!! PROBLEM!!!!!!!!
	///WORK HERE!!!!!!!
	if(diaEventsInSumCMN[ch]==0)
		cout<<"events in sum=0: "<<nEvent<<" "<<ch<<" "<<diaEventsInSumCMN[ch]<<" "<<diaEventsInSum[ch]<<endl;
	meanCMN=diaSUMCmn[ch]/(Float_t)diaEventsInSumCMN[ch];
	//  if(ch==7)cout<<diaSUMCmn[ch]<<" "<<diaSUM2Cmn[ch]<<" "<<diaEventsInSumCMN[ch]<<" "<<meanCMN<<endl;
	sigmaCMN=TMath::Sqrt( (diaSUM2Cmn[ch]/(Float_t)diaEventsInSumCMN[ch])-meanCMN*meanCMN);

	diaPedestalMeanCMN[ch]=RoundFloat(meanCMN);
	diaPedestalSigmaCMN[ch]=RoundFloat(sigmaCMN);
	pair<Float_t,Float_t> output = make_pair(meanCMN,sigmaCMN);
	if(iterations==0)return output;
	else return this->calculateFirstPedestalDiaCMN(ch,adcQueue,meanCMN,sigmaCMN,iterations-1,maxSigma);
}
//////////////////////////////////////////////////////////////////////////
//																		//
//																		//
//////////////////////////////////////////////////////////////////////////
void SFloat4::Fix(void)
{
	x = RoundFloat(x, BINARY_PRECISION);
	y = RoundFloat(y, BINARY_PRECISION);
	z = RoundFloat(z, BINARY_PRECISION);
	w = RoundFloat(w, BINARY_PRECISION);
}
pair <Float_t,Float_t> TPedestalCalculation::calculateFirstPedestalDia(int ch,deque<Int_t> adcQueue, float meanChannel, float sigmaChannel,int iterations,float maxSigma){
	diaSUM[ch]=0;
	diaSUM2[ch]=0;
	diaEventsInSum[ch]=0;
	this->diaEventUsed[ch].clear();
	for(UInt_t nEvent=0;nEvent<adcQueue.size();nEvent++){
		Float_t adc = (Float_t) adcQueue.at(nEvent);
		if(   (adc >= getLowLimitPedestal(meanChannel,sigmaChannel,maxSigma)  )
				&& (adc <= getHighLimitPedestal(meanChannel,sigmaChannel,maxSigma) ) ){
			diaEventUsed[ch].push_back(true);
			diaSUM[ch]+=adc;
			diaSUM2[ch]+=adc*adc;
			diaEventsInSum[ch]++;
		}//end if
		else
			diaEventUsed[ch].push_back(false);
	}//end for nEvent
	if(diaEventsInSum[ch]<0.1*adcQueue.size())
		cout<<"For the calculation of first pedestals in diamond and ch "<<ch<<"there were only "<<diaEventsInSum[ch]<<" Events used..."<<endl;
	Float_t mean=diaSUM[ch]/(Float_t)diaEventsInSum[ch];
	Float_t sigma=TMath::Sqrt( diaSUM2[ch]/(Float_t)diaEventsInSum[ch]-mean*mean);

	diaPedestalMean[ch]=RoundFloat(mean);
	diaPedestalSigma[ch]=RoundFloat(sigma);
	pair<Float_t,Float_t> output = make_pair(mean,sigma);
	//	if(verbosity>4&& ch ==103)
	//		cout<<"diamond ch "<<ch<<", it "<<iterations<<", usedEvents " <<diaEventsInSum[ch]<<"\t"<<mean<<"+/-"<<sigma<<endl;
	if(iterations==0)return output;
	else return this->calculateFirstPedestalDia(ch,adcQueue,mean,sigma,iterations-1,maxSigma);
}
Exemple #4
0
void
nsClientRect::SetLayoutRect(const nsRect& aLayoutRect)
{
  double scale = 65536.0;
  // Round to the nearest 1/scale units. We choose scale so it can be represented
  // exactly by machine floating point.
  double scaleInv = 1/scale;
  double t2pScaled = scale/nsPresContext::AppUnitsPerCSSPixel();
  double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
  double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
  SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
          RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
}
pair<float,float> TPedestalCalculation::checkPedestalDia(int ch,int maxSigma){
	float mean =this->diaSUM[ch]/(float)this->diaEventsInSum[ch];//ok
	float meanCMN= this->diaSUMCmn[ch]/(float)diaEventsInSumCMN[ch];//ok
	float sigma=TMath::Sqrt(this->diaSUM2[ch]/(float)this->diaEventsInSum[ch]-mean*mean);//ok
	float sigmaCMN=TMath::Sqrt(this->diaSUM2Cmn[ch]/(float)diaEventsInSumCMN[ch]-meanCMN*meanCMN);//ok
	//cout<<mean<<" "<<sigma<<" "<<this->diaAdcValues[ch].front()<<" "<<this->diaAdcValues[ch].back()<<" "<<diaEventUsed[ch].front()<<" "<<(diaAdcValues[ch].back()<mean+sigma*maxSigma)<<endl;
	//NORMAL CALCULATION WAY //ok
	if(this->diaEventUsed[ch].front()){
		this->diaSUM[ch]-=this->diaAdcValues[ch].front();
		this->diaSUM2[ch]-=this->diaAdcValues[ch].front()*this->diaAdcValues[ch].front();
		this->diaEventsInSum[ch]--;
	}
	if(diaAdcValues[ch].back()<=mean+max(sigma*maxSigma,(float)1.)&&diaAdcValues[ch].back()>=mean-max(sigma*maxSigma,(float)1.)){
		this->diaSUM[ch]+=this->diaAdcValues[ch].back();
		this->diaSUM2[ch]+=this->diaAdcValues[ch].back()*this->diaAdcValues[ch].back();
		this->diaEventsInSum[ch]++;
		this->diaEventUsed[ch].push_back(true);
	}
	else
		this->diaEventUsed[ch].push_back(false);

	//COMMON MODE NOISE CALCULATION WAY
	if(this->diaEventUsedCMN[ch].front()){
		this->diaSUMCmn[ch]-=this->diaAdcValuesCMN[ch].front();
		this->diaSUM2Cmn[ch]-=this->diaAdcValuesCMN[ch].front()*this->diaAdcValuesCMN[ch].front();
		this->diaEventsInSumCMN[ch]--;
	}
	if(diaAdcValuesCMN[ch].back()<=meanCMN+max(sigmaCMN*maxSigma,(float)1.)&&diaAdcValuesCMN[ch].back()>=meanCMN-max(sigmaCMN*maxSigma,(float)1.)){
		this->diaSUMCmn[ch]+=this->diaAdcValuesCMN[ch].back();
		this->diaSUM2Cmn[ch]+=this->diaAdcValuesCMN[ch].back()*this->diaAdcValuesCMN[ch].back();
		this->diaEventsInSumCMN[ch]++;
		this->diaEventUsedCMN[ch].push_back(true);
	}
	else
		this->diaEventUsedCMN[ch].push_back(false);

	mean =this->diaSUM[ch]/(float)this->diaEventsInSum[ch];//ok
	meanCMN = diaSUMCmn[ch]/(float)diaEventsInSumCMN[ch];//ok
	sigma=TMath::Sqrt(this->diaSUM2[ch]/(float)this->diaEventsInSum[ch]-mean*mean);//ok
	sigmaCMN=TMath::Sqrt(this->diaSUM2Cmn[ch]/(float)this->diaEventsInSumCMN[ch]-meanCMN*meanCMN);//ok
	diaPedestalMeanCMN[ch]=RoundFloat(meanCMN);
	diaPedestalSigmaCMN[ch]=RoundFloat(sigmaCMN);
	diaPedestalMean[ch]=RoundFloat(mean);
	diaPedestalSigma[ch]=RoundFloat(sigma);
	//  if(diaPedestalSigma[ch]<diaPedestalSigmaCMN[ch])
	//    cout<<std::setw(5)<<nEvent<<" "<<std::setw(3)<<ch<<" "<<setw(6)<<diaPedestalSigma[ch]<<" "<<setw(6)<<diaPedestalSigmaCMN[ch]<<endl;
	//	if(ch==7) cout<<cmNoise<<" mean: "<<mean<<"/"<<meanCMN<<"\tsigma:"<<sigma<<"/"<<sigmaCMN<<"\t"<<diaEventsInSum[ch]<<"/"<<diaEventsInSumCMN[ch]<<endl;
	return make_pair(mean,sigma);

}
/*==================================================================================================
BRIEF: Converts tick into x-coordinate (app window relative).

PARAMETERS:
[IN]
    tick - tick value
    loc - grid location
[OUT]
N/A

OUTPUT: x-coordinate
==================================================================================================*/
int Tick2X(float tick, Loc loc)
{
    if(loc == Loc_MainGrid)
    {
        //return ApproxFloat((tick - OffsTick)*tickWidth + GridX1);
		return RoundFloat(tick*tickWidth) - RoundFloat(OffsTick*tickWidth) + GridX1;
    }
    else if(loc == Loc_SmallGrid)
    {
        //return ApproxFloat((tick - gAux->OffsTick)*gAux->tickWidth + GridXS1);
		return RoundFloat(tick*aux_panel->tickWidth) - RoundFloat(aux_panel->OffsTick*aux_panel->tickWidth) + GridXS1;
    }
    else
    {
        return 0;
    }
}
void TPedestalCalculation::calculateFirstPedestals(deque<Int_t> DetAdcQueue[8][N_DET_CHANNELS], deque<Int_t> DiaAdcQueue[N_DIA_CHANNELS], int maxSigma){
	if(verbosity)cout<<"calculate Pedestal for the first "<<slidingLength<<" Entries..."<<endl;
	for(int det=0;det <8;det++){
		for(int ch=0;ch<N_DET_CHANNELS;ch++){
			TRawEventSaver::showStatusBar(256*det+ch,256*8,10);
			pair<Float_t,Float_t> values;
			values=this->calculateFirstPedestalDet(det,ch,DetAdcQueue[det][ch],meanValues[det][ch],sigmaValues[det][ch],7,MAXSDETSIGMA);//7 iteration for first pedestal
			pedestalMean[det][ch]=RoundFloat(values.first);
			pedestalSigma[det][ch]=RoundFloat(values.second);
		}
	}

	for(int ch=0;ch<N_DIA_CHANNELS;ch++){
		pair<Float_t,Float_t> values;
		values=this->calculateFirstPedestalDia(ch,DiaAdcQueue[ch],meanValues[8][ch],sigmaValues[8][ch],7,MAXDIASIGMA);//7 iterations for first pedestal
		diaPedestalMeanStartValues[ch]=RoundFloat(values.first);
		diaPedestalSigmaStartValues[ch]=RoundFloat(values.second);
	}
	if(verbosity)cout<<"\tDONE!"<<endl;
}
bool AuxCheckPosData(int* posX)
{
    if(aux_panel->auxmode == AuxMode_Pattern && aux_panel->workPt != aux_panel->blankPt)
    {
       *posX = aux_panel->curr_play_x - RoundFloat(aux_panel->OffsTick*aux_panel->tickWidth);
        return true;
    }
    else
    {
        return false;
    }
}
void TPedestalCalculation::fillFirstEventsAndMakeDiaDeque()
{
	for(UInt_t ch=0;ch<N_DIA_CHANNELS;ch++){
		//		diaAdcValues[ch].clear();
		diaAdcValuesCMN[ch].clear();
	}
	//	//save Sliding Pedestal Values for first slidingLength Events

	for(nEvent=0;nEvent<slidingLength;nEvent++){
		//Fill tree
		//		eventReader->LoadEvent(nEvent);
		doCmNoiseCalculation();
		cmnValues.push_back(cmNoise);
		for(UInt_t ch=0;ch<N_DIA_CHANNELS;ch++){
			Float_t adc = (nEvent<slidingLength)?this->diaAdcValues[ch].at(nEvent):eventReader->getDia_ADC(ch);;
			adc -=cmNoise;
			diaAdcValuesCMN[ch].push_back(adc);
			Float_t mean = RoundFloat(diaPedestalMeanStartValues[ch]);
			Float_t sigma= RoundFloat(diaPedestalSigmaStartValues[ch]);

			diaPedestalMean[ch]= RoundFloat(mean);
			diaPedestalSigma[ch]= RoundFloat(sigma);
			mean-=cmNoise;
			//if(ch==7)cout<<nEvent<<" deque "<<adc<<" "<<diaAdcValues[ch].size()<<endl;
			diaPedestalMeanCMN[ch]= RoundFloat(mean);;
			diaPedestalSigmaCMN[ch]=RoundFloat(sigma);

		}
	}
	if(verbosity)cout<<"update first Pedestal Calculation"<<endl;
	for(UInt_t ch=0;ch<N_DIA_CHANNELS;ch++){
		pair<Float_t, Float_t> values = calculateFirstPedestalDia(ch,diaAdcValues[ch],diaPedestalMeanStartValues[ch],diaPedestalMeanStartValues[ch],7,MAXDIASIGMA);
		values = calculateFirstPedestalDiaCMN(ch,diaAdcValuesCMN[ch],diaPedestalMeanStartValues[ch],diaPedestalMeanStartValues[ch],7,3);
		diaPedestalMeanCMN[ch] = values.first;
		diaPedestalSigmaCMN[ch] = values.second;
		if(ch==7&&verbosity>4){
			//      cout<<"PEDESTAL: ch: "<<ch<<" "<<values.first<<" "<<values.second<<endl;
			for(UInt_t i=0;i<diaAdcValues[ch].size()&&i<diaAdcValuesCMN[ch].size();i++){
				cout<<" "<<setw(3)<<i<<"  "<<diaAdcValues[ch].at(i)<<" "<<diaEventUsed[ch].at(i)<<" "<<diaAdcValuesCMN[ch].at(i)<<" "<<diaEventUsedCMN[ch].at(i)<<" ";
				cout<<std::setw(5)<<(diaAdcValues[ch].at(i)-diaAdcValuesCMN[ch].at(i))<<" "<<cmNoise<<" "<<diaEventsInSum[ch]<<" "<<diaEventsInSumCMN[ch]<<endl;
			}
			if(verbosity%2==1){
			cout<<"press a key and enter to continue..."<<endl;
			char t; cin>>t;
			}
		}
	}
void TestRoundFloat(void)
{
	AssertFloat(1.0f, RoundFloat(0.75f, 0), 7);
	AssertFloat(1.0f, RoundFloat(1.0f, 0), 7);
	AssertFloat(1.0f, RoundFloat(0.5f, 0), 7);
	AssertFloat(1.0f, RoundFloat(1.49f, 0), 7);
	AssertFloat(0.0f, RoundFloat(0.25f, 0), 7);
	AssertFloat(-1.0f, RoundFloat(-0.75f, 0), 7);
	AssertFloat(-1.0f, RoundFloat(-1.0f, 0), 7);
	AssertFloat(-1.0f, RoundFloat(-0.5f, 0), 7);
	AssertFloat(0.0f, RoundFloat(-0.25f, 0), 7);
	AssertFloat(2.0f, RoundFloat(2.9f, 1), 7);
	AssertFloat(2.0f, RoundFloat(1.0f, 1), 7);
}
Exemple #11
0
/** Constructor, based on Vector3f equivalent
*/
Vector2i::Vector2i(const Vector3f & base){
	x = (int) RoundFloat((base[0]));
	y = (int) RoundFloat((base[1]));
}
Exemple #12
0
void Loaders::t3DSLoader::ReadKeyFrameRotations(t3DModel *pModel, tChunk *pPreviousChunk)
{
    short frameNumber = 0, flags = 0, rotkeys = 0, ignored = 0;
    long lunknown = 0;
    float rotationDegree = 0;
    vector<int> vFrameNumber;
    vector<float> vRotDegree;
    vector<CVector3> vRotation;
    int i;

    pPreviousChunk->bytesRead += fread(&ignored, 1, sizeof(short), m_FilePointer);
    pPreviousChunk->bytesRead += fread(&ignored, 1, sizeof(short), m_FilePointer);
    pPreviousChunk->bytesRead += fread(&ignored, 1,  sizeof(short), m_FilePointer);
    pPreviousChunk->bytesRead += fread(&ignored, 1,  sizeof(short), m_FilePointer);
    pPreviousChunk->bytesRead += fread(&ignored, 1,  sizeof(short), m_FilePointer);

    pPreviousChunk->bytesRead += fread(&(m_CurrentObject->rotationFrames), 1, sizeof(short), m_FilePointer);

    pPreviousChunk->bytesRead += fread(&ignored, 1,  sizeof(short), m_FilePointer);

    for (i = 0; i < m_CurrentObject->rotationFrames; i++)
    {
        vRotation.push_back(CVector3());

        pPreviousChunk->bytesRead += fread(&frameNumber, 1, sizeof(short), m_FilePointer);

        vFrameNumber.push_back(frameNumber);

        pPreviousChunk->bytesRead += fread(&lunknown, 1, sizeof(long), m_FilePointer);

        pPreviousChunk->bytesRead += fread(&rotationDegree, 1, sizeof(float), m_FilePointer);

        rotationDegree = rotationDegree * (180.0f / 3.14159f);

        vRotDegree.push_back(rotationDegree);

        pPreviousChunk->bytesRead += fread(&(vRotation[i]), 1, sizeof(CVector3), m_FilePointer);

        vRotation[i].x = RoundFloat(vRotation[i].x);
        vRotation[i].y = RoundFloat(vRotation[i].y);
        vRotation[i].z = RoundFloat(vRotation[i].z);

        float temp = vRotation[i].y;
        vRotation[i].y = -vRotation[i].z;
        vRotation[i].z = temp;

        vRotation[i].x *= -1;
    }

    m_CurrentObject->vRotation.resize(m_CurrentObject->vRotation.size()+1);
    m_CurrentObject->vRotation[m_CurrentObject->vRotation.size()-1] = vRotation[0];

    m_CurrentObject->vRotDegree.resize(m_CurrentObject->vRotDegree.size()+1);
    m_CurrentObject->vRotDegree[m_CurrentObject->vRotDegree.size()-1] = vRotDegree[0];

    int currentKey = 1;

    for (i = 1; i <= (pModel->numberOfFrames + 1); i++)
    {
        m_CurrentObject->vRotation.resize(i + 1);
        m_CurrentObject->vRotDegree.resize(i + 1);

        if (currentKey < m_CurrentObject->rotationFrames)
        {
            int currentFrame = vFrameNumber[currentKey];
            int previousFrame = vFrameNumber[currentKey - 1];
            float degree = vRotDegree[currentKey];

            float rotDegree = degree / (currentFrame - previousFrame);

            m_CurrentObject->vRotation[i] = vRotation[currentKey];
            m_CurrentObject->vRotDegree[i] = rotDegree;

            if (vFrameNumber[currentKey] <= i)
                currentKey++;
        }
        else
        {
            m_CurrentObject->vRotation[i] = vRotation[currentKey - 1];
            m_CurrentObject->vRotDegree[i] = 0.0f;
        }
    }
}