Py::Object RendererAgg::write_rgba(const Py::Tuple& args) { _VERBOSE("RendererAgg::write_rgba"); args.verify_length(1); std::string fname = Py::String( args[0]); std::ofstream of2( fname.c_str(), std::ios::binary|std::ios::out); for (size_t i=0; i<NUMBYTES; ++i) { of2.write((char*)&(pixBuffer[i]), sizeof(char)); } return Py::Object(); }
void ObjectiveFunctionTests::test_clone( ObjectiveFunctionTemplate* of ) { const double some_vals[] = { 1, 2, 3, 4, 5, 6, 0.5 }; const unsigned num_vals = sizeof(some_vals)/sizeof(some_vals[0]); OFTestQM metric( some_vals, num_vals ); of->set_quality_metric(&metric); // test that we get the same value from both auto_ptr<ObjectiveFunction> of2( of->clone() ); double exp_val, val; exp_val = evaluate_internal( ObjectiveFunction::CALCULATE, EVAL, of ); val = evaluate_internal( ObjectiveFunction::CALCULATE, EVAL, of2.get() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_val, val, 1e-12 ); // check if OF supports BCD -- if not then done MsqError err; of->evaluate( ObjectiveFunction::UPDATE, patch(), val, false, err ); if (err) { err.clear(); return; } // build up some saved state in the objective function of->clear(); const double vals1[] = { 1.0, 3.0, 4.0, 8.0 }; const size_t vals1_len = sizeof(vals1)/sizeof(vals1[0]); const double vals2[] = { 21.5, 11.1, 30.0, 0.5 }; const size_t vals2_len = sizeof(vals2)/sizeof(vals2[0]); metric.set_values( vals1, vals1_len ); evaluate_internal( ObjectiveFunction::SAVE, EVAL, of ); metric.append_values( vals2, vals2_len ); evaluate_internal( ObjectiveFunction::ACCUMULATE, EVAL, of ); // check that clone has same accumulated data of2 = auto_ptr<ObjectiveFunction>(of->clone()); metric.set_values( some_vals, num_vals ); exp_val = evaluate_internal( ObjectiveFunction::UPDATE, EVAL, of ); val = evaluate_internal( ObjectiveFunction::UPDATE, EVAL, of2.get() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_val, val, 1e-12 ); }
double StartTraining(int&result) { double errors=0.0; vcbList eTrainVcbList, fTrainVcbList; globeTrainVcbList=&eTrainVcbList; globfTrainVcbList=&fTrainVcbList; string repFilename = Prefix + ".gizacfg" ; ofstream of2(repFilename.c_str()); writeParameters(of2,getGlobalParSet(),-1) ; cout << "reading vocabulary files \n"; eTrainVcbList.setName(SourceVocabFilename.c_str()); fTrainVcbList.setName(TargetVocabFilename.c_str()); eTrainVcbList.readVocabList(); fTrainVcbList.readVocabList(); cout << "Source vocabulary list has " << eTrainVcbList.uniqTokens() << " unique tokens \n"; cout << "Target vocabulary list has " << fTrainVcbList.uniqTokens() << " unique tokens \n"; vcbList eTestVcbList(eTrainVcbList) ; vcbList fTestVcbList(fTrainVcbList) ; corpus = new sentenceHandler(CorpusFilename.c_str(), &eTrainVcbList, &fTrainVcbList); if (TestCorpusFilename == "NONE") TestCorpusFilename = ""; if (TestCorpusFilename != ""){ cout << "Test corpus will be read from: " << TestCorpusFilename << '\n'; testCorpus= new sentenceHandler(TestCorpusFilename.c_str(), &eTestVcbList, &fTestVcbList); cout << " Test total # sentence pairs : " <<(*testCorpus).getTotalNoPairs1()<<" weighted:"<<(*testCorpus).getTotalNoPairs2() <<'\n'; cout << "Size of the source portion of test corpus: " << eTestVcbList.totalVocab() << " tokens\n"; cout << "Size of the target portion of test corpus: " << fTestVcbList.totalVocab() << " tokens \n"; cout << "In source portion of the test corpus, only " << eTestVcbList.uniqTokensInCorpus() << " unique tokens appeared\n"; cout << "In target portion of the test corpus, only " << fTestVcbList.uniqTokensInCorpus() << " unique tokens appeared\n"; cout << "ratio (target/source) : " << double(fTestVcbList.totalVocab()) / eTestVcbList.totalVocab() << '\n'; } cout << " Train total # sentence pairs (weighted): " << corpus->getTotalNoPairs2() << '\n'; cout << "Size of source portion of the training corpus: " << eTrainVcbList.totalVocab()-corpus->getTotalNoPairs2() << " tokens\n"; cout << "Size of the target portion of the training corpus: " << fTrainVcbList.totalVocab() << " tokens \n"; cout << "In source portion of the training corpus, only " << eTrainVcbList.uniqTokensInCorpus() << " unique tokens appeared\n"; cout << "In target portion of the training corpus, only " << fTrainVcbList.uniqTokensInCorpus() << " unique tokens appeared\n"; cout << "lambda for PP calculation in IBM-1,IBM-2,HMM:= " << double(fTrainVcbList.totalVocab()) << "/(" << eTrainVcbList.totalVocab() << "-" << corpus->getTotalNoPairs2() << ")="; LAMBDA = double(fTrainVcbList.totalVocab()) / (eTrainVcbList.totalVocab()-corpus->getTotalNoPairs2()); cout << "= " << LAMBDA << '\n'; // load dictionary Dictionary *dictionary; useDict = !dictionary_Filename.empty(); if (useDict) dictionary = new Dictionary(dictionary_Filename.c_str()); else dictionary = new Dictionary(""); int minIter=0; #ifdef BINARY_SEARCH_FOR_TTABLE if( CoocurrenceFile.length()==0 ) { cerr << "ERROR: NO COOCURRENCE FILE GIVEN!\n"; abort(); } //ifstream coocs(CoocurrenceFile.c_str()); tmodel<COUNT, PROB> tTable(CoocurrenceFile); #else tmodel<COUNT, PROB> tTable; #endif model1 m1(CorpusFilename.c_str(), eTrainVcbList, fTrainVcbList,tTable,trainPerp, *corpus,&testPerp, testCorpus, trainViterbiPerp, &testViterbiPerp); amodel<PROB> aTable(false); amodel<COUNT> aCountTable(false); model2 m2(m1,aTable,aCountTable); hmm h(m2); model3 m3(m2); if(ReadTablePrefix.length() ) { string number = "final"; string tfile,afilennfile,dfile,d4file,p0file,afile,nfile; //d5file tfile = ReadTablePrefix + ".t3." + number ; afile = ReadTablePrefix + ".a3." + number ; nfile = ReadTablePrefix + ".n3." + number ; dfile = ReadTablePrefix + ".d3." + number ; d4file = ReadTablePrefix + ".d4." + number ; //d5file = ReadTablePrefix + ".d5." + number ; p0file = ReadTablePrefix + ".p0_3." + number ; tTable.readProbTable(tfile.c_str()); aTable.readTable(afile.c_str()); m3.dTable.readTable(dfile.c_str()); m3.nTable.readNTable(nfile.c_str()); sentPair sent ; double p0; ifstream p0f(p0file.c_str()); p0f >> p0; d4model d4m(MAX_SENTENCE_LENGTH); d4m.makeWordClasses(m1.Elist,m1.Flist,SourceVocabFilename+".classes",TargetVocabFilename+".classes"); d4m.readProbTable(d4file.c_str()); //d5model d5m(d4m); //d5m.makeWordClasses(m1.Elist,m1.Flist,SourceVocabFilename+".classes",TargetVocabFilename+".classes"); //d5m.readProbTable(d5file.c_str()); makeSetCommand("model4smoothfactor","0.0",getGlobalParSet(),2); //makeSetCommand("model5smoothfactor","0.0",getGlobalParSet(),2); if( corpus||testCorpus ) { sentenceHandler *x=corpus; if(x==0) x=testCorpus; cout << "Text corpus exists.\n"; x->rewind(); while(x&&x->getNextSentence(sent)){ Vector<WordIndex>& es = sent.eSent; Vector<WordIndex>& fs = sent.fSent; int l=es.size()-1; int m=fs.size()-1; transpair_model4 tm4(es,fs,m1.tTable,m2.aTable,m3.dTable,m3.nTable,1-p0,p0,&d4m); alignment al(l,m); cout << "I use the alignment " << sent.sentenceNo-1 << '\n'; //convert(ReferenceAlignment[sent.sentenceNo-1],al); transpair_model3 tm3(es,fs,m1.tTable,m2.aTable,m3.dTable,m3.nTable,1-p0,p0,0); double p=tm3.prob_of_target_and_alignment_given_source(al,1); cout << "Sentence " << sent.sentenceNo << " has IBM-3 prob " << p << '\n'; p=tm4.prob_of_target_and_alignment_given_source(al,3,1); cout << "Sentence " << sent.sentenceNo << " has IBM-4 prob " << p << '\n'; //transpair_model5 tm5(es,fs,m1.tTable,m2.aTable,m3.dTable,m3.nTable,1-p0,p0,&d5m); //p=tm5.prob_of_target_and_alignment_given_source(al,3,1); //cout << "Sentence " << sent.sentenceNo << " has IBM-5 prob " << p << '\n'; } } else { cout << "No corpus exists.\n"; } }
//=========================================================================== void SplineCurve::appendCurve(ParamCurve* other_curve, int continuity, double& dist, bool repar) //=========================================================================== { SplineCurve* other_cv = dynamic_cast<SplineCurve*>(other_curve); ALWAYS_ERROR_IF(other_cv == 0, "Given an empty curve or not a SplineCurve."); ALWAYS_ERROR_IF(dim_ != other_cv->dimension(), "The curves must lie in the same space."); ALWAYS_ERROR_IF(continuity < -1 || continuity + 1 > order(), "Specified continuity not attainable."); #ifdef DEBUG // DEBUG OUTPUT std::ofstream of0("basis0.g2"); writeStandardHeader(of0); write(of0); other_cv->writeStandardHeader(of0); other_cv->write(of0); #endif // Making sure the curves have the same order. Raise if necessary. int diff_order = order() - other_cv->order(); if (diff_order > 0) other_cv->raiseOrder(diff_order); else if (diff_order < 0) raiseOrder(abs(diff_order)); // Make sure that we have k-regularity at meeting ends. makeKnotEndRegular(); other_cv->makeKnotStartRegular(); // Ensure that either none of the curves or both are rational if (rational_ && !other_cv->rational()) other_cv->representAsRational(); if (!rational_ && other_cv->rational()) representAsRational(); #ifdef DEBUG // DEBUG OUTPUT std::ofstream of1("basis1.g2"); writeStandardHeader(of1); write(of1); other_cv->writeStandardHeader(of1); other_cv->write(of1); #endif if (rational_) { // Set end weight to 1 setBdWeight(1.0, false); other_cv->setBdWeight(1.0, true); } // Reparametrization (translatation and mult.) of other_cv->basis().knots_ . if (repar && continuity > 0) { if (rational_) { // The weights corresponding to the two coefficients close to the // joints should be equal equalBdWeights(false); other_cv->equalBdWeights(true); } } #ifdef DEBUG // DEBUG OUTPUT std::ofstream of1_2("basis1_2.g2"); writeStandardHeader(of1_2); write(of1_2); other_cv->writeStandardHeader(of1_2); other_cv->write(of1_2); #endif #ifdef DEBUG // DEBUG OUTPUT std::ofstream of2("basis2.dat"); basis_.write(of2); of2 << std::endl; other_cv->basis_.write(of2); of2 << std::endl; #endif if (continuity > -1 && rational_) { // Make sure that the rational curves have equal weights in the end int k2 = (numCoefs() - 1) * (dim_+1); double frac = rcoefs_[k2+dim_]/other_cv->rcoefs_[dim_]; int kn = other_cv->numCoefs(); for (int j=0; j<kn*(dim_+1); ++j) other_cv->rcoefs_[j] *= frac; } #ifdef DEBUG // DEBUG OUTPUT std::ofstream of3("basis3.dat"); basis_.write(of3); of3 << std::endl; other_cv->basis_.write(of3); of3 << std::endl; #endif if (repar && continuity > 0) { double sum1 = 0; double sum2 = 0; if (rational_) { int k2 = (numCoefs() - 1) * (dim_+1); int k1 = (numCoefs() - 2) * (dim_+1); for (int j = 0; j < dim_; ++j) { double t0 = (rcoefs_[k2 + j] - rcoefs_[k1 + j])*rcoefs_[k2 + dim_] - rcoefs_[k2 + j]*(rcoefs_[k2 + dim_] - rcoefs_[k1 + dim_]); sum1 += t0*t0; } sum1 = sqrt(sum1)/(rcoefs_[k2+dim_]*rcoefs_[k2+dim_]); k2 = dim_+1; k1 = 0; for (int j = 0; j < dim_; ++j) { double t0 = (other_cv->rcoefs_[k2 + j] - other_cv->rcoefs_[k1 + j])*other_cv->rcoefs_[k1 + dim_] - other_cv->rcoefs_[k1 + j]*(other_cv->rcoefs_[k2 + dim_] - other_cv->rcoefs_[k1 + dim_]); sum2 += t0*t0; } sum2 = sqrt(sum2)/(other_cv->rcoefs_[k1+dim_]*other_cv->rcoefs_[k1+dim_]); } else { for (int j = 0; j < dim_; ++j) { sum1 += (coefs_[(numCoefs() - 1) * dim_ + j] - coefs_[(numCoefs() - 2) * dim_ + j]) * (coefs_[(numCoefs() - 1) * dim_ + j] - coefs_[(numCoefs() - 2) * dim_ + j]); sum2 += (other_cv->coefs_[dim_ + j] - other_cv->coefs_[j]) * (other_cv->coefs_[dim_ + j] - other_cv->coefs_[j]); } sum1 = sqrt(sum1); sum2 = sqrt(sum2); } #ifdef DEBUG // DEBUG OUTPUT std::ofstream of4("basis4.dat"); basis_.write(of4); of4 << std::endl; other_cv->basis_.write(of4); of4 << std::endl; #endif if (sum1 > 1.0e-14) { // @@sbr We should have a universal noise-tolerance. double del1 = basis_.begin()[numCoefs()] - basis_.begin()[numCoefs() - 1]; double del2 = other_cv->basis_.begin()[order()] - other_cv->basis_.begin()[order() - 1]; double k = sum2*del1/(sum1*del2); other_cv->basis_.rescale(endparam(), endparam() + k * (other_cv->basis_.begin() [other_cv->numCoefs() + order() - 1] - other_cv->basis_.startparam())); } else { MESSAGE("Curve seems to be degenerated in end pt!"); } } else { other_cv->basis_.rescale(endparam(), endparam() + (other_cv->basis_.begin() [other_cv->numCoefs() + order() - 1] - other_cv->basis_.startparam())); } // Join the curve-segments (i.e. set endpoints equal), given that... if (continuity != -1) { for (int j = 0; j < dim_; ++j) { other_cv->coefs_[j] = coefs_[(numCoefs() - 1)*dim_ + j] = (coefs_[(numCoefs() - 1)*dim_ + j] + other_cv->coefs_[j])/2; } } double tpar = basis_.endparam(); int ti = numCoefs() + order() - 1; // Index of last occurence of tpar. #ifdef DEBUG // DEBUG OUTPUT std::ofstream of5("basis5.dat"); basis_.write(of5); of5 << std::endl; other_cv->basis_.write(of5); of5 << std::endl; #endif // Add other_cv's coefs. if (rational_) { // Ensure identity of the weight in the joint other_cv->setBdWeight(rcoefs_[rcoefs_.size()-1], true); rcoefs_.insert(rcoefs_end(), other_cv->rcoefs_begin(), other_cv->rcoefs_end()); } else coefs_.insert(coefs_end(), other_cv->coefs_begin(), other_cv->coefs_end()); #ifdef DEBUG // DEBUG OUTPUT std::ofstream of("basis.dat"); basis_.write(of); of << std::endl; other_cv->basis_.write(of); of << std::endl; #endif // Make an updated basis_ . std::vector<double> new_knotvector; std::copy(basis_.begin(), basis_.end(), std::back_inserter(new_knotvector)); std::copy(other_cv->basis_.begin() + order(), other_cv->basis_.end(), std::back_inserter(new_knotvector)); basis_ = BsplineBasis(order(), new_knotvector.begin(), new_knotvector.end()); if (rational_) updateCoefsFromRcoefs(); SplineCurve orig_curve = *this; // Save curve for later estimates. // Obtain wanted smoothness. int i; try { for (i = 0; i < continuity + 1; ++i) removeKnot(tpar); } catch (...) { // Leave the knots } // Estimate distance between curve and smoothed curve: // Raise (copy of) smoothed curve to original spline space // and calculate max distance between corresponding spline-coefs. SplineCurve raised_smooth_curve = *this; std::vector<double> knots; for (i = 0; i < continuity + 1; ++i) knots.push_back(tpar); raised_smooth_curve.insertKnot(knots); double sum, root_sum; dist = 0; for (i = std::max(0, ti - (continuity + 1) - order()); i < ti - order() + continuity + 1; ++i) { sum = 0; for (int j = 0; j < dim_; ++j) sum += (orig_curve.coefs_[i * dim_ + j] - raised_smooth_curve.coefs_[i * dim_ + j]) * (orig_curve.coefs_[i * dim_ + j] - raised_smooth_curve.coefs_[i * dim_ + j]); // to avoid use of the max function, which is likely to cause // trouble with the Microsoft Visual C++ Compiler, the following // two lines are added, and the third one is commented out. root_sum = sqrt(sum); dist = dist > root_sum ? dist : root_sum; //dist = std::max(dist, sqrt(sum)); } }
void calcv2(){ const int ncent = 6; const int npt = 25; int centbin[ncent+1] = {0,5,10,20,40,60,100}; gStyle->SetOptFit(kFALSE); gStyle->SetOptStat(kFALSE); ifstream fcntbbc("c1_c2_central_ptfiner_south.dat"); ifstream fcntbbcIn("c1_c2_central_ptIn_south.dat"); ifstream fcntfvtx("c1_c2_central_ptfiner_north.dat"); ifstream fcntfvtxIn("c1_c2_central_ptIn_north.dat"); ifstream fbbcfvtx("c1_c2_central_ptIn_sn.dat"); float c1cntbbc[ncent][npt], c2cntbbc[ncent][npt], c3cntbbc[ncent][npt]; float c1cntbbcIn[ncent][npt], c2cntbbcIn[ncent][npt], c3cntbbcIn[ncent][npt]; float c1cntfvtx[ncent][npt], c2cntfvtx[ncent][npt], c3cntfvtx[ncent][npt]; float c1cntfvtxIn[ncent][npt], c2cntfvtxIn[ncent][npt], c3cntfvtxIn[ncent][npt]; float c1bbcfvtx[ncent][npt], c2bbcfvtx[ncent][npt], c3bbcfvtx[ncent][npt]; float c1errcntbbc[ncent][npt], c2errcntbbc[ncent][npt], c3errcntbbc[ncent][npt]; float c1errcntbbcIn[ncent][npt], c2errcntbbcIn[ncent][npt], c3errcntbbcIn[ncent][npt]; float c1errcntfvtx[ncent][npt], c2errcntfvtx[ncent][npt], c3errcntfvtx[ncent][npt]; float c1errcntfvtxIn[ncent][npt], c2errcntfvtxIn[ncent][npt], c3errcntfvtxIn[ncent][npt]; float c1errbbcfvtx[ncent][npt], c2errbbcfvtx[ncent][npt], c3errbbcfvtx[ncent][npt]; ifstream PPfcntbbc("c1_c2_PP_centIn_south.dat"); ifstream PPfcntbbcIn("c1_c2_PP_ptIn_south.dat"); ifstream PPfcntfvtx("c1_c2_PP_centIn_north.dat"); ifstream PPfcntfvtxIn("c1_c2_PP_ptIn_north.dat"); ifstream PPfbbcfvtx("c1_c2_bbcfvtx_PP_centIn.dat"); float c1PPcntbbc[ncent][npt], c2PPcntbbc[ncent][npt], c3PPcntbbc[ncent][npt]; float c1PPcntbbcIn[ncent][npt], c2PPcntbbcIn[ncent][npt], c3PPcntbbcIn[ncent][npt]; float c1PPcntfvtx[ncent][npt], c2PPcntfvtx[ncent][npt], c3PPcntfvtx[ncent][npt]; float c1PPcntfvtxIn[ncent][npt], c2PPcntfvtxIn[ncent][npt], c3PPcntfvtxIn[ncent][npt]; float c1PPbbcfvtx[ncent][npt], c2PPbbcfvtx[ncent][npt], c3PPbbcfvtx[ncent][npt]; float c1PPerrcntbbc[ncent][npt], c2PPerrcntbbc[ncent][npt], c3PPerrcntbbc[ncent][npt]; float c1PPerrcntbbcIn[ncent][npt], c2PPerrcntbbcIn[ncent][npt], c3PPerrcntbbcIn[ncent][npt]; float c1PPerrcntfvtx[ncent][npt], c2PPerrcntfvtx[ncent][npt], c3PPerrcntfvtx[ncent][npt]; float c1PPerrcntfvtxIn[ncent][npt], c2PPerrcntfvtxIn[ncent][npt], c3PPerrcntfvtxIn[ncent][npt]; float c1PPerrbbcfvtx[ncent][npt], c2PPerrbbcfvtx[ncent][npt], c3PPerrbbcfvtx[ncent][npt]; float tmp; int scale = 1; //0: use c1 as scale factor 1: use multiplicity as scale factor //--------------Multiplicity----------------------- float MPPbbc[ncent] = {3.8,1,1,1,1,1}; float Mbbc[ncent]= {58.9,1,1,1,1,1}; float MPPfvtx[ncent] = {0.57,1,1,1,1,1}; float Mfvtx[ncent] = {4,1,1,1,1,1}; //MPPNpart[0] = 2; //MNpart[0] = 11; float MPPNpart[ncent] = {3.8,1,1,1,1,1}; //use bbc float MNpart[ncent] = {58.9,1,1,1,1,1}; //use bbc //--------------read in parameters-------------------------------------------- for(int icent=0;icent<ncent;icent++){ //output txt ofstream of1(Form("v2cntbbcs_cent%d.dat",icent)); ofstream of2(Form("v2cntfvtxs_cent%d.dat",icent)); ofstream of(Form("v2_cent%d.dat",icent)); ofstream ofsub1(Form("v2cntbbcs_cent%d_scale%d.dat",icent,scale)); ofstream ofsub2(Form("v2cntfvtxs_cent%d_scale%d.dat",icent,scale)); ofstream ofsub(Form("v2_cent%d_scale%d.dat",icent,scale)); fcntbbcIn>>c1cntbbcIn[icent][0]>>c1errcntbbcIn[icent][0]>>c2cntbbcIn[icent][0]>>c2errcntbbcIn[icent][0]>>c3cntbbcIn[icent][0]>>c3errcntbbcIn[icent][0]; fcntfvtxIn>>c1cntfvtxIn[icent][0]>>c1errcntfvtxIn[icent][0]>>c2cntfvtxIn[icent][0]>>c2errcntfvtxIn[icent][0]>>c3cntfvtxIn[icent][0]>>c3errcntfvtxIn[icent][0]; fbbcfvtx>>c1bbcfvtx[icent][0]>>c1errbbcfvtx[icent][0]>>c2bbcfvtx[icent][0]>>c2errbbcfvtx[icent][0]>>c3bbcfvtx[icent][0]>>c3errbbcfvtx[icent][0]; PPfcntbbcIn>>c1PPcntbbcIn[icent][0]>>c1PPerrcntbbcIn[icent][0]>>c2PPcntbbcIn[icent][0]>>c2PPerrcntbbcIn[icent][0]>>c3PPcntbbcIn[icent][0]>>c3PPerrcntbbcIn[icent][0]; PPfcntfvtxIn>>c1PPcntfvtxIn[icent][0]>>c1PPerrcntfvtxIn[icent][0]>>c2PPcntfvtxIn[icent][0]>>c2PPerrcntfvtxIn[icent][0]>>c3PPcntfvtxIn[icent][0]>>c3PPerrcntfvtxIn[icent][0]; PPfbbcfvtx>>c1PPbbcfvtx[icent][0]>>c1PPerrbbcfvtx[icent][0]>>c2PPbbcfvtx[icent][0]>>c2PPerrbbcfvtx[icent][0]>>c3PPbbcfvtx[icent][0]>>c3PPerrbbcfvtx[icent][0]; // fcntbbcIn>>tmp>>tmp>>c1cntbbcIn[icent][0]>>c1errcntbbcIn[icent][0]>>c2cntbbcIn[icent][0]>>c2errcntbbcIn[icent][0]; // fcntfvtxIn>>tmp>>tmp>>c1cntfvtxIn[icent][0]>>c1errcntfvtxIn[icent][0]>>c2cntfvtxIn[icent][0]>>c2errcntfvtxIn[icent][0]; // fbbcfvtx>>tmp>>tmp>>c1bbcfvtx[icent][0]>>c1errbbcfvtx[icent][0]>>c2bbcfvtx[icent][0]>>c2errbbcfvtx[icent][0]; for(int ipt=0;ipt<npt;ipt++){ fcntbbc>>c1cntbbc[icent][ipt]>>c1errcntbbc[icent][ipt]>>c2cntbbc[icent][ipt]>>c2errcntbbc[icent][ipt]>>c3cntbbc[icent][ipt]>>c3errcntbbc[icent][ipt]; fcntfvtx>>c1cntfvtx[icent][ipt]>>c1errcntfvtx[icent][ipt]>>c2cntfvtx[icent][ipt]>>c2errcntfvtx[icent][ipt]>>c3cntfvtx[icent][ipt]>>c3errcntfvtx[icent][ipt]; PPfcntbbc>>c1PPcntbbc[icent][ipt]>>c1PPerrcntbbc[icent][ipt]>>c2PPcntbbc[icent][ipt]>>c2PPerrcntbbc[icent][ipt]>>c3PPcntbbc[icent][ipt]>>c3PPerrcntbbc[icent][ipt]; PPfcntfvtx>>c1PPcntfvtx[icent][ipt]>>c1PPerrcntfvtx[icent][ipt]>>c2PPcntfvtx[icent][ipt]>>c2PPerrcntfvtx[icent][ipt]>>c3PPcntfvtx[icent][ipt]>>c3PPerrcntfvtx[icent][ipt]; } cout<<"icent: "<<centbin[icent] << "\% to " << centbin[icent+1]<< "\%"<<endl; cout<<"cnt - bbc "<<c2cntbbcIn[icent][0]<<" "<<c2errcntbbcIn[icent][0]<<endl; cout<<"cnt - fvtx "<<c2cntfvtxIn[icent][0]<<" "<<c2errcntfvtxIn[icent][0]<<endl; cout<<"bbc - fvtx "<<c2bbcfvtx[icent][0]<<" "<<c2errbbcfvtx[icent][0]<<endl; cout<<"cnt - bbc PP"<<c2PPcntbbcIn[icent][0]<<" "<<c2PPerrcntbbcIn[icent][0]<<endl; cout<<"cnt - fvtx PP"<<c2PPcntfvtxIn[icent][0]<<" "<<c2PPerrcntfvtxIn[icent][0]<<endl; cout<<"bbc - fvtx PP"<<c2PPbbcfvtx[icent][0]<<" "<<c2PPerrbbcfvtx[icent][0]<<endl; //---------------calculating cnt/bbc/fvtx inclusive v2------------------------------ if(c2cntbbcIn[icent][0]*c2cntfvtxIn[icent][0]/c2bbcfvtx[icent][0]<=0) {cout<<"negative?"<<endl; continue;} float v2cnt = sqrt(c2cntbbcIn[icent][0]*c2cntfvtxIn[icent][0]/c2bbcfvtx[icent][0]); //float v2errcnt = 1/2.*v2cnt*sqrt(TMath::Power(c2errcntbbcIn[icent][0]/c2cntbbcIn[icent][0],2)+TMath::Power(c2errcntfvtxIn[icent][0]/c2cntfvtxIn[icent][0],2)+TMath::Power(c2errbbcfvtx[icent][0]/c2bbcfvtx[icent][0],2)); float v2errcnt = get3sqerr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0]); float v2bbc = c2cntbbcIn[icent][0]/v2cnt; //float v2errbbc = v2bbc * sqrt(TMath::Power(c2errcntbbcIn[icent][0]/c2cntbbcIn[icent][0],2)+TMath::Power(v2errcnt/v2cnt,2)); float v2errbbc = get2derr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],v2cnt,v2errcnt); float v2fvtx = c2cntfvtxIn[icent][0]/v2cnt; //float v2errfvtx = v2fvtx * sqrt(TMath::Power(c2errcntfvtxIn[icent][0]/c2cntfvtxIn[icent][0],2)+TMath::Power(v2errcnt/v2cnt,2)); float v2errfvtx = get2derr(c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],v2cnt,v2errcnt); cout<<"Integral v2 cnt = "<<v2cnt<<" "<<v2errcnt<<endl; cout<<"Integral v2 bbc = "<<v2bbc<<" "<<v2errbbc<<endl; cout<<"Integral v2 fvtx = "<<v2fvtx<<" "<<v2errfvtx<<endl; //------------calculating cnt pt dependence v2--------------------method1---------------- float v2cntpt1[ncent][npt], v2errcntpt1[ncent][npt]; float v2cntpt2[ncent][npt], v2errcntpt2[ncent][npt]; float ptmean[npt]; for(int ipt=0;ipt<npt;ipt++){ v2cntpt1[icent][ipt] = c2cntbbc[icent][ipt]/v2bbc; //v2errcntpt1[icent][ipt] = v2cntpt1[icent][ipt]*sqrt(TMath::Power(c2errcntbbc[icent][ipt]/c2cntbbc[icent][ipt],2)+TMath::Power(v2errbbc/v2bbc,2)); v2errcntpt1[icent][ipt] = get2derr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],v2bbc,v2errbbc); v2cntpt2[icent][ipt] = c2cntfvtx[icent][ipt]/v2fvtx; //v2errcntpt2[icent][ipt] = v2cntpt2[icent][ipt]*sqrt(TMath::Power(c2errcntfvtx[icent][ipt]/c2cntfvtx[icent][ipt],2)+TMath::Power(v2errfvtx/v2fvtx,2)); v2errcntpt2[icent][ipt] = get2derr(c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],v2bbc,v2errbbc); ptmean[ipt] = 0.1+0.2*ipt; } //------------calculating cnt pt dependence v2--------------------method2---------------- float v2cntpt[ncent][npt]; float v2errcntpt[ncent][npt]; for(int ipt=0;ipt<npt;ipt++){ v2cntpt[icent][ipt] = sqrt(c2cntbbc[icent][ipt]*c2cntfvtx[icent][ipt]/c2bbcfvtx[icent][0]); //v2errcntpt[icent][ipt] = v2cntpt[icent][ipt]*sqrt(TMath::Power(c2errcntbbc[icent][ipt]/c2cntbbc[icent][ipt],2)+TMath::Power(c2errcntfvtx[icent][ipt]/c2cntfvtx[icent][ipt],2)+TMath::Power(c2errbbcfvtx[icent][0]/c2bbcfvtx[icent][0],2)); v2errcntpt[icent][ipt] = get3sqerr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0]); of1<<ptmean[ipt]<<" "<<v2cntpt1[icent][ipt]<<" "<<v2errcntpt1[icent][ipt]<<endl; of2<<ptmean[ipt]<<" "<<v2cntpt2[icent][ipt]<<" "<<v2errcntpt2[icent][ipt]<<endl; of<<ptmean[ipt]<<" "<<v2cntpt[icent][ipt]<<" "<<v2errcntpt[icent][ipt]<<endl; } of1.close(); of2.close(); of.close(); //----subtract---------calculating cnt/bbc/fvtx inclusive v2------------------------------ if(scale==0){ c2cntbbcIn[icent][0] = c2cntbbcIn[icent][0] - c2PPcntbbcIn[icent][0]*c1cntbbcIn[icent][0]/c1PPcntbbcIn[icent][0]; c2cntfvtxIn[icent][0] = c2cntfvtxIn[icent][0] - c2PPcntfvtxIn[icent][0]*c1cntfvtxIn[icent][0]/c1PPcntfvtxIn[icent][0]; c2bbcfvtx[icent][0] = c2bbcfvtx[icent][0] - c2PPbbcfvtx[icent][0]*c1bbcfvtx[icent][0]/c1PPbbcfvtx[icent][0]; c2errcntbbcIn[icent][0] = get2mierr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],c2PPcntbbcIn[icent][0]*c1cntbbcIn[icent][0]/c1PPcntbbcIn[icent][0], get3err(c2PPcntbbcIn[icent][0],c2PPerrcntbbcIn[icent][0],c1cntbbcIn[icent][0],c1errcntbbcIn[icent][0],c1PPcntbbcIn[icent][0],c1PPerrcntbbcIn[icent][0])); c2errcntfvtxIn[icent][0] = get2mierr(c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],c2PPcntfvtxIn[icent][0]*c1cntfvtxIn[icent][0]/c1PPcntfvtxIn[icent][0], get3err(c2PPcntfvtxIn[icent][0],c2PPerrcntfvtxIn[icent][0],c1cntfvtxIn[icent][0],c1errcntfvtxIn[icent][0],c1PPcntfvtxIn[icent][0],c1PPerrcntfvtxIn[icent][0])); c2errbbcfvtx[icent][0] = get2mierr(c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0],c2PPbbcfvtx[icent][0]*c1bbcfvtx[icent][0]/c1PPbbcfvtx[icent][0], get3err(c2PPbbcfvtx[icent][0],c2PPerrbbcfvtx[icent][0],c1bbcfvtx[icent][0],c1errbbcfvtx[icent][0],c1PPbbcfvtx[icent][0],c1PPerrbbcfvtx[icent][0])); } else{ c2cntbbcIn[icent][0] = c2cntbbcIn[icent][0] - c2PPcntbbcIn[icent][0]*MPPbbc[icent]/Mbbc[icent]; c2cntfvtxIn[icent][0] = c2cntfvtxIn[icent][0] - c2PPcntfvtxIn[icent][0]*MPPfvtx[icent]/Mfvtx[icent]; c2bbcfvtx[icent][0] = c2bbcfvtx[icent][0] - c2PPbbcfvtx[icent][0]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent]); c2errcntbbcIn[icent][0] = get2mierr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],c2PPcntbbcIn[icent][0]*MPPbbc[icent]/Mbbc[icent],c2PPerrcntbbcIn[icent][0]*MPPbbc[icent]/Mbbc[icent]); c2errcntfvtxIn[icent][0] = get2mierr(c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],c2PPcntfvtxIn[icent][0]*MPPfvtx[icent]/Mfvtx[icent],c2PPerrcntfvtxIn[icent][0]*MPPfvtx[icent]/Mfvtx[icent]); c2errbbcfvtx[icent][0] = get2mierr(c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0],c2PPbbcfvtx[icent][0]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent]),c2PPerrbbcfvtx[icent][0]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent])); } cout<<"cnt - bbc subtract ="<<c2cntbbcIn[icent][0]<<" "<<c2errcntbbcIn[icent][0]<<endl; cout<<"cnt - fvtx subtract ="<<c2cntfvtxIn[icent][0]<<" "<<c2errcntfvtxIn[icent][0]<<endl; cout<<"bbc - fvtx subtract ="<<c2bbcfvtx[icent][0]<<" "<<c2errbbcfvtx[icent][0]<<endl; float v2cnt = sqrt(c2cntbbcIn[icent][0]*c2cntfvtxIn[icent][0]/c2bbcfvtx[icent][0]); // float v2errcnt = 1/2.*v2cnt*sqrt(TMath::Power(c2errcntbbcIn[icent][0]/c2cntbbcIn[icent][0],2)+TMath::Power(c2errcntfvtxIn[icent][0]/c2cntfvtxIn[icent][0],2)+TMath::Power(c2errbbcfvtx[icent][0]/c2bbcfvtx[icent][0],2)); float v2errcnt = get3sqerr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0]); float v2bbc = c2cntbbcIn[icent][0]/v2cnt; //float v2errbbc = v2bbc * sqrt(TMath::Power(c2errcntbbcIn[icent][0]/c2cntbbcIn[icent][0],2)+TMath::Power(v2errcnt/v2cnt,2)); float v2errbbc = get2derr(c2cntbbcIn[icent][0],c2errcntbbcIn[icent][0],v2cnt,v2errcnt); float v2fvtx = c2cntfvtxIn[icent][0]/v2cnt; //float v2errfvtx = v2fvtx * sqrt(TMath::Power(c2errcntfvtxIn[icent][0]/c2cntfvtxIn[icent][0],2)+TMath::Power(v2errcnt/v2cnt,2)); float v2errfvtx = get2derr(c2cntfvtxIn[icent][0],c2errcntfvtxIn[icent][0],v2cnt,v2errcnt); cout<<"Integral v2 subtract cnt = "<<v2cnt<<" "<<v2errcnt<<endl; cout<<"Integral v2 subtract bbc = "<<v2bbc<<" "<<v2errbbc<<endl; cout<<"Integral v2 subtract fvtx = "<<v2fvtx<<" "<<v2errfvtx<<endl; //----subtract--------calculating cnt pt dependence v2--------------------method1---------------- float v2cntpt1[ncent][npt], v2errcntpt1[ncent][npt]; float v2cntpt2[ncent][npt], v2errcntpt2[ncent][npt]; float ptmean[npt]; for(int ipt=0;ipt<npt;ipt++){ if(scale==0){ c2cntbbc[icent][ipt] = c2cntbbc[icent][ipt] - c2PPcntbbc[icent][ipt]*c1cntbbc[icent][ipt]/c1PPcntbbc[icent][ipt]; c2cntfvtx[icent][ipt] = c2cntfvtx[icent][ipt] - c2PPcntfvtx[icent][ipt]*c1cntfvtx[icent][ipt]/c1PPcntfvtx[icent][ipt]; c2bbcfvtx[icent][ipt] = c2bbcfvtx[icent][ipt] - c2PPbbcfvtx[icent][ipt]*c1bbcfvtx[icent][ipt]/c1PPbbcfvtx[icent][ipt]; c2errcntbbc[icent][ipt] = get2mierr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],c2PPcntbbc[icent][ipt]*c1cntbbc[icent][ipt]/c1PPcntbbc[icent][ipt], get3err(c2PPcntbbc[icent][ipt],c2PPerrcntbbc[icent][ipt],c1cntbbc[icent][ipt],c1errcntbbc[icent][ipt],c1PPcntbbc[icent][ipt],c1PPerrcntbbc[icent][ipt])); c2errcntfvtx[icent][ipt] = get2mierr(c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],c2PPcntfvtx[icent][ipt]*c1cntfvtx[icent][ipt]/c1PPcntfvtx[icent][ipt], get3err(c2PPcntfvtx[icent][ipt],c2PPerrcntfvtx[icent][ipt],c1cntfvtx[icent][ipt],c1errcntfvtx[icent][ipt],c1PPcntfvtx[icent][ipt],c1PPerrcntfvtx[icent][ipt])); c2errbbcfvtx[icent][ipt] = get2mierr(c2bbcfvtx[icent][ipt],c2errbbcfvtx[icent][ipt],c2PPbbcfvtx[icent][ipt]*c1bbcfvtx[icent][ipt]/c1PPbbcfvtx[icent][ipt], get3err(c2PPbbcfvtx[icent][ipt],c2PPerrbbcfvtx[icent][ipt],c1bbcfvtx[icent][ipt],c1errbbcfvtx[icent][ipt],c1PPbbcfvtx[icent][ipt],c1PPerrbbcfvtx[icent][ipt])); } else{ c2cntbbc[icent][ipt] = c2cntbbc[icent][ipt] - c2PPcntbbc[icent][ipt]*MPPbbc[icent]/Mbbc[icent]; c2cntfvtx[icent][ipt] = c2cntfvtx[icent][ipt] - c2PPcntfvtx[icent][ipt]*MPPfvtx[icent]/Mfvtx[icent]; c2bbcfvtx[icent][ipt] = c2bbcfvtx[icent][ipt] - c2PPbbcfvtx[icent][ipt]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent]); c2errcntbbc[icent][ipt] = get2mierr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],c2PPcntbbc[icent][ipt]*MPPbbc[icent]/Mbbc[icent],c2PPerrcntbbc[icent][ipt]*MPPbbc[icent]/Mbbc[icent]); c2errcntfvtx[icent][ipt] = get2mierr(c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],c2PPcntfvtx[icent][ipt]*MPPfvtx[icent]/Mfvtx[icent],c2PPerrcntfvtx[icent][ipt]*MPPfvtx[icent]/Mfvtx[icent]); c2errbbcfvtx[icent][ipt] = get2mierr(c2bbcfvtx[icent][ipt],c2errbbcfvtx[icent][ipt],c2PPbbcfvtx[icent][ipt]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent]),c2PPerrbbcfvtx[icent][ipt]*(MPPbbc[icent]*MPPfvtx[icent]/MPPNpart[icent])/(Mbbc[icent]*Mfvtx[icent]/MNpart[icent])); } } for(int ipt=0;ipt<npt;ipt++){ v2cntpt1[icent][ipt] = c2cntbbc[icent][ipt]/v2bbc; //v2errcntpt1[icent][ipt] = v2cntpt1[icent][ipt]*sqrt(TMath::Power(c2errcntbbc[icent][ipt]/c2cntbbc[icent][ipt],2)+TMath::Power(v2errbbc/v2bbc,2)); v2errcntpt1[icent][ipt] = get2derr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],v2bbc,v2errbbc); v2cntpt2[icent][ipt] = c2cntfvtx[icent][ipt]/v2fvtx; //v2errcntpt2[icent][ipt] = v2cntpt2[icent][ipt]*sqrt(TMath::Power(c2errcntfvtx[icent][ipt]/c2cntfvtx[icent][ipt],2)+TMath::Power(v2errfvtx/v2fvtx,2)); v2errcntpt2[icent][ipt] = get2derr(c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],v2fvtx,v2errfvtx); ptmean[ipt] = 0.1+0.2*ipt; } //----subtract--------calculating cnt pt dependence v2--------------------method2---------------- float v2cntpt[ncent][npt]; float v2errcntpt[ncent][npt]; for(int ipt=0;ipt<npt;ipt++){ v2cntpt[icent][ipt] = sqrt(c2cntbbc[icent][ipt]*c2cntfvtx[icent][ipt]/c2bbcfvtx[icent][0]); //v2errcntpt[icent][ipt] = v2cntpt[icent][ipt]*sqrt(TMath::Power(c2errcntbbc[icent][ipt]/c2cntbbc[icent][ipt],2)+TMath::Power(c2errcntfvtx[icent][ipt]/c2cntfvtx[icent][ipt],2)+TMath::Power(c2errbbcfvtx[icent][0]/c2bbcfvtx[icent][0],2)); v2errcntpt[icent][ipt] = get3sqerr(c2cntbbc[icent][ipt],c2errcntbbc[icent][ipt],c2cntfvtx[icent][ipt],c2errcntfvtx[icent][ipt],c2bbcfvtx[icent][0],c2errbbcfvtx[icent][0]); ofsub1<<ptmean[ipt]<<" "<<v2cntpt1[icent][ipt]<<" "<<v2errcntpt1[icent][ipt]<<endl; ofsub2<<ptmean[ipt]<<" "<<v2cntpt2[icent][ipt]<<" "<<v2errcntpt2[icent][ipt]<<endl; ofsub<<ptmean[ipt]<<" "<<v2cntpt[icent][ipt]<<" "<<v2errcntpt[icent][ipt]<<endl; } ofsub1.close(); ofsub2.close(); ofsub.close(); } }