Ejemplo n.º 1
0
void flavor_ana(int doMC=1,
                const char * JecType = "abs",
                const char * inFile0Name="../outputs/jetSkimRelValQCD_Pt_80_120_sw354-JEC_Summer09_7TeV_ReReco332.root",
                const char * inFile1Name="djtree_JEC_Summer09_7TeV_ReReco332.root")
{
    // Define Inputs
    cout << "======= Inputs: ========" << endl;
    //cout << "Inclusive jets: " << inFile0Name << endl;
    //cout << "Dijets:         " << inFile1Name << endl;
    //TFile * inFile0 = new TFile(inFile0Name);
    //TFile * inFile1 = new TFile(inFile1Name);
    TFile * inFile0 = new TFile("../outputs/jetSkimRelValQCD_Pt_80_120_sw354-JEC_Summer09_7TeV_ReReco332.root");
    TFile * inFile1 = new TFile(Form("djtree_JEC_Summer09_7TeV_ReReco332_%s.root",JecType));
    TTree * Events;
    inFile0->GetObject("Events",Events);
    TTree * djtree;
    inFile1->GetObject("djtree",djtree);
    aliases(Events);

    // === Dijets ===
    cout << endl << "================ dijets ==============" << endl;
    Int_t numPreSelEvtl = djtree->GetEntries("vz>-99");
    cout << "Events:" << endl;
    cout << "- with none-fake vtx: " << numPreSelEvtl << endl;
    //  - selection -
    TCut evtSelDj("nlpet>80 && nlpet<120 && alpet>80 && jdphi>2.8");
    TCut evtSelDj2("nlpet>80 && nlpet<120 && alpet>80 && jdphi>3.0");
    Int_t numSelEvt1 = djtree->GetEntries(evtSelDj);
    cout << "- Passing sel: " << numSelEvt1 << endl;
    Int_t numSelEvt2 = djtree->GetEntries(evtSelDj2);
    cout << "- Passing diphi sel: " << numSelEvt2 << endl;

    // === flavor studies ===
    TProfile * hNrJFlav = new TProfile("hNrJFlav","flavor",10,85,110);
    hNrJFlav->SetMarkerColor(kRed);
    hNrJFlav->SetLineColor(kRed);
    hNrJFlav->SetMarkerStyle(kOpenCircle);
    hNrJFlav->SetMinimum(0.);
    hNrJFlav->SetMaximum(0.7);
    hNrJFlav->SetTitle(";p_{T}^{gen jet};q jet fraction");
    TProfile * hAwJFlav = (TProfile*)hNrJFlav->Clone("hAwJFlav");
    hAwJFlav->SetMarkerColor(kBlue);
    hAwJFlav->SetLineColor(kBlue);

    TCanvas * cJFlav = new TCanvas("cJFlav","cJFlav",500,500);
    TCut matParton("nlpstat>-99&&alpstat>-99");
    djtree->Draw("(abs(nlpid)<6):nlpet>>hNrJFlav",evtSelDj&&matParton,"prof");
    djtree->Draw("(abs(alpid)<6):alpet>>hAwJFlav",evtSelDj&&matParton,"prof same");

    TLegend *leg2 = new TLegend(0.605,0.216,0.905,0.369,NULL,"brNDC");
    leg2->SetFillColor(0);
    leg2->SetBorderSize(0);
    leg2->SetTextSize(0.03);
    leg2->AddEntry(hNrJFlav,"Di-Jets, Near Jet","p");
    leg2->AddEntry(hAwJFlav,"Di-Jets, Away Jet","p");
    leg2->Draw();
    cJFlav->Print("plots/cDJFlavor.gif");
}
Ejemplo n.º 2
0
// ----------------------------------------------------------------------
void nmod(const int offset = 400) {
  
  c0.Clear();
  c0.Divide(2,8);

  tl->SetTextSize(0.2);
  tl->SetNDC(kTRUE);
  tl->SetTextAngle(90); 
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gROOT->ForceStyle();

  double min(-1), max(-1);
  if (offset == 600) {
    min = 120; 
    max = 200;
  }


  TProfile *p;
  for (int i = 0; i < 16; ++i) {
    c0.cd(i+1);
    p = (TProfile*)gFile->Get(Form("p%i", offset+i));
    if (min > -1) {
      p->SetMinimum(min);
      p->SetMaximum(max);
    }
    p->Draw();
    
    tl->DrawLatex(0.2, 0.11, Form("Chip %i", i)); 
  }

  if (offset == 400) c0.SaveAs("ped-nmod.ps");
  if (offset == 500) c0.SaveAs("gain-nmod.ps");
  if (offset == 600) c0.SaveAs("noise-nmod.ps");
  if (offset == 700) c0.SaveAs("pedgain-nmod.ps");

  
}
Ejemplo n.º 3
0
void fitBjetJES(int ppPbPb=1, int cbinlo=12, int cbinhi=40){

  if(!ppPbPb){
    cbinlo=0;
    cbinhi=40;
  }

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);

  TFile *fL;
  
  if(!ppPbPb)fL=new TFile("histos/ppMC_hiReco_jetTrig_highPurity_JEC.root");
  else     fL=new TFile("histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root");

  // these are dummy files for pp
  TFile *fB=new TFile("histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root");
  TFile *fC=new TFile("histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root");


  TNtuple *tL = (TNtuple*) fL->Get("nt");
  TNtuple *tB = (TNtuple*) fB->Get("nt");
  TNtuple *tC = (TNtuple*) fC->Get("nt");
  
  float jtptL, refptL, jtetaL, weightL, refparton_flavorForBL, binL;

  tL->SetBranchAddress("jtpt",&jtptL);
  tL->SetBranchAddress("jteta",&jtetaL);
  tL->SetBranchAddress("refpt",&refptL);
  tL->SetBranchAddress("weight",&weightL);
  if(ppPbPb)tL->SetBranchAddress("bin",&binL);
  tL->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBL);

  float jtptB, refptB, jtetaB, weightB, refparton_flavorForBB, binB;

  tB->SetBranchAddress("jtpt",&jtptB);
  tB->SetBranchAddress("jteta",&jtetaB);
  tB->SetBranchAddress("refpt",&refptB);
  tB->SetBranchAddress("weight",&weightB);
  if(ppPbPb)tB->SetBranchAddress("bin",&binB);
  tB->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBB);

  float jtptC, refptC, jtetaC, weightC, refparton_flavorForBC, binC;

  tC->SetBranchAddress("jtpt",&jtptC);
  tC->SetBranchAddress("jteta",&jtetaC);
  tC->SetBranchAddress("refpt",&refptC);
  tC->SetBranchAddress("weight",&weightC);
  if(ppPbPb)tC->SetBranchAddress("bin",&binC);
  tC->SetBranchAddress("refparton_flavorForB",&refparton_flavorForBC);

  TProfile  *hL = new TProfile("hL","hL",250,50,300,0,10);
  TProfile  *hB = new TProfile("hB","hB",250,50,300,0,10);
  TProfile  *hC = new TProfile("hC","hC",250,50,300,0,10);
  hL->Sumw2(),hB->Sumw2(),hC->Sumw2();


  for(int i=0;i<tL->GetEntries();i++){
    tL->GetEntry(i);
    if(!ppPbPb) binL=39;

    if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi)
      hL->Fill(refptL,jtptL/refptL,weightL); 


    if(!ppPbPb){
      if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==5)
	hB->Fill(refptL,jtptL/refptL,weightL);
      
      if(fabs(jtetaL)<2 && binL>=cbinlo && binL<cbinhi && abs(refparton_flavorForBL)==4)
	hC->Fill(refptL,jtptL/refptL,weightL);      
    }
  }

  if(ppPbPb){
    for(int i=0;i<tB->GetEntries();i++){
      tB->GetEntry(i);
      if(fabs(jtetaB)<2 && binB>=cbinlo && binB<cbinhi && abs(refparton_flavorForBB)==5)
	hB->Fill(refptB,jtptB/refptB,weightB);
    }
    for(int i=0;i<tC->GetEntries();i++){
      tC->GetEntry(i);
      if(fabs(jtetaC)<2 && binC>=cbinlo && binC<cbinhi && abs(refparton_flavorForBC)==4)
	hC->Fill(refptC,jtptC/refptC,weightC);
    }
  }

  
 
  hL->SetMinimum(0.);
  
  hL->SetLineColor(kBlue);
  hB->SetLineColor(kRed);
  hC->SetLineColor(kGreen);

  hL->SetMarkerColor(kBlue);
  hB->SetMarkerColor(kRed);
  hC->SetMarkerColor(kGreen);
  
  //hL->SetMarkerStyle(4);
  //hB->SetMarkerStyle(4);
  //hC->SetMarkerStyle(4);
  
  hL->SetXTitle("genJet p_{T} (GeV/c)");
  hL->SetYTitle("<reco p_{T} / gen p_{T} >");

  hL->GetXaxis()->SetRangeUser(50.,199.999);
  hL->GetYaxis()->SetRangeUser(0.5,1.05);
  
  TCanvas *c1=new TCanvas("c1","c1",800,600);
  c1->SetGridx(1);
  c1->SetGridy(1);

  hL->Draw("e1");
  hB->Draw("e1,same");
  hC->Draw("e1,same");

  TLegend *leg=new TLegend(0.4,0.15,0.9,0.45);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  if(ppPbPb&&cbinlo==0&&cbinhi==40)leg->SetHeader("Pythia+Hydjet, 0-100%");
  leg->AddEntry(hL,"Inclusive jets","pl");
  leg->AddEntry(hC,"c-jets","pl");
  leg->AddEntry(hB,"b-jets","pl");
  leg->Draw();

  TCanvas *c2=new TCanvas("c2","c2",1);
  /*
  TH1F *hL2 = (TH1F*)hL->Clone("hL2");
  TH1F *hB2 = (TH1F*)hB->Clone("hB2");
  hL2->Add(hB2,-1);
  hL2->Draw();
  */

  TH1F  *hcorr = new TH1F("hcorr","hcorr",250,50,300);
  hcorr->Sumw2();

  for(int i=0;i<hL->GetNbinsX();i++){
    cout<<" b resp "<<hB->GetBinContent(i+1)<<endl;
    cout<<" l resp "<<hL->GetBinContent(i+1)<<endl;
    cout<<" l offset "<<1.-hL->GetBinContent(i+1)<<endl;
    cout<<" corrected b resp "<<hB->GetBinContent(i+1)+1.-hL->GetBinContent(i+1)<<endl;
    float jesOffset = 1.-hL->GetBinContent(i+1);

    hcorr->SetBinContent(i+1,hB->GetBinContent(i+1)+jesOffset);

    hcorr->SetBinError(i+1,sqrt(hB->GetBinError(i+1)*hB->GetBinError(i+1)+hL->GetBinError(i+1)*hL->GetBinError(i+1)));


  }

  hcorr->SetMinimum(0.5);
  hcorr->SetMaximum(1.1);
      
  hcorr->SetLineColor(kRed);
  hcorr->SetMarkerColor(kRed);
  hcorr->SetMarkerStyle(4);
  hcorr->Draw();

  TF1 *fCorr = new TF1("fCorr","[0]+[1]*log(x)+[2]*log(x)*log(x)",50,300);
  fCorr->SetLineWidth(1);
  fCorr->SetLineColor(kBlue);
  hcorr->Fit(fCorr);

  TFile *fout;
  if(ppPbPb) fout =new TFile(Form("bJEShistos/bJetScale_PbPb_Cent_fineBin_%d_%d.root",cbinlo,cbinhi),"recreate");
  else fout =new TFile("bJEShistos/bJetScale_PP_fineBin.root","recreate");
  hcorr->Write();
  fCorr->Write();
  fout->Close();

}
Ejemplo n.º 4
0
void makePlots (string configFilePath){

  if (( nHistList % inputRootFile.size() == 0 )) 
    {
      for (int i=0; i<numHistos; i++) 
        {
	 
          TCanvas *c = new TCanvas(theHistNameStrings.at(i).c_str(), "", 81,58,500,602);
 
          TH1* h_mc;        // histograms for MC
          TH1* h_mc_clone;  // histograms for MC 
          TH1* h_data;      // histogram to store data points 
	  TH1* h_data_clone;
          TLegend *legend = new TLegend(0.2, 0.85-.035*inputLegend.size(), 0.5, 0.90,NULL,"brNDC");
          int whichHisto = 0;
	  
          for (int j=1;j<inputRootFile.size();j++)
	    {
	      
	      whichHisto=j*numHistos; 
	      
	      int a = 0;
	      bool foundHisto = false;
              
	      if (theHistNameStrings.at(i) == theHistNameStrings.at(i+whichHisto)) 
		{
		  foundHisto=true; 
		  a=i;
		}
	      
	      else 
		{
		  for (a = 0; a < numHistos; a++)
		    {
		      if (theHistNameStrings.at(i) == theHistNameStrings.at(a+whichHisto))
			{
			  foundHisto = true;
			  break;
			}
		    }
		}
	      //-----------------------------------------------------------
              
	      string hist2name = listHistos->At(a+whichHisto)->GetName();
	      if (foundHisto == true)
		{
                  h_data = (TH1*)listHistos->At(i);
                  h_data->SetMarkerStyle(inputMarkerStyle.at(0));
                  h_data = SetStyleh(h_data);
                  h_data->Sumw2();
                  int thelineStyle = inputSetLineStyle.at(j);
                  int thelineWidth = inputSetLineWidth.at(j);
                  int setcolor = inputColor.at(j);
                  int marker   = inputMarkerStyle.at(j);
                  h_data->SetMarkerColor(inputColor.at(0));
                  h_data->SetLineColor(inputColor.at(0));
                  if (j == 1) 
                    { 
		       if ( h_data->IsA()->InheritsFrom( "TH2" ) ) {
			 //n.b. that ProfileX will do nothing if the
			 //name you choose is alreayd taken!  so each
			 //profileX needs a unique name
			 TString profileName = TString::Format("%s_data_pfx",h_data->GetName());
			 TProfile *dataProf = ((TH2*)h_data)->ProfileX(profileName.Data());
			 dataProf->SetMinimum(h_data->GetMinimum()); //min/max values were stored in the original hist
			 dataProf->SetMaximum(h_data->GetMaximum());
			 dataProf->Draw("");
			 
			 //profileX cretaes a clone, so no need to
			 //clone again here.  Need to set the hist
			 //name so root doesn't complain
			 TString cloneName = TString::Format("%s_data_pfx_clone",h_data->GetName());
			 TString cloneName2 = TString::Format("%s_data_pfx_clone_px",h_data->GetName());
			 h_data_clone = ((TH2*)h_data)->ProfileX(cloneName.Data())->ProjectionX(cloneName2.Data());
		       }
		       else { //1d case
                         Float_t ymaxc = gPad->GetUymax();
                         //h_data->SetMaximum(ymaxc+0.15*ymaxc);
			 h_data->Draw("ep1");
			 h_data_clone = (TH1*)h_data->Clone();
		       }
                       //h_data->SetLineColor(1);
                       h_data->SetLineStyle(thelineStyle);
                       h_data->SetLineWidth(thelineWidth);
                       float rms_data = h_data->GetRMS();
                       float mean_data = h_data->GetMean();
                       std::stringstream legend_data;
                       legend_data.str("");
                       legend_data << inputLegend.at(0).c_str() << ": mean=" << setprecision(3)
                                   <<mean_data <<", rms=" << setprecision(3) <<rms_data<< endl;
                       legend->AddEntry(h_data,legend_data.str().c_str(), "lep");

                    }
		  h_mc = (TH1*)listHistos->At(a+whichHisto);
                  h_mc = SetStyleh(h_mc);
		  h_mc->SetName(hist2name.c_str());
                  //cout<<"NAME "<<h_mc->GetName()<<endl;
		  // Style
                  
		  string processlegend = (inputLegend.at(j)).c_str();
 
		  h_mc->SetLineStyle(thelineStyle);
		  h_mc->SetLineWidth(thelineWidth);
		  h_mc->SetLineColor(setcolor);
                  h_mc->SetMarkerStyle(marker);
                  h_mc->SetMarkerColor(setcolor);                 
 
                  string processlegend = (inputLegend.at(j)).c_str(); 

		  if ( h_mc->IsA()->InheritsFrom( "TH2" ) ) {
		    TString profileName = TString::Format("%s_mc_pfx", h_mc->GetName());
		    ((TH2*)h_mc)->ProfileX(profileName.Data())->Draw("SAME");
		    //profileX cretaes a clone, so no need to
		    //clone again here.  Need to set the hist
		    //name so root doesn't complain
		    TString cloneName = TString::Format("%s_mc_pfx_clone",h_mc->GetName());
		    TString cloneName2 = TString::Format("%s_mc_pfx_clone_px",h_mc->GetName());
		    h_mc_clone = ((TH2*)h_mc)->ProfileX(cloneName.Data())->ProjectionX(cloneName2.Data());
		  } else { //1d case
                    Float_t ymaxc = gPad->GetUymax();
                    h_mc->SetMaximum(ymaxc+0.15*ymaxc);
		    h_mc->Draw("epsame");
		    h_mc_clone = (TH1*)h_mc->Clone();
		  }
                  h_mc_clone->SetMarkerStyle(marker);
                  h_mc_clone->SetMarkerColor(setcolor);
                  float rms_mc = h_mc->GetRMS();
                  float mean_mc = h_mc->GetMean();
		  std::stringstream legend_mc;
                  legend_mc.str("");
                  legend_mc << processlegend.c_str() << " - "<< "mean: " << setprecision(3)
                              <<mean_mc <<" , rms: " << setprecision(3) <<rms_mc<< endl;
                  legend->AddEntry(h_mc, legend_mc.str().c_str(), "lep"); 
		}// close if (foundHisto)
 
	      legend->SetTextFont(42);
              legend->SetTextSize(.04);
              legend->SetMargin(0.15);
              legend->SetLineColor(1);
              legend->SetLineStyle(1);
              legend->SetLineWidth(1);
              legend->SetFillColor(0);
              legend->SetFillStyle(0);
              legend->SetBorderSize(0);
              legend->SetFillColor(kWhite);
              legend->Draw();
 
	      c->cd();
 	      
              if (j == 1)
                {
	           float startxbin = h_data_clone->GetXaxis()->GetBinWidth(h_data_clone->GetXaxis()->GetFirst()) * 
		      (h_data_clone->GetXaxis()->GetFirst() - 1);
	           float lastxbin  = h_data_clone->GetXaxis()->GetBinCenter(h_data_clone->GetXaxis()->GetNbins());
	      
	            double x1 = 0;
	            double x2 = lastxbin + h_data_clone->GetXaxis()->GetBinWidth(h_data_clone->GetXaxis()->GetNbins())/2.;
	      
	            if (h_data_clone->GetXaxis()->GetBinCenter(0) <= 0)
		        x1 = h_data_clone->GetXaxis()->GetBinCenter(0) + h_data_clone->GetXaxis()->GetBinWidth(0)/2. + startxbin;
	            else 
		        x1 = h_data_clone->GetXaxis()->GetBinCenter(0) - h_data_clone->GetXaxis()->GetBinWidth(0)/2. - startxbin;
	        } 
	  
	    } // close for loop inputRootFile
	  
	  TFile *hfile = (TFile*)gROOT->FindObject(HistosOutputRootFile.c_str());
	  if (hfile) {hfile->Close();}
	  hfile = new TFile(HistosOutputRootFile.c_str(),"UPDATE");

          for (int o = 0; o < inputHistoName.size(); o++)
             {
                if ( c->GetName() == inputHistoName.at(o) )
                  {
                     string save = configFilePath+"/"+inputHistoName.at(o)+".pdf";  
                     c->SaveAs(save.c_str());
                     c->Write();    
                     break;
                  }
             }

	  hfile->Close();
          c->Close();
	  
	}  // close foor loop numHistos     
      
    } // close if numHistos % inputRootFile.size() == 0
} // close  makePlots function
Ejemplo n.º 5
0
void makePlot(char* canv)
{
	t->SetBranchAddress("LM_PX1", &intree.LM_PX1);
	t->SetBranchAddress("LM_PX2", &intree.LM_PX2);
	t->SetBranchAddress("LM_PY1", &intree.LM_PY1);
	t->SetBranchAddress("LM_PY2", &intree.LM_PY2);
	t->SetBranchAddress("LM_P2_Integral", &intree.LM_P2_Integral);
	t->SetBranchAddress("time", &intree.timeline);
	t->Print();

	if(entries<=0)
		entries = t->GetEntries();

	char title[100]=0;
	sprintf(title,"%s runs 1100-1107",canv);
	TProfile *prof = new TProfile(title,title,24,0,entries);
	TProfile *prof1 = new TProfile(title,title,24,0,entries);
	TProfile *prof2 = new TProfile(title,title,24,0,entries);

	/**************************************
     * read entries
     **************************************
    */
	Double_t *ratio = new Double_t[entries];
	Double_t *parmean = new Double_t[entries];
	Double_t *p1 = new Double_t[entries];
	Double_t *p2 = new Double_t[entries];

	for (int j = 0; j < entries; ++j){
		gSystem->Sleep (sleep);
		t->GetEntry(j);
		ratio[j] = intree.LM_PY1/intree.LM_PY2;
		p1[j] = intree.LM_PY1;
		p2[j] = intree.LM_PY2;
		//cout<<"entry "<<j<<" peak2 "<<intree.LM_PY2<<endl;
	}

	Double_t mean = TMath::Mean(entries,ratio);
	Double_t mean1 = TMath::Mean(entries,p1);
	Double_t mean2 = TMath::Mean(entries,p2);
	for (int j = 0; j < entries; ++j){
		prof->Fill(j,(ratio[j]/mean-1)*100);
		prof1->Fill(j,(p1[j]/mean1-1)*100);
		prof2->Fill(j,(p2[j]/mean2-1)*100);
	}

	TCanvas *c1 = new TCanvas(canv,"frascatirun",900,700);
	c1->cd();

    char axisXname[100];
	sprintf(axisXname,"Time (Entries) (total: %i)",entries);
	prof->SetXTitle(axisXname);
	prof->SetYTitle("Variation (%)");
	prof->SetMaximum(1);
	prof->SetMinimum(-1);
	prof->SetMarkerColor(4);
	prof->SetMarkerSize(1);
	prof->SetMarkerStyle(8);
	prof->SetStats(kFALSE);
	prof->Draw();

	prof1->SetMarkerColor(5);
	prof1->SetMarkerSize(1);
	prof1->SetMarkerStyle(6);
	prof1->Draw("same");

	prof2->SetMarkerColor(1);
	prof2->SetMarkerSize(1);
	prof2->SetMarkerStyle(7);
	prof2->Draw("same");

/*	TLegend leg = new TLegend(0.1,0.7,0.48,0.9);
	leg->SetHeader("The Legend Title");
	leg->AddEntry(h1,"Histogram filled with random numbers","f");
	leg->AddEntry("f1","Function abs(#frac{sin(x)}{x})","l");
	leg->AddEntry("gr","Graph with error bars","lep");
	leg->Draw("same");
*/
}