void InputField::newInput(const QString & text)
{
    Quantity res;
    try{
        res = Quantity::parse(text);
    }catch(Base::Exception &e){
        ErrorText = e.what();
        this->setToolTip(QString::fromAscii(ErrorText.c_str()));
        QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height()));
        iconLabel->setPixmap(pixmap);
        parseError(QString::fromAscii(ErrorText.c_str()));
        return;
    }

    QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
    iconLabel->setPixmap(pixmap);

    ErrorText = "";
    this->setToolTip(QString::fromAscii(ErrorText.c_str()));
    actQuantity = res;
    double dFactor;
    res.getUserString(dFactor,actUnitStr);
    // calculate the number shown 
    actUnitValue = res.getValue()/dFactor; 
    // signaling 
    valueChanged(res);

}
Ejemplo n.º 2
0
void InputField::newInput(const QString & text)
{
    Quantity res;
    try{
        res = Quantity::parse(text);
    }catch(Base::Exception &e){
        ErrorText = e.what();
        this->setToolTip(QString::fromAscii(ErrorText.c_str()));
        QPalette palette;
        palette.setColor(QPalette::Base,QColor(255,200,200));
        setPalette(palette);
        parseError(QString::fromAscii(ErrorText.c_str()));
        return;
    }
    QPalette palette;
    palette.setColor(QPalette::Base,QColor(200,255,200));
    setPalette(palette);
    ErrorText = "";
    this->setToolTip(QString::fromAscii(ErrorText.c_str()));
    actQuantity = res;
    double dFactor;
    res.getUserString(dFactor,actUnitStr);
    // calculate the number shown 
    actUnitValue = res.getValue()/dFactor; 
    // signaling 
    valueChanged(res);

}
Ejemplo n.º 3
0
void QuantitySpinBox::updateText(const Quantity &quant)
{
    Q_D(QuantitySpinBox);

    double dFactor;
    QString txt = quant.getUserString(dFactor,d->unitStr);
    d->unitValue = quant.getValue()/dFactor;
    lineEdit()->setText(txt);
}
Ejemplo n.º 4
0
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
{
    if (PyString_Check(ArgObj)) {
        // Parse the string
        QString str = QString::fromLatin1(PyString_AsString(ArgObj));
        Quantity q = Quantity::parse(str);
        if (q.getUnit() == u)
            return q.getValue();
        throw Base::Exception("Wrong unit type!");
    }
    else if (PyFloat_Check(ArgObj)) {
        return PyFloat_AsDouble(ArgObj);
    }
    else if (PyInt_Check(ArgObj)) {
        return static_cast<double>(PyInt_AsLong(ArgObj));
    }
    else {
        throw Base::Exception("Wrong parameter type!");
    }
}
Ejemplo n.º 5
0
Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
{
    double d;
    if (PyString_Check(ArgObj)) {
        // Parse the string
        QString str = QString::fromLatin1(PyString_AsString(ArgObj));
        Quantity q = Quantity::parse(str);
        d = q.getValue();
    }
    else if (PyFloat_Check(ArgObj)) {
        d = PyFloat_AsDouble(ArgObj);
    }
    else if (PyInt_Check(ArgObj)) {
        d = static_cast<double>(PyInt_AsLong(ArgObj));
    }
    else {
        throw Base::Exception("Wrong parameter type!");
    }

    return Quantity(d,u);
}
Ejemplo n.º 6
0
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
{
#if PY_MAJOR_VERSION >= 3
    if (PyUnicode_Check(ArgObj)) {
        QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
#else
    if (PyString_Check(ArgObj)) {
        QString str = QString::fromLatin1(PyString_AsString(ArgObj));
#endif
        // Parse the string
        Quantity q = Quantity::parse(str);
        if (q.getUnit() == u)
            return q.getValue();
        throw Base::UnitsMismatchError("Wrong unit type!");
    }
    else if (PyFloat_Check(ArgObj)) {
        return PyFloat_AsDouble(ArgObj);
    }
#if PY_MAJOR_VERSION < 3
    else if (PyInt_Check(ArgObj)) {
        return static_cast<double>(PyInt_AsLong(ArgObj));
#else
    else if (PyLong_Check(ArgObj)) {
        return static_cast<double>(PyLong_AsLong(ArgObj));
#endif
    }
    else {
        throw Base::UnitsMismatchError("Wrong parameter type!");
    }
}

Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
{
    double d;
#if PY_MAJOR_VERSION >= 3
    if (PyUnicode_Check(ArgObj)) {
        QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
#else
    if (PyString_Check(ArgObj)) {
        QString str = QString::fromLatin1(PyString_AsString(ArgObj));
#endif
        // Parse the string
        Quantity q = Quantity::parse(str);
        d = q.getValue();
    }
    else if (PyFloat_Check(ArgObj)) {
        d = PyFloat_AsDouble(ArgObj);
    }
#if PY_MAJOR_VERSION < 3
    else if (PyInt_Check(ArgObj)) {
        d = static_cast<double>(PyInt_AsLong(ArgObj));
#else
    else if (PyLong_Check(ArgObj)) {
        d = static_cast<double>(PyLong_AsLong(ArgObj));
#endif
    }
    else {
        throw Base::UnitsMismatchError("Wrong parameter type!");
    }

    return Quantity(d,u);
}

void UnitsApi::setDecimals(int prec)
{
    UserPrefDecimals = prec;
}

int UnitsApi::getDecimals()
{
    return UserPrefDecimals;
}
Ejemplo n.º 7
0
double Quantity::getValueAs(const Quantity &q)const
{
    return _Value/q.getValue();
}
Ejemplo n.º 8
0
void Plotter2::fill(TTree *tree){
	TString path;
	path.Form("%s/second_pass",RDKANAL);
	Int_t multi_missmatch=0;
	Double_t avg_missmatch=0;
	Double_t bgo_scale=Double_t(windows[0][1]-windows[0][2])/
		Double_t(windows[0][3]-windows[0][0]+windows[0][1]-windows[0][2]);
	Double_t bapd_scale=Double_t(windows[1][1]-windows[1][2])/
		Double_t(windows[1][3]-windows[1][0]+windows[1][1]-windows[1][2]);
	Double_t binSize=E_e_chi2_max/E_e_chi2_bins;
	//TChain *tree=new TChain("rdk_second_pass");
	//FileStat_t stats;
	//TPRegexp regex("ss\\d+"),number("\\d+");
	//if(!gSystem->GetPathInfo(path,stats)){
	//	TSystemDirectory dir(".",path);
	//	TList *list=dir.GetListOfFiles();
	//	for(Int_t i=0;i<list->GetEntries();i++){
	//		TSystemFile *file=(TSystemFile*)list->At(i);
	//		TString fileName=file->GetName();
	//		if(file->IsDirectory() && fileName==fileName(regex)){
	//			Int_t n=TString(fileName(number)).Atoi();
	//			path.Form("%s/second_pass/ss%i/S%i.root",RDKANAL,n,n);
	//			if(n<400 && !gSystem->GetPathInfo(path,stats)){
	//				tree->AddFile(path);
	//			}
	//		}
	//	}
	//}
	epEvent epevent;
	tree->SetBranchAddress("epEvent",(Double_t*)&epevent);
	path.Form("%s/detector_config.csv",RDKANAL);
	RDKConfig config(path);
	//begin filling histograms
	Quantity ep;
	vector<UInt_t> modes(14);
	vector<Double_t> totalE(14),avgT(14),m(14);
	vector<Double_t> tempE(14),tempT(14),tempM(14);
	for(Int_t i=0;i<tree->GetEntries();i++){
		tree->GetEntry(i);
		UInt_t c=config.getConfig(epevent.nseries);
		Double_t tof=epevent.t_p-epevent.t_e;
		if(epFilter(epevent)){
			for(Int_t j=0;j<14;j++){
				modes[j]=RDKConfig::getMode(c,j);
				totalE[j]=0;
				avgT[j]=0;
			}
			sbd_E_e->Fill(epevent.E_e);
			sbd_E_p->Fill(epevent.E_p);
			sbd_tof->Fill(tof);
			Double_t q_tof=epevent.t_q-epevent.t_e;
			if(q_tof>tofmin && q_tof<tofmax){
				sbd_E_q->Fill(epevent.E_q);
				sbd_q_tof->Fill(epevent.t_q-epevent.t_e);
			}
			ep+=Quantity(1);
			//Chi2(E_e) and Chi2 vs E_e
			Int_t E_bin=TMath::Floor(epevent.E_e/binSize);
			getSbdChi2OfE(E_bin)->Fill(epevent.chi2_ep);
			sbdChi2vE->Fill(epevent.E_e,epevent.chi2_ep);
			if(MULTIPLICITY){
				for(Int_t j=0;j<14;j++){
					m[j]=0;
					totalE[j]=0;
					avgT[j]=0;
				}
				for(Int_t j=0;j<14;j++){
					Int_t grp=epevent.grp[j];
					if(modes[j]==BGO_MODE && grp>-1 && grp<14){
						m[grp]++;
						totalE[grp]+=epevent.E_gamma[j];
						avgT[grp]+=epevent.t_gamma[j];
					}
				}
				for(Int_t j=0;j<14;j++){
					Int_t grp=epevent.grp[j];
					if(modes[j]==BGO_MODE && epevent.grp[j]>-1 && epevent.grp[j]<14){
						epevent.E_gamma[j]=totalE[grp];
						epevent.t_gamma[j]=avgT[grp]/m[grp];
						if(m[grp]!=epevent.M[j]){
							multi_missmatch++;
							avg_missmatch+=epevent.M[j]-m[grp];
						}
					}
				}
			}
			for(Int_t j=0;j<14;j++){
				if(modes[j]==BGO_MODE){
					Int_t index=j-j/7;
					ep_bgo[index]+=Quantity(1,1);
					if(epevent.E_gamma[j]>min[0] && epevent.E_gamma[j]<max[0]){
						Double_t delta_t=epevent.t_gamma[j]-epevent.t_e;
						Double_t mScale=epevent.M[j]>0 && MULTIPLICITY?1.0/epevent.M[j]:1;
						getBgoDeltaT(index)->Fill(delta_t,mScale);
						if(delta_t>windows[0][1] && delta_t<=windows[0][2]){	//on peak
							getBgoOnPeak(index)->Fill(epevent.E_gamma[j],mScale);
							epg_ep_bgo[index]+=Quantity(1,1);
						}else if(delta_t>windows[0][0] && delta_t<=windows[0][3]){ //off peak
							getBgoOffPeak(index)->Fill(epevent.E_gamma[j],mScale);
							epg_ep_bgo[index]-=Quantity(bgo_scale,bgo_scale);
						}
					}
				}else if(modes[j]==BAPD_MODE){
					Int_t index=bapdIndex(modes[j],j);
					ep_bapd3[index]+=Quantity(1,1);
					if(epevent.E_gamma[j]>min[1] && epevent.E_gamma[j]<max[1]){
						Double_t delta_t=epevent.t_gamma[j]-epevent.t_e;
						getBapd3DeltaT(index)->Fill(delta_t);
						if(delta_t>windows[1][1] && delta_t<=windows[1][2]){
							getBapd3OnPeak(index)->Fill(epevent.E_gamma[j]);
							epg_ep_bapd3[index]+=Quantity(1,1);
						}else if(delta_t>windows[1][0] && delta_t<=windows[1][3]){
							getBapd3OffPeak(index)->Fill(epevent.E_gamma[j]);
							epg_ep_bapd3[index]-=Quantity(bapd_scale,bapd_scale);
						}
					}
				}else if(modes[j]==BAPD_PERP){
					//Int_t index=bapdIndex(modes[j],j);
					//ep_bapd4[index]+=Quantity(1,1);
					//if(epevent.E_gamma[j]>min[1] && epevent.E_gamma[j]<max[1]){
					//	Double_t delta_t=epevent.t_gamma[j]-epevent.t_e;
					//	getBapd4DeltaT(index)->Fill(delta_t);
					//	if(delta_t>windows[1][1] && delta_t<=windows[1][2]){
					//		getBapd4OnPeak(index)->Fill(epevent.E_gamma[j]);
					//		epg_ep_bapd4[index]+=Quantity(1,1);
					//	}else if(delta_t>windows[1][0] && delta_t<=windows[1][3]){
					//		getBapd4OffPeak(index)->Fill(epevent.E_gamma[j]);
					//		epg_ep_bapd4[index]-=Quantity(bapd_scale,bapd_scale);
					//	}
					//}
				}
			}
		}
	}
	if(multi_missmatch>0){
		avg_missmatch/=multi_missmatch;
		cout<<"Multiplicity missmatches: "<<multi_missmatch<<endl;
		cout<<"Average missmatch: "<<avg_missmatch<<endl;
	}
	Quantity ep_total=0;
	for(Int_t i=0;i<12;i++){
		ep_total+=ep_bgo[i];
		if(ep_bgo[i].getValue()>0){
			Double_t scale=EPSCALE?1/ep_bgo[i].getValue():1;
			getBgoOnPeak(i)->Scale(scale);
			getBgoOffPeak(i)->Scale(scale);
			getBgoDeltaT(i)->Scale(scale);
			getBgoFinal(i)->Add(getBgoOnPeak(i),getBgoOffPeak(i),1,bgo_scale);
		}
	}
	for(Int_t i=0;i<12;i++){
		getBgoOnPeak(12)->Add(getBgoOnPeak(i),(ep_bgo[i]/ep_total).getValue());
		getBgoOffPeak(12)->Add(getBgoOffPeak(i),(ep_bgo[i]/ep_total).getValue());
		getBgoDeltaT(12)->Add(getBgoDeltaT(i),(ep_bgo[i]/ep_total).getValue());
		epg_ep_bgo[12]+=epg_ep_bgo[i];
		epg_ep_bgo[i]/=ep_bgo[i];
	}
	epg_ep_bgo[12]/=ep_total;
	getBgoFinal(12)->Add(getBgoOnPeak(12),getBgoOffPeak(12),1,bgo_scale);
	getBgoFinal(12)->Scale(12);
	ep_total=0;
	for(Int_t i=0;i<3;i++){
		ep_total+=ep_bapd3[i];
		Double_t scale=EPSCALE?1/ep_bapd3[i].getValue():1;
		getBapd3OnPeak(i)->Scale(scale);
		getBapd3OffPeak(i)->Scale(scale);
		getBapd3DeltaT(i)->Scale(scale);
		getBapd3Final(i)->Add(getBapd3OnPeak(i),getBapd3OffPeak(i),1,bapd_scale);
	}
	for(Int_t i=0;i<3;i++){
		Double_t scale=(ep_bapd3[i]/ep_total).getValue();	//Weighted sum
		//Double_t scale=1;	//Non weighted sum
		getBapd3OnPeak(3)->Add(getBapd3OnPeak(i),scale);
		getBapd3OffPeak(3)->Add(getBapd3OffPeak(i),scale);
		getBapd3DeltaT(3)->Add(getBapd3DeltaT(i),scale);
		epg_ep_bapd3[3]+=epg_ep_bapd3[i];
		epg_ep_bapd3[i]/=ep_bapd3[i];
	}
	epg_ep_bapd3[3]/=ep_total;
	getBapd3Final(3)->Add(getBapd3OnPeak(3),getBapd3OffPeak(3),1,bapd_scale);
	getBapd3Final(3)->Scale(3);
	ep_total=0;
	for(Int_t i=0;i<4;i++){
		ep_total+=ep_bapd4[i];
		Double_t scale=EPSCALE?1/ep_bapd4[i].getValue():1;
		getBapd4OnPeak(i)->Scale(scale);
		getBapd4OffPeak(i)->Scale(scale);
		getBapd4Final(i)->Add(getBapd4OnPeak(i),getBapd4OffPeak(i),1,bapd_scale);
	}
	for(Int_t i=0;i<4;i++){
		getBapd4OnPeak(4)->Add(getBapd4OnPeak(i),(ep_bapd4[i]/ep_total).getValue());
		getBapd4OffPeak(4)->Add(getBapd4OffPeak(i),(ep_bapd4[i]/ep_total).getValue());
		getBapd4DeltaT(4)->Add(getBapd4DeltaT(i),(ep_bapd4[i]/ep_total).getValue());
		epg_ep_bapd4[4]+=epg_ep_bapd4[i];
		epg_ep_bapd4[i]/=ep_bapd4[i];
	}
	epg_ep_bapd4[4]/=ep_total;
	getBapd4Final(4)->Add(getBapd4OnPeak(4),getBapd4OffPeak(4),1,bapd_scale);
	getBapd4Final(4)->Scale(4);
	Double_t scale=EPSCALE?1/ep.getValue():1;
	sbd_E_e->Scale(scale);
	sbd_E_p->Scale(scale);
	sbd_tof->Scale(scale);
	sbd_E_q->Scale(scale);
	sbd_q_tof->Scale(scale);
}
QString UnitsSchemaImperial1::schemaTranslate(const Quantity &quant, double &factor, QString &unitString)
{
    double UnitValue = std::abs(quant.getValue());
    Unit unit = quant.getUnit();
    // for imperial user/programmer mind; UnitValue is in internal system, that means
    // mm/kg/s. And all combined units have to be calculated from there!

    // now do special treatment on all cases seems necessary:
    if (unit == Unit::Length) {  // Length handling ============================
        if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation
            unitString = QString::fromLatin1("in");
            factor = 25.4;
        }
        else if(UnitValue < 2.54) { // smaller then 0.1 inch -> Thou (mil)
            unitString = QString::fromLatin1("thou");
            factor = 0.0254;
        }
        else if(UnitValue < 304.8) {
            unitString = QString::fromLatin1("\"");
            factor = 25.4;
        }
        else if(UnitValue < 914.4) {
            unitString = QString::fromLatin1("\'");
            factor = 304.8;
        }
        else if(UnitValue < 1609344.0) {
            unitString = QString::fromLatin1("yd");
            factor = 914.4;
        }
        else if(UnitValue < 1609344000.0) {
            unitString = QString::fromLatin1("mi");
            factor = 1609344.0;
        }
        else { // bigger then 1000 mi -> scientific notation
            unitString = QString::fromLatin1("in");
            factor = 25.4;
        }
    }
    else if (unit == Unit::Area) {
        // TODO Cascade for the Areas
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("in^2");
        factor = 645.16;
    }
    else if (unit == Unit::Volume) {
        // TODO Cascade for the Volume
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("in^3");
        factor = 16387.064;
    }
    else if (unit == Unit::Mass) {
        // TODO Cascade for the weights
        // default action for all cases without special treatment:
        unitString = QString::fromLatin1("lb");
        factor = 0.45359237;
    }
    else if (unit == Unit::Pressure) {
        if (UnitValue < 6894.744) {// psi is the smallest
            unitString = QString::fromLatin1("psi");
            factor = 6.894744825494;
        }
        else if (UnitValue < 6894744.825) {
            unitString = QString::fromLatin1("ksi");
            factor = 6894.744825494;
        }
        else { // bigger then 1000 ksi -> psi + scientific notation
            unitString = QString::fromLatin1("psi");
            factor = 6.894744825494;
        }
    }
    else if (unit == Unit::Velocity) {
        unitString = QString::fromLatin1("in/min");
        factor = 25.4/60;
    }
    else {
        // default action for all cases without special treatment:
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }

    return toLocale(quant, factor, unitString);
}
QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, double &factor, QString &unitString)
{
    // this schema expresses distances in feet + inches + fractions
    // ex: 3'- 4 1/4" with proper rounding
    Unit unit = quant.getUnit();
    if (unit == Unit::Length) {
        unitString = QString::fromLatin1("in");
        factor = 25.4;

        // Total number of inches to format
        double totalInches = std::abs(quant.getValue())/factor;

        // minimum denominator (8 for 1/8, 16 for 1/16, etc)
        int       minden;

        // Outputs
        int       feet;    // whole feet
        int       inches;  // whole inches
        int       num,den; // numerator and denominator of fractional val
        std::stringstream output; // output stream

        // Intermediate values
        int       ntot;    // total fractional units
        int       a,b,d;   // used to compute greatest common denominator
        int       tmp;     // temporary variable for GCD

        // Get the current user specified minimum denominator
        minden = quant.getFormat().getDenominator();

        // Compute and round the total number of fractional units
        ntot = (int)std::round(totalInches * (double)minden);

        // If this is zero, nothing to do but return
        if( ntot==0 )
            return QString::fromLatin1("0");

        // Compute the whole number of feet and remaining units
        feet = (int)std::floor(ntot / (12*minden));
        ntot = ntot - 12*minden*feet;

        // Compute the remaining number of whole inches
        inches = (int)std::floor(ntot/minden);

        // Lastly the fractional quantities
        num = ntot - inches*minden;
        den = minden;

        // If numerator is not zero, compute greatest common divisor and reduce
        // fraction
        if( num!=0 )
        {
            // initialize
            a = num;
            b = den;
            while (b != 0)
            {
                tmp = a % b;

                a = b;
                b = tmp;
            }
            d = a;

            num /= d;
            den /= d;
        }

        // Process into string. Start with negative sign if quantity is less
        // than zero
        if( quant.getValue() < 0 )
            output << "-";

        // Print feet if we have any
        if( feet!=0 )
        {
            output << feet << "'";

            // if there is to be trailing numbers, add space
            if( inches!=0 || num!=0 )
            {
                output << " ";
            }
        }

        // Three cases:
        //   1. Whole inches, no fraction
        //   2. Whole inches, fraction
        //   3. Fraction only
        if( inches>0 && num==0 ) // case 1.
        {
            output << inches << "\"";
        }
        else if( inches>0 && num!=0 ) // case 2
        {
            output << inches << "+" << num << "/" << den << "\"";
        }
        else if( inches==0 && num!=0 ) // case 3
        {
            output << num << "/" << den << "\"";
        }

        // Done!
        return QString::fromLatin1(output.str().c_str());
    }
    else if (unit == Unit::Area) {
        unitString = QString::fromLatin1("sqft");
        factor = 92903.04;
    }
    else if (unit == Unit::Volume) {
        unitString = QString::fromLatin1("cuft");
        factor = 28316846.592;
    }
    else if (unit == Unit::Velocity) {
        unitString = QString::fromLatin1("in/min");
        factor = 25.4/60;
    }
    else {
        unitString = quant.getUnit().getString();
        factor = 1.0;
    }

    return toLocale(quant, factor, unitString);
}