Пример #1
0
void DynamicExec()
{
   // Example of function called when a mouse event occurs in a pad.
   // When moving the mouse in the canvas, a second canvas shows the
   // projection along X of the bin corresponding to the Y position
   // of the mouse. The resulting histogram is fitted with a gaussian.
   // A "dynamic" line shows the current bin position in Y.
   // This more elaborated example can be used as a starting point
   // to develop more powerful interactive applications exploiting CINT
   // as a development engine.
   //
   // Author:  Rene Brun
   
   TObject *select = gPad->GetSelected();
   if(!select) return;
   if (!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0); return;}
   TH2 *h = (TH2*)select;
   gPad->GetCanvas()->FeedbackMode(kTRUE);

   //erase old position and draw a line at current position
   int pyold = gPad->GetUniqueID();
   int px = gPad->GetEventX();
   int py = gPad->GetEventY();
   float uxmin = gPad->GetUxmin();
   float uxmax = gPad->GetUxmax();
   int pxmin = gPad->XtoAbsPixel(uxmin);
   int pxmax = gPad->XtoAbsPixel(uxmax);
   if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
   gVirtualX->DrawLine(pxmin,py,pxmax,py);
   gPad->SetUniqueID(py);
   Float_t upy = gPad->AbsPixeltoY(py);
   Float_t y = gPad->PadtoY(upy);

   //create or set the new canvas c2
   TVirtualPad *padsav = gPad;
   TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
   if(c2) delete c2->GetPrimitive("Projection");
   else   c2 = new TCanvas("c2","Projection Canvas",710,10,700,500);
   c2->SetGrid();
   c2->cd();

   //draw slice corresponding to mouse position
   Int_t biny = h->GetYaxis()->FindBin(y);
   TH1D *hp = h->ProjectionX("",biny,biny);
   hp->SetFillColor(38);
   char title[80];
   sprintf(title,"Projection of biny=%d",biny);
   hp->SetName("Projection");
   hp->SetTitle(title);
   hp->Fit("gaus","ql");
   hp->GetFunction("gaus")->SetLineColor(kRed);
   hp->GetFunction("gaus")->SetLineWidth(6);
   c2->Update();
   padsav->cd();
}
Пример #2
0
void GetCosmicOut(){
  gSystem->Load("lib/libtest.so");
  IDHandler* handler  = new IDHandler("Data/crystal.txt");
  CsIImage*  image    = new CsIImage(handler);
  image->SetTitle("Distribution On image; x[mm]; y[mm]");
  TH1D* gainHist      = new TH1D("gain","Distribution of gain;Integrated ADC;N/10cnt",500,0,5000);				 
  
  std::ofstream ofs("CH_Cosmic_outList_3599_3600.txt");  
  
  Double_t gain;
  Double_t Sigma;
  Double_t Norm;
  Double_t HistEntries;
  TFile* tf = new TFile("cosmic_3599_3600.root");
  
  for( int i = 0; i< 2716; i++){    
    TH1D* hist  = (TH1D*)tf->Get(Form("his_CH%04d",i));
    TF1*  func  = NULL;
    func        = hist->GetFunction("landau");
    if( func == NULL ){
      continue;
    }
    if( i < 2240){      
      gain = func->GetParameter(1);      
      image->Fill(i, func->GetParameter(1));
      ofs << i << "\t" 
	  << gain << "\t"
	  << func->GetParameter(2) << std::endl; 
    }else{
      gain = func->GetParameter(1)/2;
      image->Fill(i, gain);
      ofs << i << "\t" 
	  << gain << "\t" 
	  << func->GetParameter(2)/2   << std::endl; 
    }
    gainHist->Fill(gain);
  }

  ofs.close();
  TCanvas* can = new TCanvas("can","",1600,800);
  can->Divide(2,1);  
  can->cd(1);
  image->Draw();
  can->cd(2);
  gainHist->Draw();

}
Пример #3
0
// Show the Pt spectra, and start the tree viewer.
int showEventSample()
{
  // Load needed libraries
  loadLibraries();

  // Open the file
  TFile* file = TFile::Open(FILENAME, "READ");
  if (!file || !file->IsOpen()) {
    Error("showEventSample", "Couldn;t open file %s", FILENAME);
    return 1;
  }

  // Get the tree
  TTree* tree = (TTree*)file->Get(TREENAME);
  if (!tree) {
    Error("showEventSample", "couldn't get TTree %s", TREENAME);
    return 2;
  }

  // Start the viewer.
  tree->StartViewer();

  // Get the histogram
  TH1D* hist = (TH1D*)file->Get(HISTNAME);
  if (!hist) {
    Error("showEventSample", "couldn't get TH1D %s", HISTNAME);
    return 4;
  }

  // Draw the histogram in a canvas
  gStyle->SetOptStat(1);
  TCanvas* canvas = new TCanvas("canvas", "canvas");
  canvas->SetLogy();
  hist->Draw("e1");
  TF1* func = hist->GetFunction("expo");

  char expression[64];
  sprintf(expression,"T #approx %5.1f", -1000 / func->GetParameter(1));
  TLatex* latex = new TLatex(1.5, 1e-4, expression);
  latex->SetTextSize(.1);
  latex->SetTextColor(4);
  latex->Draw();

  return 0;
}
Пример #4
0
void plotXY(char* fname){

  // input: root file from GBL

  gStyle->SetOptStat(0);
  Double_t w = 1.2; // number of RMS for gaussian fit
  TString filename = fname;
  TCanvas *cTop = new TCanvas("cTop","Residuals in lab frame, TOP", 800, 1000);
  TCanvas *cBot = new TCanvas("cBot","Residuals in lab frame, BOTTOM",800, 1000);
  cTop->SetFillColor(kBlue-10); cTop->SetFillStyle(3001);
  cBot->SetFillColor(kMagenta-10); cBot->SetFillStyle(3001);
  Double_t halfWid = 38.34/2.;
  Double_t halfLen = 98.33/2.;
  TBox *module = new TBox(-halfLen, -halfWid, halfLen, halfWid);
  module->SetLineColor(kMagenta);
  module->SetFillStyle(0);

  Int_t ic=0;
  TFile *f = new TFile(filename.Data());
  // extract string 
  Int_t idx2 = filename.Index("/");
  Int_t idx1 = filename.Index("_");
  TString outn = filename(idx1+1,idx2-(idx1+1));
  TString outname ="predXY_"; outname += outn.Data(); outname += ".txt";
  TString topName ="predXY_"; topName += outn.Data(); topName += "_topO.gif";
  TString botName ="predXY_"; botName += outn.Data(); botName += "_botO.gif";
  //  ofstream outf(outname.Data());
  // top
  Int_t nrow = 13;
  Double_t space = 0.007;
  Double_t space1 = 0.03;
  Double_t y2 = 1./13*nrow-space1;
  Double_t y1 = 1./13*(--nrow)-space1;
  TPad *tp1 = new TPad("tp1","tp1",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp2 = new TPad("tp2","tp2",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *tp3 = new TPad("tp3","tp3",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp4 = new TPad("tp4","tp4",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *tp5 = new TPad("tp5","tp5",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp6 = new TPad("tp6","tp6",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  Double_t off = 0.12;
  off = 0.165;
  y1 -= space1; y2 -= space1;
  space1 *= 2;
  TPad *tp7 = new TPad("tp7","tp7",0.+off,y1,0.33+off,y2);
  TPad *tp8 = new TPad("tp8","tp8",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp9 = new TPad("tp9","tp9",0.+off,y1,0.33+off,y2);
  TPad *tp10 = new TPad("tp10","tp10",0.66-off,y1,1.-off,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *tp11 = new TPad("tp11","tp11",0.+off,y1,0.33+off,y2);
  TPad *tp12 = new TPad("tp12","tp12",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp13 = new TPad("tp13","tp13",0.+off,y1,0.33+off,y2);
  TPad *tp14 = new TPad("tp14","tp14",0.66-off,y1,1.-off,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *tp15 = new TPad("tp15","tp15",0.+off,y1,0.33+off,y2);
  TPad *tp16 = new TPad("tp16","tp16",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *tp17 = new TPad("tp17","tp17",0.+off,y1,0.33+off,y2);
  TPad *tp18 = new TPad("tp18","tp18",0.66-off,y1,1.-off,y2);
  cout << " TOP " << endl;

  cTop->cd();
  tp1->Draw();
  tp2->Draw();
  tp3->Draw();
  tp4->Draw();
  tp5->Draw();
  tp6->Draw();
  tp7->Draw();
  tp8->Draw();
  tp9->Draw();
  tp10->Draw();
  tp11->Draw();
  tp12->Draw();
  tp13->Draw();
  tp14->Draw();
  tp15->Draw();
  tp16->Draw();
  tp17->Draw();
  tp18->Draw();

  ic = 2;
  Int_t ipad=0;
  for(Int_t i=1; i<4; i++){
    TString hisname = "h_xy_module_L"; hisname  += i;
    hisname += "t_halfmodule_axial_sensor0";
    TString layer = "L"; layer+=i; layer+= "TA"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    TH1D *his = (TH1D*)his2->ProjectionY();
    ipad++;
    TString pd = "tp"; pd+=ipad;
    TPad *pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    Double_t low = his->GetMean()-w*his->GetRMS();
    Double_t up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up);
    his2->Draw("colz");
    module->Draw("same");
    TF1 *fit = his->GetFunction("gaus");
    // cout << "sensor " << i << " axial mean :  " << his->GetMean()*1000. << " - RMS : " << his->GetRMS()*1000. << " (um) " << " " << his->GetEntries() << endl;
    // cout << "sensor " << i << " axial mu :  " << fit->GetParameter(1)*1000. << " - sigma : " << fit->GetParameter(2)*1000. << " (um) " << endl;
    // outf << layer.Data() << " " << fit->GetParameter(1)*1000. << " " << fit->GetParameter(2)*1000. << " " << his->GetEntries() << endl;

    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "t_halfmodule_stereo_sensor0";
    layer = "L"; layer+=i; layer+= "TS"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    his = (TH1D*)his2->ProjectionY();
    ipad++;
    pd = "tp"; pd+=ipad;
    pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
  }
  //  ic = 19;
  for(Int_t i=4; i<7; i++){
    TString hisname = "h_xy_module_L"; hisname  += i;
    TString hisname2 = hisname;
    hisname += "t_halfmodule_axial_hole_sensor0";
    hisname2 += "t_halfmodule_axial_slot_sensor0";
    TH2D *hisOther = (TH2D*) f->Get(hisname2.Data());
    Double_t norma2 = hisOther->GetMaximum();
    TString layer = "L"; layer+=i; layer+= "TAHo"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    TH1D *his = (TH1D*)his2->ProjectionY();     
    Double_t norma1 = his2->GetMaximum();
    Double_t normamax = TMath::Max(norma1,norma2);
    his2->SetMaximum(normamax);
    ipad++;
    TString pd = "tp"; pd+=ipad;
    TPad *pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    Double_t low = his->GetMean()-w*his->GetRMS();
    Double_t up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    TF1 *fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname2 = hisname;
    hisname += "t_halfmodule_stereo_hole_sensor0";
    hisname2 += "t_halfmodule_stereo_slot_sensor0";
    TH2D *hisOther = (TH2D*) f->Get(hisname2.Data());
    norma2 = hisOther->GetMaximum();
    TString layer = "L"; layer+=i; layer+= "TAHo"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    TH1D *his = (TH1D*)his2->ProjectionY();     
    norma1 = his2->GetMaximum();
    normamax2 = TMath::Max(norma1,norma2);
    his2->SetMaximum(normamax2);
    layer = "L"; layer+=i; layer+= "TSHo"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    his = (TH1D*)his2->ProjectionY();
    ipad++; ipad++;
    pd = "tp"; pd+=ipad;
    pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "t_halfmodule_axial_slot_sensor0";
    layer = "L"; layer+=i; layer+= "TASl";
    his2 = (TH2D*) f->Get(hisname.Data());
    his2->SetMaximum(normamax);
    his = (TH1D*)his2->ProjectionY();     
    ipad--;
    pd = "tp"; pd+=ipad;
    pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "t_halfmodule_stereo_slot_sensor0";
    layer = "L"; layer+=i; layer+= "TSSl"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    his2->SetMaximum(normamax2);
    his = (TH1D*)his2->ProjectionY();     
    ipad++; ipad++;
    pd = "tp"; pd+=ipad;
    pad = (TPad*) cTop->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
  }
  cout << endl;
  cout << "------------------------" << endl;
  cout << endl;
  cout << " BOTTOM " << endl;
  nrow = 13;
  space = 0.007;
  space1 = 0.03;
  y2 = 1./13*nrow-space1;
  y1 = 1./13*(--nrow)-space1;
  TPad *bp1 = new TPad("bp1","bp1",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp2 = new TPad("bp2","bp2",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *bp3 = new TPad("bp3","bp3",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp4 = new TPad("bp4","bp4",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *bp5 = new TPad("bp5","bp5",0.33,y1,0.66,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp6 = new TPad("bp6","bp6",0.33,y1,0.66,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  off = 0.165;
  y1 -= space1; y2 -= space1;
  space1 *= 2;
  TPad *bp7 = new TPad("bp7","bp7",0.+off,y1,0.33+off,y2);
  TPad *bp8 = new TPad("bp8","bp8",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp9 = new TPad("bp9","bp9",0.+off,y1,0.33+off,y2);
  TPad *bp10 = new TPad("bp10","bp10",0.66-off,y1,1.-off,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *bp11 = new TPad("bp11","bp11",0.+off,y1,0.33+off,y2);
  TPad *bp12 = new TPad("bp12","bp12",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp13 = new TPad("bp13","bp13",0.+off,y1,0.33+off,y2);
  TPad *bp14 = new TPad("bp14","bp14",0.66-off,y1,1.-off,y2);
  y2 = y1-space; y1 = 1./13.*(--nrow)-space1;
  TPad *bp15 = new TPad("bp15","bp15",0.+off,y1,0.33+off,y2);
  TPad *bp16 = new TPad("bp16","bp16",0.66-off,y1,1.-off,y2);
  y2 = y1; y1 = 1./13.*(--nrow)-space1;
  TPad *bp17 = new TPad("bp17","bp17",0.+off,y1,0.33+off,y2);
  TPad *bp18 = new TPad("bp18","bp18",0.66-off,y1,1.-off,y2);

  cBot->cd();
  bp1->Draw();
  bp2->Draw();
  bp3->Draw();
  bp4->Draw();
  bp5->Draw();
  bp6->Draw();
  bp7->Draw();
  bp8->Draw();
  bp9->Draw();
  bp10->Draw();
  bp11->Draw();
  bp12->Draw();
  bp13->Draw();
  bp14->Draw();
  bp15->Draw();
  bp16->Draw();
  bp17->Draw();
  bp18->Draw();

  cBot->cd();
  bp1->Draw();
  bp2->Draw();
  bp3->Draw();
  bp4->Draw();
  bp5->Draw();
  bp6->Draw();
  bp7->Draw();
  bp8->Draw();
  bp9->Draw();
  bp10->Draw();
  bp11->Draw();
  bp12->Draw();
  bp13->Draw();
  bp14->Draw();
  bp15->Draw();
  bp16->Draw();
  bp17->Draw();
  bp18->Draw();

  ic=0;
  ipad = 0;
  for(Int_t i=1; i<4; i++){
    TString hisname = "h_xy_module_L"; hisname  += i;
    TString hisname2 = hisname;
    hisname += "b_halfmodule_stereo_sensor0";
    hisname2 += "b_halfmodule_axial_sensor0";
    TH2D *hisOther = (TH2D*) f->Get(hisname2.Data());
    Double_t norma2 = hisOther->GetMaximum();
    TString layer = "L"; layer+=i; layer+= "BS"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    Double_t norma1 = his2->GetMaximum();
    Double_t normamax = TMath::Max(norma1,norma2);
    //    his2->SetMaximum(normamax);
    TH1D *his = (TH1D*)his2->ProjectionY();     
    if(layer.Contains("1")){his->SetFillColor(kRed);}
    else if(layer.Contains("2")){his->SetFillColor(kOrange);}
    else if(layer.Contains("3")){his->SetFillColor(kYellow);}
    else if(layer.Contains("4")){his->SetFillColor(kGreen);}
    else if(layer.Contains("5")){his->SetFillColor(kCyan);}
    else if(layer.Contains("6")){his->SetFillColor(kBlue);}
    if(layer.Contains("A")){his->SetFillStyle(3007);}
    else if(layer.Contains("S")){his->SetFillStyle(3004);}
    //    cBot->cd(++ic);
    ipad++;
    TString pd = "bp"; pd+=ipad;
    TPad *pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    Double_t low = his->GetMean()-w*his->GetRMS();
    Double_t up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    TF1 *fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "b_halfmodule_axial_sensor0";
    layer = "L"; layer+=i; layer+= "BA"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    //   his2->SetMaximum(normamax);
    his = (TH1D*)his2->ProjectionY();     
    ipad++;
    pd = "bp"; pd+=ipad;
    pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
  }
  for(Int_t i=4; i<7; i++){
    TString hisname = "h_xy_module_L"; hisname  += i;
    TString hisname2 = hisname;
    hisname += "b_halfmodule_stereo_hole_sensor0";
    hisname2 += "b_halfmodule_stereo_slot_sensor0";
    TH2D *hisOther = (TH2D*) f->Get(hisname2.Data());
    Double_t norma2 = hisOther->GetMaximum();
    TString layer = "L"; layer+=i; layer+= "BSHo"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    TH1D *his = (TH1D*)his2->ProjectionY();     
    Double_t norma1 = his2->GetMaximum();
    Double_t normamax1 = TMath::Max(norma1,norma2);
    his2->SetMaximum(normamax1);
    ipad++; 
    TString pd = "bp"; pd+=ipad;
    TPad *pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    Double_t low = his->GetMean()-w*his->GetRMS();
    Double_t up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    TF1 *fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    TString hisname2 = hisname;
    hisname += "b_halfmodule_axial_hole_sensor0";
    hisname2 += "b_halfmodule_axial_slot_sensor0";
    TH2D *hisOther = (TH2D*) f->Get(hisname2.Data());
    Double_t norma2 = hisOther->GetMaximum();
    TString layer = "L"; layer+=i; layer+= "BAHo"; 
    TH2D *his2 = (TH2D*) f->Get(hisname.Data());
    TH1D *his = (TH1D*)his2->ProjectionY();     
    Double_t norma1 = his2->GetMaximum();
    Double_t normamax2 = TMath::Max(norma1,norma2);
    his2->SetMaximum(normamax2);
    ipad++; ipad++;
    pd = "bp"; pd+=ipad;
    pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "b_halfmodule_stereo_slot_sensor0";
    layer = "L"; layer+=i; layer+= "BSSl"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    his2->SetMaximum(normamax1);
    his = (TH1D*)his2->ProjectionY();     
    ipad--;
    pd = "bp"; pd+=ipad;
    pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
    hisname = "h_xy_module_L"; hisname  += i;
    hisname += "b_halfmodule_axial_slot_sensor0";
    layer = "L"; layer+=i; layer+= "BASl"; 
    his2 = (TH2D*) f->Get(hisname.Data());
    his2->SetMaximum(normamax2);
    his = (TH1D*)his2->ProjectionY();     
    ipad++; ipad++;
    pd = "bp"; pd+=ipad;
    pad = (TPad*) cBot->GetListOfPrimitives()->FindObject(pd.Data());
    pad->cd();
    low = his->GetMean()-w*his->GetRMS();
    up = his->GetMean()+w*his->GetRMS();    
    his->Fit("gaus","Q0","",low,up); his2->Draw("colz");
    module->Draw("same");
    fit = his->GetFunction("gaus");
  }

  //  outf.close();
  cTop->SaveAs(topName.Data());
  cBot->SaveAs(botName.Data());

}
Пример #5
0
//void testFit(int count=3,Double_t ptmin=30.,Double_t ptmax=40,TString sample="PbPb")
void compareUpgrade(int option=2)
{

  int count; Double_t ptmin; Double_t ptmax; TString sample;
  int nmin,nmax,mymaxhisto;
  
  if (option==1)
  {count=3; ptmin=30.; ptmax=40; sample="PbPb"; mymaxhisto=2000;  };
  if (option==2)
  {count=1; ptmin=2.; ptmax=3; sample="PbPbMB"; mymaxhisto=600000;};


  TCanvas* c= new TCanvas(Form("c%d",count),"",600,600);
  TFile *file=new TFile(Form("FitsFiles/Fits_%s_%d.root",sample.Data(), count));
  TH1D* h = (TH1D*)file->Get(Form("h-%d",count));
  TH1D* hMCSignal = (TH1D*)file->Get(Form("hMCSignal-%d",count));
  TH1D* hMCSwapped = (TH1D*)file->Get(Form("hMCSwapped-%d",count));
    
  TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0);

  f->SetParLimits(4,-1000,1000);
  f->SetParLimits(10,0.001,0.05);
  f->SetParLimits(2,0.01,0.1);
  f->SetParLimits(8,0.02,0.2);
  f->SetParLimits(7,0,1);
  f->SetParLimits(9,0,1);
  
  f->SetParameter(0,setparam0);
  f->SetParameter(1,setparam1);
  f->SetParameter(2,setparam2);
  f->SetParameter(10,setparam10);
  f->SetParameter(9,setparam9);

  f->FixParameter(8,setparam8);
  f->FixParameter(7,1);
  f->FixParameter(1,fixparam1);
  f->FixParameter(3,0);
  f->FixParameter(4,0);
  f->FixParameter(5,0);
  f->FixParameter(6,0);
  h->GetEntries();
  
  hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
 
  f->ReleaseParameter(1);
  hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(10,f->GetParameter(10));
  f->FixParameter(9,f->GetParameter(9));
  f->FixParameter(7,0);
  f->ReleaseParameter(8);
  f->SetParameter(8,setparam8);
  
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  
  f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(8,f->GetParameter(8));
  f->ReleaseParameter(3);
  f->ReleaseParameter(4);
  f->ReleaseParameter(5);
  f->ReleaseParameter(6);

  f->SetLineColor(kRed);
  

  /*
  TCanvas*mycanvas=new TCanvas("mycanvas","mycanvas",1000,500);
  mycanvas->Divide(2,1);
  mycanvas->cd(1);
  hMCSignal->Draw();
  mycanvas->cd(2);
  hMCSwapped->Draw();
  mycanvas->SaveAs("mycanvas.pdf");
*/
  
  h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  //f->ReleaseParameter(2);                                     // you need to release these two parameters if you want to perform studies on the sigma shape
  //f->ReleaseParameter(10);                                   // you need to release these two parameters if you want to perform studies on the sigma shape
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  
  std::cout<<"parameter 10="<<f->GetParameter(10)<<std::endl;

  TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetParameter(2,f->GetParameter(5));
  background->SetParameter(3,f->GetParameter(6));
  background->SetLineColor(4);
  background->SetRange(minhisto,maxhisto);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(7));
  mass->SetParError(4,f->GetParError(9));
  mass->SetParError(5,f->GetParError(10));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
  
  TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])");
  massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8));
  massSwap->SetParError(0,f->GetParError(0));
  massSwap->SetParError(1,f->GetParError(1));
  massSwap->SetParError(2,f->GetParError(7));
  massSwap->SetParError(3,f->GetParError(8));
  massSwap->SetFillColor(kGreen+4);
  massSwap->SetFillStyle(3005);
  massSwap->SetLineColor(kGreen+4);
  massSwap->SetLineWidth(3);
  massSwap->SetLineStyle(1);
  
  h->SetXTitle("m_{#piK} (GeV/c^{2})");
  h->SetYTitle("Entries / (5 MeV/c^{2})");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");

  background->Draw("same");   
  mass->SetRange(minhisto,maxhisto);	
  mass->Draw("same");
  massSwap->SetRange(minhisto,maxhisto);
  massSwap->Draw("same");
  f->Draw("same");
  
  Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
  Double_t yieldtotal = f->Integral(minhisto,maxhisto)/binwidthmass;
  Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);
  
  std::cout<<"yield signal="<<yield<<std::endl;
  std::cout<<"total counts="<<yieldtotal<<std::endl;

  TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f");
  leg->AddEntry(massSwap,"K-#pi swapped","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  TLatex Tl;
  Tl.SetNDC();
  Tl.SetTextAlign(12);
  Tl.SetTextSize(0.04);
  Tl.SetTextFont(42);
  Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Performance");
  Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data()));

  TLatex* tex;

  tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  tex = new TLatex(0.22,0.83,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  h->GetFunction(Form("f%d",count))->Delete();
  TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun");
  histo_copy_nofitfun->Draw("esame");

 TH1D* hTest = new TH1D("hTest","",nbinsmasshisto,minhisto,maxhisto);

 for (int m=0;m<yieldtotal;m++){
 double r = f->GetRandom();
 hTest->Fill(r);
 
 }

 TF1* ffaketotal=(TF1*)f->Clone("ffake");
 TF1* ffakemass=(TF1*)mass->Clone("ffakemass");
 TF1* ffakebackground=(TF1*)background->Clone("ffakebackground");
 TF1* ffakemassSwap=(TF1*)massSwap->Clone("ffakemassSwap");
 
 Double_t yieldtotal_original = ffaketotal->Integral(minhisto,maxhisto)/binwidthmass;
 Double_t yieldmass_original = ffakemass->Integral(minhisto,maxhisto)/binwidthmass;
 Double_t yieldbackground_original = ffakebackground->Integral(minhisto,maxhisto)/binwidthmass;
 Double_t yieldswapped_original = ffakemassSwap->Integral(minhisto,maxhisto)/binwidthmass;

 TH1D* hTestFake = new TH1D("hTestFake","",nbinsmasshisto,minhisto,maxhisto);
  ffakemass->SetParameter(2,ffaketotal->GetParameter(2)*0.8);
  ffakemass->SetParameter(10,ffaketotal->GetParameter(10)*0.8);
 
Double_t yieldmass_modified= ffakemass->Integral(minhisto,maxhisto)/binwidthmass;

cout<<"mass original="<<yieldmass_original<<endl;
cout<<"mass modified="<<yieldmass_modified<<endl;

 for (int m=0;m<yieldmass_original*scalefactor;m++){
   double r = ffakemass->GetRandom();
   hTestFake->Fill(r);
 }

  for (int m=0;m<(int)(yieldbackground_original*scalefactor*bkgreduction);m++){
   double r = ffakebackground->GetRandom();
   hTestFake->Fill(r);
 }
 
 for (int m=0;m<(int)(yieldswapped_original*scalefactor*bkgreduction);m++){
   double r = ffakemassSwap->GetRandom();
   hTestFake->Fill(r);
 }

 TCanvas*c2=new TCanvas("c2","c2",500,500);
 c2->cd();
 hTest->SetMaximum(2000);
  hTest->SetXTitle("m_{#piK} (GeV/c^{2})");
  hTest->SetYTitle("Entries / (5 MeV/c^{2})");
  hTest->GetXaxis()->CenterTitle();
  hTest->GetYaxis()->CenterTitle();
  hTest->SetAxisRange(0,hTest->GetMaximum()*1.*1.2,"Y");
  hTest->GetXaxis()->SetTitleOffset(1.3);
  hTest->GetYaxis()->SetTitleOffset(1.8);
  hTest->GetXaxis()->SetLabelOffset(0.007);
  hTest->GetYaxis()->SetLabelOffset(0.007);
  hTest->GetXaxis()->SetTitleSize(0.045);
  hTest->GetYaxis()->SetTitleSize(0.045);
  hTest->GetXaxis()->SetTitleFont(42);
  hTest->GetYaxis()->SetTitleFont(42);
  hTest->GetXaxis()->SetLabelFont(42);
  hTest->GetYaxis()->SetLabelFont(42);
  hTest->GetXaxis()->SetLabelSize(0.04);
  hTest->GetYaxis()->SetLabelSize(0.04);
  hTest->SetMarkerSize(0.8);
  hTest->SetMarkerStyle(20);
  hTest->SetStats(0);
  hTest->Draw("e");

 hTest->SetLineColor(1);
 hTest->SetMarkerColor(1);
  hTestFake->SetLineColor(2);
 hTestFake->SetMarkerColor(2);

 
 hTest->Draw("ep");
 hTestFake->Draw("epsame");

  TLegend* myleg = new TLegend(0.2177419,0.6292373,0.6633065,0.7266949,NULL,"brNDC");
  myleg->SetBorderSize(0);
  myleg->SetTextSize(0.04);
  myleg->SetTextFont(42);
  myleg->SetFillStyle(0);
  myleg->AddEntry(hTest,"Current CMS, |y|<1, L_{int}=0.5/nb","pl");
  myleg->AddEntry(hTestFake,"Upgraded CMS, |y|<2, L_{int}=1.5/nb","l");
  myleg->Draw("same");

  TLatex* mytex;

  mytex = new TLatex(0.22,0.83,Form("%.0f < p_{T} < %.0f GeV/c",ptmin,ptmax));
  mytex->SetNDC();
  mytex->SetTextFont(42);
  mytex->SetTextSize(0.04);
  mytex->SetLineWidth(2);
  mytex->Draw();
  
  TLatex* mychannel;

  mychannel = new TLatex(0.22,0.765,"D^{0} #rightarrow K#pi");
  mychannel->SetNDC();
  mychannel->SetTextFont(42);
  mychannel->SetTextSize(0.055);
  mychannel->SetLineWidth(2);
  mychannel->Draw();

  TLatex myTl;
  myTl.SetNDC();
  myTl.SetTextAlign(12);
  myTl.SetTextSize(0.04);
  myTl.SetTextFont(42);
  myTl.DrawLatex(0.2,0.90, "#scale[1.25]{CMS} Performance");
  myTl.DrawLatex(0.63,0.90, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data()));
  
  
  TFile*foutput=new TFile(Form("foutput_%s.root",sample.Data()),"recreate");
  foutput->cd();
  hTest->SetName("hTest");
  hTestFake->SetName("hTestFake");
  hTest->SetMaximum(mymaxhisto);
  hTest->Write();
  hTestFake->SetMaximum(mymaxhisto);
  hTestFake->Write();
  hMCSignal->Write();
  hMCSwapped->Write();
  c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.pdf",sample.Data()));
  c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.png",sample.Data()));

 
}
Пример #6
0
// nEvents is how many events we want.
int makeEventSample(Int_t nEvents)
{
  // Load needed libraries
  loadLibraries();

  // Create an instance of the Pythia event generator ...
  TPythia6* pythia = new TPythia6;

  // ... and initialise it to run p+p at sqrt(200) GeV in CMS
  pythia->Initialize("cms", "p", "p", 200);

  // Open an output file
  TFile* file = TFile::Open(FILENAME, "RECREATE");
  if (!file || !file->IsOpen()) {
    Error("makeEventSample", "Couldn;t open file %s", FILENAME);
    return 1;
  }

  // Make a tree in that file ...
  TTree* tree = new TTree(TREENAME, "Pythia 6 tree");

  // ... and register a the cache of pythia on a branch (It's a
  // TClonesArray of TMCParticle objects. )
  TClonesArray* particles = (TClonesArray*)pythia->GetListOfParticles();
  tree->Branch(BRANCHNAME, &particles);

  // Now we make some events
  for (Int_t i = 0; i < nEvents; i++) {
    // Show how far we got every 100'th event.
    if (i % 100 == 0)
      cout << "Event # " << i << endl;

    // Make one event.
    pythia->GenerateEvent();

    // Maybe you want to have another branch with global event
    // information.  In that case, you should process that here.
    // You can also filter out particles here if you want.

    // Now we're ready to fill the tree, and the event is over.
    tree->Fill();
  }

  // Show tree structure
  tree->Print();

  // After the run is over, we may want to do some summary plots:
  TH1D* hist = new TH1D(HISTNAME, "p_{#perp}  spectrum for  #pi^{+}",
                        100, 0, 3);
  hist->SetXTitle("p_{#perp}");
  hist->SetYTitle("dN/dp_{#perp}");
  char expression[64];
  sprintf(expression,"sqrt(pow(%s.fPx,2)+pow(%s.fPy,2))>>%s",
          BRANCHNAME, BRANCHNAME, HISTNAME);
  char selection[64];
  sprintf(selection,"%s.fKF==%d", BRANCHNAME, PDGNUMBER);
  tree->Draw(expression,selection);

  // Normalise to the number of events, and the bin sizes.
  hist->Sumw2();
  hist->Scale(3 / 100. / hist->Integral());
  hist->Fit("expo", "QO+", "", .25, 1.75);
  TF1* func = hist->GetFunction("expo");
  func->SetParNames("A", "- 1 / T");
  // and now we flush and close the file
  file->Write();
  file->Close();

  return 0;
}
Пример #7
0
int CompareP()
{
  char wkdir[1000]={"/Volumes/IR1_CPRA_X6/output"};
  TFile *outfile = new TFile("/Volumes/IR1_CPRA_X6/output/pcom.root","recreate");
  char file[21][100];
  double ene[21];
  sprintf(file[0], "001_2.0000"); ene[0] = 2.0000;
  sprintf(file[1], "002_2.0500"); ene[1] = 2.0500;
  sprintf(file[2], "003_2.1000"); ene[2] = 2.1000;
  sprintf(file[3], "004_2.1500"); ene[3] = 2.1500;
  sprintf(file[4], "005_2.1750"); ene[4] = 2.1750;
  sprintf(file[5], "006_2.2000"); ene[5] = 2.2000;
  sprintf(file[6], "007_2.2324"); ene[6] = 2.2324;
  sprintf(file[7], "008_2.3094"); ene[7] = 2.3094;
  sprintf(file[8], "009_2.3864"); ene[8] = 2.3864;
  sprintf(file[9], "010_2.3960"); ene[9] = 2.3960;
  sprintf(file[10],"011_2.5000"); ene[10]= 2.5000;
  sprintf(file[11],"012_2.6444"); ene[11]= 2.6444;
  sprintf(file[12],"013_2.6464"); ene[12]= 2.6464;
  sprintf(file[13],"014_2.7000"); ene[13]= 2.7000;
  sprintf(file[14],"015_2.8000"); ene[14]= 2.8000;
  sprintf(file[15],"016_2.9000"); ene[15]= 2.9000;
  sprintf(file[16],"017_2.9500"); ene[16]= 2.9500;
  sprintf(file[17],"018_2.9810"); ene[17]= 2.9810;
  sprintf(file[18],"019_3.0000"); ene[18]= 3.0000;
  sprintf(file[19],"020_3.0200"); ene[19]= 3.0200;
  sprintf(file[20],"021_3.0800"); ene[20]= 3.0800;
  double mka = 0.493677;
  double mmu = 0.1057;

  double enee[21]={0};
  double pka[21],pkae[21],pka3e[21],pka5e[21];
  double pmu[21],pmue[21],pmu3e[21],pmu5e[21];

  gStyle->SetOptStat(0);
  for (int enei=0; enei<21; enei++){
    char filename[100];
    sprintf(filename,"%s/mcBB_%s.root",wkdir,file[enei]);
    TFile *filei1 = new TFile(filename);
    TH1D *hpee   = (TH1D*)filei1->Get("hpNocut");
    TH2D *h2pee  = (TH2D*)filei1->Get("h2pNocut");
    TH1D *hpeec  = (TH1D*)filei1->Get("hpcutTOF");
    TH2D *h2peec = (TH2D*)filei1->Get("h2pcutTOF");

    sprintf(filename,"%s/mcdimu_%s.root",wkdir,file[enei]);
    TFile *filei2 = new TFile(filename);
    TH1D *hpmu   = (TH1D*)filei2->Get("hpNocut");
    TH2D *h2pmu  = (TH2D*)filei2->Get("h2pNocut");
    TH1D *hpmuc  = (TH1D*)filei2->Get("hpcutTOF");
    TH2D *h2pmuc = (TH2D*)filei2->Get("h2pcutTOF");

    sprintf(filename,"%s/mchad_%s.root",wkdir,file[enei]);
    TFile *filei3 = new TFile(filename);
    TH1D *hpha   = (TH1D*)filei3->Get("hpNocut");
    TH2D *h2pha  = (TH2D*)filei3->Get("h2pNocut");
    TH1D *hphac  = (TH1D*)filei3->Get("hpcutTOF");
    TH2D *h2phac = (TH2D*)filei3->Get("h2pcutTOF");

    sprintf(filename,"%s/KKsel_%03d_myxs.root",wkdir,enei+1);
    TFile *filei4 = new TFile(filename);
    TH1D *hpka   = (TH1D*)filei4->Get("hpNocut");
    TH2D *h2pka  = (TH2D*)filei4->Get("h2pNocut");
    TH1D *hpkac  = (TH1D*)filei4->Get("hpcutTOF");
    TH2D *h2pkac = (TH2D*)filei4->Get("h2pcutTOF");

    TCanvas *c1 = new TCanvas();
    TLegend *legend = new TLegend(0.15, 0.6,0.4,0.85);
    if (hpka!=0) {hpka->SetFillColor(0);hpka->SetLineColor(1);hpka->SetMarkerColor(1);hpka->Draw(); legend->AddEntry(hpka,"p_{K}");} else continue;
    if (hpee!=0) {hpee->SetFillColor(0);hpee->SetLineColor(2);hpee->SetMarkerColor(2);hpee->Draw("same");legend->AddEntry(hpee,"p_{e}");}
    if (hpmu!=0) {hpmu->SetFillColor(0);hpmu->SetLineColor(3);hpmu->SetMarkerColor(3);hpmu->Draw("same");legend->AddEntry(hpmu,"p_{#mu}");}
    if (hpha!=0) {hpha->SetFillColor(0);hpha->SetLineColor(4);hpha->SetMarkerColor(4);hpha->Draw("same");legend->AddEntry(hpha,"p_{had}");}
    legend->Draw();
    
    TCanvas *c3 = new TCanvas();
    TLegend *lgd3 = new TLegend(0.15, 0.6,0.4,0.85);
    if (hpkac!=0) {hpkac->SetFillColor(0);hpkac->SetLineColor(1);hpkac->SetMarkerColor(1);hpkac->Draw(); lgd3->AddEntry(hpkac,"p_{K}");} else continue;
    if (hpeec!=0) {hpeec->SetFillColor(0);hpeec->SetLineColor(2);hpeec->SetMarkerColor(2);hpeec->Draw("same");lgd3->AddEntry(hpeec,"p_{e}");}
    if (hpmuc!=0) {hpmuc->SetFillColor(0);hpmuc->SetLineColor(3);hpmuc->SetMarkerColor(3);hpmuc->Draw("same");lgd3->AddEntry(hpmuc,"p_{#mu}");}
    if (hphac!=0) {hphac->SetFillColor(0);hphac->SetLineColor(4);hphac->SetMarkerColor(4);hphac->Draw("same");lgd3->AddEntry(hphac,"p_{had}");}
    lgd3->Draw();
    
    TCanvas *c2 = new TCanvas();
    TLegend *lgd2 = new TLegend(0.15, 0.6,0.4,0.85);
    if(h2pka!=0){h2pka->SetFillColor(0);h2pka->SetLineColor(1);h2pka->SetMarkerColor(1);h2pka->Draw();lgd2->AddEntry(h2pka,"p_{K}");} else continue;
    if(h2pee!=0){h2pee->SetFillColor(0);h2pee->SetLineColor(2);h2pee->SetMarkerColor(2);h2pee->Draw("same");lgd2->AddEntry(h2pee,"p_{e}");}
    if(h2pmu!=0){h2pmu->SetFillColor(0);h2pmu->SetLineColor(3);h2pmu->SetMarkerColor(3);h2pmu->Draw("same");lgd2->AddEntry(h2pmu,"p_{#mu}");}
    if(h2pha!=0){h2pha->SetFillColor(0);h2pha->SetLineColor(4);h2pha->SetMarkerColor(4);h2pha->Draw("same");lgd2->AddEntry(h2pha,"p_{had}");}
    lgd2->Draw();
    
    TCanvas *c4 = new TCanvas();
    TLegend *lgd4 = new TLegend(0.15, 0.6,0.4,0.85);
    if (h2pkac!=0) {h2pkac->SetFillColor(0);h2pkac->SetLineColor(1);h2pkac->SetMarkerColor(1);h2pkac->Draw(); lgd4->AddEntry(h2pkac,"p_{K}");} else continue;
    if (h2peec!=0) {h2peec->SetFillColor(0);h2peec->SetLineColor(2);h2peec->SetMarkerColor(2);h2peec->Draw("same");lgd4->AddEntry(h2peec,"p_{e}");}
    if (h2pmuc!=0) {h2pmuc->SetFillColor(0);h2pmuc->SetLineColor(3);h2pmuc->SetMarkerColor(3);h2pmuc->Draw("same");lgd4->AddEntry(h2pmuc,"p_{#mu}");}
    if (h2phac!=0) {h2phac->SetFillColor(0);h2phac->SetLineColor(4);h2phac->SetMarkerColor(4);h2phac->Draw("same");lgd4->AddEntry(h2phac,"p_{had}");}
    lgd4->Draw();
    
    sprintf(filename,"%s_1p",file[enei]);
    outfile->WriteTObject(c1,filename);
    sprintf(filename,"%s_2p",file[enei]);
    outfile->WriteTObject(c2,filename);
    sprintf(filename,"%s_1p_cut",file[enei]);
    outfile->WriteTObject(c3,filename);
    sprintf(filename,"%s_2p_cut",file[enei]);
    outfile->WriteTObject(c4,filename);

    double p_ka = sqrt(pow(ene[enei]/2,2)-mka*mka);
    double p_mu = sqrt(pow(ene[enei]/2,2)-mmu*mmu);
    //std::cout<<p_ka<<' '<<p_mu<<std::endl;
    hpka->Fit("gaus","R","",p_ka-0.1,p_ka+0.1);
    hpmu->Fit("gaus","R","",p_mu-0.1,p_mu+0.1);
    pka[enei] = hpka->GetFunction("gaus")->GetParameter(1);
    pkae[enei]= hpka->GetFunction("gaus")->GetParameter(2);
    pka3e[enei]= 3*pkae[enei]/2.6*3;
    pka5e[enei]= 5*pkae[enei]/2.6*3;
    pmu[enei] = hpmu->GetFunction("gaus")->GetParameter(1);
    pmue[enei]= hpmu->GetFunction("gaus")->GetParameter(2);
    pmu3e[enei]= 3*pmue[enei]/2.6*3;
    pmu5e[enei]= 5*pmue[enei]/2.6*3;
    std::cout<<p_ka<<' ' << pka[enei]<<" "<< pkae[enei]<<std::endl;
    std::cout<<p_mu<<' ' << pmu[enei]<<" "<< pmue[enei]<<std::endl;
    
    delete filei1;
    delete filei2;
    delete filei3;
    delete filei4;
    delete c1;
    delete c2;
    delete c3;
    delete c4;
    delete legend;
    delete lgd2;
    delete lgd3;
    delete lgd4;
  }

  new TCanvas();
  TGraphErrors *graph1 = new TGraphErrors(21,ene,pka,enee,pkae);
  graph1->SetFillColor(0);
  graph1->SetMarkerStyle(24);
  TGraphErrors *graph1_1 = new TGraphErrors(21,ene,pka,enee,pkae);
  graph1_1->SetFillColor(3);
  TGraphErrors *graph1_3 = new TGraphErrors(21,ene,pka,enee,pka3e);
  graph1_3->SetFillColor(4);
  TGraphErrors *graph1_5 = new TGraphErrors(21,ene,pka,enee,pka5e);
  graph1_5->SetFillColor(2);
  //graph1->Draw("A3LP");

  TGraphErrors *graph2 = new TGraphErrors(21,ene,pmu,enee,pmue);
  graph2->SetFillColor(0);
  graph2->SetMarkerStyle(25);
  TGraphErrors *graph2_1 = new TGraphErrors(21,ene,pmu,enee,pmue);
  graph2_1->SetFillColor(3);
  TGraphErrors *graph2_3 = new TGraphErrors(21,ene,pmu,enee,pmu3e);
  graph2_3->SetFillColor(4);
  TGraphErrors *graph2_5 = new TGraphErrors(21,ene,pmu,enee,pmu5e);
  graph2_5->SetFillColor(2);
  //graph2->Draw("L3P");
  
  TMultiGraph *mg = new TMultiGraph();
  mg->SetTitle("p of 2 prong process");
  mg->Add(graph1_5);
  mg->Add(graph2_5);
  mg->Add(graph1_3);
  mg->Add(graph2_3);
  mg->Add(graph1_1);
  mg->Add(graph2_1);
  mg->Draw("ALP3");
  mg->GetXaxis()->SetTitle("#sqrt{s} (GeV)");
  mg->GetYaxis()->SetTitle("p (GeV/c)");
  graph1->Draw("PL");
  graph2->Draw("PL");

  TLegend *legend = new TLegend(0.15,0.65,0.45,0.85);
  legend->AddEntry(graph1,"p_{K}");
  legend->AddEntry(graph2,"p_{#mu}");
  legend->AddEntry(graph1_1,"1 #sigma");
  legend->AddEntry(graph1_3,"3 #sigma");
  legend->AddEntry(graph1_5,"5 #sigma");
  legend->SetMargin(0.6);
  legend->Draw();

}
Пример #8
0
// ----------------------------------------------------------------------
void invertedMuonID(string era = "2016BF", float bdt = -99., TH1D *hresult = 0) {
  if ("all" == era) {
    invertedMuonID("2016BF");
    invertedMuonID("2016GH");
    return;
  }

  TFile *fd(0), *fm0(0), *fm1(0);
  float bdtcut(0.);
  cout << "======================================================================" << endl;
  if (era == "2016BF") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016BF-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016BF-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016BF-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.30;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2016GH") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016GH-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016GH-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016GH-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.31;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2012") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2012-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.34;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2011") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2011-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.28;
    } else {
      bdtcut = bdt;
    }
  }

  TTree *td = (TTree*)fd->Get("candAnaMuMu/events");
  TTree *tm0 = (TTree*)fm0->Get("candAnaMuMu/events");
  TTree *tm1 = (TTree*)fm1->Get("candAnaMuMu/events");

  TH1D *hd0 = new TH1D("hd0", "mass", 60, 4.8, 6.0);
  TH1D *hm0 = new TH1D("hm0", "mass", 60, 4.8, 6.0);
  TH1D *hm1 = new TH1D("hm1", "mass", 60, 4.8, 6.0);
  string cut(Form("chan==0 && !gmuid &&hlt1&&tos&&l1t &&bdt>%4.3f && m < 6 && m > 4.8", bdtcut));
  cout << cut << endl;
  td->Draw("m>>hd0", cut.c_str());
  tm0->Draw("m>>hm0", cut.c_str());
  tm1->Draw("m>>hm1", cut.c_str());

  c0->Clear();
  // c0->Divide(2,2);
  // c0->cd(1);
  hd0->Draw("hist");
  // B0 -> mu mu
  // c0->cd(2);
  hm0->Fit("gaus");
  double p0 = hm0->GetFunction("gaus")->GetParameter(1);
  double s0 = hm0->GetFunction("gaus")->GetParameter(2);
  cout << "p0: " << p0 << " s0: " << s0 << endl;
  // Bs -> mu mu
  // c0->cd(3);
  hm1->Fit("gaus");
  double p1 = hm1->GetFunction("gaus")->GetParameter(1);
  double s1 = hm1->GetFunction("gaus")->GetParameter(2);
  cout << "p1: " << p1 << " s1: " << s1 << endl;

  // c0->cd(4);
  TH1D *hFit = (TH1D*)hd0->Clone("hFit");
  hFit->SetTitle("");
  hFit->SetMinimum(0.);
  TF1 *f1 = new TF1("f1", adhocfunction, 4.8, 6.0, 7);
  f1->SetParameter(0, 1);  f1->SetParLimits(0, 0., 1000.);
  f1->SetParameter(1, p0); f1->FixParameter(1, p0);
  f1->SetParameter(2, s0); f1->FixParameter(2, s0);
  f1->SetParameter(3, 1);  f1->SetParLimits(3, 0., 1000.);
  f1->SetParameter(4, p1); f1->FixParameter(4, p1);
  f1->SetParameter(5, s1); f1->FixParameter(5, s1);
  f1->SetParameter(6, 1);

  hFit->Fit(f1, "RL", "", 5.1, 6.0);

  double nb0 = hFit->GetFunction("f1")->GetParameter(0);
  double eb0 = hFit->GetFunction("f1")->GetParError(0);
  double nbs = hFit->GetFunction("f1")->GetParameter(3);
  double ebs = hFit->GetFunction("f1")->GetParError(3);

  TF1 *f0 = (TF1*)hm0->GetFunction("gaus")->Clone("f0");
  TF1 *fs = (TF1*)hm1->GetFunction("gaus")->Clone("fs");

  f0->SetParameter(0, nb0); f0->SetLineColor(kRed+2);
  fs->SetParameter(0, nbs); fs->SetLineColor(kBlue);
  f0->Draw("same");
  fs->Draw("same");
  tl->DrawLatexNDC(0.10, 0.92, era.c_str());
  tl->DrawLatexNDC(0.40, 0.92, Form("BDT > %3.2f", bdtcut));
  double iB0 = f0->Integral(5.1, 5.6);
  double iBs = fs->Integral(5.1, 5.6);
  double ratioV(0.);
  double relErr(0.);
  double ratioE(0.01);
  if (iBs > 1.e-3) {
    ratioV = iB0/iBs;
    relErr = TMath::Sqrt((eb0/nb0)*(eb0/nb0) + (ebs/nbs)*(ebs/nbs));
    ratioE = relErr * ratioV;
  }

  cout << "ratio of B0 and Bs: " << iB0 << "/" << iBs << " = " << ratioV << " +/- " << ratioE << " relErr: " << relErr << endl;

  c0->SaveAs(Form("invertedMuonID-%s-%3.2f.pdf", era.c_str(), bdtcut));

  if (hresult) {
    hresult->SetBinContent(hresult->FindBin(bdtcut), ratioV);
    hresult->SetBinError(hresult->FindBin(bdtcut), ratioE);
  }
}
Пример #9
0
TF1* fit(TString variable, TString variableplot, TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax, int isMC)
{
  static int count=0;
  count++;

  TCanvas* c= new TCanvas(Form("c%d",count),"",600,600);
  TH1D* h = new TH1D(Form("h-%d",count),"",nbinsmasshisto,minhisto,maxhisto);
  TH1D* hMCSignal = new TH1D(Form("hMCSignal-%d",count),"",nbinsmasshisto,minhisto,maxhisto);
  TH1D* hMCSwapped = new TH1D(Form("hMCSwapped-%d",count),"",nbinsmasshisto,minhisto,maxhisto);
  
  TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0);
  TString mycut=Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax);
  if(isMC==1) nt->Project(Form("h-%d",count),"Dmass",TCut(weight)*TCut(mycut));   
  else nt->Project(Form("h-%d",count),"Dmass",Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax));   
  
  ntMC->Project(Form("hMCSignal-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23333))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax));   
  ntMC->Project(Form("hMCSwapped-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23344))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax));   
  
  
  TFile *fout=new TFile(Form("FitsFiles/Fits_%s_%d.root",collisionsystem.Data(),count),"recreate");
  fout->cd();
  hMCSignal->Write();
  hMCSwapped->Write();
  h->Write();  
  fout->Close();
  
  
  f->SetParLimits(4,-1000,1000);
  f->SetParLimits(10,0.001,0.05);
  f->SetParLimits(2,0.01,0.1);
  f->SetParLimits(8,0.02,0.2);
  f->SetParLimits(7,0,1);
  f->SetParLimits(9,0,1);
  
  f->SetParameter(0,setparam0);
  f->SetParameter(1,setparam1);
  f->SetParameter(2,setparam2);
  f->SetParameter(10,setparam10);
  f->SetParameter(9,setparam9);

  f->FixParameter(8,setparam8);
  f->FixParameter(7,1);
  f->FixParameter(1,fixparam1);
  f->FixParameter(3,0);
  f->FixParameter(4,0);
  f->FixParameter(5,0);
  f->FixParameter(6,0);
  h->GetEntries();
  
  hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  
  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(10,f->GetParameter(10));
  f->FixParameter(9,f->GetParameter(9));
  f->FixParameter(7,0);
  f->ReleaseParameter(8);
  f->SetParameter(8,setparam8);
  
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  
  f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(8,f->GetParameter(8));
  f->ReleaseParameter(3);
  f->ReleaseParameter(4);
  f->ReleaseParameter(5);
  f->ReleaseParameter(6);

  f->SetLineColor(kRed);
  
  h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  //f->ReleaseParameter(2);                                     // you need to release these two parameters if you want to perform studies on the sigma shape
  //f->ReleaseParameter(10);                                   // you need to release these two parameters if you want to perform studies on the sigma shape
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
  h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
  
  TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetParameter(2,f->GetParameter(5));
  background->SetParameter(3,f->GetParameter(6));
  background->SetLineColor(4);
  background->SetRange(minhisto,maxhisto);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(7));
  mass->SetParError(4,f->GetParError(9));
  mass->SetParError(5,f->GetParError(10));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
  
  TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])");
  massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8));
  massSwap->SetParError(0,f->GetParError(0));
  massSwap->SetParError(1,f->GetParError(1));
  massSwap->SetParError(2,f->GetParError(7));
  massSwap->SetParError(3,f->GetParError(8));
  massSwap->SetFillColor(kGreen+4);
  massSwap->SetFillStyle(3005);
  massSwap->SetLineColor(kGreen+4);
  massSwap->SetLineWidth(3);
  massSwap->SetLineStyle(1);
  
  h->SetXTitle("m_{#piK} (GeV/c^{2})");
  h->SetYTitle("Entries / (5 MeV/c^{2})");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");

  background->Draw("same");   
  mass->SetRange(minhisto,maxhisto);	
  mass->Draw("same");
  massSwap->SetRange(minhisto,maxhisto);
  massSwap->Draw("same");
  f->Draw("same");
  
  Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
  Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);
  
  std::cout<<"YIELD="<<yield<<"and error"<<yieldErr<<std::endl;
  std::cout<<"relative error="<<yieldErr/yield<<std::endl;

  TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f");
  leg->AddEntry(massSwap,"K-#pi swapped","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  TLatex Tl;
  Tl.SetNDC();
  Tl.SetTextAlign(12);
  Tl.SetTextSize(0.04);
  Tl.SetTextFont(42);
  Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data()));

  TLatex* tex;

  tex = new TLatex(0.22,0.78,Form("%.1f < %s  < %.1f",ptmin,variableplot.Data(),ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  tex = new TLatex(0.22,0.83,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  h->GetFunction(Form("f%d",count))->Delete();
  TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun");
  histo_copy_nofitfun->Draw("esame");
//
  if(nBins==1) c->SaveAs(Form("DMass-inclusive%s_%d.pdf",collisionsystem.Data(),count));
  else c->SaveAs(Form("DMass%s_%d.pdf",collisionsystem.Data(),count));
  
  return mass;
}
Пример #10
0
void sqrtMethodSameSign(int ptBin, double ptCutLo, double ptCutHi, int massBin, double mCutLo, double mCutHi, int etaBin, double etaCutLo, double etaCutHi){
	
	//OPTIONS AND CUTS------------
	bool useBlueBeam = true;
	bool useYellowBeam = true;
	bool randomizeSpin = false;
	
	double PI = 3.14159265359;
	
	cout << "\n";
	if (useBlueBeam && useYellowBeam){cout << "using both beams-----" << endl;}
	if (useBlueBeam && !useYellowBeam){cout << "using blue beam------" << endl;}
	if (!useBlueBeam && useYellowBeam){cout << "using yellow beam----" << endl;}
	cout << "\n";
	if (randomizeSpin){cout << "randomizing spin-----" << endl;}
	
	
	
	//PION PAIR CUTS:
	/*
	 double ptCutLo = 4;
	 double ptCutHi = 10;
	 double mCutLo = .4;
	 double mCutHi = 1;
	 double etaCutLo = -1.4;
	 double etaCutHi = 1.4;
	 //*/
	//double phiCutLo = -.5;
	//double phiCutHi = .5;
	
	//----------------------------	
	
	
	//LOAD LIBS
	cout << "\n";
	gROOT->Macro("StRoot/LoadLibs.C");
	gSystem->Load("sameSignPair");
	cout << " loading of sameSignPair library done" << endl;

	
	
	//SET UP INPUT FILE	
	TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_samesign_4_14/allSameSign_4_14.root");
	
	
	
	//SET UP TREE TO RECEIVE INPUT
	sameSignPair* pair1 = new sameSignPair();
	TTree* pairTree = infile->Get("sameSignTree");
	pairTree->SetBranchAddress("sameSignPair", &pair1);
	
	
	//SET UP HISTOGRAMS
	
	//event variable histograms
	TH1D* hInvarM    = new TH1D("invarM","invarM",80,0,2);
	TH1D* hEtaTot	   = new TH1D("etaTot","etaTot",60,-1.5,1.5);
	TH1D* hPhiR      = new TH1D("hPhiR","hPhiR",60,-4,4);
	TH1D* hPhiS      = new TH1D("hPhiS","hPhiS",60,-4,4);
	TH1D* hPhiSR     = new TH1D("hPhiSR","hPhiSR",60,-4,4);
	TH1D* hTheta     = new TH1D("hTheta","hTheta",30,-0.85,4);
	TH1D* hCosTheta  = new TH1D("hCosTheta","hCosTheta",80,-1,1);
	TH1D* hZ         = new TH1D("hZ","hZ",80,0,1);
	TH1D* hPtot      = new TH1D("hPtot","hPtot",80,0,20);
	TH1D* hPtTOT     = new TH1D("hPt","hPt",80,0,15);
	
	//histos for asym analysis	
	double histMin = -PI;
	double histMax =  PI;
	const int binNumber = 16;
	
	TH1D * hNumberUp   = new TH1D("hNumberUp","hNumberUp",binNumber,histMin,histMax);
	TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",binNumber,histMin,histMax);
	
	TH1D * hDiff  = new TH1D("hNumberSum","hNumberSum",binNumber,histMin,histMax);
	TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax);
	
	
	//BEAM POLARIZATION
	
	ifstream polFile;
	polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt");
	
	
	map<int, double> polarizationOfFill_Y;
	map<int, double> polErrOfFill_Y;
	
	map<int, double> polarizationOfFill_B;
	map<int, double> polErrOfFill_B;
	
	
	
	int    fill;
	int    beamE;
	int    startT;
	string plusminus;
	
	double pAvrgBlue;
	double pErrAvrgBlue;
	
	double pInitialBlue;
	double pErrInitialBlue;
	double dPdTBlue;
	double dPdTErrBlue;
	
	double pAvrgYellow;
	double pErrAvrgYellow;
	
	double pInitialYellow;
	double pErrInitialYellow;
	double dPdTYellow;
	double dPdTErrYellow;
	
	string header;
	
	for (int i=0; i<19; i++){polFile >> header;}
	
	while (!polFile.eof())
	{
		
		polFile >> fill;
		polFile >> beamE;
		polFile >> startT;
		
		polFile >> pAvrgBlue;
		polFile >> plusminus;
		polFile >> pErrAvrgBlue;
		
		polFile >> pInitialBlue;
		polFile >> plusminus;
		polFile >> pErrInitialBlue;
		
		polFile >> dPdTBlue;
		polFile >> plusminus;
		polFile >> dPdTErrBlue;
		
		polFile >> pAvrgYellow;
		polFile >> plusminus;
		polFile >> pErrAvrgYellow;
		
		polFile >> pInitialYellow;
		polFile >> plusminus;
		polFile >> pErrInitialYellow;
		
		polFile >> dPdTYellow;
		polFile >> plusminus;
		polFile >> dPdTErrYellow;
		
		
		polarizationOfFill_B[fill] = pAvrgBlue/100.;
		polErrOfFill_B[fill] = pErrAvrgBlue/100.;
		
		polarizationOfFill_Y[fill] = pAvrgYellow/100.;
		polErrOfFill_Y[fill] = pErrAvrgYellow/100.;
		
		
		
	}
	
	double avgPolOfBinUp[binNumber];
	double polOfBinSumUp[binNumber];
	
	double avgPerrorOfBinUp[binNumber];
	double pErrorOfBinUp[binNumber];
	
	double avgPolOfBinDown[binNumber];
	double polOfBinSumDown[binNumber];
	
	double avgPerrorOfBinDown[binNumber];
	double pErrorOfBinDown[binNumber];
	
	for (int i=0; i<binNumber; i++)
	{
		avgPolOfBinUp[i] = 0;
		polOfBinSumUp[i] = 0;
		
		avgPerrorOfBinUp[i] = 0;
		pErrorOfBinUp[i] = 0;
		
		avgPolOfBinDown[i] = 0;
		polOfBinSumDown[i] = 0;
		
		avgPerrorOfBinDown[i] = 0;
		pErrorOfBinDown[i] = 0;
		
	}
	
	
	//   ======================================================================
	//============================================================================
	//START ANALYSIS==============================================================
	//============================================================================
	//   ======================================================================
	
	cout << pairTree->GetEntries() << endl;
	
	cout << "\n";
	cout << "<----STARTING ANALYSIS---->" << endl;
  cout << "\n";
	
	
	double blueFillNo;
	double yellowFillNo;
	
	int bin;
	
	TLorentzVector sum;
	TLorentzVector sumY;
	TLorentzVector sumB;
	
	//random number for randomizing spin.
	//set seed to zero to gaurenty unique numbers each time.
	TRandom3 r;
	r.SetSeed(0);
	
	int rand5 = 0;
	int rand6 = 0;
	int rand9 = 0;
	int rand10 = 0;
	
	
	int totalPairsFinal = 0;
	int blueD = 0;
	int blueU = 0;
	int yellowD = 0;
	int yellowU = 0;
	
	int pionStarNumber = 0;
	
	
	for (int iPair = pionStarNumber; iPair < pairTree->GetEntries(); iPair++)
	{
		if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;}
		
		//if (iPair == pionStarNumber+2000000){break;}
		
		pairTree->GetEntry(iPair);
				
		
		if (pair1->withinRadius(0.05, 0.3))
		{
			
			
			bool triggerFired = false;
			bool fromKaon = false;
			
			StTriggerId trigId = pair1->triggerIds();
			
			
			//JP0,JP1,JP2,AJP
			if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641))
			{
				triggerFired = true;
			}
			
			//BHT0VPD,BHT1VPD,BHT2BBC,BHT2
			if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531))
			{
				triggerFired = true;
			}
			
			
			if (pair1->invarientMass() > .4921 && pair1->invarientMass() < .4990)
			{
				fromKaon = true;
			}
			
			
			
			if (triggerFired)
			{
				
				
				blueFillNo   = pair1->runInfo().beamFillNumber(1); //1 = blue beam
				yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam 
				
				//cout << blueFillNo << "  " << yellowFillNo << endl;
				
				
				if (polarizationOfFill_B[blueFillNo] == 0 || polarizationOfFill_Y[yellowFillNo] == 0) //0 is gap
				{
					continue;
				}
				
				
				hInvarM->Fill(pair1->invarientMass());
				
				
				sum = pair1->pion1LV() + pair1->pion2LV();
				sumB = sum; //blue beam.
				
				
				//yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. 				
				sumY = sum;
				sumY.RotateY(PI);
				
				//cout << pair1->phiS('y')-pair1->phiR('y') << "   " << pair1->phiSR('y') << endl;
				
				//option for randomizing spin
				if (randomizeSpin)
				{
					
					int origSpinBit = pair1->spinBit();
					
					double randomSpin = r.Uniform(0, 1);
					
					int randomSpinBit;
					
					if (randomSpin >=0 && randomSpin <0.25)  {randomSpinBit = 5; rand5++;}
					if (randomSpin >=0.25 && randomSpin <0.5){randomSpinBit = 6; rand6++;}
					if (randomSpin >=0.5 && randomSpin <0.75){randomSpinBit = 9; rand9++;}
					if (randomSpin >=0.75 && randomSpin <1.0){randomSpinBit = 10; rand10++;}
					
					
					
					pair1->setSpinBit(randomSpinBit);
					
					
					
				}
				
				
				//cout << pair1->sinPhiSR('b') << "   " << pair1->cosPhiSR('b') << "   " << pair1->phiSR('b') << endl;
				
				
				//MANUALLY ALTER ANGLES FOR TESTING-----
				/*
				 double testPhiS_y = -pair1->phiS('y');
				 double testPhiR_y = pair1->phiR('y');
				 
				 double testPhiS_b = -pair1->phiS('b');
				 double testPhiR_b = pair1->phiR('b');
				 
				 
				 
				 double testPhiSR_y = testPhiS_y - testPhiR_y;
				 
				 double testPhiSR_b = testPhiS_b - testPhiR_b;
				 
				 //cout << testPhiS_b << " " << testPhiR_b << "  " << testPhiS_y << " " << testPhiR_y << endl;
				 
				 
				 if (testPhiSR_y > PI)
				 {
				 testPhiSR_y -= 2*PI;
				 }
				 
				 if (testPhiSR_y < -PI)
				 {
				 testPhiSR_y += 2*PI;
				 }
				 
				 if (testPhiSR_b > PI)
				 {
				 testPhiSR_b -= 2*PI;
				 }
				 
				 if (testPhiSR_b < -PI)
				 {
				 testPhiSR_b += 2*PI;
				 }
				 
				 //cout << testPhiSR_b << "   " << testPhiSR_y << endl;
				 //*/
				
				//CHECK CUTS
				if (sumB.Pt() > ptCutLo && sumB.Pt() < ptCutHi && sumB.M() > mCutLo && sumB.M() < mCutHi && sumB.Eta() > etaCutLo && sumB.Eta() < etaCutHi && useBlueBeam == true)
				{
					
					//BLUE BEAM SPIN UP: spin bin 9 and 10
					if (pair1->spinBit() == 9 || pair1->spinBit() == 10)
					{
						blueU++;
						
						
						//make sure to set it back if you randomized it for up/down.
						//still need origional spin bit to calc anlge.
						if (randomizeSpin){pair1->setSpinBit(origSpinBit);}
						
						bin = hNumberUp->FindBin(pair1->phiSR('b'));
						hNumberUp->Fill(pair1->phiSR('b'));
						
						//bin = hNumberUp->FindBin(testPhiSR_b);
						//hNumberUp->Fill(testPhiSR_b);
						
						
						
						polOfBinSumUp[bin] += polarizationOfFill_B[blueFillNo];
						pErrorOfBinUp[bin] += polErrOfFill_B[blueFillNo];
						
						
						//If rondomized spin, have to set the spin bit back to random
						//for next spin bit check
						if (randomizeSpin){pair1->setSpinBit(randomSpinBit);}
					}
					
					//BLUE BEAM SPIN DOWN: spin bin 5 and 6
					if (pair1->spinBit() == 5 || pair1->spinBit() == 6)
					{
						blueD++;
						
						if (randomizeSpin){pair1->setSpinBit(origSpinBit);}
						
						bin = hNumberDown->FindBin(pair1->phiSR('b'));
						hNumberDown->Fill(pair1->phiSR('b'));
						
						//bin = hNumberDown->FindBin(testPhiSR_b);
						//hNumberDown->Fill(testPhiSR_b);
						
						
						polOfBinSumDown[bin] += polarizationOfFill_B[blueFillNo];
						pErrorOfBinDown[bin] += polErrOfFill_B[blueFillNo];		
						
						if (randomizeSpin){pair1->setSpinBit(randomSpinBit);}
					}
					
				}//end blue cuts
				
				
				
				if (sumY.Pt()>ptCutLo && sumY.Pt() < ptCutHi && sumY.M() > mCutLo && sumY.M() < mCutHi && sumY.Eta() > etaCutLo && sumY.Eta() < etaCutHi && useYellowBeam == true)
				{
					
					//YELLOW BEAM SPIN UP: spin bin 6 and 10
					if (pair1->spinBit() == 6 || pair1->spinBit() == 10)
					{
						
						yellowU++;
						
						if (randomizeSpin){pair1->setSpinBit(origSpinBit);}
						
						bin = hNumberUp->FindBin(pair1->phiSR('y'));
						hNumberUp->Fill(pair1->phiSR('y'));
						
						
						//bin = hNumberUp->FindBin(testPhiSR_y);
						//hNumberUp->Fill(testPhiSR_y);
						
						
						
						polOfBinSumUp[bin] += polarizationOfFill_Y[yellowFillNo];
						pErrorOfBinUp[bin] += polErrOfFill_Y[yellowFillNo];
						
						if (randomizeSpin){pair1->setSpinBit(randomSpinBit);}
					}	
					//YELLOW BEAM SPIN DOWN: spin bit 5 and 9
					if (pair1->spinBit() == 5 || pair1->spinBit() == 9)
					{
						
						yellowD++;
						
						if (randomizeSpin){pair1->setSpinBit(origSpinBit);}
						
						bin = hNumberDown->FindBin(pair1->phiSR('y'));
						hNumberDown->Fill(pair1->phiSR('y'));
						
						//bin = hNumberDown->FindBin(testPhiSR_y);
						//hNumberDown->Fill(testPhiSR_y);
						
						
						polOfBinSumDown[bin] += polarizationOfFill_Y[yellowFillNo];
						pErrorOfBinDown[bin] += polErrOfFill_Y[yellowFillNo];
						
						if (randomizeSpin){pair1->setSpinBit(randomSpinBit);}
					}
				}//end yellow cuts
			}//end triger check
		}//end radius check
	}//end pairTree loop
	
	
	//CALCULATE ASYMMETRY BIN BY BIN
	cout << "\n";
	cout << "<----CALCULATING ASYMMETRY---->" << endl;
	cout << "\n";
	
	for (int ibin=1; ibin<=binNumber; ibin++)
	{
		
		if (ibin <= binNumber*0.5)
		{
			double nUp   = hNumberUp->GetBinContent(ibin);
			double nUpPi = hNumberUp->GetBinContent(ibin+binNumber*0.5);
			
			double nDown   = hNumberDown->GetBinContent(ibin);
			double nDownPi = hNumberDown->GetBinContent(ibin+binNumber*0.5);
			
			
			int binIndexPi = ibin+binNumber*0.5;
			
			double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi);
			double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown);
			
			double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi);
			
		}
		else
		{
			double nUp   = hNumberUp->GetBinContent(ibin);
			double nUpPi = hNumberUp->GetBinContent(ibin-binNumber*0.5);
			
			double nDown   = hNumberDown->GetBinContent(ibin);
			double nDownPi = hNumberDown->GetBinContent(ibin-binNumber*0.5);
			
			int binIndexPi = ibin-binNumber*0.5;
			
			double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi);
			double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown);
			
			double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi);
			
			double realAvgPolE = (pErrorOfBinUp[ibin]+pErrorOfBinDown[binIndexPi]+pErrorOfBinUp[binIndexPi]+pErrorOfBinDown[ibin])/(nUp+nUpPi+nDown+nDownPi);
			
		}
		
		
		cout << avgPolA << "   " << avgPolB << endl;
		
		
		
		
		hDiff->SetBinContent(ibin, sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi));
		
		//hAut->SetBinContent(ibin, (1/avgPolA * sqrt(nUp*nDownPi) - 1/avgPolB * sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi))    );
		
		
		hAut->SetBinContent(ibin, 1/realAvgPol * (sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi))    );
		
		
		
		
		//error
		if (realAvgPol*pow(sqrt(nUp*nDownPi)+sqrt(nDown*nUpPi), 2) != 0)
		{
			
			double a = sqrt(nUp*nDownPi);
			double b = sqrt(nUpPi*nDown);
			
			
			double firstTerm = realAvgPol**2 * (nUpPi*nDown*(nUp+nDownPi) + nDownPi*nUp*(nUpPi+nDown));
			
			//double secondTerm = ((nUp*nDownPi)**2 +(nUpPi*nDown)**2 - 2*nUp*nDown*nUpPi*nDownPi)*realAvgPolE**2;
			
			double secondTerm = 0;
			
			
			double binError = 1/realAvgPol**2 * 1/(a+b)**2 * sqrt(firstTerm + secondTerm);
			
			
		}	
		else
		{
			double binError = 0.01;
			cout << "bin " << ibin << " Has problem with error" << endl;
		}
		
		hAut->SetBinError(ibin, binError);
		
	}//end Asym calc
	
	
	
	//DRAW HISTOGRAMS
	
	hInvarM->Draw();
	
	TCanvas* cNup = new TCanvas();
	hNumberUp->Draw();
	
	TCanvas* cNdown = new TCanvas();
	hNumberDown->Draw();
	
	TCanvas* cAut = new TCanvas();
	cAut->SetName("cAut");
	
	TF1* fitFunc = new TF1("fitFunc","[0]*cos(x)+[1]",-PI,PI);
	hAut->Fit("fitFunc","R");
	hAut->Draw();
	
	hAut->GetXaxis()->SetTitle("#phi_{S} - #phi_{R}");
	
	char title[150];
	sprintf(title, "%.1f < P_{T}^{#pi^{1}#pi^{2}} < %.1f  %.1f < M_{inv}^{#pi^{1}#pi^{2}} < %.1f  %.1f < #eta^{#pi^{1}#pi^{2}} < %.1f", ptCutLo, ptCutHi, mCutLo, mCutHi, etaCutLo, etaCutHi);
	
	hAut->SetTitle(title);
	
	
	cout << "Asym  = " << hAut->GetFunction("fitFunc")->GetParameter(0) << endl;
	cout << "error = " << hAut->GetFunction("fitFunc")->GetParError(0) << endl;
	cout << "chi2  = " << hAut->GetFunction("fitFunc")->GetChisquare() << endl;
	cout << "Nup   = " << hNumberUp->GetEntries() << endl;
	cout << "Ndown = " << hNumberDown->GetEntries() << endl;
  cout << "ran5  = " << rand5 << endl;
  cout << "ran6  = " << rand6 << endl;
  cout << "ran9  = " << rand9 << endl;
  cout << "ran10 = " << rand10 << endl;
	cout << "blueU = " << blueU << endl;
	cout << "blueD = " << blueD << endl;
	cout << "yellowU = " << yellowU << endl;
	cout << "yellowD = " << yellowD << endl;
	
	
	
	
	//SAVE CANVAS	
	
	
	stringstream pt;
	stringstream eta;
	stringstream mass;
	
	string part1 = "_ptBin";
	string part2 = "_massBin";
	string part3 = "_etaBin";
	
	string ptBinStr;
	string etaBinStr;
	string massBinStr;
	
	pt << ptBin;
	
	eta << etaBin;
	
	mass << massBin;
	
	if (ptBin == 9){ptBinStr = "All";}
	else{	ptBinStr = pt.str();}
	
	if (massBin == 9){massBinStr = "All";}
	else{	massBinStr = mass.str();}
	
	if (etaBin == 9){etaBinStr = "All";}
	else{	etaBinStr = eta.str();}
	
	cout << "total pairs " << totalPairsFinal << endl;
	
	
	stringstream pionNum;
	pionNum << pionStarNumber; 
	string pionNumStr = pionNum.str();
	
	
	string outFileName = "./results_samesign_4_14/sameSign"+part1+ptBinStr+part2+massBinStr+part3+etaBinStr+".root";
	TFile* outFile = new TFile(outFileName.c_str(),"Recreate");
	
	
	cout << "---WRITING FILE---" << endl; 
	//cAut->SaveAs(outFileName.c_str());
	hAut->Write();
	hNumberUp->Write();
	hNumberDown->Write();
	
	cout << "---END---" << endl; 
}
Пример #11
0
void readPullBias(char*prefix="pull_bias"){

  gSystem->mkdir(Form("figures_%s",prefix));
  char* dec[2] = {"EB","EE"};
  const int fBinsPt[]={21,23,26,30,35,40,45,50,60,85,120,300};
  const int nPtBin = sizeof(fBinsPt)/sizeof(fBinsPt[0])-1;
  const int NRUNS=8;

  ofstream foutm;
  foutm.open("mean.dat");

  ofstream fouts;
  fouts.open("sigma.dat");

  TH1D* hpull = new TH1D("hpull","",50,-5.0,5.0);
  hpull->SetXTitle("(Fit-Input)/Fit_err");
  TH1D* hbias = new TH1D("hbias","",100,-0.5,0.5);
  hbias->SetXTitle("(Fit-Input)/Input");

  TCanvas* c1 = new TCanvas("c1","",500,500);

  char tmp[1000];
  for(int ieta=0; ieta < 2; ieta++){
    for(int ipt=0; ipt < nPtBin; ipt++){
      hpull->Reset();
      hbias->Reset();
      for(int irun=0; irun < NRUNS; irun++){
	sprintf(tmp,"%s%d_%s_pt%d.dat",prefix,irun,dec[ieta],fBinsPt[ipt]);		cout << "Opening file " << tmp << endl;
	FILE *infile =  fopen(tmp,"r");  
	cout << "Opened file " << tmp << endl;

	Double_t pull=-100., bias=-100.; // combined isolation, pt, eta
	int flag = 1;
	if(infile==NULL){
	  cout << "File does not exist" << endl;
	  continue;
	}
	  
	while (flag!=-1){
	  flag =fscanf(infile,"%lf %lf",&pull, &bias);
	  if(flag!=-1){
	    hpull->Fill(pull);
	    hbias->Fill(bias);
	  }
 
	}// keep reading files as long as text exists

      } // end of iterations
      
      cout << hpull->GetEntries() << endl;
      cout << hbias->GetEntries() << endl;
 
      hpull->SetTitle(Form("%s, pt = %d-%d GeV",dec[ieta],
			   fBinsPt[ipt],fBinsPt[ipt+1]));
      
      hbias->SetTitle(Form("%s, pt = %d-%d GeV",dec[ieta],
			   fBinsPt[ipt],fBinsPt[ipt+1]));
      if(hpull->GetEntries()<1)continue;
      hpull->Fit("gaus");
      TF1* f1 = hpull->GetFunction("gaus");
      foutm << dec[ieta] << " pt" << fBinsPt[ipt] << " pull: " << f1->GetParameter(1) << " +- " << f1->GetParError(1) << endl;
      fouts << dec[ieta] << " pt" << fBinsPt[ipt] << " pull: " << f1->GetParameter(2) << " +- " << f1->GetParError(2) << endl;

      c1->Print(Form("figures_%s/pull_%s_%s_pt%d.png",
		     prefix,prefix,dec[ieta],fBinsPt[ipt]));

      if(hbias->GetEntries()<1)continue;
      hbias->Fit("gaus");
      TF1* f2 = hbias->GetFunction("gaus");
      foutm << dec[ieta] << " pt" << fBinsPt[ipt] << " bias: " << f2->GetParameter(1) << " +- " << f2->GetParError(1) << endl;
      fouts << dec[ieta] << " pt" << fBinsPt[ipt] << " bias: " << f2->GetParameter(2) << " +- " << f2->GetParError(2) << endl;
      c1->Print(Form("figures_%s/bias_%s_%s_pt%d.png",
		     prefix,prefix,dec[ieta],fBinsPt[ipt]));

    } // end of loop over pt bins
  } // end of loop over eta bins



}
void drawMixedEvent()
{
  gStyle->SetOptStat(0);
  gStyle->SetLabelFont(132, "x");
  gStyle->SetLabelFont(132, "y");
  gStyle->SetTitleFont(132, "x");
  gStyle->SetTitleFont(132, "y");
  gStyle->SetLegendFont(132);

  TFile *f = new TFile("mixedEventSeparatedByCharge.root");

  const float massFrom = 0;
  const float massTo = 3;
  const float fixedBinWidth = 0.01;
  const int massNBins = (massTo - massFrom) / fixedBinWidth;

  TCanvas *C = new TCanvas("C", "mass plot", 500, 500);
  TH1D* sig = new TH1D("sig", "", massNBins, massFrom, massTo);
  TH1D* bkgSELS = new TH1D("bkgSELS", "", massNBins, massFrom, massTo);
  TH1D* bkgMEUS = new TH1D("bkgMEUS", "", massNBins, massFrom, massTo);
  TH1D* bkgMELS = new TH1D("bkgMELS", "", massNBins, massFrom, massTo);

  //--------------------------------------------------
  for (int iCent = minCent; iCent < maxCent; ++iCent)
  {
    for (int iVz = 0; iVz < 10; ++iVz)
    {
      std::string baseName = Form("Cent_%i_Vz_%i",iCent,iVz);

      TH2F* hSE_LS = static_cast<TH2F*>(f->Get(Form("%s_se_ls_mass", baseName.data())));
      TH2F* hSE_US_plus = static_cast<TH2F*>(f->Get(Form("%s_se_us_plus_mass", baseName.data())));
      TH2F* hSE_US_minus = static_cast<TH2F*>(f->Get(Form("%s_se_us_minus_mass", baseName.data())));
      TH2F* hME_LS = static_cast<TH2F*>(f->Get(Form("%s_me_ls_mass", baseName.data())));
      TH2F* hME_US_plus = static_cast<TH2F*>(f->Get(Form("%s_me_us_plus_mass", baseName.data())));
      TH2F* hME_US_minus = static_cast<TH2F*>(f->Get(Form("%s_me_us_minus_mass", baseName.data())));

      const int firstPtBin = 10.*minPt + 1;
      cout << "first bin " << firstPtBin << endl;
      const int lastPtBin = 10.*maxPt;
      cout << "last bin " << lastPtBin << endl;

      TH1D* massProj_SE_LS = hSE_LS->ProjectionY(Form("%s_se_ls_mass_proj", baseName.data()), firstPtBin, lastPtBin);
      TH1D* massProj_SE_US_plus = hSE_US_plus->ProjectionY(Form("%s_se_us_plus_mass_proj", baseName.data()), firstPtBin, lastPtBin);
      TH1D* massProj_SE_US_minus = hSE_US_minus->ProjectionY(Form("%s_se_us_minus_mass_proj", baseName.data()), firstPtBin, lastPtBin);
      TH1D* massProj_ME_LS = hME_LS->ProjectionY(Form("%s_me_ls_mass_proj", baseName.data()), firstPtBin, lastPtBin);
      TH1D* massProj_ME_US_plus = hME_US_plus->ProjectionY(Form("%s_me_us_plus_mass_proj", baseName.data()), firstPtBin, lastPtBin);
      TH1D* massProj_ME_US_minus = hME_US_minus->ProjectionY(Form("%s_me_us_minus_mass_proj", baseName.data()), firstPtBin, lastPtBin);

      // add the bin content
      const int firstBin = massFrom / fixedBinWidth;
      for (int iBin = 0; iBin < massNBins; ++iBin)
      {
	const int histBin = iBin+1;
	const int movedBin = firstBin + iBin + 1;

	sig->SetBinContent(histBin, massProj_SE_US_plus->GetBinContent(movedBin) + sig->GetBinContent(histBin));
	sig->SetBinContent(histBin, massProj_SE_US_minus->GetBinContent(movedBin) + sig->GetBinContent(histBin));
	bkgSELS->SetBinContent(histBin, massProj_SE_LS->GetBinContent(movedBin) + bkgSELS->GetBinContent(histBin));
	bkgMEUS->SetBinContent(histBin, massProj_ME_US_plus->GetBinContent(movedBin) + bkgMEUS->GetBinContent(histBin));
	bkgMEUS->SetBinContent(histBin, massProj_ME_US_minus->GetBinContent(movedBin) + bkgMEUS->GetBinContent(histBin));
	bkgMELS->SetBinContent(histBin, massProj_ME_LS->GetBinContent(movedBin) + bkgMELS->GetBinContent(histBin));

	sig->SetBinError(histBin, addErrors(sig->GetBinError(histBin), massProj_SE_US_plus->GetBinError(movedBin)) );
	sig->SetBinError(histBin, addErrors(sig->GetBinError(histBin), massProj_SE_US_minus->GetBinError(movedBin)) );
	bkgSELS->SetBinError(histBin, addErrors(bkgSELS->GetBinError(histBin), massProj_SE_LS->GetBinError(movedBin)) );
	bkgMEUS->SetBinError(histBin, addErrors(bkgMEUS->GetBinError(histBin), massProj_ME_US_plus->GetBinError(movedBin)) );
	bkgMEUS->SetBinError(histBin, addErrors(bkgMEUS->GetBinError(histBin), massProj_ME_US_minus->GetBinError(movedBin)) );
	bkgMELS->SetBinError(histBin, addErrors(bkgMELS->GetBinError(histBin), massProj_ME_LS->GetBinError(movedBin)) );
      }
    }
  }
  //--------------------------------------------------
  const float sigma = 7.76446e-03; // taken from fit of the whole dataset +-3.64310e-03
  const float meanInclusive = 2.28359; // +-2.14540e-03
  const float nSigma = 8.;
  const float sideBandTo = roundToPreviousBin(meanInclusive - nSigma*sigma, massNBins, massFrom, massTo);
  const float sideBandFrom = roundToNextBin(meanInclusive + nSigma*sigma, massNBins, massFrom, massTo);

  const float sideBand = sig->Integral(massFrom, sideBandTo) + sig->Integral(sideBandFrom, massTo);
  cout << "Side-band yield = " << sideBand << endl;

  // scaling the mixed event BKG by the yield of the side-band
  float sideBandYield = 0;
  float mixedSideBandYield = 0;
  for (int i = 0; i < massNBins; ++i)
  {
    const float binCenter = sig->GetXaxis()->GetBinCenter(i+1);
    if(binCenter < sideBandTo || binCenter > sideBandFrom)
    {
      sideBandYield += sig->GetBinContent(i+1);
      mixedSideBandYield += bkgMEUS->GetBinContent(i+1);
    }

  }
  TH1D* sideBandMarker = new TH1D("sideBandMarker","marker for the sideband in the form of a histogram", massNBins, massFrom, massTo);
  const float binWidth = (massTo - massFrom) / static_cast<float>(massNBins);
  for(int i = 0; i < massNBins; ++i)
    sideBandMarker->SetBinContent(i+1, 1000);
  for(float bin = sideBandTo; bin < sideBandFrom; bin += binWidth)
  {
    // cout << bin << endl;
    sideBandMarker->Fill(bin + 0.5*binWidth, -1e6);
  }
  sideBandMarker->SetFillColor(kRed);
  sideBandMarker->SetFillStyle(3004);
  sideBandMarker->SetLineColorAlpha(kRed,0);

  bkgSELS->Scale(1./3.);
  cout << "Scaling mixed event bg by " << sideBandYield / mixedSideBandYield << endl;
  bkgMEUS->Scale(sideBandYield / (mixedSideBandYield) );

  TF1 *line = new TF1("line", "[0] + [1]*x");
  TF1 *gaussPlusLine = new TF1("gaussPlusLine", "[0] + [1]*x + [2]*TMath::Gaus(x,[3],[4],1)");

  bkgMEUS->Fit(line, "", "", 2.1, 2.5);
  double offset = line->GetParameter(0);
  double slope = line->GetParameter(1);
  const double LcMass = 2.28646;

  gaussPlusLine->FixParameter(0,offset);
  gaussPlusLine->FixParameter(1,slope);
  gaussPlusLine->SetParameter(3,LcMass);

  gaussPlusLine->SetParameter(2,1);
  gaussPlusLine->SetParameter(4,sigma);

  sig->Fit(gaussPlusLine, "", "", 2.1, 2.5);

  // -- Drawing
  sig->GetXaxis()->SetTitle("#font[12]{m}_{pK#pi} (GeV/#font[12]{c}^{2})");
  sig->GetXaxis()->CenterTitle();
  sig->GetXaxis()->SetLabelSize(0.04);
  sig->GetXaxis()->SetTitleSize(0.055);
  sig->GetXaxis()->SetTitleOffset(0.8);
  // sig->GetXaxis()->SetTickLength(0.001);
  sig->GetYaxis()->SetTitle("#font[12]{N}/(10 MeV/#font[12]{c}^{2})");
  sig->GetYaxis()->CenterTitle();
  sig->GetYaxis()->SetLabelSize(0.04);
  sig->GetYaxis()->SetTitleSize(0.055);
  sig->GetYaxis()->SetTitleOffset(0.8);
  // sig->GetYaxis()->SetRangeUser(17, 95);

  sig->SetMarkerStyle(20);
  sig->SetLineColor(kBlack);

  bkgMEUS->SetMarkerStyle(21);
  bkgMEUS->SetMarkerColor(kOrange+5);
  bkgMEUS->SetLineColor(kOrange+5);
  bkgMEUS->GetFunction("line")->SetLineColor(kRed);
  bkgMEUS->GetFunction("line")->SetLineStyle(2);
  bkgMEUS->GetFunction("line")->SetNpx(10000);

  bkgSELS->SetMarkerStyle(22);
  bkgSELS->SetMarkerColor(kBlue-7);
  bkgSELS->SetLineColor(kBlue-7);

  bkgMELS->SetMarkerStyle(23);
  bkgMELS->SetMarkerColor(kGreen+2);
  bkgMELS->SetLineColor(kGreen+2);
  
  sig->GetFunction("gaussPlusLine")->SetLineColor(kRed);
  sig->GetFunction("gaussPlusLine")->SetNpx(10000);

  sig->GetXaxis()->SetRangeUser(2.1,2.5);
  sig->Draw("E");
  bkgMEUS->Draw("Esame");
  bkgSELS->Draw("Esame");
  // bkgMELS->Draw("Esame");

  TLegend *leg = new TLegend(0.5,0.6,0.89,0.8);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->AddEntry(sig, "Same event correct sign", "pl");
  leg->AddEntry(bkgSELS, "Same event wrong sign", "pl");
  leg->AddEntry(bkgMEUS, "Mixed event correct sign", "pl");
  // leg->AddEntry(bkgMELS, "Mixed event wrong sign", "pl");
  leg->Draw();
  // sideBandMarker->Draw("same BAR");

  TLegend *dataSet = new TLegend(0., 0.7, 0.4, 0.89);
  dataSet->SetFillStyle(0);
  dataSet->SetBorderSize(0);
  dataSet->AddEntry("", "#font[22]{Au+Au 200 GeV, 10-60%}","");
  dataSet->AddEntry("",Form("%1.0f GeV/#font[12]{c} < #font[12]{p}_{T} < %1.0f GeV/#font[12]{c}", minPt, maxPt),"");
  dataSet->Draw();

  // --  yield calculation
  const float min = 2.26;
  const float max = 2.31;

  // -- get part of the Gauss curve
  TF1 *normGaus = new TF1("normGaus", "TMath::Gaus(x,[0],[1],1)");
  double mean = gaussPlusLine->GetParameter(3);
  double width= gaussPlusLine->GetParameter(4);
  normGaus->SetParameter(0,mean);
  normGaus->SetParameter(1,width);
  double norm = normGaus->Integral(min, max);

  int minBin = sig->FindBin(min) + 1;
  int maxBin = sig->FindBin(max);
  cout << "integral from " << sig->GetBinCenter(minBin) - 0.005 << " to " << sig->GetBinCenter(maxBin) + 0.005 << endl;
  float NSig = sig->Integral(minBin,maxBin);
  float NBkg = bkgMEUS->Integral(minBin, maxBin);
  float Nlc = (NSig - NBkg)/norm;
  float error = std::sqrt(NSig/norm);

  cout << "N Sig = " << NSig << endl;
  cout << "N Bkg = " << NBkg << endl;
  cout << "norm = " << norm << endl;
  cout << "N Lambda_c = " << Nlc << endl;
  cout << "sigma = " << error << endl;
}
Пример #13
0
void ABCD2vari_p3(const char* ISO) { //Only iso is external, all the regions go in a loop!!! to be fed in the macro at once

  
  TString PREFIX = "./";

  //Get the fractions
  //gStyle->SetOptStat(0);
  TFile* fB = new TFile(PREFIX+"factor_qcd_"+TString(ISO)+"_B.root", "open");
  fB->cd();
  TH1D* hRatioB = (TH1D*)gDirectory->Get("hfactor");
  hRatioB->Fit("pol0");
  //2D needs, preliminary
  TH1D* hRatioB2030 = (TH1D*)gDirectory->Get("hfactor2030");
  hRatioB2030->Fit("pol0");
  TH1D* hRatioB3045 = (TH1D*)gDirectory->Get("hfactor3045");
  hRatioB3045->Fit("pol0");
  TH1D* hRatioB4560 = (TH1D*)gDirectory->Get("hfactor4560");
  hRatioB4560->Fit("pol0");
  TH1D* hRatioB60120 = (TH1D*)gDirectory->Get("hfactor60120");
  hRatioB60120->Fit("pol0");
  TH1D* hRatioB120200 = (TH1D*)gDirectory->Get("hfactor120200");
  hRatioB120200->Fit("pol0");
  TH1D* hRatioB2001500 = (TH1D*)gDirectory->Get("hfactor2001500");
  hRatioB2001500->Fit("pol0");

  TF1 *myfitB = (TF1*)hRatioB->GetFunction("pol0");
  Double_t factor_B = myfitB->GetParameter(0);
  Double_t factor_B_err = myfitB->GetParError(0);
  //2D needs, preliminary
  TF1 *myfitB2030 = (TF1*)hRatioB2030->GetFunction("pol0");
  Double_t factor_B2030 = myfitB2030->GetParameter(0);
  Double_t factor_B_err2030 = myfitB2030->GetParError(0);
  TF1 *myfitB3045 = (TF1*)hRatioB3045->GetFunction("pol0");
  Double_t factor_B3045 = myfitB3045->GetParameter(0);
  Double_t factor_B_err3045 = myfitB3045->GetParError(0);
  TF1 *myfitB4560 = (TF1*)hRatioB4560->GetFunction("pol0");
  Double_t factor_B4560 = myfitB4560->GetParameter(0);
  Double_t factor_B_err4560 = myfitB4560->GetParError(0);
  TF1 *myfitB60120 = (TF1*)hRatioB60120->GetFunction("pol0");
  Double_t factor_B60120 = myfitB60120->GetParameter(0);
  Double_t factor_B_err60120 = myfitB60120->GetParError(0);
  TF1 *myfitB120200 = (TF1*)hRatioB120200->GetFunction("pol0");
  Double_t factor_B120200 = myfitB120200->GetParameter(0);
  Double_t factor_B_err120200 = myfitB120200->GetParError(0);
  TF1 *myfitB2001500 = (TF1*)hRatioB2001500->GetFunction("pol0");
  Double_t factor_B2001500 = myfitB2001500->GetParameter(0);
  Double_t factor_B_err2001500 = myfitB2001500->GetParError(0);


  //repeat for region D
  TFile* fD = new TFile(PREFIX+"factor_qcd_"+TString(ISO)+"_D.root", "open");
  fD->cd();
  TH1D* hRatioD = (TH1D*)gDirectory->Get("hfactor");
  hRatioD->Fit("pol0");

  //2D needs, preliminary
  TH1D* hRatioD2030 = (TH1D*)gDirectory->Get("hfactor2030");
  hRatioD2030->Fit("pol0");
  TH1D* hRatioD3045 = (TH1D*)gDirectory->Get("hfactor3045");
  hRatioD3045->Fit("pol0");
  TH1D* hRatioD4560 = (TH1D*)gDirectory->Get("hfactor4560");
  hRatioD4560->Fit("pol0");
  TH1D* hRatioD60120 = (TH1D*)gDirectory->Get("hfactor60120");
  hRatioD60120->Fit("pol0");
  TH1D* hRatioD120200 = (TH1D*)gDirectory->Get("hfactor120200");
  hRatioD120200->Fit("pol0");
  TH1D* hRatioD2001500 = (TH1D*)gDirectory->Get("hfactor2001500");
  hRatioD2001500->Fit("pol0");

  TF1 *myfitD = (TF1*)hRatioD->GetFunction("pol0");
  Double_t factor_D = myfitD->GetParameter(0);
  Double_t factor_D_err = myfitD->GetParError(0);
  //2D needs, preliminary
  TF1 *myfitD2030 = (TF1*)hRatioD2030->GetFunction("pol0");
  Double_t factor_D2030 = myfitD2030->GetParameter(0);
  Double_t factor_D_err2030 = myfitD2030->GetParError(0);
  TF1 *myfitD3045 = (TF1*)hRatioD3045->GetFunction("pol0");
  Double_t factor_D3045 = myfitD3045->GetParameter(0);
  Double_t factor_D_err3045 = myfitB3045->GetParError(0);
  TF1 *myfitD4560 = (TF1*)hRatioD4560->GetFunction("pol0");
  Double_t factor_D4560 = myfitD4560->GetParameter(0);
  Double_t factor_D_err4560 = myfitD4560->GetParError(0);
  TF1 *myfitD60120 = (TF1*)hRatioD60120->GetFunction("pol0");
  Double_t factor_D60120 = myfitD60120->GetParameter(0);
  Double_t factor_D_err60120 = myfitD60120->GetParError(0);
  TF1 *myfitD120200 = (TF1*)hRatioD120200->GetFunction("pol0");
  Double_t factor_D120200 = myfitD120200->GetParameter(0);
  Double_t factor_D_err120200 = myfitD120200->GetParError(0);
  TF1 *myfitD2001500 = (TF1*)hRatioD2001500->GetFunction("pol0");
  Double_t factor_D2001500 = myfitD2001500->GetParameter(0);
  Double_t factor_D_err2001500 = myfitD2001500->GetParError(0);

  // directory with data
  TString protocol = "file://";
  TString dirname = "/scratch/lustreC/a/asvyatko/DY2013/rootfiles/";

  // EWK
  TFileCollection* c6 = new TFileCollection("WJets","WJets");
  c6->Add(protocol+dirname+"WJets_PU"+"/*.root");

  // diboson
  TFileCollection* c7a = new TFileCollection("WZJetsTo3LNu","WZJetsTo3LNu");
  c7a->Add(protocol+dirname+"WZJetsTo3LNu_PU"+"/*.root");

  TFileCollection* c7b = new TFileCollection("WZJetsTo2L2Q","WZJetsTo2L2Q");
  c7b->Add(protocol+dirname+"WZJetsTo2L2Q_PU"+"/*.root");

  TFileCollection* c7c = new TFileCollection("ZZJetsTo2L2Nu","ZZJetsTo2L2Nu");
  c7c->Add(protocol+dirname+"ZZJetsTo2L2Nu_PU"+"/*.root");

  TFileCollection* c7d = new TFileCollection("ZZJetsTo4L","ZZJetsTo4L");
  c7d->Add(protocol+dirname+"ZZJetsTo4L_PU"+"/*.root");

  TFileCollection* c7e = new TFileCollection("ZZJetsTo2L2Q","ZZJetsTo2L2Q");
  c7e->Add(protocol+dirname+"ZZJetsTo2L2Q_PU"+"/*.root");

  TFileCollection* c7f = new TFileCollection("WWJetsTo2L2Nu","WWJetsTo2L2Nu");
  c7f->Add(protocol+dirname+"WWJetsTo2L2Nu_PU"+"/*.root");

  //ttbar
  TFileCollection* c8a = new TFileCollection("tW","tW");
  c8a->Add(protocol+dirname+"tW_PU"+"/*.root");

  TFileCollection* c8b = new TFileCollection("tbarW","tbarW");
  c8b->Add(protocol+dirname+"tbarW_PU"+"/*.root");

  TFileCollection* c8c = new TFileCollection("tt1000","ttbar1000");
  c8c->Add(protocol+dirname+"tt1000_PU"+"/*.root");

  TFileCollection* c8d = new TFileCollection("tt700","ttbar700");
  c8d->Add(protocol+dirname+"tt700_PU"+"/*.root");

  TFileCollection* c8a = new TFileCollection("tW","tW");
  c8a->Add(protocol+dirname+"tW_PU"+"/*.root");

  TFileCollection* c8b = new TFileCollection("tbarW","tbarW");
  c8b->Add(protocol+dirname+"tbarW_PU"+"/*.root");

  TFileCollection* c8c = new TFileCollection("tt1000","ttbar1000");
  c8c->Add(protocol+dirname+"tt1000_PU"+"/*.root");

  TFileCollection* c8d = new TFileCollection("tt700","ttbar700");
  c8d->Add(protocol+dirname+"tt700_PU"+"/*.root");

  TFileCollection* c8e = new TFileCollection("ttjets","ttjets");
  c8e->Add(protocol+dirname+"ttjets_PU_p1"+"/*.root");
  c8e->Add(protocol+dirname+"ttjets_PU_p2"+"/*.root");


  gEnv->SetValue("ProofLite.Sandbox", "/home/ba01/u115/asvyatko/DYStudy/CMSSW_5_3_3_patch2/src/DimuonAnalysis/DYPackage/test/ABCDmethod/proofbox_p3");
  TProof* p = TProof::Open("workers=10"); //"workers=1"); ////proof://pccmspurdue3:-1"); // set number of works to 2:  TProof::Open("//lite:///?workers=2");
  p->RegisterDataSet("WJets", c6,"OV");
  p->RegisterDataSet("WZJetsTo3LNu", c7a,"OV");
  p->RegisterDataSet("WZJetsTo2L2Q", c7b,"OV");
  p->RegisterDataSet("ZZJetsTo2L2Nu", c7c,"OV");
  p->RegisterDataSet("ZZJetsTo4L", c7d,"OV");
  p->RegisterDataSet("ZZJetsTo2L2Q", c7e,"OV");
  p->RegisterDataSet("WWJetsTo2L2Nu", c7f,"OV");
  p->RegisterDataSet("tW", c8a,"OV");
  p->RegisterDataSet("tbarW", c8b,"OV");
  p->RegisterDataSet("tt1000", c8c,"OV");
  p->RegisterDataSet("tt700", c8d,"OV");
  p->RegisterDataSet("ttjets", c8e,"OV");
  
  p->ShowDataSets();

  //FIXME try not to ue the class, just define the parameters you need and load them with AdInoput
  //this is correct
  TObjString* useNtupleWeightFlag = new TObjString("False");
  p->AddInput(new TNamed("useNtupleWeightFlag","False"));
  TObjString* iso = new TObjString(ISO); 
  p->AddInput(new TNamed("iso",ISO));
  gROOT->ProcessLine(".L ../tools/misctools.C");
  TObjString* factorB = new TObjString(fota(factor_B));
  p->AddInput(new TNamed("factorB",fota(factor_B)));
  TObjString* factorB_err = new TObjString(fota(factor_B_err));
  p->AddInput(new TNamed("factorB_err",fota(factor_B_err)));

  TObjString* factorB2030 = new TObjString(fota(factor_B2030));
  p->AddInput(new TNamed("factorD2030",fota(factor_B2030)));
  TObjString* factorB_err2030 = new TObjString(fota(factor_B_err2030));
  p->AddInput(new TNamed("factorB_err2030",fota(factor_B_err2030)));
  TObjString* factorB3045 = new TObjString(fota(factor_B3045));
  p->AddInput(new TNamed("factorB3045",fota(factor_B3045)));
  TObjString* factorB_err3045 = new TObjString(fota(factor_B_err3045));
  p->AddInput(new TNamed("factorB_err3045",fota(factor_B_err3045)));
  TObjString* factorB4560 = new TObjString(fota(factor_B4560));
  p->AddInput(new TNamed("factorB4560",fota(factor_B4560)));
  TObjString* factorB_err4560 = new TObjString(fota(factor_B_err4560));
  p->AddInput(new TNamed("factorB_err4560",fota(factor_B_err4560)));
  TObjString* factorB60120 = new TObjString(fota(factor_B60120));
  p->AddInput(new TNamed("factorB60120",fota(factor_B60120)));
  TObjString* factorB_err60120 = new TObjString(fota(factor_B_err60120));
  p->AddInput(new TNamed("factorB_err60120",fota(factor_B_err60120)));
  TObjString* factorB120200 = new TObjString(fota(factor_B120200));
  p->AddInput(new TNamed("factorB120200",fota(factor_B120200)));
  TObjString* factorB_err120200 = new TObjString(fota(factor_B_err120200));
  p->AddInput(new TNamed("factorB_err120200",fota(factor_B_err120200)));
  TObjString* factorB2001500 = new TObjString(fota(factor_B2001500));
  p->AddInput(new TNamed("factorB2001500",fota(factor_B2001500)));
  TObjString* factorB_err2001500 = new TObjString(fota(factor_B_err2001500));
  p->AddInput(new TNamed("factorB_err2001500",fota(factor_B_err2001500)));

  /*TObjString* factorC = new TObjString(fota(factor_C));
  p->AddInput(new TNamed("factorC",fota(factor_C)));
  TObjString* factorC_err = new TObjString(fota(factor_C_err));
  p->AddInput(new TNamed("factorC_err",fota(factor_C_err)));
  */
  TObjString* factorD = new TObjString(fota(factor_D));
  p->AddInput(new TNamed("factorD",fota(factor_D)));
  TObjString* factorD_err = new TObjString(fota(factor_D_err));
  p->AddInput(new TNamed("factorD_err",fota(factor_D_err)));

  TObjString* factorD2030 = new TObjString(fota(factor_D2030));
  p->AddInput(new TNamed("factorD2030",fota(factor_D2030)));
  TObjString* factorD_err2030 = new TObjString(fota(factor_D_err2030));
  p->AddInput(new TNamed("factorD_err2030",fota(factor_D_err2030)));
  TObjString* factorD3045 = new TObjString(fota(factor_D3045));
  p->AddInput(new TNamed("factorD3045",fota(factor_D3045)));
  TObjString* factorD_err3045 = new TObjString(fota(factor_D_err3045));
  p->AddInput(new TNamed("factorD_err3045",fota(factor_D_err3045)));
  TObjString* factorD4560 = new TObjString(fota(factor_D4560));
  p->AddInput(new TNamed("factorD4560",fota(factor_D4560)));
  TObjString* factorD_err4560 = new TObjString(fota(factor_D_err4560));
  p->AddInput(new TNamed("factorD_err4560",fota(factor_D_err4560)));
  TObjString* factorD60120 = new TObjString(fota(factor_D60120));
  p->AddInput(new TNamed("factorD60120",fota(factor_D60120)));
  TObjString* factorD_err60120 = new TObjString(fota(factor_D_err60120));
  p->AddInput(new TNamed("factorD_err60120",fota(factor_D_err60120)));
  TObjString* factorD120200 = new TObjString(fota(factor_D120200));
  p->AddInput(new TNamed("factorD120200",fota(factor_D120200)));
  TObjString* factorD_err120200 = new TObjString(fota(factor_D_err120200));
  p->AddInput(new TNamed("factorD_err120200",fota(factor_D_err120200)));
  TObjString* factorD2001500 = new TObjString(fota(factor_D2001500));
  p->AddInput(new TNamed("factorD2001500",fota(factor_D2001500)));
  TObjString* factorD_err2001500 = new TObjString(fota(factor_D_err2001500));
  p->AddInput(new TNamed("factorD_err2001500",fota(factor_D_err2001500)));

  gROOT->Time();
  p->SetParameter("PROOF_LookupOpt", "all");
  p->Process("WJets#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("WZJetsTo3LNu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("WZJetsTo2L2Q#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("ZZJetsTo2L2Nu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("ZZJetsTo4L#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("ZZJetsTo2L2Q#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("WWJetsTo2L2Nu#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("tW#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("tbarW#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("tt1000#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("tt700#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  p->Process("ttjets#/recoTree/DiMuonTree","EventSelector_Bkg2.C+");
  
}
Пример #14
0
void bToDRawYield()
{
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

	TCanvas* c4 = new TCanvas("c4","",800,600);
	c4->Divide(2,2);

	TCanvas* c2 = new TCanvas("c2","",400,600);
	c2->Divide(1,2);

	TCanvas* c1 = new TCanvas();

	TCanvas* c15 = new TCanvas("c15","",810,1000);
	c15->Divide(3,5);

	TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root");
	TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root");
	TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root");
	TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root");

	TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData");
	TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband");
	TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData");
	TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband");
	TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca");
	TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca");

	TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal");
	TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal");
	TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped");
	TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped");

	TH3D* hData = (TH3D*)hDataPbPb->Clone("hData");
	hData->Sumw2();
	hData->Add(hDataPbPbMB);

	TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband");
	hSideband->Sumw2();
	hSideband->Add(hSidebandPbPbMB);

	TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca");
	hPtMD0Dca->Sumw2();
	hPtMD0Dca->Add(hPtMD0DcaPbPbMB);

	TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal");
	hMCPSignal->Sumw2();
	hMCPSignal->Add(hMCPSignalPbPbMB);

	TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal");
	hMCNPSignal->Sumw2();
	hMCNPSignal->Add(hMCNPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal");
	hPtMD0DcaMCPSignal->Sumw2();
	hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped");
	hPtMD0DcaMCPSwapped->Sumw2();
	hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB);

	TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
	texCms->SetNDC();
	texCms->SetTextAlign(12);
	texCms->SetTextSize(0.06);
	texCms->SetTextFont(42);

	TLatex* texCol = new TLatex(0.96,0.93, "PbPb #sqrt{s_{NN}} = 5.02 TeV");
	texCol->SetNDC();
	texCol->SetTextAlign(32);
	texCol->SetTextSize(0.06);
	texCol->SetTextFont(42);

	const int nPtBins = 14;
	float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

	float pts[nPtBins];
	float ptErrors[nPtBins];
	float promptFraction[nPtBins];
	float totalYield[nPtBins];
	float totalYieldInvMassFit[nPtBins];
	float totalYieldInvMassFitError[nPtBins];
	float bToDYield[nPtBins];
	float bToDYieldError[nPtBins];
	float bToDYieldErrorDataOnly[nPtBins];
	float promptDYield[nPtBins];
	float promptDYieldError[nPtBins];
	float promptDYieldErrorDataOnly[nPtBins];

	const int nBinY = 14;
	Float_t binsY[nBinY+1];
	float firstBinYWidth = 0.001;
	float binYWidthRatio = 1.27;
	binsY[0]=0;
	for(int i=1; i<=nBinY; i++)
		binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1);
	cout<<"last y bin: "<<binsY[nBinY]<<endl;

	//  for(int i=1; i<=nPtBins; i++)
	for(int i =7; i<=7; i++)
	{
		pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]);
		ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]);
		float ptLow = ptBins[i-1];
		float ptHigh = ptBins[i];
		cout<<endl<<"======================================="<<endl;
		cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl;

		TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c      |y| < 1.0",ptLow,ptHigh));
		texPtY->SetNDC();
		texPtY->SetTextFont(42);
		texPtY->SetTextSize(0.06);
		texPtY->SetLineWidth(2);

		TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh));
		texPt->SetNDC();
		texPt->SetTextFont(42);
		texPt->SetTextSize(0.06);
		texPt->SetLineWidth(2);

		TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0"));
		texY->SetNDC();
		texY->SetTextFont(42);
		texY->SetTextSize(0.06);
		texY->SetLineWidth(2);

		c2->cd(1);

		hPtMD0Dca->GetZaxis()->SetRange(1,100);
		hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh));
		TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y");
		TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y");

		setColorTitleLabel(hMData);
		setColorTitleLabel(hMMCSignal);
		setColorTitleLabel(hMMCSwapped);

		TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped);

		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0);      
		fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0));
		fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1));
		fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2));
		fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7));
		fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8));
		fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9));
		fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10));
		fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11));

		TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x");
		background->SetParameter(0,fMass->GetParameter(3));
		background->SetParameter(1,fMass->GetParameter(4));
		background->SetParameter(2,fMass->GetParameter(5));
		background->SetParameter(3,fMass->GetParameter(6));

		cout<<"MC signal width: "<<fMass->GetParameter(2)<<"   "<<fMass->GetParameter(10)<<endl;
		cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl;

		float massD = 1.8649;
		float massSignal1 = massD-0.025;
		float massSignal2 = massD+0.025;
		float massSideBand1 = massD-0.1;
		float massSideBand2 = massD-0.075;
		float massSideBand3 = massD+0.075;
		float massSideBand4 = massD+0.1;

		float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl;
		totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl;
		float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl;

		TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground));
		texScale->SetNDC();
		texScale->SetTextFont(42);
		texScale->SetTextSize(0.06);
		texScale->SetLineWidth(2);
		texScale->Draw();

		TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5);
		TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5);
		TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5);
		TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5);
		lineSignal1->Draw();
		lineSignal2->Draw();
		lineSideBand1->Draw();
		lineSideBand2->Draw();
		lineSideBand3->Draw();
		lineSideBand4->Draw();

		c2->cd(2);
		gPad->SetLogy();

		hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);

		TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0");
		TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband");
		TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0");
		TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0");

		float integralRawYieldMCP = hD0DcaMCPSignal0->Integral();
		float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral();
		cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl;
		cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl;

		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;

		divideBinWidth(hD0DcaData0);
		divideBinWidth(hD0DcaSideband);
		setColorTitleLabel(hD0DcaData0, 1);
		hD0DcaData0->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData0->GetYaxis()->SetTitle("counts per cm");

		TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0");
		hD0DcaSideband->Scale(scaleSideBandBackground);

		TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand");
		hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1);
		hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal);

		hD0DcaData0->SetMarkerSize(0.6);
		hD0DcaData0->Draw();
		hD0DcaSideband->Draw("hsame");
		hD0DcaSideband0->SetLineStyle(2);
		hD0DcaSideband0->Draw("hsame");

		TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC");
		leg1->SetBorderSize(0);
		leg1->SetTextSize(0.06);
		leg1->SetTextFont(42);
		leg1->SetFillStyle(0);
		leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl");
		leg1->AddEntry(hD0DcaSideband,"side band","l");
		leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l");
		leg1->Draw("same");

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh));

		c2->cd(1);
		hMMCSignal->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->cd(2);
		gPad->SetLogy(0);
		hMMCSwapped->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh));

		c15->cd(1);

		fitMass(hMData, hMMCSignal, hMMCSwapped);

		texPt->Draw();
		texY->Draw();

		TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY);

		for(int j=1; j<=14; j++)
		{
			c15->cd(j+1);
			hPtMD0Dca->GetZaxis()->SetRange(j,j);
			float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j);
			float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j);
			TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh));
			setColorTitleLabel(hMData_D0Dca);
			fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped);

			float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);
			float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);

			hD0DcaDataFit->SetBinContent(j, yield);
			hD0DcaDataFit->SetBinError(j, yieldError);

			TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh));
			texD0Dca->SetNDC();
			texD0Dca->SetTextFont(42);
			texD0Dca->SetTextSize(0.06);
			texD0Dca->SetLineWidth(2);
			texD0Dca->Draw();

			TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError));
			texYield->SetNDC();
			texYield->SetTextFont(42);
			texYield->SetTextSize(0.06);
			texYield->SetLineWidth(2);
			texYield->Draw();
		}

		c15->SaveAs(Form("plots/PbPb_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh));

		divideBinWidth(hD0DcaDataFit);

		c4->cd(1);
		gPad->SetLogy();

		normalize(hD0DcaMCPSignal);
		setColorTitleLabel(hD0DcaMCPSignal, 2);
		hD0DcaMCPSignal->GetXaxis()->SetRangeUser(0,0.07);

		normalize(hD0DcaMCNPSignal);
		setColorTitleLabel(hD0DcaMCNPSignal, 4);
		hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})");
		hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)");
		hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.);

		hD0DcaMCNPSignal->Draw("");
		hD0DcaMCPSignal->Draw("same");

		TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC");
		leg2->SetBorderSize(0);
		leg2->SetTextSize(0.06);
		leg2->SetTextFont(42);
		leg2->SetFillStyle(0);
		leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl");
		leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl");
		leg2->Draw("same");

		c4->cd(2);
		gPad->SetLogy();

		TH1D* hD0DcaData = hD0DcaDataFit;
		if(pts[i-1]>20) hD0DcaData = hD0DcaDataSubSideBand;

		setColorTitleLabel(hD0DcaData, 1);

		double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width");
		cout<<"integralTotalYield: "<<integralTotalYield<<endl;

		TF1* fMix = new TF1("fMix",&funMix, 0., 0.5, 2);
		fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
		fMix->SetParLimits(0,0,2*integralTotalYield);
		fMix->SetParLimits(1,0,2*integralTotalYield);

		fMix->SetLineColor(2);
		fMix->SetFillColor(kRed-9);
		fMix->SetFillStyle(1001);

		float fitRangeL = 0;
		float fitRangeH = 0.08;

		hD0DcaData->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData->Draw();
		int fitStatus = 1;
		TFitResultPtr fitResult;
		double fitPrecision = 1.e-6;
		while(fitStatus)
		{
			TFitter::SetPrecision(fitPrecision);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);
			fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH);
			fitStatus = fitResult->Status();
			cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;
			if(fitStatus)
				fitPrecision *= 10;
		}
		cout<<"============== do main fit ============"<<endl;
		fMix->SetParameters(integralTotalYield,0.9);
		fMix->SetParError(0,0.1*integralTotalYield);
		fMix->SetParError(1,0.1);
		fMix->SetNpx(10000);
		fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH);
		hD0DcaData->GetFunction("fMix")->Draw("flsame");
		fitStatus = fitResult->Status();
		cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;

		TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2);
		fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1));
		fNP->SetRange(fitRangeL,fitRangeH);
		fNP->SetLineColor(4);
		fNP->SetFillStyle(1001);
		fNP->SetFillColor(kBlue-9);
		fNP->SetNpx(10000);
		fNP->Draw("same");  

		hD0DcaData->Draw("same");

		promptDYield[i-1] = fMix->GetParameter(0);
		promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0);
		bToDYield[i-1] = fMix->GetParameter(1);
		bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1);
		totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1];
		promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1];

		cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl;

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0)));
		texPrompt->SetNDC();
		texPrompt->SetTextFont(42);
		texPrompt->SetTextSize(0.06);
		texPrompt->SetLineWidth(2);
		texPrompt->Draw();

		TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1)));
		texNonPrompt->SetNDC();
		texNonPrompt->SetTextFont(42);
		texNonPrompt->SetTextSize(0.06);
		texNonPrompt->SetLineWidth(2);
		texNonPrompt->Draw();

		TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62);
		leg4->SetBorderSize(0);
		leg4->SetTextSize(0.06);
		leg4->SetTextFont(42);
		leg4->SetFillStyle(0);
		leg4->AddEntry(hD0DcaData,"Data","pl");
		leg4->AddEntry(fMix,"Prompt D^{0}","f");
		leg4->AddEntry(fNP,"B to D^{0}","f");
		leg4->Draw("same");

		//smear MC smaple with the error, to simulate the MC statistic error effect.
		c4->cd(3);

		hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal");
		hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal");

		TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		setColorTitleLabel(hNPYield, 1);
		setColorTitleLabel(hPYield, 1);

		int nSmear = 1000;

		for(int j=0; j<nSmear; j++)
		{
			RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal);
			RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);

			hD0DcaData->Fit("fMix","E QN0");

			hPYield->Fill(fMix->GetParameter(0));
			hNPYield->Fill(fMix->GetParameter(1));
		}

		hPYield->GetXaxis()->SetTitle("prompt D^{0} yield");
		hPYield->GetYaxis()->SetTitle("counts");
		hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum());
		hPYield->SetMarkerStyle(20);
		hPYield->SetStats(0);
		hPYield->Draw("e");
		hPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaP->SetNDC();
		texGaussMeanSigmaP->SetTextFont(42);
		texGaussMeanSigmaP->SetTextSize(0.06);
		texGaussMeanSigmaP->SetLineWidth(2);
		texGaussMeanSigmaP->Draw();

		float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2);
		promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2));

		c4->cd(4);

		hNPYield->GetXaxis()->SetTitle("B to D^{0} yield");
		hNPYield->GetYaxis()->SetTitle("counts");
		hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum());
		hNPYield->SetMarkerStyle(20);
		hNPYield->SetStats(0);
		hNPYield->Draw("e");
		hNPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaNP->SetNDC();
		texGaussMeanSigmaNP->SetTextFont(42);
		texGaussMeanSigmaNP->SetTextSize(0.06);
		texGaussMeanSigmaNP->SetLineWidth(2);
		texGaussMeanSigmaNP->Draw();

		float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2);
		bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2));

		cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl;
		cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl;
		cout<<"total yield: "<<totalYield[i-1]<<endl;
		cout<<"prompt fraction: "<<promptFraction[i-1]<<endl;

		float promptMCScale = promptDYield[i-1]/integralRawYieldMCP;
		float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP;

		cout<<"promptMCScale: "<<promptMCScale<<endl;
		cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl;

		//restore original unsmeared histograms before saving plots
		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;
		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;
		hD0DcaData->Fit("fMix","E QN0");

		c4->SaveAs(Form("plots/PbPb_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		c1->cd();

		TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit");
		hD0DcaDataOverFit->Divide(fMix);
		hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit");
		hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5);
		hD0DcaDataOverFit->GetXaxis()->SetRangeUser(0,0.07);
		setColorTitleLabel(hD0DcaDataOverFit, 1);
		hD0DcaDataOverFit->Draw("e");

		TF1* fLine1 = new TF1("fLine1", "1", 0,1);
		fLine1->Draw("same");
		hD0DcaDataOverFit->Draw("esame");

		c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;

	} // end for i ptbins
	c1->cd();

	TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100);
	hStupidJie->GetYaxis()->SetRangeUser(0,1);
	hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	hStupidJie->GetYaxis()->SetTitle("prompt fraction");
	hStupidJie->SetStats(0);
	hStupidJie->Draw();
	TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction);
	grFraction->SetName("grPromptFraction");
	grFraction->SetMarkerStyle(20);
	grFraction->Draw("psame");

	c1->SaveAs("promptFraction.pdf");

	c1->SetLogy();

	TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(bToDYield[i-1] <= 0) continue;
		hBtoDRawYield->SetBinContent(i, bToDYield[i-1]);
		hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]);
	}
	divideBinWidth(hBtoDRawYield);
	setColorTitleLabel(hBtoDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hBtoDRawYield->Draw("p");
	c1->SaveAs("BtoD.pdf");

	TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(promptDYield[i-1] <= 0) continue;
		hPromptDRawYield->SetBinContent(i, promptDYield[i-1]);
		hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]);
	}
	divideBinWidth(hPromptDRawYield);
	setColorTitleLabel(hPromptDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hPromptDRawYield->Draw("p");
	c1->SaveAs("promptD.pdf");

	TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(totalYieldInvMassFit[i-1] <= 0) continue;
		hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]);
		hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]);
	}
	divideBinWidth(hTotalDYieldInvMassFit);
	setColorTitleLabel(hTotalDYieldInvMassFit, 1);
	hTotalDYieldInvMassFit->Draw("p");
	c1->SaveAs("totalDInvMassFit.pdf");

	TFile* fOut = new TFile("bFeedDownResult.root", "recreate");
	fOut->WriteTObject(grFraction);
	fOut->WriteTObject(hBtoDRawYield);
	fOut->WriteTObject(hPromptDRawYield);
	fOut->WriteTObject(hTotalDYieldInvMassFit);
	fOut->Write();
	fOut->Close();
}
Пример #15
0
int logWeightingScanAll(){//main
  SetTdrStyle();

  //TString plotDir = "../PLOTS/gitV00-02-12/version12/gamma/200um/";
  TString plotDir = "/afs/cern.ch/work/a/amagnan/PFCalEEAna/PLOTS/gitV00-02-12/version12/gamma/200um/";

  bool useFit = true;

  //const unsigned nPu = 2;
  //unsigned pu[nPu] = {0,140};
  const unsigned nPu = 1;//2;
  unsigned pu[nPu] = {0};//,140};

  const unsigned nScans = 50;
  const double wStart = 1.;
  const double wStep = (6.-wStart)/nScans;

  const unsigned neta = 4;//7;
  const unsigned npt = 3;//13;

  const unsigned nLayers = 30;

  unsigned eta[neta] = {17,21,25,29};
  //unsigned pt[npt] = {20,30,40,50,60,70,80,90,100,125,150,175,200};
  unsigned pt[npt] = {20,50,100};

  //TF1 *cauchy = new TF1("cauchy","1/(TMath::Pi()*[2]*(1+pow((x-[0])/[2],2)))",-15,15);
  //cauchy->SetParameters(0,0,2.5);


  double wxminall[nPu][nLayers][neta];
  double wyminall[nPu][nLayers][neta];
  double etaval[neta];
       
  const unsigned nCanvas = 5;  
  TCanvas *mycx[nCanvas];
  TCanvas *mycy[nCanvas];
  for (unsigned iC(0);iC<nCanvas;++iC){
    std::ostringstream lName;
    lName << "mycx" << iC;
    mycx[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1500,1000);
    mycx[iC]->Divide(3,2);
    lName.str("");
    lName << "mycy" << iC;
    mycy[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1500,1000);
    mycy[iC]->Divide(3,2);
  }
  
  TCanvas *mycW = new TCanvas("mycW","mycW",1500,1000);
  TCanvas *mycFit = new TCanvas("mycFit","mycFit",1);

  for (unsigned ieta(0); ieta<neta;++ieta){
    etaval[ieta] = eta[ieta]/10.;
    bool savePoint = (eta[ieta] == 17);// &&  pt[ipt]==50);
    std::ostringstream pteta;
    pteta << "eta" << eta[ieta];// << "_et" << pt[ipt];
      
    TFile *fin[nPu];
      
    TFile *fout = 0;
    if (savePoint) {
      fout = TFile::Open(("PLOTS/LogWeightingStudy_"+pteta.str()+".root").c_str(),"RECREATE");
      fout->mkdir("scan");
      fout->mkdir("scan/xpos");
      fout->mkdir("scan/ypos");
      for (unsigned iS(0); iS<nScans;++iS){
	std::ostringstream lName;
	lName << "scan/xpos/scan_" << wStart+iS*wStep;
	fout->mkdir(lName.str().c_str());
	lName.str("");
	lName << "scan/ypos/scan_" << wStart+iS*wStep;
	fout->mkdir(lName.str().c_str());
      }
	
      fout->cd();
    }
    TH1F *p_xt;
    TH1F *p_yt; 
    TH1F *p_intercalibSigmaSquare[nPu];
    TH1F *p_chi2ndf; 
    if (savePoint) {
      p_xt = new TH1F("p_xt",";x truth (mm)",100,-5,5); 
      p_yt = new TH1F("p_yt",";y truth (mm)",100,-5,5);//200,1170,1370); 
	
      p_intercalibSigmaSquare[0] = new TH1F("p_intercalibSigmaSquare_0",";#sigma_{E}^{2} (2% intercalib) (GeV^2)",3000,0,30000);
      p_intercalibSigmaSquare[1] = new TH1F("p_intercalibSigmaSquare_140",";#sigma_{E}^{2} (2% intercalib) (GeV^2)",3000,0,30000);
      p_chi2ndf = new TH1F("p_chi2ndf",";#chi^{2}/N",100,0,20);
    }
      
    TH1F *p_posx[nPu][nLayers][nScans];
    TH1F *p_posy[nPu][nLayers][nScans];
      
    TH1F *p_wx[nPu][nLayers][3];
    TH1F *p_wy[nPu][nLayers][3];
      
    TH2F *p_Exy[nPu][nLayers];
    TH2F *p_deltavsreco_x[nPu][nLayers];
    TH2F *p_deltavsreco_y[nPu][nLayers];
    TH2F *p_recovstruth_x[nPu][nLayers];
    TH2F *p_recovstruth_y[nPu][nLayers];
      
    if (savePoint){
      mycFit->Print("PLOTS/fits_x.pdf[");
      mycFit->Print("PLOTS/fits_y.pdf[");
    }
      
    gStyle->SetOptStat("eMRuo");
      
    TGraphErrors *grX[nPu][nLayers];
    TGraphErrors *grY[nPu][nLayers];
    TGraphErrors *grXrms[nPu][nLayers];
    TGraphErrors *grYrms[nPu][nLayers];
      
    double resxmin[nPu][nLayers];
    double resymin[nPu][nLayers];
    double lay[nLayers];
    double wxmin[nPu][nLayers];
    double wymin[nPu][nLayers];

    for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu


      std::vector<std::vector<double> > Exy;
      std::vector<double> init;
      init.resize(25,0);
      Exy.resize(nLayers,init);
      std::vector<double> truthPosX;
      truthPosX.resize(nLayers,0);
      std::vector<double> truthPosY;
      truthPosY.resize(nLayers,0);
	  
	  
      std::ostringstream label;
      label << "pu" << pu[ipu];
      if (savePoint){
	fout->mkdir(label.str().c_str());
	fout->cd(label.str().c_str());
      }

      for (unsigned iL(0);iL<nLayers;++iL){
	lay[iL] = iL;
	resxmin[ipu][iL] = 100;
	wxmin[ipu][iL] = 10;
	resymin[ipu][iL] = 100;
	wymin[ipu][iL] = 10;
	label.str("");   
	label << "pu" << pu[ipu];
	if (savePoint) fout->cd(label.str().c_str());
	label.str("");   
	label << "grX_pu" << pu[ipu] << "_" << iL;
	grX[ipu][iL] = new TGraphErrors();
	grX[ipu][iL]->SetName(label.str().c_str());
	label.str("");   
	label << "grY_pu" << pu[ipu] << "_" << iL;
	grY[ipu][iL] = new TGraphErrors();
	grY[ipu][iL]->SetName(label.str().c_str());
	label.str("");   
	label << "grXrms_pu" << pu[ipu] << "_" << iL;
	grXrms[ipu][iL] = new TGraphErrors();
	grXrms[ipu][iL]->SetName(label.str().c_str());
	label.str("");   
	label << "grYrms_pu" << pu[ipu] << "_" << iL;
	grYrms[ipu][iL] = new TGraphErrors();
	grYrms[ipu][iL]->SetName(label.str().c_str());
	if (savePoint) {
	  label.str("");   
	  label << "Exy_pu"<< pu[ipu] << "_" << iL;
	  p_Exy[ipu][iL] = new TH2F(label.str().c_str(),";x idx;y idx; E (mips)",
				    5,0,5,5,0,5);
	}
	label.str("");   
	label << "deltavsreco_x_pu"<< pu[ipu] << "_" << iL;
	p_deltavsreco_x[ipu][iL] = new TH2F(label.str().c_str(),";x reco (mm);x_{reco}-x_{truth} (mm);",
					    30,-15,15,100,-10,10);
	label.str("");
	label << "deltavsreco_y_pu"<< pu[ipu] << "_" << iL;
	p_deltavsreco_y[ipu][iL] = new TH2F(label.str().c_str(),";y reco (mm);y_{reco}-y_{truth} (mm);",
					    30,-15,15,100,-10,10);
	if (savePoint) {
	  label.str("");   
	  label << "recovstruth_x_pu"<< pu[ipu] << "_" << iL;
	  p_recovstruth_x[ipu][iL] = new TH2F(label.str().c_str(),";x_{truth} (mm);x reco (mm)",
					      30,-15,15,30,-15,15);
	  label.str("");
	  label << "recovstruth_y_pu"<< pu[ipu] << "_" << iL;
	  p_recovstruth_y[ipu][iL] = new TH2F(label.str().c_str(),";y_{truth} (mm);y reco (mm)",
					      30,-15,15,//200,1170,1370,
					      30,-15,15
					      ); 
	    
	}


	if (savePoint) {
	  if (savePoint) {
	    label.str("");   
	    label << "pu" << pu[ipu];
	    fout->cd(label.str().c_str());
	  }
	  for (unsigned i(0);i<5;++i){
	    label.str("");     
	    label << "wx_pu" << pu[ipu] << "_" << iL << "_" << i;
	    p_wx[ipu][iL][i] = new TH1F(label.str().c_str(),
					";wx;events",
					100,-10,0);
	    label.str("");     
	    label << "wy_pu" << pu[ipu] << "_" << iL << "_" << i;
	    p_wy[ipu][iL][i] = new TH1F(label.str().c_str(),
					";wy;events",
					100,-10,0);
	  }
	}
	for (unsigned iS(0); iS<nScans;++iS){
	  label.str("");
	  label << "scan/xpos/scan_" << wStart+iS*wStep;
	  if (savePoint) fout->cd(label.str().c_str());
	  label.str("");
	  label << "posx_pu" << pu[ipu] << "_" << iL << "_" << iS;
	  p_posx[ipu][iL][iS] = new TH1F(label.str().c_str(),
					 ";x-x_{truth} (mm);events",
					 100,-10,10);
	  label.str("");
	  label << "scan/ypos/scan_" << wStart+iS*wStep;
	  if (savePoint) fout->cd(label.str().c_str());
	  label.str("");
	  label << "posy_pu" << pu[ipu] << "_" << iL << "_" << iS;
	  p_posy[ipu][iL][iS] = new TH1F(label.str().c_str(),
					 ";y-y_{truth} (mm);events",
					 100,-10,10);
	}
      }//loop on layers
	  
      for (unsigned ipt(0); ipt<npt;++ipt){
	
	std::ostringstream linputStr;
	linputStr << plotDir << "/" << "eta" << eta[ieta] << "_et" << pt[ipt] << "_pu" << pu[ipu] ;
	//linputStr << "_logweight";
	linputStr << ".root";
	fin[ipu] = TFile::Open(linputStr.str().c_str());
	if (!fin[ipu]) {
	  std::cout << " -- Error, input file " << linputStr.str() << " cannot be opened. Skipping..." << std::endl;
	  continue;
	}
	else std::cout << " -- File " << linputStr.str() << " successfully opened." << std::endl;
	    
	TTree *tree = (TTree*)gDirectory->Get("EcellsSR2");
	if (!tree) {
	  std::cout << " Tree not found! " << std::endl;
	  continue;
	  //return 1;
	}

	for (unsigned iL(0);iL<nLayers;++iL){
	  label.str("");     
	  label << "TruthPosX_" << iL;
	  tree->SetBranchAddress(label.str().c_str(),&truthPosX[iL]);
	  label.str("");     
	  label << "TruthPosY_" << iL;
	  tree->SetBranchAddress(label.str().c_str(),&truthPosY[iL]);
	      
	  for (unsigned iy(0);iy<5;++iy){
	    for (unsigned ix(0);ix<5;++ix){
	      unsigned idx = 5*iy+ix;
	      label.str("");     
	      label << "E_" << iL << "_" << idx;
	      tree->SetBranchAddress(label.str().c_str(),&Exy[iL][idx]);
	    }
	  }
	}//loop on layers
	
	unsigned nEvts = tree->GetEntries();
	for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries
	      
	  if (ievt%50 == 0) std::cout << "... Processing entry: " << ievt << std::endl;
	      
	  tree->GetEntry(ievt);
	      
	  double Etotsq = 0;
	      
	  for (unsigned iL(0);iL<nLayers;++iL){
	    double Etot = 0;
	    double Ex[5] = {0,0,0,0,0};
	    double Ey[5] = {0,0,0,0,0};
	    for (unsigned idx(0);idx<25;++idx){
	      if (iL>22) Etot += Exy[iL][idx];
	      else if ((idx>5 && idx<9)||
		       (idx>10 && idx<14)||
		       (idx>15 && idx<19)) Etot += Exy[iL][idx];
	    }
	    Etotsq += pow(calibratedE(Etot*absWeight(iL,eta[ieta]/10.),eta[ieta]/10.),2);

	    if (iL>22){
	      Ex[0] = Exy[iL][0]+Exy[iL][5]+Exy[iL][10]+Exy[iL][15]+Exy[iL][20];
	      Ex[1] = Exy[iL][1]+Exy[iL][6]+Exy[iL][11]+Exy[iL][16]+Exy[iL][21];
	      Ex[2] = Exy[iL][2]+Exy[iL][7]+Exy[iL][12]+Exy[iL][17]+Exy[iL][22];
	      Ex[3] = Exy[iL][3]+Exy[iL][8]+Exy[iL][13]+Exy[iL][18]+Exy[iL][23];
	      Ex[4] = Exy[iL][4]+Exy[iL][9]+Exy[iL][14]+Exy[iL][19]+Exy[iL][24];
	      Ey[0] = Exy[iL][0]+Exy[iL][1]+Exy[iL][2]+Exy[iL][3]+Exy[iL][4];
	      Ey[1] = Exy[iL][5]+Exy[iL][6]+Exy[iL][7]+Exy[iL][8]+Exy[iL][9];
	      Ey[2] = Exy[iL][10]+Exy[iL][11]+Exy[iL][12]+Exy[iL][13]+Exy[iL][14];
	      Ey[3] = Exy[iL][15]+Exy[iL][16]+Exy[iL][17]+Exy[iL][18]+Exy[iL][19];
	      Ey[4] = Exy[iL][20]+Exy[iL][21]+Exy[iL][22]+Exy[iL][23]+Exy[iL][24];
	    }
	    else {
	      Ex[0] = Exy[iL][6]+Exy[iL][11]+Exy[iL][16];
	      Ex[1] = Exy[iL][7]+Exy[iL][12]+Exy[iL][17];
	      Ex[2] = Exy[iL][8]+Exy[iL][13]+Exy[iL][18];
	      Ey[0] = Exy[iL][6]+Exy[iL][7]+Exy[iL][8];
	      Ey[1] = Exy[iL][11]+Exy[iL][12]+Exy[iL][13];
	      Ey[2] = Exy[iL][16]+Exy[iL][17]+Exy[iL][18];
	    }
	    
	    double simplex = 0;
	    double simpley = 0;
	    if (Etot!=0) {
	      if (iL>22) {
		simplex = 10*(2*Ex[4]+Ex[3]-Ex[1]-2*Ex[0])/Etot;
		simpley = 10*(2*Ey[4]+Ey[3]-Ey[1]-2*Ey[0])/Etot;
	      }
	      else {
		simplex = 10*(Ex[2]-Ex[0])/Etot;
		simpley = 10*(Ey[2]-Ey[0])/Etot;
	      }
	    }
		
	    double xt = truthPosX[iL];
	    unsigned cellCenter = static_cast<unsigned>((truthPosY[iL]+5)/10.)*10;
	    double yt = 0;
	    //if (cellCenter>truthPosY[iL]) yt = cellCenter-truthPosY[iL];
	    yt=truthPosY[iL]-cellCenter;
	    p_deltavsreco_x[ipu][iL]->Fill(simplex,simplex-xt);
	    p_deltavsreco_y[ipu][iL]->Fill(simpley,simpley-yt);
	    if (savePoint) {
	      p_xt->Fill(xt);
	      p_yt->Fill(yt);
	      p_recovstruth_x[ipu][iL]->Fill(xt,simplex);
	      p_recovstruth_y[ipu][iL]->Fill(yt,simpley);
	
	      for (unsigned idx(0);idx<9;++idx){
		p_Exy[ipu][iL]->Fill(idx%5,idx/5,Exy[iL][idx]/Etot);
	      }
	    }
	    double wx[6][nScans];
	    double wy[6][nScans];
	  
	    for (unsigned i(0);i<6;++i){
	      for (unsigned iS(0); iS<nScans;++iS){
		wx[i][iS] = 0;
		wy[i][iS] = 0;
	      }
	    }
	    for (unsigned i(0);i<5;++i){
	      if (savePoint) p_wx[ipu][iL][i]->Fill(log(Ex[i]/Etot));
	      if (savePoint) p_wy[ipu][iL][i]->Fill(log(Ey[i]/Etot));
	      for (unsigned iS(0); iS<nScans;++iS){
		double w0 = wStart+iS*wStep;
		wx[i][iS] = std::max(0.,log(Ex[i]/Etot)+w0);
		wy[i][iS] = std::max(0.,log(Ey[i]/Etot)+w0);
		// if (log(Ex[i]/Etot)+w0<0)
		//   std::cout << " - iL= " << iL << " i=" << i << " w0=" << w0 
		// 		<< " logEx=" << log(Ex[i]/Etot)
		// 		<< " wx " << wx[i][iS] 
		// 		<< std::endl;
		// if (log(Ey[i]/Etot)+w0<0) 
		//   std::cout << " - iL= " << iL << " i=" << i << " w0=" << w0 
		// 		<< " logEy=" << log(Ey[i]/Etot)
		// 		<< " wy " << wy[i][iS] 
		// 		<< std::endl;
		wx[5][iS] += wx[i][iS];
		wy[5][iS] += wy[i][iS];
	      }
	    }
	    for (unsigned iS(0); iS<nScans;++iS){
	      double x = 0;//10*(wx[2][iS]-wx[0][iS])/wx[3][iS];
	      if (wx[5][iS]!=0) {
		if (iL>22) x = 10*(2*wx[4][iS]+wx[3][iS]-wx[1][iS]-2*wx[0][iS])/wx[5][iS];
		else x = 10*(wx[2][iS]-wx[0][iS])/wx[5][iS];
	      }
	      double y = 0;//10*(wy[2][iS]-wy[0][iS])/wy[3][iS];
	      if (wy[5][iS]!=0) {
		if (iL>22) y = 10*(2*wy[4][iS]+wy[3][iS]-wy[1][iS]-2*wy[0][iS])/wy[5][iS];
		else y = 10*(wy[2][iS]-wy[0][iS])/wy[5][iS];
	      }

	      //if (fabs(y-yt)>5) std::cout << " --- iL=" << iL << " iS=" << iS 
	      //<< " x=" << x << " xt=" << xt 
	      //<< " y=" << y << " yt=" << yt 
	      //<< std::endl;
	      p_posx[ipu][iL][iS]->Fill(x-xt);
	      p_posy[ipu][iL][iS]->Fill(y-yt);
	    }

	  }//loop on layers
	  if (savePoint) p_intercalibSigmaSquare[ipu]->Fill(Etotsq);
	}//loop on entries
    
      }//loop on pt

      //fill first point with linear weighting
      TLatex lat;
      char buf[500];

      for (unsigned iL(0);iL<nLayers;++iL){
	mycFit->cd();
	TH1D *projy = p_deltavsreco_x[ipu][iL]->ProjectionY();
	projy->Draw();
	projy->Fit("gaus","0+Q");
	TF1 *fitx = projy->GetFunction("gaus");
	fitx->SetLineColor(6);
	fitx->Draw("same");
	sprintf(buf,"Layer %d, linear weighting, pu=%d",iL,pu[ipu]);
	lat.DrawLatexNDC(0.1,0.96,buf);
	
	grX[ipu][iL]->SetPoint(0,0.5,fitx->GetParameter(2));
	grX[ipu][iL]->SetPointError(0,0,fitx->GetParError(2));
	grXrms[ipu][iL]->SetPoint(0,0.5,projy->GetRMS());
	grXrms[ipu][iL]->SetPointError(0,0,projy->GetRMSError());
	mycFit->Update();
	if (savePoint) mycFit->Print("PLOTS/fits_x.pdf");
	
	mycFit->cd();
	projy = p_deltavsreco_y[ipu][iL]->ProjectionY();
	projy->Draw();
	projy->Fit("gaus","0+Q");
	TF1 *fity = projy->GetFunction("gaus");
	fitx->SetLineColor(6);
	fitx->Draw("same");
	sprintf(buf,"Layer %d, linear weighting, pu=%d",iL,pu[ipu]);
	lat.DrawLatexNDC(0.1,0.96,buf);
	
	grY[ipu][iL]->SetPoint(0,0.5,fity->GetParameter(2));
	grY[ipu][iL]->SetPointError(0,0,fity->GetParError(2));
	grYrms[ipu][iL]->SetPoint(0,0.5,projy->GetRMS());
	grYrms[ipu][iL]->SetPointError(0,0,projy->GetRMSError());
	mycFit->Update();
	if (savePoint) mycFit->Print("PLOTS/fits_y.pdf");
      }

      //fit vs w0, get w0min
      for (unsigned iL(0);iL<nLayers;++iL){
	for (unsigned iS(0); iS<nScans;++iS){
	  mycFit->cd();
	  p_posx[ipu][iL][iS]->Draw();
	  double w0 = wStart+iS*wStep;
	  //myGaus->SetParameters();
	  p_posx[ipu][iL][iS]->Fit("gaus","0+Q","",-2.,2.);
	  TF1 *fitx = p_posx[ipu][iL][iS]->GetFunction("gaus");
	  fitx->SetLineColor(6);
	  fitx->Draw("same");
	  sprintf(buf,"Layer %d, w0=%3.1f, pu=%d",iL,w0,pu[ipu]);
	  lat.DrawLatexNDC(0.1,0.96,buf);

	  mycFit->Update();
	  if (savePoint) mycFit->Print("PLOTS/fits_x.pdf");

	  mycFit->cd();
	  p_posy[ipu][iL][iS]->Draw();
	  p_posy[ipu][iL][iS]->Fit("gaus","0+Q","",-2.,2.);
	  TF1 *fity = p_posy[ipu][iL][iS]->GetFunction("gaus");
	  fity->SetLineColor(6);
	  fity->Draw("same");
	  sprintf(buf,"Layer %d, w0=%3.1f, pu=%d",iL,w0,pu[ipu]);
	  lat.DrawLatexNDC(0.1,0.96,buf);
	  mycFit->Update();
	  if (savePoint) mycFit->Print("PLOTS/fits_y.pdf");
	  //grX[ipu][iL]->SetPoint(iS,w0,p_posx[ipu][iL][iS]->GetRMS());
	  //grX[ipu][iL]->SetPointError(iS,0,p_posx[ipu][iL][iS]->GetRMSError());
	  //grY[ipu][iL]->SetPoint(iS,w0,p_posy[ipu][iL][iS]->GetRMS());
	  //grY[ipu][iL]->SetPointError(iS,0,p_posy[ipu][iL][iS]->GetRMSError());
	  double xval = useFit? fitx->GetParameter(2) : p_posx[ipu][iL][iS]->GetRMS();
	  if (savePoint) p_chi2ndf->Fill(fitx->GetChisquare()/fitx->GetNDF());
	
	  grX[ipu][iL]->SetPoint(iS+1,w0,fitx->GetParameter(2));
	  grX[ipu][iL]->SetPointError(iS+1,0,fitx->GetParError(2));
	  grXrms[ipu][iL]->SetPoint(iS+1,w0,p_posx[ipu][iL][iS]->GetRMS());
	  grXrms[ipu][iL]->SetPointError(iS+1,0,p_posx[ipu][iL][iS]->GetRMSError());
	  if (xval < resxmin[ipu][iL]){
	    resxmin[ipu][iL] = xval;
	    wxminall[ipu][iL][ieta] = w0;
	    wxmin[ipu][iL] = w0;
	  }
	  double yval = useFit? fity->GetParameter(2) : p_posy[ipu][iL][iS]->GetRMS();
	  if (savePoint) p_chi2ndf->Fill(fity->GetChisquare()/fity->GetNDF());
	  grY[ipu][iL]->SetPoint(iS+1,w0,fity->GetParameter(2));
	  grY[ipu][iL]->SetPointError(iS+1,0,fity->GetParError(2));
	  grYrms[ipu][iL]->SetPoint(iS+1,w0,p_posy[ipu][iL][iS]->GetRMS());
	  grYrms[ipu][iL]->SetPointError(iS+1,0,p_posy[ipu][iL][iS]->GetRMSError());
	
	  if (yval < resymin[ipu][iL]){
	    resymin[ipu][iL] = yval;
	    wyminall[ipu][iL][ieta] = w0;
	    wymin[ipu][iL] = w0;
	  }
	}
	grX[ipu][iL]->SetTitle(";W0; #sigma(x-xt) (mm)");
	grY[ipu][iL]->SetTitle(";W0; #sigma(y-yt) (mm)");
	grX[ipu][iL]->SetLineColor(ipu+1);
	grX[ipu][iL]->SetMarkerColor(ipu+1);
	grX[ipu][iL]->SetMarkerStyle(ipu+21);
	grY[ipu][iL]->SetLineColor(ipu+1);
	grY[ipu][iL]->SetMarkerColor(ipu+1);
	grY[ipu][iL]->SetMarkerStyle(ipu+21);

	grXrms[ipu][iL]->SetLineColor(ipu+3);
	grXrms[ipu][iL]->SetMarkerColor(ipu+3);
	grXrms[ipu][iL]->SetMarkerStyle(ipu+23);
	grYrms[ipu][iL]->SetLineColor(ipu+3);
	grYrms[ipu][iL]->SetMarkerColor(ipu+3);
	grYrms[ipu][iL]->SetMarkerStyle(ipu+23);

	mycx[iL/6]->cd(iL%6+1);
	grX[ipu][iL]->Draw(ipu==0?"APL":"PLsame");
	grXrms[ipu][iL]->Draw("PLsame");
	//gStyle->SetStatX(0.4);
	//gStyle->SetStatY(1.0);
	//p_Exy[ipu][iL]->Draw("colztext");
	sprintf(buf,"Layer %d",iL);
	lat.DrawLatexNDC(0.4,0.85,buf);
	mycy[iL/6]->cd(iL%6+1);
	grY[ipu][iL]->Draw(ipu==0?"APL":"PLsame");
	grYrms[ipu][iL]->Draw("PLsame");
	lat.DrawLatexNDC(0.4,0.85,buf);

      }//loop on layers

      //return 1;
    }//loop on pu

    if (savePoint) {
      mycFit->Print("PLOTS/fits_x.pdf]");
      mycFit->Print("PLOTS/fits_y.pdf]");
    }

    return 1;

    TLegend *leg = new TLegend(0.6,0.6,0.94,0.94);
    leg->SetFillColor(0);
    if (grX[0][10]) leg->AddEntry(grX[0][10],"fit pu=0","P");
    if (grXrms[0][10]) leg->AddEntry(grXrms[0][10],"RMS pu=0","P");
    if (grX[1][10]) leg->AddEntry(grX[1][10],"fit pu=140","P");
    if (grXrms[1][10]) leg->AddEntry(grXrms[1][10],"RMS pu=140","P");
    for (unsigned iC(0);iC<nCanvas;++iC){
      mycx[iC]->cd(1);
      leg->Draw("same");
      mycx[iC]->Update();
      std::ostringstream lsave;
      lsave << "PLOTS/logWeighted_x_" << 6*iC << "_" << 6*iC+5 << "_" << pteta.str() ;
      lsave << ".pdf";
      mycx[iC]->Print(lsave.str().c_str());
      mycx[iC]->Update();
	
      mycy[iC]->cd(1);
      leg->Draw("same");
      lsave.str("");
      lsave << "PLOTS/logWeighted_y_" << 6*iC << "_" << 6*iC+5 << "_" << pteta.str();
      lsave << ".pdf";
      mycy[iC]->Print(lsave.str().c_str());
    }
      
    //plot w0min vs layer
    TGraph *grW[4] = {0,0,0,0};
    for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu
      std::cout << " --Processing pu " << pu[ipu] << std::endl;
	
      grW[2*ipu] = new TGraph(nLayers,lay,wxmin[ipu]);
      grW[2*ipu+1] = new TGraph(nLayers,lay,wymin[ipu]);
      for (unsigned iL(0);iL<nLayers;++iL){
	std::cout << " if (layer==" << iL 
		  << ") return " << (wxmin[ipu][iL]+wymin[ipu][iL])/2. <<";"
	  //		<< " minimum x= " << grX[ipu][iL]->GetYaxis()->GetXmin()
	  //		<< " minimum y= " << grY[ipu][iL]->GetYaxis()->GetXmin()
		  << std::endl;
      }
      mycW->cd();
      grW[2*ipu]->SetTitle(";layer;W0");
      grW[2*ipu]->SetMaximum(6);
      grW[2*ipu]->SetMinimum(0);
      grW[2*ipu]->SetLineColor(2*ipu+1);
      grW[2*ipu]->SetMarkerColor(2*ipu+1);
      grW[2*ipu]->SetMarkerStyle(20+2*ipu+1);
      grW[2*ipu+1]->SetLineColor(2*ipu+2);
      grW[2*ipu+1]->SetMarkerColor(2*ipu+2);
      grW[2*ipu+1]->SetMarkerStyle(20+2*ipu+2);
      if (ipu==0) {
	grW[2*ipu]->Draw("APL");
	grW[2*ipu+1]->Draw("PLsame");
      }
      else {
	grW[2*ipu]->Draw("PLsame");
	grW[2*ipu+1]->Draw("PLsame");
      }
    }
    std::ostringstream lsave;
    lsave << "PLOTS/w0minvsLayers_" << pteta.str();
    if (useFit) lsave << "_fit";
    else lsave << "_rms";
    lsave << ".pdf";
    mycW->Update();
    mycW->Print(lsave.str().c_str());

    if (savePoint) fout->Write();
    else {
      for (unsigned i(0);i<4;++i){
	if (grW[i]) grW[i]->Delete();
      }
      for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu
	for (unsigned iL(0); iL<nLayers;++iL){//loop on layers
	  grX[ipu][iL]->Delete();
	  grXrms[ipu][iL]->Delete();
	  grY[ipu][iL]->Delete();
	  grYrms[ipu][iL]->Delete();
	  p_deltavsreco_x[ipu][iL]->Delete();
	  p_deltavsreco_y[ipu][iL]->Delete();
	  for (unsigned iS(0); iS<nScans;++iS){
	    p_posx[ipu][iL][iS]->Delete();
	    p_posy[ipu][iL][iS]->Delete();
	  }
	}
      }
    }

    std::cout << " -- eta point finished successfully" << std::endl;

  }//loop on eta

  //plot w0min vs pt for all eta
  TGraph *grW[4] = {0,0,0,0};
  mycW->Clear();
  for (unsigned iL(0); iL<nLayers;++iL){//loop on layers
    for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu
      std::cout << " --Processing pu " << pu[ipu] << std::endl;
      grW[2*ipu] = new TGraph(neta,etaval,wxminall[ipu][iL]);
      grW[2*ipu+1] = new TGraph(neta,etaval,wyminall[ipu][iL]);
      mycW->cd();//ieta+1);
      grW[2*ipu]->SetTitle(";#eta;W0");
      grW[2*ipu]->SetMaximum(6);
      grW[2*ipu]->SetMinimum(0);
      grW[2*ipu]->SetLineColor(2*ipu+1);
      grW[2*ipu]->SetMarkerColor(2*ipu+1);
      grW[2*ipu]->SetMarkerStyle(20+2*ipu+1);
      grW[2*ipu+1]->SetLineColor(2*ipu+2);
      grW[2*ipu+1]->SetMarkerColor(2*ipu+2);
      grW[2*ipu+1]->SetMarkerStyle(20+2*ipu+2);
      if (ipu==0) {
	grW[2*ipu]->Draw("APL");
	grW[2*ipu+1]->Draw("PLsame");
      }
      else {
	grW[2*ipu]->Draw("PLsame");
	grW[2*ipu+1]->Draw("PLsame");
      }
    }//loop on pu
    std::ostringstream lsave;
    lsave << "PLOTS/w0minvseta_layer" << iL;
    if (useFit) lsave << "_fit";
    else lsave << "_rms";
    lsave << ".pdf";
    
    char buf[500];
    TLatex lat;
    sprintf(buf,"Layer %d",iL);
    lat.DrawLatexNDC(0.1,0.96,buf);
    
    mycW->Update();
    mycW->Print(lsave.str().c_str());
  }//loop on layers
  
  
  return 0;
}//main
//___________________________________________________________________________________
void SliceH2(
  // input
  const TH2 *h, const TString &axis, const Int_t n, Double_t fitMin, Double_t fitMax, const Double_t &factorSigma,
  // output
  TGraphErrors &*grMean, TGraphErrors &*grSigma)
{
  // Slice the h
  // Fit each slice to the gaus
  
  // Arrays for the output graphs
  Double_t x[n]    = {0.};
  Double_t errX[n] = {0.};
  Double_t sigma[n]    = {0.};
  Double_t errSigma[n] = {0.};
  Double_t mean[n]    = {0.};
  Double_t errMean[n] = {0.};
  
  // Get # of bin in the h
  Int_t nbins = 0;
  TAxis *axisPr, *axisSliced;
  if (axis != "y")
  {
    cout << "X-projections" << endl;
    nbins = h->GetNbinsY();
    axisSliced = h->GetYaxis();
    axisPr = h->GetXaxis();
  }
  else
  {
    cout << "Y-projections" << endl;
    nbins = h->GetNbinsX();
    axisSliced = h->GetXaxis();
    axisPr = h->GetYaxis();
  }
  
  // Slice step
  Int_t step = 0;
  if ( n != 0 ) step = ceil(Double_t(nbins)/n);
  
  // Bin counter. The first bin = 1
  Int_t i = 1;
  
  // # of points in the output graphs
  Int_t nPoints = 0;
  
  // Make the slices
  TH1D *hTmp = NULL;
  TCanvas *cTmp = new TCanvas();
  Char_t buf[10];
  Double_t xTmp;
  TString nameTmp;
  Int_t iUp = (step != 0) ? i+step-1 : nbins+1;
  while ( iUp <= nbins )
  {
    xTmp = (axisSliced->GetBinLowEdge(i) + axisSliced->GetBinUpEdge(iUp))/2.;
    sprintf(buf,"%d",xTmp);
    nameTmp = TString(axisSliced->GetTitle())+" = "+TString(buf);
    if (axis != "y") hTmp = h->ProjectionX(nameTmp, i, iUp, "e");
    else             hTmp = h->ProjectionY(nameTmp, i, iUp, "e");
    hTmp->Draw();
    if (fitMin != fitMax) hTmp->Fit("gaus","","",fitMin,fitMax);
//     cTmp->WaitPrimitive();
    if ( hTmp->GetFunction("gaus") )
    {
      x[nPoints] = xTmp;
      sigma[nPoints]    = hTmp->GetFunction("gaus")->GetParameter(2)/factorSigma;
      errSigma[nPoints] = hTmp->GetFunction("gaus")->GetParError(2)/factorSigma;
      mean[nPoints]     = hTmp->GetFunction("gaus")->GetParameter(1);
      errMean[nPoints]  = hTmp->GetFunction("gaus")->GetParError(1);
      if ( errSigma[nPoints] < 99999.9 ) ++nPoints;
    }
    i += step;
    iUp = i+step-1;
    delete hTmp;
  }
  
  // "Sigma" graph
  grSigma = new TGraphErrors(nPoints,x,sigma,errX,errSigma);
  
  // "Mean" graph
  grMean = new TGraphErrors(nPoints,x,mean,errX,errMean);
  
  delete cTmp;
}
Пример #17
0
// ----------------------------------------------------------------------
void invertedMuonID2Comb(string era = "2016BF", float bdt = -99., TH1D *hBd = 0,  TH1D *hBs = 0) {
  if ("all" == era) {
    invertedMuonID2Comb("2016BF");
    invertedMuonID2Comb("2016GH");
    invertedMuonID2Comb("2011");
    invertedMuonID2Comb("2012");
    return;
  }

  TFile *fd(0), *fm0(0), *fm1(0);
  float bdtcut(0.);
  cout << "======================================================================" << endl;
  if (era == "2016BF") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016BF-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016BF-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016BF-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.30;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2016GH") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmCharmonium2016GH-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BdToMuMu-2016GH-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-RunIISpring16DR80-BsToMuMu-2016GH-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.31;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2012") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2012-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Winter17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.34;
    } else {
      bdtcut = bdt;
    }
  } else if (era == "2011") {
    fd = TFile::Open("/scratch/ursl/bmm4/s01/bmm-data-bmmMuOnia2011-s01.root");
    fm0 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BdToMuMu-s01.root");
    fm1 = TFile::Open("/scratch/ursl/bmm4/s01/bmm-mc-Summer17_private-BsToMuMu-s01.root");
    if (bdt < -1.) {
      bdtcut = 0.28;
    } else {
      bdtcut = bdt;
    }
  }

  TTree *td = (TTree*)fd->Get("candAnaMuMu/events");
  TTree *tm0 = (TTree*)fm0->Get("candAnaMuMu/events");
  TTree *tm1 = (TTree*)fm1->Get("candAnaMuMu/events");

  TH1D *hd0 = new TH1D("hd0", "mass", 60, 4.8, 6.0);
  TH1D *hm0 = new TH1D("hm0", "mass", 60, 4.8, 6.0);
  TH1D *hm1 = new TH1D("hm1", "mass", 60, 4.8, 6.0);
  int ichan(0);
  string cut(Form("chan==%d && !gmuid &&hlt1&&tos&&l1t &&bdt>%4.3f && m < 6 && m > 4.8", ichan, bdtcut));
  cout << cut << endl;
  td->Draw("m>>hd0", cut.c_str());
  tm0->Draw("m>>hm0", cut.c_str());
  tm1->Draw("m>>hm1", cut.c_str());

  c0->Clear();
  // c0->Divide(2,2);
  // c0->cd(1);
  hd0->Draw("hist");
  // B0 -> mu mu
  // c0->cd(2);
  hm0->Fit("gaus");
  double p0 = hm0->GetFunction("gaus")->GetParameter(1);
  double s0 = hm0->GetFunction("gaus")->GetParameter(2);
  cout << "p0: " << p0 << " s0: " << s0 << endl;
  // Bs -> mu mu
  // c0->cd(3);
  hm1->Fit("gaus");
  double p1 = hm1->GetFunction("gaus")->GetParameter(1);
  double s1 = hm1->GetFunction("gaus")->GetParameter(2);
  cout << "p1: " << p1 << " s1: " << s1 << endl;

  // c0->cd(4);
  TH1D *hFit = (TH1D*)hd0->Clone("hFit");
  hFit->SetTitle("");
  hFit->SetMinimum(0.);
  TF1 *f1 = new TF1("f1", adhocfunction, 4.8, 6.0, 7);
  f1->SetParameter(0, 1);  f1->SetParLimits(0, 0., 1000.);
  f1->SetParameter(1, p0); f1->FixParameter(1, p0);
  f1->SetParameter(2, s0); f1->FixParameter(2, s0);
  f1->SetParameter(3, 1);  f1->SetParLimits(3, 0., 1000.);
  f1->SetParameter(4, p1); f1->FixParameter(4, p1);
  f1->SetParameter(5, s1); f1->FixParameter(5, s1);
  f1->SetParameter(6, 1);

  hFit->Fit(f1, "RL", "", 5.1, 6.0);

  double nb0 = hFit->GetFunction("f1")->GetParameter(0);
  double eb0 = hFit->GetFunction("f1")->GetParError(0);
  double nbs = hFit->GetFunction("f1")->GetParameter(3);
  double ebs = hFit->GetFunction("f1")->GetParError(3);
  double nco = hFit->GetFunction("f1")->GetParameter(6);
  double eco = hFit->GetFunction("f1")->GetParError(6);

  TF1 *f0 = (TF1*)hm0->GetFunction("gaus")->Clone("f0");
  TF1 *fs = (TF1*)hm1->GetFunction("gaus")->Clone("fs");

  f0->SetParameter(0, nb0); f0->SetLineColor(kRed+2);
  fs->SetParameter(0, nbs); fs->SetLineColor(kBlue);
  f0->Draw("same");
  fs->Draw("same");
  tl->DrawLatexNDC(0.10, 0.92, era.c_str());
  tl->DrawLatexNDC(0.40, 0.92, Form("BDT > %3.2f", bdtcut));
  double iB0   = f0->Integral(5.1, 5.6);
  double iBs   = fs->Integral(5.1, 5.6);
  float  nB0   = f0->Integral(5.2, 5.3)/hFit->GetBinWidth(1);
  float  nB0E  = eb0/nb0*nB0;
  float  nBs   = fs->Integral(5.3, 5.45)/hFit->GetBinWidth(1);
  float  nBsE  = ebs/nbs*nBs;
  double iComb = nco*(6.0-5.6);
  double ratioVs(0.);
  double relErrs(0.);
  double ratioEs(0.01);
  double ratioVd(0.);
  double relErrd(0.);
  double ratioEd(0.01);
  if (iComb > 1.e-3) {
    ratioVs = iBs/iComb;
    relErrs = TMath::Sqrt((ebs/nbs)*(ebs/nbs) + (eco/nco)*(eco/nco));
    ratioEs = relErrs * ratioVs;

    ratioVd = iB0/iComb;
    relErrd = TMath::Sqrt((eb0/nb0)*(eb0/nb0) + (eco/nco)*(eco/nco));
    ratioEd = relErrd * ratioVd;
 }

  cout << "ratio of B0/comb: " << iB0 << "/" << iComb << " = " << ratioVd << " +/- " << ratioEd << " relErr: " << relErrd << endl;
  cout << "ratio of Bs/comb: " << iBs << "/" << iComb << " = " << ratioVs << " +/- " << ratioEs << " relErr: " << relErrs << endl;

  ofstream TEX(Form("invertedMuonIDStudies.tex"), ios::app);
  TEX << Form("\\vdef{%ss01:nb0:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nB0) << endl;
  TEX << Form("\\vdef{%ss01:eb0:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nB0E) << endl;
  TEX << Form("\\vdef{%ss01:nbs:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nBs) << endl;
  TEX << Form("\\vdef{%ss01:ebs:bdt%3.2f:chan%d}  {%3.1f}", era.c_str(), bdtcut, ichan, nBsE) << endl;
  TEX.close();

  c0->SaveAs(Form("invertedMuonIDcomb-%s-%3.2f.pdf", era.c_str(), bdtcut));

  if (hBd) {
    hBd->SetBinContent(hBd->FindBin(bdtcut), ratioVd);
    hBd->SetBinError(hBd->FindBin(bdtcut), ratioEd);
  }
  if (hBs) {
    hBs->SetBinContent(hBs->FindBin(bdtcut), ratioVs);
    hBs->SetBinError(hBs->FindBin(bdtcut), ratioEs);
  }
}