void Parameters::initialParameters() { QFile parameterFile("Parameters.xml"); if(parameterFile.exists()) { QDomDocument domDocument; if(!parameterFile.open(QFile::ReadOnly)) { qDebug()<<QObject::tr("打开参数文件进行读取失败!"); goto initial; } if(!domDocument.setContent(¶meterFile)) { qDebug()<<QObject::tr("解析参数文件失败!"); goto initial; } QDomElement rootElement = domDocument.firstChildElement(); dayStartTime = QTime::fromString(rootElement.attribute("DayStartTime"), "hh:mm"); dayEndTime = QTime::fromString( rootElement.attribute("DayEndTime"),"hh:mm"); dayVolume = rootElement.attribute("DayVolume").toInt(); nightStartTime = QTime::fromString(rootElement.attribute("NightStartTime"), "hh:mm"); nightEndTime = QTime::fromString(rootElement.attribute("NightEndTime"), "hh:mm"); nightVolume = rootElement.attribute("NightVolume").toInt(); checkClientOnlineSecond = rootElement.attribute("CheckClientOnlineSecond").toULong(); transferExistsFileHandleCode = rootElement.attribute("TransferExistsFileHandleCode").toInt(); playListFileTransferMode = rootElement.attribute("PlayListFileTransferMode").toInt(); comPort = rootElement.attribute("ComPort"); //phoneNo = rootElement.attribute("PhoneNo"); isCheckSMSModem = rootElement.attribute("isCheckSMSModem").toInt(); } else { initial: dayStartTime.setHMS(0,0,0,0); dayEndTime.setHMS(18,0,0,0); dayVolume = 100; nightStartTime.setHMS(18,0,0,0); nightEndTime.setHMS(23,59,59,0); nightVolume = 70; checkClientOnlineSecond = 60; transferExistsFileHandleCode = 3; playListFileTransferMode = 0; comPort = "COM3"; isCheckSMSModem = false; //phoneNo = ""; } }
void MainWindow::on_loadParametersPushButton_clicked() { QString filename = QFileDialog::getOpenFileName(NULL, "Wybierz plik"); qDebug() << "Wybrano plik: " << filename; QFile parameterFile(filename); if ( ! parameterFile.open(QFile::ReadOnly) ) { QMessageBox::information(NULL, "Błąd pliku", "Otwieranie pliku nie powiodło się", QMessageBox::Ok); return; } QTextStream parameters(¶meterFile); while ( ! parameters.atEnd() ) { QString inputFileName; QString outputFileName; double alpha; int minNumberOfBusStopsInRegion; int maxNumberOfBusStopsInRegion; int minBuslineLength; int maxBuslineLength; int numberOfReplacementBusstops; long numberOfIterations; double lambda; parameters >> inputFileName; if ( inputFileName == "#" ) { // comment was present parameters.readLine(); continue; } parameters >> outputFileName; parameters >> alpha; parameters >> minNumberOfBusStopsInRegion; parameters >> maxNumberOfBusStopsInRegion; parameters >> minBuslineLength; parameters >> maxBuslineLength; parameters >> numberOfReplacementBusstops; parameters >> numberOfIterations; parameters >> lambda; Parameters::setAlpha(alpha); Parameters::setMinNumberOfBusStopsInRegion(minNumberOfBusStopsInRegion); Parameters::setMaxNumberOfBusStopsInRegion(maxNumberOfBusStopsInRegion); Parameters::setMinNumberOfBusStopsInBusline(minBuslineLength); Parameters::setMaxNumberOfBusStopsInBusLine(maxBuslineLength); Parameters::setNumberOfReplacementBusStops(numberOfReplacementBusstops); ui->alpha_lineedit->setText(QString::number(alpha)); ui->minbusstopsinregion->setText(QString::number(minNumberOfBusStopsInRegion)); ui->maxbusstopsinregion->setText(QString::number(maxNumberOfBusStopsInRegion)); ui->minlinelength->setText(QString::number(minBuslineLength)); ui->maxlinelength->setText(QString::number(maxBuslineLength)); ui->numofiterations->setText(QString::number(numberOfIterations)); } }
// --- Parameterization ---------------------------------------------------- // bool MmffForceField::setup() { if(!m_parameters || m_parameters->fileName() != parameterFile()){ m_parameters = new MmffParameters; bool ok = m_parameters->read(parameterFile()); if(!ok){ setErrorString("Failed to load parameters: " + m_parameters->errorString()); delete m_parameters; m_parameters = 0; return false; } } const boost::shared_ptr<chemkit::Topology> &topology = this->topology(); if(!topology){ return false; } // bond strech calculations foreach(const chemkit::Topology::BondedInteraction &interaction, topology->bondedInteractions()){ size_t a = interaction[0]; size_t b = interaction[1]; addCalculation(new MmffBondStrechCalculation(a, b)); } // angle bend and strech bend calculations foreach(const chemkit::Topology::AngleInteraction &interaction, topology->angleInteractions()){ size_t a = interaction[0]; size_t b = interaction[1]; size_t c = interaction[2]; addCalculation(new MmffAngleBendCalculation(a, b, c)); addCalculation(new MmffStrechBendCalculation(a, b, c)); } // out of plane bending calculation (for each trigonal center) foreach(const chemkit::Topology::ImproperTorsionInteraction &interaction, topology->improperTorsionInteractions()){ size_t a = interaction[0]; size_t b = interaction[1]; size_t c = interaction[2]; size_t d = interaction[3]; addCalculation(new MmffOutOfPlaneBendingCalculation(a, b, c, d)); addCalculation(new MmffOutOfPlaneBendingCalculation(a, b, d, c)); addCalculation(new MmffOutOfPlaneBendingCalculation(c, b, d, a)); } // torsion calculations (for each dihedral) foreach(const chemkit::Topology::TorsionInteraction &interaction, topology->torsionInteractions()){ size_t a = interaction[0]; size_t b = interaction[1]; size_t c = interaction[2]; size_t d = interaction[3]; addCalculation(new MmffTorsionCalculation(a, b, c, d)); } // van der waals and electrostatic calculations foreach(const chemkit::Topology::NonbondedInteraction &interaction, topology->nonbondedInteractions()){ size_t a = interaction[0]; size_t b = interaction[1]; addCalculation(new MmffVanDerWaalsCalculation(a, b)); addCalculation(new MmffElectrostaticCalculation(a, b)); } bool ok = true; foreach(chemkit::ForceFieldCalculation *calculation, calculations()){ bool setup = static_cast<MmffCalculation *>(calculation)->setup(m_parameters); if(!setup){ ok = false; } setCalculationSetup(calculation, setup); }
int main(int argc, char** argv) { if(argc!=2) { std::cout<<"Usage: regression.exe configurationFile\n"; return 1; } std::string parameterFile(argv[1]); RegressionManager manager; bool status = true; status = manager.init(parameterFile); if(status) { manager.makeRegression(); } if(!status) std::cout<<"FATAL: A fatal error occured - QUIT -\n"; else std::cout<<"- Finish - All good -\n"; /* TFile *file = new TFile("GBR_Clustering_70pre11_Photons_EG_results.root","READ"); const std::vector<std::string> *varlist = (std::vector<std::string>*)file->Get("varlistEB"); const GBRForest *forest = (GBRForest*)file->Get("EBCorrection"); int numvars = varlist->size(); int numtrees = forest->Trees().size(); printf("liste des variables \n"); for (int ivar = 0; ivar<numvars; ++ivar) { printf("%i: %s\n",ivar, varlist->at(ivar).c_str()); } printf("nombre de trees : %i \n",numtrees); TTree *dtree; TFile *fdin = TFile::Open("~/eos/cms/store/group/phys_egamma/lgray/PhotonRegressionTrees_23012014_v2-runPhotonRegressionTrees_cfg/runPhotonRegressionTrees_cfg-step4_RECO_EI-0006AD69-4A69-E211-922D-002354EF3BE4.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("egSCTree"); dtree = (TTree*)ddir->Get("SuperClusterTree"); float* Input; Input = new float[numvars]; dtree->SetBranchAddress("scEta",&Input[0]); dtree->SetBranchAddress("scPhi",&Input[1]); dtree->SetBranchAddress("scEtaWidth",&Input[2]); dtree->SetBranchAddress("scPhiWidth",&Input[3]); double Output; for (int i=0;i<100;i++){ dtree->GetEntry(i); //printf(" eta =%f phi =%f etawidth = %f phiwidth = %f \n",scEta,scPhi, scEtaWidth, scPhiWidth); //Input[0]=scEta; //Input[1]=scPhi; //Input[2]=scEtaWidth; //Input[3]=scPhiWidth; Output=forest->GetResponse(Input); printf("Ecor/Eraw = %f \n",Output); } */ RegressionTest test; test.init("GBR_Clustering_70pre11_Photons_EG_results.root","~/eos/cms/store/group/phys_egamma/lgray/PhotonRegressionTrees_23012014_v2-runPhotonRegressionTrees_cfg/runPhotonRegressionTrees_cfg-step4_RECO_EI-FA47A89F-906A-E211-9ABF-003048FFCBB0.root","egSCTree","SuperClusterTree"); test.PlotResponse(); return status; }
FrameSource::IntrinsicParameters CameraV2::getIntrinsicParameters(void) { /* Assemble the name of the intrinsic parameter file: */ std::string intrinsicParameterFileName=KINECT_INTERNAL_CONFIG_CONFIGDIR; intrinsicParameterFileName.push_back('/'); intrinsicParameterFileName.append(KINECT_INTERNAL_CONFIG_CAMERA_INTRINSICPARAMETERSFILENAMEPREFIX); intrinsicParameterFileName.push_back('-'); intrinsicParameterFileName.append(serialNumber); intrinsicParameterFileName.append(".dat"); /* Check if a file of the given name exists and is readable: */ IntrinsicParameters result; if(IO::Directory::getCurrent()->getPathType(intrinsicParameterFileName.c_str())==Misc::PATHTYPE_FILE) { try { /* Open the parameter file: */ IO::FilePtr parameterFile(IO::Directory::getCurrent()->openFile(intrinsicParameterFileName.c_str())); parameterFile->setEndianness(Misc::LittleEndian); /* Read lens distortion correction parameters: */ Misc::Float64 depthLensDistortionParameters[5]; parameterFile->read(depthLensDistortionParameters,5); for(int i=0;i<3;++i) result.depthLensDistortion.setKappa(i,depthLensDistortionParameters[i]); for(int i=0;i<2;++i) result.depthLensDistortion.setRho(i,depthLensDistortionParameters[3+i]); /* Read the depth unprojection matrix: */ Misc::Float64 depthMatrix[16]; parameterFile->read(depthMatrix,4*4); result.depthProjection=IntrinsicParameters::PTransform::fromRowMajor(depthMatrix); /* Read the color projection matrix: */ Misc::Float64 colorMatrix[16]; parameterFile->read(colorMatrix,4*4); result.colorProjection=IntrinsicParameters::PTransform::fromRowMajor(colorMatrix); } catch(std::runtime_error err) { /* Log an error: */ Misc::formattedConsoleError("Kinect::CameraV2::getIntrinsicParameters: Could not load intrinsic parameter file %s due to exception %s",intrinsicParameterFileName.c_str(),err.what()); } } else { /* Get depth camera parameters from command dispatcher: */ const KinectV2CommandDispatcher::DepthCameraParams& dcp=commandDispatcher->getDepthCameraParams(); /* Initialize the lens distortion correction formula: */ result.depthLensDistortion.setKappa(0,dcp.k1); result.depthLensDistortion.setKappa(1,dcp.k2); result.depthLensDistortion.setKappa(2,dcp.k3); result.depthLensDistortion.setRho(0,dcp.p1); result.depthLensDistortion.setRho(1,dcp.p2); /* Initialize the depth unprojection matrix: */ FrameSource::IntrinsicParameters::PTransform::Matrix& dum=result.depthProjection.getMatrix(); dum=FrameSource::IntrinsicParameters::PTransform::Matrix::zero; dum(0,0)=-1.0/dcp.sx; dum(0,3)=dcp.cx/dcp.sx; dum(1,1)=1.0/dcp.sy; dum(1,3)=-dcp.cy/dcp.sy; dum(2,3)=-1.0; dum(3,2)=-1.0/depthStreamReader->getA(); dum(3,3)=depthStreamReader->getB()/depthStreamReader->getA(); /* Scale the depth unprojection matrix to cm: */ result.depthProjection.leftMultiply(FrameSource::IntrinsicParameters::PTransform::scale(0.1)); /* Initialize the color projection matrix: */ result.colorProjection=FrameSource::IntrinsicParameters::PTransform::identity; #if 1 // Evil temporary hack IO::FilePtr colorMatrixFile=IO::Directory::getCurrent()->openFile("/home/okreylos/Projects/Kinect/ColorMatrix.dat"); colorMatrixFile->setEndianness(Misc::LittleEndian); double colorMatrix[16]; colorMatrixFile->read(colorMatrix,16); #if 0 for(int i=0;i<4;++i) colorMatrix[i]=(colorMatrix[i+12]-colorMatrix[i])*1920.0; for(int i=4;i<8;++i) colorMatrix[i]*=1080.0; #endif for(int i=4;i<8;++i) colorMatrix[i]=(colorMatrix[i+8]-colorMatrix[i]); result.colorProjection=FrameSource::IntrinsicParameters::PTransform::fromRowMajor(colorMatrix); result.colorProjection*=result.depthProjection; /* Write the constructed calibration data to a calibration data file: */ std::cout<<"Writing intrinsic calibration parameters to file "<<intrinsicParameterFileName<<std::endl; IO::FilePtr parameterFile(IO::Directory::getCurrent()->openFile(intrinsicParameterFileName.c_str(),IO::File::WriteOnly)); parameterFile->setEndianness(Misc::LittleEndian); /* Write lens distortion correction parameters: */ for(int i=0;i<3;++i) parameterFile->write<Misc::Float64>(result.depthLensDistortion.getKappa(i)); for(int i=0;i<2;++i) parameterFile->write<Misc::Float64>(result.depthLensDistortion.getRho(i)); /* Write the depth unprojection matrix: */ for(int i=0;i<4;++i) for(int j=0;j<4;++j) parameterFile->write<Misc::Float64>(result.depthProjection.getMatrix()(i,j)); /* Write the color projection matrix: */ for(int i=0;i<4;++i) for(int j=0;j<4;++j) parameterFile->write<Misc::Float64>(result.colorProjection.getMatrix()(i,j)); #endif } return result; }