コード例 #1
0
void Mask::ApplyToRGBImage(TImage* const image, const TColor& color) const
{
  // Using generics, we allow any Color class that has .red(), .green(), and .blue() member functions
  // to be used to specify the color.
  if(image->GetLargestPossibleRegion() != this->GetLargestPossibleRegion())
  {
    std::cerr << "Image and mask must be the same size!" << std::endl
              << "Image region: " << image->GetLargestPossibleRegion() << std::endl
              << "Mask region: " << this->GetLargestPossibleRegion() << std::endl;
    return;
  }

  // Color the hole pixels in the image.
  typename TImage::PixelType holeValue;
  holeValue.SetSize(image->GetNumberOfComponentsPerPixel());
  holeValue.Fill(0);
  if(image->GetNumberOfComponentsPerPixel() >= 3)
  {
    holeValue[0] = color.red();
    holeValue[1] = color.green();
    holeValue[2] = color.blue();
  }

  itk::ImageRegionConstIterator<Mask> maskIterator(this, this->GetLargestPossibleRegion());

  while(!maskIterator.IsAtEnd())
  {
    if(this->IsHole(maskIterator.GetIndex()))
    {
      image->SetPixel(maskIterator.GetIndex(), holeValue);
    }

    ++maskIterator;
  }
}
コード例 #2
0
ファイル: bright_colors.C プロジェクト: alisw/AliRoot
void bright_colors(Float_t value=1)
{
  // Notes:
  // you can store the original colors by creating a clone of
  // (TObjArray*)gROOT->GetListOfColors() and restore the colors by
  // assigning the vector with original values to the list of colors
  // that gROOT handles.

  if (value > 5)
  {
    printf("Value %f too high - maximum is 5.\n", value);
    return;
  }
  value *= 0.1f;

  TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
  TColor    *color  = 0;
  Float_t    r, g, b;
  for (int i = 0; i < colors->GetSize(); ++i)
  {
    if ((color = dynamic_cast<TColor*>(colors->At(i))) != 0)
    {
      color->GetRGB(r, g, b);
      if (r < 0.01 && g < 0.01 && b < 0.01) continue; // skip black
      if (r > 0.95 && g > 0.95 && b > 0.95) continue; // skip white
      r = TMath::Min(r + value, 1.0f);
      g = TMath::Min(g + value, 1.0f);
      b = TMath::Min(b + value, 1.0f);
      color->SetRGB(r, g, b);
    }
  }

  if (gEve)
    gEve->FullRedraw3D();
}
コード例 #3
0
ファイル: TColor.cpp プロジェクト: DynalitykStudio/C-Project
TColor TColor::Grayscale()const
{
	TColor tTemp = TColor(r, g, b, a);
	tTemp.r = (r * 0.2126f) + (g * 0.7152f) + (b * 0.0722f);
	tTemp.g = (r * 0.2126f) + (g * 0.7152f) + (b * 0.0722f);
	tTemp.b = (r * 0.2126f) + (g * 0.7152f) + (b * 0.0722f);
	
	tTemp = tTemp.Clamp();

	return tTemp;
}
コード例 #4
0
ファイル: TColor.cpp プロジェクト: DynalitykStudio/C-Project
TColor TColor::Sepia()const
{
	TColor tTemp = TColor(r, g, b, a);
	tTemp.r = (r * 0.393f) + (g * 0.769f) + (b * 0.189f);
	tTemp.g = (r * 0.349f) + (g * 0.686f) + (b * 0.168f);
	tTemp.b = (r * 0.272f) + (g * 0.534f) + (b * 0.131f);
	
	tTemp = tTemp.Clamp();

	return tTemp;
}
コード例 #5
0
///
/// Copied from TColor::GetColorDark(Int_t n), but customized
/// the 'darkness'.
///
int ColorBuilder::darklightcolor(int n, float scale)
{
	if (n < 0) return -1;

	// Get list of all defined colors
	TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
	Int_t ncolors = colors->GetSize();
	// Get existing color at index n
	TColor *color = 0;
	if (n < ncolors) color = (TColor*)colors->At(n);
	if (!color) return -1;

	// Get the rgb of the the new dark color corresponding to color n
	Float_t r,g,b;
	TColor::HLStoRGB(color->GetHue(), scale*color->GetLight(), color->GetSaturation(), r, g, b);

	// Build the dark color (unless the slot nd is already used)
	Int_t nd = scale<1. ? n+100 : n+150;
	TColor *colord = 0;
	if (nd < ncolors) colord = (TColor*)colors->At(nd);
	if (colord) return nd;
	colord = new TColor(nd,r,g,b);
	colord->SetName(scale<1. ? Form("%s_dark",color->GetName()) : Form("%s_light",color->GetName()));
	colors->AddAtAndExpand(colord,nd);
	return nd;
}
コード例 #6
0
void setStyle_uncertainty(TH1* histogram)
{
  const int color_int = 12;
  const double alpha = 0.40;
  TColor* color = gROOT->GetColor(color_int);
  static int newColor_int = -1;
  static TColor* newColor = 0;
  if ( !newColor ) {
    newColor_int = gROOT->GetListOfColors()->GetSize() + 1;
    newColor = new TColor(newColor_int, color->GetRed(), color->GetGreen(), color->GetBlue(), "", alpha);
  }
  histogram->SetLineColor(newColor_int);
  histogram->SetLineWidth(0);
  histogram->SetFillColor(newColor_int);
  histogram->SetFillStyle(1001);
}
コード例 #7
0
ファイル: tga_io.cpp プロジェクト: bartholomule/panorama
int TImageTga::save (const TImage* pktIMAGE)
{

  TColor     tColor;
  TColor     tPixel;
  ofstream   sFile;
  size_t     zWidth  = pktIMAGE->width();
  size_t     zHeight = pktIMAGE->height();
  Byte*      pbRow   = new Byte [zWidth * 3];

  sFile.open (tFileName.c_str(), ios::binary | ios::out);

  sFile << (Byte) 0;                         // Length of identifier string
  sFile << (Byte) 0;                         // Color map type (0 = no color map)
  sFile << (Byte) 2;                         // Image type (2 = RGB)
  sFile << (Byte) 0;                         // First color map entry (LSB)
  sFile << (Byte) 0;                         //   "     "    "    "   (MSB)
  sFile << (Byte) 0;                         // Entries in color map (LSB)
  sFile << (Byte) 0;                         //    "     "   "    "  (MSB)
  sFile << (Byte) 0;                         // Size of color map entry
  sFile << (Byte) 0;                         // X origin of image (LSB)
  sFile << (Byte) 0;                         // "    "    "   "   (MSB)
  sFile << (Byte) 0;                         // Y origin of image (LSB)
  sFile << (Byte) 0;                         // "    "    "   "   (MSB)
  sFile << (Byte) (zWidth % 256);
  sFile << (Byte) (zWidth / 256);
  sFile << (Byte) (zHeight % 256);
  sFile << (Byte) (zHeight / 256);
  sFile << (Byte) 24;                        // Pixel size (24 bits)
  sFile << (Byte) 0;                         // Attributes (0 = origin in lower left)

  for (int J = (zHeight - 1) ; ( J >= 0 ) ;J--)
  {
    for (size_t I = 0; ( I < zWidth ) ;I++)
    {
      tPixel = pktIMAGE->getPixel (I, J);
      tPixel.clamp();
      tColor = tPixel.convertTo24Bits();

      pbRow [I * 3]     = (Byte) tColor.blue();
      pbRow [I * 3 + 1] = (Byte) tColor.green();
      pbRow [I * 3 + 2] = (Byte) tColor.red();
    }
    sFile.write ((char*)pbRow, zWidth * 3);
  }

  sFile.close();

  delete[] pbRow;
  
  return 0;
  
}  /* save() */
コード例 #8
0
ファイル: triangles.C プロジェクト: bbannier/root-1
void triangles(Int_t ntriangles=50) {
  TCanvas *c1 = new TCanvas("c1","triangles",10,10,700,700);
  TRandom r;
  Double_t dx = 0.2; Double_t dy = 0.2;
  Int_t ncolors = gStyle->GetNumberOfColors();
  Double_t x[4],y[4];
  TColor *c;
  Int_t ci;
  for (Int_t i=0;i<ntriangles;i++) {
     x[0] = r.Uniform(.05,.95); y[0] = r.Uniform(.05,.95);
     x[1] = x[0] + dx*r.Rndm(); y[1] = y[0] + dy*r.Rndm();
     x[2] = x[1] - dx*r.Rndm(); y[2] = y[1] - dy*r.Rndm();
     x[3] = x[0];               y[3] = y[0];
     TPolyLine *pl = new TPolyLine(4,x,y);
     pl->SetUniqueID(i);
     ci = ncolors*r.Rndm();
     c  = gROOT->GetColor(TColor::GetColorPalette(ci));
     c->SetAlpha(r.Rndm());
     pl->SetFillColor(ci);
     pl->Draw("f");
  }
  c1->AddExec("ex","TriangleClicked()");
}
コード例 #9
0
ファイル: r2iv_1.C プロジェクト: star-bnl/star-soft
   void ShapeHeader(void) {
      TVolumePosition *p =  (*GlobalIter)[GlobalIter->GetDepth()];

      Float_t ObjectX = p->GetX();
      Float_t ObjectY = p->GetY();
      Float_t ObjectZ = p->GetZ();
      Double_t* ObjectMatrix = p->GetMatrix()->GetMatrix() ;

      fprintf(
         TIVFile::File,
         "\tMatrixTransform { \n"
         "\t    matrix %f\t%f\t%f\t%f \n" 
         "\t           %f\t%f\t%f\t%f \n"
         "\t           %f\t%f\t%f\t%f \n"
         "\t           %f\t%f\t%f\t%f \n"
         "\t}\n\n",
         ObjectMatrix[0], ObjectMatrix[1], ObjectMatrix[2], 0,
         ObjectMatrix[3], ObjectMatrix[4], ObjectMatrix[5], 0,
         ObjectMatrix[6], ObjectMatrix[7], ObjectMatrix[8], 0,
         ObjectX, ObjectY, ObjectZ, 1
         ); 

      Color_t ColorOfObject = Volume->GetLineColor();
      TColor *colorObject = gROOT->GetColor(ColorOfObject);
      Float_t Objectred, Objectgreen, Objectblue;
      colorObject->GetRGB(Objectred, Objectgreen, Objectblue); 


      fprintf(
         TIVFile::File,
         "\tMaterial {\n"
         "\t    ambientColor %f %f %f \n"
         "\t}\n", 
         Objectred, Objectgreen, Objectblue 
         ); 
   }
