void ParameterList::Append(const ParameterList& addList) { for(int i=0; i<addList.GetNBool(); i++ ) AddParameter(addList.GetBoolParameter(i)); for(int i=0; i<addList.GetNInteger(); i++ ) AddParameter(addList.GetIntegerParameter(i)); for(int i=0; i<addList.GetNDouble(); i++ ) AddParameter(addList.GetDoubleParameter(i)); for(int i=0; i<addList.GetNComplex(); i++ ) AddParameter(addList.GetComplexParameter(i)); for(int i=0; i<addList.GetNMultiDouble(); i++ ) AddParameter(addList.GetMultiDouble(i)); for(int i=0; i<addList.GetNMultiComplex(); i++ ) AddParameter(addList.GetMultiComplex(i)); for(int i=0; i<addList.GetNMultiUnsignedInteger(); i++ ) AddParameter(addList.GetMultiUnsignedInteger(i)); }
void ParameterList::DeepCopy(const ParameterList& in) { out_=in.out_; vMultiComplex_.clear(); vMultiDouble_.clear(); vDouble_.clear(); vInt_.clear(); vBool_.clear(); for(unsigned int i=0; i<in.GetNMultiComplex();i++) vMultiComplex_.push_back( std::shared_ptr<MultiComplex>( new MultiComplex(*(in.vMultiComplex_[i])) ) ); for(unsigned int i=0; i<in.GetNMultiDouble();i++) vMultiDouble_.push_back( std::shared_ptr<MultiDouble>( new MultiDouble(*(in.vMultiDouble_[i])) ) ); for(unsigned int i=0; i<in.GetNDouble();i++) vDouble_.push_back( std::shared_ptr<DoubleParameter>( new DoubleParameter(*(in.vDouble_[i])) ) ); for (unsigned int i = 0; i < in.GetNMultiUnsignedInteger(); i++) vMultiUnsignedInteger_.push_back( std::shared_ptr<MultiUnsignedInteger>( new MultiUnsignedInteger(*(in.vMultiUnsignedInteger_[i])) ) ); for(unsigned int i=0; i<in.GetNInteger();i++) vInt_.push_back( std::shared_ptr<IntegerParameter>( new IntegerParameter(*(in.vInt_[i])) ) ); for(unsigned int i=0; i<in.GetNBool();i++) vBool_.push_back( std::shared_ptr<BoolParameter>( new BoolParameter(*(in.vBool_[i])) ) ); }
std::shared_ptr<FitResult> GenevaIF::exec(ParameterList& par) { std::shared_ptr<GenevaResult> result(new GenevaResult()); ParameterList initialParList(par); Go2 go( (configFileDir+"Go2.json")); // Initialize a client, if requested if(go.clientMode()) { std::cout << "Geneva Client waiting for action!" << std::endl; go.clientRun(); return result; } boost::shared_ptr<GStartIndividual> p( new GStartIndividual(_myData, par) ); go.push_back(p); // Add an evolutionary algorithm to the Go2 class. GEvolutionaryAlgorithmFactory ea((configFileDir+"GEvolutionaryAlgorithm.json"), parallelizationMode); go & ea(); // Perform the actual optimization boost::shared_ptr<GStartIndividual> bestIndividual_ptr = go.optimize<GStartIndividual>(); // Terminate bestIndividual_ptr->getPar(par); result->setResult(bestIndividual_ptr); result->SetAmplitude(_myData->getAmplitudes().at(0)); result->setInitialParameters(initialParList); result->setFinalParameters(par); //int whattodowiththisidontknow = go.finalize(); //Go2::finalize(); //write Parameters back ParameterList resultPar; bestIndividual_ptr->getPar(resultPar); for(unsigned int i=0; i<par.GetNDouble(); i++){ //TODO: better way, no cast or check type if(!par.GetDoubleParameter(i)->IsFixed()) par.GetDoubleParameter(i)->SetValue(resultPar.GetDoubleParameter(i)->GetValue()); } return result; }
/** * The main function. */ int main(int argc, char **argv) { int seed = 1234; string output_filename("JakeFitResult.root"); string output_directory("./executables/DalitzFit/"); string input_filename("JPSIPSMC.ACC.root"); string input_directory("./executables/DalitzFit/"); string output_file_suffix(""); if (argc > 1) output_directory = argv[1]; if (argc > 2) output_filename = argv[2]; if (argc > 3) input_directory = argv[3]; if (argc > 4) input_filename = argv[4]; if (argc > 5) seed = atoi(argv[5]); if (argc > 6) output_file_suffix = argv[6]; // create correct output file name boost::filesystem::path input_file(input_filename); string input_file_path = input_directory + "/" + input_filename; if (output_file_suffix != "") input_file_path = input_directory + "/" + input_file.stem().string() + "_" + output_file_suffix + input_file.extension().string(); Logging log("log", boost::log::trivial::debug); //initialize logging BOOST_LOG_TRIVIAL(info)<< " ComPWA Copyright (C) 2013 Mathias Michel "; BOOST_LOG_TRIVIAL(info)<< " This program comes with ABSOLUTELY NO WARRANTY; for details see license.txt"; BOOST_LOG_TRIVIAL(info)<< std::endl; DalitzKinematics* kin = dynamic_cast<DalitzKinematics*>(DalitzKinematics::createInstance( "jpsi", "gamma", "pi0", "pi0")); //DPKinematics kin("J/psi","gamma","pi0","pi0"); //DPKinematics kin("D0","gamma","K-","K+"); //static dataPoint* point = dataPoint::instance(kin); bool useFctTree = false, resultGen = true; const char* pPath = getenv("COMPWA_DIR"); std::string path = ""; try { path = std::string(pPath); } catch (std::logic_error& ex) { BOOST_LOG_TRIVIAL(error)<<"Environment Variable COMPWA_DIR not set?"<<std::endl; } std::string resoFile = path + "/executables/DalitzFit/Jake_ypipi.xml"; boost::property_tree::ptree pt; read_xml(resoFile, pt, boost::property_tree::xml_parser::trim_whitespace); auto fitAmpPtr = new AmpSumIntensity("amp",normStyle::none, std::shared_ptr<Efficiency>(new UnitEfficiency()), nFitEvents); fitAmpPtr->Configure(pt); std::shared_ptr<Amplitude> amps( fitAmpPtr ); BOOST_LOG_TRIVIAL(info)<< "Load Modules"; std::string file = "executables/DalitzFit/JPSIDATA.ACC.root"; std::shared_ptr<JakeReader> myReader( new JakeReader(file, "kin")); //std::shared_ptr<RootReader> myReader( //new RootReader(input_file_path, "data")); myReader->resetWeights(); //setting weights to 1 std::shared_ptr<JakeReader> myPHSPReader( new JakeReader(input_file_path, "kin")); myPHSPReader->setEfficiency(shared_ptr<Efficiency>(new UnitEfficiency())); //setting efficiency to 1 //std::shared_ptr<Amplitude> amps(new AmpSumIntensity(M, Br, m1, m2, m3,"J/psi","gamma","pi0","pi0", ini)); // Initiate parameters ParameterList par; std::shared_ptr<Optimizer::ControlParameter> esti; amps->FillParameterList(par); //perfect startvalues esti = MinLogLH::createInstance(amps, myReader, myPHSPReader, nStartEvent, nFitEvents); MinLogLH* contrPar = dynamic_cast<MinLogLH*>(&*(esti->Instance())); std::shared_ptr<FunctionTree> tree; if (useFctTree) { contrPar->setUseFunctionTree(1); tree = contrPar->getTree(); } // if(useFctTree){//using tree? // esti = MinLogLH::createInstance(amps, myReader, myPHSPReader, nStartEvent, nFitEvents); // }else{ // BOOST_LOG_TRIVIAL(debug)<<"allMasses: try to get MassContainer..."; // allMasses myEvtMasses(myReader->getMasses(nStartEvent,nFitEvents)); // allMasses myPhspMasses(myPHSPReader->getMasses(nStartEvent,nFitEvents)); // BOOST_LOG_TRIVIAL(debug)<<"EvtMasses: "<< myEvtMasses.nEvents <<" events and "<< myEvtMasses.nInvMasses <<" inv masses"; // BOOST_LOG_TRIVIAL(debug)<<"PHSPMasses: "<< myPhspMasses.nEvents <<" events and "<< myPhspMasses.nInvMasses <<" inv masses"; //// physicsTree = amps->functionTree(myPhspMasses,myEvtMasses); // allMasses emptyMasses; //// amps->iniFunctionTree(myEvtMasses,myPhspMasses,emptyMasses); //// physicsTree = amps->getPhysicsTree(); // if(!physicsTree){ // BOOST_LOG_TRIVIAL(error)<<"Physics Trees not setup correctly, quitting"; // return 0; // } //// phspTree = amps->getPhspTree(); // if(!phspTree){ // BOOST_LOG_TRIVIAL(error)<<"Phsp Trees not setup correctly, quitting"; // return 0; // } // // BOOST_LOG_TRIVIAL(debug)<<"Check Trees: "; // if(!physicsTree->sanityCheck()) return 0; // if(!phspTree->sanityCheck()) return 0; // //BOOST_LOG_TRIVIAL(info)<<physicsTree<<std::endl; // //BOOST_LOG_TRIVIAL(info)<<phspTree<<std::endl; // physicsTree->recalculate(); // phspTree->recalculate(); // BOOST_LOG_TRIVIAL(debug)<<physicsTree<<std::endl; // BOOST_LOG_TRIVIAL(debug)<<phspTree<<std::endl; // BOOST_LOG_TRIVIAL(debug)<<"Evt Tree: "<<(std::dynamic_pointer_cast<DoubleParameter>(physicsTree->head()->getValue()))->GetValue(); // BOOST_LOG_TRIVIAL(debug)<<"Phsp Tree: "<<(std::dynamic_pointer_cast<DoubleParameter>(phspTree->head()->getValue()))->GetValue(); // BOOST_LOG_TRIVIAL(info)<<"Trees are set up"<<std::endl; // // esti = MinLogLH::createInstance(physicsTree, phspTree, myEvtMasses.nEvents); // dataPoint myPoint(myReader->getEvent(0)); // std::shared_ptr<TreeNode> LogNode = (physicsTree->head()->getChildren())[0]; // std::shared_ptr<TreeNode> IntNode = (LogNode->getChildren())[0]; // std::shared_ptr<TreeNode> AmpNodeEff = (IntNode->getChildren())[0]; // std::shared_ptr<TreeNode> AmpNode = (AmpNodeEff->getChildren())[1]; // std::shared_ptr<TreeNode> ResNode = (AmpNode->getChildren())[0]; // std::shared_ptr<TreeNode> BWNode = (ResNode->getChildren())[0]; // std::shared_ptr<TreeNode> ADNode = (ResNode->getChildren())[2]; // // std::shared_ptr<MultiComplex> resoChild = std::dynamic_pointer_cast<MultiComplex>( ResNode->getValue() ); // std::shared_ptr<MultiDouble> intensChild = std::dynamic_pointer_cast<MultiDouble>( IntNode->getValue() ); // std::shared_ptr<MultiComplex> bwChild = std::dynamic_pointer_cast<MultiComplex>( BWNode->getValue() ); // std::shared_ptr<MultiDouble> adChild = std::dynamic_pointer_cast<MultiDouble>( ADNode->getValue() ); // std::shared_ptr<MultiComplex> ampChild = std::dynamic_pointer_cast<MultiComplex>( AmpNode->getValue() ); // // BOOST_LOG_TRIVIAL(debug) << "InvMasses first Evt from dataPoint: \t" << myPoint.getVal("m23sq") << " \t " << myPoint.getVal("m13sq"); // BOOST_LOG_TRIVIAL(debug) << "InvMasses first Evt from allMasses: \t" << (myEvtMasses.masses_sq[std::make_pair(2,3)])[0] << " \t " << (myEvtMasses.masses_sq[std::make_pair(1,3)])[0]; // // BOOST_LOG_TRIVIAL(debug) << "First BW first Evt classical: \t" << (amps->getFirstBW(myPoint,par)); // BOOST_LOG_TRIVIAL(debug) << "First BW first Evt from tree: \t" << (bwChild->GetValue()*adChild->GetValue()); // // BOOST_LOG_TRIVIAL(debug) << "FirstReso first Evt classical: \t" << amps->getFirstReso(myPoint,par); // BOOST_LOG_TRIVIAL(debug) << "FirstReso first Evt from tree: \t" << resoChild->GetValue(); // // BOOST_LOG_TRIVIAL(debug) << "First Amp first Evt classical: \t" << amps->getFirstAmp(myPoint,par); // BOOST_LOG_TRIVIAL(debug) << "First Amp first Evt from tree: \t" << ampChild->GetValue(); // // BOOST_LOG_TRIVIAL(debug) << "Intensity of first data event classical: \t" << amps->intensity(myPoint,par).GetParameterValue(0); // BOOST_LOG_TRIVIAL(debug) << "Intensity of first data event from tree: \t" << intensChild->GetValue(); // BOOST_LOG_TRIVIAL(debug)<<"Finish consistency checks"<<std::endl; // } //std::shared_ptr<ControlParameter> esti = MinLogLH::createInstance(amps, myReader, myPHSPReader); //std::shared_ptr<Estimator> esti(new MinLogLH(amps, myReader, myPHSPReader)); std::shared_ptr<Optimizer::Optimizer> opti(new Optimizer::Minuit2::MinuitIF(esti, par)); ParameterList test; /*if(useFctTree) if(!amps->functionTree(test)) return 1;*/ //return 0; BOOST_LOG_TRIVIAL(info)<< "LH with optimal parameters: " << esti->controlParameter(par); if (useFctTree) BOOST_LOG_TRIVIAL(info)<<tree; //exit(1); double startInt[par.GetNDouble()], optiInt[par.GetNDouble()]; for (unsigned int i = 0; i < par.GetNDouble(); i++) { std::shared_ptr<DoubleParameter> tmp = par.GetDoubleParameter(i); optiInt[i] = tmp->GetValue(); //if (/*i < 2 ||*/ i > 10 /*|| i%4==2 || i%4==3 */) { //omega's and f0 fixed //if(i<2 || i>3 || i%2==1){ //omega's and f0 fixed // tmp->FixParameter(true); //} else { // tmp->FixParameter(true); if(i==5) tmp->FixParameter(false); // BOOST_LOG_TRIVIAL(debug)<< *tmp; //tmp->SetValue(tmp->GetValue()+0.5); ///((i+1))); // tmp->SetError(tmp->GetValue()); // if (!tmp->GetValue()) // tmp->SetError(1.); //} startInt[i] = tmp->GetValue(); } BOOST_LOG_TRIVIAL(info)<< "LH with following parameters: " << esti->controlParameter(par); for (unsigned int i = 0; i < par.GetNDouble(); i++) { BOOST_LOG_TRIVIAL(info)<< par.GetDoubleParameter(i)->GetName() << " = " << par.GetDoubleParameter(i)->GetValue(); } // std::cout << "Fixing 5 of 7 parameters " << std::endl; //for(unsigned int i=2; i<par.GetNDouble(); i++){ // par.GetDoubleParameter(i).FixParameter(true); // } BOOST_LOG_TRIVIAL(info)<< "Start Fit"; std::shared_ptr<FitResult> genResult = opti->exec(par); BOOST_LOG_TRIVIAL(info)<< "Final LH = " << genResult->getResult(); BOOST_LOG_TRIVIAL(info)<< "Optimierte intensitäten: " << esti->controlParameter(par); for (unsigned int i = 0; i < par.GetNDouble(); i++) { BOOST_LOG_TRIVIAL(info)<< par.GetDoubleParameter(i)->GetName() << " = " << par.GetDoubleParameter(i)->GetValue() << " [ start: " << startInt[i] << " ," << " optimal: " << optiInt[i] << " ]"; } /*AmplitudeSetup iniTrue(resoFile); //put start parameters here std::shared_ptr<Amplitude> trueAmp( new AmpSumIntensity(iniTrue, AmpSumIntensity::normStyle::none, std::shared_ptr<Efficiency>(new UnitEfficiency()), myReader->getNEvents())); ParameterList truePar; trueAmp->fillStartParVec(truePar); //true values genResult->setTrueParameters(truePar); genResult->print(); amps->printFractions();*/ string output_file_path = output_directory + "/fitresult.txt"; if (output_file_suffix != "") output_file_path = output_directory + "/fitresult_" + output_file_suffix + ".txt"; //genResult->writeText(output_file_path); output_file_path = output_directory + "/simplefitresult.txt"; if (output_file_suffix != "") output_file_path = output_directory + "/simplefitresult_" + output_file_suffix + ".txt"; //genResult->writeSimpleText(output_file_path); // if(useFctTree){ // BOOST_LOG_TRIVIAL(debug)<<physicsTree<<std::endl; // BOOST_LOG_TRIVIAL(debug)<<phspTree<<std::endl; // } if (!resultGen) return 0; //Plot result TH2D* bw12 = new TH2D("bw12", "inv. mass-sq of particles 1&2 Generated", 1000, 0., 10., 1000, 0., 10.); bw12->GetXaxis()->SetTitle("m_{12}^{2} / GeV^{2}"); bw12->GetXaxis()->CenterTitle(); bw12->GetYaxis()->SetTitle("#"); bw12->GetYaxis()->CenterTitle(); TH2D* bw13 = new TH2D("bw13", "inv. mass-sq of particles 1&3 Generated", 1000, 0., 10., 1000, 0., 10.); bw13->GetXaxis()->SetTitle("m_{13}^{2} / GeV^{2}"); bw13->GetXaxis()->CenterTitle(); bw13->GetYaxis()->SetTitle("#"); bw13->GetYaxis()->CenterTitle(); TH2D* bw23 = new TH2D("bw23", "inv. mass-sq of particles 2&3 Generated", 1000, 0., 10., 1000, 0., 10.); bw23->GetXaxis()->SetTitle("m_{23}^{2} / GeV^{2}"); bw23->GetXaxis()->CenterTitle(); bw23->GetYaxis()->SetTitle("#"); bw23->GetYaxis()->CenterTitle(); JakeReader myReaderPHSP(input_file_path, "kin"); unsigned int maxEventsPHSP = myReaderPHSP.getNEvents(); //double masssq12PHSP, masssq13PHSP, masssq23PHSP; TH2D* bw12PHSP = new TH2D("bw12PHSP", "inv. mass-sq of particles 1&2 PHSP", 1000, 0., 10., 1000, 0., 10.); bw12PHSP->GetXaxis()->SetTitle("m_{12}^{2} / GeV^{2}"); bw12PHSP->GetXaxis()->CenterTitle(); bw12PHSP->GetYaxis()->SetTitle("#"); bw12PHSP->GetYaxis()->CenterTitle(); TH2D* bw13PHSP = new TH2D("bw13PHSP", "inv. mass-sq of particles 1&3 PHSP", 1000, 0., 10., 1000, 0., 10.); bw13PHSP->GetXaxis()->SetTitle("m_{13}^{2} / GeV^{2}"); bw13PHSP->GetXaxis()->CenterTitle(); bw13PHSP->GetYaxis()->SetTitle("#"); bw13PHSP->GetYaxis()->CenterTitle(); TH2D* bw23PHSP = new TH2D("bw23PHSP", "inv. mass-sq of particles 2&3 PHSP", 1000, 0., 10., 1000, 0., 10.); bw23PHSP->GetXaxis()->SetTitle("m_{23}^{2} / GeV^{2}"); bw23PHSP->GetXaxis()->CenterTitle(); bw23PHSP->GetYaxis()->SetTitle("#"); bw23PHSP->GetYaxis()->CenterTitle(); TH2D* bw12FIT = new TH2D("bw12FIT", "inv. mass-sq of particles 1&2 FitResult", 1000, 0., 10., 1000, 0., 10.); bw12FIT->GetXaxis()->SetTitle("m_{12}^{2} / GeV^{2}"); bw12FIT->GetXaxis()->CenterTitle(); bw12FIT->GetYaxis()->SetTitle("#"); bw12FIT->GetYaxis()->CenterTitle(); TH2D* bw13FIT = new TH2D("bw13FIT", "inv. mass-sq of particles 1&3 FitResult", 1000, 0., 10., 1000, 0., 10.); bw13FIT->GetXaxis()->SetTitle("m_{13}^{2} / GeV^{2}"); bw13FIT->GetXaxis()->CenterTitle(); bw13FIT->GetYaxis()->SetTitle("#"); bw13PHSP->GetYaxis()->CenterTitle(); TH2D* bw23FIT = new TH2D("bw23FIT", "inv. mass-sq of particles 2&3 FitResult", 1000, 0., 10., 1000, 0., 10.); bw23FIT->GetXaxis()->SetTitle("m_{23}^{2} / GeV^{2}"); bw23FIT->GetXaxis()->CenterTitle(); bw23FIT->GetYaxis()->SetTitle("#"); bw23FIT->GetYaxis()->CenterTitle(); TH2D* bw12DIFF = new TH2D("bw12DIFF", "inv. mass-sq of particles 1&2 FitResult", 1000, 0., 10., 1000, 0., 10.); bw12DIFF->GetXaxis()->SetTitle("m_{12}^{2} / GeV^{2}"); bw12DIFF->GetXaxis()->CenterTitle(); bw12DIFF->GetYaxis()->SetTitle("#"); bw12DIFF->GetYaxis()->CenterTitle(); TH2D* bw13DIFF = new TH2D("bw13DIFF", "inv. mass-sq of particles 1&3 FitResult", 1000, 0., 10., 1000, 0., 10.); bw13DIFF->GetXaxis()->SetTitle("m_{13}^{2} / GeV^{2}"); bw13DIFF->GetXaxis()->CenterTitle(); bw13DIFF->GetYaxis()->SetTitle("#"); bw13PHSP->GetYaxis()->CenterTitle(); TH2D* bw23DIFF = new TH2D("bw23DIFF", "inv. mass-sq of particles 2&3 FitResult", 1000, 0., 10., 1000, 0., 10.); bw23DIFF->GetXaxis()->SetTitle("m_{23}^{2} / GeV^{2}"); bw23DIFF->GetXaxis()->CenterTitle(); bw23DIFF->GetYaxis()->SetTitle("#"); bw23DIFF->GetYaxis()->CenterTitle(); double masssq12, masssq13, masssq23; for (unsigned int i = 0; i < myReader->getNEvents(); i++) { Event event(myReader->getEvent(i)); //myReader.getEvent(-1, a, b, masssq); //if(!myReader.getEvent(i, event)) continue; TODO: try exception if (!event.getNParticles() == 3) continue; //if(!event) continue; //cout << "Event: \t" << i << "\t NParticles: \t" << event.getNParticles() << endl; const Particle &a(event.getParticle(0)); const Particle &b(event.getParticle(1)); const Particle &c(event.getParticle(2)); masssq12 = pow(a.E + b.E, 2) - pow(a.px + b.px, 2) - pow(a.py + b.py, 2) - pow(a.pz + b.pz, 2); masssq13 = pow(a.E + c.E, 2) - pow(a.px + c.px, 2) - pow(a.py + c.py, 2) - pow(a.pz + c.pz, 2); masssq23 = pow(b.E + c.E, 2) - pow(b.px + c.px, 2) - pow(b.py + c.py, 2) - pow(b.pz + c.pz, 2); bw12->Fill(masssq12, masssq13); bw13->Fill(masssq13, masssq12); bw23->Fill(masssq23, masssq12); } // TH2D* bw12DIFF = (TH2D*)bw12->Clone("bw12DIFF"); // TH2D* bw13DIFF = (TH2D*)bw13->Clone("bw13DIFF"); // TH2D* bw23DIFF = (TH2D*)bw23->Clone("bw23DIFF"); for (unsigned int i = 0; i < maxEventsPHSP; i++) { Event event(myReaderPHSP.getEvent(i)); //myReader.getEvent(-1, a, b, masssq); //if(!myReader.getEvent(i, event)) continue; TODO: try exception if (!event.getNParticles() == 3) continue; //if(!event) continue; //cout << "Event: \t" << i << "\t NParticles: \t" << event.getNParticles() << endl; const Particle &a(event.getParticle(0)); const Particle &b(event.getParticle(1)); const Particle &c(event.getParticle(2)); masssq12 = pow(a.E + b.E, 2) - pow(a.px + b.px, 2) - pow(a.py + b.py, 2) - pow(a.pz + b.pz, 2); masssq13 = pow(a.E + c.E, 2) - pow(a.px + c.px, 2) - pow(a.py + c.py, 2) - pow(a.pz + c.pz, 2); masssq23 = pow(b.E + c.E, 2) - pow(b.px + c.px, 2) - pow(b.py + c.py, 2) - pow(b.pz + c.pz, 2); bw12PHSP->Fill(masssq12, masssq13); bw13PHSP->Fill(masssq13, masssq12); bw23PHSP->Fill(masssq23, masssq12); vector<double> x; x.push_back(sqrt(masssq23)); x.push_back(sqrt(masssq13)); x.push_back(sqrt(masssq12)); //bw12FIT->Fill(masssq12,masssq13,1000*amps->intensity(x,par)); // bw13FIT->Fill(masssq13,masssq12,1000*amps->intensity(x,par)); // bw23FIT->Fill(masssq23,masssq12,1000*amps->intensity(x,par)); } //Generation TRandom3 rando; TLorentzVector W(0.0, 0.0, 0.0, M); //= beam + target; //(Momentum, Energy units are Gev/C, GeV) Double_t masses[3] = { m1, m2, m2 }; TGenPhaseSpace event; event.SetDecay(W, 3, masses); TLorentzVector *pGamma, *pPip, *pPim, pPm23, pPm13, pPm12; double weight, m23sq, m13sq, m12sq, maxTest = 0; ParameterList paras(par); if (useFctTree) { paras.RemoveDouble("ma"); paras.RemoveDouble("mb"); paras.RemoveDouble("mc"); } BOOST_LOG_TRIVIAL(info)<< "Einschwingen"; unsigned int schwingFactor = 10; if (myReader->getNEvents() < 1000) schwingFactor = 1000; for (unsigned int schwing = 0; schwing < schwingFactor * myReader->getNEvents(); schwing++) { weight = event.Generate(); pGamma = event.GetDecay(0); pPip = event.GetDecay(1); pPim = event.GetDecay(2); pPm23 = *pPim + *pPip; pPm13 = *pGamma + *pPim; pPm12 = *pGamma + *pPip; m23sq = pPm23.M2(); m13sq = pPm13.M2(); m12sq = pPm12.M2(); dataPoint point; try{ Kinematics::instance()->FillDataPoint(0,1,m23sq,m13sq,point); } catch (BeyondPhsp& ex){ continue; } // m12sq = kin.getThirdVariableSq(m23sq,m13sq); //point->setMsq(3,m12sq); point->setMsq(4,m13sq); point->setMsq(5,m23sq); // m12sq=M*M+m1*m1+m2*m2+m3*m3-m13sq-m23sq; if (std::fabs(m12sq - kin->getThirdVariableSq(m23sq, m13sq)) > 0.01) { std::cout << m12sq << " " << kin->getThirdVariableSq(m23sq, m13sq) << std::endl; std::cout << " " << m23sq << " " << m13sq << " " << m12sq << std::endl; } //call physics module vector<double> x; x.push_back(sqrt(m23sq)); x.push_back(sqrt(m13sq)); x.push_back(sqrt(m12sq)); //ParameterList intensL = amps->intensity(x, paras); double AMPpdf = amps->intensity(point).GetDoubleParameterValue(0); //double AMPpdf = intensL.GetDoubleParameter(0)->GetValue(); //double AMPpdf = testBW.intensity(x, minPar); //mb.setVal(m13); //double m13pdf = totAmp13.getVal();//fun_combi2->Eval(m13); if (maxTest < (weight * AMPpdf)) maxTest = (weight * AMPpdf); } maxTest *= 1.1; BOOST_LOG_TRIVIAL(info)<< "Start generation of y pi0 pi0 Dalitz Result"; unsigned int i = 0; do { weight = event.Generate(); pGamma = event.GetDecay(0); pPip = event.GetDecay(1); pPim = event.GetDecay(2); pPm23 = *pPim + *pPip; pPm13 = *pGamma + *pPim; pPm12 = *pGamma + *pPip; m23sq = pPm23.M2(); m13sq = pPm13.M2(); m12sq = pPm12.M2(); dataPoint dataP; dataP.setVal(0, m23sq); dataP.setVal(1, m13sq); // m12sq=M*M-m13sq-m23sq; //if(m12sq<0){ //cout << tmpm12_sq << "\t" << M*M << "\t" << m13_sq << "\t" << m23_sq << endl; //continue; // m12sq=0.0001; // } TParticle fparticleGam(22, 1, 0, 0, 0, 0, *pGamma, W); TParticle fparticlePip(211, 1, 0, 0, 0, 0, *pPip, W); TParticle fparticlePim(-211, 1, 0, 0, 0, 0, *pPim, W); //call physics module //dataPoint dataP; dataP.setVal("m23sq",m23sq); dataP.setVal("m13sq",m13sq); // vector<double> x; // x.push_back(sqrt(m23sq)); // x.push_back(sqrt(m13sq)); // x.push_back(sqrt(m12sq)); double AMPpdf = amps->intensity(dataP).GetDoubleParameterValue(0); //double AMPpdf = amps->intensity(x, par); double test = rando.Uniform(0, maxTest); //mb.setVal(m13); //double m13pdf = totAmp13.getVal();//fun_combi2->Eval(m13); if (maxTest < (weight * AMPpdf)) cout << "Einschwingen zu kurz!" << endl; if (test < (weight * AMPpdf)) { i++; bw12FIT->Fill(m12sq, m13sq); bw13FIT->Fill(m13sq, m12sq); bw23FIT->Fill(m23sq, m12sq); if(i%1000 == 0) BOOST_LOG_TRIVIAL(debug)<< "Event " << i; } } while (i < (myReader->getNEvents()/10.)); bw12DIFF->Add(bw12, 1.0); bw23DIFF->Add(bw23, 1.0); bw13DIFF->Add(bw13, 1.0); bw12DIFF->Divide(bw12FIT); bw23DIFF->Divide(bw23FIT); bw13DIFF->Divide(bw13FIT); // bw12DIFF = new TH2D(*bw12 - *bw12FIT); // bw23DIFF = new TH2D(*bw23 - *bw23FIT); // bw13DIFF = new TH2D(*bw13 - *bw13FIT); boost::filesystem::path output_file(output_filename); output_file_path = output_directory + "/" + output_filename; if (output_file_suffix != "") output_file_path = output_directory + "/" + output_file.stem().string() + "_" + output_file_suffix + output_file.extension().string(); TFile output(output_file_path.c_str(), "RECREATE", "ROOT_Tree"); bw12->Write(); bw13->Write(); bw23->Write(); bw12PHSP->Write(); bw13PHSP->Write(); bw23PHSP->Write(); bw12FIT->Write(); bw13FIT->Write(); bw23FIT->Write(); bw12DIFF->Write(); bw13DIFF->Write(); bw23DIFF->Write(); output.Write(); output.Close(); BOOST_LOG_TRIVIAL(info)<< "Done"; return 0; }
/** * The main function. */ int main(int argc, char **argv){ boost::log::core::get()->set_filter(trivial::severity >= trivial::debug); //setting log level BOOST_LOG_TRIVIAL(info) << " ComPWA Copyright (C) 2013 Mathias Michel "; BOOST_LOG_TRIVIAL(info) << " This program comes with ABSOLUTELY NO WARRANTY; for details see license.txt"; BOOST_LOG_TRIVIAL(info) << std::endl; DalitzKinematics* kin = dynamic_cast<DalitzKinematics*>(DalitzKinematics::createInstance("J/psi","gamma","pi0","pi0")); //DPKinematics kin("J/psi","gamma","pi0","pi0"); //DPKinematics kin("D0","gamma","K-","K+"); //static dataPoint* point = dataPoint::instance(kin); bool resultGen = true; std::string file="test/3Part-4vecs_1M_PDG.root"; const char* pPath = getenv("COMPWA_DIR"); std::string path = ""; try{ path = std::string(pPath); }catch(std::logic_error& ex){ BOOST_LOG_TRIVIAL(error)<<"Environment Variable COMPWA_DIR not set?"<<std::endl; } std::string resoFile=path+"/test/JPSI_ypipi.xml"; boost::property_tree::ptree pt; read_xml(resoFile, pt, boost::property_tree::xml_parser::trim_whitespace); BOOST_LOG_TRIVIAL(info)<< "Load Modules"; std::shared_ptr<RootReader> myReader(new RootReader(file, "data")); std::shared_ptr<RootReader> myPHSPReader(new RootReader(file, "mc")); std::shared_ptr<AmpSumIntensity> amps( new AmpSumIntensity( "amp", normStyle::none, std::shared_ptr<Efficiency>(new UnitEfficiency()), nFitEvents) ); amps->Configure(pt); // Initiate parameters ParameterList par; std::shared_ptr<Estimator::SliceFitUB::SliceFitUB> esti; amps->FillParameterList(par); //perfect startvalues esti = std::static_pointer_cast<Estimator::SliceFitUB::SliceFitUB>( Estimator::SliceFitUB::SliceFitUB::createInstance( amps, myReader, myPHSPReader, par, nStartEvent, nFitEvents, nBins, nF0, nF2 ) ); //unsigned int nSlices = nBins-(nBins/20.); ParameterList slicePars; //for(unsigned int i=0; i<nSlices; i++){ // std::string sliceName = "S"+std::to_string(i); std::shared_ptr<DoubleParameter> tmpA = std::shared_ptr<DoubleParameter>(new DoubleParameter("P0",0.75,0.1,100.)); std::shared_ptr<DoubleParameter> tmpB = std::shared_ptr<DoubleParameter>(new DoubleParameter("P1",1.,-15,15)); std::shared_ptr<DoubleParameter> tmpC = std::shared_ptr<DoubleParameter>(new DoubleParameter("P2",0.,0,15)); std::shared_ptr<DoubleParameter> tmpD = std::shared_ptr<DoubleParameter>(new DoubleParameter("P3",0.1,-15,15)); std::shared_ptr<DoubleParameter> tmpE = std::shared_ptr<DoubleParameter>(new DoubleParameter("P4",1.,0,50)); //std::shared_ptr<DoubleParameter> tmpF = std::shared_ptr<DoubleParameter>(new DoubleParameter("P5",1.,-10,10)); tmpA->FixParameter(true); //tmpC->FixParameter(true); //tmpE->FixParameter(true); //tmpB->FixParameter(true); //tmpD->FixParameter(true); tmpB->SetError(1.); tmpC->SetError(1.); tmpD->SetError(1.); tmpE->SetError(1.); //tmpA->UseBounds(true); //tmpB->UseBounds(true); //tmpC->UseBounds(true); //tmpD->UseBounds(true); //tmpE->UseBounds(true); slicePars.AddParameter(tmpA); slicePars.AddParameter(tmpB); slicePars.AddParameter(tmpC); slicePars.AddParameter(tmpD); slicePars.AddParameter(tmpE); //slicePars.AddParameter(tmpF); TH2D* phspA = new TH2D("phspTOT","phspTOT",100,0,10,100,0,10); TH2D* phspB = new TH2D("phspSpin0","phspSpin0",100,0,10,100,0,10); TH2D* phspD = new TH2D("phspSpin2","phspSpin2",100,0,10,100,0,10); TH2D* phspC = new TH2D("phspAll","phspAll",100,0,10,100,0,10); std::complex<double> reso[2]; reso[0]=std::complex<double>(10,0); reso[1]=std::complex<double>(0,0); std::complex<double> resoC[2]; resoC[0]=std::complex<double>(0,0); resoC[1]=std::complex<double>(20,0); std::complex<double> resoTOT[2]; resoTOT[0]=std::complex<double>(0,0); resoTOT[1]=std::complex<double>(0,0); std::complex<double> resoFull[2]; resoFull[0]=std::complex<double>(22,0); resoFull[1]=std::complex<double>(15,0); //std::cout << " " << reso[0] << " " << reso[1] << std::endl; for(unsigned int i=0; i<95; i++){ for(unsigned int j=0; j<95; j++){ dataPoint point; point.setVal("m23sq",i/10.); point.setVal("m13sq",j/10.); //std::cout << " " << amps->sliceIntensity(point, par, reso, 2) << " " << amps->sliceIntensity(point, par, resoTOT, 2) << std::endl; phspA->SetBinContent(i,j,amps->sliceIntensity(point, par, resoTOT, 2,1.,nF0,nF2)); phspB->SetBinContent(i,j,amps->sliceIntensity(point, par, reso, 2,1.,nF0,nF2)); phspC->SetBinContent(i,j,amps->sliceIntensity(point, par, resoFull, 2,1.,nF0,nF2)); phspD->SetBinContent(i,j,amps->sliceIntensity(point, par, resoC, 2,1.,nF0,nF2)); }} //slicePars.AddParameter(std::shared_ptr<DoubleParameter>(new DoubleParameter("P6",1.))); //} std::shared_ptr<Optimizer::Optimizer> opti(new Optimizer::Minuit2::MinuitIF(esti, slicePars)); esti->setSlice(33); BOOST_LOG_TRIVIAL(info) << "LH with start parameters slice 33: " << esti->controlParameter(slicePars); /*double startInt[par.GetNDouble()], optiInt[par.GetNDouble()]; for(unsigned int i=0; i<par.GetNDouble(); i++){ std::shared_ptr<DoubleParameter> tmp = par.GetDoubleParameter(i); optiInt[i] = tmp->GetValue(); if(i<0 || i>9 || i%2==1){ //omega's and f0 fixed // if(i<2 || i>3 || i%2==1){ //omega's and f0 fixed tmp->FixParameter(true); }else{ tmp->SetValue(tmp->GetValue()/((i+1))); tmp->SetError(std::shared_ptr<ParError<double>>(new SymError<double>(tmp->GetValue()))); if(!tmp->GetValue()) tmp->SetError(std::shared_ptr<ParError<double>>(new SymError<double>(1.))); } startInt[i] = tmp->GetValue(); }*/ // std::cout << "Fixing 5 of 7 parameters " << std::endl; //for(unsigned int i=2; i<par.GetNDouble(); i++){ // par.GetDoubleParameter(i).FixParameter(true); // } BOOST_LOG_TRIVIAL(info) << "Start multiple Fit of slice " << testSlice << " with " << nRand <<" random start parameter"; std::vector<std::complex<double> > p1,p2, e1, e2; std::vector<double> invMass, norm, norme, lh; std::vector<std::shared_ptr<TH1D> > histData, histModel, histModelCl; //std::vector<std::shared_ptr<TH1D> > histData, histModel, histModelCl; TRandom3 r; for(int i=0; i<nRand; i++){ double tmpMass = esti->setSlice(testSlice); BOOST_LOG_TRIVIAL(debug) << "InvMass Slice " << testSlice << " " << tmpMass ; std::shared_ptr<FitResult> genResult = opti->exec(slicePars); genResult->writeText("FitResultsAllSlicesUB_RAND.txt"); histData.push_back(esti->getSliceHist()); histModel.push_back(esti->getAmpSlHist()); histModelCl.push_back(esti->getAmpClHist()); histData.at(histData.size()-1)->GetXaxis()->SetTitle("m^{2}(#pi^{0} #gamma) [GeV/c^{2}]^{2}"); histModel.at(histModel.size()-1)->GetXaxis()->SetTitle("m^{2}(#pi^{0} #gamma) [GeV/c^{2}]^{2}"); histModelCl.at(histModelCl.size()-1)->GetXaxis()->SetTitle("m^{2}(#pi^{0} #gamma) [GeV/c^{2}]^{2}"); histData.at(histData.size()-1)->GetYaxis()->SetTitle("Entries"); histModel.at(histModel.size()-1)->GetYaxis()->SetTitle("Entries"); histModelCl.at(histModelCl.size()-1)->GetYaxis()->SetTitle("Entries"); histData.at(histData.size()-1)->SetStats(0); histModel.at(histModel.size()-1)->SetStats(0); histModelCl.at(histModelCl.size()-1)->SetStats(0); double parN(slicePars.GetDoubleParameter(0)->GetValue()); double parE(slicePars.GetDoubleParameter(0)->GetError()); std::complex<double> parCA(slicePars.GetDoubleParameter(1)->GetValue(), slicePars.GetDoubleParameter(2)->GetValue()); std::complex<double> parCB(slicePars.GetDoubleParameter(3)->GetValue(), slicePars.GetDoubleParameter(4)->GetValue()); std::complex<double> parEA(slicePars.GetDoubleParameter(1)->GetError(), slicePars.GetDoubleParameter(2)->GetError()); std::complex<double> parEB(slicePars.GetDoubleParameter(3)->GetError(), slicePars.GetDoubleParameter(4)->GetError()); p1.push_back(parCA); p2.push_back(parCB); e1.push_back(parEA); e2.push_back(parEB); invMass.push_back(i); norm.push_back(std::fabs(parN)); norme.push_back(parE); lh.push_back(genResult->getResult()); //p3.push_back(slicePars.GetDoubleParameter(3)->GetValue()); //p4.push_back(slicePars.GetDoubleParameter(4)->GetValue()); //if(i==30) i = 10000; genResult.reset(); BOOST_LOG_TRIVIAL(info) << "RandFit " << i << " reset par" ; for(unsigned int i=0; i<slicePars.GetNDouble(); i++){ std::shared_ptr<DoubleParameter> tmp = slicePars.GetDoubleParameter(i); if(!tmp->IsFixed()){ tmp->SetValue(r.Uniform(0,10)); tmp->SetError(tmp->GetValue()); } } } BOOST_LOG_TRIVIAL(debug) << "Results"; for(unsigned int i=0; i<p1.size(); i++){ BOOST_LOG_TRIVIAL(debug) << "Rand " << i << " " << std::abs(p1[i]) << " " << std::abs(p2[i]); } if(!resultGen) return 0; //Plot result TGraphErrors par_N(nRand); TGraphErrors par_r0(nRand); TGraphErrors par_r2(nRand); TGraphErrors par_p0(nRand); TGraphErrors par_p2(nRand); TGraphErrors par_x0(nRand); TGraphErrors par_y0(nRand); TGraphErrors par_x2(nRand); TGraphErrors par_y2(nRand); TGraphErrors par_xy0(nRand); TGraphErrors par_xy2(nRand); TGraphErrors par_LH(nRand); // NeatPlotting::PlotBundle bundlexy0; //std::vector<NeatPlotting::PlotLabel> labelsxy0; for(unsigned int i=0; i<p1.size(); i++){ double phi0=std::arg(p1[i]), phi2=std::arg(p2[i]); double phi0e, phi2e, abs0e, abs2e; while(phi0<0){ phi0+=2*3.14159; }; while(phi2<0){ phi2+=2*3.14159; }; double xx, yy, xexe, yeye; xx = p1[i].real()*p1[i].real(); yy = p1[i].imag()*p1[i].imag(); xexe = e1[i].real()*e1[i].real(); yeye = e1[i].imag()*e1[i].imag(); phi0e = sqrt((xx*yeye + yy*xexe)/(xx+yy)); abs0e = sqrt((xx*xexe + yy*yeye)/(xx+yy)); xx = p2[i].real()*p2[i].real(); yy = p2[i].imag()*p2[i].imag(); xexe = e2[i].real()*e2[i].real(); yeye = e2[i].imag()*e2[i].imag(); phi2e = sqrt((xx*yeye + yy*xexe)/(xx+yy)); abs2e = sqrt((xx*xexe + yy*yeye)/(xx+yy)); BOOST_LOG_TRIVIAL(debug) << "Slice " << i+(nBins/40.) << " " << std::abs(p1[i]) << " " << std::abs(p2[i]); BOOST_LOG_TRIVIAL(debug) << "Slice " << i+(nBins/40.) << " " << abs0e << " " << abs2e; par_r0.SetPoint(i,invMass[i],std::abs(p1[i])); par_p0.SetPoint(i,invMass[i],phi0); par_r0.SetPointError(i,0,abs0e); par_p0.SetPointError(i,0,phi0e); par_x0.SetPoint(i,invMass[i],p1[i].real()); par_y0.SetPoint(i,invMass[i],p1[i].imag()); par_x0.SetPointError(i,0,e1[i].real()); par_y0.SetPointError(i,0,e1[i].imag()); par_r2.SetPoint(i,invMass[i],std::abs(p2[i])); par_p2.SetPoint(i,invMass[i],phi2); par_r2.SetPointError(i,0,abs2e); par_p2.SetPointError(i,0,phi2e); par_x2.SetPoint(i,invMass[i],p2[i].real()); par_y2.SetPoint(i,invMass[i],p2[i].imag()); par_x2.SetPointError(i,0,e2[i].real()); par_y2.SetPointError(i,0,e2[i].imag()); par_xy0.SetPoint(i,p1[i].real(),p1[i].imag()); par_xy2.SetPoint(i,p2[i].real(),p2[i].imag()); par_xy0.SetPointError(i,e1[i].real(),e1[i].imag()); par_xy2.SetPointError(i,e2[i].real(),e2[i].imag()); //NeatPlotting::PlotLabel tmplabelxy0(std::to_string(i),NeatPlotting::TextStyle()); //tmplabelxy0.setAbsolutionPosition(p1[i].real()+0.2,p1[i].imag()+0.2); // labelsxy0.push_back(tmplabelxy0); par_LH.SetPoint(i,invMass[i],lh[i]); par_N.SetPoint(i,invMass[i],norm[i]); par_N.SetPointError(i,0,norme[i]); } //bundlexy0.addGraph(par_xy0, NeatPlotting::DataObjectStyle()); // for(unsigned int i=0; i<labelsxy0.size(); i++){ // bundlexy0.plot_decoration.labels.push_back(labelsxy0[i]); //} //NeatPlotting::PlotStyle myStyle; //bundlexy0.plot_axis.x_axis_title = "Real Spin 0"; // bundlexy0.plot_axis.y_axis_title = "Imag Spin 0"; //TCanvas bla("Argand Spin 0"); //bundlexy0.drawOnCurrentPad(myStyle); par_r0.Draw(); par_r2.Draw(); par_p0.Draw(); par_p2.Draw(); par_r0.SetTitle(""); par_r2.SetTitle(""); par_p0.SetTitle(""); par_p2.SetTitle(""); par_r0.GetYaxis()->SetTitle("Magnitude Spin 0"); par_p0.GetYaxis()->SetTitle("Phase Spin 0 /rad"); par_r0.GetXaxis()->SetTitle("Run ID"); par_p0.GetXaxis()->SetTitle("Run ID"); par_r2.GetYaxis()->SetTitle("Magnitude Spin 2"); par_p2.GetYaxis()->SetTitle("Phase Spin 2 /rad"); par_r2.GetXaxis()->SetTitle("Run ID"); par_p2.GetXaxis()->SetTitle("Run ID"); par_x0.Draw(); par_x2.Draw(); par_y0.Draw(); par_y2.Draw(); par_x0.SetTitle(""); par_x2.SetTitle(""); par_y0.SetTitle(""); par_y2.SetTitle(""); par_x0.GetYaxis()->SetTitle("Real Spin 0"); par_y0.GetYaxis()->SetTitle("Imag Spin 0"); par_x0.GetXaxis()->SetTitle("Run ID"); par_y0.GetXaxis()->SetTitle("Run ID"); par_x2.GetYaxis()->SetTitle("Real Spin 2"); par_y2.GetYaxis()->SetTitle("Imag Spin 2 /rad"); par_x2.GetXaxis()->SetTitle("Run ID"); par_y2.GetXaxis()->SetTitle("Run ID"); par_xy0.Draw(); par_xy2.Draw(); par_xy0.SetTitle(""); par_xy2.SetTitle(""); par_xy0.GetXaxis()->SetTitle("Real Spin 0"); par_xy0.GetYaxis()->SetTitle("Imag Spin 0"); par_xy2.GetXaxis()->SetTitle("Real Spin 2"); par_xy2.GetYaxis()->SetTitle("Imag Spin 2"); par_LH.Draw(); par_LH.SetTitle(""); par_LH.GetXaxis()->SetTitle("RUN ID"); par_LH.GetYaxis()->SetTitle("LH"); TFile output("test/FitResultJPSISLICEUB_RAND.root","RECREATE","ROOT_Tree"); par_N.Write("Constant"); par_r0.Write("Magn Spin 0"); par_r2.Write("Magn Spin 2"); par_p0.Write("Arg Spin 0"); par_p2.Write("Arg Spin 2"); par_x0.Write("Real Spin 0"); par_x2.Write("Real Spin 2"); par_y0.Write("Imag Spin 0"); par_y2.Write("Imag Spin 2"); //phspA->Write(); // phspB->Write(); // phspC->Write(); // phspD->Write(); par_xy0.Write("Argand Spin 0"); par_xy2.Write("Argand Spin 2"); par_LH.Write("LH"); output.mkdir("RandFit"); output.cd("RandFit"); for(unsigned int h=0; h<histData.size(); h++){ histData[h]->Write(); histModel[h]->Write(); histModelCl[h]->Write(); } output.Write(); output.Close(); BOOST_LOG_TRIVIAL(info) << "Done"; return 0; }
/** * The main function. */ int main(int argc, char **argv){ int seed = 3041; //default seed //number of calls for numeric integration and number of events for phsp integration unsigned int mcPrecision = 500000; Logging log("log-compareTreeAmp.txt",boost::log::trivial::debug); //initialize logging //initialize kinematics of decay Physics::DPKinematics::DalitzKinematics::createInstance("D0","K_S0","K-","K+");//setup kinematics //initialize random generator std::shared_ptr<Generator> gen = std::shared_ptr<Generator>( new Physics::DPKinematics::RootGenerator(seed) ); RunManager run; run.setGenerator(gen); //======================= DATA ============================= unsigned int numEvents = 2000;//data size to be generated //empty file: run generation before fit std::shared_ptr<Data> inputData( new DataReader::RootReader::RootReader() ); //======================= EFFICIENCY ============================= std::shared_ptr<Efficiency> eff(new UnitEfficiency()); //======================= AMPLITUDE ============================= //true amplitude model std::string trueModelFile = "test/CompareTreeAmp-model.xml"; boost::property_tree::ptree pt; read_xml( trueModelFile, pt, boost::property_tree::xml_parser::trim_whitespace ); auto a = new Physics::AmplitudeSum::AmpSumIntensity( "amp", normStyle::one, eff, mcPrecision ); a->Configure(pt); std::shared_ptr<Amplitude> trueAmp(a); //fit amplitude model std::string fitModelFile = trueModelFile; boost::property_tree::ptree pt2; read_xml(fitModelFile, pt2, boost::property_tree::xml_parser::trim_whitespace); auto fitAmpPtr = new Physics::AmplitudeSum::AmpSumIntensity( "fitAmp", normStyle::one, eff, mcPrecision ); fitAmpPtr->Configure(pt2); auto fitAmpTreePtr = new Physics::AmplitudeSum::AmpSumIntensity( "fitAmpTree", normStyle::one, eff, mcPrecision ); fitAmpTreePtr->Configure(pt2); // AmplitudeSetup ini(fitModelFile);//put start parameters here // AmplitudeSetup iniTree(fitModelFile);//put start parameters here // AmpSumIntensity* fitAmpPtr = new AmpSumIntensity(ini, normStyle::one, eff, mcPrecision); // AmpSumIntensity* fitAmpTreePtr = new AmpSumIntensity(iniTree, normStyle::one, eff, mcPrecision); std::shared_ptr<Amplitude> fitAmp(fitAmpPtr); std::shared_ptr<Amplitude> fitAmpTree(fitAmpTreePtr); run.setAmplitude(trueAmp);//set true model here for generation //empty phsp sample std::shared_ptr<Data> toyPhspData( new DataReader::RootReader::RootReader() ); run.setPhspSample(toyPhspData); if( !toyPhspData->getNEvents() ) { run.generatePhsp(mcPrecision); } toyPhspData->setEfficiency(eff); run.setData(inputData); if( !inputData->getNEvents() ) { run.generate(numEvents); } //======================= PARAMETERS ============================= ParameterList fitPar; fitAmp->FillParameterList(fitPar); ParameterList fitParTree; fitAmpTree->FillParameterList(fitParTree); ParameterList truePar; trueAmp->FillParameterList(truePar); //true values // fitParTree.GetDoubleParameter("g1_a_0")->FixParameter(1); // fitPar.GetDoubleParameter("g1_a_0")->FixParameter(1); for(unsigned int i=0; i<fitParTree.GetNDouble(); i++) fitParTree.GetDoubleParameter(i)->SetError(.1); for(unsigned int i=0; i<fitPar.GetNDouble(); i++) fitPar.GetDoubleParameter(i)->SetError(.1); fitAmpTree->UpdateParameters(fitParTree); fitAmp->UpdateParameters(fitPar); fitAmp->to_str(); BOOST_LOG_TRIVIAL(info)<<"Entries in data file: "<<inputData->getNEvents(); BOOST_LOG_TRIVIAL(info)<<"True model file: "<<trueModelFile ; BOOST_LOG_TRIVIAL(info)<<"Fit model file: "<<fitModelFile ; //======================= TREE FIT ============================= std::shared_ptr<Optimizer::ControlParameter> esti(Estimator::MinLogLH::MinLogLH::createInstance( fitAmpTree, inputData, toyPhspData)); Estimator::MinLogLH::MinLogLH* minLog = dynamic_cast<Estimator::MinLogLH::MinLogLH*>(&*(esti->Instance())); minLog->setUseFunctionTree(1); std::shared_ptr<FunctionTree> physicsTree = minLog->getTree(); BOOST_LOG_TRIVIAL(debug) << physicsTree->head()->to_str(20); double initialLHTree = esti->controlParameter(fitParTree); std::shared_ptr<Optimizer::Optimizer> optiTree( new Optimizer::Minuit2::MinuitIF(esti, fitParTree) ); run.setOptimizer(optiTree); //======================= Compare tree and amplitude ============================= std::shared_ptr<AmpRelBreitWignerRes> phiRes = std::dynamic_pointer_cast<AmpRelBreitWignerRes>( fitAmpPtr->GetResonance("phi(1020)") ); double phimag = fitAmpPtr->GetResonance("phi(1020)")->GetMagnitude(); double phiphase = fitAmpPtr->GetResonance("phi(1020)")->GetPhase(); std::complex<double> phiCoeff( phimag*cos(phiphase), phimag*sin(phiphase) ); std::shared_ptr<AmpFlatteRes> a0Res = std::dynamic_pointer_cast<AmpFlatteRes>( fitAmpPtr->GetResonance("a_0(980)0") ); double a0mag = fitAmpPtr->GetResonance("a_0(980)0")->GetMagnitude(); double a0phase = fitAmpPtr->GetResonance("a_0(980)0")->GetPhase(); std::complex<double> a0Coeff( a0mag*cos(a0phase), a0mag*sin(a0phase) ); std::shared_ptr<AmpFlatteRes> aplusRes = std::dynamic_pointer_cast<AmpFlatteRes>( fitAmpPtr->GetResonance("a_0(980)+") ); double aplusmag = fitAmpPtr->GetResonance("a_0(980)+")->GetMagnitude(); double aplusphase = fitAmpPtr->GetResonance("a_0(980)+")->GetPhase(); std::complex<double> aplusCoeff( aplusmag*cos(aplusphase), aplusmag*sin(aplusphase) ); dataPoint point(inputData->getEvent(0)); //first data point in sample ParameterList intens = fitAmpPtr->intensity(point); /*the tree contains multiple node with the same names. We search for node 'Intens' first and * afterwards for the resonance.*/ std::shared_ptr<TreeNode> intensNode; MultiDouble* intensValue; intensNode = physicsTree->head()->getChildNode("AmpSq"); if(intensNode) intensValue = dynamic_cast<MultiDouble*>( &*(intensNode->getValue()) ); else { BOOST_LOG_TRIVIAL(error)<<"Failed to get Node 'AmpSq'!"; throw; } BOOST_LOG_TRIVIAL(info) <<" Total integral of phi(1020) "<<phiRes->GetTotalIntegral(); std::cout<<std::setprecision(8)<<std::endl; BOOST_LOG_TRIVIAL(info) <<"==========================================="; BOOST_LOG_TRIVIAL(info) <<"Compare values: (use first event of data sample) TREE/AMPLITUDE"; BOOST_LOG_TRIVIAL(info) <<"==========================================="; BOOST_LOG_TRIVIAL(info) <<"Intensity: "<<intensValue->GetValue(0) <<"/"<<*intens.GetDoubleParameter(0) <<" = "<<intensValue->GetValue(0) / *intens.GetDoubleParameter(0); double norm_tree = physicsTree->head()->getChildSingleValue("N").real(); double norm_amp = 1/fitAmp->GetIntegral(); BOOST_LOG_TRIVIAL(info)<<" Norm: "<<norm_tree <<"/"<<norm_amp <<" = "<<norm_tree/norm_amp; BOOST_LOG_TRIVIAL(info) <<"================= phi(1020) =========================="; BOOST_LOG_TRIVIAL(info) <<"Reso_phi(1020): "<<intensNode->getChildSingleValue("Reso_phi(1020)") <<"/"<<phiRes->Evaluate(point); BOOST_LOG_TRIVIAL(info) <<"N_phi(1020): "<<intensNode->getChildSingleValue("N_phi(1020)").real() <<"/"<<phiRes->GetNormalization() <<" = "<<intensNode->getChildSingleValue("N_phi(1020)").real()/phiRes->GetNormalization(); BOOST_LOG_TRIVIAL(info) <<"RelBW_phi(1020): "<<intensNode->getChildSingleValue("RelBW_phi(1020)") <<"/"<<phiRes->EvaluateAmp(point); BOOST_LOG_TRIVIAL(info) <<"AngD_phi(1020): "<<intensNode->getChildSingleValue("AngD_phi(1020)").real() <<"/"<<phiRes->EvaluateWignerD(point); BOOST_LOG_TRIVIAL(info) <<"================= a_0(980)0 =========================="; BOOST_LOG_TRIVIAL(info) <<"Reso_a_0(980)0: "<<intensNode->getChildSingleValue("Reso_a_0(980)0") <<"/"<<a0Res->Evaluate(point); BOOST_LOG_TRIVIAL(info) <<"N_a_0(980)0: "<<intensNode->getChildSingleValue("N_a_0(980)0").real() <<"/"<<a0Res->GetNormalization(); BOOST_LOG_TRIVIAL(info) <<"FlatteRes_a_0(980)0: "<<intensNode->getChildSingleValue("FlatteRes_a_0(980)0") <<"/"<<a0Res->EvaluateAmp(point); BOOST_LOG_TRIVIAL(info) <<"================= a_0(980)+ =========================="; BOOST_LOG_TRIVIAL(info) <<"Reso_a_0(980)+: "<<intensNode->getChildSingleValue("Reso_a_0(980)+") <<"/"<<aplusRes->Evaluate(point); BOOST_LOG_TRIVIAL(info) <<"N_a_0(980)+: "<<intensNode->getChildSingleValue("N_a_0(980)+").real() <<"/"<<aplusRes->GetNormalization(); BOOST_LOG_TRIVIAL(info) <<"FlatteRes_a_0(980)+: "<<intensNode->getChildSingleValue("FlatteRes_a_0(980)+") <<"/"<<aplusRes->EvaluateAmp(point); BOOST_LOG_TRIVIAL(info) <<"==========================================="; std::shared_ptr<FitResult> resultTree = run.startFit(fitParTree); double finalLHTree = resultTree->getResult(); resultTree->setTrueParameters(truePar);//set true parameters //======================= AMPLITUDE FIT ============================= esti->resetInstance(); esti = std::shared_ptr<Optimizer::ControlParameter>( Estimator::MinLogLH::MinLogLH::createInstance( fitAmp, inputData, toyPhspData) ); double initialLH = esti->controlParameter(fitPar); std::cout<<std::setprecision(20); BOOST_LOG_TRIVIAL(info) <<"Initial likelihood: "<<initialLHTree<< "/"<<initialLH << " Deviation = "<<initialLHTree-initialLH; std::shared_ptr<Optimizer::Optimizer> opti( new Optimizer::Minuit2::MinuitIF(esti, fitPar) ); run.setOptimizer(opti); std::shared_ptr<FitResult> result= run.startFit(fitPar); double finalLH = result->getResult(); result->setTrueParameters(truePar);//set true parameters //======================= OUTPUT ============================= BOOST_LOG_TRIVIAL(info) <<"TREE fit result:"; resultTree->print("P"); BOOST_LOG_TRIVIAL(info) <<"AMPLITUDE fit result:"; result->print("P"); BOOST_LOG_TRIVIAL(info) <<"Comparison TREE/AMPLITUDE:"; BOOST_LOG_TRIVIAL(info) <<"Timings[s]: "<<resultTree->getTime()<<"/"<<result->getTime() <<"="<<resultTree->getTime()/result->getTime(); BOOST_LOG_TRIVIAL(info) <<"Initial likelihood: "<<initialLHTree<< "/"<<initialLH << " Deviation = "<<initialLHTree/initialLH; BOOST_LOG_TRIVIAL(info) <<"Final likelihood: "<<finalLHTree<< "/"<<finalLH << " Deviation = "<<finalLHTree/finalLH; BOOST_LOG_TRIVIAL(info) << "FINISHED!"; return 0; }