void drawEllipse(double x, double y, double r) { TEllipse *e; e = new TEllipse(x,y,r); e->SetFillStyle(4000); e->Draw(); }
void transparency() { TCanvas *c1 = new TCanvas("c1", "c1",224,330,700,527); c1->Range(-0.125,-0.125,1.125,1.125); TLatex *tex = new TLatex(0.06303724,0.0194223,"This text is opaque and this line is transparent"); tex->SetLineWidth(2); tex->Draw(); TArrow *arrow = new TArrow(0.5555158,0.07171314,0.8939828,0.6195219,0.05,"|>"); arrow->SetLineWidth(4); arrow->SetAngle(30); arrow->Draw(); // Draw a transparent graph. Double_t x[10] = { 0.5232808, 0.8724928, 0.9280086, 0.7059456, 0.7399714, 0.4659742, 0.8241404, 0.4838825, 0.7936963, 0.743553}; Double_t y[10] = { 0.7290837, 0.9631474, 0.4775896, 0.6494024, 0.3555777, 0.622012, 0.7938247, 0.9482072, 0.3904382, 0.2410359}; TGraph *graph = new TGraph(10,x,y); graph->SetLineColorAlpha(46, 0.1); graph->SetLineWidth(7); graph->Draw("l"); // Draw an ellipse with opaque colors. TEllipse *ellipse = new TEllipse(0.1740688,0.8352632,0.1518625,0.1010526,0,360,0); ellipse->SetFillColor(30); ellipse->SetLineColor(51); ellipse->SetLineWidth(3); ellipse->Draw(); // Draw an ellipse with transparent colors, above the previous one. ellipse = new TEllipse(0.2985315,0.7092105,0.1566977,0.1868421,0,360,0); ellipse->SetFillColorAlpha(9, 0.571); ellipse->SetLineColorAlpha(8, 0.464); ellipse->SetLineWidth(3); ellipse->Draw(); // Draw a transparent blue text. tex = new TLatex(0.04871059,0.1837649,"This text is transparent"); tex->SetTextColorAlpha(9, 0.476); tex->SetTextSize(0.125); tex->SetTextAngle(26.0); tex->Draw(); }
void drawExperiments(){ TEllipse *eRHIC = new TEllipse(0.4, 0.55, 0.035, 0.13, 0., 165., 335.); // eRHIC->SetFillColor(0); eRHIC->SetNoEdges(); eRHIC->SetFillStyle(0); eRHIC->SetLineWidth(2); eRHIC->Draw(); TLine *lGarbage = new TLine(0.383507,0.595395,0.401148,0.546523); lGarbage->SetLineColor(17); lGarbage->SetLineWidth(3); lGarbage->Draw(); TArrow *aRHIC = new TArrow(0.385543,0.600282,0.382829,0.595395, 0.025, "|>"); aRHIC->Draw(); TLatex *xRHIC = new TLatex(0.417432, 0.679342, "RHIC"); xRHIC->SetTextSize(0.04); xRHIC->Draw(); }
/// used in display_beamprofile() : not working ! void getEllipseParameters(const float * x_data, const float * y_data, const unsigned int N, float& x_width, float& y_width, float& angle) { // In order to fit a good ellipse on the scattered plot : // 1) The TH2 is copied into a TGraph, to fit it with y(x) = ax => to retrieve the angle // 2) Rotation of the Graph to get the RMS in X and Y // 3) Creation of the final ellipse, with the good widths and angle TCanvas * ca0 = new TCanvas; ca0->Divide(2,1); ca0->cd(1); TGraph * draft = new TGraph(N,x_data,y_data); draft->Draw("AP"); draft->Fit("pol1","Q"); TF1 * pol1 = draft->GetFunction("pol1"); pol1->Draw("same"); // gets the angle [rad] angle = asin(1.) - atan(pol1->GetParameter(1)); double x_datarot[N], y_datarot[N]; for (unsigned int i=0; i<N; i++) { x_datarot[i]= x_data[i]*cos(angle) - y_data[i]*sin(angle); y_datarot[i]= x_data[i]*sin(angle) + y_data[i]*cos(angle); } ca0->cd(2); TGraph * draft2 = new TGraph(N,x_datarot,y_datarot); draft2->Draw("AP"); x_width = draft2->GetRMS(1); y_width = draft2->GetRMS(2); angle = 180-90*angle/asin(1.); // draft->Draw("AP"); ca0->cd(1); TEllipse * ell = new TEllipse(draft->GetMean(1),draft2->GetMean(2),x_width*3,y_width*3); ell->SetTheta(angle); ell->Draw("same"); //cout << "x = " << x_width << "\t y = " << y_width << "\t angle = " << angle << endl; // delete draft2; // delete draft; // delete ca0; return; }
void drawNormal(){ TEllipse *eNorm = new TEllipse(0.45, 0.0, 0.07, 0.03, 0., 180., 0.); eNorm->SetFillColor(1); eNorm->Draw(); TLatex *xNorm = new TLatex(0.39, 0.05, "Nuclei"); xNorm->SetTextSize(0.04); xNorm->Draw(); }
void plotThisOne() { gSystem->Load("libAskRay.so"); TCanvas * can = new TCanvas("can","can"); TH1F *framey = can->DrawFrame(-7e6,-7e6,+7e6,+7e6); TEllipse *elipsey = new TEllipse(0,0,6378.1e3,6378.1e3); elipsey->SetLineColor(8); elipsey->SetLineWidth(3); elipsey->Draw();//Ellipse(0,0,6378.1e3,6378.1e3); Double_t gz[361],gx[361]; Int_t count=0; for(Double_t theta=-180;theta<=180;theta+=1) { Double_t radius=AskGeom::getGeoidFromTheta(theta*TMath::DegToRad()); gz[count]=radius*TMath::Cos(theta*TMath::DegToRad()); gx[count]=radius*TMath::Sin(theta*TMath::DegToRad()); // cout << theta << "\t" << radius << "\t" << gz[count] << "\t" << gx[count] << endl; count++; } TGraph *geoid = new TGraph(count,gx,gz); geoid->Draw("l"); TLine *liney = new TLine(); liney->SetLineColor(9); liney->SetLineWidth(1); liney->SetLineStyle(2); Double_t point1[3]={-294476, 489656, 6.33461e+06}; Double_t point2[3]={-297716, 487929, 6.34309e+06}; liney->DrawLine(point1[1],point1[2],point2[1],point2[2]); }
void eventDirGenerator() { double xVals[10000],yVals[10000],zVals[10000]; double rV=25000; double thetaV,phiV; double thetaMom,phiMom; int numPoints=0; TCanvas * can = new TCanvas("can","can"); TH1F *framey = can->DrawFrame(-7e6,-7e6,+7e6,+7e6); TEllipse *elipsey = new TEllipse(0,0,6378.1e3,6378.1e3); elipsey->SetLineColor(8); elipsey->SetLineWidth(3); elipsey->Draw();//Ellipse(0,0,6378.1e3,6378.1e3); TLine *liney = new TLine(); liney->SetLineColor(9); liney->SetLineWidth(1); liney->SetLineStyle(2); for(int i=0; i<10000; i++) { pickRandomThetaPhiOnSphere(phiV,thetaV); pickRandomDowngoingDirection(phiMom,thetaMom); double dxp=-1*TMath::Cos(phiMom)*TMath::Sin(thetaMom); double dyp=-1*TMath::Sin(phiMom)*TMath::Sin(thetaMom); double dzp=-1*TMath::Cos(thetaMom); TVector3 veccy(dxp,dyp,dzp); veccy.RotateZ(phiV); veccy.RotateX(thetaV); // double cosphi=TMath::Cos(phiV); // double sinphi=TMath::Sin(phiV); // double costheta=TMath::Cos(thetaV); // double sintheta=TMath::Sin(thetaV); // double dx=cosphi*dxp-sinphi*dyp; // double dy=costheta*sinphi*dxp + costheta*cosphi*dyp - sintheta*dzp; // double dz=sintheta*sinphi*dxp + sintheta*cosphi*dxp + costheta*dzp; // cout << veccy.X() << "\t" << veccy.Y() << "\t" << veccy.Z() << endl; // cout << dx << "\t" << dy << "\t" << dz << endl; // cout << veccy.Mag() << endl; //cout << phiV << "\t" << thetaV << endl; // cout <<rEarth*rEarth << "\t" << rV*rV << "\t" << 2*rEarth*rV*TMath::Cos(TMath::Pi()-thetaV) << endl; double rNew=TMath::Sqrt(rEarth*rEarth + rV*rV - 2*rEarth*rV*TMath::Cos(TMath::Pi()-thetaV)); double thetaNew=TMath::ASin(TMath::Sin(TMath::Pi()-thetaV)*rV/rNew); double phiNew=phiV; // if(rNew>rEarth) { // cout << "Above:\t" << endl; // } // else { // cout << "Below:\t" << endl; // } double z=rNew*TMath::Cos(thetaNew); double x=rNew*TMath::Sin(thetaNew)*TMath::Cos(phiNew); double y=rNew*TMath::Sin(thetaNew)*TMath::Sin(phiNew); TVector3 intPos(x,y,z); TVector3 surfPos; int isValid=getSurfacePoint(intPos,veccy,surfPos); // cout << isValid << endl; double x2=surfPos.X(); double y2=surfPos.Y(); double z2=surfPos.Z(); if(isValid) { double x3=surfPos.X()+veccy.X()*1e6; double z3=surfPos.Z()+veccy.Z()*1e6; liney->DrawLine(x2,z2,x3,z3); xVals[numPoints]=surfPos.X(); yVals[numPoints]=surfPos.Y(); zVals[numPoints]=surfPos.Z(); numPoints++; } } cout << numPoints << endl; TGraph *grxz= new TGraph(numPoints,xVals,yVals); grxz->Draw("p"); }
void draw_layer(TCanvas* c, TH2F* h, Int_t iHist, Int_t nLayers, Double_t maxWeight) { const Double_t MAX_NEURONS_NICE = 12; const Double_t LABEL_HEIGHT = 0.03; const Double_t LABEL_WIDTH = 0.20; Double_t ratio = ((Double_t)(c->GetWindowHeight())) / c->GetWindowWidth(); Double_t rad, cx1, *cy1, cx2, *cy2; // this is the smallest radius that will still display the activation images rad = 0.04*650/c->GetWindowHeight(); Int_t nNeurons1 = h->GetNbinsX(); cx1 = iHist*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH; cy1 = new Double_t[nNeurons1]; Int_t nNeurons2 = h->GetNbinsY(); cx2 = (iHist+1)*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH; cy2 = new Double_t[nNeurons2]; Double_t effRad1 = rad; if (nNeurons1 > MAX_NEURONS_NICE) effRad1 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons1); for (Int_t i = 0; i < nNeurons1; i++) { cy1[nNeurons1-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons1 + 1.0/(2.0*nNeurons1) + LABEL_HEIGHT; if (iHist == 0) { TEllipse *ellipse = new TEllipse(cx1, cy1[nNeurons1-i-1], effRad1*ratio, effRad1, 0, 360, 0); ellipse->SetFillColor(TColor::GetColor( "#fffffd" )); ellipse->SetFillStyle(1001); ellipse->Draw(); if (i == 0) ellipse->SetLineColor(9); if (nNeurons1 > MAX_NEURONS_NICE) continue; Int_t whichActivation = 0; if (iHist==0 || iHist==nLayers-1 || i==0) whichActivation = 1; draw_activation(c, cx1, cy1[nNeurons1-i-1], rad*ratio, rad, whichActivation); } } if (iHist == 0) draw_input_labels(nNeurons1, cy1, rad, (1.0-LABEL_WIDTH)/nLayers); Double_t effRad2 = rad; if (nNeurons2 > MAX_NEURONS_NICE) effRad2 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons2); for (Int_t i = 0; i < nNeurons2; i++) { cy2[nNeurons2-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons2 + 1.0/(2.0*nNeurons2) + LABEL_HEIGHT; TEllipse *ellipse = new TEllipse(cx2, cy2[nNeurons2-i-1], effRad2*ratio, effRad2, 0, 360, 0); ellipse->SetFillColor(TColor::GetColor( "#fffffd" )); ellipse->SetFillStyle(1001); ellipse->Draw(); if (i == 0 && nNeurons2 > 1) ellipse->SetLineColor(9); if (nNeurons2 > MAX_NEURONS_NICE) continue; Int_t whichActivation = 0; if (iHist+1==0 || iHist+1==nLayers-1 || i==0) whichActivation = 1; draw_activation(c, cx2, cy2[nNeurons2-i-1], rad*ratio, rad, whichActivation); } for (Int_t i = 0; i < nNeurons1; i++) { for (Int_t j = 0; j < nNeurons2; j++) { draw_synapse(cx1, cy1[i], cx2, cy2[j], effRad1*ratio, effRad2*ratio, h->GetBinContent(i+1, j+1)/maxWeight); } } delete[] cy1; delete[] cy2; }
void drawSinglePositionPlot( const std::string& outputdir, TFile* file, const std::string& runName, const std::string& suffix ) { // manually set beam nominal position for some known runs: float beamX = -999.; float beamY = -999.; float beamRX = 4.; float beamRY = 2.; RunHelper::getBeamPosition( runName, beamX, beamY ); bool drawBeam = ((beamX>-999.) && (beamY>-999.)); //bool beamInsideHodo = ((fabs(beamX)<4.) && (fabs(beamY)<4.)); TCanvas* c1 = new TCanvas("c1", "", 600, 600); c1->cd(); TH2D* h2_xyPos = (TH2D*)file->Get(Form("xyPos_new%s", suffix.c_str())); TH2D* h2_xyPos_hodo = (TH2D*)file->Get(Form("xyPos%s_hodo", suffix.c_str())); //TH2D* h2_xyPos_hodo = (TH2D*)file->Get(Form("xyPos%s_hodo", suffix.c_str())); TH2D* h2_xyPos_bgo = (TH2D*)file->Get(Form("xyPos%s_bgo", suffix.c_str())); TH2D* h2_xyPos_calo = (TH2D*)file->Get(Form("xyPos%s_calo", suffix.c_str())); float xySize = 25.; float xMax = xySize*3./2.; TH2D* h2_axes = new TH2D("axes", "", 10, -xMax, xMax, 10, -xMax, xMax); h2_axes->SetXTitle("X Position [mm]"); h2_axes->SetYTitle("Y Position [mm]"); h2_axes->Draw(); TGraphErrors* gr_xyCenter = get_xyCenter( h2_xyPos ); TGraphErrors* gr_xyCenter_hodo = get_xyCenter( h2_xyPos_hodo ); TGraphErrors* gr_xyCenter_bgo = get_xyCenter( h2_xyPos_bgo ); TGraphErrors* gr_xyCenter_calo = get_xyCenter( h2_xyPos_calo ); gr_xyCenter->SetMarkerColor(kRed+2); gr_xyCenter->SetLineColor(kRed+2); gr_xyCenter->SetMarkerStyle(20); gr_xyCenter->SetMarkerSize(1.6); gr_xyCenter_hodo->SetMarkerColor(kBlack); gr_xyCenter_hodo->SetLineColor(kBlack); gr_xyCenter_hodo->SetMarkerStyle(20); gr_xyCenter_hodo->SetMarkerSize(1.6); gr_xyCenter_bgo->SetMarkerColor(kGreen+3); gr_xyCenter_bgo->SetLineColor(kGreen+3); gr_xyCenter_bgo->SetMarkerStyle(20); gr_xyCenter_bgo->SetMarkerSize(1.6); gr_xyCenter_calo->SetMarkerColor(kBlue); gr_xyCenter_calo->SetLineColor(kBlue); gr_xyCenter_calo->SetMarkerStyle(20); gr_xyCenter_calo->SetMarkerSize(1.6); //TGraphErrors* gr_xyPos_fit = getFitPositionCeF3(file); //gr_xyPos_fit->SetMarkerColor(kRed+2); //gr_xyPos_fit->SetLineColor(kRed+2); //gr_xyPos_fit->SetMarkerStyle(24); //gr_xyPos_fit->SetMarkerSize(1.6); // fit hodo points with the expected beam size float xPos_hodo_fit, xPos_hodo_fit_err; float yPos_hodo_fit, yPos_hodo_fit_err; fitHodoWithBeam( outputdir, "X"+suffix, h2_xyPos_hodo->ProjectionX(), beamRX, xPos_hodo_fit, xPos_hodo_fit_err ); fitHodoWithBeam( outputdir, "Y"+suffix, h2_xyPos_hodo->ProjectionY(), beamRY, yPos_hodo_fit, yPos_hodo_fit_err ); TGraphErrors* gr_xyCenter_hodo_fit = new TGraphErrors(0); gr_xyCenter_hodo_fit->SetPoint(0, xPos_hodo_fit, yPos_hodo_fit); gr_xyCenter_hodo_fit->SetPointError(0, xPos_hodo_fit_err, yPos_hodo_fit_err); gr_xyCenter_hodo_fit->SetMarkerStyle(20); gr_xyCenter_hodo_fit->SetMarkerSize(1.6); int lineColor = 17; //TLine* line_x1 = new TLine( -xMax, -xySize/2., +xMax, -xySize/2. ); //line_x1->SetLineColor(lineColor); //line_x1->Draw("same"); //TLine* line_x2 = new TLine( -xMax, +xySize/2., +xMax, +xySize/2. ); //line_x2->SetLineColor(lineColor); //line_x2->Draw("same"); //TLine* line_y1 = new TLine( -xySize/2., -xMax, -xySize/2., +xMax ); //line_y1->SetLineColor(lineColor); //line_y1->Draw("same"); //TLine* line_y2 = new TLine( +xySize/2., -xMax, +xySize/2., +xMax ); //line_y2->SetLineColor(lineColor); //line_y2->Draw("same"); TLegend* legend = new TLegend( 0.75, 0.21, 0.9, 0.39 ); legend->SetFillColor(0); legend->SetTextSize(0.038); legend->AddEntry( gr_xyCenter_hodo_fit, "Hodo", "P" ); //legend->AddEntry( gr_xyCenter, "CeF3", "P" ); legend->AddEntry( gr_xyCenter_bgo, "BGO", "P" ); legend->AddEntry( gr_xyCenter_calo, "Calo", "P" ); legend->Draw("same"); float bgoFrontSize = 22.; std::vector<TBox*> b_bgo; for( unsigned i=0; i<BGO_CHANNELS; ++i ) { float x,y; RunHelper::getBGOCoordinates( i, x, y ); TBox* b_bgo0 = new TBox( x-bgoFrontSize/2., y-bgoFrontSize/2., x+bgoFrontSize/2., y+bgoFrontSize/2. ); b_bgo0->SetFillColor(0); b_bgo0->SetFillStyle(0); b_bgo0->SetLineColor(lineColor); b_bgo0->SetLineWidth(1.); b_bgo0->Draw("L same"); b_bgo.push_back(b_bgo0); } TGraph* gr_beamPos = new TGraph(0); gr_beamPos->SetMarkerStyle(24); gr_beamPos->SetMarkerSize(4); TLegend* legend2 = new TLegend( 0.18, 0.225, 0.5, 0.255 ); legend2->SetFillColor(0); legend2->SetFillStyle(0); legend2->SetLineColor(0); legend2->SetLineWidth(0); legend2->SetTextSize(0.035); legend2->AddEntry( gr_beamPos, "Beam Position", "P" ); if( drawBeam ) legend2->Draw("same"); TPaveText* label_top = DrawTools::getLabelTop(); TPaveText* label_run = DrawTools::getLabelRun(runName); label_top->Draw("same"); label_run->SetFillStyle(0); label_run->SetLineColor(0); label_run->SetLineWidth(0); label_run->Draw("same"); h2_xyPos_hodo->SetMarkerColor(14); h2_xyPos->SetMarkerColor(46); h2_xyPos_bgo->SetMarkerColor(30); h2_xyPos_calo->SetMarkerColor(38); float hodoSize = 8.; TLine* lineHodo_x1 = new TLine( -hodoSize/2., -hodoSize/2., +hodoSize/2., -hodoSize/2. ); lineHodo_x1->SetLineColor(kBlack); lineHodo_x1->SetLineStyle(2); lineHodo_x1->Draw("same"); TLine* lineHodo_x2 = new TLine( -hodoSize/2., +hodoSize/2., +hodoSize/2., +hodoSize/2. ); lineHodo_x2->SetLineColor(kBlack); lineHodo_x2->SetLineStyle(2); lineHodo_x2->Draw("same"); TLine* lineHodo_y1 = new TLine( -hodoSize/2., -hodoSize/2., -hodoSize/2., +hodoSize/2. ); lineHodo_y1->SetLineColor(kBlack); lineHodo_y1->SetLineStyle(2); lineHodo_y1->Draw("same"); TLine* lineHodo_y2 = new TLine( +hodoSize/2., -hodoSize/2., +hodoSize/2., +hodoSize/2. ); lineHodo_y2->SetLineColor(kBlack); lineHodo_y2->SetLineStyle(2); lineHodo_y2->Draw("same"); h2_xyPos_bgo->Draw("same"); //h2_xyPos->Draw("same"); h2_xyPos_hodo->Draw("same"); h2_xyPos_calo->Draw("same"); TEllipse* beamPos = new TEllipse( beamX, beamY, beamRX, beamRY ); beamPos->SetLineColor(kBlack); beamPos->SetFillStyle(0); beamPos->Draw("same"); //gr_xyCenter_hodo->Draw("p same"); // now using hodo_fit gr_xyCenter_hodo_fit->Draw("p same"); gr_xyCenter_bgo->Draw("p same"); //gr_xyCenter->Draw("p same"); // don't draw for now gr_xyCenter_calo->Draw("p same"); //gr_xyPos_fit->Draw("p same"); c1->SaveAs(Form("%s/xyPos%s.eps", outputdir.c_str(), suffix.c_str()) ); c1->SaveAs(Form("%s/xyPos%s.pdf", outputdir.c_str(), suffix.c_str()) ); c1->SaveAs(Form("%s/xyPos%s.png", outputdir.c_str(), suffix.c_str()) ); c1->Clear(); xMax = xySize/2.; TH2D* h2_axes_zoom = new TH2D("axes_zoom", "", 10, -xMax, xMax, 10, -xMax, xMax); h2_axes_zoom->SetXTitle("X Position [mm]"); h2_axes_zoom->SetYTitle("Y Position [mm]"); h2_axes_zoom->Draw(); drawBeam = ((fabs(beamX)<xMax) && (fabs(beamY)<xMax)); if( drawBeam ) legend2->Draw("same"); label_top->Draw("same"); label_run->Draw("same"); legend->Draw("same"); h2_xyPos_bgo->Draw("same"); h2_xyPos_hodo->Draw("same"); h2_xyPos_calo->Draw("same"); //h2_xyPos->Draw("same"); lineHodo_x1->Draw("same"); lineHodo_x2->Draw("same"); lineHodo_y1->Draw("same"); lineHodo_y2->Draw("same"); beamPos->Draw("same"); //gr_xyCenter_hodo->Draw("p same"); // now using hodo_fit gr_xyCenter_hodo_fit->Draw("p same"); gr_xyCenter_bgo->Draw("p same"); //gr_xyCenter->Draw("p same"); gr_xyCenter_calo->Draw("p same"); //gr_xyPos_fit->Draw("p same"); c1->SaveAs(Form("%s/xyPos%s_zoom.eps", outputdir.c_str(), suffix.c_str()) ); c1->SaveAs(Form("%s/xyPos%s_zoom.pdf", outputdir.c_str(), suffix.c_str()) ); c1->SaveAs(Form("%s/xyPos%s_zoom.png", outputdir.c_str(), suffix.c_str()) ); delete c1; delete h2_axes; delete h2_axes_zoom; delete legend; }
/* EXAMPLE root .L particleDrawer.C++ particleDrawer("../test/test.root",11,2) */ void particleDrawer(TString filename, int entry = 0, int PVAssoc = 2, bool debug = false) { cout << "particleDrawer::Setting the TDR style ... "; setTDRStyle(); cout << "DONE" << endl; cout << "particleDrawer::Drawing the default (TDR) frame ... " << endl; TH1D* frame = new TH1D(); frame->GetXaxis()->SetLimits(-5,5); frame->GetXaxis()->SetTitle("#eta"); frame->GetYaxis()->SetRangeUser(-TMath::Pi(),TMath::Pi()); frame->GetYaxis()->SetTitle("#phi"); TCanvas* c = tdrCanvas("particleBasedEvent",frame,4,0,true); c->GetPad(0)->SetLogz(); cout << "\r\r\r\r\r\r" << flush; cout << setw(52) << " " << "DONE" << endl << endl; cout << "particleDrawer::Opening the input file (" << filename << " ) ... "; TFile* inFile = TFile::Open(filename,"READ"); assert(inFile!=NULL); cout << "DONE" << endl; cout << "particleDrawer::Getting the input trees ... "; TTree* puppiTree = (TTree*)inFile->Get("puppiReader/puppiTree"); assert(puppiTree!=NULL); TTree* jetTree = (TTree*)inFile->Get("nt_AK4PFchs/t"); assert(jetTree!=NULL); cout << "DONE" << endl; cout << "particleDrawer::Making the ntuples ... "; puppiNtuple* pNtuple = new puppiNtuple(puppiTree); validatorNtuple* jNtuple = new validatorNtuple(jetTree); cout << "DONE" << endl; cout << "particleDrawer::Getting entry " << entry << " for puppiTree ... "; puppiTree->GetEntry(entry); cout << "DONE" << endl; cout << "particleDrawer::Filling the histograms ... "; TH2F* hPU = new TH2F("hPU","hPU",50,-5,5,60,-TMath::Pi(),TMath::Pi()); TH2F* hHard = new TH2F("hHard","hHard",50,-5,5,60,-TMath::Pi(),TMath::Pi()); for(unsigned int iparticle=0; iparticle<(*pNtuple->px).size(); iparticle++) { TLorentzVector tempVect((*pNtuple->px)[iparticle],(*pNtuple->py)[iparticle], (*pNtuple->pz)[iparticle],(*pNtuple->e)[iparticle]); if((*pNtuple->fromPV)[iparticle]<PVAssoc) { if(debug) cout << "Filling PU::fromPV = " << (*pNtuple->fromPV)[iparticle] << endl; hPU->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt()); } else { if(debug) cout << "Filling hard-scatter:: fromPV = " << (*pNtuple->fromPV)[iparticle] << endl; hHard->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt()); } } if(debug) { cout << "hPU->GetEntries() = " << hPU->GetEntries() << endl; cout << "hHard->GetEntries() = " << hHard->GetEntries() << endl; } else cout << "DONE" << endl; cout << "particleDrawer::Drawing the histograms ... "; //tdrDraw(hPU,"BOX",kFullSquare,kNone,kSolid,kGray,kNone,kNone); //tdrDraw(hHard,"colz"); THStack* stack = new THStack("stack","stack"); hPU->SetLineStyle(kSolid); hPU->SetLineColor(kGray); hPU->SetFillStyle(1001); hPU->SetFillColor(kNone); hPU->SetMarkerStyle(kFullSquare); hPU->SetMarkerColor(kNone); if(hHard->GetEntries()>0) stack->Add(hHard,"colz"); if(hPU->GetEntries()>0) stack->Add(hPU,"BOX"); tdrDraw(stack,"nostack"); set_plot_style(); c->Update(); c->RedrawAxis(); cout << "DONE" << endl; cout << "particleDrawer::Getting entry " << entry << " for jetTree ... "; jetTree->GetEntry(entry); cout << "DONE" << endl; cout << "particleDrawer::Drawing the jets ... " << endl; vector<JetCircle> jets; for(unsigned int ijet=0; ijet<jNtuple->nref; ijet++) { if((*jNtuple->jtpt)[ijet]<20) continue; double RJet = TMath::Sqrt((*jNtuple->jtarea)[ijet]/TMath::Pi()); jets.push_back(JetCircle((*jNtuple->jteta)[ijet],(*jNtuple->jtphi)[ijet],RJet,(*jNtuple->jtpt)[ijet])); } for(unsigned int ijet=0; ijet<jets.size(); ijet++) { for(unsigned int jjet=ijet+1; jjet<jets.size(); jjet++) { if(check_overlap(jets[ijet].getX(),jets[ijet].getY(),jets[ijet].getRadius(), jets[jjet].getX(),jets[jjet].getY(),jets[jjet].getRadius())) { cout << "Jet " << ijet << " overlaps with jet " << jjet << endl; if(jets[ijet].getPt()>jets[jjet].getPt()) { //find angle for jjet; jets[jjet].findAngles(jets[ijet]); } else if(jets[ijet].getPt()<jets[jjet].getPt()) { //find angle for ijet jets[ijet].findAngles(jets[jjet]); } else { //must find angle for both jets //then must draw a straight line between the two intersection points jets[jjet].findAngles(jets[ijet]); jets[ijet].findAngles(jets[jjet]); //NEED TO COMPLETE THIS FUNCTION. CURRENTLY DOESNOT DRAW LINE BETWEEN THE JETS. } cout << "Jet " << ijet << ": \n" << jets[ijet] << endl; cout << "Jet " << jjet << ": \n" << jets[jjet] << endl; } } } for(unsigned int ijet=0; ijet<jets.size(); ijet++) { loadbar2(ijet+1, jets.size()); TEllipse* cJet = new TEllipse(jets[ijet].getX(),jets[ijet].getY(), jets[ijet].getRadius(),jets[ijet].getRadius(), jets[ijet].getStartAngle(),jets[ijet].getEndAngle()); cJet->SetFillStyle(0); cJet->SetFillColor(kNone); cJet->SetLineStyle(kSolid); cJet->SetLineColor(kRed); cJet->SetLineWidth(3); cJet->Draw("only same"); } //cout << "\r\r\r\r" << flush; //cout << setw(37) << " " << "DONE" << endl << endl; cout << "particleDrawer::Saving the canvas ... "; TString name = Form("particleMap_entry%i_PVAssoc%i",entry,PVAssoc); c->SaveAs(name+".png"); c->SaveAs(name+".pdf"); c->SaveAs(name+".C"); cout << "DONE" << endl; }
void Purity_2d_fit_etagg_corr(bool data = false){ TChain* tree = new TChain("TEvent"); if(!data) tree->Add("/home/vitaly/B0toDh0/TMVA/FIL_b2dh_gen_0-1_full.root"); else tree->Add("/home/vitaly/B0toDh0/TMVA/FIL_b2dh_data.root"); const int _mode = 2; const int _h0mode = 10; const int _b0f = -1; // gROOT->ProcessLine(".L pdfs/RooRhoDeltaEPdf.cxx+"); RooCategory b0f("b0f","b0f"); b0f.defineType("signal",1); b0f.defineType("fsr",10); b0f.defineType("bad_pi0",5); // b0f.defineType("peak1",3); // b0f.defineType("peak2",4); // b0f.defineType("peak3",11); // b0f.defineType("peak4",20); b0f.defineType("comb",-1); // RooCategory d0f("d0f","d0f"); // d0f.defineType("signal",1); RooArgSet argset; argset.add(b0f); const double mbcMin = 5.2; const double mbcMax = 5.29; double deMin = -0.15; // if(keysflag) deMin = -0.3; const double deMax = 0.3; const double elliscaleDe = TMath::Sqrt(4./TMath::Pi()); const double elliscaleMbc = TMath::Sqrt(4./TMath::Pi()); const double DE_MIN = de_min; const double DE_MAX = de_max; // RooConstVar DELO("DELO","DELO",DE_MIN); RooConstVar DELO("DELO","DELO",DE_MIN); RooRealVar mbc_center("mbc_center","mbc_center",0.5*(mbc_min+mbc_max),mbc_min,mbc_max); mbc_center.setConstant(kTRUE); RooRealVar mbc_center_eq("mbc_center_eq","mbc_center_eq",mr_argedge_3-0.5*(mbc_max-mbc_min)*elliscaleMbc,mbc_min,mbc_max); mbc_center_eq.setConstant(kTRUE); RooRealVar de_center("de_center","de_center",0.5*(DE_MIN+DE_MAX),DE_MIN,DE_MAX); de_center.setConstant(kTRUE); RooRealVar mbc_radius("mbc_radius","mbc_radius",0.5*(mbc_max-mbc_min)*elliscaleMbc,0,0.5*(mbcMax-mbcMin)); mbc_radius.setConstant(kTRUE); RooRealVar de_radius("de_radius","de_radius",0.5*(DE_MAX-DE_MIN)*elliscaleDe,0.,0.5*(deMax-deMin)); de_radius.setConstant(kTRUE); RooRealVar mbc_radius1("mbc_radius1","mbc_radius1",0.5*(mbc_max-mbc_min),0,0.5*(mbcMax-mbcMin)); mbc_radius1.setConstant(kTRUE); RooRealVar de_radius1("de_radius1","de_radius1",0.5*(DE_MAX-DE_MIN),0.,0.5*(deMax-deMin)); de_radius1.setConstant(kTRUE); cout << 0.5*(mbc_min+mbc_max) << " " << 0.5*(mbc_max-mbc_min) << endl; cout << 0.5*(DE_MIN+DE_MAX) << " " << 0.5*(DE_MAX-DE_MIN) << endl; mbc_center.Print(); mbc_center_eq.Print(); const double BDTG_MIN = bdtg_cut_etagg; const double BDTG_MAX = 1; RooCategory mode("mode","mode"); mode.defineType("eta",2); RooCategory h0mode("h0mode","h0mode"); h0mode.defineType("gg",10); argset.add(mode); argset.add(h0mode); RooRealVar mbc("mbc","M_{bc}",0.5*(mbc_min+mbc_max),mbcMin,mbcMax,"GeV"); argset.add(mbc); mbc.setRange("Signal",mbc_min,mbc_max); mbc.setRange("mbcSignal",mbc_min,mbc_max); mbc.setRange("deSignal",mbcMin,mbcMax); RooRealVar de("de","#DeltaE",deMin,deMax,"GeV"); argset.add(de); de.setRange("Signal",DE_MIN,DE_MAX); de.setRange("mbcSignal",deMin,deMax); de.setRange("deSignal",DE_MIN,DE_MAX); RooRealVar md("md","md",DMass-md_cut,DMass+md_cut,"GeV"); argset.add(md); RooRealVar mk("mk","mk",KMass-mk_cut,KMass+mk_cut,"GeV"); argset.add(mk); RooRealVar mh0("mh0","mh0",EtaMass-meta_cut,EtaMass+meta_cut,"GeV"); argset.add(mh0); RooRealVar bdtg("bdtg","bdtg",BDTG_MIN,1.); argset.add(bdtg); RooRealVar atckpi_max("atckpi_max","atckpi_max",0.,atckpi_cut); argset.add(atckpi_max); argset.add(b0f); RooDataSet ds("ds","ds",tree,argset,"mbc>0||mbc<=0"); // RooDataSet* ds0 = ds.reduce(RooArgSet(de,mbc)); stringstream out; out.str(""); out << "de<" << DE_MAX << " && de>" << DE_MIN; out << " && mbc>" << mbc_min << " && mbc<" << mbc_max; Roo1DTable* sigtable = ds.table(b0f,out.str().c_str()); sigtable->Print(); sigtable->Print("v"); Roo1DTable* fulltable = ds.table(b0f); fulltable->Print(); fulltable->Print("v"); // RooDataHist* dh = ds0->binnedClone(); ds.Print(); if(!data){ out.str(""); out << "de<" << DE_MAX << " && de>" << DE_MIN; out << " && mbc>" << mbc_min << " && mbc<" << mbc_max; Roo1DTable* sigtable = ds.table(b0f,out.str().c_str()); sigtable->Print(); sigtable->Print("v"); Roo1DTable* fulltable = ds.table(b0f); fulltable->Print(); fulltable->Print("v"); } //////////////// // Signal PDF // //////////////// //////////// // de pdf // //////////// RooRealVar de0("de0","de0",get_de0(_mode,_h0mode,_b0f),-0.2,0.1); if(cSIG) de0.setConstant(kTRUE); RooRealVar s1("s1","s1",get_s1(_mode,_h0mode,_b0f),0.,0.5); if(cSIG) s1.setConstant(kTRUE); RooGaussian g1("g1","g1",de,de0,s1); RooRealVar deCBl("deCBl","deCBl",get_deCBl(_mode,_h0mode,_b0f),-0.2,0.1); if(cSIG) deCBl.setConstant(kTRUE); RooRealVar sCBl("sCBl","sCBl",get_sCBl(_mode,_h0mode,_b0f),0.,0.5); if(cSIG) sCBl.setConstant(kTRUE); RooRealVar nl("nl","nl",get_nl(_mode,_h0mode,_b0f),0.,100.); if(cSIG) nl.setConstant(kTRUE); RooRealVar alphal("alphal","alphal",get_alphal(_mode,_h0mode,_b0f),-10.,10.); if(cSIG) alphal.setConstant(kTRUE); RooRealVar deCBr("deCBr","deCBr",get_deCBr(_mode,_h0mode,_b0f),-0.2,0.1); if(cSIG) deCBr.setConstant(kTRUE); RooRealVar sCBr("sCBr","sCBr",get_sCBr(_mode,_h0mode,_b0f),0.,0.5); if(cSIG) sCBr.setConstant(kTRUE); RooRealVar nr("nr","nr",get_nr(_mode,_h0mode,_b0f),0.,100.); if(cSIG) nr.setConstant(kTRUE); RooRealVar alphar("alphar","alphar",get_alphar(_mode,_h0mode,_b0f),-10.,10.); if(cSIG) alphar.setConstant(kTRUE); RooCBShape CBl("CBl","CBl",de,deCBl,sCBl,alphal,nl); RooCBShape CBr("CBr","CBr",de,deCBr,sCBr,alphar,nr); RooRealVar fCBl("fCBl","fCBl",get_fCBl(_mode,_h0mode,_b0f),0.,1.); if(cSIG) fCBl.setConstant(kTRUE); RooRealVar fCBr("fCBr","fCBr",get_fCBr(_mode,_h0mode,_b0f),0.,1.); if(cSIG) fCBr.setConstant(kTRUE); RooAddPdf pdf_de_sig("pdf_de_sig","pdf_de_sig",RooArgList(CBl,CBr,g1),RooArgSet(fCBl,fCBr)); ///////////// // mbc pdf // ///////////// RooRealVar c1_mbc0("c1_mbc0","c1_mbc0",m_mbc0_c1_eta10,-0.1,0.); c1_mbc0.setConstant(kTRUE); RooRealVar c2_mbc0("c2_mbc0","c2_mbc0",m_mbc0_c2_eta10,0.,1.); c2_mbc0.setConstant(kTRUE); RooRealVar c3_mbc0("c3_mbc0","c3_mbc0",m_mbc0_c3_eta10,0.,10.); c3_mbc0.setConstant(kTRUE); RooRealVar mbc0("mbc0","mbc0",m_mbc0_c0_eta10,5.26,5.30); if(cSIG) mbc0.setConstant(kTRUE); // RooFormulaVar _mbc0("_mbc0","_mbc0","abs(@0+@1*@2+@1*@1*@3+@1*@1*@1*@4) > abs(@0+@5*@2+@5*@5*@3+@5*@5*@5*@4) ? (@0+@5*@2+@5*@5*@3+@5*@5*@5*@4) : @0+@1*@2+@1*@1*@3+@1*@1*@1*@4",RooArgList(mbc0,de,c1_mbc0,c2_mbc0,c3_mbc0,DELO)); RooFormulaVar _mbc0("_mbc0","_mbc0","abs(@1*@2+@1*@1*@3+@1*@1*@1*@4) > abs(@5*@2+@5*@5*@3+@5*@5*@5*@4) ? @0 : @0+@1*@2+@1*@1*@3+@1*@1*@1*@4",RooArgList(mbc0,de,c1_mbc0,c2_mbc0,c3_mbc0,DELO)); RooRealVar c1_alpha("c1_alpha","c1_alpha",m_alpha_c1_eta10,-2.,0.); c1_alpha.setConstant(kTRUE); RooRealVar c2_alpha("c2_alpha","c2_alpha",m_alpha_c2_eta10,10.,100.);c2_alpha.setConstant(kTRUE); RooRealVar c3_alpha("c3_alpha","c3_alpha",m_alpha_c3_eta10,10.,100.);c3_alpha.setConstant(kTRUE); RooRealVar alpha("alpha","alpha",m_alpha_c0_eta10,0.,0.1); if(cSIG) alpha.setConstant(kTRUE); RooFormulaVar _alpha("_alpha","_alpha","abs(@0+@1*@2+@1*@1*@3+@1*@1*@1*@4) > abs(@0+@5*@2+@5*@5*@3+@5*@5*@5*@4) ? (@0+@5*@2+@5*@5*@3+@5*@5*@5*@4) : (@0+@1*@2+@1*@1*@3+@1*@1*@1*@4)",RooArgList(alpha,de,c1_alpha,c2_alpha,c3_alpha,DELO)); RooRealVar c1_width("c1_width","c1_width",m_width_c1_eta10,-2.,0.); c1_width.setConstant(kTRUE); RooRealVar c2_width("c2_width","c2_width",m_width_c2_eta10,10.,100.);c2_width.setConstant(kTRUE); RooRealVar width("width","width",m_width_c0_eta10,0.,0.1); if(cSIG) width.setConstant(kTRUE); RooFormulaVar _width("_width","_width","@0+@1*@2+@1*@1*@3",RooArgList(width,de,c1_width,c2_width)); RooNovosibirsk pdf_mbc_sig("pdf_mbc_sig","pdf_mbc_sig",mbc,_mbc0,_width,_alpha); ///////// // pdf // ///////// RooProdPdf pdf_sig("pdf_sig","pdf_sig",pdf_de_sig,Conditional(pdf_mbc_sig,mbc)); ////////////// // Comb PDF // ////////////// //////////// // de pdf // //////////// RooRealVar c10("c10","c10",m_c10_eta10,-10.,10.);c10.setConstant(kTRUE); RooRealVar c11("c11","c11",m_c11_eta10,-10.,10); c11.setConstant(kTRUE); RooRealVar c12("c12","c12",m_c12_eta10,-10.,10); c12.setConstant(kTRUE); RooFormulaVar _c1("_c1","@0+@1*@3+@2*@3*@3",RooArgSet(c10,c11,c12,mbc)); RooRealVar c20("c20","c20",m_c20_eta10,-10.,10.);c20.setConstant(kTRUE); RooRealVar c21("c21","c21",m_c21_eta10,-10.,10); c21.setConstant(kTRUE); RooFormulaVar _c2("_c2","@0+@1*@2",RooArgSet(c20,c21,mbc)); RooRealVar d1("d1","d1",0.,-100000,100000); RooRealVar d2("d2","d2",0.,-100000,100000); RooChebychev pdf_de_comb("pdf_de_comb","pdf_de_comb",de,RooArgSet(d1,d2)); ///////////// // mbc pdf // ///////////// RooRealVar argpar("argpar","argus shape parameter",m_argpar_eta10,-100.,-1.); argpar.setConstant(kTRUE); RooRealVar argedge("argedge","argedge",m_argedge_eta10,5.285,5.292); argedge.setConstant(kTRUE); RooArgusBG pdf_mbc_comb("pdf_mbc_comb","Argus PDF",mbc,argedge,argpar); ////////////// // pdf comb // ////////////// // RooProdPdf pdf_comb("pdf_comb","pdf_comb",pdf_mbc_comb,Conditional(pdf_de_comb,de)); RooProdPdf pdf_comb("pdf_comb","pdf_comb",RooArgSet(pdf_mbc_comb,pdf_de_comb,de)); ///////////////// // BB comb PDF // ///////////////// ///////////// // mbc pdf // ///////////// // RooRealVar edge("edge","edge",5.29,5.28,5.30,"GeV");// edge.setConstant(kTRUE); // RooRealVar mbctau("mbctau","mbctau",-97.,-300,0.,"GeV"); // RooRealVar pow1("pow1","pow1",6.8,0.1,10); // RooRealVar pow2("pow2","pow2",0.12,0.1,10); RooRealVar edge("edge","edge",5.29,5.28,5.30,"GeV"); edge.setConstant(kTRUE); RooRealVar mbctau("mbctau","mbctau",m_mbctau_bbcomb_eta10,-100,0.,"GeV"); mbctau.setConstant(kTRUE); RooRealVar pow1("pow1","pow1",m_pow1_bbcomb_eta10,0.1,10); pow1.setConstant(kTRUE); RooRealVar pow2("pow2","pow2",m_pow2_bbcomb_eta10,0.1,10); pow2.setConstant(kTRUE); RooGenericPdf pdf_mbc_bb_comb("pdf_mbc_bb_comb","pow(@1-@0,@2)*exp(@3*pow(@1-@0,@4))",RooArgList(mbc,edge,pow1,mbctau,pow2)); //////////// // de pdf // //////////// RooRealVar c3("c3","c3",m_c0_bb_eta10,-100000.,10.); c3.setConstant(kTRUE); RooRealVar c31("c31","c31",m_c1_bb_eta10,-10.,10.); c31.setConstant(kTRUE); RooFormulaVar _c3("_c3","@0+@1*@2",RooArgSet(c3,c31,mbc)); RooExponential pdf_de_bb_comb("pdf_de_bb_comb","pdf_de_bb_comb",de,_c3); RooProdPdf pdf_bb_comb("pdf_bb_comb","pdf_bb_comb",pdf_mbc_bb_comb,Conditional(pdf_de_bb_comb,de)); ////////////////// // Complete PDF // ////////////////// const bool OneDfit = false; RooRealVar Nsig("Nsig","Nsig",600,0.,10000.); RooRealVar Ncmb("Ncmb","Ncmb",10000,0,100000); RooRealVar NBBcmb("NBBcmb","NBBcmb",0,0,100000.); RooAddPdf pdf("pdf","pdf",RooArgList(pdf_sig,pdf_comb,pdf_bb_comb),RooArgList(Nsig,Ncmb,NBBcmb)); // RooAddPdf pdf("pdf","pdf",RooArgList(pdf_sig,pdf_bb_comb),RooArgList(Nsig,NBBcmb)); // RooAddPdf pdf("pdf","pdf",RooArgList(pdf_sig,pdf_comb),RooArgList(Nsig,Ncmb)); // RooFormulaVar NCmb("NCmb","@0+@1",RooArgList(NBBcmb,Ncmb)); // RooArgSet* params = pdf.getParameters(RooArgSet(de,mbc)); // RooArgset* initParams = (RooArgSet*) params->snapshot(); if(!OneDfit) pdf.fitTo(ds,Verbose(),Timer(true)); else{ RooAddPdf pdf_de("pdf_de","pdf_de",RooArgList(pdf_de_sig,pdf_de_comb),RooArgList(Nsig,Ncmb)); NBBcmb.setVal(0); NBBcmb.setConstant(kTRUE); pdf_de.fitTo(ds,Verbose(),Timer(true)); } //return; // params->printLatex(OutputFile("PurityEtaGGFit.tex")); RooAbsReal* intSig = pdf_sig.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Signal")); RooAbsReal* intRho = pdf_bb_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Signal")); RooAbsReal* intCmb = pdf_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Signal")); const double nsig = intSig->getVal()*Nsig.getVal(); const double nsig_err = intSig->getVal()*Nsig.getError(); const double nsig_err_npq = TMath::Sqrt(nsig*(Nsig.getVal()-nsig)/Nsig.getVal()); const double nsig_err_total = TMath::Sqrt(nsig_err*nsig_err+nsig_err_npq*nsig_err_npq); const double nrho = intRho->getVal()*NBBcmb.getVal(); const double nrho_err = intRho->getVal()*NBBcmb.getError(); const double nrho_err_npq = TMath::Sqrt(nrho*(NBBcmb.getVal()-nrho)/NBBcmb.getVal()); const double nrho_err_total = TMath::Sqrt(nrho_err*nrho_err+nrho_err_npq*nrho_err_npq); const double ncmb = intCmb->getVal()*Ncmb.getVal(); const double ncmb_err = intCmb->getVal()*Ncmb.getError(); const double ncmb_err_npq = TMath::Sqrt(ncmb*(Ncmb.getVal()-ncmb)/Ncmb.getVal()); const double ncmb_err_total = TMath::Sqrt(ncmb_err*ncmb_err+ncmb_err_npq*ncmb_err_npq); const double purity = nsig/(nsig+nrho+ncmb); const double purity_err = nsig_err_total/(nsig+nrho+ncmb); de.setRange("Ellips",DE_MIN,DE_MAX); RooFormulaVar mbclo("mbclo","(1-(@0-@3)/@4*(@0-@3)/@4) > 0 ? @1-@2*TMath::Sqrt(1-(@0-@3)/@4*(@0-@3)/@4) : 0",RooArgSet(de,mbc_center,mbc_radius,de_center,de_radius)); RooFormulaVar mbchi("mbchi","(1-(@0-@3)/@4*(@0-@3)/@4) > 0 ? @1+@2*TMath::Sqrt(1-(@0-@3)/@4*(@0-@3)/@4) : 0",RooArgSet(de,mbc_center,mbc_radius,de_center,de_radius)); mbc.setRange("Ellips",mbclo,mbchi); de.setRange("Elli",DE_MIN,DE_MAX); RooFormulaVar mbclo1("mbclo1","(1-(@0-@3)/@4*(@0-@3)/@4) > 0 ? @1-@2*TMath::Sqrt(1-(@0-@3)/@4*(@0-@3)/@4) : 0",RooArgSet(de,mbc_center,mbc_radius1,de_center,de_radius1)); RooFormulaVar mbchi1("mbchi1","(1-(@0-@3)/@4*(@0-@3)/@4) > 0 ? @1+@2*TMath::Sqrt(1-(@0-@3)/@4*(@0-@3)/@4) : 0",RooArgSet(de,mbc_center,mbc_radius1,de_center,de_radius1)); mbc.setRange("Elli",mbclo1,mbchi1); RooAbsReal* intSigEl = pdf_sig.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Ellips")); RooAbsReal* intRhoEl = pdf_bb_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Ellips")); RooAbsReal* intCmbEl = pdf_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Ellips")); const double nsigEl = intSigEl->getVal()*Nsig.getVal(); const double nsig_errEl = intSigEl->getVal()*Nsig.getError(); const double nsig_errEl_npq = TMath::Sqrt(nsigEl*(Nsig.getVal()-nsigEl)/Nsig.getVal()); const double nsig_errEl_total = TMath::Sqrt(nsig_errEl*nsig_errEl+nsig_errEl_npq*nsig_errEl_npq); const double nrhoEl = intRhoEl->getVal()*NBBcmb.getVal(); const double nrho_errEl = intRhoEl->getVal()*NBBcmb.getError(); const double nrho_errEl_npq = TMath::Sqrt(nrhoEl*(NBBcmb.getVal()-nrhoEl)/NBBcmb.getVal()); const double nrho_errEl_total = TMath::Sqrt(nrho_errEl*nrho_errEl+nrho_errEl_npq*nrho_errEl_npq); const double ncmbEl = intCmbEl->getVal()*Ncmb.getVal(); const double ncmb_errEl = intCmbEl->getVal()*Ncmb.getError(); const double ncmb_errEl_npq = TMath::Sqrt(ncmbEl*(Ncmb.getVal()-ncmbEl)/Ncmb.getVal()); const double ncmb_errEl_total = TMath::Sqrt(ncmb_errEl*ncmb_errEl+ncmb_errEl_npq*ncmb_errEl_npq); const double purityEl = nsigEl/(nsigEl+nrhoEl+ncmbEl); const double purity_errEl = nsig_errEl_total/(nsigEl+nrhoEl+ncmbEl); RooAbsReal* intSigEl1 = pdf_sig.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Elli")); RooAbsReal* intRhoEl1 = pdf_bb_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Elli")); RooAbsReal* intCmbEl1 = pdf_comb.createIntegral(RooArgSet(de,mbc),NormSet(RooArgSet(de,mbc)),Range("Elli")); const double nsigEl1 = intSigEl1->getVal()*Nsig.getVal(); const double nsig_errEl1 = intSigEl1->getVal()*Nsig.getError(); const double nsig_errEl1_npq = TMath::Sqrt(nsigEl1*(Nsig.getVal()-nsigEl1)/Nsig.getVal()); const double nsig_errEl1_total = TMath::Sqrt(nsig_errEl1*nsig_errEl1+nsig_errEl1_npq*nsig_errEl1_npq); const double nrhoEl1 = intRhoEl1->getVal()*NBBcmb.getVal(); const double nrho_errEl1 = intRhoEl1->getVal()*NBBcmb.getError(); const double nrho_errEl1_npq = TMath::Sqrt(nrhoEl1*(NBBcmb.getVal()-nrhoEl1)/NBBcmb.getVal()); const double nrho_errEl1_total = TMath::Sqrt(nrho_errEl1*nrho_errEl1+nrho_errEl1_npq*nrho_errEl1_npq); const double ncmbEl1 = intCmbEl1->getVal()*Ncmb.getVal(); const double ncmb_errEl1 = intCmbEl1->getVal()*Ncmb.getError(); const double ncmb_errEl1_npq = TMath::Sqrt(ncmbEl1*(Ncmb.getVal()-ncmbEl1)/Ncmb.getVal()); const double ncmb_errEl1_total = TMath::Sqrt(ncmb_errEl1*ncmb_errEl1+ncmb_errEl1_npq*ncmb_errEl1_npq); const double purityEl1 = nsigEl1/(nsigEl1+nrhoEl1+ncmbEl1); const double purity_errEl1 = nsig_errEl1_total/(nsigEl1+nrhoEl1+ncmbEl1); ///////////// // Plots // ///////////// // de // RooPlot* deFrame = de.frame(); ds.plotOn(deFrame,DataError(RooAbsData::SumW2),MarkerSize(1),CutRange("mbcSignal")); pdf.plotOn(deFrame,Components(pdf_sig),LineStyle(kDashed),ProjectionRange("mbcSignal")); // pdf.plotOn(deFrame,Components(pdf_back),LineStyle(kDashed),ProjectionRange("mbcSignal")); pdf.plotOn(deFrame,Components(pdf_bb_comb),LineStyle(kDashed),ProjectionRange("mbcSignal")); pdf.plotOn(deFrame,Components(RooArgSet(pdf_comb)),LineStyle(kDashed),ProjectionRange("mbcSignal")); pdf.plotOn(deFrame,LineWidth(2),ProjectionRange("mbcSignal")); RooHist* hdepull = deFrame->pullHist(); RooPlot* dePull = de.frame(Title("#Delta E pull distribution")); dePull->addPlotable(hdepull,"P"); dePull->GetYaxis()->SetRangeUser(-5,5); TCanvas* cm = new TCanvas("#Delta E","#Delta E",600,700); cm->cd(); TPad *pad3 = new TPad("pad3","pad3",0.01,0.20,0.99,0.99); TPad *pad4 = new TPad("pad4","pad4",0.01,0.01,0.99,0.20); pad3->Draw(); pad4->Draw(); pad3->cd(); pad3->SetLeftMargin(0.15); pad3->SetFillColor(0); deFrame->GetXaxis()->SetTitleSize(0.05); deFrame->GetXaxis()->SetTitleOffset(0.85); deFrame->GetXaxis()->SetLabelSize(0.04); deFrame->GetYaxis()->SetTitleOffset(1.6); deFrame->Draw(); stringstream out1; TPaveText *pt = new TPaveText(0.6,0.75,0.98,0.9,"brNDC"); pt->SetFillColor(0); pt->SetTextAlign(12); out1.str(""); out1 << "#chi^{2}/n.d.f = " << deFrame->chiSquare(); pt->AddText(out1.str().c_str()); out1.str(""); if(!data) out1 << "S: " << (int)(nsig+0.5) << " #pm " << (int)(nsig_err_total+0.5); else out1 << "S: " << (int)(nsigEl+0.5) << " #pm " << (int)(nsig_errEl_total+0.5); pt->AddText(out1.str().c_str()); out1.str(""); if(!data) out1 << "Purity: " << std::fixed << std::setprecision(2) << purity*100. << " #pm " << purity_err*100; else out1 << "Purity: " << std::fixed << std::setprecision(2) << purityEl*100. << " #pm " << purity_errEl*100; pt->AddText(out1.str().c_str()); pt->Draw(); TLine *de_line_RIGHT; if(!data) de_line_RIGHT = new TLine(DE_MAX,0,DE_MAX,120); else de_line_RIGHT = new TLine(DE_MAX,0,DE_MAX,30); de_line_RIGHT->SetLineColor(kRed); de_line_RIGHT->SetLineStyle(1); de_line_RIGHT->SetLineWidth((Width_t)2.); de_line_RIGHT->Draw(); TLine *de_line_LEFT; if(!data) de_line_LEFT = new TLine(DE_MIN,0,DE_MIN,120); else de_line_LEFT = new TLine(DE_MIN,0,DE_MIN,30); de_line_LEFT->SetLineColor(kRed); de_line_LEFT->SetLineStyle(1); de_line_LEFT->SetLineWidth((Width_t)2.); de_line_LEFT->Draw(); pad4->cd(); pad4->SetLeftMargin(0.15); pad4->SetFillColor(0); dePull->SetMarkerSize(0.05); dePull->Draw(); TLine *de_lineUP = new TLine(deMin,3,deMax,3); de_lineUP->SetLineColor(kBlue); de_lineUP->SetLineStyle(2); de_lineUP->Draw(); TLine *de_line = new TLine(deMin,0,deMax,0); de_line->SetLineColor(kBlue); de_line->SetLineStyle(1); de_line->SetLineWidth((Width_t)2.); de_line->Draw(); TLine *de_lineDOWN = new TLine(deMin,-3,deMax,-3); de_lineDOWN->SetLineColor(kBlue); de_lineDOWN->SetLineStyle(2); de_lineDOWN->Draw(); cm->Update(); // mbc // RooPlot* mbcFrame = mbc.frame(); ds.plotOn(mbcFrame,DataError(RooAbsData::SumW2),MarkerSize(1),CutRange("deSignal")); // pdf.plotOn(mbcFrame,Components(pdf_back),LineStyle(kDashed),ProjectionRange("deSignal")); pdf.plotOn(mbcFrame,Components(pdf_comb),LineStyle(kDashed),ProjectionRange("deSignal")); pdf.plotOn(mbcFrame,Components(pdf_bb_comb),LineStyle(kDashed),ProjectionRange("deSignal")); pdf.plotOn(mbcFrame,Components(pdf_sig),LineStyle(kDashed),ProjectionRange("deSignal")); pdf.plotOn(mbcFrame,LineWidth(2),ProjectionRange("deSignal")); RooHist* hmbcpull = mbcFrame->pullHist(); RooPlot* mbcPull = mbc.frame(Title("#Delta E pull distribution")); mbcPull->addPlotable(hmbcpull,"P"); mbcPull->GetYaxis()->SetRangeUser(-5,5); TCanvas* cmmbc = new TCanvas("M_{bc}","M_{bc}",600,700); cmmbc->cd(); TPad *pad1 = new TPad("pad1","pad1",0.01,0.20,0.99,0.99); TPad *pad2 = new TPad("pad2","pad2",0.01,0.01,0.99,0.20); pad1->Draw(); pad2->Draw(); pad1->cd(); pad1->SetLeftMargin(0.15); pad1->SetFillColor(0); mbcFrame->GetXaxis()->SetTitleSize(0.05); mbcFrame->GetXaxis()->SetTitleOffset(0.85); mbcFrame->GetXaxis()->SetLabelSize(0.04); mbcFrame->GetYaxis()->SetTitleOffset(1.6); mbcFrame->Draw(); TPaveText *ptmbc = new TPaveText(0.2,0.75,0.58,0.9,"brNDC"); ptmbc->SetFillColor(0); ptmbc->SetTextAlign(12); out1.str(""); out1 << "#chi^{2}/n.d.f = " << mbcFrame->chiSquare(); ptmbc->AddText(out1.str().c_str()); out1.str(""); if(!data) out1 << "S: " << (int)(nsig+0.5) << " #pm " << (int)(nsig_err_total+0.5); else out1 << "S: " << (int)(nsigEl+0.5) << " #pm " << (int)(nsig_errEl_total+0.5); ptmbc->AddText(out1.str().c_str()); out1.str(""); if(!data) out1 << "Purity: " << std::fixed << std::setprecision(2) << purity*100. << " #pm " << purity_err*100; else out1 << "Purity: " << std::fixed << std::setprecision(2) << purityEl*100. << " #pm " << purity_errEl*100; ptmbc->AddText(out1.str().c_str()); ptmbc->Draw(); TLine *mbc_line_RIGHT; if(!data) mbc_line_RIGHT = new TLine(mbc_max,0,mbc_max,70); else mbc_line_RIGHT = new TLine(mbc_max,0,mbc_max,40); mbc_line_RIGHT->SetLineColor(kRed); mbc_line_RIGHT->SetLineStyle(1); mbc_line_RIGHT->SetLineWidth((Width_t)2.); mbc_line_RIGHT->Draw(); TLine *mbc_line_LEFT; if(!data) mbc_line_LEFT = new TLine(mbc_min,0,mbc_min,70); else mbc_line_LEFT = new TLine(mbc_min,0,mbc_min,40); mbc_line_LEFT->SetLineColor(kRed); mbc_line_LEFT->SetLineStyle(1); mbc_line_LEFT->SetLineWidth((Width_t)2.); mbc_line_LEFT->Draw(); pad2->cd(); pad2->SetLeftMargin(0.15); pad2->SetFillColor(0); mbcPull->SetMarkerSize(0.05); mbcPull->Draw(); TLine *mbc_lineUP = new TLine(mbcMin,3,mbcMax,3); mbc_lineUP->SetLineColor(kBlue); mbc_lineUP->SetLineStyle(2); mbc_lineUP->Draw(); TLine *mbc_line = new TLine(mbcMin,0,mbcMax,0); mbc_line->SetLineColor(kBlue); mbc_line->SetLineStyle(1); mbc_line->SetLineWidth((Width_t)2.); mbc_line->Draw(); TLine *mbc_lineDOWN = new TLine(mbcMin,-3,mbcMax,-3); mbc_lineDOWN->SetLineColor(kBlue); mbc_lineDOWN->SetLineStyle(2); mbc_lineDOWN->Draw(); cmmbc->Update(); double DEMIN = -0.15; // if(keysflag) DEMIN = -0.3; TH2D* hh_pdf = pdf.createHistogram("hh_data",de,Binning(50,DEMIN,0.1),YVar(mbc,Binning(50,5.26,5.30))); hh_pdf->SetLineColor(kBlue); TCanvas* hhc = new TCanvas("hhc","hhc",600,600); hhc->cd(); hh_pdf->Draw("SURF"); // Show signal ranges TEllipse* elli = new TEllipse(de_center.getVal(),mbc_center.getVal(),de_radius.getVal(),mbc_radius.getVal()); elli->SetFillColor(0); elli->SetFillStyle(0); elli->SetLineColor(kBlue); elli->SetLineWidth(2); TEllipse* elli1 = new TEllipse(de_center.getVal(),mbc_center.getVal(),de_radius1.getVal(),mbc_radius1.getVal()); elli1->SetFillColor(0); elli1->SetFillStyle(0); elli1->SetLineColor(kBlue); elli1->SetLineWidth(2); TLine* l1 = new TLine(DE_MIN,mbc_min,DE_MAX,mbc_min); l1->SetLineColor(kRed); l1->SetLineStyle(1); l1->SetLineWidth(2); TLine* l2 = new TLine(DE_MIN,mbc_max,DE_MAX,mbc_max); l2->SetLineColor(kRed); l2->SetLineStyle(1); l2->SetLineWidth(2); TLine* l3 = new TLine(DE_MIN,mbc_min,DE_MIN,mbc_max); l3->SetLineColor(kRed); l3->SetLineStyle(1); l3->SetLineWidth(2); TLine* l4 = new TLine(DE_MAX,mbc_min,DE_MAX,mbc_max); l4->SetLineColor(kRed); l4->SetLineStyle(1); l4->SetLineWidth(2); TCanvas* ellican = new TCanvas("ellican","ellican",400,400); ellican->cd(); out.str(""); out << "bdtg>" << BDTG_MIN << " && bdtg<" << BDTG_MAX << " && de>-0.15 && de<0.20 && mbc>5.265"; tree->Draw("mbc:de",out.str().c_str()); elli->Draw(); elli1->Draw(); l1->Draw(); l2->Draw(); l3->Draw(); l4->Draw(); if(!data){ TCanvas* sigcan = new TCanvas("sigcan","sigcan",400,400); sigcan->cd(); out.str(""); out << "bdtg>" << BDTG_MIN << " && bdtg<" << BDTG_MAX << " && de>-0.15 && de<0.20 && mbc>5.265 && (b0f == 1 || b0f == 5 || b0f == 10)"; tree->Draw("mbc:de",out.str().c_str()); elli->Draw(); elli1->Draw(); l1->Draw(); l2->Draw(); l3->Draw(); l4->Draw(); TCanvas* backcan = new TCanvas("backcan","backcan",400,400); backcan->cd(); out.str(""); out << "bdtg>" << BDTG_MIN << " && bdtg<" << BDTG_MAX << " && de>-0.15 && de<0.20 && mbc>5.265 && !(b0f == 1 || b0f == 5 || b0f == 10 || b0f == 0)"; tree->Draw("mbc:de",out.str().c_str()); elli->Draw(); elli1->Draw(); l1->Draw(); l2->Draw(); l3->Draw(); l4->Draw(); cout << "Rectangle:" << endl; out.str(""); out << "de<" << DE_MAX << " && de>" << DE_MIN; out << " && mbc>" << mbc_min << " && mbc<" << mbc_max; Roo1DTable* recttable = ds.table(b0f,out.str().c_str()); recttable->Print(); recttable->Print("v"); cout << "Ellips:" << endl; out.str(""); out << "(de-" << de_center.getVal() << ")/" << de_radius.getVal() << "*(de-" << de_center.getVal() << ")/" << de_radius.getVal() << "+(mbc-"<<mbc_center.getVal()<<")/" << mbc_radius.getVal() << "*(mbc-" << mbc_center.getVal() << ")/" << mbc_radius.getVal() << "<1"; cout << out.str() << endl; Roo1DTable* ellitable = ds.table(b0f,out.str().c_str()); ellitable->Print(); ellitable->Print("v"); cout << "Elli:" << endl; out.str(""); out << "(de-" << de_center.getVal() << ")/" << de_radius1.getVal() << "*(de-" << de_center.getVal() << ")/" << de_radius1.getVal() << "+(mbc-"<<mbc_center.getVal()<<")/" << mbc_radius1.getVal() << "*(mbc-" << mbc_center.getVal() << ")/" << mbc_radius1.getVal() << "<1"; cout << out.str() << endl; Roo1DTable* ellitable1 = ds.table(b0f,out.str().c_str()); ellitable1->Print(); ellitable1->Print("v"); Roo1DTable* fulltable = ds.table(b0f); fulltable->Print(); fulltable->Print("v"); } cout << "Rectangle:" << endl; cout << "Nsig = " << nsig <<" +- " << nsig_err << " +- " << nsig_err_npq << " (" << nsig_err_total << ")" << endl; cout << "NBBcomb = " << nrho <<" +- " << nrho_err << " +- " << nrho_err_npq << " (" << nrho_err_total << ")" << endl; cout << "Ncmb = " << ncmb <<" +- " << ncmb_err << " +- " << ncmb_err_npq << " (" << ncmb_err_total << ")" << endl; cout << "Pury = " << purity << " +- " << purity_err << endl; cout << "Ellips:" << endl; cout << "Nsig = " << nsigEl <<" +- " << nsig_errEl << " +- " << nsig_errEl_npq << " (" << nsig_errEl_total << ")" << endl; cout << "NBBcomb = " << nrhoEl <<" +- " << nrho_errEl << " +- " << nrho_errEl_npq << " (" << nrho_errEl_total << ")" << endl; cout << "Ncmb = " << ncmbEl <<" +- " << ncmb_errEl << " +- " << ncmb_errEl_npq << " (" << ncmb_errEl_total << ")" << endl; cout << "Pury = " << purityEl << " +- " << purity_errEl << endl; cout << "Elli:" << endl; cout << "Nsig = " << nsigEl1 <<" +- " << nsig_errEl1 << " +- " << nsig_errEl1_npq << " (" << nsig_errEl1_total << ")" << endl; cout << "NBBcomb = " << nrhoEl1 <<" +- " << nrho_errEl1 << " +- " << nrho_errEl1_npq << " (" << nrho_errEl1_total << ")" << endl; cout << "Ncmb = " << ncmbEl1 <<" +- " << ncmb_errEl1 << " +- " << ncmb_errEl1_npq << " (" << ncmb_errEl1_total << ")" << endl; cout << "Pury = " << purityEl1 << " +- " << purity_errEl1 << endl; // de full // RooPlot* deFrameF = de.frame(); ds.plotOn(deFrameF,DataError(RooAbsData::SumW2),MarkerSize(1),MarkerColor(kGreen)); pdf.plotOn(deFrameF,Components(pdf_sig),LineStyle(kDashed)); pdf.plotOn(deFrameF,Components(RooArgSet(pdf_comb,pdf_bb_comb)),LineStyle(kDashed)); pdf.plotOn(deFrameF,LineWidth(2)); RooHist* hdepullF = deFrameF->pullHist(); RooPlot* dePullF = de.frame(Title("#Delta E pull")); dePullF->addPlotable(hdepullF,"P"); dePullF->GetYaxis()->SetRangeUser(-5,5); TCanvas* cmf = new TCanvas("#Delta E full","#Delta E full",600,700); cmf->cd(); TPad *pad5 = new TPad("pad5","pad5",0.01,0.20,0.99,0.99); TPad *pad6 = new TPad("pad6","pad6",0.01,0.01,0.99,0.20); pad5->Draw(); pad6->Draw(); pad5->cd(); pad5->SetLeftMargin(0.15); pad5->SetFillColor(0); deFrameF->GetXaxis()->SetTitleSize(0.05); deFrameF->GetXaxis()->SetTitleOffset(0.85); deFrameF->GetXaxis()->SetLabelSize(0.04); deFrameF->GetYaxis()->SetTitleOffset(1.6); deFrameF->Draw(); TPaveText *ptf = new TPaveText(0.6,0.75,0.98,0.9,"brNDC"); ptf->SetFillColor(0); ptf->SetTextAlign(12); out1.str(""); out1 << "#chi^{2}/n.d.f = " << deFrameF->chiSquare(); ptf->AddText(out1.str().c_str()); // out1.str(""); // if(!data) out1 << "S: " << (int)(nsig+0.5) << " #pm " << (int)(nsig_err_total+0.5); // else out1 << "S: " << (int)(nsigEl+0.5) << " #pm " << (int)(nsig_errEl_total+0.5); // ptf->AddText(out1.str().c_str()); // out1.str(""); // if(!data) out1 << "Purity: " << std::fixed << std::setprecision(2) << purity*100. << " #pm " << purity_err*100; // else out1 << "Purity: " << std::fixed << std::setprecision(2) << purityEl*100. << " #pm " << purity_errEl*100; // ptf->AddText(out1.str().c_str()); ptf->Draw(); // TLine *de_line_RIGHT; // if(!data) de_line_RIGHT = new TLine(DE_MAX,0,DE_MAX,120); // else de_line_RIGHT = new TLine(DE_MAX,0,DE_MAX,30); // de_line_RIGHT->SetLineColor(kRed); // de_line_RIGHT->SetLineStyle(1); // de_line_RIGHT->SetLineWidth((Width_t)2.); // de_line_RIGHT->Draw(); TLine *de_line_LEFT; // if(!data) de_line_LEFT = new TLine(DE_MIN,0,DE_MIN,120); // else de_line_LEFT = new TLine(DE_MIN,0,DE_MIN,30); // de_line_LEFT->SetLineColor(kRed); // de_line_LEFT->SetLineStyle(1); // de_line_LEFT->SetLineWidth((Width_t)2.); de_line_LEFT->Draw(); pad6->cd(); pad6->SetLeftMargin(0.15); pad6->SetFillColor(0); dePullF->SetMarkerSize(0.05); dePullF->Draw(); // TLine *de_lineUP = new TLine(deMin,3,deMax,3); // de_lineUP->SetLineColor(kBlue); // de_lineUP->SetLineStyle(2); de_lineUP->Draw(); // TLine *de_line = new TLine(deMin,0,deMax,0); // de_line->SetLineColor(kBlue); // de_line->SetLineStyle(1); // de_line->SetLineWidth((Width_t)2.); de_line->Draw(); // TLine *de_lineDOWN = new TLine(deMin,-3,deMax,-3); // de_lineDOWN->SetLineColor(kBlue); // de_lineDOWN->SetLineStyle(2); de_lineDOWN->Draw(); cmf->Update(); }
void dumpStg6Results(string inFile,string outFile, int nEvents = 0,bool useRBM = 1,double theta2Cut = 0.03, bool NoFromStg5 = true,string Stg5Path = "/data/veritas/bzitzer/bootes_1/data/root/") { gROOT->SetBatch(true); TH1D* hSigRF = new TH1D("SigDistRF","Significance Distrbution RF",50,-5,5); TH1D* hSigCBG = new TH1D("SigDistCBG","Significance Distrbution CBG",50,-5,5); // Opening files and getting VEGAS objects: TFile* f = new TFile(inFile.c_str(),"READ"); if(!f->IsOpen() ) { cerr << "Problem opening ROOT file!" << endl; return; } TTree* EventTree = (TTree*)gDirectory->Get("EventStatsTree"); if( EventTree == NULL ) { cout << "No Event Tree!" << endl; return; } TTree* RunTree = (TTree*)gDirectory->Get("RunStatsTree"); if( RunTree == NULL ) { cout << "No Run Tree!" << endl; return; } VASkyMap* vaMapOn = (VASkyMap*)gDirectory->Get("RingBackgroundModelAnalysis/SkyMapOn"); VASkyMap* vaMapAlpha = (VASkyMap*)gDirectory->Get("RingBackgroundModelAnalysis/fAlphaMap"); VACoordinatePair onCenter = vaMapOn->GetCenter(); VACoordinatePair eventCoord; VACoordinatePair trackCoord; VACoordinatePair fRootCoord; VACoordinatePair sourceCoord; // -------------------- // Exclusion regions: // -------------------- TDirectory* RBMExclusion = (TDirectory*)gDirectory->Get("RingBackgroundModelAnalysis/ExclusionRegions"); if( RBMExclusion == NULL ) { cerr << "Problem loading the RBM exclusion directory!" << endl; return; } int nRegions = RBMExclusion->GetNkeys(); VASkyMapExclusionRegion* hSourceExclusion; const int tmp = nRegions; VASkyMapExclusionRegion* exclList[tmp]; vector<VASkyMapExclusionRegion*> vaSourceExcl; TIter next(RBMExclusion->GetListOfKeys()); TKey *key; int i=0; while(key=(TKey*)next()) { hSourceExclusion = (VASkyMapExclusionRegion*)RBMExclusion->FindObjectAny(key->GetName())->Clone(); if( hSourceExclusion != NULL) { if( hSourceExclusion->wasUsed() ) { cout << i << endl; exclList[i] = hSourceExclusion; vaSourceExcl.push_back(hSourceExclusion); cout << hSourceExclusion->GetName() << endl; //cout << "Exclusion Center RA: " << hSourceExclusion->center().getRA_J2000_Deg() << endl; cout << "Exclusion Center RA: " << exclList[i]->center().getRA_J2000_Deg() << endl; cout << "Exclusion Center Dec: " << hSourceExclusion->center().getDec_J2000_Deg() << endl; cout << "Exclusion Radius: " << hSourceExclusion->radius_Deg() << endl; i++; } } } nRegions = i; dumpExcl(exclList,nRegions,outFile); double TelLatRad = 5.52828386357865242e-01; double TelLongRad = -1.93649167430676461e+00; Float_t EffArea,EnergyGeV,El,Az; double RA,Dec; double RATrack,DecTrack; double DayNS; UInt_t MJD; UInt_t RunID; Float_t El_track,Az_track; Float_t El_check,Az_check; double MJDDbl; Double_t W; Double_t liveTime; Double_t PsiEventTree; int NumRuns = RunTree->GetEntries(); Bool_t IsOn,IsOff; double Noise; Float_t RA_fRoot,Dec_fRoot; EventTree->SetBranchAddress("RunNum",&RunID); EventTree->SetBranchAddress("Azimuth",&Az); EventTree->SetBranchAddress("Elevation",&El); EventTree->SetBranchAddress("Noise",&Noise); EventTree->SetBranchAddress("EnergyGeV",&EnergyGeV); EventTree->SetBranchAddress("TrackingAzimuth",&Az_track); EventTree->SetBranchAddress("TrackingElevation",&El_track); EventTree->SetBranchAddress("OnEvent",&IsOn); EventTree->SetBranchAddress("OffEvent",&IsOff); EventTree->SetBranchAddress("Weight",&W); EventTree->SetBranchAddress("Psi",&PsiEventTree); // EventTree->SetBranchAddress("RA",&RA_fRoot); // EventTree->SetBranchAddress("Dec",&Dec_fRoot); EventTree->SetBranchAddress("MJDDbl",&MJDDbl); EventTree->SetBranchAddress("DayNSDbl",&DayNS); EventTree->SetBranchAddress("EffectiveArea",&EffArea); double RASource,DecSource,RAOffset,DecOffset; double RAError,DecError; double fSigRF,fSigCBG; int RunNumRunTree; RunTree->SetBranchAddress("faLiveTime",&liveTime); RunTree->SetBranchAddress("fSourceDecDeg",&DecSource); RunTree->SetBranchAddress("fSourceRADeg",&RASource); RunTree->SetBranchAddress("fOffsetDecDeg",&DecOffset); RunTree->SetBranchAddress("fOffsetRADeg",&RAOffset); RunTree->SetBranchAddress("fSignificance",&fSigRF); RunTree->SetBranchAddress("faRunNumber",&RunNumRunTree); // Signficance distributions: VAAzElRADecXY coord(TelLongRad,TelLatRad); VATime time; TGraph* map = new TGraph(); TGraph* trackError = new TGraph(); TH2D* map2 = new TH2D("skymap","raw counts map",100,65,115,100,10,30); double X,Y; double XRot,YRot; double theta; double RunIDOld = 0; int j = 0; int k = 0; filebuf fb; fb.open(outFile.c_str(),ios::out); ostream os(&fb); TGraph* geffAreaVTime = new TGraph(); if( nEvents == 0 ){ nEvents = EventTree->GetEntries(); } int NumOnEvents = 0; int NumOffEvents = 0; // Stuff to make RBM work; double upperRadRBM = 0.8; double lowerRadRBM = 0.6; double angularSep,psi; bool IsInExcl; // Stuff to make zCresent work: double areaBgRegion = DBL_EPSILON; double upperRadCres = 0.4; double lowerRadCres = 0.6; double areaOnRegion = TMath::TwoPi()*(1.0 - TMath::Cos(TMath::Sqrt(theta2Cut)*TMath::DegToRad())); // rad^2 areaOnRegion *= pow(TMath::RadToDeg(),2.0); // deg^2 //double areaOnRegion = TMath::Pi()*theta2Cut; double wobOffset; // vaStage6 Generalized LiMa calc stuff: vector<double> Non; vector<double> Noff; vector<double> Alpha; vector<double> ExpOn; vector<double> ExpOff; vector<int> RunIDVec; vector<double> SigmaVec; int NumRuns = 0; // header os << "RunID LiveTime(min) Time(MJD) RA Dec RA_track Dec_track Energy(GeV) IsOn Weight Elevation Azimuth Noise Offset" << endl; os << "----------------------------------------------------------------------------------------------------------" << endl; cout.precision(12); os.precision(7); double AvgNoiseFromStg5; for(int i=0; i<nEvents; i++) { EventTree->GetEntry(i); if(i%1000==0) cout << "On Event: " << i << " of " << nEvents <<endl; if(RunID != RunIDOld) { // A new run has started: if(RunIDOld != 0) { Non.push_back(NumOnEvents); Noff.push_back(NumOffEvents); ExpOn.push_back(liveTime/60); ExpOff.push_back(liveTime/60); Alpha.push_back(areaOnRegion/areaBgRegion); cout << RunIDOld << " Non: " << NumOnEvents << " Noff: " << NumOffEvents << " Alpha: " << areaOnRegion/areaBgRegion << " Exp: " << liveTime/60 << endl; fSigCBG = lima(NumOnEvents,NumOffEvents,areaOnRegion/areaBgRegion); SigmaVec.push_back(fSigCBG); RunIDVec.push_back(RunIDOld); hSigCBG->Fill(fSigCBG); NumOnEvents = 0; NumOffEvents = 0; } RunTree->GetEntry(j); if(RunID != RunNumRunTree) { cout << "Run mis-match! " << endl; cout << " Event Tree thinks it is run number: " << RunID << endl; cout << " Run Tree thinks it is run number: " << RunNumRunTree << endl; } j++; hSigRF->Fill(fSigRF); cout << fSigRF << endl; // RASource, RAOffset in Deg if(NoFromStg5 == true) AvgNoiseFromStg5 = getAvgPedVar(RunID,Stg5Path); // I confess to a bit of a Kludge here: coord.setRASource2000((RASource + RAOffset)*TMath::DegToRad()); coord.setDecSource2000((DecSource + DecOffset)*TMath::DegToRad()); sourceCoord.setCoordinates_Deg(RASource,DecSource,2); cout << RunID << " " << liveTime << " " << RASource << " " << DecSource << " " << RAOffset << " " << DecOffset << endl; } time.setFromMJDDbl(MJDDbl); // -------------------- // Coordinate transforms: // -------------------- // Az,El already in radians coord.AzEl2RADec2000(Az,El,time,RA,Dec); // RA,Dec in radians // Az_track, El_track in degrees coord.AzEl2RADec2000(Az_track*TMath::DegToRad(),El_track*TMath::DegToRad(),time,RATrack,DecTrack); // RATrack,DecTrack in radians coord.AzElToXY(Az,El,time,RASource*TMath::DegToRad(),DecSource*TMath::DegToRad(),X,Y); coord.AzElToXY(Az,El,time,X,Y); // coord.XY2RADec2000(X,Y,time,RA,Dec); coord.Derotate(time,X,Y,RATrack*TMath::DegToRad(),DecTrack*TMath::DegToRad(),XRot,YRot); // Flip axis: //XRot = -1.0*XRot; // RA Dec in Degrees now RA *= TMath::RadToDeg(); Dec *= TMath::RadToDeg(); RATrack *= TMath::RadToDeg(); DecTrack *= TMath::RadToDeg(); // RA_fRoot *= TMath::RadToDeg(); // Dec_fRoot *= TMath::RadToDeg(); // RA = XRot + RATrack - RAOffset; //Dec = YRot + DecTrack - DecOffset; // RAError = RA - RA_fRoot; // DecError = Dec - Dec_fRoot; RAError = RASource - (RATrack - RAOffset); DecError = DecSource - (DecTrack - DecOffset); // error corrections: // RA += RAError; // Dec += DecError; RAError *= 3600; //arc sec DecError *= 3600; // arc sec coord.RADec2000ToAzEl(RATrack*TMath::DegToRad(),DecTrack*TMath::DegToRad(),time,Az_check,El_check); // checks in Deg Az_check*=TMath::RadToDeg(); El_check*=TMath::RadToDeg(); eventCoord.setCoordinates_Deg(RA,Dec,2); //trackCoord.setCoordinates_Deg(RATrack,DecTrack,2); trackCoord.setCoordinates_Deg(RASource+RAOffset,DecSource+DecOffset,2); fRootCoord.setCoordinates_Deg(RA_fRoot,Dec_fRoot,2); angularSep = onCenter.angularSeparation_Deg(eventCoord); //psi = trackCoord.angularSeparation_Deg(eventCoord); theta = sourceCoord.angularSeparation_Deg(eventCoord); psi = PsiEventTree; // cout << "dPsi: " << psi - PsiEventTree << endl; //------------------------- // Stuff for RBM analysis: //------------------------- if(useRBM) { IsOff = 0; IsInExcl = 0; if(RunID != RunIDOld) { //wobOffset = sqrt(pow(DecOffset,2.0)+pow(RAOffset,2.0)); wobOffset = sourceCoord.angularSeparation_Deg(trackCoord); upperRadCres = wobOffset + sqrt(theta2Cut); lowerRadCres = wobOffset - sqrt(theta2Cut); // Segue North Kludge/Hack: /* if(TMath::Abs(trackCoord.getRA_J2000_Deg()-151.767) < 0.1 && TMath::Abs(trackCoord.getDec_J2000_Deg()-16.582) < 0.1) { cout << "Warning! I think this is a Segue North Run!" << endl; upperRadCres = 0.5; } */ VASkyMap* vaMapCustom = new VASkyMap("h","h1",sourceCoord,6.0,0.01); //VASkyMap* vaMapCustom = new VASkyMap("h","h1",trackCoord,6.0,0.01); vaMapCustom->MakeBinAreaMap(); areaBgRegion = IntegrateBgArea(vaMapCustom,exclList,trackCoord,lowerRadCres,upperRadCres,nRegions); vaMapCustom->Delete(); cout << "Alpha for Run# " << RunID << " is: " << areaOnRegion/areaBgRegion << endl; } //if( lowerRadRBM < angularSep && angularSep < upperRadRBM ) if( lowerRadCres < psi && psi < upperRadCres ) { for(int m=0; m<nRegions; m++) { if( exclList[m]->isWithinRegion(eventCoord) ) IsInExcl = 1; } if(!IsInExcl) { IsOff = 1; W = areaOnRegion/areaBgRegion; } } } // IsOn = reDefOnFlag(sourceCoord,eventCoord,theta2Cut); if(IsOff || IsOn) { map->SetPoint(k,RA,Dec); trackError->SetPoint(k,RAError,DecError); if(TMath::Abs(RAError) > 40.0 || TMath::Abs(DecError) > 40.0) cout << "Warning! Tracking Error large for for: " << RunID << " RA Error: " << RAError << " Dec Error: " << DecError << endl; k++; if(IsOn) { // if( sqrt((RA - RASource)**2.0 + (Dec - DecSource)**2.0) > sqrt(theta2Cut)) if( theta > sqrt(theta2Cut) ) { cout << "Theta: " << theta << endl; } NumOnEvents++; } if(IsOff){ NumOffEvents++; } // putting needed output into ASCII file os << RunID << " "; os << liveTime << " "; os.precision(12); os << MJDDbl << " "; os.precision(9); os << RA << " "; os << Dec << " "; os << RATrack << " "; os << DecTrack << " "; os.precision(7); os << EnergyGeV << " "; os << IsOn << " "; os << W << " "; os << El_track << " "; os << Az_track << " "; if(!NoFromStg5) os << Noise << " "; else os << AvgNoiseFromStg5 << " "; os << psi << " "; os << endl; } RunIDOld = RunID; } Non.push_back(NumOnEvents); Noff.push_back(NumOffEvents); ExpOn.push_back(liveTime/60); ExpOff.push_back(liveTime/60); Alpha.push_back(areaOnRegion/areaBgRegion); fSigCBG = lima(NumOnEvents,NumOffEvents,areaOnRegion/areaBgRegion); SigmaVec.push_back(fSigCBG); RunIDVec.push_back(RunIDOld); cout << RunIDOld << " Non: " << NumOnEvents << " Noff: " << NumOffEvents << " Alpha: " << areaOnRegion/areaBgRegion << " Exp: " << liveTime/60 << endl; VAStatisticsUtilitiesAnl* StatAnl = new VAStatisticsUtilitiesAnl(Non,Noff,ExpOn,ExpOff,Alpha); cout.precision(7); cout << "Number of ON events: " << sumVector(Non) << endl; cout << "Number of OFF events: " << sumVector(Noff) << endl; cout << "Mean Alpha: " << sumVector(Alpha)/Alpha.size() << endl; cout << "Total Exp Time: " << sumVector(ExpOn) << endl; cout << "Excess : " << StatAnl->ExcessRate() << " +/- " << StatAnl->ExcessRateError() << endl; cout << "Generalized LiMa Significance: " << StatAnl->GeneralisedLiMa() << endl; fb.close(); fb.open("Results.txt",ios::out); ostream os(&fb); for(int i=0; i<Non.size(); i++) { os << "Results for run# " << RunIDVec.at(i) << endl; os << " Number of ON events: " << Non.at(i) << endl; os << " Number of OFF events: " << Noff.at(i) << endl; os << " Alpha: " << Alpha.at(i) << endl; os << " Exp Time: " << ExpOn.at(i) << endl; os << " Significance: " << SigmaVec.at(i) << endl; os << " " << endl; } os << "---------------------------" << endl; os << "Final Results for all runs:" << endl; os << " Number of ON events: " << sumVector(Non) << endl; os << " Number of OFF events: " << sumVector(Noff) << endl; os << " Mean Alpha: " << calcWeightAvgVector(Alpha,ExpOn) << endl; os << " Total Exp Time: " << sumVector(ExpOn) << endl; os << " Excess : " << StatAnl->ExcessRate() << " +/- " << StatAnl->ExcessRateError() << endl; os << " Generalized LiMa Significance: " << StatAnl->GeneralisedLiMa() << endl; fb.close(); TCanvas* c1 = new TCanvas(); map->Draw("A*"); TEllipse* drawBg[tmp]; for(int k=0; k<nRegions; k++) { drawBg[k] = new TEllipse(exclList[k]->center().getRA_J2000_Deg(),exclList[k]->center().getDec_J2000_Deg(), exclList[k]->radius_Deg(),exclList[k]->radius_Deg()); drawBg[k]->SetLineColor(kBlue); drawBg[k]->SetFillColor(0); drawBg[k]->SetFillStyle(0); drawBg[k]->Draw("same"); } // ON region: TEllipse* drawONregion = new TEllipse(RASource,DecSource,sqrt(theta2Cut),sqrt(theta2Cut)); drawONregion->SetLineColor(kRed); drawONregion->SetFillColor(0); drawONregion->SetFillStyle(0); drawONregion->Draw("same"); TCanvas* c2 = new TCanvas(); trackError->GetXaxis()->SetTitle("#delta RA (asec)"); trackError->GetYaxis()->SetTitle("#delta Dec (asec)"); trackError->Draw("A*"); fSigCBG = lima(NumOnEvents,NumOffEvents,areaOnRegion/areaBgRegion); hSigCBG->Fill(fSigCBG); TCanvas* c3 = new TCanvas(); TH1F* hSigRBM = (TH1F*)gDirectory->Get("RingBackgroundModelAnalysis/SigDistributionMinusAllExcl"); TLegend* l = new TLegend(0.7,0.7,0.9,0.9); //hSigRBM->SetDirectory(0); hSigRF->SetDirectory(0); hSigCBG->SetDirectory(0); hSigRF->Scale(1.0/hSigRF->GetEntries()); //hSigRBM->Scale(1.0/hSigRBM->GetEntries()); hSigCBG->Scale(1.0/hSigCBG->GetEntries()); hSigCBG->Draw(); hSigCBG->SetLineColor(kBlue); hSigRF->Draw("same"); hSigRF->SetLineColor(kBlack); //hSigRBM->SetLineColor(kRed); //hSigRBM->Draw("same"); //l->AddEntry(hSigRBM,"Ring Background Model"); l->AddEntry(hSigRF,"Reflected Ring Model"); l->AddEntry(hSigCBG,"Cresent Background Model"); l->Draw("same"); hSigRF->Fit("gaus","LLN"); hSigCBG->Fit("gaus","LLN"); //hSigRBM->Fit("gaus","LLN"); /* TF1* hFitRF = hSigRF->GetFunction("gaus"); TF1* hFitCBG = hSigRF->GetFunction("gaus"); TF1* hFitRBM = hSigRF->GetFunction("gaus"); hFitRF->Draw("same"); hFitRF->SetLineColor(kBlue); hFitCBG->Draw("same"); hFitRBM->Draw("same"); hFitRBM->SetLineColor(kRed); */ cout << "Number of RF entries: " << hSigRF->GetEntries() << endl; cout << "Number of CBG entries: " << hSigCBG->GetEntries() << endl; cout << "CBG Results in Results.txt and Results.root. Remember to rename them!" << endl; f->Close(); TFile* fOut = new TFile("Results.root","RECREATE"); if(!fOut->IsOpen()) { cerr << "Problem with output root file!" << endl; return; } //hSigRBM->Write(); hSigRF->Write(); hSigCBG->Write(); c1->Write(); c2->Write(); c3->Write(); fOut->Close(); }
void much_draw_digis( TString mcFileName = "data/mc.root", TString digiFileName = "data/much_digi_sector.root", TString rcFileName = "data/hits.root", Int_t iEvent = 0, Int_t iStationSelected = 0, Int_t iLayerSelected = 2, Int_t iSideSelected = 0, // 0 - front, 1 - back, 2 - both Double_t xmin = -250, Double_t xmax = 250, Double_t ymin = -250, Double_t ymax = 250 ){ TString paramDir = gSystem->Getenv("VMCWORKDIR"); TString digiFileName = paramDir+"/parameters/much/much_v12c.digi.root"; gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C"); basiclibs(); gROOT->LoadMacro("$VMCWORKDIR/macro/much/muchlibs.C"); muchlibs(); // init digi scheme TFile* digiFile = new TFile(digiFileName); TObjArray* stations = (TObjArray*) digiFile->Get("stations"); CbmMuchGeoScheme* digiScheme = CbmMuchGeoScheme::Instance(); digiScheme->Init(stations); // get TClonesArrays from trees TFile* mcFile = new TFile(mcFileName); TFile* rcFile = new TFile(rcFileName); TTree* mcTree = mcFile ? (TTree*) mcFile->Get("cbmsim") : 0; TTree* rcTree = rcFile ? (TTree*) rcFile->Get("cbmsim") : 0; TClonesArray* points = new TClonesArray("CbmMuchPoint"); TClonesArray* digis = new TClonesArray("CbmMuchDigi"); TClonesArray* hits = new TClonesArray("CbmMuchPixelHit"); if (mcTree) mcTree->SetBranchAddress("MuchPoint",&points); if (rcTree) rcTree->SetBranchAddress("MuchDigi",&digis); if (rcTree) rcTree->SetBranchAddress("MuchPixelHit",&hits); if (mcTree) mcTree->GetEntry(iEvent); if (rcTree) rcTree->GetEntry(iEvent); // Draw pads TCanvas* c1 = new TCanvas("station","station",1000*(xmax-xmin)/(ymax-ymin),1000); c1->Range(xmin,ymin,xmax,ymax); for (Int_t iSide=1;iSide>=0;iSide--){ if (iSideSelected!=2 && iSide!=iSideSelected)continue; CbmMuchLayerSide* side = digiScheme->GetLayerSide(iStationSelected,iLayerSelected,iSide); for (Int_t iModule=0;iModule<side->GetNModules();++iModule) { CbmMuchModuleGem* module = (CbmMuchModuleGem*) side->GetModule(iModule); if (!module) continue; module->Draw(); printf("%i\n",module->GetNPads()); } } return; // Mark fired pads for (Int_t i=0;i<digis->GetEntriesFast();i++){ CbmMuchDigi* digi = (CbmMuchDigi*) digis->At(i); // Filter out points Int_t detId = digi->GetDetectorId(); if (!IsSelected(detId,iStationSelected,iLayerSelected,iSideSelected)) continue; CbmMuchModuleGem* module = (CbmMuchModuleGem*)digiScheme->GetModuleByDetId(detId); if (!module) continue; module->SetPadFired(digi->GetChannelId(),i,digi->GetADCCharge()); } // Draw points for (Int_t i=0;i<points->GetEntriesFast();i++){ CbmMuchPoint* point = (CbmMuchPoint*) points->At(i); Int_t detId = point->GetDetectorId(); if (!IsSelected(detId,iStationSelected,iLayerSelected,iSideSelected)) continue; TLine* l = new TLine(point->GetXIn()-0.1,point->GetYIn()-0.1,point->GetXOut()+0.1,point->GetYOut()+0.1); l->SetLineColor(kBlack); l->SetLineWidth(3); l->Draw(); } // Draw hits for (Int_t i=0;i<hits->GetEntriesFast();i++){ CbmMuchPixelHit* hit = (CbmMuchPixelHit*) hits->At(i); Int_t detId = hit->GetDetectorId(); if (!IsSelected(detId,iStationSelected,iLayerSelected,iSideSelected)) continue; TEllipse* p = new TEllipse(hit->GetX(),hit->GetY(),0.08); p->SetFillColor(kRed); p->SetLineColor(kRed); p->Draw(); } // Draw a hole TArc* holeArc = new TArc(0.,0.,digiScheme->GetStation(iStationSelected)->GetRmin()); holeArc->Draw(); c1->Print("station.png"); }
void TOF1_Circle() { float Gap1[3][2]; float Gap7[3][2]; float Gap2[3][2]; float Gap8[3][2]; float Gap3[3][2]; float Gap9[3][2]; float Gap4[3][2]; float Gap10[3][2]; float Gap5[3][2]; float Gap11[3][2]; float Gap6[3][2]; float Gap12[3][2]; TH2F *h_Circle = new TH2F("Test", "TARGET and TOF1", 500, -50, 50, 500, -50, 50); TH2F *h_Target = new TH2F("Test Target", "Target", 3000, -50, 50, 3000, -50, 50); TEllipse *ell = new TEllipse(0, 0, 44.5,0); TCanvas *c1; c1 = new TCanvas("cc1","cc1",0,200,500,500); //c1->Divide(3,2); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0, "ProcEvent(Int_t,Int_t,Int_t,TObject*)"); // TLine *Gap1l = new TLine(28.9952, 34.7881, 15.7548, 42.2881); // TLine *Gap2l = new TLine(42.2881, 15.7548, 34.7881, 28.7452); // TLine *Gap3l = new TLine(44.5, -7.5, 44.5, 7.5); // TLine *Gap4l = new TLine(42.2881, -15.7548, 34.7881, -28.7452); // TLine *Gap5l = new TLine(28.7452, -34.7881, 15.7548, -42.2881); // TLine *Gap6l = new TLine(-7.5, -44.5, 7.5, -44.5); // TLine *Gap7l = new TLine(-28.7452, -34.7881, -15.7548, -42.2881); // TLine *Gap8l = new TLine(-42.2881, -15.7548, -34.7881, -28.7452); // TLine *Gap9l = new TLine(-44.5, -7.5, -44.5, 7.5); // TLine *Gap10l = new TLine(-42.2881, 15.7548, -34.7881, 28.7452); // TLine *Gap11l = new TLine(-28.9952, 34.7881, -15.7548, 42.2881); // TLine *Gap12l = new TLine(-7.5, 44.5, 7.5, 44.5); for(int t=0; t<256; t++) { h_Target->Fill(Xloc[t],Yloc[t]); } for(int i=0; i<3; i++) { Gap1[i][0] = TOF_Gap1XLoc[i]; Gap7[i][0] = TOF_Gap7XLoc[i]; Gap2[i][0] = TOF_Gap2XLoc[i]; Gap8[i][0] = TOF_Gap8XLoc[i]; Gap3[i][0] = TOF_Gap3XLoc[i]; Gap9[i][0] = TOF_Gap9XLoc[i]; Gap4[i][0] = TOF_Gap4XLoc[i]; Gap10[i][0] = TOF_Gap10XLoc[i]; Gap5[i][0] = TOF_Gap5XLoc[i]; Gap11[i][0] = TOF_Gap11XLoc[i]; Gap6[i][0] = TOF_Gap6XLoc[i]; Gap12[i][0] = TOF_Gap12XLoc[i]; } for(int j=0; j<3; j++) { Gap1[j][1] = TOF_Gap1YLoc[j]; Gap7[j][1] = TOF_Gap7YLoc[j]; Gap2[j][1] = TOF_Gap2YLoc[j]; Gap8[j][1] = TOF_Gap8YLoc[j]; Gap3[j][1] = TOF_Gap3YLoc[j]; Gap9[j][1] = TOF_Gap9YLoc[j]; Gap4[j][1] = TOF_Gap4YLoc[j]; Gap10[j][1] = TOF_Gap10YLoc[j]; Gap5[j][1] = TOF_Gap5YLoc[j]; Gap11[j][1] = TOF_Gap11YLoc[j]; Gap6[j][1] = TOF_Gap6YLoc[j]; Gap12[j][1] = TOF_Gap12YLoc[j]; } cout << " " << endl; cout << " " << endl; //for(int k=0; k<3; k++) //{ // cout << Gap12[k][0] << " " << Gap12[k][1] << endl; //} for(int ii=0; ii<3; ii++) { h_Circle->Fill(Gap1[ii][0],Gap1[ii][1]); h_Circle->Fill(Gap7[ii][0],Gap7[ii][1]); h_Circle->Fill(Gap2[ii][0],Gap2[ii][1]); h_Circle->Fill(Gap8[ii][0],Gap8[ii][1]); h_Circle->Fill(Gap3[ii][0],Gap3[ii][1]); h_Circle->Fill(Gap9[ii][0],Gap9[ii][1]); h_Circle->Fill(Gap4[ii][0],Gap4[ii][1]); h_Circle->Fill(Gap10[ii][0],Gap10[ii][1]); h_Circle->Fill(Gap5[ii][0],Gap5[ii][1]); h_Circle->Fill(Gap11[ii][0],Gap11[ii][1]); h_Circle->Fill(Gap6[ii][0],Gap6[ii][1]); h_Circle->Fill(Gap12[ii][0],Gap12[ii][1]); } c1->cd(); h_Circle->SetMarkerStyle(5); h_Circle->SetMarkerSize(1.2); h_Circle->SetLineWidth(2); h_Circle->Draw(); h_Target->SetMarkerStyle(25); h_Target->SetMarkerColor(4); h_Target->SetMarkerSize(1.2); h_Target->Draw("same"); Gap1l->Draw("same"); //Gap2l->Draw("same"); //Gap3l->Draw("same"); //Gap4l->Draw("same"); //Gap5l->Draw("same"); //Gap6l->Draw("same"); //Gap7l->Draw("same"); //Gap8l->Draw("same"); //Gap9l->Draw("same"); //Gap10l->Draw("same"); //Gap11l->Draw("same"); Gap12l->Draw("same"); ell->SetFillStyle(0); ell->SetLineColor(6); ell->Draw("same"); }
int main(int argc, char** argv) { std::vector<std::string> names; names.push_back("b-tag"); names.push_back("mis-tag"); names.push_back("JER"); names.push_back("JES"); names.push_back("luminosity"); names.push_back("$\\rm m_{top}$"); names.push_back("Unclust. Energy"); names.push_back("pile up"); names.push_back("$\\rm Q^{2}$ scale"); names.push_back("$t\\bar{t}$ norm."); names.push_back("EWK norm."); names.push_back("QCD norm."); names.push_back("Wshape (c-flavor)"); names.push_back("Wshape (b-flavor)"); names.push_back("PDF"); names.push_back("CompHep"); names.push_back("MC stat."); names.push_back("Anom. $\\twb;\\,V_{R}$"); names.push_back("Anom. $\\twb;\\,g_{L}$"); names.push_back("SM W-helicity Ref."); /* * For Muon * * VR: * +0.05 * 0.308 = 0.0154 * 0.02 * -0.03 = - 0.0006 * +0.00 * 0.722 = 0 * * gL: * +0.075 * 0.308 = 0.023 * -0.012 * 0.722 = -0.009 * -0.02 * -0.03 = 0.0006 */ std::vector<double> F0Up; std::vector<double> FlUp; std::vector<double> FrUp; std::vector<double> F0Down; std::vector<double> FlDown; std::vector<double> FrDown; double F0Cent = 0; double FlCent = 0; for (int f = 1; f < argc; f++) { std::string arg_fth(*(argv + f)); if (arg_fth == "F0Up") { f++; std::string in(*(argv + f)); F0Up.push_back(atof(in.c_str())); } else if (arg_fth == "FlUp") { f++; std::string in(*(argv + f)); FlUp.push_back(atof(in.c_str())); } else if (arg_fth == "F0Down") { f++; std::string in(*(argv + f)); F0Down.push_back(atof(in.c_str())); } else if (arg_fth == "FlDown") { f++; std::string in(*(argv + f)); FlDown.push_back(atof(in.c_str())); } else if (arg_fth == "FrDown") { f++; std::string in(*(argv + f)); FrDown.push_back(atof(in.c_str())); } else if (arg_fth == "FrUp") { f++; std::string in(*(argv + f)); FrUp.push_back(atof(in.c_str())); } else if (arg_fth == "F0Cent") { f++; std::string in(*(argv + f)); F0Cent = atof(in.c_str()); } else if (arg_fth == "FlCent") { f++; std::string in(*(argv + f)); FlCent = atof(in.c_str()); } } cout << F0Up.size() << "\t" << FlUp.size() << "\t" << FrUp.size() << "\t" << names.size() << "\t" << endl; if (FlUp.size() > names.size()) { cout << (FlUp.size() - names.size()) << endl; double p = (FlUp.size() - names.size()); for (unsigned int s = 0; s < p; s++) names.push_back("blah"); } cout << F0Up.size() << "\t" << FlUp.size() << "\t" << FrUp.size() << "\t" << names.size() << "\t" << endl; ProperSystCalculator myIndividualSyst(F0Cent, FlCent, F0Up, F0Down, FlUp, FlDown, names); TMatrixT<double> * p = myIndividualSyst.GetCovarianceMatrix(); cout << p->GetMatrixArray()[0] << "\t" << p->GetMatrixArray()[1] << "\t" << p->GetMatrixArray()[2] << "\t" << p->GetMatrixArray()[3] << endl; std::pair<double, double> roots = myIndividualSyst.GetRoots(p); cout << "not ordered: " << roots.first << "\t" << roots.second << endl; if (!myIndividualSyst.isFirstGreater(p)) { double s = roots.first; roots.first = roots.second; roots.second = s; } cout << "ordered: " << roots.first << "\t" << roots.second << endl; std::cout.setf(std::ios::fixed); std::cout.precision(3); cout << sqrt(roots.first) << "\t" << sqrt(roots.second) << endl; myIndividualSyst.Set3rdVar(FrUp, FrDown); // myIndividualSyst.printSystTable(false, true); // myIndividualSyst.printSystTable(true, true); TEllipse * el = myIndividualSyst.GetEllipse(p); TCanvas C; C.cd(); el->Draw("ap"); C.SaveAs("a.C"); return 0; }
void EtaPhi::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; cout << "Choose event, -1 for no choice" << endl; int choice; cin >> choice; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; fChain->GetEntry(jentry); bool stahp = false; int count = 0; vector<int> jets; double phi_sum = 0; if ( choice >= 0 && choice != jentry ) continue; cout << jentry << endl; for ( int j = 0; j < fJets; ++j ) { int fl = fFlav[j]; TLorentzVector t(fX[j],fY[j],fZ[j],fT[j]); if (fl < 0 || fl == 10) { continue; } jets.push_back(j); cout << " " << fl << endl; if ( fl != 0 ) ++count; if ( fabs(t.Rapidity()) > 3 && jets.size() < 3 ) { stahp = true; break; } phi_sum += t.Phi(); } if ( stahp || (count > 1 && choice == -1) ) { continue; } if ( !accept() ) continue; TCanvas* c1 = new TCanvas("c1", "c1", 1200, 1000); TH1D* th = new TH1D("","",100,-5.0,5.0); gStyle->SetOptStat(0); th->SetMinimum(-TMath::Pi()); th->SetMaximum(TMath::Pi()); th->SetXTitle("y"); th->SetYTitle("#phi"); th->Draw("P"); phi_sum /= jets.size(); for ( unsigned j = 0; j < jets.size(); ++j ) { TLorentzVector t(fX[jets[j]],fY[jets[j]],fZ[jets[j]],fT[jets[j]]); TEllipse *el = new TEllipse(t.Rapidity(),phif(t.Phi(),phi_sum),0.5,0.5); Color_t ell_col = kRed+1; if (j == 1) ell_col = kRed; else if (j == 2) ell_col = kMagenta; else if (j == 3) ell_col = kCyan+2; else if (j > 3) ell_col = kBlue; el->SetLineColor(ell_col); el->SetFillStyle(0); el->Draw("same"); } for ( int j = 0; j < fJets; ++j ) { int fl = fFlav[j]; TLorentzVector t(fX[j],fY[j],fZ[j],fT[j]); if (fl == 10) continue; fl *= -1; double saizu = TMath::Log10(t.Pt()/0.01); Color_t col; Style_t sty; if ( fl == 10 ) { col = kBlue; sty = kCircle; } else if ( fl == 11 ) { col = kAzure + 7; sty = kCircle; } else if ( fl == 12 ) { col = kRed; sty = kOpenSquare; } else if ( fl == 13 ) { col = kGreen-7; sty = kCircle; } else if ( fl == 14 ) { col = kYellow + 1; sty = kCircle; } else if ( fl == 15 ) { col = kGreen+2; sty = kOpenSquare; //} else if ( fl == 7 || fl == 8 ) { // col = kBlack; // sty = kOpenSquare; } else if ( fl == 9 ) { col = kMagenta; sty = kDiamond; } else { continue; } if (saizu < 0) continue; if ( fl == 13 || fl == 14 || fl == 15 || fl == 9 ) saizu *= 2; TGraph *f = new TGraph(1); f->SetPoint(0,t.Rapidity(),phif(t.Phi(),phi_sum)); f->SetMarkerStyle(sty); f->SetMarkerColor(col); f->SetMarkerSize(saizu); f->Draw("sameP"); } break; } }
/// plots the beam profiles in (x1,x2) and (x,x') planes void display_beamprofile(float s, string filename="data/LHCB1IR5_v6.500.tfs", char * ipname = "IP5", int side = 1, char * title ="", unsigned int NParticle=1000, const int crang_sign=-1, const bool save=false, char * outfilename="") { /// @param s : distance from IP [m] /// @param filename : optics source file /// @param ipname : string identifier for the IP position /// @param side : direction of propagation (forward 1, backward -1) /// @param title : for the graph /// @param NParticle : beam content /// @param crang_sign : direction for the (half) crossing angle at IP /// @param save : boolean /// @param outfilename: file to be written // note : beam 1 forward : side = 1 crang_sign =-1 // note : beam 1 backward : side = -1 crang_sign = 1 // note : beam 2 forward : side = -1 crang_sign =-1 // note : beam 2 backward : side = 1 crang_sign = 1 extern bool relative_energy; relative_energy = false; if(relative_energy) { cout << "You should be in absolute energy" << endl; return; } extern int kickers_on; kickers_on = 1; int max = (crang_sign>0)?100:-95; int min = (crang_sign<0)?-100:95; TH2F * hp = new TH2F("Positions","",100,min,max,100,-2.5,2.5); TH2F * ha = new TH2F("Angles","",100,-50,50,100,-50,50); TH2F * hax = new TH2F("Phase_x","",100,min,max,100,-50,50); TH2F * hay = new TH2F("Phase_y","",100,-2.5,2.5,100,-50,50); float draftx[NParticle], drafty[NParticle], drafttx[NParticle], draftty[NParticle]; // float rmsx=0, rmsy=0, angle=0; TMultiGraph * profile = new TMultiGraph("prof",""); H_BeamLine* beamline = new H_BeamLine(side,s+0.1); beamline->fill(filename,-1*side*crang_sign,ipname); beamline->offsetElements(120,0.097*crang_sign); // extern int kickers_on; // kickers_on = 1; for (unsigned int i=0; i<NParticle ; i++) { H_BeamParticle p1; p1.smearPos(); p1.smearAng(); p1.setPosition(p1.getX()-500.,p1.getY(),p1.getTX()+crang_sign*CRANG,p1.getTY(),0); p1.computePath(beamline); p1.propagate(beamline); p1.propagate(s); hp->Fill(p1.getX()/1000.,p1.getY()/1000.); ha->Fill(p1.getTX(),p1.getTY()); hax->Fill(p1.getX()/1000.,p1.getTX()); hay->Fill(p1.getY()/1000.,p1.getTY()); draftx[i]=p1.getX()/1000.; drafty[i]=p1.getY()/1000.; drafttx[i]=p1.getTX(); draftty[i]=p1.getTY(); TGraph * path = p1.getPath(0,1); profile->Add(path); } TCanvas * can = new TCanvas; can->cd(); hp->SetTitle(title); hp->Draw(); hp->GetXaxis()->SetTitle("x (mm)"); hp->GetYaxis()->SetTitleOffset(1.2); hp->GetYaxis()->SetTitle("y (mm)"); TEllipse * ellipse = new TEllipse(hp->GetMean(1),hp->GetMean(2),3*(hp->GetRMS(1)),3*(hp->GetRMS(2))); cout << "mean = " << hp->GetMean(1) << " " << hp->GetMean(2) << endl; ellipse->SetLineColor(kRed); ellipse->Draw(); TCanvas * ca2 = new TCanvas; ca2->cd(); profile->Draw("ACP"); TCanvas *ca3 = new TCanvas; ca3->cd(); ha->SetTitle(title); ha->Draw(); ha->GetXaxis()->SetTitle("#theta_{x} (#murad)"); ha->GetYaxis()->SetTitle("#theta_{y} (#murad)"); TEllipse * ellips2 = new TEllipse(ha->GetMean(1),ha->GetMean(2),3*(ha->GetRMS(1)),3*(ha->GetRMS(2))); ellips2->SetLineColor(kRed); ellips2->Draw(); TCanvas *ca4 = new TCanvas; ca4->cd(); hax->SetTitle(title); hax->Draw(); hax->SetStats(0); hax->GetXaxis()->SetTitle("x (mm)"); hax->GetYaxis()->SetTitle("#theta_{x} (#murad)"); // getEllipseParameters(draftx,drafttx,NParticle,rmsx,rmsy,angle); // ca4->cd(); // cout << rmsx << " " << rmsy << " " << angle << endl; // TEllipse * ellips3 = new TEllipse(hp->GetMean(1),ha->GetMean(1),3*rmsx,3*rmsy); // ellips3->SetTheta(angle); // ellips3->SetLineColor(kRed); // ellips3->Draw(); TCanvas *ca5 = new TCanvas; ca5->cd(); hay->SetTitle(title); hay->Draw(); hay->SetStats(0); hay->GetXaxis()->SetTitle("y (mm)"); hay->GetYaxis()->SetTitle("#theta_{y} (#murad)"); // getEllipseParameters(drafty,draftty,NParticle,rmsx,rmsy,angle); // ca5->cd(); // cout << rmsx << " " << rmsy << " " << angle << endl; // TEllipse * ellips4 = new TEllipse(hp->GetMean(2),ha->GetMean(2),3*rmsx,3*rmsy); // ellips4->SetTheta(angle); // ellips4->SetLineColor(kRed); // ellips4->Draw(); if(save) { char filetitle_pos[50], filetitle_ang[50], filetitle_phasex[50], filetitle_phasey[50]; sprintf(filetitle_pos,"%s_pos.eps",outfilename); cout << filetitle_pos << endl; can->Print(filetitle_pos,"eps"); sprintf(filetitle_ang,"%s_ang.eps",outfilename); cout << filetitle_ang << endl; ca3->Print(filetitle_ang,"eps"); sprintf(filetitle_phasex,"%s_px.eps",outfilename); cout << filetitle_phasex << endl; ca4->Print(filetitle_phasex,"eps"); sprintf(filetitle_phasey,"%s_py.eps",outfilename); cout << filetitle_phasey << endl; ca5->Print(filetitle_phasey,"eps"); delete can; delete ca2; delete ca3; delete ca4; delete ca5; delete hp; delete ha; delete hax; delete hay; delete profile; delete beamline; delete ellipse; delete ellips2; // delete ellips3; // delete ellips4; } }
void fitcorr(){ setTDRStyle(); TFile *f = new TFile("rootfiles/fitresults_2D_data.root"); TTree *t = (TTree*)f->Get("FitResults"); double mt=0, jsf=0, mcmass=0; t->SetBranchAddress("mt", &mt); t->SetBranchAddress("jesfactor", &jsf); t->SetBranchAddress("mcmass", &mcmass); TH2D *h2D = new TH2D("h2D",";M_{t} [GeV];JSF", 20, 170, 173, 20, 0.99, 1.04 ); TGraph *g = new TGraph(); for( int i=0; i < t->GetEntries(); i++ ){ t->GetEntry(i); //if( mcmass != 172.5 ) continue; h2D->Fill(mt, jsf); g->SetPoint(g->GetN(), mt, jsf); } // uncertainty contour double mean_mt = g->GetMean(1); double mean_jsf = g->GetMean(2); double sigma_mt = g->GetRMS(1); double sigma_jsf = g->GetRMS(2); double rho = g->GetCorrelationFactor(); std::cout << "Mean Mt = " << mean_mt << " +- " << sigma_mt << std::endl; std::cout << "Mean JSF = " << mean_jsf << " +- " << sigma_jsf << std::endl; std::cout << "Correlation = " << rho << std::endl; TMatrixDSym m(2); m(0,0) = sigma_mt*sigma_mt; m(1,1) = sigma_jsf*sigma_jsf; m(0,1) = rho*sigma_mt*sigma_jsf; m(1,0) = rho*sigma_mt*sigma_jsf; TMatrixDSymEigen eigen(m); TVectorD eigenval = eigen.GetEigenValues(); std::cout << eigenval[0] << " " << eigenval[1] << endl; // convert to ellipse tilt and radius //double phi = 0.5*TMath::ATan( (3/0.03)*(2*rho*sigma_mt*sigma_jsf)/(sigma_mt*sigma_mt-sigma_jsf*sigma_jsf) ); double phi = (180.0/TMath::Pi())*0.5*TMath::ATan( (2*rho*sigma_mt*sigma_jsf)/(sigma_mt*sigma_mt-sigma_jsf*sigma_jsf) ); std::cout << "phi = " << phi << std::endl; TEllipse *el = new TEllipse(mean_mt, mean_jsf, sqrt(eigenval[0]), sqrt(eigenval[1]), 0, 360, phi); TEllipse *el2 = new TEllipse(mean_mt, mean_jsf, 2*sqrt(eigenval[0]), 2*sqrt(eigenval[1]), 0, 360, phi); /* TF2* fell = new TF2("fell","pow((x-[1])*cos([0])+(y-[2])*sin([0]),2)/[3] + pow((x-[1])*sin([0])-(y-[2])*cos([0]),2)/[4]",171,174,0.985,1.015); fell->SetParameter(0,phi); fell->SetParameter(1,mean_mt); fell->SetParameter(2,mean_jsf); fell->SetParameter(3,eigenval[0]); fell->SetParameter(4,eigenval[1]); double cont[1] = {1}; fell->SetContour(1, cont); */ const Int_t Number = 2; Double_t Red[Number] = { 0.90, 0.10}; Double_t Green[Number] = { 0.90, 0.10}; Double_t Blue[Number] = { 0.90, 0.10}; Double_t Stops [Number] = {0, 1}; Double_t Length [Number] = {0, 1}; Int_t nb=50; TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb); gStyle->SetPadRightMargin(0.16); gStyle->SetPadTopMargin(0.08); TCanvas *c = new TCanvas("c","c",800,600); h2D->Draw("colzC"); el->SetFillStyle(0); el->SetLineColor(2); el->SetLineWidth(3); el->Draw(); el2->SetFillStyle(0); el2->SetLineColor(2); el2->SetLineWidth(3); el2->Draw(); int iPeriod = 2; int iPos = 33; lumi_sqrtS = "8 TeV"; writeExtraText = false; CMS_lumi( c, iPeriod, iPos ); c->Update(); c->RedrawAxis(); c->GetFrame()->Draw(); TLatex latex; latex.SetNDC(); latex.SetTextSize(0.06); latex.SetTextFont(42); latex.DrawLatex(0.2, 0.84, "2D fit"); c->Print("pdfplots/fitcorr.pdf"); //delete c; return; }