コード例 #10
0
ファイル: TOverlay.cpp プロジェクト: bdbdonp/tubras
 //-----------------------------------------------------------------------
 //                          s e t A l p h a 
 //-----------------------------------------------------------------------
 void TOverlay::setAlpha(float alpha)
 {
     TColor c = m_color;
     c.setAlpha((u32)(255.f * alpha));
     setColor(c);
 }
コード例 #11
0
ファイル: Z0AccEff.C プロジェクト: CmsHI/CVS_CmsHi
void Z0AccEff(int isData = 2, int yieldInt = 1, int iSpec = 3, int Weight =1)
{
  ////////  definitions of Switches   ///////////
  //  isData = 1 for Data
  //  isData = 2 for Simulation
  
    
  // iSpec = 1  pT spectra
  // iSpec = 2  Y spectra
  // iSpec = 3  Centrality Spectra
  
  //Weight = 1 for weighted histo
  //weight = 0  for non weighted histo



  ////////////////////////////////////////////////////////////
  gStyle->SetOptStat(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0000); 

  // Fit ranges
  float mass_low, mass_high, mlow, mhigh;
  int nrebin;
  bool isLog, isFit;
  double MassZ0, WidthZ0;

  // High Mass range
  MassZ0 = 91.1876; WidthZ0 = 2.4952;
  mass_low = 60; mass_high = 120;  // Fit ranges Glb Glb
  //mass_low = 40; mass_high = 140;  // Fit ranges STA
  mlow = 0.0; mhigh = 200.0; nrebin = 80; isLog =0; isFit = 0; // draw ranges
  
  int whis = 1; // 1 for full all eta, 2 for barrel  //4 for trigger matched PAT
  
  //file one is good file

  TFile *fil1, *fil2;

  if (isData == 2) fil2 = new TFile("Z0_DataMixPt50_PatDiMuonPlots_All11Dec.root");
  //if (isData == 2) fil2 = new TFile("ReReco_DM_DiMuonPlot_All16Dec.root");
  if (isData == 2)  fil1 = new TFile("Z0HydPt50_PatDiMuonPlots_AllWOSel12Dec.root");

  // Pt bin sizes
  int Nptbin=1;
  double pt_bound[100] = {0};
  
  if(iSpec == 1) { 
    Nptbin = 3;
    pt_bound[0] = 0.0; pt_bound[1] = 6.0;
    pt_bound[2] = 12.0; pt_bound[3] = 100.0;
    
    if(isData == 2) {
      Nptbin = 25;
      // pt_bound[100] = {0.0,100.0,12.0,100.0};
      pt_bound[0] = 0;
      pt_bound[1] = 2;
      pt_bound[2] = 4;
      pt_bound[3] = 6;
      pt_bound[4] = 8;
      pt_bound[5] = 10;
      pt_bound[6] = 12;
      pt_bound[7] = 14;
      pt_bound[8] = 16;
      pt_bound[9] = 18;
      pt_bound[10] = 20;
      pt_bound[11] = 22;
      pt_bound[12] = 24;
      pt_bound[13] = 26;
      pt_bound[14] = 28;
      pt_bound[15] = 30;
      pt_bound[16] = 32;
      pt_bound[17] = 34;
      pt_bound[18] = 36;
      pt_bound[19] = 38;
      pt_bound[20] = 40;
      pt_bound[21] = 42;
      pt_bound[22] = 44;
      pt_bound[23] = 46;
      pt_bound[24] = 48;
      pt_bound[25] = 50;
    }
  }
  
  // Y bin sizes
  if(iSpec == 2) {
    Nptbin = 10;
    // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; 
    // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; 
    // pt_bound[100] = {-2.4,-2.1,-1.6,-1.1,-0.6,0,0.6,1.1,1.6,2.1,2.4}; 
    pt_bound[0] = -2.4; 
    pt_bound[1] = -2.1; 
    pt_bound[2] = -1.6; 
    pt_bound[3] = -1.1; 
    pt_bound[4] = -0.6; 
    pt_bound[5] =  0.0; 
    pt_bound[6] = 0.6; 
    pt_bound[7] = 1.1; 
    pt_bound[8] = 1.6; 
    pt_bound[9] = 2.1; 
    pt_bound[10] = 2.4; 

  }
  
  if(iSpec == 3) {
    if(isData == 2) { 
      Nptbin = 9;
      pt_bound[0] = 0.0;
      pt_bound[1] = 4.0;
      pt_bound[2] = 8.0;
      pt_bound[3] = 12.0;
      pt_bound[4] = 16.0;
      pt_bound[5] = 20.0;
      pt_bound[6] = 24.0;
      pt_bound[7] = 28.0;
      pt_bound[8] = 32.0;
      pt_bound[9] = 40.0;
    }
  }
  
  double PT[100], DelPT[100], mom_err[100];
  for (Int_t ih = 0; ih < Nptbin; ih++) {
    PT[ih] = (pt_bound[ih] + pt_bound[ih+1])/2.0;
    DelPT[ih] = pt_bound[ih+1] - pt_bound[ih];
    mom_err[ih] = DelPT[ih]/2.0;
  }
  
  float gen_pt[100], gen_ptError[100];
  float gen_ptS[100], gen_ptErrorS[100];
  
  if(isData==2){

    TH2D *genMass_1, *genMassS_1;

    if (iSpec == 1 &&  Weight==1 ) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPtW");
    if (iSpec == 2 &&  Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsYW");
    if (iSpec == 3 &&  Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCenW");
    
    if (iSpec == 1 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPtW");
    if (iSpec == 2 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsYW");
    if (iSpec == 3 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCenW");
    
    if (iSpec == 1 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPt");
    if (iSpec == 2 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsY");
    if (iSpec == 3 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCen");


    if (iSpec == 1 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPt");
    if (iSpec == 2 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsY");
    if (iSpec == 3 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCen");

    TH1D *ptaxis = (TH1D*)genMass_1->ProjectionY("ptaxis");
    
    for (Int_t ih = 0; ih < Nptbin; ih++) {
      cout<<pt_bound[ih]<<"  "<<pt_bound[ih+1]<<endl;
      int pt_bin1 = ptaxis->FindBin(pt_bound[ih]+0.0000001);
      int pt_bin2 = ptaxis->FindBin(pt_bound[ih+1]+0.0000001);
      
      cout<< pt_bin1<<"  "<< pt_bin2<<endl; 
      TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", pt_bin1, pt_bin2-1);
      TH1D * genMassVsPtS = (TH1D*)genMassS_1->ProjectionX("genMassVsPtS", pt_bin1, pt_bin2-1);
      
      //does not work with weight
      //gen_pt[ih] = genMassVsPt->GetEntries();
      
      double genError,genErrorS;
      gen_pt[ih] = genMassVsPt->IntegralAndError(1,8000,genError);
      gen_ptError[ih]= genError;
      
      gen_ptS[ih] = genMassVsPtS->IntegralAndError(1,8000,genErrorS);
      gen_ptErrorS[ih]= genErrorS;
      
      cout<<" gen entries : "<< gen_pt[ih]<<endl;
      cout<<"genErro "<<genError<<"  "<< gen_ptError[ih]<<endl<<endl;
    }
  }
  
  // Efficiency
  float Eff_cat_1[100]; 
  float Eff_catS_1[100]; 
  
  float errEff_cat_1[100];
  float errEff_catS_1[100];
  
  float errEff_cat_S1[100], errEff_cat_S2[100];
  float errEff_catS_S1[100], errEff_catS_S2[100];
  
  char *Xname[100] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"};
  
  double yld_cat_1[100];
  double yld_catS_1[100];
  double cyld_cat_1[100];
  double cyld_catS_1[100];
  double eyld_cat_1[100];
  double eyld_catS_1[100];
  double ceyld_cat_1[100], ceyld_catS_1[100];

  char namePt_1[500];
  char namePt_1S[500];
  //char namePt_1B[500];
  char text[100];
  
  ///// Write the spectra 
  char fspectra[500];
  sprintf(fspectra,"fileSpecta%d.root", yieldInt);
  TFile *fileSpectra = new TFile(fspectra, "recreate");

  ///////////////////////////////////////////////////////////////////////
  // Category _1 
  TLegend *lcat_1;
  lcat_1 = new TLegend(.1, .82, .50, .93);
  lcat_1->SetName("lcat_1");
  lcat_1->SetBorderSize(0);
  lcat_1->SetFillStyle(0);
  lcat_1->SetFillColor(0);
  lcat_1->SetTextSize(0.032);
  //lcat_1->AddEntry(RBWPOL," CMS Preliminary", " ");
  //lcat_1->AddEntry(RBWPOL," PbPb #sqrt{s_{NN}} = 2.76 TeV ", " ");
  
  TLegend *legend_1[100];
  for(int i=0; i<100; i++) { 
    if(isFit) legend_1[i] = new TLegend(.62, .52, .91, 0.93 );
    if(!isFit) legend_1[i] = new TLegend(.62, .68, .91, 0.93 );
    legend_1[i]->SetBorderSize(0);
    legend_1[i]->SetFillStyle(0);
    legend_1[i]->SetFillColor(0);
    legend_1[i]->SetTextSize(0.032);
  }
  
  //for no cut
  //if(whis == 1 && iSpec == 1 ) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("dimu");
  //if(whis == 2 && iSpec == 1) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtBRL");
  //if(whis == 4 && iSpec == 1 ) {
    //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATInvMassVsPt");
    //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATSTAInvMassVsPt");
  //}



  TH2D *Z0Mass_1, *Z0Mass_1S;

  //with weight

  if(iSpec == 1 &&  Weight==1 ) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtW");
  if(iSpec == 2 &&  Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsYW");
  if(iSpec == 3 &&  Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCenW");


  //without weight
  if(iSpec == 1  &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPt");
  if(iSpec == 2 &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsY");
  if(iSpec == 3 &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCen");
      
  //with weight fil2
  if(iSpec == 1  &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPtW");
  if(iSpec == 2 &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsYW");
  if(iSpec == 3 &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCenW");

  //without weight fil2
  if(iSpec == 1 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPt");
  if(iSpec == 2 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsY");
  if(iSpec == 3 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCen");
  
  TH1D *service = (TH1D*)Z0Mass_1->ProjectionY("service");
  int pt_bin_bound[100];
  TH1D *dimuonsGlobalInvMassVsPt[100],  *dimuonsGlobalInvMassVsPtS[100];
  
  TCanvas *CanvPt_1 = new TCanvas("CanvPt_1"," Z0 Yield Vs. Pt ", 40,40,1000,700);
  if (Nptbin == 2)  CanvPt_1->Divide(2,1);
  if (Nptbin == 3 || Nptbin == 4)  CanvPt_1->Divide(2,2);
  if (Nptbin == 5 || Nptbin == 6)  CanvPt_1->Divide(3,2);
  if (Nptbin == 9 || Nptbin == 10)  CanvPt_1->Divide(5,2);
  cout << endl << Xname[iSpec] << "    Yield      Mass (GeV)    Width (GeV)    GauWidth    chi2/ndf " << endl << endl; 
  //ih loop
  for (Int_t ih = 0; ih < Nptbin; ih++) 
    {
      CanvPt_1->cd(ih+1);
      gPad->SetTickx();
      gPad->SetTicky();
      
      // Project 1 D 
      pt_bin_bound[ih] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih]+0.0000001);
      pt_bin_bound[ih+1] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih+1]-0.0000001);
      sprintf(namePt_1,"Z0_1_pt_%d",ih);
      sprintf(namePt_1S,"Z0_1S_pt_%d",ih);
      
      //printf(namePt_1,"Z0_1_pt_%d",ih);
      //cout<<endl<<endl;
      //continue;
      
      dimuonsGlobalInvMassVsPt[ih] = (TH1D*)Z0Mass_1->ProjectionX(namePt_1, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1, "e");
      dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)Z0Mass_1S->ProjectionX(namePt_1S, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1,"e");
      if(iSpec == 1 || iSpec == 2) {sprintf(text," %s [%.1f, %.1f]", Xname[iSpec], service->GetBinLowEdge(pt_bin_bound[ih]), 
					    service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1]));}
      if(iSpec == 3) {sprintf(text," %s [%.1f, %.1f] %s", Xname[iSpec], 2.5*service->GetBinLowEdge(pt_bin_bound[ih]), 
			      2.5*(service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1])), "%");}
      
      dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin);
      dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin);
      
      float m_low = 60.0;
      float m_high = 120.0;
      
      TAxis *axs   = dimuonsGlobalInvMassVsPt[ih]->GetXaxis();
      int binlow = axs->FindBin(m_low);
      int binhi  = axs->FindBin(m_high);
      //      Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin());
      //    Float_t int_sig = 0.0;
      //for(Int_t bin = binlow; bin<=binhi;bin++) {
      //int_sig+ = dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);
      //}   
      double recerror,recerrorS;
      //double yld;
      double yld_1 = dimuonsGlobalInvMassVsPt[ih]->IntegralAndError(binlow, binhi, recerror);
      double yldS_1 = dimuonsGlobalInvMassVsPtS[ih]->IntegralAndError(binlow, binhi, recerrorS); 
      eyld_cat_1[ih] =recerror;
      eyld_catS_1[ih] =recerrorS;
      cout<< "yld " << yld_1 <<"  eyld_cat_1[ih]  "<< eyld_cat_1[ih]<<" rec error "<<recerror<<endl;
      
      yld_cat_1[ih] = yld_1;
      yld_catS_1[ih] = yldS_1;
      
      if(isLog) gPad->SetLogy(1);
      TColor *pal = new TColor();
      Int_t kblue = pal->GetColor(9,0,200);
      //      Int_t korange  = pal->GetColor(101, 42,  0);
      
      dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21);
      dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue);
      dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue);
      dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})");
      dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("Events/(2 GeV/c^{2})");
      dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(mlow,mhigh);
      dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPL");
      // fil2
      dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8);
      dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46);
      dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46);
      //****** dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame");
      //RBWPOL->SetLineColor(kblue);
      //backfun_1->SetLineColor(46);
      //backfun_1->SetLineWidth(1);
      //if(isFit) backfun_1->Draw("same");
      lcat_1->Draw("same"); 
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],"Global-Global", " ");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |y| < 2.4 ", "");  
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, "");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Opposite Charge ", "LP");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Same Charge ", "LP");
      char label_1[512];
      //      char label_2[512], label_3[512], label_4[512];
      sprintf(label_1, "N=%1.2f #pm %1.2f ", yld_cat_1[ih], eyld_cat_1[ih]);
      //    sprintf(label_1, "N_{Z^{0}} = 27");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_1, "");
    }//ih loop
  cout << endl << endl;
  CanvPt_1->Print("Pt_Z0MassCat_1.png");
  
  TGraphErrors *Z0pt_cat_1 = new TGraphErrors(Nptbin, PT, yld_cat_1, mom_err, eyld_cat_1);
  Z0pt_cat_1->SetMarkerStyle(20);
  Z0pt_cat_1->SetMarkerColor(2);
  Z0pt_cat_1->GetXaxis()->SetTitle(Xname[iSpec]);
  Z0pt_cat_1->GetYaxis()->SetTitle("counts");

  new TCanvas;
  Z0pt_cat_1->SetMinimum(0.0);
  Z0pt_cat_1->SetName("Z0pt_cat_1");
  Z0pt_cat_1->Draw("AP");
  lcat_1->Draw("same"); 
  gPad->Print("Pt_Z0YieldCat_1.png");
  cout << endl << endl;
  Z0pt_cat_1->Write();
  lcat_1->Write();
  
  // Efficiency correction
  if(isData==2) 
    {
       ofstream fileout("correction.txt");
       cout << Xname[iSpec] << "   Eff_cat_1  " << endl;
       
       for (Int_t ih = 0; ih < Nptbin; ih++) {
      	//cout<<"gen_pt[ih];  "<<gen_pt[ih]<<endl;
	 Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih]; 
	 Eff_catS_1[ih] = yld_catS_1[ih]/gen_ptS[ih]; 
	 //eyld_cat_1[ih];
	 //gen_ptError[ih];
	 //cout<<endl<<endl<<endl;
	//cout<<"Eff_cat_1[ih] "<<Eff_cat_1[ih]<<endl;
	//cout<<"yld_cat_1[ih] "<< yld_cat_1[ih] <<endl;
	//cout<<"eyld_cat_1[ih] "<<eyld_cat_1[ih] <<endl;
	//cout<<"gen_pt[ih]    "<< gen_pt[ih] <<endl;
	//cout<<"gen_ptError[ih] "<< gen_ptError[ih]<<endl;
	 //Error for first graph
	 double errEff_cat_S1_1[100]={0},errEff_cat_S1_2[100]={0};
	 double errEff_cat_S2_1[100]={0},errEff_cat_S2_2[100]={0};
	 errEff_cat_S1_1[ih]= ( (Eff_cat_1[ih] * Eff_cat_1[ih]) /(gen_pt[ih] * gen_pt[ih]) );
	 errEff_cat_S1_2[ih]= (gen_ptError[ih] * gen_ptError[ih] ) - ( eyld_cat_1[ih] * eyld_cat_1[ih] );
	 errEff_cat_S1[ih]= (errEff_cat_S1_1[ih] * errEff_cat_S1_2[ih]);
	 //cout<<" errEff_cat_S1_1[ih] "<<	errEff_cat_S1_1[ih]<< " errEff_cat_S1_2[ih] "<<errEff_cat_S1_2[ih]<<endl;
	 errEff_cat_S2_1[ih]= ( (1 - Eff_cat_1[ih])* (1 - Eff_cat_1[ih]) ) / ( gen_pt[ih] * gen_pt[ih]);
	 errEff_cat_S2_2[ih]= (eyld_cat_1[ih] * eyld_cat_1[ih]);
	 errEff_cat_S2[ih]=errEff_cat_S2_1[ih]*errEff_cat_S2_2[ih];
	 //cout<<" errEff_cat_S2_1[ih] "<<	errEff_cat_S2_1[ih]<< " errEff_cat_S2_2[ih] "<<errEff_cat_S2_2[ih]<<endl;
	 //cout<<"errEff_cat_S1[ih]    "<<errEff_cat_S1[ih]<< " errEff_cat_S2[ih]   "<< errEff_cat_S2[ih]<<endl;	
	 errEff_cat_1[ih]=sqrt(errEff_cat_S1[ih] + errEff_cat_S2[ih]);
	 
	 //Error for second graph
	 double errEff_catS_S1_1[100]={0},errEff_catS_S1_2[100]={0};
	 double errEff_catS_S2_1[100]={0},errEff_catS_S2_2[100]={0};
	 errEff_catS_S1_1[ih]= ( (Eff_catS_1[ih] * Eff_catS_1[ih]) /(gen_ptS[ih] * gen_ptS[ih]) );
	 errEff_catS_S1_2[ih]= (gen_ptErrorS[ih] * gen_ptErrorS[ih] ) - (eyld_catS_1[ih] * eyld_catS_1[ih] );
	 errEff_catS_S1[ih]= (errEff_catS_S1_1[ih] * errEff_catS_S1_2[ih]);
	 errEff_catS_S2_1[ih]= ( (1 - Eff_catS_1[ih])* (1 - Eff_catS_1[ih]) ) / ( gen_ptS[ih] * gen_ptS[ih]);
	 errEff_catS_S2_2[ih]= (eyld_catS_1[ih] * eyld_catS_1[ih]);
	 errEff_catS_S2[ih]= errEff_catS_S2_1[ih]*errEff_catS_S2_2[ih];
	 errEff_catS_1[ih]=sqrt(errEff_catS_S1[ih] + errEff_catS_S2[ih]);
	 //Error for no weight
	 //errEff_cat_1[ih] =((Eff_cat_1[ih]*(1- Eff_cat_1[ih]))/gen_pt[ih]);
	 //Prashant error
	 //errEff_cat_1[ih] = eyld_cat_1[ih]/gen_pt[ih]; 
	 fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << errEff_cat_1[ih] << endl; 
	 cout <<"    " << PT[ih] <<"    "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl;
	 cyld_cat_1[ih] = Eff_cat_1[ih];
	 ceyld_cat_1[ih] = errEff_cat_1[ih];
	 cyld_catS_1[ih] = Eff_catS_1[ih];
	 ceyld_catS_1[ih] = errEff_catS_1[ih];
       }
    }
  
  TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(Nptbin, PT, cyld_cat_1, mom_err, ceyld_cat_1);
  Z0ptC_cat_1->SetMarkerStyle(20);
  Z0ptC_cat_1->SetMarkerColor(2);
  Z0ptC_cat_1->GetXaxis()->SetTitle(Xname[iSpec]);
  Z0ptC_cat_1->GetYaxis()->SetTitle("Acc #times Eff");
  Z0ptC_cat_1->GetYaxis()->SetRangeUser(0,1.0);

  TGraphErrors *Z0ptC_catS_1 = new TGraphErrors(Nptbin, PT, cyld_catS_1, mom_err, ceyld_catS_1);
  Z0ptC_catS_1->SetMarkerStyle(8);
  Z0ptC_catS_1->SetMarkerColor(1);
  Z0ptC_catS_1->GetYaxis()->SetRangeUser(0,0.8);
  
  TLegend *legend_GP = new TLegend( 0.59,0.79,0.88,0.89);
  legend_GP->SetBorderSize(0);
  legend_GP->SetFillStyle(0);
  legend_GP->SetFillColor(0);
  legend_GP->SetTextSize(0.032);
  //legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB HI Data ", "");
  legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB Hydjet ", "");
  new TCanvas;
  Z0ptC_cat_1->SetMinimum(0.0);
  Z0ptC_cat_1->Draw("AP");
  //Z0ptC_catS_1->Draw("sameP");
  lcat_1->Draw("same"); 
  legend_GP->Draw("same");
  cout << endl << endl;
  Z0ptC_cat_1->Write();
}
コード例 #12
0
bool
TListViewCtrl::SetBkColor(const TColor& c)
{
  PRECONDITION(GetHandle());
  return ToBool(SendMessage(LVM_SETBKCOLOR, 0, TParam2(c.GetValue())));
}
コード例 #13
0
ファイル: Malla.cpp プロジェクト: SalamiCo/IGrP7
void Malla::dibuja(bool rellena, bool normales){
	glPushMatrix();
	glMatrixMode(GL_MODELVIEW);

	glRotated(angleX, 1,0,0);
	glRotated(angleY, 0,1,0);
	glRotated(angleZ, 0,0,1);

	glEnable(GL_TEXTURE_2D);

	for(int i = 0; i < numCaras; i++){
		glColor3f(0.f, 0.f, 1.f);
		glLineWidth(1.0);

		if(rellena)
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		else
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

		glBegin(GL_POLYGON);

		//Color marron
		if(i < 15){
			TColor colorVerde = TColor((GLfloat)0.0, (GLfloat)0.5, (GLfloat)0.0);
			glColor3f(colorVerde.getRed(), colorVerde.getGreen(), colorVerde.getBlue());
		} else {
			TColor colorMarron = TColor((GLfloat)0.55, (GLfloat)0.27, (GLfloat)0.07);
			glColor3f(colorMarron.getRed(), colorMarron.getGreen(), colorMarron.getBlue());
		}

		for(int j = 0; j < cara[i]->getNumVertices(); j++){
			int iN = cara[i]->getIndiceNormalK(j);
			int iV = cara[i]->getIndiceVerticeK(j);
			glNormal3f(normal[iN]->getX(), normal[iN]->getY(), normal[iN]->getZ());

			//Textura
			if(i >= 15){
				t.bindTexture(0);
				glTexCoord3f(vertice[iV]->getX(), vertice[iV]->getY(), vertice[iV]->getZ());
			} else {
				t.bindTexture(1);
				glTexCoord3f(vertice[iV]->getX(), vertice[iV]->getY(), vertice[iV]->getZ());
			}

			glVertex3f(vertice[iV]->getX(), vertice[iV]->getY(), vertice[iV]->getZ());
		}
		glEnd();

		if(normales){
			//Pintar las normales
			glColor3f(1.0, 0.0, 0.0);
			glBegin(GL_LINES);
			for(int j = 0; j < cara[i]->getNumVertices(); j++){
				int iN = cara[i]->getIndiceNormalK(j);
				int iV = cara[i]->getIndiceVerticeK(j);
				glVertex3f(vertice[iV]->getX(), vertice[iV]->getY(), vertice[iV]->getZ());
				glVertex3f(vertice[iV]->getX() + normal[iN]->getX(), vertice[iV]->getY() + normal[iN]->getY(), vertice[iV]->getZ() + normal[iN]->getZ());
			}
			glEnd();
		}
	}
	glDisable(GL_TEXTURE_2D);

	glPopMatrix();
}
コード例 #14
0
ファイル: dileptonMassFit.C プロジェクト: rchudasa/CVS_CmsHi
void dileptonMassFit(const char* pInFileName="PanchoSkim4JanAll.root",
                     // "PromtRecoV2V3V3H_DiMuonPlot_TightSTACutsAll15Dec.root",
                     // "Z0_DataMixPt50_PatDiMuonPlots_NewCutAll14Dec.root",
                     const char* pHistNameOpCh="diMuonsGlobalInvMassVsPt",//diMuonsGlobalInvMassVsPtW",
                     const char* pHistNameSameCh="diMuonsGlobalSameChargeInvMassVsPt",
                     const char* pSpectra="pt",  // pt, y, centr
                     bool doMc=false,
                     int nFitFunction = 3,
                     int getYield = 1)
{
    gROOT->Macro("setStyle.C+");

    //gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+");
    char szBuf[256];

    ////////  definitions of Switches   ///////////
    //  nFitFunction  = 1  RBW + Pol2
    //  nFitFunction  = 2  Gaus + Pol2
    //  nFitFunction  = 3  RBWGaus + Pol2

    //  getYield = 1  Bin counting
    //  getYield = 2  Integral
    ////////////////////////////////////////////////////////////

    // make some choices
    float MassZ0         = 91.1876;
    float WidthZ0        = 2.4952;
    float massFit_low    = 60;
    float massFit_high   = 120;   // Fit ranges
    float massDraw_low   = 30.0;  // 0.
    float massDraw_high  = 130.0; // 200/
    int nrebin           = 80;
    bool isLog           = 0;
    bool isFit           = 1; // draw ranges

    float massCount_low  = 60.0; //78.0
    float massCount_high = 120.0; //102.0

    //___________________________________________________________________________________
    // ------- Open input file
    sprintf(szBuf,"%s",pInFileName);
    TString inFileName(szBuf);
    TFile *pfInFile = new TFile(inFileName);

    // ------- get histograms:
    sprintf(szBuf,"%s",pHistNameOpCh);
    TH2D *phDimuMass_1  = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1");

    sprintf(szBuf,"%s",pHistNameSameCh);
    TH2D *phDimuMass_1S = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1S");

    phDimuMass_1->SetDirectory(0);
    phDimuMass_1S->SetDirectory(0);

    // Open pp data file

    TFile *ppFile = new TFile("Zmumu_40-200_35pb.root");
    TH1F *Zmumu  = (TH1F*)ppFile->Get("hdata");


    //___________________________________________________________________________________
    // bins definition:
    const char* Xname[] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"};
    bool doPt   = false;
    bool doY    =  false;
    bool doCent = false;

    int GenRange, nBins;
    double binEdge[10];
    char* label;
    sprintf(szBuf,"%s",pSpectra);
    TString wichSpectra(szBuf);

    if ( wichSpectra.CompareTo("pt") == 0) {
        doPt               = true;
        label              = (char*)Xname[1];
        GenRange           = 20;
        nBins              = 1;
        binEdge[0] = 0.0;
        binEdge[1]= 100.0;
        //    double binEdge[10] = {0.0, 10., 20., 100.0};
        if(doMc) {
            nBins              = 1;
            binEdge[0] = 0.0;
            binEdge[1]= 50.0;
            //	  nBins          = 7;
            // binEdge[0] =  0.0;  binEdge[1] =  2.0;  binEdge[2] =  4.0;  binEdge[3] = 8.0;
            //binEdge[4] = 12.0;  binEdge[5] = 16.0;  binEdge[6] = 22.0;  binEdge[7] = 50.0;
        }
    } else {
        if ( wichSpectra.CompareTo("y") == 0) {
            doY              = true;
            label            = (char*)Xname[2];
            nBins            = 3;
            GenRange         = 4.8;
            binEdge[0] = -2.4;
            binEdge[1] = -0.8;
            binEdge[2] =  0.8;
            binEdge[3] =  2.4;
        } else {
            if ( wichSpectra.CompareTo("cent") == 0) 	{
                doCent           = true;
                label            = (char*)Xname[3];
                nBins            = 4;
                GenRange         = 40;
                binEdge[0] = 0.;
                binEdge[1] =   4;
                binEdge[2] = 8.;
                binEdge[3] =  16;
                binEdge[4] =  40;
            } else {
                cout<<"Don't know what you want to do!!!!"<<endl;
                return;
            }
        }
    }

    double PT[10], DelPT[10], mom_err[100];
    for (Int_t ih = 0; ih < nBins; ih++)  {
        PT[ih]      = (binEdge[ih] + binEdge[ih+1])/2.0;
        DelPT[ih]   = binEdge[ih+1] - binEdge[ih];
        mom_err[ih] = DelPT[ih]/2.0;
    }

    //___________________________________________________________________________________

    double gen_pt[10];
    double egen_pt[10];

    TCanvas *pcPt_1 = new TCanvas("pcPt_1"," Z0 Yield Vs. Pt ", 40,40,600,600);

    if(doMc) {
        pcPt_1->Divide(nBins,2);

        //TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPt");
        TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPtW");
        TH1D *ptaxis    = (TH1D*)genMass_1->ProjectionY("ptaxis");

        for (Int_t ih = 0; ih < nBins; ih++) {
            pcPt_1->cd(ih+nBins+1);

            int bin1 = ptaxis->FindBin(binEdge[ih]+0.0000001);
            int bin2 = ptaxis->FindBin(binEdge[ih+1]+0.0000001);

            TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", bin1, bin2-1);
            genMassVsPt->Draw("EPL");
            pcPt_1->Update();

            TAxis *axs        = genMassVsPt->GetXaxis();
            int binlow        = axs->FindBin(massCount_low);
            int binhi         = axs->FindBin(massCount_high);

            double int_sig_gen;
            double int_sig_gen_sqr;
            for(Int_t bin = binlow; bin<=binhi; bin++) {
                //    cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sigpow_gen <<"+="<< "bin" << bin << " content"<<genMassVsPt->GetBinContent(bin)<<endl;
                int_sig_gen += genMassVsPt->GetBinContent(bin);
                int_sig_gen_sqr += pow(genMassVsPt->GetBinContent(bin),2);
            }


            gen_pt[ih] = int_sig_gen;//genMassVsPt->GetEntries();
            cout<<" gen entries : "<< gen_pt[ih]<<endl;
            egen_pt[ih] =int_sig_gen_sqr;

        }
    }
    else {
        if (nBins == 2)  pcPt_1->Divide(2,1);
        if (nBins == 3 || nBins == 4)  pcPt_1->Divide(2,2);
        if (nBins == 5 || nBins == 6)  pcPt_1->Divide(3,2);

    }


    //___________________________________________________________________________________
    // Fit Function
    //  const char *name_fit[] = {"  ", "RBWPol1", "GausPol1", "RBWGausPol2"};
    int nParam[]           = {0,6,6,7};
    int nFitParam          = nParam[nFitFunction];
    TF1 *RBWPOL=0;
    if(nFitFunction == 1) RBWPOL = new TF1("RBWPOL", RBWPol2,     0, 200, nFitParam);
    if(nFitFunction == 2) RBWPOL = new TF1("RBWPOL", GausPol2,    0, 200, nFitParam);
    if(nFitFunction == 3) RBWPOL = new TF1("RBWPOL", RBWGausPol2, 0, 200, nFitParam);
    TF1 *EXP               = new TF1("EXP", Exp, 0, 200, 2);

    RBWPOL->SetLineWidth(1);
    RBWPOL->SetParameter(1, MassZ0);
    RBWPOL->SetParameter(2, WidthZ0);

    RBWPOL->SetParLimits(1, 0.9*MassZ0, 1.1*MassZ0);
    RBWPOL->SetParLimits(2, 0.1*WidthZ0, 5.0*WidthZ0);

    if(nFitFunction  == 1 || nFitFunction  == 2) RBWPOL->FixParameter(5, 0);
    if(nFitFunction  == 3 || nFitFunction  == 4)  {
        RBWPOL->SetParameter(3, WidthZ0);
        RBWPOL->SetParLimits(3, 0.1, 20);
        RBWPOL->FixParameter(2, WidthZ0);

        RBWPOL->FixParameter(4, 0);   // for no bkg
        RBWPOL->FixParameter(5, 0);   // for no bkg
        RBWPOL->FixParameter(6, 0);
    }


    //___________________________________________________________________________________
    // Efficiency

    double yld_cat_1[10], cyld_cat_1[10], eyld_cat_1[10], ceyld_cat_1[10];
    double Eff_cat_1[10], errEff_cat_1[10];


    ///// Write the spectra
    sprintf(szBuf,"fileSpecta%d.root", getYield);
    //  TFile *fileSpectra = new TFile(szBuf, "recreate");


    //___________________________________________________________________________________
    // Drawing
    // Category _1
    TLegend *pLegCategory = new TLegend(.66, .74, .92, .94);
    //  pLegCategory = new TLegend(.1, .82, .50, .93);
    pLegCategory->SetBorderSize(0);
    pLegCategory->SetFillStyle(0);
    pLegCategory->SetFillColor(0);
    pLegCategory->SetTextSize(0.03);
    //  pLegCategory->AddEntry(RBWPOL," CMS Preliminary", " ");

    pLegCategory->AddEntry(RBWPOL," CMS Pb+Pb ", " ");
    pLegCategory->AddEntry(RBWPOL," #sqrt{s_{NN}} = 2.76 TeV ", " ");
    pLegCategory->AddEntry(RBWPOL," #int Ldt  = 6.6 #mub^{-1} ", " ");

    //  pLegCategory->AddEntry(RBWPOL," Global-Global ", "");
    //pLegCategory->AddEntry(RBWPOL," |y| < 2.4 ", "P");
    //pLegCategory->AddEntry(RBWPOL," Run# 150431-151027 ", "P");

    TLegend *legend_1[12];
    for(int i=0; i<12; i++) {
        if(isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94);
        if(!isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94 );
        //    legend_1[i] = new TLegend(.68, .62, .91, 0.93 );
        legend_1[i]->SetBorderSize(0);
        legend_1[i]->SetFillStyle(0);
        legend_1[i]->SetFillColor(0);
        legend_1[i]->SetTextSize(0.028);
    }

    int bin_bound[100];
    TH1D *dimuonsGlobalInvMassVsPt[10];
    TH1D *dimuonsGlobalInvMassVsPtS[10];
    TH1D *service = (TH1D*)phDimuMass_1->ProjectionY("service");

    //  cout << endl << label << "    Yield      Mass (GeV)    Width (GeV)    GauWidth    chi2/ndf " << endl << endl;
    for (Int_t ih = 0; ih < nBins; ih++)  {
        pcPt_1->cd(ih+1);
        gPad->SetTickx();
        gPad->SetTicky();

        // Project 1 D
        bin_bound[ih]   = service->FindBin(binEdge[ih]+0.0000001);
        bin_bound[ih+1] = service->FindBin(binEdge[ih+1]+0.0000001);

        sprintf(szBuf,"Z0_1_pt_%d",ih);
        dimuonsGlobalInvMassVsPt[ih]  = (TH1D*)phDimuMass_1->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1, "e");
        sprintf(szBuf,"Z0_1S_pt_%d",ih);
        dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)phDimuMass_1S->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1);
        cout << "reco entries" << dimuonsGlobalInvMassVsPt[ih]->GetEntries() <<endl;
        if(doPt || doY) {
            sprintf(szBuf," %s [%.1f, %.1f]",
                    label,
                    service->GetBinLowEdge(bin_bound[ih]),
                    service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1]));
        }

        if(doCent) {
            sprintf(szBuf," %s [%.1f, %.1f] %s",
                    label,
                    2.5*service->GetBinLowEdge(bin_bound[ih]),
                    2.5*(service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])), "%");
        }

        dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin);
        dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin);

        // -------- Fit Function + Bkg Function
        double part[20];
        dimuonsGlobalInvMassVsPt[ih]->Fit("EXP","LEQ", "", 34, 60);
        EXP->GetParameters(part);
        if(nFitFunction  == 4) {
            RBWPOL->FixParameter(4, part[0]);
            RBWPOL->FixParameter(5, part[1]);
        }

        if(isFit) {
            //dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQ", "", massFit_low, massFit_high);
            //TFitResultPtr r =
            dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQS0","", massFit_low, massFit_high);
            //	if(r->IsValid()) r->Print();
            //else cout<<"Fit not valid!!!\n"<<endl;
        }

        //------  get fit parameters
        double par[20];
        RBWPOL->GetParameters(par);

        float GGphDimuMass = RBWPOL->GetParameter(1);
        float GGZ0Width    = RBWPOL->GetParameter(2);
        float GauWidth     =0;
        if(nFitFunction  == 3 || nFitFunction  == 4) GauWidth = RBWPOL->GetParameter(3);

        double chisq      = RBWPOL->GetChisquare();
        int ndf           = RBWPOL->GetNDF();
        double chisqdf    =1000;
        if(ndf!=0) chisqdf=chisq/ndf;

        // +++ set backgroudn fit
        sprintf(szBuf,"pt_1B_%d",ih);
        TF1 *bkgFit_1 = new TF1(szBuf, Pol2, massFit_low, massFit_high, 3);
        // if(nFitFunction  == 4) bkgFit_1 = new TF1(namePt_1B, Exp, massFit_low, massFit_high, 2);

        bkgFit_1->SetParameters(&par[3]);
        if(nFitFunction  == 3 || nFitFunction  == 4) bkgFit_1->SetParameters(&par[4]);

        // ----------  Integrated Yield
        //    float massCount_low =GGphDimuMass-(4.0*GGZ0Width);
        //    float massCount_high =GGphDimuMass+(4.0*GGZ0Width);

        TAxis *axs        = dimuonsGlobalInvMassVsPt[ih]->GetXaxis();
        int binlow        = axs->FindBin(massCount_low);
        int binhi         = axs->FindBin(massCount_high);
        Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin());

        Float_t int_sig   = 0.0;
        Float_t int_sig_sqr   = 0.0;
        for(Int_t bin = binlow; bin<=binhi; bin++) {
            //	  cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sig <<"+="<< "bin" << bin << " content"<<dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin)<<endl;
            int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);
            int_sig_sqr += pow(dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin),2);
        }

        if(getYield == 2) {
            int_sig =  RBWPOL->Integral(massCount_low, massCount_high)*bin_size;
            yld_cat_1[ih]   = int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);
            eyld_cat_1[ih] = TMath::Sqrt(int_sig + bin_size*bkgFit_1->Integral(massCount_low, massCount_high) );
        }

        else {
            yld_cat_1[ih]   = int_sig ;
            eyld_cat_1[ih] = int_sig_sqr;
        }
        cout << "int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);" << int_sig<< "  -"<< bin_size<<"*"<<bkgFit_1->Integral(massCount_low, massCount_high)<< " with low"<< massCount_low<<" high "<< massCount_high<<endl;
        //// Printing /////
        cout <<  PT[ih] << "    " << yld_cat_1[ih] << " +- " << eyld_cat_1[ih] <<"     " << GGphDimuMass << "    " << GGZ0Width  << "    " << GauWidth <<"   "<< chisq << "/" << ndf  << endl;


        // -------------- Draw
        //    dimuonsGlobalInvMassVsPt[ih]->SetMinimum(-.05*dimuonsGlobalInvMassVsPt[ih]->GetMaximum());

        if(isLog) gPad->SetLogy(1);

        TColor *pal    = new TColor();
        Int_t kblue    = pal->GetColor(9,0,200);
        //    Int_t korange  = pal->GetColor(101, 42,  0);

        // +++ opposite charge
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})");
        dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("dN/dM (2 GeV/c^{2})^{-1}");

        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(massDraw_low,massDraw_high);
        //    dimuonsGlobalInvMassVsPt[ih]->Add(dimuonsGlobalInvMassVsPtS[ih], -1);

        pcPt_1->cd(ih+1);


        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        // pp data

        TAxis *axs1   = Zmumu->GetXaxis();
        int ll        = axs1->FindBin(massCount_low);
        int hh        = axs1->FindBin(massCount_high);

        double scalefactor =  yld_cat_1[ih]/Zmumu->Integral(ll, hh);

        cout << Zmumu->Integral(ll, hh) << endl;

        Zmumu->Scale(scalefactor);

        Zmumu->SetFillColor(19);

        Zmumu->Draw("same");

        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        //    dimuonsGlobalInvMassVsPt[ih]->Draw("B");

        // +++ same charge
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8);
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46);
        dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46);

        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame");


        // background
        //    RBWPOL->SetLineColor(kblue);
        bkgFit_1->SetLineColor(46);
        bkgFit_1->SetLineWidth(1);
        //    if(isFit) bkgFit_1->Draw("same");

        // ++++ legend
        pLegCategory->Draw("same");


        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Global-Global", " ");

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |#eta^{#mu}| < 2.4, p_{T}^{#mu} > 10 GeV/c ", "");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Unlike Sign ", "LP");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Like Sign ", "LP");
        legend_1[ih]->AddEntry(Zmumu," pp Data ", "L");




        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, "");


        sprintf(szBuf, "N=%1.0f #pm %1.1f ", yld_cat_1[ih], sqrt(yld_cat_1[ih]) );

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        //    sprintf(label_1, "N_{Z^{0}} = 27");

        sprintf(szBuf, "mass = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(1), RBWPOL->GetParError(1));
        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],szBuf, "");

        sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(2), RBWPOL->GetParError(2));

        if(nFitFunction ==3 || nFitFunction  == 4)
            sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(3), RBWPOL->GetParError(3));

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        sprintf(szBuf, "#chi^{2}/ndf = %1.2f / %d", chisq, ndf);

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_4, "");

        legend_1[ih]->Draw("same");

        pcPt_1->Update();
    }

    cout << endl << endl;


    TGraphErrors *Z0pt_cat_1 = new TGraphErrors(nBins, PT, yld_cat_1, mom_err, eyld_cat_1);
    Z0pt_cat_1->SetMarkerStyle(20);
    Z0pt_cat_1->SetMarkerColor(2);
    Z0pt_cat_1->GetXaxis()->SetTitle(label);
    Z0pt_cat_1->GetYaxis()->SetTitle("counts");

    TCanvas *pc2 = new TCanvas("pc2","pc2");
    Z0pt_cat_1->SetMinimum(0.0);
    Z0pt_cat_1->SetName("Z0pt_cat_1");
    Z0pt_cat_1->Draw("AP");


    TGraphErrors *Z0ptC_cat_1_gen = new TGraphErrors(nBins, PT, gen_pt, mom_err, egen_pt);
    //  Z0ptC_cat_1_gen->SetMarkerStyle(23);
    //Z0ptC_cat_1_gen->SetMarkerColor(3);
    //Z0ptC_cat_1_gen->Draw("AP");


    pLegCategory->Draw("same");

    Z0pt_cat_1->Write();
    pLegCategory->Write();


    //    gPad->Print("Pt_Z0YieldCat_1.png");
    pcPt_1->Print("Pt_Z0YieldCat_1.png");


    cout << endl << endl;




    //////////////////////////////////////////////////////////////////////////////

    // Efficiency correction
    if(doMc)  {
        ofstream fileout("correction.txt");
        cout << label << "   Eff_cat_1  " << endl;

        for (Int_t ih = 0; ih < nBins; ih++)  {
            Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih];

            errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
                                     +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*( yld_cat_1[ih]-gen_pt[ih]/ yld_cat_1[ih]));
            //	  errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
            //			   +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*event failing);


            //	fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << Eff_cat_2[ih] <<"    " << Eff_cat_3[ih] << endl;
            //	cout <<"    " << PT[ih] <<"      "<< Eff_cat_1[ih] << "      " << Eff_cat_2[ih] << "      " << Eff_cat_3[ih] << endl;

            fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << errEff_cat_1[ih] << endl;
            cout <<"    " << PT[ih] <<"    "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl;
            cyld_cat_1[ih] = Eff_cat_1[ih];
            ceyld_cat_1[ih] = errEff_cat_1[ih];

        }
    }
    else {
        ifstream filein("correction.txt");
        cout <<  label << " yld_cat_1 "  << "  efficiency " <<  " corr. yld_cat_1  " << endl;
        for (Int_t ih = 0; ih < nBins; ih++)  {

            //      filein >> PT[ih] >>  Eff_cat_1[ih] >>  Eff_cat_2[ih]  >>  Eff_cat_3[ih] ;
            //      cout << "       " << PT[ih] << "      "<< yld_cat_1[ih] << "       " << yld_cat_2[ih] <<"      " <<  yld_cat_3[ih] << endl;

            filein >> PT[ih] >>  Eff_cat_1[ih]  >> errEff_cat_1[ih];
            cout << "    " << PT[ih] << "     " << yld_cat_1[ih] << "     " << Eff_cat_1[ih] << "     " << yld_cat_1[ih]/Eff_cat_1[ih] << endl;
            cyld_cat_1[ih] = yld_cat_1[ih]/Eff_cat_1[ih];
            ceyld_cat_1[ih] = eyld_cat_1[ih]/Eff_cat_1[ih];

        }
    }

    //  TF1 *EXPA = new TF1("EXPA", Exp, 0, 100, 2);

    TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(nBins, PT, cyld_cat_1, mom_err, ceyld_cat_1);
    Z0ptC_cat_1->SetMarkerStyle(20);
    Z0ptC_cat_1->SetMarkerColor(2);
    Z0ptC_cat_1->GetXaxis()->SetTitle(label);
    Z0ptC_cat_1->GetYaxis()->SetTitle("Acc x Eff");
    //  if(part == 2) Z0ptC_cat_1->Fit("EXPA","LEQ", "", 7, 16);


    new TCanvas;
    Z0ptC_cat_1->SetMinimum(0.0);
    Z0ptC_cat_1->SetMaximum(0.8);
    Z0ptC_cat_1->SetName("Z0ptC_cat_1");
    Z0ptC_cat_1->Draw("AP");


    pLegCategory->Draw("same");

    cout << endl << endl;

    Z0ptC_cat_1->Write();

}
コード例 #15
0
ファイル: draw_jetEt.C プロジェクト: CmsHI/CVS_SavedFMa
void draw_jetEt(){

  TColor *pal = new TColor();
  Int_t kred     = pal->GetColor(190,  0,  3);
  Int_t kgreen   = pal->GetColor( 15, 85, 15);
  Int_t kazure   = pal->GetColor(  0, 48, 97);
  Int_t kcyan    = pal->GetColor(  0, 83, 98);

  TFile *fMBNZP = new TFile("../test/dijetAna_anaJet_MinBias.root");
  TFile *fHENZP = new TFile("../test/dijetAna_anaJet_HardEnriched.root");
  TFile *fHEZP = new TFile("../franktrees/dijetAna_JEx_ZP_Hard_proc0_all.root");



  fMBNZP->cd("dijetAna_data");

  TH1F *h1 = new TH1F("hMBNZP","hMBNZP",170,0,170);
  
  TTree *tMBNZP = (TTree*)fMBNZP->Get("dijetAna_data/djTree");
  cout<<tMBNZP->GetEntries()<<endl;
  tMBNZP->Draw("nljet>>hMBNZP","abs(nljeta)<2.");


  fHENZP->cd("dijetAna_data");
  
  TH1F *h2 = new TH1F("hHENZP","hHENZP",170,0,170);
  
  TTree *tHENZP = (TTree*)fHENZP->Get("dijetAna_data/djTree");
  cout<<tHENZP->GetEntries()<<endl;
  tHENZP->Draw("nljet>>hHENZP","abs(nljeta)<2.");

  TH1F *h3 = new TH1F("hHEZP","hHEZP",170,0,170);
  
  TTree *tHEZP = (TTree*)fHEZP->Get("dijetAna_data/djTree");
  cout<<tHEZP->GetEntries()<<endl;
  tHEZP->Draw("nljet>>hHEZP","abs(nljeta)<2.");


  h1->Scale(1./h1->Integral("width"));
  h2->Scale(1./h2->Integral("width"));
  h3->Scale(1./h3->Integral("width"));
  
  h1->SetTitle("Minimum Bias (NZP) vs. Hard Enriched (ZP, NZP)");
  h1->GetXaxis()->SetTitle("E_{T} [GeV]");
  h1->GetYaxis()->SetTitle("dN/dE_{T} (Arb. Norm.)");

  h1->Draw();

  h2->SetLineColor(kred);
  h2->Draw("sames");

  h3->SetLineColor(4);
  h3->Draw("sames");

  TLegend *t=new TLegend(0.5,0.5,0.9,0.8);
  t->SetBorderSize(0);
  t->SetFillStyle(0);
  t->AddEntry(h1,"Minimum Bias, NZP","l");
  t->AddEntry(h2,"Hard Enriched, NZP","l");
  t->AddEntry(h3,"Hard Enriched, ZP","l");
  t->Draw();
    
}
コード例 #16
0
ファイル: per_bump.cpp プロジェクト: bartholomule/panorama
TVector TPerturbationBump::perturbNormal (const TSurfaceData& rktDATA) const
{

  TVector   tNewNormal = rktDATA.unperturbedNormal();

  if ( fabs(tBumpFactor) > FX_EPSILON )
  {
    TSurfaceData   tData;
    TColor         tColor;
    TColor         tBasisColor;
    TVector        tGradientU;
    TVector        tGradientV;
    TVector        r, s, t;
    TVector        tTemp;
    TScalar        tHeight;
    TScalar        tHeightDiff;
    TScalar        dx, dy;
    TScalar        x, y;
    TScalar        tRDamping;
    TScalar        tTDamping;
    TScalar        tRDampingAbs;
    TScalar        tTDampingAbs;
    TScalar        tRDampingTotal;
    TScalar        tTDampingTotal;
    TScalar        tRTotal;
    TScalar        tTTotal;
    TMatrix        tObjectTransform = *rktDATA.object()->transformMatrix();

    if ( !ptPattern )
    {
      cout << ("Error: pattern must be set") << endl;
      exit (1);
    }

    s = tNewNormal;

    r = crossProduct (s, TVector(0.0, 1.0, 0.0));

    if ( r.norm() < FX_EPSILON )
    {
      r = TVector(1.0, 0.0, 0.0);

      if ( fabs (s.y() - 1.0) < FX_EPSILON )
      {
	s = TVector(0.0, 1.0, 0.0);
      }
      else
      {
	s = TVector(0.0, -1.0, 0.0);
      }
    }

    r.normalize();
    t = crossProduct (r, s);
    t.normalize();

    tGradientU = r * tGradientDisplacement.x();
    tGradientV = t * tGradientDisplacement.y();

    tData = rktDATA;

    tColor = ptPattern->color (rktDATA);
    tHeight = tColor.average();

    dx = ( tSamples.x() > 1 ) ? (2.0 / (tSamples.x() - 1.0)) : 0;
    dy = ( tSamples.y() > 1 ) ? (2.0 / (tSamples.y() - 1.0)) : 0; 

    tRTotal = 0;
    tTTotal = 0;

    tRDampingTotal = 0;
    tTDampingTotal = 0;

    y = -1.0;

    for (size_t iy = 0; ( iy < (size_t) tSamples.y() ); iy++)
    {

      tTDampingAbs = (1.0 - (y * y) * 0.8);

      if ( tTDampingAbs > (1.0 - FX_EPSILON) )
      {
        tTDampingAbs = 0;
      }

      tTDamping = ( y > 0 ) ? tTDampingAbs : -tTDampingAbs;

      x = -1.0;

      for (size_t ix = 0; ( ix < (size_t) tSamples.x() ); ix++)
      {
        tTemp = ptPattern->warp (rktDATA.localPoint()) + (tGradientU * x) + (tGradientV * y);
        tData.setPoint (tObjectTransform * tTemp);
        tColor = ptPattern->color (tData);

        tHeightDiff = tHeight - tColor.average();

        tRDampingAbs = (1.0 - (x * x) * 0.8);

	if ( tRDampingAbs > (1.0 - FX_EPSILON) )
	{
          tRDampingAbs = 0;
        }
  
	tRDamping = ( x > 0 ) ? tRDampingAbs : -tRDampingAbs;

	tRDampingTotal += tRDampingAbs;
	tTDampingTotal += tTDampingAbs;
    
	tRTotal += tHeightDiff * tRDamping;
	tTTotal += tHeightDiff * tTDamping;

        x += dx;
      }

      y += dy;
    }

    r *= tRTotal / tRDampingTotal;
    t *= tTTotal / tTDampingTotal;

    tNewNormal = s + (r + t) * tBumpFactor;
    tNewNormal.normalize();
  }

  return tNewNormal;

}  /* perturbNormal() */
コード例 #17
0
ファイル: tga_io.cpp プロジェクト: bartholomule/panorama
TImage* TImageTga::load (void)
{

  ifstream   sFile;
  Byte       bRed, bGreen, bBlue;
  Byte       bAux;
  TColor     tColor;
  TImage*    ptImage;
  size_t     zWidth, zHeight, zCountColors, zTotalNoPixels;
  Byte       bIndentifierLength;
  Byte       bColorMapType;
  Byte       bSizeofMapEntry;
  Byte       bImageType;
  Byte       bAttributes;
  Byte       bPixelSize;
  int        iStart, iStop, iAdd;

  sFile.open (tFileName.c_str(), ios::in | ios::binary);

  if ( !sFile )
  {
    return NULL;
  }
  
  bAux = sFile.get();                             // Length of identifier string
  bIndentifierLength = bAux;

  bAux = sFile.get();                             // Color map type (0 = no color map)
  bColorMapType = bAux;

  bAux = sFile.get();                             // Image type
  bImageType = bAux;

  if ( ( bImageType != 2 ) && ( bImageType != 10 ) )
  {
    cerr << "TImageTga::load : Unsupported image type. Error loading " << tFileName << endl;
    return NULL;    
  }

  bAux = sFile.get();                             // First color map entry
  bAux = sFile.get();

  bAux = sFile.get();                             // Entries in color map
  zCountColors = bAux;
  bAux = sFile.get();
  zCountColors += (Word (bAux) * 256);

  bAux = sFile.get();                             // Size of color map entry
  bSizeofMapEntry = bAux;

  bAux = sFile.get();                             // X origin of image
  bAux = sFile.get();
  bAux = sFile.get();                             // Y origin of image
  bAux = sFile.get();

  bAux = sFile.get();
  zWidth = bAux;
  bAux = sFile.get();
  zWidth += (Word (bAux) * 256);

  bAux = sFile.get();
  zHeight = bAux;
  bAux = sFile.get();
  zHeight += (Word (bAux) * 256);

  bAux = sFile.get();                             // Pixel size 
  bPixelSize = bAux;

  if ( ( bPixelSize != 16 ) && ( bPixelSize != 24 ) && ( bPixelSize != 32 ) )
  {
    cerr << "TImageTga::load : Unsupported pixel size. Error loading " << tFileName << endl;
    return NULL;    
  }

  bAux = sFile.get();                             // Attributes 
  bAttributes = bAux;

  sFile.seekg(bIndentifierLength, std::ios::cur);
  
  if ( bColorMapType )                            // Ignore color map
  {
    sFile.seekg ((bSizeofMapEntry / 8) * zCountColors, std::ios::cur);
  }

  if ( bAttributes & 0x20 )                       // Check origin (upper or lower left)
  {
    iStart = 0;
    iStop  = zHeight;
    iAdd   = 1;
  }
  else 
  {
    iStart = zHeight - 1; 
    iStop  = -1; 
    iAdd   = -1;
  } 

  ptImage = new TImage (zWidth, zHeight);

  bRed   = 0;
  bGreen = 0;
  bBlue  = 0;

  if ( bImageType == 2 )                          // Uncompressed      
  {
    for (int J = iStart; ( J != iStop ) ;(J += iAdd))
    {
      for (size_t I = 0; ( I < zWidth ) ;I++)
      {
        grabRGB (bPixelSize, sFile, bRed, bGreen, bBlue); 

        tColor = TColor (bRed, bGreen, bBlue);
        tColor = tColor.convertFrom24Bits();
        ptImage->setPixel (I, J, tColor);
      }
    }
  }
  else                                            // Runlength encoded
  {
    zTotalNoPixels = zWidth * zHeight;
 
    int    J = iStart;
    size_t I = 0;
    
    Byte   N = 0;

    while ( zTotalNoPixels )
    {
      bAux = sFile.get();

      N = ((bAux & 0x7f) + 1);

      if ( bAux & 0x80 )
      {
        grabRGB (bPixelSize, sFile, bRed, bGreen, bBlue); 

        tColor = TColor (bRed, bGreen, bBlue);
        tColor = tColor.convertFrom24Bits();

        for (Byte M = 0; ( M < N ) ;M++)
        {
          ptImage->setPixel (I, J, tColor);

          I++;
          zTotalNoPixels--;

          if ( I == zWidth ) 
          {
            I  = 0;
            J += iAdd;
          }
        }                
      }
      else
      {
        for (Byte M = 0; ( M < N ) ;M++)
        {
          grabRGB (bPixelSize, sFile, bRed, bGreen, bBlue); 

          tColor = TColor (bRed, bGreen, bBlue);
          tColor = tColor.convertFrom24Bits();
          ptImage->setPixel (I, J, tColor);

          I++;
          zTotalNoPixels--;

          if ( I == zWidth ) 
          {
            I  = 0;
            J += iAdd;
          }
        }                
      }
    }
  }
  
  sFile.close();

  return ptImage;
  
}  /* load() */
コード例 #18
0
void TGo4HisDrawOptionsShort::ChangeColor(int kind)
{
   TGo4ViewPanel* panel = TGo4MdiArea::Instance()->GetActivePanel();
   if (panel==0) return;

   TPad* pad = panel->GetActivePad();
   TObject* obj = panel->GetSelectedObject(pad, 0);

   Color_t icol = 0;

   switch (kind) {
      case 0: {
        TAttLine* att = dynamic_cast<TAttLine*> (obj);
        if (att==0) return;
        icol = att->GetLineColor();
        break;
      }
      case 1: {
        TAttFill* att = dynamic_cast<TAttFill*> (obj);
        if (att==0) return;
        icol = att->GetFillColor();
        break;
      }
      case 2: {
        TAttMarker* att = dynamic_cast<TAttMarker*> (obj);
        if (att==0) return;
        icol = att->GetMarkerColor();
        break;
      }
   }

   TColor* rcol = gROOT->GetColor(icol);

   QColor qcol;

   if (rcol!=0)
      qcol.setRgb(rcol->GetRed(), rcol->GetGreen(), rcol->GetBlue());

   QColor c = QColorDialog::getColor(qcol);
   if (!c.isValid()) return;

   icol = TColor::GetColor(c.red(), c.green(), c.blue());

   switch (kind) {
      case 0: {
        TAttLine* att = dynamic_cast<TAttLine*> (obj);
        if (att!=0) att->SetLineColor(icol);
        break;
      }
      case 1: {
        TAttFill* att = dynamic_cast<TAttFill*> (obj);
        if (att!=0) att->SetFillColor(icol);
        break;
      }
      case 2: {
        TAttMarker* att = dynamic_cast<TAttMarker*> (obj);
        if (att!=0) att->SetMarkerColor(icol);
        break;
      }
   }

   panel->MarkPadModified(pad);

   panel->ShootRepaintTimer(pad);

   panel->ActivateInGedEditor(obj);
}