void gatherAEff(const char *inpFile=NULL) { std::string line; std::vector<std::string> lines; if (!inpFile) { std::cout << "\ninpFile=NULL\n"; std::cout << "Creating sample input file\n"; const char *sampleFName="aeff_sample.inp"; std::ofstream fout(sampleFName); fout << "../root_files/constants/DY_j22_19789pb/acceptance_constants1D.root\n"; fout << "../root_files/constants/DY_j22_19789pb/event_efficiency_constants1D.root\n"; fout << "../root_files/constants/DY_j22_19789pb/scale_factors_1D_Full2012_hltEffOld_PU.root\n"; fout.close(); std::cout << "check the file <" << sampleFName << ">\n"; std::cout << "1D/2D in the name does not matter\n"; return; } else { // load input std::ifstream finput(inpFile); if (!finput) { std::cout << "failed to open file <" << inpFile << ">\n"; return; } getline(finput,line); lines.push_back(line); std::cout << "line1=<" << line << ">\n"; getline(finput,line); lines.push_back(line); std::cout << "line2=<" << line << ">\n"; getline(finput,line); lines.push_back(line); std::cout << "line3=<" << line << ">\n"; finput.close(); } std::cout << dashline; std::string fnameAcc,fnameEff,fnameRho; int count=0; for (unsigned int i=0; i<lines.size(); ++i) { line=lines[i]; AdjustDim(line); if (PosOk(line,"acceptance")) { fnameAcc=line; count++; } else if (PosOk(line,"efficiency")) { fnameEff=line; count++; } else if (PosOk(line,"scale_factors")) { fnameRho=line; count++; } else { std::cout << "could not identify the file <" << line << ">\n"; return; } } if (count!=3) { std::cout << "not all files were identified\n"; return; } std::cout << "files were identified ok\n"; std::cout << dashline; TMatrixD effM(DYTools::nMassBins,DYTools::nYBinsMax); TMatrixD effErrM(effM); TMatrixD accM(effM), accErrM(effM); TMatrixD rhoM(effM), rhoErrM(effM); if (!LoadMatrix(fnameAcc,accM,accErrM,"acceptanceMatrix","acceptanceErrMatrix") || !LoadMatrix(fnameEff,effM,effErrM,"efficiencyArray","efficiencyErrArray") || !LoadMatrix(fnameRho,rhoM,rhoErrM,"scaleFactor","scaleFactorErr") ) { std::cout << "failed to load field\n"; return; } TString outFName; if (DYTools::study2D) { outFName="dyee_aeff_2D.root"; TFile fout(outFName,"recreate"); accM.Write("acceptance"); accErrM.Write("acceptanceErr"); effM.Write("efficiency"); effErrM.Write("efficiencyErr"); rhoM.Write("scaleFactor"); rhoErrM.Write("scaleFactorErr"); unfolding::writeBinningArrays(fout); for (int i=0; i<DYTools::nMassBins; ++i) { TString massRange=Form("_%1.0lf_%2.0lf",DYTools::massBinLimits[i],DYTools::massBinLimits[i+1]); TString hAccName=TString("hAcc") + massRange; Histo_t *hAcc=extractRapidityDependence(hAccName,"",accM,accErrM,i,0); TString hEffName=TString("hEff") + massRange; Histo_t *hEff=extractRapidityDependence(hEffName,"",effM,effErrM,i,0); TString hRhoName=TString("hRho") + massRange; Histo_t *hRho=extractRapidityDependence(hRhoName,"",rhoM,rhoErrM,i,0); if (!hAcc || !hEff || !hRho) { std::cout << "got unexpected null histo\n"; break; } hAcc->Write(); hEff->Write(); hRho->Write(); } fout.Close(); } else { // 1D case outFName="dyee_aeff_1D.root"; std::cout << "accM: rows " << accM.GetNrows() << ", cols " << accM.GetNcols() << "\n"; TVectorD eff(DYTools::nMassBins), effErr(eff); TVectorD acc(eff), accErr(eff); TVectorD rho(eff), rhoErr(eff); GetMassProfile1D(accM,accErrM, acc,accErr); GetMassProfile1D(effM,effErrM, eff,effErr); GetMassProfile1D(rhoM,rhoErrM, rho,rhoErr); Histo_t *hAcc=extractMassDependence("hAcc","",accM,accErrM,0,0,0); Histo_t *hEff=extractMassDependence("hEff","",effM,effErrM,0,0,0); Histo_t *hRho=extractMassDependence("hRho","",rhoM,rhoErrM,0,0,0); if (!hAcc || !hEff || !hRho) { std::cout << "got unexpected null histo\n"; } else { TFile fout(outFName,"recreate"); acc.Write("acceptance"); accErr.Write("acceptanceErr"); eff.Write("efficiency"); effErr.Write("efficiencyErr"); rho.Write("scaleFactor"); rhoErr.Write("scaleFactorErr"); unfolding::writeBinningArrays(fout); hAcc->Write(); hEff->Write(); hRho->Write(); fout.Close(); } } std::cout << "file <" << outFName << "> created\n"; return; }
int main(){ Convexhull h; vector<Point> point; vector<Point> result; vector<Point> internal; while(1){ int i,option,n; cout << "Please choose method: (1)brute force (2)Jarvis's march (3)exit" <<endl; cin >> option; ifstream finput("Input.txt"); internal.clear(); point.clear(); result.clear(); finput >> n; // Ū¤F´XÓ¦r¤¸ for(i=0; i<n; i++){ double x,y; finput >> x >> y; Point a = Point(x,y); point.push_back(a); } struct timeval tv, tv2; unsigned long long int start_utime, end_utime; if(option == 1){ gettimeofday(&tv, NULL); h.FindConvexHull_bf(point, result); gettimeofday(&tv2, NULL); start_utime = tv.tv_sec*1000000 + tv.tv_usec; end_utime = tv2.tv_sec*1000000 + tv2.tv_usec; } else if(option == 2){ gettimeofday(&tv, NULL); h.FindConvexHull_jm(point, result); gettimeofday(&tv2, NULL); start_utime = tv.tv_sec*1000000 + tv.tv_usec; end_utime = tv2.tv_sec*1000000 + tv2.tv_usec; } else break; cout << "cost time: " << end_utime - start_utime << " us" <<endl; internal = h.FindInternalPoint(point,result); ofstream foutput("Output.txt"); foutput << internal.size() << endl; vector<Point> upper; vector<Point> lower; upper.clear(); lower.clear(); for(i=0; i<internal.size(); i++){ if(internal[i].y >= 0) upper.push_back(internal[i]); else lower.push_back(internal[i]); } sort(upper.begin(), upper.end(), up_compare); sort(lower.begin(), lower.end(), low_compare); for(i=0; i<upper.size(); i++) foutput << upper[i].x << " " << upper[i].y << endl; for(i=0; i<lower.size(); i++) foutput << lower[i].x << " " << lower[i].y << endl; foutput << endl; foutput << result.size() << endl; Point start_p = FindStartPoint(result); upper.clear(); lower.clear(); for(i=0; i<result.size(); i++){ if(result[i] == start_p) continue; if(result[i].y > start_p.y) upper.push_back(result[i]); else lower.push_back(result[i]); } sort(upper.begin(), upper.end(), up_compare); sort(lower.begin(), lower.end(), low_compare); foutput << start_p.x << " " << start_p.y << endl; for(i=0; i<upper.size(); i++) foutput << upper[i].x << " " << upper[i].y << endl; for(i=0; i<lower.size(); i++) foutput << lower[i].x << " " << lower[i].y << endl; } return 0; }