Пример #1
0
void drawPtEta(char *inf){
TFile a(inf);
a.cd("ana");
TProfile *h = new TProfile("h","",100,-3,3);
TCanvas *c = new TCanvas("c","",400,400);
hi->Draw("(pt):eta>>h","evtType!=92&&evtType!=93&&(abs(eta)<2.4&&chg!=0&&abs(pdg)!=11&&abs(pdg)!=13)","prof",10000);
double nevt = hi->GetEntries("evtType!=92&&evtType!=93");
h->Sumw2();
//h->Scale(2./nevt);
h->SetXTitle("#eta");
h->SetYTitle("Average P_{T}");
h->Draw();
c->SaveAs(Form("%s-PtEta-2.4.gif",inf));
c->SaveAs(Form("%s-PtEta-2.4.C",inf));
}
Пример #2
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();

}
Пример #3
0
void TOFCheck(string MODE="COMPILE")
{
  if(MODE=="COMPILE") return;

   system("mkdir pictures");

   setTDRStyle();
   gStyle->SetPadTopMargin   (0.06);
   gStyle->SetPadBottomMargin(0.15);
   gStyle->SetPadRightMargin (0.03);
   gStyle->SetPadLeftMargin  (0.07);
   gStyle->SetTitleSize(0.04, "XYZ");
   gStyle->SetTitleXOffset(1.1);
   gStyle->SetTitleYOffset(1.35);
   gStyle->SetPalette(1);
   gStyle->SetNdivisions(505,"X");
   TH1::AddDirectory(kTRUE);

   // get all the samples and clean the list to keep only the one we want to run on... Also initialize the BaseDirectory
   std::vector<stSample> samples;

   InitBaseDirectory();
   GetSampleDefinition(samples, "../../ICHEP_Analysis/Analysis_Samples.txt");
   if(MODE.find("ANALYSE_")==0){
      int sampleIdStart, sampleIdEnd; sscanf(MODE.c_str(),"ANALYSE_%d_to_%d",&sampleIdStart, &sampleIdEnd);
      keepOnlyTheXtoYSamples(samples,sampleIdStart,sampleIdEnd);
      printf("----------------------------------------------------------------------------------------------------------------------------------------------------\n");
      printf("Run on the following samples:\n");
      for(unsigned int s=0;s<samples.size();s++){samples[s].print();}
      printf("----------------------------------------------------------------------------------------------------------------------------------------------------\n\n");
   }else{
      printf("You must select a MODE:\n");
      printf("MODE='ANALYSE_X_to_Y'   : Will run the analysis on the samples with index in the range [X,Y]\n"); 
      return;
   }

   //create histogram file and run the analyis
   system("mkdir pictures/");
   TFile* OutputHisto = new TFile(("pictures/Histos_"+samples[0].Name+"_"+samples[0].FileName+".root").c_str(),"RECREATE");

   TH1D* TOF = new TH1D("TOF", "TOF", 100, 0, 2); TOF->Sumw2();
   TH1D* TOFDT  = new TH1D("TOFDT", "TOFDT", 100, 0, 2); TOFDT->Sumw2();
   TH1D* TOFCSC  = new TH1D("TOFCSC", "TOFCSC", 100, 0, 2); TOFCSC->Sumw2();
   TH1D* Vertex  = new TH1D("Vertex", "Vertex", 100, -10, 10); Vertex->Sumw2();
   TH1D* VertexDT = new TH1D("VertexDT", "VertexDT", 100, -10, 10); VertexDT->Sumw2();
   TH1D* VertexCSC = new TH1D("VertexCSC", "VertexCSC", 100, -10, 10); VertexCSC->Sumw2();
   TProfile* TOFVsEta = new TProfile("TOFVsEta", "TOFVsEta", 50, -2.1, 2.1); TOFVsEta->Sumw2();
   TProfile* TOFVsPhi = new TProfile("TOFVsPhi", "TOFVsPhi", 50, -3.14, 3.14); TOFVsPhi->Sumw2();
   TProfile* TOFVsPt  = new TProfile("TOFVsPt" , "TOFVsPt" , 50, 40, 140); TOFVsPt->Sumw2();
   TProfile* CSCTOFVsEta = new TProfile("CSCTOFVsEta", "CSCTOFVsEta", 50, -2.1, 2.1); CSCTOFVsEta->Sumw2();
   TProfile* CSCTOFVsPhi = new TProfile("CSCTOFVsPhi", "CSCTOFVsPhi", 50, -3.14, 3.14); CSCTOFVsPhi->Sumw2();
   TProfile* CSCTOFVsPt  = new TProfile("CSCTOFVsPt" , "CSCTOFVsPt" , 50, 40, 140); CSCTOFVsPt->Sumw2();
   TProfile* DTTOFVsEta = new TProfile("DTTOFVsEta", "DTTOFVsEta", 50, -2.1, 2.1); DTTOFVsEta->Sumw2();
   TProfile* DTTOFVsPhi = new TProfile("DTTOFVsPhi", "DTTOFVsPhi", 50, -3.14, 3.14); DTTOFVsPhi->Sumw2();
   TProfile* DTTOFVsPt  = new TProfile("DTTOFVsPt" , "DTTOFVsPt" , 50, 40, 140); DTTOFVsPt->Sumw2();

   TProfile* VertexVsEta = new TProfile("VertexVsEta", "VertexVsEta", 50, -2.1, 2.1); VertexVsEta->Sumw2();
   TProfile* VertexVsPhi = new TProfile("VertexVsPhi", "VertexVsPhi", 50, -3.14, 3.14); VertexVsPhi->Sumw2();
   TProfile* VertexVsPt  = new TProfile("VertexVsPt" , "VertexVsPt" , 50, 40, 140); VertexVsPt->Sumw2();
   TProfile* CSCVertexVsEta = new TProfile("CSCVertexVsEta", "CSCVertexVsEta", 50, -2.1, 2.1); CSCVertexVsEta->Sumw2();
   TProfile* CSCVertexVsPhi = new TProfile("CSCVertexVsPhi", "CSCVertexVsPhi", 50, -3.14, 3.14); CSCVertexVsPhi->Sumw2();
   TProfile* CSCVertexVsPt  = new TProfile("CSCVertexVsPt" , "CSCVertexVsPt" , 50, 40, 140); CSCVertexVsPt->Sumw2();
   TProfile* DTVertexVsEta = new TProfile("DTVertexVsEta", "DTVertexVsEta", 50, -2.1, 2.1); DTVertexVsEta->Sumw2();
   TProfile* DTVertexVsPhi = new TProfile("DTVertexVsPhi", "DTVertexVsPhi", 50, -3.14, 3.14); DTVertexVsPhi->Sumw2();
   TProfile* DTVertexVsPt  = new TProfile("DTVertexVsPt" , "DTVertexVsPt" , 50, 40, 140); DTVertexVsPt->Sumw2();

   TypeMode      = 2;


   for(unsigned int s=0;s<samples.size();s++){
     std::vector<string> FileName;
     GetInputFiles(samples[s], BaseDirectory, FileName);
     fwlite::ChainEvent tree(FileName);

     printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
     printf("Looping on Tree              :");
     int TreeStep = tree.size()/50;if(TreeStep==0)TreeStep=1;
     for(Long64_t e=0;e<tree.size();e++){
//      if(e>10)break;
       tree.to(e);
      if(e%TreeStep==0){printf(".");fflush(stdout);}

      if(!PassingTrigger(tree))continue;

      fwlite::Handle<susybsm::HSCParticleCollection> hscpCollHandle;
      hscpCollHandle.getByLabel(tree,"HSCParticleProducer");
      if(!hscpCollHandle.isValid()){printf("HSCP Collection NotFound\n");continue;}
      susybsm::HSCParticleCollection hscpColl = *hscpCollHandle;

      fwlite::Handle<DeDxDataValueMap> dEdxSCollH;
      dEdxSCollH.getByLabel(tree, dEdxS_Label.c_str());
      if(!dEdxSCollH.isValid()){printf("Invalid dEdx Selection collection\n");continue;}

      fwlite::Handle<DeDxDataValueMap> dEdxMCollH;
      dEdxMCollH.getByLabel(tree, dEdxM_Label.c_str());
      if(!dEdxMCollH.isValid()){printf("Invalid dEdx Mass collection\n");continue;}

      fwlite::Handle<MuonTimeExtraMap> TOFCollH;
      TOFCollH.getByLabel(tree, "muontiming",TOF_Label.c_str());
      if(!TOFCollH.isValid()){printf("Invalid TOF collection\n");return;}

      fwlite::Handle<MuonTimeExtraMap> TOFDTCollH;
      TOFDTCollH.getByLabel(tree, "muontiming",TOFdt_Label.c_str());
      if(!TOFDTCollH.isValid()){printf("Invalid DT TOF collection\n");continue;}

      fwlite::Handle<MuonTimeExtraMap> TOFCSCCollH;
      TOFCSCCollH.getByLabel(tree, "muontiming",TOFcsc_Label.c_str());
      if(!TOFCSCCollH.isValid()){printf("Invalid CSCTOF collection\n");continue;}

      double Mass=0;
      int ind1=-1, ind2=-1;

      for(unsigned int c=0;c<hscpColl.size();c++){
         susybsm::HSCParticle hscp  = hscpColl[c];
         reco::TrackRef track = hscp.trackRef();
         if(track.isNull())continue;
	 if(hscp.muonRef().isNull()) continue;

         const DeDxData& dedxSObj  = dEdxSCollH->get(track.key());
         const DeDxData& dedxMObj  = dEdxMCollH->get(track.key());

         const reco::MuonTimeExtra* tof = NULL;
         const reco::MuonTimeExtra* dttof = NULL;
         const reco::MuonTimeExtra* csctof = NULL;
         if(!hscp.muonRef().isNull()){ tof  = &TOFCollH->get(hscp.muonRef().key()); dttof  = &TOFDTCollH->get(hscp.muonRef().key()); csctof  = &TOFCSCCollH->get(hscp.muonRef().key());}
         if(!PassPreselection(hscp, dedxSObj, dedxMObj, tof, dttof, csctof, tree))continue;

	 for(unsigned int d=c+1;d<hscpColl.size();d++){
	   susybsm::HSCParticle hscp2  = hscpColl[d];
	   reco::TrackRef track2 = hscp2.trackRef();
	   if(track2.isNull())continue;
	   if(hscp2.muonRef().isNull()) continue;

	   const DeDxData& dedxSObj2  = dEdxSCollH->get(track.key());
	   const DeDxData& dedxMObj2  = dEdxMCollH->get(track.key());

	   const reco::MuonTimeExtra* tof2 = NULL;
	   const reco::MuonTimeExtra* dttof2 = NULL;
	   const reco::MuonTimeExtra* csctof2 = NULL;
	   if(!hscp2.muonRef().isNull()){ tof2  = &TOFCollH->get(hscp.muonRef().key()); dttof2  = &TOFDTCollH->get(hscp.muonRef().key()); csctof2  = &TOFCSCCollH->get(hscp.muonRef().key());}
	   if(!PassPreselection(hscp2, dedxSObj2, dedxMObj2, tof2, dttof2, csctof2, tree))continue;

	   if(track->charge()==track2->charge()) continue;
	   double E = track->p() + track2->p();
	   double px = track->px() + track2->px();
	   double py = track->py() + track2->py();
	   double pz = track->pz() + track2->pz();
	   double p = px + py +pz;
	   double M = sqrt(E*E - p*p);
	   if(fabs(M-91.1876)>fabs(Mass-91.1876)) continue;
	   Mass=M;
	   ind1=c;
	   ind2=d;
	 }
      }

      for(int c=0;c<(int)hscpColl.size();c++){
	if(c!=ind1 && c!=ind2) continue;
	susybsm::HSCParticle hscp  = hscpColl[c];
	reco::TrackRef track = hscp.trackRef();
	if(track.isNull())continue;
	if(hscp.muonRef().isNull()) continue;

	const reco::MuonTimeExtra* tof = NULL;
	const reco::MuonTimeExtra* dttof = NULL;
	const reco::MuonTimeExtra* csctof = NULL;
	if(!hscp.muonRef().isNull()){ tof  = &TOFCollH->get(hscp.muonRef().key()); dttof  = &TOFDTCollH->get(hscp.muonRef().key()); csctof  = &TOFCSCCollH->get(hscp.muonRef().key());}

	if(tof && tof->nDof()>=GlobalMinNDOF && (dttof->nDof()>=GlobalMinNDOFDT || csctof->nDof()>=GlobalMinNDOFCSC) && tof->inverseBetaErr()<=GlobalMaxTOFErr){
	  TOF->Fill(tof->inverseBeta());
          TOFVsEta->Fill(track->eta(), tof->inverseBeta());
          TOFVsPhi->Fill(track->phi(), tof->inverseBeta());
          TOFVsPt->Fill(track->pt(), tof->inverseBeta());
	  if(dttof->nDof()>=GlobalMinNDOFDT) {
	    TOFDT->Fill(dttof->inverseBeta());
	    DTTOFVsEta->Fill(track->eta(), dttof->inverseBeta());
	    DTTOFVsPhi->Fill(track->phi(), dttof->inverseBeta());
	    DTTOFVsPt->Fill(track->pt(), dttof->inverseBeta());
	  }
	  if(csctof->nDof()>=GlobalMinNDOFCSC) {
	    TOFCSC->Fill(csctof->inverseBeta());
	    CSCTOFVsEta->Fill(track->eta(), csctof->inverseBeta());
	    CSCTOFVsPhi->Fill(track->phi(), csctof->inverseBeta());
	    CSCTOFVsPt->Fill(track->pt(), csctof->inverseBeta());
	  }


	  Vertex->Fill(tof->timeAtIpInOut());
          VertexVsEta->Fill(track->eta(), tof->timeAtIpInOut());
          VertexVsPhi->Fill(track->phi(), tof->timeAtIpInOut());
          VertexVsPt->Fill(track->pt(), tof->timeAtIpInOut());
	  if(dttof->nDof()>=GlobalMinNDOFDT) {
	    VertexDT->Fill(dttof->timeAtIpInOut());
	    DTVertexVsEta->Fill(track->eta(), dttof->timeAtIpInOut());
	    DTVertexVsPhi->Fill(track->phi(), dttof->timeAtIpInOut());
	    DTVertexVsPt->Fill(track->pt(), dttof->timeAtIpInOut());
	  }
	  if(csctof->nDof()>=GlobalMinNDOFCSC) {
	    VertexCSC->Fill(csctof->timeAtIpInOut());
	    CSCVertexVsEta->Fill(track->eta(), csctof->timeAtIpInOut());
	    CSCVertexVsPhi->Fill(track->phi(), csctof->timeAtIpInOut());
	    CSCVertexVsPt->Fill(track->pt(), csctof->timeAtIpInOut());
	  }
	}
      }
     }printf("\n");
   }

   OutputHisto->Write();
   OutputHisto->Close();  
}