void main() { // 전역 함수의 포인터 void(*fp1)(int) = func; fp1(10); // Clazz::static_val = 0; // Clazz.static_val = 0; Clazz obj; obj.function(10); // Clazz::function(&obj, 10); }
void move_file(std::string const& old, std::string const& new_) { { std::ifstream fp1(new_.c_str()); if(!fp1) throw std::runtime_error( "couldn't open file '" + new_ + "' for reading" ); std::ifstream fp2(old.c_str()); if(fp2 && equal_streams(fp1, fp2)) return; } fs::create_directories(fs::parent_path(old)); fs::rename(new_.c_str(), old.c_str()); }
void KisFixedPointMathsTest::testOperatorsNegative() { KisFixedPoint fp1(qreal(-2.5)); KisFixedPoint fp2(2); KisFixedPoint fp3(-3); QCOMPARE(fp1 + fp2, KisFixedPoint(qreal(-0.5))); QCOMPARE(fp1 - fp2, KisFixedPoint(qreal(-4.5))); QCOMPARE(fp1 * fp2, KisFixedPoint(-5)); QCOMPARE(fp1 * fp3, KisFixedPoint(qreal(7.5))); QCOMPARE(fp2 / fp1, KisFixedPoint(qreal(-0.8))); QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(-1.25))); QCOMPARE(fp3 / fp1, KisFixedPoint(qreal(1.2))); }
sk_sp<GrFragmentProcessor> SkColorFilterShader::asFragmentProcessor(const AsFPArgs& args) const { sk_sp<GrFragmentProcessor> fp1(fShader->asFragmentProcessor(args)); if (!fp1) { return nullptr; } sk_sp<GrFragmentProcessor> fp2(fFilter->asFragmentProcessor(args.fContext)); if (!fp2) { return fp1; } sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(fp1), std::move(fp2) }; return GrFragmentProcessor::RunInSeries(fpSeries, 2); }
static void test_standalone_funcs() { printf("\r\n********** Starting test_standalone_funcs **********\r\n"); const char *testmsg1 = "Test message 1"; const char *testmsg2 = "Test message 2"; const int testint1 = 13; const double testdouble = 100.0; // First call function pointers directly FunctionPointer1<void, const char*> fp1(sa_func_1); FunctionPointer1<void, int> fp2(sa_func_2); FunctionPointer0<void> fp3(sa_func_3); FunctionPointer3<void, int, const char*, double> fp4(sa_func_4); call_fp1("ptr to standalone func(char*)", fp1, testmsg1); call_fp1("ptr to standalone func(char*)", fp1, testmsg2); call_fp1("ptr to standalone func(int)", fp2, testint1); call_fp0("ptr to standalone func(void)", fp3); call_fp3("ptr to standalong func(int, const char*, double)", fp4, testint1, testmsg1, testdouble); }
int main() { FP fp1; // 함수 포인터 별칭으로 변수 선언 fp1 = add; printf("%d\n", fp1(10, 20)); // 30 FP fp[10]; // 함수 포인터 별칭으로 배열 선언 fp[0] = add; printf("%d\n", fp[0](30, 40)); // 70 struct Calc c; c.fp = add; printf("%d\n", c.fp(50, 60)); // 110 executer(add); // 150: executer를 호출할 때 add 함수의 메모리 주소를 전달 return 0; }
int main (void) { void *h1; int (*fp1) (int); void *h2; int (*fp2) (int); int res1; int res2; mtrace (); h1 = dlopen ("testobj1.so", RTLD_LAZY); if (h1 == NULL) error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so", dlerror ()); h2 = dlopen ("testobj1_1.so", RTLD_LAZY); if (h1 == NULL) error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1_1.so", dlerror ()); fp1 = dlsym (h1, "obj1func1"); if (fp1 == NULL) error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s", "testobj1.so", dlerror ()); fp2 = dlsym (h2, "obj1func1"); if (fp2 == NULL) error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s", "testobj1_1.so", dlerror ()); res1 = fp1 (10); res2 = fp2 (10); printf ("fp1(10) = %d\nfp2(10) = %d\n", res1, res2); if (dlclose (h1) != 0) error (EXIT_FAILURE, 0, "cannot close testobj1.so: %s\n", dlerror ()); if (dlclose (h2) != 0) error (EXIT_FAILURE, 0, "cannot close testobj1_1.so: %s\n", dlerror ()); return res1 != 42 || res2 != 72; }
static void test_funcs_nontca() { printf("\r\n********** Starting test_funcs_nontca **********\r\n"); FunctionPointer1<void, MyArg> fp1(sa_ntc); Event e1, e2, e3; { // Test binding argument that gets out of scope at the end of this block MyArg arg("test", 10, 20); call_fp1("ptr to standalong func taking non-trivial arg", fp1, arg); e1 = e2 = e3 = fp1.bind(arg); } e1.call(); // This should work, since it has a copy of 'arg' above // Test functions taking non-trivial arguments inside classes ADerived d(10, 100); ABase *pDerived = &d; FunctionPointer1<void, MyArg> fp2(&d, &ADerived::print_virtual_arg); FunctionPointer1<void, MyArg> fp3(pDerived, &ABase::print_virtual_arg); call_fp1("ptr to virtual method taking non-tc argument", fp2, MyArg("notest", 5, 8)); call_fp1("ptr to virtual method taking non-tc argument (via base class pointer)", fp2, MyArg("notest", 5, 8)); }
static void test_array_of_events() { printf("\r\n********** Starting test_array_of_events **********\r\n"); const char* testmsg1 = "Test message 1"; const char* testmsg2 = "Test message 2"; const int testint = 13; VDerived derived(20, 100); MyArg arg("array", 5, 10); FunctionPointer1<void, const char*> fp1((VBase*)&derived, &VBase::print_virtual_str); FunctionPointer0<void> fp2(sa_func_3); FunctionPointer1<void, int> fp3(sa_func_2); FunctionPointer0<void> fp4(&derived, &VDerived::print_virtual_noargs); FunctionPointer1<void, MyArg> fp5(sa_ntc); Event events[] = {fp1.bind(testmsg1), fp1.bind(testmsg2), fp2.bind(), fp3.bind(testint), fp4.bind(), fp5.bind(arg)}; for (unsigned i = 0; i < sizeof(events)/sizeof(events[0]); i ++) { events[i].call(); } }
void KisFixedPointMathsTest::testConversionsNegative() { KisFixedPoint fp1(qreal(-2.5)); KisFixedPoint fp2(qreal(-2.73)); KisFixedPoint fp3(qreal(-2.34)); QCOMPARE(fp1.toInt(), -2); QCOMPARE(fp1.toIntRound(), -3); QCOMPARE(fp1.toIntFloor(), -3); QCOMPARE(fp1.toIntCeil(), -2); QCOMPARE(fp2.toInt(), -2); QCOMPARE(fp2.toIntRound(), -3); QCOMPARE(fp2.toIntFloor(), -3); QCOMPARE(fp2.toIntCeil(), -2); QCOMPARE(fp3.toInt(), -2); QCOMPARE(fp3.toIntRound(), -2); QCOMPARE(fp3.toIntFloor(), -3); QCOMPARE(fp3.toIntCeil(), -2); }
const GrFragmentProcessor* SkColorFilterShader::asFragmentProcessor( GrContext* context, const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality fq) const { SkAutoTUnref<const GrFragmentProcessor> fp1(fShader->asFragmentProcessor(context, viewM, localMatrix, fq)); if (!fp1.get()) { return nullptr; } SkAutoTUnref<const GrFragmentProcessor> fp2(fFilter->asFragmentProcessor(context)); if (!fp2.get()) { return fp1.release(); } const GrFragmentProcessor* fpSeries[] = { fp1.get(), fp2.get() }; return GrFragmentProcessor::RunInSeries(fpSeries, 2); }
PyObject *_PY_fp1(PyObject *self, PyObject *args, PyObject *kwds) {int ok; PyObject *_lo; int _la1; bool *_rv; char *kw_list[] = {"a1", NULL}; /* local variable initializations */ _la1 = 0; ok = PyArg_ParseTupleAndKeywords(args, kwds, "i:fp1_p", kw_list, &_la1); if (ok == FALSE) return(NULL); _rv = fp1(_la1); _lo = PY_build_object("fp1", G_BOOL_I, 0, &_rv, 0); return(_lo);}
void KisFixedPointMathsTest::testOperators() { KisFixedPoint fp1(1); KisFixedPoint fp2(2); KisFixedPoint fp3(qreal(2.5)); KisFixedPoint fp4(qreal(2.0)); QVERIFY(fp1 < fp2); QVERIFY(fp2 < fp3); QVERIFY(fp2 > fp1); QVERIFY(fp3 > fp2); QVERIFY(fp1 != fp2); QVERIFY(fp2 == fp4); QCOMPARE(fp1 + fp2, KisFixedPoint(3)); QCOMPARE(fp1 - fp2, KisFixedPoint(-1)); QCOMPARE(fp1 * fp2, KisFixedPoint(2)); QCOMPARE(fp2 * fp3, KisFixedPoint(5)); QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(0.5))); QCOMPARE(fp1 / fp3, KisFixedPoint(qreal(0.4))); QCOMPARE(fp2 / fp3, KisFixedPoint(qreal(0.8))); }
void KisFixedPointMathsTest::testConversions() { KisFixedPoint fp1(qreal(2.5)); KisFixedPoint fp2(qreal(2.73)); KisFixedPoint fp3(qreal(2.34)); QCOMPARE(fp1.toInt(), 2); QCOMPARE(fp1.toIntRound(), 3); QCOMPARE(fp1.toIntFloor(), 2); QCOMPARE(fp1.toIntCeil(), 3); QCOMPARE(fp1.toFloat(), qreal(2.5)); QCOMPARE(fp2.toInt(), 2); QCOMPARE(fp2.toIntRound(), 3); QCOMPARE(fp2.toIntFloor(), 2); QCOMPARE(fp2.toIntCeil(), 3); QCOMPARE(fp2.toFloat(), qreal(698.0/256.0)); QCOMPARE(fp3.toInt(), 2); QCOMPARE(fp3.toIntRound(), 2); QCOMPARE(fp3.toIntFloor(), 2); QCOMPARE(fp3.toIntCeil(), 3); QCOMPARE(fp3.toFloat(), qreal(599.0/256.0)); }
bool Frustum::bakeProjectionOffset() { // Nothing to bake if ortho if( mIsOrtho ) return false; // Nothing to bake if no offset if( mProjectionOffset.isZero() ) return false; // Near plane points in camera space Point3F np[4]; np[0].set( mNearLeft, mNearDist, mNearTop ); // NearTopLeft np[1].set( mNearRight, mNearDist, mNearTop ); // NearTopRight np[2].set( mNearLeft, mNearDist, mNearBottom ); // NearBottomLeft np[3].set( mNearRight, mNearDist, mNearBottom ); // NearBottomRight // Generate the near plane PlaneF nearPlane( np[0], np[1], np[3] ); // Far plane points in camera space const F32 farOverNear = mFarDist / mNearDist; Point3F fp0( mNearLeft * farOverNear, mFarDist, mNearTop * farOverNear ); // FarTopLeft Point3F fp1( mNearRight * farOverNear, mFarDist, mNearTop * farOverNear ); // FarTopRight Point3F fp2( mNearLeft * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomLeft Point3F fp3( mNearRight * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomRight // Generate the far plane PlaneF farPlane( fp0, fp1, fp3 ); // The offset camera point Point3F offsetCamera( mProjectionOffset.x, 0.0f, mProjectionOffset.y ); // The near plane point we'll be using for our calculations below U32 nIndex = 0; if( mProjectionOffset.x < 0.0 ) { // Offset to the left so we'll need to use the near plane point on the right nIndex = 1; } if( mProjectionOffset.y > 0.0 ) { // Offset to the top so we'll need to use the near plane point at the bottom nIndex += 2; } // Begin by calculating the offset point on the far plane as it goes // from the offset camera to the edge of the near plane. Point3F farPoint; Point3F fdir = np[nIndex] - offsetCamera; fdir.normalize(); if( farPlane.intersect(offsetCamera, fdir, &farPoint) ) { // Calculate the new near plane edge from the non-offset camera position // to the far plane point from above. Point3F nearPoint; Point3F ndir = farPoint; ndir.normalize(); if( nearPlane.intersect( Point3F::Zero, ndir, &nearPoint) ) { // Handle a x offset if( mProjectionOffset.x < 0.0 ) { // The new near plane right side mNearRight = nearPoint.x; } else if( mProjectionOffset.x > 0.0 ) { // The new near plane left side mNearLeft = nearPoint.x; } // Handle a y offset if( mProjectionOffset.y < 0.0 ) { // The new near plane top side mNearTop = nearPoint.y; } else if( mProjectionOffset.y > 0.0 ) { // The new near plane bottom side mNearBottom = nearPoint.y; } } } mDirty = true; // Indicate that we've modified the frustum return true; }
void minuitFit() { TH1F::SetDefaultSumw2(); TH1D::SetDefaultSumw2(); cout << "Must Use Same Binning as previous Analysis!" << endl; gStyle->SetOptFit(1111); gStyle->SetOptStat(0); haveName = kFALSE; char fname[100]; TFile* file; Bool_t makePDF = checkMakePDF(); Bool_t makeROOT = checkMakeRoot(); if(makeROOT){ sprintf(fname,"/Users/zach/Research/pythia/200GeVTemplate/FFOutput/%s_FIT.root",FileNameR); file = new TFile(fname,"RECREATE"); if (file->IsOpen()==kFALSE) { std::cout << "!!! Outfile Not Opened !!!" << std::endl; makeROOT = kFALSE; } } char name[1000]; sprintf(name,"/Users/zach/Research/pythia/200GeVTemplate/currentTemplate.root"); TFile *fT = new TFile(name,"READ"); sprintf(name,"/Users/zach/Research/rootFiles/run12NPEhPhi/currentData.root"); TFile *fD = new TFile(name,"READ"); if (fT->IsOpen()==kFALSE || fD->IsOpen()==kFALSE) { std::cout << "!!!!!! Either B,C, or Data File not found !!!!!!" << std::endl << "Looking for currentB.root, currentC.root, and currentData.root" << std::endl; exit(1); } // Set constants and projection bins (from header file anaConst, analysis constants) Float_t lowpt[numPtBins],highpt[numPtBins]; for(Int_t c=0; c< numPtBins; c++){ lowpt[c] = anaConst::lpt[c]; highpt[c] = anaConst::hpt[c]; } Float_t hptCut=anaConst::hptCut; // Make Canvases TCanvas* deltaPhi = new TCanvas("deltaPhi","Pythia Delta Phi",150,0,1150,1000); TCanvas* deltaPhi2 = new TCanvas("deltaPhi2","Pythia Delta Phi",150,0,1150,1000); TCanvas* fitResult0 = new TCanvas("fitResult0","RB Extraction HT0",150,0,1150,1000); TCanvas* fitResult2 = new TCanvas("fitResult2","RB Extraction HT2",150,0,1150,1000); TCanvas* fitResultC = new TCanvas("fitResultC","RB Extraction Combined Trigs",150,0,1150,1000); TCanvas* fitResultP = new TCanvas("fitResultP","RB Previous Analysis",150,0,1150,1000); TCanvas* scaleCheck = new TCanvas("scaleCheck","Check scale diff",150,0,1150,1000); TCanvas* prettyPlot = new TCanvas("prettyPlot","PrettyPlot",150,0,1150,1000); deltaPhi ->Divide(3,3); deltaPhi2 ->Divide(3,3); fitResult0->Divide(3,4); fitResult2->Divide(3,4); fitResultC->Divide(3,4); fitResultP->Divide(2,2); scaleCheck->Divide(1,2); // Get and Draw histos TPaveText* lbl[numPtBins]; TPaveText* stat[4][numPtBins]; char statLabel[100]; char textLabel[100]; Int_t plotbin; Double_t norm0,norm2,normB,normC; // Get ptbin independent hists histoNorms = (TH2F*)fD->Get("histoNorms"); // Get Previous Analysis TFile *file3 = new TFile("/Users/zach/Research/previousNPEhFigures/Chi2_25_35.root"); Hdphi[0] = (TH1D*)file3->Get("fit_25_35"); HpphiD[0] = (TH1D*)file3->Get("De_25_35"); HpphiB[0] = (TH1D*)file3->Get("Be_25_35"); TFile *file4 = new TFile("/Users/zach/Research/previousNPEhFigures/Chi2_55_65.root"); Hdphi[1] = (TH1D*)file4->Get("fit_55_65"); HpphiD[1] = (TH1D*)file4->Get("De_55_65"); HpphiB[1] = (TH1D*)file4->Get("Be_55_65"); for(Int_t ptbin=0; ptbin<numPtBins; ptbin++) { bPtNorms[ptbin] = (TH1F*)fT->Get(Form("beEventTally_%i",ptbin)); cPtNorms[ptbin] = (TH1F*)fT->Get(Form("ceEventTally_%i",ptbin)); norm0 = histoNorms->GetBinContent(histoNorms->GetBin(1,ptbin+1)); norm2 = histoNorms->GetBinContent(histoNorms->GetBin(3,ptbin+1)); normB = bPtNorms[ptbin]->GetBinContent(1); normC = cPtNorms[ptbin]->GetBinContent(1); cout << ptbin << "; 0: " << norm0 << " 2: " << norm2 << endl; if( norm0 == 0) { cout << ptbin << " For this bin, some norm0 = 0" << endl; continue; } if( norm2 == 0 ) { cout << ptbin << " For this bin, some norm2 = 0" << endl; continue; } if( normB == 0 ) { cout << ptbin << " For this bin, some normB = 0" << endl; continue; } if( normC == 0) { cout << ptbin << " For this bin, some normC = 0" << endl; continue; } plotbin = ptbin; // Init necessary plotting tools lbl[ptbin] = new TPaveText(.15,.15,.35,.23,Form("NB NDC%i",ptbin)); sprintf(textLabel,"%.1f < P_{T,e} < %.1f",lowpt[ptbin],highpt[ptbin]); lbl[ptbin]->AddText(textLabel); lbl[ptbin]->SetFillColor(kWhite); projB[ptbin] = (TH1D*)fT->Get(Form("hdPhiRawbe_%i",ptbin)); projC[ptbin] = (TH1D*)fT->Get(Form("hdPhiRawce_%i",ptbin)); projData0[ptbin]= (TH1D*)fD->Get(Form("NPEhDelPhi_0_%i",ptbin)); projData2[ptbin]= (TH1D*)fD->Get(Form("NPEhDelPhi_2_%i",ptbin)); pileupCorrect[ptbin][0] = (TH1D*)fD->Get(Form("pileupCorrection_%i_0",ptbin)); pileupCorrect[ptbin][1] = (TH1D*)fD->Get(Form("pileupCorrection_%i_2",ptbin)); pileupCorrect[ptbin][0]->Sumw2(); pileupCorrect[ptbin][1]->Sumw2(); // Do any rebinning Int_t RB = 1; projB[ptbin]->Rebin(RB); projC[ptbin]->Rebin(RB); projData0[ptbin]->Rebin(RB); projData2[ptbin]->Rebin(RB); // Clone to make plots without effecting fits plotD0[ptbin] = (TH1D*) projData0[ptbin]->Clone(); plotD2[ptbin] = (TH1D*) projData2[ptbin]->Clone(); plotB[ptbin] = (TH1D*) projB[ptbin]->Clone(); plotC[ptbin] = (TH1D*) projC[ptbin]->Clone(); // Set features that are the same in plots projData0[ptbin]->SetLineColor(kBlue); projData2[ptbin]->SetLineColor(kGreen+3); projB[ptbin]->SetLineColor(kRed); projC[ptbin]->SetLineColor(kBlack); projC[ptbin]->GetXaxis()->SetRangeUser(-3.5,3.5); plotD0[ptbin]->SetLineColor(kBlue); plotD2[ptbin]->SetLineColor(kGreen+3); plotD0[ptbin]->SetMarkerStyle(20); plotD0[ptbin]->SetMarkerColor(kBlue); plotD0[ptbin]->SetMarkerSize(0.4); plotB[ptbin]->SetLineColor(kRed); plotC[ptbin]->SetLineColor(kBlack); plotC[ptbin]->GetXaxis()->SetRangeUser(-3.5,3.5); combData[ptbin] = (TH1D*) projData0[ptbin]->Clone(); combData[ptbin] -> Add(projData2[ptbin]); combData[ptbin]->SetLineColor(kBlue); combData[ptbin]->SetMarkerStyle(20); combData[ptbin]->SetMarkerColor(kBlue); combData[ptbin]->SetMarkerSize(0.4); combData[ptbin]->SetTitle(""); // Normalize projB[ptbin] -> Scale(1./normB); projC[ptbin] -> Scale(1./normC); projData0[ptbin] -> Scale(1./norm0); projData2[ptbin] -> Scale(1./norm2); plotD0[ptbin] -> Scale(1./norm0); plotD2[ptbin] -> Scale(1./norm2); plotB[ptbin] -> Scale(1./normB); plotC[ptbin] -> Scale(1./normC); combData[ptbin] -> Scale(1./(norm0+norm2)); // Subtract Pileup correction (data only) projData0[ptbin]->Sumw2();projData2[ptbin]->Sumw2(); //projData0[ptbin]->Add(pileupCorrect[ptbin][0],-1); //projData2[ptbin]->Add(pileupCorrect[ptbin][1],-1); // Draw Templates on own plots if(ptbin+1 <= 9) deltaPhi->cd(plotbin+1); if(ptbin+1 > 9) deltaPhi2->cd(ptbin-8); plotC[ptbin]->GetYaxis()->SetRangeUser(-.1,0.8); plotC[ptbin] -> Draw("hist"); plotB[ptbin] -> Draw("same hist"); plotD0[ptbin] -> Draw("same"); plotD2[ptbin] -> Draw("same"); lbl[ptbin] -> Draw("same"); TLegend* leg = new TLegend(0.65,0.6,0.85,0.85); leg->AddEntry(projB[ptbin],"b#bar{b}->NPE","lpe"); leg->AddEntry(projC[ptbin],"c#bar{c}->NPE","lpe"); leg->AddEntry(projData0[ptbin],"HT0","lpe"); leg->AddEntry(projData2[ptbin],"HT2","lpe"); leg->Draw(); deltaPhi->cd(1); Hdphi[0]->Draw("same"); deltaPhi->cd(4); Hdphi[1]->Draw("same"); if(ptbin == 1) { prettyPlot->cd(); plotC[ptbin]->GetYaxis()->SetRangeUser(0,0.35); plotC[ptbin]->SetMarkerStyle(20); plotC[ptbin]->SetMarkerSize(0.6); plotB[ptbin]->SetMarkerStyle(21); plotB[ptbin]->SetMarkerSize(0.6); plotB[ptbin]->SetMarkerColor(kRed); plotD0[ptbin]->SetMarkerStyle(22); plotD0[ptbin]->SetMarkerSize(0.9); plotC[ptbin]->GetXaxis()->SetTitle("#Delta#phi_{NPE-h} (rad)"); plotC[ptbin]->GetYaxis()->SetTitle("#frac{1}{N_{NPE}} #frac{dN}{d(#Delta#phi)}"); plotC[ptbin]->DrawClone("P"); plotB[ptbin]->DrawClone("same P"); plotD0[ptbin]->DrawClone("same P"); TLegend* legPret = new TLegend(0.65,0.6,0.85,0.85); legPret->AddEntry(plotB[ptbin],"B #rightarrow NPE-h, Monte Carlo","LPE"); legPret->AddEntry(plotC[ptbin],"D #rightarrow NPE-h, Monte Carlo","LPE"); legPret->AddEntry(plotD0[ptbin],"NPE-h 2012 STAR Data","LPE"); lbl[ptbin]->Draw("same"); legPret->Draw("same"); } /*// Draw Scale Check scaleCheck->cd(1); TH1F* HT0 = (TH1F*) plotD0[0]->Clone(); HT0->Divide(HT0,Hdphi[0],1,1); HT0->Draw(); scaleCheck->cd(2); TH1F* HT2 = (TH1F*) plotD2[3]->Clone(); HT2->Divide(HT2,Hdphi[1],1,1); HT0->GetXaxis()->SetRangeUser(-3.5,3.5); HT2->GetXaxis()->SetRangeUser(-3.5,3.5); HT2->Draw(); lbl[ptbin]->Draw("same"); TLegend* legSC = new TLegend(0.65,0.6,0.85,0.85); legSC->AddEntry(HT0,"HT0/prevdata","lpe"); legSC->AddEntry(HT2,"HT2/prevdata","lpe"); legSC->Draw();*/ ///////////////////// // Do the actual fits ///////////////////// currentPtBin = ptbin; cout << "!!!!!!! HT0 ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; TMinuit* gMinuit = new TMinuit(1); gMinuit->SetFCN(chi2_0); currentPtBin = ptbin; doFit(gMinuit,p01[ptbin],p00[ptbin],e01[ptbin],e00[ptbin]); // assign to plotting variables if(highpt[ptbin] < 6) { pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; dx[plotCount0] = 0.; ptOFF1[plotCount0] = pT[ptbin]; Rb0[plotCount0] = p01[ptbin];///(p01[ptbin]+p00[ptbin]); eb0[plotCount0] = e01[ptbin]; plotCount0++; } // Plot results fitResult0->cd(ptbin+1); TH1D* dClone = (TH1D*) projData0[ptbin]->Clone(); TH1D* cClone = (TH1D*) projC[ptbin]->Clone(); TH1D* bClone = (TH1D*) projB[ptbin]->Clone(); stat[0][ptbin] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%i",ptbin)); sprintf(statLabel,"Chi2/NDF: %.2f/%.0f",curChi2,curNDF); stat[0][ptbin]->InsertText(statLabel); stat[0][ptbin]->SetFillColor(kWhite); cClone->Scale((1.-p01[ptbin])*p00[ptbin]); bClone->Scale(p00[ptbin]*p01[ptbin]); // scale by contribution param cClone->Add(bClone); //cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); dClone->Draw(); cClone->Draw("same"); stat[0][ptbin]->Draw("same"); lbl[ptbin]->Draw("same"); cout << "!!!!!!! HT2 ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; gMinuit->SetFCN(chi2_2); doFit(gMinuit,p21[ptbin],p20[ptbin],e21[ptbin],e20[ptbin]); // assign to plotting variables if(highpt[ptbin] > 3.6) { pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; ptOFF2[plotCount2] = pT[ptbin]; Rb2[plotCount2] = p21[ptbin];///(p21[ptbin]+p20[ptbin]); eb2[plotCount2] = e21[ptbin]; plotCount2++; } // Plot results fitResult2->cd(ptbin+1); dClone = (TH1D*) projData2[ptbin]->Clone(); cClone = (TH1D*) projC[ptbin]->Clone(); bClone = (TH1D*) projB[ptbin]->Clone(); stat[2][ptbin] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%i",ptbin)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[2][ptbin]->InsertText(statLabel); stat[2][ptbin]->SetFillColor(kWhite); cClone->Scale((1.-p21[ptbin])*p20[ptbin]); bClone->Scale(p20[ptbin]*p21[ptbin]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); dClone->Draw(); cClone->Draw("same"); stat[2][ptbin]->Draw("same"); lbl[ptbin]->Draw("same"); cout << "!!!!!!! HTC ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; gMinuit->SetFCN(chi2_C); doFit(gMinuit,pC1[ptbin],pC0[ptbin],eC1[ptbin],eC0[ptbin]); // assign to plotting variables pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; RbC[plotCount] = pC1[ptbin];///(p21[ptbin]+p20[ptbin]); ebC[plotCount] = eC1[ptbin]; plotCount++; } cout << "!!!!!!! Previous Data: 0"<<" !!!!!!!"<< endl; ////////// // 2.5-3.5 GeV Bin ////////// gMinuit->SetFCN(chi2_P0); doFit(gMinuit,RbP[0],SF[0],EbP[0],eSF[0]); // assign plotting variables pTP[0] = 3.; // Plot results fitResultP->cd(1); /*TH1D* dClone = (TH1D*) Hdphi[0]->Clone(); TH1D* cClone = (TH1D*) projC[0]->Clone(); TH1D* bClone = (TH1D*) projB[0]->Clone();*/ TH1D* dClone = (TH1D*) projData0[0]->Clone(); TH1D* cClone = (TH1D*) HpphiD[0]->Clone(); TH1D* bClone = (TH1D*) HpphiB[0]->Clone(); stat[3][0] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%iP",0)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[3][0]->InsertText(statLabel); stat[3][0]->SetFillColor(kWhite); cClone->Scale((1.-RbP[0])*SF[0]); bClone->Scale(RbP[0]*SF[0]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); cClone->SetLineColor(kRed); dClone->Draw(); cClone->Draw("same"); stat[3][0]->Draw("same"); //////// // 5.5-6.5 GeV Bin //////// gMinuit->SetFCN(chi2_P1); doFit(gMinuit,RbP[1],SF[1],EbP[1],eSF[1]); // assign plotting variables pTP[1] = 6.; // Plot results fitResultP->cd(2); /*dClone = (TH1D*) Hdphi[1]->Clone(); cClone = (TH1D*) projC[3]->Clone(); bClone = (TH1D*) projB[3]->Clone();*/ dClone = (TH1D*) projData2[3]->Clone(); cClone = (TH1D*) HpphiD[1]->Clone(); bClone = (TH1D*) HpphiB[1]->Clone(); stat[3][1] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%iP",0)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[3][1]->InsertText(statLabel); stat[3][1]->SetFillColor(kWhite); cClone->Scale((1.-RbP[1])*SF[1]); bClone->Scale(RbP[1]*SF[1]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); cClone->SetLineColor(kRed); dClone->Draw(); cClone->Draw("same"); stat[3][1]->Draw("same"); //////// // Old Data, Old Template /////// gMinuit->SetFCN(chi2_PP); doFit(gMinuit,RbPP[0],SFPP[0],EbPP[0],eSFPP[0]); // assign plotting variables pTPP[0] = 3.; // Plot results fitResultP->cd(3); dClone = (TH1D*) Hdphi[0]->Clone(); cClone = (TH1D*) HpphiD[0]->Clone(); bClone = (TH1D*) HpphiB[0]->Clone(); stat[3][2] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%iP",0)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[3][2]->InsertText(statLabel); stat[3][2]->SetFillColor(kWhite); cClone->Scale((1.-RbPP[0])*SFPP[0]); bClone->Scale(RbPP[0]*SFPP[0]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); cClone->SetLineColor(kRed); dClone->Draw(); cClone->Draw("same"); stat[3][2]->Draw("same"); // Bin at 6 GeV gMinuit->SetFCN(chi2_PP1); doFit(gMinuit,RbPP[1],SFPP[1],EbPP[1],eSFPP[1]); // assign plotting variables pTPP[1] = 6.; // Plot results fitResultP->cd(4); dClone = (TH1D*) Hdphi[1]->Clone(); cClone = (TH1D*) HpphiD[1]->Clone(); bClone = (TH1D*) HpphiB[1]->Clone(); stat[3][3] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%iP",0)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[3][3]->InsertText(statLabel); stat[3][3]->SetFillColor(kWhite); cClone->Scale((1.-RbPP[1])*SFPP[1]); bClone->Scale(RbPP[1]*SFPP[1]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.6); cClone->SetLineColor(kRed); dClone->Draw(); cClone->Draw("same"); stat[3][3]->Draw("same"); // Get FONLL Calc Int_t l=0; char line[1000]; Float_t xF[100],yF[100],minF[100],maxF[100]; ifstream fp("/Users/zach/Research/pythia/200GeVTemplate/FONLL.txt",ios::in); while (!fp.eof()){ fp.getline(line,1000); sscanf(line,"%f %f %f %f",&xF[l],&yF[l],&minF[l],&maxF[l]); // printf("L: %f %f\n",xF[l],yF[l]); l++; } fp.close(); // Get Previous Analysis Int_t p=0; Float_t xP[100],yP[100],dyP[100]; ifstream fp1("/Users/zach/Research/pythia/200GeVTemplate/run5_6.txt",ios::in); while (!fp1.eof()){ fp1.getline(line,1000); sscanf(line,"%f %f %f",&xP[p],&yP[p],&dyP[p]); // printf("L: %f %f\n",xF[l],yF[l]); p++; } fp1.close(); //cout << "at bottom contrib plot" << endl; TCanvas* c1 = new TCanvas("c1","Bottom Contribution",150,0,1150,1000); TGraphErrors *gr0 = new TGraphErrors(plotCount0-1,ptOFF1,Rb0,dx,eb0); TGraphErrors *gr2 = new TGraphErrors(plotCount2-1,ptOFF2,Rb2,dx,eb2); TGraphErrors *grC = new TGraphErrors(plotCount-1,pT,RbC,dx,ebC); TGraphErrors *grF = new TGraphErrors(l-1,xF,yF); TGraphErrors *grFmax = new TGraphErrors(l-1,xF,maxF); TGraphErrors *grFmin = new TGraphErrors(l-1,xF,minF); TGraphErrors *grP = new TGraphErrors(p-1,xP,yP,0,dyP); TGraphErrors *grPr = new TGraphErrors(2,pTP,RbP,0,EbP); TGraphErrors *grPPr = new TGraphErrors(2,pTPP,RbPP,0,EbPP); c1->cd(1); grP->SetTitle(""); grP->GetXaxis()->SetTitle("NPE p_{T} (GeV/c)"); grP->GetYaxis()->SetTitle("r_{B}"); gr0->SetMarkerStyle(20); gr0->SetMarkerSize(1); gr0->SetLineColor(kBlue); gr0->SetMarkerColor(kBlue); gr2->SetMarkerStyle(22); gr2->SetMarkerSize(1); gr2->SetLineColor(kRed); gr2->SetMarkerColor(kRed); grC->SetMarkerStyle(21); grC->SetMarkerSize(1); grC->SetLineColor(kRed); grC->SetMarkerColor(kRed); grP->GetXaxis()->SetLimits(0,10); grP->GetYaxis()->SetRangeUser(0,1); grF->SetLineStyle(1); grFmax->SetLineStyle(2); grFmin->SetLineStyle(2); grP->SetMarkerStyle(33); grP->SetMarkerColor(kBlack); grPr->SetMarkerStyle(29); grPr->SetMarkerColor(9); grPr->SetLineColor(9); grPPr->SetMarkerStyle(29); grPPr->SetMarkerColor(49); grPPr->SetLineColor(49); grP->Draw("AP"); //grC->Draw("same P"); gr2->Draw("same P"); grF->Draw("same"); grFmax->Draw("same"); grFmin->Draw("same"); gr0->Draw("same P"); // grPr->Draw("same P"); //grPPr->Draw("same P"); TLegend* leg2 = new TLegend(0.15,0.68,0.48,0.85); leg2->AddEntry(gr0,"STAR Run 12 - Low p_{T} Analysis","pe"); leg2->AddEntry(gr2,"STAR Run 12 - High p_{T} Analysis","pe"); //leg2->AddEntry(grC,"Combined Trigs","pe"); leg2->AddEntry(grP,"STAR Run 6 Analysis (Stat. Uncertainty)","pe"); // leg2->AddEntry(grPr,"Run 12 Data, Run 5/6 Templates)","pe"); //leg2->AddEntry(grPPr,"Run 5/6 Refit (prev Template)","pe"); leg2->AddEntry(grF,"FONLL Calculation","l"); leg2->Draw("same"); // Write to Root File if open if(makeROOT){ file3->Close(); file4->Close(); file->cd(); grP->Write("PreviousData"); //grC->Write("same P"); gr2->Write("HT2"); grF->Write("FONLL"); grFmax->Write("FONLLmax"); grFmin->Write("FONLLmin"); gr0->Write("HT0"); // grPr->Write("PrevTempMyData"); //grPPr->Write("PrevTempPreData"); } // Make PDF with output canvases if(makePDF) { //Set front page TCanvas* fp = new TCanvas("fp","Front Page",100,0,1000,900); fp->cd(); TBox *bLabel = new TBox(0.01, 0.88, 0.99, 0.99); bLabel->SetFillColor(38); bLabel->Draw(); TLatex tl; tl.SetNDC(); tl.SetTextColor(kWhite); tl.SetTextSize(0.033); char tlName[100]; char tlName2[100]; TString titlename = FileName; int found = titlename.Last('/'); if(found >= 0){ titlename.Replace(0, found+1, ""); } sprintf(tlName, "RUN 12 NPE-h #Delta#phi Correlations"); tl.SetTextSize(0.05); tl.SetTextColor(kWhite); tl.DrawLatex(0.05, 0.92,tlName); TBox *bFoot = new TBox(0.01, 0.01, 0.99, 0.12); bFoot->SetFillColor(38); bFoot->Draw(); tl.SetTextColor(kWhite); tl.SetTextSize(0.05); tl.DrawLatex(0.05, 0.05, (new TDatime())->AsString()); tl.SetTextColor(kBlack); tl.SetTextSize(0.03); tl.DrawLatex(0.1, 0.14, titlename); sprintf(tlName,"TEST"); tl.DrawLatex(0.1, 0.8,tlName); // Place canvases in order TCanvas* temp = new TCanvas(); sprintf(name, "FFOutput/%s.pdf[", FileName); temp->Print(name); sprintf(name, "FFOutput/%s.pdf", FileName); temp = deltaPhi; temp->Print(name); temp = fitResult0; temp->Print(name); temp = fitResult2; temp->Print(name); // temp = fitResultC; // temp->Print(name); temp = c1; temp->Print(name); sprintf(name, "FFOutput/%s.pdf]", FileName); temp->Print(name); } if(makeROOT) { file->Write(); file->Close(); } }
bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts) { pwr_tFileName filename1, filename2; sprintf( filename2, fname2, get_language_str()); dcli_translate_filename( filename1, fname1); dcli_translate_filename( filename2, filename2); ifstream fp1( filename1); if ( !fp1 && strcmp( fname1, "$pwr_exe/en_us/xtt_lng.dat") == 0) { // Try $pwr_eexe strcpy( fname1, "$pwr_eexe/en_us/xtt_lng.dat"); dcli_translate_filename( filename1, fname1); fp1.open( filename1); if ( !fp1) { *sts = LNG__FILE; return false; } } else if ( !fp1) { *sts = LNG__FILE; return global ? false : true; } ifstream fp2( filename2); if ( !fp2 && strcmp( fname2, "$pwr_exe/%s/xtt_lng.dat") == 0) { // Try $pwr_eexe strcpy( fname2, "$pwr_eexe/%s/xtt_lng.dat"); sprintf( filename2, fname2, get_language_str()); dcli_translate_filename( filename2, filename2); fp2.open( filename2); if ( !fp2) { *sts = LNG__FILE; return false; } } else if ( !fp2) { *sts = LNG__FILE; return global ? false : true; } Row r1( fp1, filename1); Row r2( fp2, filename2); read_metadata( fp1, global, sts); read_metadata( fp2, global, sts); read_include( fp1, fp2, global, sts); bool hit = true; for (;;) { if ( hit) { if ( !read_line( r1)) break; if ( !read_line( r2)) break; } else if ( r1.lt( r2)) { if ( !read_line( r1)) break; } else { if ( !read_line( r2)) break; } hit = false; if ( r1.eq( r2)) hit = true; if ( hit) { lang_sKey key; lang_sRecord *record; strncpy( key.text, r1.text, sizeof(key.text)); key.type = r1.type; record = (lang_sRecord *) tree_Insert( sts, tree, &key); strcpy( record->transl, r2.text); // printf ( "%c %d.%d.%d '%s' '%s'\n", r1.type, r1.n1, r1.n2, r1.n3, r1.text,r2.text); } } *sts = LNG__SUCCESS; return true; }
BamX::BamX(pars & Params1) // optional constructor { // parameters Params=Params1; Nread=0; Npair=0; Nproper=0; Nout=0; LFlow=INT_MIN; LFhigh=INT_MAX; region.limit=false; IlluminizeBam=0; outFragTailBam=false; outInterChromBam=false; outUniqueMultipleBam=false; outUniquePartialBam=false; outUniqueUnmappedBam=false; outAllPairsBam=false; outReadPairPosBam=false; //output file //samfile_t *fp; bam_header_t *bam_header; string s = Params.getInput(); BamUtil bam1(s); Bam = bam1; string filename=extractfilename(s); // parameters string fragPosFile = Params.getString("ReadPairPosFile"); string r = Params.getString("ChromRegion"); int maxReads = Params.getInt("MaxReads"); Qmin = Params.getInt("Qmin"); LRmin = Params.getInt("MinReadLength"); maxmismatchPC=Params.getDouble("FractionMaxMisMatches"); FragLengthWindow=Params.getInt("FragmentLengthWindow"); int cmd_MateMode=Params.getInt("ReadPairSenseConfig"); string ReferenceFastaFile=Params.getString("ReferenceFastaFile"); FragmentTailPercent=Params.getDouble("FragmentTailPercent"); IlluminizeBam=Params.getInt("Illuminize")>0; outputDirectory=Params.getString("OutputDirectory"); int minLR=Params.getInt("MinReadLength"); int SplitBracketMin=Params.getInt("SplitBracketMin"); int SplitBaseQmin=Params.getInt("SplitBaseQmin"); string StatFile=Params.getString("StatFile"); if (StatFile.size()>0) { hists H1(StatFile); hist HLF=H1.h["LF"]; hist HLR=H1.h["LR"]; Params.setHist("LF",HLF); Params.setHist("LR",HLR); H1.h.clear(); // free some memory if (FragmentTailPercent>0) { LFlow=int(HLF.p2xTrim(FragmentTailPercent/100.)); LFhigh=int(HLF.p2xTrim(1-FragmentTailPercent/100.)); } } int dbg = Params.getInt("Dbg"); time(&tprev); if (ReferenceFastaFile.size()>0) { FastaObj RF1(ReferenceFastaFile, ""); Reference=RF1; RF1.seq.clear(); // free some memory } bam_header= Bam.fp->header; string bamheadertext = bam_header->text; ReadGroup = extractBamTag(bamheadertext,"@RG"); outAllPairsBam=(r.size()>0); if (!outAllPairsBam) { outFragTailBam=true; //FragmentTailPercent>=0; outInterChromBam=true; outUniqueMultipleBam=true; outUniquePartialBam=true; outUniqueUnmappedBam=true; } // output Bams outputBam.clear(); /* // test BamHeaderContainer vector<BamHeaderContainer> x; string sv=SpannerVersion; string q="@PG\tID:FragmentTail\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); while (true) { string outfile=outputDirectory+"/"+filename+".fragtail.bam"; q=q+"\n@PG\tID:FragmentTail\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); BamHeaderContainer x1( bam_header, q); x.push_back(x1); bam_header_t* h1=x[x.size()-1].header(); cout<< h1->text << endl; } cout << x.size() << endl; */ samfile_t *fpFT=0; samfile_t *fpIC=0; samfile_t *fpUM=0; samfile_t *fpUP=0; samfile_t *fpUZ=0; samfile_t *fpAP=0; samfile_t *fpWP=0; //region if (r.size()>0) { int r1,r2,r3; C_region r0(r); region=r0; string bamRegion=region.region; size_t k=bamRegion.find("chr"); if (k!=string::npos) { bamRegion=bamRegion.substr(3); } if ( bam_parse_region(bam_header, bamRegion.c_str(), &r1, &r2, &r3)==0) { region.limit=true; region.anchor=r1; region.start=r2; region.end=r3; } else { cerr << "region not found\t" << r << endl; exit(111); } } //fragPosFile if (fragPosFile.size()>0) { FragmentPosFileObj fp(fragPosFile); if (fp.fragmentPosList.size()>0) { FragPos=fp; } else { cerr << "Read Pair Pos file not found\t" << fragPosFile << endl; exit(112); } outFragTailBam=false; outInterChromBam=false; outUniqueMultipleBam=false; outUniquePartialBam=false; outUniqueUnmappedBam=false; outReadPairPosBam=true; } if (outAllPairsBam) { string outfile=outputDirectory+"/"+filename+"."+r+".bam"; string sv=SpannerVersion; string q="@PG\tID:Region\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["AP"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["AP"].header(); if ((fpAP = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(160); } } if (outFragTailBam) { string outfile=outputDirectory+"/"+filename+".fragtail.bam"; string sv=SpannerVersion; string q="@PG\tID:FragmentTail\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["FT"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["FT"].header(); if ((fpFT = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(161); } } if (outInterChromBam) { string outfile=outputDirectory+"/"+filename+".interchrom.bam"; string sv=SpannerVersion; string q="@PG\tID:InterChromPairs\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["IC"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["IC"].header(); if ((fpIC = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(162); } } if (outUniqueMultipleBam) { string outfile=outputDirectory+"/"+filename+".uMult.bam"; string sv=SpannerVersion; string q="@PG\tID:uniqMultiplyMappedPairs\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["UM"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["IUM"].header(); if ((fpUM = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(163); } } if (outUniquePartialBam) { string outfile=outputDirectory+"/"+filename+".uPart.bam"; string sv=SpannerVersion; string q="@PG\tID:uniqPartiallyMappedPairs\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["UP"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["UP"].header(); if ((fpUP = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(164); } } if (outUniqueUnmappedBam) { string outfile=outputDirectory+"/"+filename+".uUnmapped.bam"; string sv=SpannerVersion; string q="@PG\tID:uniqUnMappedPairs\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["UZ"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["UZ"].header(); if ((fpUZ = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(165); } } if (outReadPairPosBam) { string outfile=outputDirectory+"/"+filename+".weirdpairs.bam"; string sv=SpannerVersion; string q="@PG\tID:weirdpairs\tPN:SpannerX\tVN"+sv+"\tCL:"+Params.getCmdLine(); outputBam["WP"]=BamHeaderContainer(bam_header,q); bam_header_t* h1=outputBam["WP"].header(); if ((fpWP = samopen(outfile.c_str(), "wb", h1)) == 0) { fprintf(stderr, "samopen: Fail to open output BAM file %s\n", filename.c_str()); exit(165); } } cout << ReadGroup << endl << endl; //extractMateMode(); if (cmd_MateMode>=0) MateMode=cmd_MateMode; BamContainerPair bampair; bool more = true; while (more) { bampair=Bam.getNextBamPair(); // skip if neither end within region more=(bampair.BamEnd.size()>1); Npair++; if (Npair>=maxReads) break; // if ( (dbg!=0)&&(elapsedtime()>float(dbg))) { time(&tprev); cout << " pairs:" << Npair << "\toutput:" << Nout; cout << "\tchr:" << bampair.BamEnd[0].b.core.tid+1; cout << "\tpos:" << bampair.BamEnd[0].b.core.pos; cout << endl; } if (!more) continue; if (region.limit) { bool overlap = false; for (int e=0; e<=1; e++) { int a1=bampair.BamEnd[e].b.core.tid; int p1=bampair.BamEnd[e].b.core.pos; int p2=p1+bampair.BamEnd[e].len; overlap=region.overlap(a1,p1,p2); if (overlap) break; } if (!overlap) continue; } bampair.Illuminize(IlluminizeBam); bampair.calcFragmentLengths(); more=(bampair.BamEnd[1].packeddata.size()>1); //if (bampair.BamEnd[0].b.core.tid==bampair.BamEnd[1].b.core.tid) // cout<< bampair << endl; bool bothmap = ((bampair.BamEnd[0].b.core.flag&BAM_FUNMAP)==0)&&((bampair.BamEnd[0].b.core.flag&BAM_FMUNMAP)==0); if (outAllPairsBam) { Nout++; int s1=samwrite(fpAP, &(bampair.BamEnd[0].b)); int s2=samwrite(fpAP, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to pairs.bam" << endl; exit(150); } } if (outReadPairPosBam) { int ichr1=bampair.BamEnd[0].b.core.tid+1; int istd1=bampair.BamEnd[0].sense=='+'? 0: 1; int ista1=bampair.BamEnd[0].b.core.pos+1; int iq1=bampair.BamEnd[0].q; int ichr2=bampair.BamEnd[1].b.core.tid+1; int istd2=bampair.BamEnd[1].sense=='+'? 0: 1; int ista2=bampair.BamEnd[1].b.core.pos+1; int iq2=bampair.BamEnd[1].q; FragmentPosObj fp1(0,ichr1,istd1,ista1,0,ichr2,istd2,ista2,0,iq1, iq2,0); /* if ((fp1.chr1==10)&&(fp1.start1>=89687801)&&(fp1.end1<=89700722)) { cout << "read "<< fp1 << endl; } */ if (FragPos.find(fp1)) { Nout++; int s1=samwrite(fpWP, &(bampair.BamEnd[0].b)); int s2=samwrite(fpWP, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to weirdpairs.bam" << endl; exit(156); } } } bool ok[2]; for (int e=0; e<2; e++) { uint8_t* bq=bam1_qual(&(bampair.BamEnd[e].b)); int LR=bampair.BamEnd[0].b.core.l_qseq; double bok=0; for (int ib=0; ib<LR; ib++) { if (bq[ib]>SplitBaseQmin) { bok++; } } ok[e]=(bok>LRmin); } if (! (ok[0]&ok[1]) ) continue; if ( (outFragTailBam) & ((bampair.BamEnd[0].q>=Qmin)|(bampair.BamEnd[1].q>=Qmin)) ) { bool FT=(bampair.FragmentLength>LFhigh)|((bampair.FragmentLength<LFlow)&(bampair.FragmentLength>INT_MIN))&bothmap; if (FT && (fpFT!=0)) { Nout++; int s1=samwrite(fpFT, &(bampair.BamEnd[0].b)); int s2=samwrite(fpFT, &(bampair.BamEnd[1].b)); //if (outputBam["FT"].write(&(bampair.BamEnd[0].b),&(bampair.BamEnd[1].b))) { if ((s1*s2)>0) { continue; } else { cerr << "bad write to fragtail.bam" << endl; exit(151); } } } if ((outInterChromBam) & ((bampair.BamEnd[0].q>=Qmin)&(bampair.BamEnd[1].q>=Qmin))) { bool IC=(bampair.BamEnd[0].b.core.tid!=bampair.BamEnd[1].b.core.tid)&&bothmap; if (IC && (fpIC!=0)) { Nout++; int s1=samwrite(fpIC, &(bampair.BamEnd[0].b)); int s2=samwrite(fpIC, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to interchrom.bam" << endl; exit(152); } } } if ((outUniqueMultipleBam) & ((bampair.BamEnd[0].q>=Qmin)|(bampair.BamEnd[1].q>=Qmin))){ int im=bampair.BamEnd[0].nmap>1? 0: 1; int iu=bampair.BamEnd[0].q>=Qmin? 0: 1; bool UM=(bampair.BamEnd[iu].nmap>1)&&(iu!=im)&&bothmap; if (UM && (fpUM!=0)) { Nout++; int s1=samwrite(fpUM, &(bampair.BamEnd[0].b)); int s2=samwrite(fpUM, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to uMult.bam" << endl; exit(153); } } } if ( (outUniquePartialBam) && ((bampair.BamEnd[0].q>=Qmin)|(bampair.BamEnd[1].q>=Qmin)) && bothmap) { int c0=bampair.BamEnd[0].clip[0]+bampair.BamEnd[0].clip[1]; int LR=bampair.BamEnd[0].b.core.l_qseq; bool split0=((LR-c0)>SplitBracketMin)&(c0>SplitBracketMin); int ib0=0; if ((split0)&(bampair.BamEnd[0].clip[0]>SplitBracketMin)) { ib0=bampair.BamEnd[0].clip[0]; } else if ((split0)&(bampair.BamEnd[0].clip[1]>SplitBracketMin) ) { ib0=LR-bampair.BamEnd[0].clip[1]; } split0=split0&(ib0>0); if (split0) { uint8_t* bq=bam1_qual(&(bampair.BamEnd[0].b)); for (int ib=(ib0-SplitBracketMin); ib<(ib0+SplitBracketMin); ib++) { if (bq[ib]<SplitBaseQmin) { split0=false; break; } } } int c1=bampair.BamEnd[1].clip[0]+bampair.BamEnd[1].clip[1]; LR=bampair.BamEnd[1].b.core.l_qseq; bool split1=((LR-c0)>SplitBracketMin)&(c1>SplitBracketMin);; int ib1=0; if ((split1)&(bampair.BamEnd[1].clip[0]>SplitBracketMin)) { ib1=bampair.BamEnd[1].clip[0]; } else if ((split1)&(bampair.BamEnd[1].clip[1]>SplitBracketMin) ) { ib1=LR-bampair.BamEnd[1].clip[1]; } split1=split1&(ib1>0); if (split1) { uint8_t* bq=bam1_qual(&(bampair.BamEnd[1].b)); for (int ib=(ib1-SplitBracketMin); ib<(ib1+SplitBracketMin); ib++) { if (bq[ib]<SplitBaseQmin) { split1=false; break; } } } bool UP=(split0|split1)&((c1+c0)>minLR); if (UP && (fpUP!=0)) { Nout++; int s1=samwrite(fpUP, &(bampair.BamEnd[0].b)); int s2=samwrite(fpUP, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to uPart.bam" << endl; exit(154); } } } if ( (outUniqueUnmappedBam) & ((bampair.BamEnd[0].q>=Qmin)|(bampair.BamEnd[1].q>=Qmin)) ) { bool z0=((bampair.BamEnd[0].b.core.flag&BAM_FUNMAP)>0); bool z1=((bampair.BamEnd[1].b.core.flag&BAM_FUNMAP)>0); uint8_t* bq=bam1_qual(&(bampair.BamEnd[0].b)); for (int nb,ib=0; ib<bampair.BamEnd[0].b.core.l_qseq; ib++) { if (bq[ib]<SplitBaseQmin) { nb++; } } bool UZ=(z0|z1)&(!(z1&z0)); if (UZ && (fpUZ!=0)) { Nout++; int s1=samwrite(fpUZ, &(bampair.BamEnd[0].b)); int s2=samwrite(fpUZ, &(bampair.BamEnd[1].b)); if ((s1*s2)>0) { continue; } else { cerr << "bad write to uUnmapped.bam" << endl; exit(155); } } } //cout<< bampair.Orientation << "\t"<< bampair.FragmentLength << "\t" <<bampair.BamEnd[1].b.core.pos << endl; } if (outReadPairPosBam) { samclose(fpWP); } else { if (outAllPairsBam) { samclose(fpAP); } else { samclose(fpFT); samclose(fpIC); samclose(fpUP); samclose(fpUM); samclose(fpUZ); } } /* for (ioutputBam=outputBam.begin(); ioutputBam!=outputBam.end(); ioutputBam++) { (*ioutputBam).second.close(); } if (FragmentTailPercent>0) outputBam["FT"].close(); */ samclose(Bam.fp); }
void minuitFit() { gStyle->SetOptFit(1111); gStyle->SetOptStat(0); Bool_t makePDF = checkMakePDF(); char name[1000]; sprintf(name,"/Users/zach/Research/pythia/ptHatTemplate/outputs/currentB.root"); TFile *fB = new TFile(name,"READ"); sprintf(name,"/Users/zach/Research/pythia/ptHatTemplate/outputs/currentC.root"); TFile *fC = new TFile(name,"READ"); sprintf(name,"/Users/zach/Research/rootFiles/run12NPEhPhi/currentData.root"); TFile *fD = new TFile(name,"READ"); if (fB->IsOpen()==kFALSE || fC->IsOpen()==kFALSE) { std::cout << "!!!!!! Either B,C, or Data File not found !!!!!!" << std::endl << "Looking for currentB.root, currentC.root, and currentData.root" << std::endl; exit(1); } // Set constants and projection bins (from header file anaConst, analysis constants) Float_t lowpt[numPtBins],highpt[numPtBins]; for(Int_t c=0; c< numPtBins; c++){ lowpt[c] = anaConst::lpt[c]; highpt[c] = anaConst::hpt[c]; } Float_t hptCut=anaConst::hptCut; Double_t p00[numPtBins],p01[numPtBins],p20[numPtBins],p21[numPtBins]; Double_t e00[numPtBins],e01[numPtBins],e20[numPtBins],e21[numPtBins]; Double_t pC0[numPtBins],pC1[numPtBins],eC0[numPtBins],eC1[numPtBins]; Double_t Rb0[numPtBins],Rb2[numPtBins],RbC[numPtBins],pT[numPtBins]; Double_t eb0[numPtBins],eb2[numPtBins],ebC[numPtBins],dx[numPtBins]; Double_t ptOFF1[numPtBins],ptOFF2[numPtBins]; Int_t plotCount0 = 0, plotCount2 = 0, plotCount = 0; // Make Canvases TCanvas* deltaPhi = new TCanvas("deltaPhi","Pythia Delta Phi",150,0,1150,1000); TCanvas* deltaPhi2 = new TCanvas("deltaPhi2","Pythia Delta Phi",150,0,1150,1000); TCanvas* fitResult0 = new TCanvas("fitResult0","RB Extraction HT0",150,0,1150,1000); TCanvas* fitResult2 = new TCanvas("fitResult2","RB Extraction HT2",150,0,1150,1000); TCanvas* fitResultC = new TCanvas("fitResultC","RB Extraction Combined Trigs",150,0,1150,1000); deltaPhi ->Divide(3,3); deltaPhi2 ->Divide(3,3); fitResult0->Divide(3,4); fitResult2->Divide(3,4); fitResultC->Divide(3,4); // Get and Draw histos TPaveText* lbl[numPtBins]; TPaveText* stat[3][numPtBins]; char statLabel[100]; char textLabel[100]; Int_t plotbin; Float_t norm0,norm2,normB,normC; // Get ptbin independent hists histoNorms = (TH1F*)fD->Get("histoNorms"); bPtNorms = (TH1F*)fB->Get("ptNorm"); cPtNorms = (TH1F*)fC->Get("ptNorm"); for(Int_t ptbin=0; ptbin<numPtBins; ptbin++) { norm0 = histoNorms->GetBinContent(histoNorms->GetBin(1,ptbin+1)); norm2 = histoNorms->GetBinContent(histoNorms->GetBin(3,ptbin+1)); normB = bPtNorms->GetBinContent(bPtNorms->GetBin(ptbin+1)); normC = cPtNorms->GetBinContent(cPtNorms->GetBin(ptbin+1)); if(norm0 == 0) { cout << ptbin << " For this bin, some norm0 = 0" << endl; continue; } if( norm2 == 0 ) { cout << ptbin << " For this bin, some norm2 = 0" << endl; continue; } if( normB == 0 ) { cout << ptbin << " For this bin, some normB = 0" << endl; continue; } if(normC == 0) { cout << ptbin << " For this bin, some normC = 0" << endl; continue; } plotbin = ptbin; // Init necessary plotting tools lbl[ptbin] = new TPaveText(.15,.15,.35,.23,Form("NB NDC%i",ptbin)); sprintf(textLabel,"%.1f < P_{T,e} < %.1f",lowpt[ptbin],highpt[ptbin]); lbl[ptbin]->AddText(textLabel); lbl[ptbin]->SetFillColor(kWhite); projB[ptbin] = (TH1D*)fB->Get(Form("delPhi_%i",ptbin)); projC[ptbin] = (TH1D*)fC->Get(Form("delPhi_%i",ptbin)); projData0[ptbin]= (TH1D*)fD->Get(Form("NPEhDelPhi_0_%i",ptbin)); projData2[ptbin]= (TH1D*)fD->Get(Form("NPEhDelPhi_2_%i",ptbin)); // Do any rebinning Int_t RB = 1; projB[ptbin]->Rebin(RB); projC[ptbin]->Rebin(RB); projData0[ptbin]->Rebin(RB); projData2[ptbin]->Rebin(RB); // Clone to make plots without effecting fits plotD0[ptbin] = (TH1D*) projData0[ptbin]->Clone(); plotD2[ptbin] = (TH1D*) projData2[ptbin]->Clone(); plotB[ptbin] = (TH1D*) projB[ptbin]->Clone(); plotC[ptbin] = (TH1D*) projC[ptbin]->Clone(); // Set features that are the same in plots projData0[ptbin]->SetLineColor(kBlue); projData2[ptbin]->SetLineColor(kGreen+3); projB[ptbin]->SetLineColor(kRed); projC[ptbin]->SetLineColor(kBlack); projC[ptbin]->GetXaxis()->SetRangeUser(-3.5,3.5); plotD0[ptbin]->SetLineColor(kBlue); plotD2[ptbin]->SetLineColor(kGreen+3); plotD0[ptbin]->SetMarkerStyle(20); plotD0[ptbin]->SetMarkerColor(kBlue); plotD0[ptbin]->SetMarkerSize(0.4); plotB[ptbin]->SetLineColor(kRed); plotC[ptbin]->SetLineColor(kBlack); plotC[ptbin]->GetXaxis()->SetRangeUser(-3.5,3.5); combData[ptbin] = (TH1D*) projData0[ptbin]->Clone(); combData[ptbin] -> Add(projData2[ptbin]); combData[ptbin]->SetLineColor(kBlue); combData[ptbin]->SetMarkerStyle(20); combData[ptbin]->SetMarkerColor(kBlue); combData[ptbin]->SetMarkerSize(0.4); combData[ptbin]->SetTitle(""); // Normalize projB[ptbin] -> Scale(1/normB); projC[ptbin] -> Scale(1/normC); projData0[ptbin] -> Scale(1/norm0); projData2[ptbin] -> Scale(1/norm2); plotD0[ptbin] -> Scale(1/norm0); plotD2[ptbin] -> Scale(1/norm2); plotB[ptbin] -> Scale(1/(normB)); plotC[ptbin] -> Scale(1/(normC)); combData[ptbin] -> Scale(1/(norm0+norm2)); /*projB[ptbin] -> Scale(projData0[ptbin]->GetBinContent(70)/projB[ptbin]->GetBinContent(70)); projC[ptbin] -> Scale(projData0[ptbin]->GetBinContent(70)/projC[ptbin]->GetBinContent(70)); plotB[ptbin] -> Scale(projData0[ptbin]->GetBinContent(70)/plotB[ptbin]->GetBinContent(70)); plotC[ptbin] -> Scale(projData0[ptbin]->GetBinContent(70)/plotC[ptbin]->GetBinContent(70)); */ // Draw Templates on own plots if(ptbin+1 <= 9) deltaPhi->cd(plotbin+1); if(ptbin+1 > 9) deltaPhi2->cd(ptbin-8); plotC[ptbin]->GetYaxis()->SetRangeUser(-.1,0.5); plotC[ptbin] -> Draw("hist"); plotB[ptbin] -> Draw("same hist"); plotD0[ptbin] -> Draw("same"); plotD2[ptbin] -> Draw("same"); lbl[ptbin] -> Draw("same"); TLegend* leg = new TLegend(0.65,0.6,0.85,0.85); leg->AddEntry(projB[ptbin],"b#bar{b}->NPE","lpe"); leg->AddEntry(projC[ptbin],"c#bar{c}->NPE","lpe"); leg->AddEntry(projData0[ptbin],"HT0","lpe"); leg->AddEntry(projData2[ptbin],"HT2","lpe"); leg->Draw(); ///////////////////// // Do the actual fits ///////////////////// cout << "!!!!!!! HT0 ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; currentPtBin = ptbin; double arglist[10];int ierflg=0; TMinuit *gMinuit=new TMinuit(2); //initialize TMinuit with a maximum of 3 params gMinuit->SetMaxIterations(50000); gMinuit->SetFCN(chi2_0); arglist[0]=1; //error definition: chi^2 change by 1 to get 1 sigma gMinuit->mnexcm("SET ERR",arglist,1,ierflg); //starting values double vstart[2]={0.3,1}; //frac double step[2]={0.01,0.01}; //starting step gMinuit->mnparm(0,"BtoNPE frac",vstart[0],step[0],0.000,2,ierflg); gMinuit->mnparm(1,"Scale Factor",vstart[1],step[1],0.000,2,ierflg); //simple scan to get better start values gMinuit->mnexcm("SCAN",arglist,0,ierflg); cout<<"done with first scan!"<<endl; //minimization arglist[0]=5000; //maxcalls arglist[1]=0.5; // tolerance = 0.001*[this value]*[error def] //5.0 before gMinuit->mnexcm("MINIMIZE",arglist,2,ierflg); cout<< "done with fit! Error Flag: " << ierflg << endl; //fit results double dum1,dum2; TString *str0 = new TString("BtoNPE frac"); TString *str1 = new TString("Scale Factor"); gMinuit->mnpout(0,*str0,p01[ptbin],e01[ptbin],dum1,dum2,ierflg); gMinuit->mnpout(1,*str1,p00[ptbin],e00[ptbin],dum1,dum2,ierflg); cout << endl << endl << "HT0 PT Bin: " << lowpt[ptbin] << "-" << highpt[ptbin] << endl << "rB: " << p01[ptbin] << " rC: " << p00[ptbin] << endl << "erB: " << e01[ptbin] << " erC: " << e00[ptbin] << endl << endl; //Print results double amin,edm,errdef; int nvpar,nparx,icstat; gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gMinuit->mnprin(4,amin); // assign to plotting variables if(highpt[ptbin] < 6) { pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; dx[plotCount0] = 0.; ptOFF1[plotCount0] = pT[ptbin]; Rb0[plotCount0] = p01[ptbin];///(p01[ptbin]+p00[ptbin]); eb0[plotCount0] = e01[ptbin]; plotCount0++; } // Plot results fitResult0->cd(ptbin+1); TH1D* dClone = (TH1D*) projData0[ptbin]->Clone(); TH1D* cClone = (TH1D*) projC[ptbin]->Clone(); TH1D* bClone = (TH1D*) projB[ptbin]->Clone(); stat[0][ptbin] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%i",ptbin)); sprintf(statLabel,"Chi2/NDF: %.2f/%.0f",curChi2,curNDF); stat[0][ptbin]->InsertText(statLabel); stat[0][ptbin]->SetFillColor(kWhite); cClone->Scale((1.-p01[ptbin])*p00[ptbin]); bClone->Scale(p00[ptbin]*p01[ptbin]); // scale by contribution param cClone->Add(bClone); //cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.4); dClone->Draw(); cClone->Draw("same"); stat[0][ptbin]->Draw("same"); lbl[ptbin]->Draw("same"); cout << "!!!!!!! HT2 ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; fitResult2->cd(ptbin+1); currentPtBin = ptbin; TMinuit *g2Minuit=new TMinuit(2); //initialize TMinuit with a maximum of 3 params g2Minuit->SetMaxIterations(50000); g2Minuit->SetFCN(chi2_2); arglist[0]=1; //error definition: chi^2 change by 1 to get 1 sigma g2Minuit->mnexcm("SET ERR",arglist,1,ierflg); //starting values double vstart2[2]={0.3,1}; //frac double step2[2]={0.01,0.01}; //starting step g2Minuit->mnparm(0,"BtoNPE frac",vstart2[0],step2[0],0.000,2,ierflg); g2Minuit->mnparm(1,"Scale Factor",vstart2[1],step2[1],0.000,2,ierflg); //simple scan to get better start values g2Minuit->mnexcm("SCAN",arglist,0,ierflg); cout<<"done with first scan!"<<endl; //minimization arglist[0]=5000; //maxcalls arglist[1]=0.5; // tolerance = 0.001*[this value]*[error def] //5.0 before g2Minuit->mnexcm("MINIMIZE",arglist,2,ierflg); cout<< "done with fit! Error Flag: " << ierflg << endl; //fit results TString *str2 = new TString("BtoNPE frac"); TString *str3 = new TString("Scale Factor"); g2Minuit->mnpout(0,*str2,p21[ptbin],e21[ptbin],dum1,dum2,ierflg); g2Minuit->mnpout(1,*str3,p20[ptbin],e20[ptbin],dum1,dum2,ierflg); cout << endl << endl << "HT2 PT Bin: " << lowpt[ptbin] << "-" << highpt[ptbin] << endl << "rB: " << p21[ptbin] << " rC: " << p20[ptbin] << endl << "erB: " << e21[ptbin] << " erC: " << e20[ptbin] << endl << endl; //Print results g2Minuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); g2Minuit->mnprin(4,amin); // assign to plotting variables if(highpt[ptbin] > 3.6) { pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; ptOFF2[plotCount2] = pT[ptbin]; Rb2[plotCount2] = p21[ptbin];///(p21[ptbin]+p20[ptbin]); eb2[plotCount2] = e21[ptbin]; plotCount2++; } // Plot results fitResult2->cd(ptbin+1); dClone = (TH1D*) projData2[ptbin]->Clone(); cClone = (TH1D*) projC[ptbin]->Clone(); bClone = (TH1D*) projB[ptbin]->Clone(); stat[2][ptbin] = new TPaveText(.4,.75,.85,.85,Form("NB NDC%i",ptbin)); sprintf(statLabel,"Chi2/NDF: %.2f/%.2f",curChi2,curNDF); stat[2][ptbin]->InsertText(statLabel); stat[2][ptbin]->SetFillColor(kWhite); cClone->Scale((1.-p21[ptbin])*p20[ptbin]); bClone->Scale(p20[ptbin]*p21[ptbin]); // scale by contribution param cClone->Add(bClone); // cClone->Scale(dClone->GetMaximum()/cClone->GetMaximum()); dClone->GetXaxis()->SetRangeUser(anaConst::lowPhi,anaConst::highPhi); dClone->GetYaxis()->SetRangeUser(-0.1,0.4); dClone->Draw(); cClone->Draw("same"); stat[2][ptbin]->Draw("same"); lbl[ptbin]->Draw("same"); cout << "!!!!!!! HT0&2 ptbin: " << highpt[ptbin] << "-" << lowpt[ptbin] <<" !!!!!!!"<< endl; fitResultC->cd(ptbin+1); currentPtBin = ptbin; TMinuit *gCMinuit=new TMinuit(2); //initialize TMinuit with a maximum of 3 params gCMinuit->SetMaxIterations(50000); gCMinuit->SetFCN(chi2_C); arglist[0]=1; //error definition: chi^2 change by 1 to get 1 sigma gCMinuit->mnexcm("SET ERR",arglist,1,ierflg); //starting values double vstartC[2]={0.3,1}; //frac double stepC[2]={0.01,0.01}; //starting step gCMinuit->mnparm(0,"BtoNPE frac",vstartC[0],stepC[0],0.000,2,ierflg); gCMinuit->mnparm(1,"Scale Factor",vstartC[1],stepC[1],0.000,2,ierflg); //simple scan to get better start values gCMinuit->mnexcm("SCAN",arglist,0,ierflg); cout<<"done with first scan!"<<endl; //minimization arglist[0]=5000; //maxcalls arglist[1]=0.5; // tolerance = 0.001*[this value]*[error def] //5.0 before gCMinuit->mnexcm("MINIMIZE",arglist,2,ierflg); cout<< "done with fit! Error Flag: " << ierflg << endl; //fit results TString *str4 = new TString("BtoNPE frac"); TString *str5 = new TString("Scale Factor"); gCMinuit->mnpout(0,*str4,pC1[ptbin],eC1[ptbin],dum1,dum2,ierflg); gCMinuit->mnpout(1,*str5,pC0[ptbin],eC0[ptbin],dum1,dum2,ierflg); cout << endl << endl << "HTC PT Bin: " << lowpt[ptbin] << "-" << highpt[ptbin] << endl << "rB: " << pC1[ptbin] << " rC: " << pC0[ptbin] << endl << "erB: " << eC1[ptbin] << " erC: " << eC0[ptbin] << endl << endl; //Print results gCMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gCMinuit->mnprin(4,amin); // assign to plotting variables pT[ptbin] = (lowpt[ptbin]+highpt[ptbin])/2.; RbC[plotCount] = pC1[ptbin];///(p21[ptbin]+p20[ptbin]); ebC[plotCount] = eC1[ptbin]; plotCount++; } // Get FONLL Calc Int_t l=0; char line[1000]; Float_t xF[100],yF[100],minF[100],maxF[100]; ifstream fp("/Users/zach/Research/pythia/ptHatTemplate/FONLL.txt",ios::in); while (!fp.eof()){ fp.getline(line,1000); sscanf(line,"%f %f %f %f",&xF[l],&yF[l],&minF[l],&maxF[l]); // printf("L: %f %f\n",xF[l],yF[l]); l++; } fp.close(); // Get Previous Analysis Int_t p=0; Float_t xP[100],yP[100],dyP[100]; ifstream fp1("/Users/zach/Research/pythia/ptHatTemplate/run5_6.txt",ios::in); while (!fp1.eof()){ fp1.getline(line,1000); sscanf(line,"%f %f %f",&xP[p],&yP[p],&dyP[p]); // printf("L: %f %f\n",xF[l],yF[l]); p++; } fp1.close(); //cout << "at bottom contrib plot" << endl; TCanvas* c1 = new TCanvas("c1","Bottom Contribution",150,0,1150,1000); TGraphErrors *gr0 = new TGraphErrors(plotCount0-1,ptOFF1,Rb0,dx,eb0); TGraphErrors *gr2 = new TGraphErrors(plotCount2-1,ptOFF2,Rb2,dx,eb2); TGraphErrors *grC = new TGraphErrors(plotCount-1,pT,RbC,dx,ebC); TGraphErrors *grF = new TGraphErrors(l-1,xF,yF); TGraphErrors *grFmax = new TGraphErrors(l-1,xF,maxF); TGraphErrors *grFmin = new TGraphErrors(l-1,xF,minF); TGraphErrors *grP = new TGraphErrors(p-1,xP,yP,0,dyP); c1->cd(1); gr0->SetTitle("Bottom Contribution"); gr0->GetXaxis()->SetTitle("p_{T,e}"); gr0->GetYaxis()->SetTitle("#frac{r_{B}}{(r_{B}+r_{C})}"); gr0->SetMarkerStyle(20); gr0->SetMarkerSize(1); gr0->SetLineColor(kBlue); gr0->SetMarkerColor(kBlue); gr2->SetMarkerStyle(22); gr2->SetMarkerSize(1); gr2->SetLineColor(kRed); gr2->SetMarkerColor(kRed); grC->SetMarkerStyle(21); grC->SetMarkerSize(1); grC->SetLineColor(kRed); grC->SetMarkerColor(kRed); gr0->GetXaxis()->SetLimits(1,14); gr0->GetYaxis()->SetRangeUser(0,1); grF->SetLineStyle(1); grFmax->SetLineStyle(2); grFmin->SetLineStyle(2); grP->SetMarkerStyle(33); grP->SetMarkerColor(kBlack); gr0->Draw("AP"); // grC->Draw("same P"); gr2->Draw("same P"); grF->Draw("same"); grFmax->Draw("same"); grFmin->Draw("same"); grP->Draw("same P"); TLegend* leg2 = new TLegend(0.15,0.68,0.4,0.85); leg2->AddEntry(gr0,"High Tower 0 Trigs","pe"); leg2->AddEntry(gr2,"High Tower 2 Trigs","pe"); // leg2->AddEntry(grC,"Combined Trigs","pe"); leg2->AddEntry(grF,"FONLL (Uncertainty: Scale Only)","l"); leg2->AddEntry(grP,"Run 5/6 Analysis (Stat Uncertainty)","pe"); leg2->Draw("same"); // Make PDF with output canvases if(makePDF) { //Set front page TCanvas* fp = new TCanvas("fp","Front Page",100,0,1000,900); fp->cd(); TBox *bLabel = new TBox(0.01, 0.88, 0.99, 0.99); bLabel->SetFillColor(38); bLabel->Draw(); TLatex tl; tl.SetNDC(); tl.SetTextColor(kWhite); tl.SetTextSize(0.033); char tlName[100]; char tlName2[100]; TString titlename = FileName; int found = titlename.Last('/'); if(found >= 0){ titlename.Replace(0, found+1, ""); } sprintf(tlName, "RUN 12 NPE-h #Delta#phi Correlations"); tl.SetTextSize(0.05); tl.SetTextColor(kWhite); tl.DrawLatex(0.05, 0.92,tlName); TBox *bFoot = new TBox(0.01, 0.01, 0.99, 0.12); bFoot->SetFillColor(38); bFoot->Draw(); tl.SetTextColor(kWhite); tl.SetTextSize(0.05); tl.DrawLatex(0.05, 0.05, (new TDatime())->AsString()); tl.SetTextColor(kBlack); tl.SetTextSize(0.03); tl.DrawLatex(0.1, 0.14, titlename); sprintf(tlName,"TEST"); tl.DrawLatex(0.1, 0.8,tlName); // Place canvases in order TCanvas* temp = new TCanvas(); sprintf(name, "FFOutput/%s.pdf[", FileName); temp->Print(name); sprintf(name, "FFOutput/%s.pdf", FileName); temp = deltaPhi; temp->Print(name); temp = fitResult0; temp->Print(name); temp = fitResult2; temp->Print(name); temp = fitResultC; temp->Print(name); temp = c1; temp->Print(name); sprintf(name, "FFOutput/%s.pdf]", FileName); temp->Print(name); } }
int main () { textmode (ATC_TEXT_MODE); clrscr(); Position::MaxX = 30; Position::MaxY = 30; char pid; Position::MaxX = 30; Position::MaxY = 30; RadarScreen *r; Landmarks l; Traffic t; Plane *p1; Gate g (Position (0, 10), 1, D90); Gate g1 (Position (0, 0), 2, D45); Gate g2 (Position (10, 0), 3, D0); Gate g3 (Position (MAX_X, MAX_Y), 4, D225); // Gate g4 (Position (10, 0), 4, D0); Airport a1 (Position (5, 5), 1, Heading (D90)); Airport a2 (Position (10, 12), 2, Heading (D45)); Beacon b1 (Position (7,13), 1); Beacon b2 (Position (1,1), 2); FlightPath fp (Position (MIN_FIELD_X, MIN_FIELD_Y), Position (MAX_FIELD_X, MAX_FIELD_Y)); FlightPath fp1 (Position (MIN_FIELD_X, MAX_FIELD_Y), Position (MAX_FIELD_X, MIN_FIELD_Y)); FlightPath fp2 (Position (10, 1), Position (10, MAX_FIELD_Y)); int i; l.AddAirport (&a1); l.AddAirport (&a2); l.AddBeacon (&b1); l.AddBeacon (&b2); l.AddGate (&g); l.AddGate (&g1); l.AddGate (&g2); l.AddGate (&g3); // l.AddGate (&g4); l.AddFlightPath (&fp); l.AddFlightPath (&fp1); l.AddFlightPath (&fp2); r = new RadarScreen (&l); Boolean Crashed = False; r->Refresh(); pid = t.NewId(); p1 = new Plane (pid, g.NewPlaneCoords(), Prop, &g1); t.NewAirborne (p1); p1 = new Plane (t.NewId(), g1.NewPlaneCoords(), Jet, &g); t.NewAirborne (p1); p1 = new Plane (t.NewId(), g2.NewPlaneCoords(), Jet, &g); t.NewAirborne (p1); r->DisplayPlanes (&t); for (i = 0; i < 34; i++) { delay (500); if (i == 17) { t.SearchAirborne ('a'); t.FoundAirborne() -> AlterTargHeading (D270, AntiClockwise); t.SearchAirborne ('b'); t.FoundAirborne() -> MakeCircle (AntiClockwise); } r->UnDisplayPlanes (&t); if (i % 2 == 0) { t.StepJets(); } else { t.StepAll(); } r->DisplayPlanes (&t); if (!Crashed && t.Crashed ()) { cout << '\a'; Crashed = True; } } textmode (C80); _setcursortype (_NORMALCURSOR); clrscr(); return 0; }
static int do_test (void) { #ifdef USE_TLS static const char modname1[] = "tst-tlsmod3.so"; static const char modname2[] = "tst-tlsmod4.so"; int result = 0; int (*fp1) (void); int (*fp2) (int, int *); void *h1; void *h2; int i; size_t modid1 = (size_t) -1; size_t modid2 = (size_t) -1; int *bazp; for (i = 0; i < 10; ++i) { h1 = dlopen (modname1, RTLD_LAZY); if (h1 == NULL) { printf ("cannot open '%s': %s\n", modname1, dlerror ()); exit (1); } /* Dirty test code here: we peek into a private data structure. We make sure that the module gets assigned the same ID every time. The value of the first round is used. */ #ifdef __UCLIBC__ if (modid1 == (size_t) -1) modid1 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid; else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid != (size_t) modid1) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid, modid1); result = 1; } #else if (modid1 == (size_t) -1) modid1 = ((struct link_map *) h1)->l_tls_modid; else if (((struct link_map *) h1)->l_tls_modid != modid1) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *) h1)->l_tls_modid, modid1); result = 1; } #endif fp1 = dlsym (h1, "in_dso2"); if (fp1 == NULL) { printf ("cannot get symbol 'in_dso2' in %s\n", modname1); exit (1); } result |= fp1 (); h2 = dlopen (modname2, RTLD_LAZY); if (h2 == NULL) { printf ("cannot open '%s': %s\n", modname2, dlerror ()); exit (1); } /* Dirty test code here: we peek into a private data structure. We make sure that the module gets assigned the same ID every time. The value of the first round is used. */ #ifdef __UCLIBC__ if (modid2 == (size_t) -1) modid2 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid; else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid != (size_t) modid2) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid, modid2); result = 1; } #else if (modid2 == (size_t) -1) modid2 = ((struct link_map *) h1)->l_tls_modid; else if (((struct link_map *) h1)->l_tls_modid != modid2) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *) h1)->l_tls_modid, modid2); result = 1; } #endif bazp = dlsym (h2, "baz"); if (bazp == NULL) { printf ("cannot get symbol 'baz' in %s\n", modname2); exit (1); } *bazp = 42 + i; fp2 = dlsym (h2, "in_dso"); if (fp2 == NULL) { printf ("cannot get symbol 'in_dso' in %s\n", modname2); exit (1); } result |= fp2 (42 + i, bazp); dlclose (h1); dlclose (h2); h1 = dlopen (modname1, RTLD_LAZY); if (h1 == NULL) { printf ("cannot open '%s': %s\n", modname1, dlerror ()); exit (1); } /* Dirty test code here: we peek into a private data structure. We make sure that the module gets assigned the same ID every time. The value of the first round is used. */ #ifdef __UCLIBC__ if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid != modid1) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid, modid1); result = 1; } #else if (((struct link_map *) h1)->l_tls_modid != modid1) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *) h1)->l_tls_modid, modid1); result = 1; } #endif fp1 = dlsym (h1, "in_dso2"); if (fp1 == NULL) { printf ("cannot get symbol 'in_dso2' in %s\n", modname1); exit (1); } result |= fp1 (); h2 = dlopen (modname2, RTLD_LAZY); if (h2 == NULL) { printf ("cannot open '%s': %s\n", modname2, dlerror ()); exit (1); } /* Dirty test code here: we peek into a private data structure. We make sure that the module gets assigned the same ID every time. The value of the first round is used. */ #ifdef __UCLIBC__ if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid != modid2) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid, modid2); result = 1; } #else if (((struct link_map *) h1)->l_tls_modid != modid2) { printf ("round %d: modid now %zd, initially %zd\n", i, ((struct link_map *) h1)->l_tls_modid, modid2); result = 1; } #endif bazp = dlsym (h2, "baz"); if (bazp == NULL) { printf ("cannot get symbol 'baz' in %s\n", modname2); exit (1); } *bazp = 62 + i; fp2 = dlsym (h2, "in_dso"); if (fp2 == NULL) { printf ("cannot get symbol 'in_dso' in %s\n", modname2); exit (1); } result |= fp2 (62 + i, bazp); /* This time the dlclose calls are in reverse order. */ dlclose (h2); dlclose (h1); } return result; #else return 0; #endif }