void Shadows::handMoved(ofxBlob &_blob){
    
    if ( hands[ _blob.id ] == NULL ){
        hands.erase( _blob.id );
        
        //  If don't have record of this blob probably it's because it's a hole of a blob...
        //  ... so try to find it owner
        //
        ofPolyline contourLine = getContour(_blob);
        int holeOfBlob  = checkIfHole(contourLine);  
        
        if (holeOfBlob >= 0){
            //  If it's a hole it will insert it into the last blobFrame
            //
            hands[holeOfBlob]->insertHole(contourLine);
            //ofLog(OF_LOG_NOTICE,"Adding new frame of hole shadow idº " + ofToString( holeOfBlob ));
        } else {
            ofLog(OF_LOG_NOTICE,"Something goes wrong... I don´t what to do with blob idº " + ofToString( _blob.id ));
        }
        
    } else {
        hands[ _blob.id ]->addFrame(_blob,width,height);
        //ofLog(OF_LOG_NOTICE,"Adding new frame of shadow id " + ofToString( _blob.id ));
    }
}
void Shadows::handAdded(ofxBlob &_blob){
    
    //  Make a ofPolygone from the _blob
    //
    ofPolyline contourLine = getContour(_blob);
    
    //  Check if it's a hole. If it´s not it will return a -1 if it´s a hole it will
    //  return the nId of the owner
    //
    int holeOfBlob  = checkIfHole(contourLine);  
        
    if (holeOfBlob >= 0){
        
        //  If it´s a hole it will insert it into the last blobFrame
        //
        hands[holeOfBlob]->insertHole(contourLine);
        //ofLog(OF_LOG_NOTICE,"Adding hole to shadow idº " + ofToString( holeOfBlob ));
    } else {
        
        //  If it's not a hole add a new shadow to the map with the first frame
        //
        AnimatedShadow *newShadow = new AnimatedShadow( _blob.id );
        newShadow->addFrame( contourLine, _blob.nFingers );
        hands[ newShadow->getId() ] = newShadow;
        //ofLog(OF_LOG_NOTICE,"Adding shadow idº " + ofToString( newShadow->getId() ));
    }
}
Example #3
0
void scribe3D (nvMapGL *map, OPTIONS *options, MISC *misc, NV_FLOAT32 *ar, NV_INT32 ncc, NV_INT32 nrr, NV_FLOAT64 xorig, NV_FLOAT64 yorig)
{
  NV_INT32                index_contour, num_points, i, num_interp, bytes, width;
  NV_FLOAT64              dcontour_x[CONTOUR_POINTS], dcontour_y[CONTOUR_POINTS], dcontour_z[CONTOUR_POINTS], dx, dy, cell_diag_length, segment_length;
  NV_FLOAT32              level, half_gridx, half_gridy, *contour_x, *contour_y, x[2], y[2], z[2], *xyz_x, *xyz_y, *xyz_z;


  void contourMinMax (NV_FLOAT32, NV_FLOAT32);
  void contourEmphasis (NV_INT32);
  void contourMaxDensity (NV_INT32);
  void contourMaxPoints (NV_INT32);
  void contourLevels (NV_INT32 numLevels, NV_FLOAT32 *);
  NV_INT32 initContour (NV_FLOAT32, NV_INT32, NV_INT32, NV_FLOAT32 *);
  NV_INT32 getContour (NV_FLOAT32 *, NV_INT32 *, NV_INT32 *, NV_FLOAT32 *, NV_FLOAT32 *);


  //  Check the smoothing factor range and get the number of interpolation 
  //  points per unsmoothed contour segment

  if (options->smoothing_factor < 0) options->smoothing_factor = 0;
  if (options->smoothing_factor > 10) options->smoothing_factor = 10;


  dcontour_x[0] = xorig + (misc->x_grid_size * ncc) * 0.5;
  dcontour_y[0] = yorig + (misc->y_grid_size * nrr) * 0.5;
  dcontour_x[1] = dcontour_x[0] + misc->x_grid_size;
  dcontour_y[1] = dcontour_y[0] + misc->y_grid_size;

  map->map_to_screen (2, dcontour_x, dcontour_y, dcontour_z, x, y, z);

  dx = x[1] - x[0];
  dy = y[1] - y[0];

  cell_diag_length = sqrt (pow (dx, 2) + pow (dy, 2));

  segment_length = DEFAULT_SEGMENT_LENGTH / options->smoothing_factor;

  if (cell_diag_length > segment_length)
    {
      num_interp = (NV_INT32) ((cell_diag_length / segment_length) + 0.5);
    }
  else
    {
      num_interp = 1;
    }


  /* allocate memory for contour arrays */

  if (options->smoothing_factor > 0)
    {
      bytes = (((num_interp * (CONTOUR_POINTS - 1)) + 1) * sizeof (NV_FLOAT64));
    }
  else
    {
      bytes = (CONTOUR_POINTS * sizeof (NV_FLOAT64));
    }

  contour_x = (NV_FLOAT32 *) malloc (bytes / 2);
  contour_y = (NV_FLOAT32 *) malloc (bytes / 2);
  xyz_x = (NV_FLOAT32 *) malloc (bytes);
  xyz_y = (NV_FLOAT32 *) malloc (bytes);
  if ((xyz_z = (NV_FLOAT32 *) malloc (bytes)) == NULL)
    {
      perror (__FILE__);
      exit (-1);
    }


  //  Set the min and max contours, the index contour interval, the
  //  maximum contour density, and the number of points to be returned
  //  by the package.

  contourMinMax (misc->min_z * options->z_factor + options->z_offset, misc->max_z * options->z_factor + options->z_offset);
  contourMaxDensity (misc->maxd);
  contourMaxPoints (CONTOUR_POINTS);


  //  If the contour interval is set to 0.0 use the user defined levels.

  if (misc->abe_share->cint == 0.0) contourLevels (misc->abe_share->num_levels, misc->abe_share->contour_levels);


  //  Pass the grid array (arranged 1D) to the contouring package.

  initContour (misc->abe_share->cint, nrr, ncc, ar);


  //  Compute half of a grid cell in degrees.

  half_gridx = misc->x_grid_size * 0.5;
  half_gridy = misc->y_grid_size * 0.5;


  //  Get the contours from the package until all are drawn.

  while (getContour (&level, &index_contour, &num_points, contour_x, contour_y))
    {
      //  Convert from grid points (returned contours) to position.
                    
      for (i = 0 ; i < num_points ; i++)
        {
          dcontour_x[i] = xorig + (contour_x[i] * misc->x_grid_size) + half_gridx;
          dcontour_y[i] = yorig + (contour_y[i] * misc->y_grid_size) + half_gridy;
          dcontour_z[i] = -level;
        }


      //  Convert from position to pixels.

      map->map_to_screen (num_points, dcontour_x, dcontour_y, dcontour_z, xyz_x, xyz_y, xyz_z);


      //  smooth out the contour (don't do this sooner for the sake of efficiency -- smooth in xy plot space)

      if (options->smoothing_factor > 0) smooth_contour (num_interp, &num_points, xyz_x, xyz_y);


      //  If this is the zero contour, thicken the line.

      width = options->contour_width;
      if (level == 0.0)
        {
          switch (width)
            {
            case 1:
              width = 3;
              break;

            case 2:
              width = 4;
              break;

            case 3:
              width = 5;
              break;
            }
        }


      //  Draw the contours.
            
      for (i = 0 ; i < num_points ; i++) map->setLines (xyz_x[i], xyz_y[i], xyz_z[i], options->contour_color, width, Qt::SolidLine, i, NVFalse);


      //  Check the event queue to see if the user wants to interrupt the contouring.

      if (qApp->hasPendingEvents ())
        {
          qApp->processEvents ();
          if (misc->drawing_canceled) break;
        }
    }

  free (contour_x);
  free (contour_y);
  free (xyz_x);
  free (xyz_y);
  free (xyz_z);


  map->setLines (0.0, 0.0, 0.0, Qt::black, 1, Qt::SolidLine, 0, NVTrue);


  map->flush ();
}
PointCloudPtr ContourGenerator::R20_H()
{
    return getContour(getRectanglePoints(0.04875, 0.034));
}
PointCloudPtr ContourGenerator::M30_H()
{
    return getContour(getHexagonPoints(0.02875));
}
PointCloudPtr ContourGenerator::M20_100_H()
{
    return getContour(getBoltPoints(0.04, 0.019, 0.1, 0.028));
}
PointCloudPtr ContourGenerator::F20_20_H()
{
    return getContour(getRectanglePoints(0.1, 0.02));
}
PointCloudPtr ContourGenerator::S40_40_H()
{
    return getContour(getRectanglePoints(0.1, 0.04));
}
Example #9
0
void drawContour(TString bino="bino", TString jet="nojet", bool print=false) {

  bool useCustomGetContour = false;

  //  TString data_dir = "table_20120131/multiChannel"; // answering preapproval questions
  TString data_dir = "table_20120209/multiChannel"; // last success after answering preapproval questions
  //TString data_dir = ".";

  gStyle->SetOptStat(0);

  TString label = bino + "_mN375_met100_" + jet;
  if(bino.Contains("mNScan")) label = bino + "_met100_" + jet;

  gStyle->SetPalette(1);
  gStyle->SetPadLeftMargin(0.15);

  //  TString option2D = "CONT4 Z";
  TString option2D = "COL Z";

  // for bino & wino
  const int nG = 21;
  const int nS = 21;
  float mGVals[nG+1] = {400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};
  float mSVals[nS+1] = {400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};

  // to make valuse on the center of each bin
  float* mGBins = new float[nG+1];
  float* mSBins = new float[nS+1];
  for(int i=0; i<nG+1; i++) mGBins[i] = mGVals[i]-40;
  for(int i=0; i<nS+1; i++) mSBins[i] = mSVals[i]-40;


  // for mNScan
  const int nX = 10;
  const int nY = 23;
  float xVals[nX+1] = {150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150};
  float yVals[nY+1] = {240, 320, 400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};

  float* xBins = new float[nX+1];
  float* yBins = new float[nY+1];

  for(int i=0; i<nX+1; i++) xBins[i] = xVals[i]-50;
  for(int i=0; i<nY+1; i++) yBins[i] = yVals[i]-40;


  TFile* fout = new TFile("hist_exclusion_"+label+".root","RECREATE");

  const int nxs = 6;
  TString xsname[nxs] = {"xsec","xsec_1L","xsec_1H","xsec_2L","xsec_2H","acc"};
  TH2D* h_xs[nxs];
  for(int i=0; i<nxs; i++) {
    if(bino.Contains("mNScan")) h_xs[i] = new TH2D(xsname[i],xsname[i],nX,xBins,nY,yBins);
    else h_xs[i] = new TH2D(xsname[i],xsname[i],nS,mSBins,nG,mGBins);
  }

  const int nlimit = 6;
  TString limitname[nlimit] = {"limit", "exp", "exp_1L","exp_1H","exp_2L","exp_2H"};
  TH2D* h_limit[nlimit];
  for(int i=0; i<nlimit; i++) {
    if(bino.Contains("mNScan")) h_limit[i] = new TH2D(limitname[i],limitname[i],nX,xBins,nY,yBins);
    else h_limit[i] = new TH2D(limitname[i],limitname[i],nS,mSBins,nG,mGBins);
  }

  TString datafile = data_dir + "/" + bino + "_" + jet + ".table";

  std::ifstream fin;
  fin.open(datafile.Data());
  while(1){
    // #echo "mS mG mN acc xsec xsecPDFError xsecRSErrorNeg xsecRSErrorPos obsLimit expLimit exp_m1s exp_m2s exp_p1s exp_p2s"
    int mS, mG, mN;
    double acc, xsec, xsecPDFError, xsecRSErrorNeg, xsecRSErrorPos, obsLimit, expLimit, exp_m1s, exp_m2s, exp_p1s, exp_p2s;
    fin >> mS >> mG >> mN >> acc >> xsec >> xsecPDFError >> xsecRSErrorNeg >> xsecRSErrorPos >> obsLimit >> expLimit >> exp_m1s >> exp_m2s >> exp_p1s >> exp_p2s;
    if(!fin.good()) break;

//     std::cout << mS << ", " << mG << ", " << mN << ", " << acc << ", " << xsec << ", " << xsecPDFError << ", "
// 	      << xsecRSErrorNeg << ", " << xsecRSErrorPos << ", " << obsLimit << ", " << expLimit << ", "
// 	      << exp_m1s << ", " << exp_m2s << ", " << exp_p1s << ", " << exp_p2s << std::endl;

    double oneSigma_L = std::sqrt(xsecRSErrorNeg * xsecRSErrorNeg + xsecPDFError * xsecPDFError);
    double oneSigma_H = std::sqrt(xsecRSErrorPos * xsecRSErrorPos + xsecPDFError * xsecPDFError);

    if(bino.Contains("mNScan")) {
      if(mS != 2500) continue;
      h_xs[5]->Fill(mN,mG,acc);
      h_xs[0]->Fill(mN,mG,xsec);
      h_xs[1]->Fill(mN,mG,xsec - xsec*oneSigma_L);
      h_xs[2]->Fill(mN,mG,xsec + xsec*oneSigma_H);
      h_xs[3]->Fill(mN,mG,xsec - xsec*2*oneSigma_L);
      h_xs[4]->Fill(mN,mG,xsec + xsec*2*oneSigma_H);

      h_limit[0]->Fill(mN,mG,obsLimit*xsec);
      h_limit[1]->Fill(mN,mG,expLimit*xsec);
      h_limit[2]->Fill(mN,mG,exp_m1s*xsec);
      h_limit[3]->Fill(mN,mG,exp_p1s*xsec);
      h_limit[4]->Fill(mN,mG,exp_m2s*xsec);
      h_limit[5]->Fill(mN,mG,exp_p2s*xsec);
    }
    else {
      if(mN != 375) continue;
      h_xs[5]->Fill(mS,mG,acc);
      h_xs[0]->Fill(mS,mG,xsec);
      h_xs[1]->Fill(mS,mG,xsec - xsec*oneSigma_L);
      h_xs[2]->Fill(mS,mG,xsec + xsec*oneSigma_H);
      h_xs[3]->Fill(mS,mG,xsec - xsec*2*oneSigma_L);
      h_xs[4]->Fill(mS,mG,xsec + xsec*2*oneSigma_H);

      h_limit[0]->Fill(mS,mG,obsLimit*xsec);
      h_limit[1]->Fill(mS,mG,expLimit*xsec);
      h_limit[2]->Fill(mS,mG,exp_m1s*xsec);
      h_limit[3]->Fill(mS,mG,exp_p1s*xsec);
      h_limit[4]->Fill(mS,mG,exp_m2s*xsec);
      h_limit[5]->Fill(mS,mG,exp_p2s*xsec);
    }// if - else

  }// while
  fin.close();

  for(int i=0; i<nxs; i++) fillPotHoles(h_xs[i]);
  for(int i=0; i<nlimit; i++) fillPotHoles(h_limit[i]);


  TGraph* noRegion2 = new TGraph(3);
  noRegion2->SetPoint(0,200,200);
  noRegion2->SetPoint(1,1100,200);
  noRegion2->SetPoint(2,1100,1100);
  noRegion2->SetFillColor(16);

  TLatex* lat44 = new TLatex(0.7,0.25,"#tilde{g} NLSP");
  lat44->SetNDC(true);
  lat44->SetTextSize(0.04);


  TString title;

  TCanvas* can_acc = new TCanvas("can_acc_"+label,"can_acc_"+label,1000,800);
  can_acc->SetRightMargin(0.19);
  h_xs[5]->GetXaxis()->SetNdivisions(505);
  h_xs[5]->GetYaxis()->SetNdivisions(505);
  h_xs[5]->GetYaxis()->SetTitleOffset(1.2);
  h_xs[5]->GetZaxis()->SetTitleOffset(1.2);
  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Acceptance";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Acceptance";
  h_xs[5]->SetTitle(title);
  h_xs[5]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_acc->Print("",".gif");
    can_acc->Print("",".pdf");
  }



  TCanvas* can_xs = new TCanvas("can_xsec_"+label,"can_xsec_"+label,1000,800);
  can_xs->SetRightMargin(0.17);
  can_xs->SetLogz();
  h_xs[0]->GetXaxis()->SetNdivisions(505);
  h_xs[0]->GetYaxis()->SetNdivisions(505);
  h_xs[0]->GetYaxis()->SetTitleOffset(1.2);
  h_xs[0]->GetZaxis()->SetTitleOffset(1.0);
  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Cross Section (pb)";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Cross Section (pb)";
  h_xs[0]->SetTitle(title);
  h_xs[0]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_xs->Print("",".gif");
    can_xs->Print("",".pdf");
  }

  TCanvas* can_limit = new TCanvas("can_limit_"+label,"can_limit_"+label,1000,800);
  can_limit->SetRightMargin(0.2);
  h_limit[0]->GetXaxis()->SetNdivisions(505);
  h_limit[0]->GetYaxis()->SetNdivisions(505);
  h_limit[0]->GetYaxis()->SetTitleOffset(1.2);
  h_limit[0]->GetZaxis()->SetTitleOffset(1.3);
  if(bino.Contains("wino")){
    can_limit->SetRightMargin(0.17);
    h_limit[0]->GetZaxis()->SetTitleOffset(1.0);
  }

  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});95% CL Upper Limit (pb)";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});95% CL Upper Limit (pb)";
  h_limit[0]->SetTitle(title);
  h_limit[0]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_limit->Print("",".gif");
    can_limit->Print("",".pdf");
  }

  // now find exclusion curves
  TCanvas* can_diff = new TCanvas("can_diff_"+label,"can_diff_"+label,1200,800);
  //  can_diff->Divide(nlimit,nxs);
  TH2D* h_excl[nlimit][nxs-1];
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {

      h_excl[i][j] = (TH2D*) h_limit[i]->Clone("exclusion_"+limitname[i]+"_"+xsname[j]);
      int nbinsx = h_excl[i][j]->GetXaxis()->GetNbins();
      int nbinsy = h_excl[i][j]->GetYaxis()->GetNbins();

      for( int ibx=1; ibx<=nbinsx; ++ibx){
	for( int iby=1; iby<=nbinsy; ++iby){
	  double x1 = h_limit[i]->GetBinContent(ibx,iby);
	  double x2 = h_xs[j]->GetBinContent(ibx,iby);
	  h_excl[i][j]->SetBinContent(ibx,iby,x2-x1);
	  x1 = h_limit[i]->GetBinError(ibx,iby);
	  x2 = h_xs[j]->GetBinError(ibx,iby);
	  h_excl[i][j]->SetBinError(ibx,iby,std::sqrt(x1*x1+x2*x2));
	}// for iby
      }// for ibx
      fixBadCells(h_excl[i][j]);
      if(i==0 && j==0) h_excl[i][j]->Draw("TEXT");
    }// for j
  }// for i


  float xmin = 400;
  float ymin = 400;
  float xmax = 2000;
  float ymax = 2000;
  if(bino.Contains("mNScan")){
    xmin = 200;
    xmax = 1500;
    ymin = 300;
    ymax = 2000;
  }


  TGraph* curv[nlimit][nxs-1];
  TGraphSmooth* gsmooth = new TGraphSmooth("normal");

  TH2D* h_back;
  if(bino.Contains("mNScan")) h_back = new TH2D("h_back",";m_{#tilde{#chi^{0}}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2})",100,xmin,xmax,100,ymin,ymax);
  else h_back = new TH2D("h_back",";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2})",100,xmin,xmax,100,ymin,ymax);

  h_back->GetXaxis()->SetNdivisions(505);
  h_back->GetYaxis()->SetNdivisions(505);
  h_back->GetYaxis()->SetTitleOffset(1.2);


  double contours[2]={ 0.0, 1.0 };
  TCanvas *can_excl01 = new TCanvas("can_excl01_"+label, "can_excl01_"+label,1200,800);
  can_excl01->Divide(nlimit,nxs-1);
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {

      can_excl01->cd(j*nlimit + i + 1);
      h_back->Draw();

      if(useCustomGetContour) {
        curv[i][j] = getContour(h_excl[i][j],"excl_curv_"+limitname[i]+"_"+xsname[j]);
        curv[i][j]->Draw("SAME L");
      }
      else {
	h_excl[i][j]->SetContour(2,contours);
	h_excl[i][j]->Draw("SAME CONT LIST");
	gPad->Update();

	TObjArray *contsM = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
	TList* contLevel = (TList*)contsM->At(0);
	curv[i][j] = (TGraph*)contLevel->First()->Clone("excl_curv_"+limitname[i]+"_"+xsname[j]);
      }
      //      PrintPoints(curv[i][j]);
      //      RemovePoints(curv[i][j]);

    }// for j
  }// for i

  if(bino.Contains("mNScan")) {
    for(int i=0; i<nlimit; i++) {
      for(int j=0; j<nxs-1; j++) {
	RemovePoints(curv[i][j]);
      }
    }

    for(int i=0; i<nlimit; i++) {
      for(int j=0; j<nxs-1; j++) {
	double x,y;
	int whichone = curv[i][j]->GetN()-1;
	curv[i][j]->GetPoint(whichone-1,x,y);
	curv[i][j]->SetPoint(whichone,y,y);
      }
    }
  }

  TGraphSmooth* gs[nlimit][nxs-1];
  TGraph* curvS[nlimit][nxs-1];
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {
      //      gs[i][j] = new TGraphSmooth("normal");
      //      curvS[i][j] = gs[i][j]->SmoothSuper(curv[i][j]);
      curvS[i][j] = (TGraph*) curv[i][j]->Clone();
      curvS[i][j]->SetName("excl_curvS_"+limitname[i]+"_"+xsname[j]);
    }
  }

  std::cout << "curv[3][0]----------------- N : " << curv[3][0]->GetN() << std::endl;
  PrintPoints(curv[3][0]);
  std::cout << "curvS[3][0]----------------- N : " << curvS[3][0]->GetN() << std::endl;
  PrintPoints(curvS[3][0]);
  std::cout << "---------------------------------" << std::endl;


  // make excluded region
  TGraph* excludedRegion = new TGraph(curvS[0][0]->GetN()+3);
  int nbins = curvS[0][0]->GetN();
  for(int i=0; i<nbins; i++){
    double x,y;
    curvS[0][0]->GetPoint(i,x,y);
    excludedRegion->SetPoint(i,x,y);
  }

  excludedRegion->SetPoint(nbins,xmax,ymin);
  excludedRegion->SetPoint(nbins+1,xmin,ymin);
  excludedRegion->SetPoint(nbins+2,xmin,ymax);

  // make band graph
  TGraph* exp1sigma_aroundExp = makeBandGraph(curvS[2][0],curvS[3][0]);


  TCanvas* can_excl02 = new TCanvas("can_excl02_"+label, "can_excl02_"+label,1000,800);
  h_back->Draw();
  //  can_excl02->SetGrid(1,1);

  // ecluded region
  excludedRegion->SetFillColor(kBlue-10);
  excludedRegion->SetFillStyle(1001);
  excludedRegion->Draw("SAME F");

  // experimental 1 sigma band around expected limit
  exp1sigma_aroundExp->SetFillColor(kOrange-3);
  exp1sigma_aroundExp->SetFillStyle(1001);
  exp1sigma_aroundExp->Draw("SAME F");

  // expected limit
  curvS[1][0]->SetLineStyle(9);
  curvS[1][0]->SetLineWidth(2);
  curvS[1][0]->SetLineColor(kOrange+9);
  curvS[1][0]->Draw("SAME L");

  // theory 1 sigma around expected limit
  curvS[1][1]->SetLineStyle(3);
  curvS[1][1]->SetLineWidth(1);
  curvS[1][1]->SetLineColor(kOrange+9);
  curvS[1][1]->Draw("SAME L");

  curvS[1][2]->SetLineStyle(3);
  curvS[1][2]->SetLineWidth(1);
  curvS[1][2]->SetLineColor(kOrange+9);
  curvS[1][2]->Draw("SAME L");

  // observed limit
  curvS[0][0]->SetLineWidth(3);
  curvS[0][0]->SetLineColor(4);
  curvS[0][0]->Draw("SAME L");

  // theory 1 sigma around observed limit
  curvS[0][1]->SetLineStyle(3);
  curvS[0][1]->SetLineWidth(2);
  curvS[0][1]->SetLineColor(kBlue);
  curvS[0][1]->Draw("SAME L");

  curvS[0][2]->SetLineStyle(3);
  curvS[0][2]->SetLineWidth(2);
  curvS[0][2]->SetLineColor(kBlue);
  curvS[0][2]->Draw("SAME L");


  PrintPoints(curvS[0][0]);


  float leg_xmin = 0.65;
  float leg_xmax = 0.9;
  float leg_ymin = 0.5;
  float leg_ymax = 0.8;
  if(bino.Contains("mNScan")){
    leg_xmin -= 0.45;
    leg_xmax -= 0.45;
  }


  TLegend* leg;
  if(bino.Contains("mNScan")) leg = new TLegend(leg_xmin,leg_ymin,leg_xmax,leg_ymax,"","brNDC");
  else leg = new TLegend(leg_xmin,leg_ymin,leg_xmax,leg_ymax,"GGM "+bino+"-like #tilde{#chi}^{0}","brNDC");
  leg->SetFillColor(0);
  leg->SetLineColor(0);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->SetTextSize(0.03);
  if(bino.Contains("mNScan")) leg->AddEntry("NULL","m_{#tilde{q}} = 2500 (GeV/c^{2})","h");
  else leg->AddEntry("NULL","m_{#tilde{#chi}^{0}} = 375 (GeV/c^{2})","h");
  TString jetRequirement = "Without jet requirement";
  if(jet.Contains("1jet")) jetRequirement = "At least 1 jet requirement";
  leg->AddEntry("NULL",jetRequirement,"h");
  leg->AddEntry("NULL","NLO Limits","h");
  leg->AddEntry(curvS[0][0],"Observed","L");
  leg->AddEntry(curvS[0][1],"#pm1#sigma (theory)","L");
  leg->AddEntry(curvS[1][0],"Expected","L");
  leg->AddEntry(curvS[1][1],"#pm1#sigma (theory)","L");
  leg->AddEntry(exp1sigma_aroundExp,"#pm1#sigma (experimental)","F");
  leg->Draw("same");

  TLatex* lat = new TLatex(leg_xmin+0.02,0.87,"CMS Preliminary");
  lat->SetNDC(true);
  lat->SetTextFont(43);
  lat->SetTextSize(30);
  lat->Draw("same");

  TLatex* lat2 = new TLatex(leg_xmin,0.83,"#int #font[12]{L}dt = 4.7fb^{-1}, #sqrt{s} = 7 TeV");
  lat2->SetNDC(true);
  lat2->SetTextFont(43);
  lat2->SetTextSize(24);
  lat2->Draw("same");

  float xv = 0.25;
  float yv = 0.25;
  if(bino.Contains("wino")){
    xv = 0.23;
    yv = 0.23;
  }
  if(bino.Contains("mNScan")){
    xv = 0.2;
    yv = 0.3;
  }
  TLatex* lat3 = new TLatex(xv,yv,"Excluded");
  lat3->SetNDC(true);
  lat3->SetTextFont(52);
  lat3->SetTextSize(0.06);
  lat3->Draw("same");

  TGraph* noRegion = new TGraph(3);
  noRegion->SetPoint(0,TMath::Min(xmin,ymin),TMath::Min(xmin,ymin));
  noRegion->SetPoint(1,xmax,ymin);
  noRegion->SetPoint(2,TMath::Min(xmax,ymax),TMath::Min(xmax,ymax));
  noRegion->SetFillColor(16);

  TLatex* lat4 = new TLatex(0.7,0.25,"#tilde{g} NLSP");
  lat4->SetNDC(true);
  lat4->SetTextSize(0.04);

  if(bino.Contains("mNScan")){
    noRegion->Draw("same f");
    lat4->Draw("same");
  }

  can_excl02->RedrawAxis();


  if(print) {
    can_excl02->Print("",".gif");
    can_excl02->Print("",".pdf");
  }

  fout->cd();
  fout->Write();

  can_acc->Write();
  can_xs->Write();
  can_limit->Write();
  can_excl01->Write();
  can_excl02->Write();

  for(int i=0; i<nlimit; i++){
    for(int j=0; j<nxs-1; j++){
      curv[i][j]->Write();
      curvS[i][j]->Write();
    }
  }


}
Example #10
0
NV_INT32 scribe (NV_INT32 num_cols, NV_INT32 num_rows, NV_FLOAT32 xorig, NV_FLOAT32 yorig, NV_FLOAT32 min_z, NV_FLOAT32 max_z, NV_FLOAT32 *ar,
                 QString shapeName, OPTIONS *options, PFM_OPEN_ARGS open_args)
{
  NV_INT32                index_contour, num_points, i, num_interp, bytes, num_contours = 0;
  NV_FLOAT64              *dcontour_x, *dcontour_y, *dcontour_m, ix[2], iy[2], dx, dy, cell_diag_length, segment_length;
  NV_FLOAT32              level, half_gridx, half_gridy, *contour_x, *contour_y;
  NV_CHAR                 shape_name[512], prj_name[512];
  FILE                    *prj_fp;
  SHPHandle               shp_hnd;
  SHPObject               *shape;
  DBFHandle               dbf_hnd;  


  void contourMinMax (NV_FLOAT32, NV_FLOAT32);
  void contourEmphasis (NV_INT32);
  void contourMaxDensity (NV_INT32);
  void contourMaxPoints (NV_INT32);
  void contourLevels (NV_INT32 numLevels, NV_FLOAT32 *);
  NV_INT32 initContour (NV_FLOAT32, NV_INT32, NV_INT32, NV_FLOAT32 *);
  NV_INT32 getContour (NV_FLOAT32 *, NV_INT32 *, NV_INT32 *, NV_FLOAT32 *, NV_FLOAT32 *);
  void smooth_contour (NV_INT32 num_interp, NV_INT32 *num_pts, NV_FLOAT64 *contour_x, NV_FLOAT64 *contour_y);



  strcpy (shape_name, shapeName.toAscii ());


  if ((shp_hnd = SHPCreate (shape_name, SHPT_ARCM)) == NULL)
    {
      QMessageBox::warning (0, pfmGeotiff::tr ("pfmGeotiff"),
                            pfmGeotiff::tr ("Unable to create ESRI SHP file ") + QDir::toNativeSeparators (shapeName) + 
                            pfmGeotiff::tr ("  The error message returned was:\n\n") +
                            QString (strerror (errno)) + 
                            pfmGeotiff::tr ("\n\nContours will not be generated."));

      return (0);
    }


  //  Making dummy DBF file so Arc won't barf.

  if ((dbf_hnd = DBFCreate (shape_name)) == NULL)
    {
      QMessageBox::warning (0, pfmGeotiff::tr ("pfmGeotiff"),
                            pfmGeotiff::tr ("Unable to create ESRI DBF file ") + QDir::toNativeSeparators (shapeName) + 
                            pfmGeotiff::tr ("  The error message returned was:\n\n") +
                            QString (strerror (errno)) + 
                            pfmGeotiff::tr ("\n\nContours will not be generated."));

      return (0);
    }


  //  Adding a dummy field.

  if (DBFAddField (dbf_hnd, "nada", FTLogical, 1, 0) == -1)
    {
      QMessageBox::warning (0, pfmGeotiff::tr ("pfmGeotiff"), pfmGeotiff::tr ("Error adding field to DBF file."));
      return (0);
    }


  //  Stupid freaking .prj file

  strcpy (prj_name, shapeName.replace (".pfm", ".prj").toAscii ());
  if ((prj_fp = fopen (prj_name, "w")) == NULL)
    {
      QMessageBox::warning (0, pfmGeotiff::tr ("pfmGeotiff"),
                            pfmGeotiff::tr ("Unable to create ESRI PRJ file ") + QDir::toNativeSeparators (QString (prj_name)) + 
                            pfmGeotiff::tr ("  The error message returned was:\n\n") +
                            QString (strerror (errno)) + 
                            pfmGeotiff::tr ("\n\nContours will not be generated."));

      return (0);
    }

  fprintf (prj_fp, "COMPD_CS[\"WGS84 with ellipsoid Z\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]],VERT_CS[\"ellipsoid Z in meters\",VERT_DATUM[\"Ellipsoid\",2002],UNIT[\"metre\",1],AXIS[\"Z\",UP]]]\n");


  //  Check the smoothing factor range and get the number of interpolation points per unsmoothed contour segment

  if (options->smoothing_factor < 0) options->smoothing_factor = 0;
  if (options->smoothing_factor > 10) options->smoothing_factor = 10;


  ix[0] = (xorig + (open_args.head.x_bin_size_degrees * num_cols) * 0.5) / open_args.head.x_bin_size_degrees;
  iy[0] = (yorig + (open_args.head.y_bin_size_degrees * num_rows) * 0.5) / open_args.head.y_bin_size_degrees;
  ix[1] = ix[0] + 1.0;
  iy[1] = iy[0] + 1.0;

  dx = ix[1] - ix[0];
  dy = iy[1] - iy[0];

  cell_diag_length = sqrt (pow (dx, 2) + pow (dy, 2));

  num_interp = 1;

  if (options->smoothing_factor)
    {
      segment_length = DEFAULT_SEGMENT_LENGTH / options->smoothing_factor;

      if (cell_diag_length > segment_length)
        {    
          num_interp = (NV_INT32) ((cell_diag_length / segment_length) + 0.5);
        }
      else
        {
          num_interp = 1;
        }
    }


  //  allocate memory for contour arrays

  if (options->smoothing_factor > 0)
    {
      bytes = (((num_interp * (CONTOUR_POINTS - 1)) + 1) * sizeof (NV_FLOAT64));
    }
  else
    {
      bytes = (CONTOUR_POINTS * sizeof (NV_FLOAT64));
    }

  if ((contour_x = (NV_FLOAT32 *) malloc (bytes / 2)) == NULL)
    {
      perror ("Allocating contour_x in scribe.cpp");
      exit (-1);
    }
  if ((contour_y = (NV_FLOAT32 *) malloc (bytes / 2)) == NULL)
    {
      perror ("Allocating contour_y in scribe.cpp");
      exit (-1);
    }
  if ((dcontour_x = (NV_FLOAT64 *) malloc (bytes)) == NULL)
    {
      perror ("Allocating dcontour_x in scribe.cpp");
      exit (-1);
    }
  if ((dcontour_y = (NV_FLOAT64 *) malloc (bytes)) == NULL)
    {
      perror ("Allocating dcontour_y in scribe.cpp");
      exit (-1);
    }
  if ((dcontour_m = (NV_FLOAT64 *) malloc (bytes)) == NULL)
    {
      perror ("Allocating dcontour_m in scribe.cpp");
      exit (-1);
    }


  //  Set the min and max contours, the index contour interval, the maximum contour density, and the
  //  number of points to be returned by the package.

  contourMinMax (min_z, max_z);
  contourMaxDensity (options->maxd);
  contourMaxPoints (CONTOUR_POINTS);
  contourEmphasis (1);


  //  If the contour interval is set to 0.0 use the user defined levels.
  /*    
  if (options->cint == 0.0)
    {
      contourLevels (options->num_levels, options->contour_levels);
    }
  */


  //  Pass the grid array (arranged 1D) to the contouring package.

  initContour (options->cint, num_rows, num_cols, ar);


  //  Compute half of a grid cell in degrees.

  half_gridx = open_args.head.x_bin_size_degrees * 0.5;
  half_gridy = open_args.head.y_bin_size_degrees * 0.5;


  //  Get the contours from the package until all are saved.

  while (getContour (&level, &index_contour, &num_points, contour_x, contour_y))
    {
      if (level != 0.0) fprintf(stderr,"%s %d %f\n",__FILE__,__LINE__,level);


      if (num_points > 1)
        {
          //  Convert from grid points (returned contours) to position.  Contours are output as elevations, not depths.

          for (i = 0 ; i < num_points ; i++)
            {
              dcontour_x[i] = xorig + (contour_x[i] * open_args.head.x_bin_size_degrees) + half_gridx;
              dcontour_y[i] = yorig + (contour_y[i] * open_args.head.y_bin_size_degrees) + half_gridy;
            }


          //  smooth out the contour.

          if (options->smoothing_factor > 0) smooth_contour (num_interp, &num_points, dcontour_x, dcontour_y);


          for (i = 0 ; i < num_points ; i++) dcontour_m[i] = (NV_FLOAT64) level;


          shape = SHPCreateObject (SHPT_ARCM, -1, 0, NULL, NULL, num_points, dcontour_x, dcontour_y, NULL, dcontour_m);
          SHPWriteObject (shp_hnd, -1, shape);
          SHPDestroyObject (shape);

          DBFWriteLogicalAttribute (dbf_hnd, num_contours, 0, '0');

          num_contours++;
        }
    }


  free (contour_x);
  free (contour_y);
  free (dcontour_x);
  free (dcontour_y);
  free (dcontour_m);


  SHPClose (shp_hnd);
  DBFClose (dbf_hnd);  
  fclose (prj_fp);


  return (num_contours);
}