Esempio n. 1
0
void readMCPerform(TString filename="QAresults_AOD.root", Int_t drawOnlyDzerDplus = 1, Int_t runNumber=-1)
{

  const Int_t totTrending=5;
  Float_t vecForTrend[totTrending];
  TString varForTrending[totTrending]={"nDzeroCandperEv","nDplusCandperEv","nDsCandperEv","nLcCandperEv","nDstarCandperEv"};

  

  TTree* trtree=new TTree("trendingHF","tree of trending variables");
  trtree->Branch("nrun",&runNumber,"nrun/I");
  for(Int_t j=0; j<totTrending; j++){
    trtree->Branch(varForTrending[j].Data(),&vecForTrend[j],Form("%s/F",varForTrending[j].Data()));
    vecForTrend[j]=-99.;
  }

  TFile *ff = new TFile(filename.Data());

  Int_t color[5] = {kBlack, kRed, kGreen, kBlue, kOrange};

  TDirectoryFile *dirD2H = (TDirectoryFile *)ff->Get("PWG3_D2H_QA");
  if(!dirD2H){
    printf("Directory PWG3_D2H_QA not found in file %s\n",filename.Data());
    return;
  }
  TList *listD2H = (TList *)dirD2H->Get("nEntriesQA");
  if(!listD2H){
    printf("TList nEntriesQA not found in file %s\n",filename.Data());
    return;  
  }
  TH1F *hNentries = (TH1F *)listD2H->FindObject("hNentries");
  TH2F *hHasSelBit = (TH2F *)listD2H->FindObject("HasSelBit");

  TCanvas *cqa = new TCanvas("cqa", "cqa", 800, 500);
  cqa->Divide(2, 1);
  cqa->cd(1);
  hNentries->Draw();
  cqa->cd(2);
  hHasSelBit->Draw("colz");
  cqa->SaveAs("plot_D2HQA.png");

  Double_t nEv=hNentries->GetBinContent(10);
  vecForTrend[0]=hHasSelBit->GetBinContent(1)/nEv;
  vecForTrend[1]=hHasSelBit->GetBinContent(2)/nEv;
  vecForTrend[2]=hHasSelBit->GetBinContent(3)/nEv;
  vecForTrend[3]=hHasSelBit->GetBinContent(4)/nEv;
  vecForTrend[4]=hHasSelBit->GetBinContent(5)/nEv;


  TDirectoryFile *dir = (TDirectoryFile *)ff->Get("PWGHF_D2H_MCPerform");
  TList* list = 0x0;
  if (dir)
  {
    list = (TList *)dir->Get("coutputDperfQA");
    if(list){
    
      TH1F *hn = (TH1F *)list->FindObject("fHistNEvents");
      TH1F *hnGenD = (TH1F *)list->FindObject("fHistNGenD");
      Int_t entries = hn->GetBinContent(3);
      
      TH2F *fHistNCand = (TH2F *)list->FindObject("fHistNCand");
      TH1F *fHistNCandDzero = (TH1F *)fHistNCand->ProjectionY("fHistNCandDzero", 1, 1);
      TH1F *fHistNCandDplus = (TH1F *)fHistNCand->ProjectionY("fHistNCandDplus", 2, 2);
      TH1F *fHistNCandDstar = (TH1F *)fHistNCand->ProjectionY("fHistNCandDstar", 3, 3);
      TH1F *fHistNCandDs = (TH1F *)fHistNCand->ProjectionY("fHistNCandDs", 4, 4);
      TH1F *fHistNCandLc = (TH1F *)fHistNCand->ProjectionY("fHistNCandLc", 5, 5);
      
      TString names[5] = {"Dzero", "Dplus", "Dstar", "Ds", "Lc2pkpi"};
      TString type[2] = {"Prompt", "Feeddown"};
      const Int_t nDecays = 5;
      TH2F *fHistXvtxResVsPt[2 * nDecays];
      TH2F *fHistYvtxResVsPt[2 * nDecays];
      TH2F *fHistZvtxResVsPt[2 * nDecays];
      TH2F *fHistInvMassVsPt[2 * nDecays];
      TH2F *fHistDecLenVsPt[2 * nDecays];
      TH2F *fHistNormDLxyVsPt[2 * nDecays];
      TH2F *fHistCosPointVsPt[2 * nDecays];
      
      TH3F *fHistPtYMultGenDauInAcc[2 * nDecays];
      TH3F *fHistPtYMultRecoFilt[2 * nDecays];
      
      TProfile *fHistXvtxRes[2 * nDecays];
      TProfile *fHistYvtxRes[2 * nDecays];
      TProfile *fHistZvtxRes[2 * nDecays];
      TProfile *fHistXvtxMean[2 * nDecays];
      TProfile *fHistYvtxMean[2 * nDecays];
      TProfile *fHistZvtxMean[2 * nDecays];
      
      TH1F *fHistXvtxRes2[2 * nDecays];
      TH1F *fHistYvtxRes2[2 * nDecays];
      TH1F *fHistZvtxRes2[2 * nDecays];
      
      TProfile *fHistInvMass[2 * nDecays];
      TProfile *fHistDecLen[2 * nDecays];
      TProfile *fHistCosp[2 * nDecays];
      
      TH1F *fHistInvMassRes[2 * nDecays];
      
      TH1F *hEffPt[2 * nDecays];
      TH1F *htemp;
      
      for (Int_t j = 0; j < 5; j++)
	{ //decays
	  for (Int_t i = 0; i < 2; i++)
	    { //prompt and fd
	      Int_t index = j * 2 + i;
	      fHistXvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hXvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hYvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxResVsPt[index] = (TH2F *)list->FindObject(Form("hZvtxResVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistInvMassVsPt[index] = (TH2F *)list->FindObject(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistDecLenVsPt[index] = (TH2F *)list->FindObject(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistCosPointVsPt[index] = (TH2F *)list->FindObject(Form("hCosPointVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultGenDauInAcc[index] = (TH3F *)list->FindObject(Form("hPtYMult%sGenDauInAcc%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultRecoFilt[index] = (TH3F *)list->FindObject(Form("hPtYMult%sRecoFilt%s", type[i].Data(), names[j].Data()));
	      
	      fHistXvtxMean[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistXvtxMean[index]->SetLineColor(color[j]);
	      fHistXvtxMean[index]->SetLineWidth(2);
	      fHistXvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxMean[index]->GetYaxis()->SetTitle("Xvtx (reco-true) mean (#mum)");
	      fHistXvtxMean[index]->SetTitle("Xvtx residual vs pT");

	      fHistYvtxMean[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxMean[index]->SetLineColor(color[j]);
	      fHistYvtxMean[index]->SetLineWidth(2);
	      fHistYvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxMean[index]->GetYaxis()->SetTitle("Yvtx (reco-true) mean (#mum)");
	      fHistYvtxMean[index]->SetTitle("Yvtx residual vs pT");

	      fHistZvtxMean[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxMean%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxMean[index]->SetLineColor(color[j]);
	      fHistZvtxMean[index]->SetLineWidth(2);
	      fHistZvtxMean[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxMean[index]->GetYaxis()->SetTitle("Zvtx (reco-true) mean (#mum)");
	      fHistZvtxMean[index]->SetTitle("Zvtx residual vs pT");

	      fHistXvtxRes[index] = (TProfile *)fHistXvtxResVsPt[index]->ProfileX(Form("hXvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistYvtxRes[index] = (TProfile *)fHistYvtxResVsPt[index]->ProfileX(Form("hYvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistZvtxRes[index] = (TProfile *)fHistZvtxResVsPt[index]->ProfileX(Form("hZvtxRes%s%s", type[i].Data(), names[j].Data()), 1, -1, "s");
	      fHistXvtxRes2[index] = (TH1F *)fHistXvtxResVsPt[index]->ProjectionX(Form("hXvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistYvtxRes2[index] = (TH1F *)fHistYvtxResVsPt[index]->ProjectionX(Form("hYvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistZvtxRes2[index] = (TH1F *)fHistZvtxResVsPt[index]->ProjectionX(Form("hZvtxRes2%s%s", type[i].Data(), names[j].Data()));
	      fHistXvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxRes[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)");
	      fHistXvtxRes[index]->SetTitle("Xvtx resolution vs pT");
	      fHistYvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxRes[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)");
	      fHistYvtxRes[index]->SetTitle("Yvtx resolution vs pT");
	      fHistZvtxRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxRes[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)");
	      fHistZvtxRes[index]->SetTitle("Zvtx resolution vs pT");

	      fHistXvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistXvtxRes2[index]->GetYaxis()->SetTitle("Xvtx (reco-true) RMS (#mum)");
	      fHistXvtxRes2[index]->SetTitle("Xvtx resolution vs pT");
	      fHistYvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistYvtxRes2[index]->GetYaxis()->SetTitle("Yvtx (reco-true) RMS (#mum)");
	      fHistYvtxRes2[index]->SetTitle("Yvtx resolution vs pT");
	      fHistZvtxRes2[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistZvtxRes2[index]->GetYaxis()->SetTitle("Zvtx (reco-true) RMS (#mum)");
	      fHistZvtxRes2[index]->SetTitle("Zvtx resolution vs pT");

	      fHistXvtxRes2[index]->SetLineColor(color[j]);
	      fHistYvtxRes2[index]->SetLineColor(color[j]);
	      fHistZvtxRes2[index]->SetLineColor(color[j]);
	      fHistXvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistXvtxRes2[index]->SetMarkerStyle(20);
	      fHistYvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistYvtxRes2[index]->SetMarkerStyle(20);
	      fHistZvtxRes2[index]->SetMarkerColor(color[j]);
	      fHistZvtxRes2[index]->SetMarkerStyle(20);
	      fHistXvtxRes2[index]->SetLineWidth(2);
	      fHistYvtxRes2[index]->SetLineWidth(2);
	      fHistZvtxRes2[index]->SetLineWidth(2);
	      fHistXvtxRes2[index]->Sumw2();
	      fHistYvtxRes2[index]->Sumw2();
	      fHistZvtxRes2[index]->Sumw2();

	      fHistInvMass[index] = (TProfile *)fHistInvMassVsPt[index]->ProfileX(Form("hInvMassVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistInvMass[index]->SetLineColor(color[j]);
	      fHistInvMass[index]->SetLineWidth(2);
	      fHistInvMass[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistInvMass[index]->GetYaxis()->SetTitle("Inv Mass (GeV/c2)");
	      fHistInvMass[index]->SetTitle("Inv Mass vs pT");

	      fHistDecLen[index] = (TProfile *)fHistDecLenVsPt[index]->ProfileX(Form("hDecLenVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistDecLen[index]->SetLineColor(color[j]);
	      fHistDecLen[index]->SetLineWidth(2);
	      fHistDecLen[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistDecLen[index]->GetYaxis()->SetTitle("Dec Len (#mum)");
	      fHistDecLen[index]->SetTitle("Prompt Dec Len vs pT");

	      fHistCosp[index] = (TProfile *)fHistCosPointVsPt[index]->ProfileX(Form("hCosPVsPt%s%s", type[i].Data(), names[j].Data()));
	      fHistCosp[index]->SetLineColor(color[j]);
	      fHistCosp[index]->SetLineWidth(2);
	      fHistCosp[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      fHistCosp[index]->GetYaxis()->SetTitle("Cos Point");
	      fHistCosp[index]->SetTitle("Prompt CosPoint vs pT");

	      if (index % 2 == 1)
		fHistDecLen[index]->SetTitle("FeedDown Dec Len vs pT");

	      htemp = (TH1F *)fHistPtYMultGenDauInAcc[index]->ProjectionX(Form("hPtDen%s%s", type[i].Data(), names[j].Data()));
	      hEffPt[index] = (TH1F *)fHistPtYMultRecoFilt[index]->ProjectionX(Form("hPtNum%s%s", type[i].Data(), names[j].Data()));
	      fHistPtYMultGenDauInAcc[index]->Sumw2();
	      fHistPtYMultRecoFilt[index]->Sumw2();
	      hEffPt[index]->Sumw2();
	      hEffPt[index]->Divide(htemp);
	      hEffPt[index]->SetLineColor(color[j]);
	      hEffPt[index]->SetLineWidth(2);
	      hEffPt[index]->GetXaxis()->SetTitle("pT (GeV/c)");
	      hEffPt[index]->GetYaxis()->SetTitle("Prompt Efficiency");
	      hEffPt[index]->SetTitle("Prompt Efficiency");
	      hEffPt[index]->SetStats(0);
	      fHistCosp[index]->SetStats(0);
	      fHistDecLen[index]->SetStats(0);

	      if (index % 2 == 1)
		{
		  hEffPt[index]->GetYaxis()->SetTitle("Feeddown Efficiency");
		  hEffPt[index]->SetTitle("Feeddown Efficiency");
		}

	      fHistInvMassRes[index] = new TH1F(*hEffPt[index]);
	      for (Int_t jj = 1; jj < hEffPt[index]->GetNbinsX() + 1; jj++)
		{
		  TH1F *hTemp = (TH1F *)fHistInvMassVsPt[index]->ProjectionY("htemp", jj, jj);
		  fHistInvMassRes[index]->SetBinContent(jj, hTemp->GetRMS());
		  fHistInvMassRes[index]->SetBinError(jj, hTemp->GetRMSError());
		  fHistInvMassRes[index]->SetLineColor(color[j]);
		  fHistInvMassRes[index]->SetLineWidth(2);
		  fHistInvMassRes[index]->GetXaxis()->SetTitle("pT (GeV/c)");
		  fHistInvMassRes[index]->GetYaxis()->SetTitle("Inv Mass RMS (GeV/c2)");
		  fHistInvMassRes[index]->SetTitle("Inv Mass RMS vs pT");
		  if (index == 0)
		    printf("D0: pt=%f, res=%f \n", fHistInvMassRes[index]->GetBinCenter(jj), fHistInvMassRes[index]->GetBinContent(jj));
		  TH1F *hTempX = (TH1F *)fHistXvtxResVsPt[index]->ProjectionY("htempX", jj, jj);
		  TH1F *hTempY = (TH1F *)fHistYvtxResVsPt[index]->ProjectionY("htempY", jj, jj);
		  TH1F *hTempZ = (TH1F *)fHistZvtxResVsPt[index]->ProjectionY("htempZ", jj, jj);

		  fHistXvtxRes2[index]->SetBinContent(jj, hTempX->GetRMS());
		  fHistXvtxRes2[index]->SetBinError(jj, hTempX->GetRMSError());

		  fHistYvtxRes2[index]->SetBinContent(jj, hTempY->GetRMS());
		  fHistYvtxRes2[index]->SetBinError(jj, hTempY->GetRMSError());

		  fHistZvtxRes2[index]->SetBinContent(jj, hTempZ->GetRMS());
		  fHistZvtxRes2[index]->SetBinError(jj, hTempZ->GetRMSError());
		}
	    }
	}

      fHistNCandDplus->SetLineColor(2);
      fHistNCandDstar->SetLineColor(3);
      fHistNCandDs->SetLineColor(4);
      fHistNCandLc->SetLineColor(kOrange);
      fHistNCandDplus->SetLineWidth(2);
      fHistNCandDstar->SetLineWidth(2);
      fHistNCandDs->SetLineWidth(2);
      fHistNCandLc->SetLineWidth(2);

      fHistNCandDzero->GetXaxis()->SetTitle("pT (GeV/c)");
      fHistNCandDzero->GetYaxis()->SetTitle("counts");
      TLegend *leg = new TLegend(0.6, 0.7, 0.8, 0.9);
      leg->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg->AddEntry(fHistNCandDplus, "Dplus", "l");
      leg->AddEntry(fHistNCandDstar, "Dstar", "l");
      leg->AddEntry(fHistNCandDs, "Ds", "l");
      leg->AddEntry(fHistNCandLc, "Lc", "l");

      TLegend *leg1 = new TLegend(0.5, 0.7, 0.7, 0.9);
      leg1->AddEntry(fHistYvtxRes2[0], "Dzero", "pl");
      leg1->AddEntry(fHistYvtxRes2[2], "Dplus", "pl");
      if (drawOnlyDzerDplus == 0)
	leg1->AddEntry(fHistYvtxRes2[6], "Ds", "pl");
      if (drawOnlyDzerDplus == 0)
	leg1->AddEntry(fHistYvtxRes2[8], "Lc", "pl");

      TLegend *leg2 = new TLegend(0.5, 0.7, 0.7, 0.9);
      leg2->AddEntry(fHistYvtxMean[0], "Dzero", "l");
      leg2->AddEntry(fHistYvtxMean[2], "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg2->AddEntry(fHistYvtxMean[6], "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg2->AddEntry(fHistYvtxMean[8], "Lc", "l");

      TLegend *leg3 = new TLegend(0.2, 0.7, 0.4, 0.9);
      leg3->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg3->AddEntry(fHistNCandDplus, "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandDstar, "Dstar", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandDs, "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg3->AddEntry(fHistNCandLc, "Lc", "l");

      TLegend *leg4 = new TLegend(0.7, 0.7, 0.9, 0.9);
      leg4->AddEntry(fHistNCandDzero, "Dzero", "l");
      leg4->AddEntry(fHistNCandDplus, "Dplus", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandDstar, "Dstar", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandDs, "Ds", "l");
      if (drawOnlyDzerDplus == 0)
	leg4->AddEntry(fHistNCandLc, "Lc", "l");

      TCanvas *c0_1 = new TCanvas("c0_1", "c0_1", 500, 500);
      hnGenD->SetTitle("number of generated D mesons");
      hnGenD->Draw();
      c0_1->SaveAs("plotDgen.png");

      TCanvas *c0_2 = new TCanvas("c0_2", "c0_2", 500, 500);
      c0_2->SetLogy();

      fHistNCandDs->SetTitle("Candidates passing filtering cuts");
      fHistNCandDs->Draw("");
      c0_2->Update();
      TPaveStats *stats = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats->SetName("h1stats");
      stats->SetY1NDC(0.5);
      stats->SetY2NDC(0.35);
      c0_2->Update();

      fHistNCandDplus->Draw("sames");
      c0_2->Update();
      TPaveStats *stats2 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats2->SetName("h2stats");
      stats2->SetY1NDC(0.8);
      stats2->SetY2NDC(.65);
      c0_2->Update();

      fHistNCandDstar->Draw("sames");
      c0_2->Update();
      TPaveStats *stats3 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats3->SetName("h3stats");
      stats3->SetY1NDC(0.65);
      stats3->SetY2NDC(.5);
      c0_2->Update();

      fHistNCandDzero->Draw("sames");
      c0_2->Update();
      TPaveStats *stats4 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats4->SetName("h4stats");
      stats4->SetY1NDC(0.95);
      stats4->SetY2NDC(.8);
      c0_2->Update();

      fHistNCandLc->Draw("sames");
      c0_2->Update();
      TPaveStats *stats5 = (TPaveStats *)c0_2->GetPrimitive("stats");
      stats5->SetName("h1stats");
      stats5->SetY1NDC(0.35);
      stats5->SetY2NDC(.2);
      c0_2->Update();
      leg->Draw();
      c0_2->SaveAs("plotDcandpt.png");

      TCanvas *c0_3 = new TCanvas("c0_3", "c0_3", 500, 500);
      fHistInvMass[0]->SetMinimum(1.6);
      fHistInvMass[0]->SetMaximum(2.4);
      fHistInvMass[0]->Draw();
      fHistInvMass[2]->Draw("sames");
      fHistInvMass[4]->Draw("sames");
      fHistInvMass[6]->Draw("sames");
      fHistInvMass[8]->Draw("sames");
      leg->Draw();
      c0_3->SaveAs("plotDcandInvMass.png");

      TCanvas *c0_4 = new TCanvas("c0_4", "c0_4", 500, 500);
      //fHistInvMassRes[0]->SetMinimum(1.6);
      //fHistInvMassRes[0]->SetMaximum(2.4);

      fHistInvMassRes[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistInvMassRes[0]->SetTitle("D0 Inv Mass RMS vs pT");
      fHistInvMassRes[0]->Draw("");
      //  fHistInvMassRes[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistInvMassRes[8]->Draw("sames");
      //leg->Draw();
      c0_4->SaveAs("plotD0candInvMassWidth.png");

      fHistXvtxMean[0]->SetStats(0);
      fHistYvtxMean[0]->SetStats(0);
      fHistZvtxMean[0]->SetStats(0);
      fHistXvtxMean[2]->SetStats(0);
      fHistYvtxMean[2]->SetStats(0);
      fHistZvtxMean[2]->SetStats(0);
      fHistXvtxRes2[0]->SetStats(0);
      fHistYvtxRes2[0]->SetStats(0);
      fHistZvtxRes2[0]->SetStats(0);
      fHistXvtxRes2[2]->SetStats(0);
      fHistYvtxRes2[2]->SetStats(0);
      fHistZvtxRes2[2]->SetStats(0);

      TCanvas *cc = new TCanvas("cc", "cc", 1200, 500);
      cc->Divide(3, 1);
      cc->cd(1);
      fHistXvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistXvtxMean[0]->SetMinimum(-300.);
      fHistXvtxMean[0]->SetMaximum(300.);
      fHistXvtxMean[0]->Draw();

      fHistXvtxMean[2]->Draw("sames");
      leg2->Draw();

      cc->cd(2);

      fHistYvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistYvtxMean[0]->SetMinimum(-300.);
      fHistYvtxMean[0]->SetMaximum(300.);
      fHistYvtxMean[0]->Draw();
      fHistYvtxMean[2]->Draw("sames");
      leg2->Draw();

      cc->cd(3);
      fHistZvtxMean[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistZvtxMean[0]->SetMinimum(-300.);
      fHistZvtxMean[0]->SetMaximum(300.);
      fHistZvtxMean[0]->Draw();
      fHistZvtxMean[2]->Draw("sames");
      leg2->Draw();
      cc->SaveAs("plotXYZVtxMean.png");
      /////////

      TCanvas *ccr = new TCanvas("ccr", "ccr", 1200, 500);
      ccr->Divide(3, 1);
      ccr->cd(1);
      fHistXvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistXvtxRes2[0]->SetMinimum(0.);
      fHistXvtxRes2[0]->SetMaximum(500.);
      fHistXvtxRes2[0]->Draw();
      fHistXvtxRes2[2]->Draw("sames");
      leg2->Draw();

      ccr->cd(2);
      fHistYvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistYvtxRes2[0]->SetMinimum(0.);
      fHistYvtxRes2[0]->SetMaximum(500.);
      fHistYvtxRes2[0]->Draw();
      fHistYvtxRes2[2]->Draw("sames");
      leg2->Draw();

      ccr->cd(3);
      fHistZvtxRes2[0]->GetYaxis()->SetTitleOffset(1.4);
      fHistZvtxRes2[0]->SetMinimum(0.);
      fHistZvtxRes2[0]->SetMaximum(500.);
      fHistZvtxRes2[0]->Draw();
      fHistZvtxRes2[2]->Draw("sames");
      leg2->Draw();
      ccr->SaveAs("plotXYZVtxRMS.png");

      TCanvas *ccc = new TCanvas("ccc", "ccc", 1200, 800);
      ccc->Divide(3, 2);
      ccc->cd(1);
      fHistDecLen[0]->GetYaxis()->SetTitleOffset(1.45);
      fHistDecLen[0]->Draw();
      fHistDecLen[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[8]->Draw("sames");
      leg3->Draw();

      ccc->cd(2);
      fHistCosp[0]->GetYaxis()->SetTitleOffset(1.45);
      fHistCosp[0]->Draw();
      fHistCosp[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[8]->Draw("sames");
      leg4->Draw();

      ccc->cd(3);
      hEffPt[0]->GetYaxis()->SetTitleOffset(1.45);
      hEffPt[0]->Draw();
      hEffPt[2]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[4]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[6]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[8]->Draw("sames");
      leg3->Draw();

      ccc->cd(4);
      fHistDecLen[1]->GetYaxis()->SetTitleOffset(1.45);
      fHistDecLen[1]->Draw();
      fHistDecLen[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistDecLen[9]->Draw("sames");
      leg3->Draw();

      ccc->cd(5);
      fHistCosp[1]->GetYaxis()->SetTitleOffset(1.45);
      fHistCosp[1]->Draw();
      fHistCosp[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	fHistCosp[9]->Draw("sames");
      leg4->Draw();

      ccc->cd(6);
      hEffPt[1]->GetYaxis()->SetTitleOffset(1.45);
      hEffPt[1]->Draw();
      hEffPt[3]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[5]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[7]->Draw("sames");
      if (drawOnlyDzerDplus == 0)
	hEffPt[9]->Draw("sames");
      leg3->Draw();

      ccc->SaveAs("plot_DL_cosp_Eff_prompt_fd.png");
    }
  }

  trtree->Fill();

  if(runNumber>0){
    TFile* foutfile=new TFile("trendingHF.root","recreate");
    trtree->Write();
    TDirectory* outdir=foutfile->mkdir(dirD2H->GetName());
    outdir->cd();
    listD2H->Write(listD2H->GetName(),1);
    foutfile->cd();
    if(dir && list){
      TDirectory* outdir2=foutfile->mkdir(dir->GetName());
      outdir2->cd();
      list->Write(list->GetName(),1);
    }
    foutfile->Close();
    delete foutfile;
  }
}
Esempio n. 2
0
TCanvas *PlotDataMCMC(TChain *data, TChain *mc, TChain *mc2,
		      TString branchname, TString binning, 
		      TString category, TString selection, 
		      TString dataLabel, TString mcLabel, TString mc2Label,
		      TString xLabel, TString yLabelUnit, 
		      bool logy=false, bool usePU=true, bool smear=false, bool scale=false){
  
  TString yLabel; 
  
  TCanvas *c = new TCanvas("c","");
  TString branchNameData=branchname;
  TString branchNameMC=branchname;

  ElectronCategory_class cutter;
  TCut selection_data="";
  if(category.Sizeof()>1) selection_data = cutter.GetCut(category, false,0);
  selection_data+=selection;
  TCut selection_MC="";
  if(category.Sizeof()>1) selection_MC = cutter.GetCut(category, true,0);
  selection_MC+=selection;

  if(smear){
    branchNameMC.ReplaceAll("invMass_SC_regrCorr_pho ","(invMass_SC_regrCorr_pho*sqrt(smearEle[0]*smearEle[1]))");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho ","(energySCEle_regrCorr_pho*smearEle) ");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho[0]","(energySCEle_regrCorr_pho[0]*smearEle[0])");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho[1]","(energySCEle_regrCorr_pho[1]*smearEle[1])");

  }
  if(scale){
    branchNameData.ReplaceAll("invMass_SC_regrCorr_pho ","(invMass_SC_regrCorr_pho*sqrt(corrEle[0]*corrEle[1]))");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho ","(energySCEle_regrCorr_pho*corrEle)");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho[0]","(energySCEle_regrCorr_pho[0]*corrEle[0])");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho[1]","(energySCEle_regrCorr_pho[1]*corrEle[1])");
  }
  //std::cout << branchNameData << "\t" << branchNameMC << std::endl;


  data->Draw(branchNameData+">>data_hist"+binning, selection_data);
  if(mc!=NULL){
    if(usePU)  mc->Draw(branchNameMC+">>mc_hist"+binning, selection_MC *"puWeight");
    else  mc->Draw(branchNameMC+">>mc_hist"+binning, selection_MC);
  }
  if(mc2!=NULL){
    if(usePU)  mc2->Draw(branchNameMC+">>mc2_hist"+binning, selection_data *"puWeight");
    else  mc2->Draw(branchNameMC+">>mc2_hist"+binning, selection_data);
  }
  

  c->Clear();
  TH1F *d = (TH1F *) gROOT->FindObject("data_hist");
  TH1F *s = (TH1F *) gROOT->FindObject("mc_hist");
  TH1F *s2 = (TH1F *) gROOT->FindObject("mc2_hist");
  if(s==NULL){
    std::cerr << "[WARNING] no mc" << std::endl;
    s=d;
  }
  if(s2==NULL){
    std::cerr << "[WARNING] no mc2" << std::endl;
    s2=s;
  }
  std::cout << s->GetEntries() << "\t" << s2->GetEntries() << "\t" << d->GetEntries() << std::endl;

  //d->SaveAs("tmp/d_hist.root");
  s->SaveAs("tmp/s_hist.root");
  s2->SaveAs("tmp/s2_hist.root");


  yLabel.Form("Events /(%.2f %s)", s->GetBinWidth(2), yLabelUnit.Data());
  float max = 1.1 * std::max(
			     d->GetMaximum(),///d->Integral(),
			     s->GetMaximum() ///s->Integral()
			     );
  max=1.1*d->GetMaximum();
  std::cout << "max = " << max << std::endl;
  std::cout << "nEvents data: " << d->Integral() << "\t" << d->GetEntries() << std::endl;
  std::cout << "nEvents signal: " << s->Integral() << "\t" << s->GetEntries() << std::endl;
  std::cout << "nEvents signal2: " << s2->Integral() << "\t" << s2->GetEntries() << std::endl;
  if(logy){
    max*=10;
    d->GetYaxis()->SetRangeUser(0.1,max);
    s->GetYaxis()->SetRangeUser(0.1,max);
    s2->GetYaxis()->SetRangeUser(0.1,max);
    c->SetLogy();
  } else {
    d->GetYaxis()->SetRangeUser(0,max);
    s->GetYaxis()->SetRangeUser(0,max);
    s2->GetYaxis()->SetRangeUser(0,max);
  }
  s->GetYaxis()->SetTitle(yLabel);
  s->GetXaxis()->SetTitle(xLabel);
  s2->GetYaxis()->SetTitle(yLabel);
  s2->GetXaxis()->SetTitle(xLabel);
  d->GetYaxis()->SetTitle(yLabel);
  d->GetXaxis()->SetTitle(xLabel);


  d->SetMarkerStyle(20);
  d->SetMarkerSize(1);
  if(d != s){
    s->SetMarkerStyle(20);
    s->SetMarkerSize(1);
    s->SetFillStyle(3001);
    s->SetFillColor(kRed);
  }
  if(s2 != s){
    //s2->SetMarkerStyle(1);
    //s2->SetMarkerSize(0);
    //s->SetFillStyle(0);
    //s->SetFillColor(kB);
    s2->SetLineWidth(3);
    s2->SetLineColor(kBlack);
  }


  TH1F* s_norm = (TH1F *) (s->DrawNormalized("hist", d->Integral()));
  TH1F* s2_norm = (TH1F *) (s2->DrawNormalized("hist same", d->Integral()));
  //TH1F* d_norm = s_norm;
  //if(d!=s) d_norm = (TH1F *) (d->DrawNormalized("p same", d->Integral()));
  if(d!=s) d->Draw("p same");

  if(logy){
    //d_norm->GetYaxis()->SetRangeUser(0.1,max);
    s_norm->GetYaxis()->SetRangeUser(0.1,max);
    c->SetLogy();
  } else {
    //d_norm->GetYaxis()->SetRangeUser(0,max);  
    s_norm->GetYaxis()->SetRangeUser(0,max);  
  }
  std::cout << "Variable  & Data & Simulation & Simulation2 \\" << std::endl;
  std::cout << "Mean      & " << d->GetMean() << " " << d->GetMeanError() 
	    << " & " << s_norm->GetMean() <<  " " << s_norm->GetMeanError() 
	    << " & " << s2_norm->GetMean() <<  " " << s2_norm->GetMeanError() 
	    << " \\" << std::endl;
  std::cout << "Std. dev. & " << d->GetRMS() << " " << d->GetRMSError() 
	    << " & " << s_norm->GetRMS() << " " << s_norm->GetRMSError() 
	    << " & " << s2_norm->GetRMS() << " " << s2_norm->GetRMSError() 
	    << " \\" << std::endl;
  std::cout << "\\hline" << std::endl;
  std::cout << "$\\Chi^2$ " <<  d->Chi2Test(s_norm, "UW CHI2/NDF NORM") << std::endl;
  

  TLegend *leg = new TLegend(0.6,0.8,1,1);
  if(dataLabel !="") leg->AddEntry(d,dataLabel,"p");
  if(mcLabel   !="") leg->AddEntry(s,mcLabel, "lf");
  if(mc2Label   !="") leg->AddEntry(s2,mc2Label, "l");
  leg->SetBorderSize(1);
  leg->SetFillColor(0);
  leg->SetTextSize(0.04);
  if(dataLabel !="" && mcLabel !="") leg->Draw();
  //c->GetListOfPrimitives()->Add(leg,"");

  TPaveText *pv = new TPaveText(0.23,0.95,0.6,1,"NDC");
  pv->AddText("CMS Preliminary 2016");
  pv->SetFillColor(0);
  pv->SetBorderSize(0);
  pv->Draw();


  return c;

}
Esempio n. 3
0
TCanvas *PlotDataMC(TChain *data, TChain *mc, TString branchname, TString binning, 
		    TString category, TString selection, 
		    TString dataLabel, TString mcLabel, TString xLabel, TString yLabelUnit, 
		    bool logy=false, bool usePU=true, bool smear=false, bool scale=false){
  
  TString yLabel; 
  std::cout<<"entering"<<std::endl;
  
  TCanvas *c = new TCanvas("c","");
  TString branchNameData=branchname;
  TString branchNameMC=branchname;

  ElectronCategory_class cutter;

  std::cout<<"entering2"<<std::endl;

  TCut selection_data="";
  if(category.Sizeof()>1) selection_data = cutter.GetCut(category, false,0,true);
  selection_data.Print();
  //  return NULL;
  selection_data+=selection;
  TCut selection_MC="";
  if(category.Sizeof()>1) selection_MC = cutter.GetCut(category, false,0);
  selection_MC+=selection;

  std::cout<<"qui"<<std::endl;

  if(smear){
    branchNameMC.ReplaceAll("invMass_SC_regrCorr_pho ","(invMass_SC_regrCorr_pho*sqrt(smearEle[0]*smearEle[1]))");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho ","(energySCEle_regrCorr_pho*smearEle) ");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho[0]","(energySCEle_regrCorr_pho[0]*smearEle[0])");
    branchNameMC.ReplaceAll("energySCEle_regrCorr_pho[1]","(energySCEle_regrCorr_pho[1]*smearEle[1])");

  }
  if(scale){
    branchNameData.ReplaceAll("invMass_SC_regrCorr_pho ","(invMass_SC_regrCorr_pho*sqrt(corrEle[0]*corrEle[1]))");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho ","(energySCEle_regrCorr_pho*corrEle)");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho[0]","(energySCEle_regrCorr_pho[0]*corrEle[0])");
    branchNameData.ReplaceAll("energySCEle_regrCorr_pho[1]","(energySCEle_regrCorr_pho[1]*corrEle[1])");
    branchNameData.ReplaceAll("energySCEle_regrCorr_ele ","(energySCEle_regrCorr_ele*corrEle)");
    branchNameData.ReplaceAll("energySCEle_regrCorr_ele[0]","(energySCEle_regrCorr_ele[0]*corrEle[0])");
    branchNameData.ReplaceAll("energySCEle_regrCorr_ele[1]","(energySCEle_regrCorr_ele[1]*corrEle[1])");

  }
  //std::cout << branchNameData << "\t" << branchNameMC << std::endl;


  if(branchname=="HLT"){
    TH1F *hlt_data = new TH1F("data_hist","",500,0,500);
    TH1F *hlt_mc = new TH1F("mc_hist","",500,0,500);
    
    
    std::vector< std::string > *HLTNames = new std::vector<std::string>; ///< List of HLT names
    std::vector<Bool_t> *HLTResults = new std::vector<Bool_t>;      ///< 0=fail, 1=fire
    
    data->SetBranchAddress("HLTNames", &HLTNames);
    data->SetBranchAddress("HLTResults", &HLTResults);
    
    data->GetEntries();
    for(Long64_t jentry=0; jentry < data->GetEntriesFast(); jentry++){
      data->GetEntry(jentry);
      std::vector<Bool_t>::const_iterator hltRes_itr=HLTResults->begin();
      for(std::vector<std::string>::const_iterator hlt_itr=HLTNames->begin();
	  hlt_itr!=HLTNames->end();
	  hlt_itr++,hltRes_itr++){
	std::cout << *hlt_itr << std::endl;
	hlt_data->Fill(hlt_itr-HLTNames->begin(),*hltRes_itr);
      }
    }
    data->ResetBranchAddresses();

    mc->SetBranchAddress("HLTNames", &HLTNames);
    mc->SetBranchAddress("HLTResults", &HLTResults);
    
    mc->GetEntries();
    for(Long64_t jentry=0; jentry < mc->GetEntriesFast(); jentry++){
      mc->GetEntry(jentry);
      std::vector<Bool_t>::const_iterator hltRes_itr=HLTResults->begin();
      for(std::vector<std::string>::const_iterator hlt_itr=HLTNames->begin();
	  hlt_itr!=HLTNames->end();
	  hlt_itr++,hltRes_itr++){
	std::cout << *hlt_itr << std::endl;
	hlt_mc->Fill(hlt_itr-HLTNames->begin(),*hltRes_itr);
      }
    }

    for(std::vector<std::string>::const_iterator hlt_itr=HLTNames->begin();
	hlt_itr!=HLTNames->end();
	hlt_itr++){
      int index=hlt_itr-HLTNames->begin()+1;
      if(hlt_mc->GetBinContent(index)>0)
      hlt_mc->GetXaxis()->SetBinLabel(index,(*hlt_itr).c_str());
    }
  } else {

  std::cout<<"qui"<<std::endl;
    data->Draw(branchNameData+">>data_hist"+binning, selection_data);
    if(mc!=NULL){
      if(usePU)  mc->Draw(branchNameMC+">>mc_hist"+binning, selection_MC *"puWeight");
    else  mc->Draw(branchNameMC+">>mc_hist"+binning, selection_MC);
  std::cout<<"qui"<<std::endl;
    }
  }

  c->Clear();
  TH1F *d = (TH1F *) gROOT->FindObject("data_hist");
  TH1F *s = (TH1F *) gROOT->FindObject("mc_hist");
  if(s==NULL) s=d;
  //d->SaveAs("tmp/d_hist.root");
  s->SaveAs("tmp/s_hist.root");
  std::cout<<"qui"<<std::endl;

  yLabel.Form("Events /(%.2f %s)", s->GetBinWidth(2), yLabelUnit.Data());
  float max = 1.1 * std::max(
			     d->GetMaximum(),///d->Integral(),
			     s->GetMaximum() ///s->Integral()
			     );
  max=1.1*d->GetMaximum();
  std::cout << "max = " << max << std::endl;
  std::cout << "nEvents data: " << d->Integral() << "\t" << d->GetEntries() << std::endl;
  std::cout << "nEvents signal: " << s->Integral() << "\t" << s->GetEntries() << std::endl;
  if(logy){
    max*=10;
    d->GetYaxis()->SetRangeUser(0.1,max);
    s->GetYaxis()->SetRangeUser(0.1,max);
    c->SetLogy();
  } else {
    d->GetYaxis()->SetRangeUser(0,max);
    s->GetYaxis()->SetRangeUser(0,max);
  }
  s->GetYaxis()->SetTitle(yLabel);
  s->GetXaxis()->SetTitle(xLabel);
  d->GetYaxis()->SetTitle(yLabel);
  d->GetXaxis()->SetTitle(xLabel);


  d->SetMarkerStyle(20);
  d->SetMarkerSize(1);
  if(d != s){
    s->SetMarkerStyle(20);
    s->SetMarkerSize(1);
    s->SetFillStyle(3001);
    s->SetFillColor(kRed);
  }

  TH1F* s_norm = (TH1F *) (s->DrawNormalized("hist", d->Integral()));
  //TH1F* d_norm = s_norm;
  //if(d!=s) d_norm = (TH1F *) (d->DrawNormalized("p same", d->Integral()));
  if(d!=s) d->Draw("p same");

  if(logy){
    //d_norm->GetYaxis()->SetRangeUser(0.1,max);
    s_norm->GetYaxis()->SetRangeUser(0.1,max);
    c->SetLogy();
  } else {
    //d_norm->GetYaxis()->SetRangeUser(0,max);  
    s_norm->GetYaxis()->SetRangeUser(0,max);  
  }
  std::cout << "Variable  & Data & Simulation \\" << std::endl;
  std::cout << "Mean      & " << d->GetMean() << " " << d->GetMeanError() 
	    << " & " << s_norm->GetMean() <<  " " << s_norm->GetMeanError() << " \\" << std::endl;
  std::cout << "Std. dev. & " << d->GetRMS() << " " << d->GetRMSError() 
	    << " & " << s_norm->GetRMS() << " " << s_norm->GetRMSError() << " \\" << std::endl;
  std::cout << "\\hline" << std::endl;
  std::cout << "$\\Chi^2$ " <<  d->Chi2Test(s_norm, "UW CHI2/NDF NORM") << std::endl;
  

  TLegend *leg = new TLegend(0.6,0.8,1,1);
  if(dataLabel !="") leg->AddEntry(d,dataLabel,"p");
  if(mcLabel   !="") leg->AddEntry(s,mcLabel, "lf");
  leg->SetBorderSize(1);
  leg->SetFillColor(0);
  leg->SetTextSize(0.04);
  if(dataLabel !="" && mcLabel !="") leg->Draw();
  //c->GetListOfPrimitives()->Add(leg,"");

  TPaveText *pv = new TPaveText(0.2,0.95,0.7,1,"NDC");
  pv->AddText("CMS Preliminary 2016");
  pv->SetFillColor(0);
  pv->SetBorderSize(0);
  pv->Draw();


  return c;

}
Esempio n. 4
0
void drawNoisePlotsMC(TString InputFileName, TString suffix)
{
  TFile* f = TFile::Open(InputFileName.Data(),"READ");
  f -> cd();
  
  
  TH1F* h_occupancy_vsNvtx   = (TH1F*)( f->Get("h_occupancy_vsNvtx_EB") );
  TH1F* h_occupancy_vsNavgPU = (TH1F*)( f->Get("h_occupancy_vsNavgPU_EB") );
  TH1F* h_occupancy_vsIeta   = (TH1F*)( f->Get("h_occupancy_vsIeta_EB") );
  TH1F* h_occupancy_vsIring  = (TH1F*)( f->Get("h_occupancy_vsIring_EE") );
  
  
    
  TGraphErrors* g_RMSNoise_vsNvtx_EB = new TGraphErrors();
  TGraphErrors* g_RMSNoise_vsNvtx_EE = new TGraphErrors();

  TGraphErrors* g_RMSNoise_vsNavgPU_EB = new TGraphErrors();
  TGraphErrors* g_RMSNoise_vsNavgPU_EE = new TGraphErrors();
  
  int point = 0;
  for(int bin = 1; bin <= nBins_nVtx; ++bin)
  {  
    TH1F* histo;
    char histoName[50];
    
    float binCenter  = h_occupancy_vsNvtx -> GetBinCenter(bin);
    float binLowEdge = h_occupancy_vsNvtx -> GetBinLowEdge(bin);
    float binHigEdge = h_occupancy_vsNvtx -> GetBinLowEdge(bin) + h_occupancy_vsNvtx_EB->GetBinWidth(bin);
    
    if( binCenter < 5. ) continue;
    if( binCenter > 30. ) continue;
        
    sprintf(histoName,"hEB_recHitE_nVtx%02.1f-%02.1f",binLowEdge,binHigEdge);
    histo = (TH1F*)( f->Get(histoName) );
    g_RMSNoise_vsNvtx_EB -> SetPoint(point,binCenter,histo->GetRMS());
    g_RMSNoise_vsNvtx_EB -> SetPointError(point,0.,histo->GetRMSError());
    
    sprintf(histoName,"hEE_recHitE_nVtx%02.1f-%02.1f",binLowEdge,binHigEdge);
    histo = (TH1F*)( f->Get(histoName) );
    g_RMSNoise_vsNvtx_EE -> SetPoint(point,binCenter,histo->GetRMS());
    g_RMSNoise_vsNvtx_EE -> SetPointError(point,0.,histo->GetRMSError());    
    
    ++point;
  }
  
  g_RMSNoise_vsNvtx_EB -> SetPoint(g_RMSNoise_vsNvtx_EB->GetN(),-1.,-1.);
  g_RMSNoise_vsNvtx_EE -> SetPoint(g_RMSNoise_vsNvtx_EE->GetN(),-1.,-1.);
  
  
  
  point = 0;
  for(int bin = 1; bin <= nBins_nAvgPU; ++bin)
  {  
    TH1F* histo;
    char histoName[50];
    
    float binCenter  = h_occupancy_vsNavgPU -> GetBinCenter(bin);
    float binLowEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin);
    float binHigEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin) + h_occupancy_vsNavgPU_EB->GetBinWidth(bin);
    
    if( binCenter < 8. ) continue;
    if( binCenter > 30. ) continue;
        
    sprintf(histoName,"hEB_recHitE_nAvgPU%02.1f-%02.1f",binLowEdge,binHigEdge);
    histo = (TH1F*)( f->Get(histoName) );
    g_RMSNoise_vsNavgPU_EB -> SetPoint(point,binCenter,histo->GetRMS());
    g_RMSNoise_vsNavgPU_EB -> SetPointError(bin-1,0.,histo->GetRMSError());
    
    sprintf(histoName,"hEE_recHitE_nAvgPU%02.1f-%02.1f",binLowEdge,binHigEdge);
    histo = (TH1F*)( f->Get(histoName) );
    g_RMSNoise_vsNavgPU_EE -> SetPoint(point,binCenter,histo->GetRMS());
    g_RMSNoise_vsNavgPU_EE -> SetPointError(bin-1,0.,histo->GetRMSError());    
    
    ++point;
  }
  
  
  
  
  
  
  TCanvas* c1_RMSNoise_EB = new TCanvas("c1_RMSNoise_EB","EB RMS noise");
  c1_RMSNoise_EB -> cd();
  c1_RMSNoise_EB -> SetGridx();
  c1_RMSNoise_EB -> SetGridy();
  
  g_RMSNoise_vsNvtx_EB -> SetMarkerColor(kRed+2);
  g_RMSNoise_vsNavgPU_EB -> SetMarkerColor(kGreen+2);
  
  g_RMSNoise_vsNvtx_EB -> GetXaxis() -> SetTitle("N_{vtx} or Num^{Int}_{True}");
  g_RMSNoise_vsNvtx_EB -> GetYaxis() -> SetTitle("noise RMS (GeV)");
  g_RMSNoise_vsNvtx_EB -> GetXaxis() -> SetRangeUser(0.,35.);
  g_RMSNoise_vsNvtx_EB -> GetYaxis() -> SetRangeUser(0.040,0.080);
  
  g_RMSNoise_vsNvtx_EB -> Draw("AP");
  g_RMSNoise_vsNavgPU_EB -> Draw("P,same");
  
  TF1* f_pol1_vsNvtx_EB   = new TF1("f_pol1_vsNvtx_EB","[0]+[1]*x",0.,35.);
  f_pol1_vsNvtx_EB -> SetLineColor(kRed+2);
  TF1* f_pol1_vsNavgPU_EB = new TF1("f_pol1_vsNavgPU_EB","[0]+[1]*x",0.,35.);
  f_pol1_vsNavgPU_EB -> SetLineColor(kGreen+2);  
  g_RMSNoise_vsNvtx_EB -> Fit("f_pol1_vsNvtx_EB","QS+","",5.,25.);
  g_RMSNoise_vsNavgPU_EB -> Fit("f_pol1_vsNavgPU_EB","QS+","",10.,25.);
  f_pol1_vsNvtx_EB -> Draw("same");
  f_pol1_vsNavgPU_EB -> Draw("same");
  
  TLegend* legend = new TLegend(0.14, 0.70, 0.60, 0.94);
  legend -> SetFillColor(kWhite);
  legend -> SetFillStyle(0);
  legend -> SetLineWidth(0);
  legend -> SetLineColor(kWhite);
  legend -> SetTextFont(42);  
  legend -> SetTextSize(0.04);
  legend -> AddEntry(g_RMSNoise_vsNvtx_EB,"noise vs N_{vtx}","P");
  legend -> AddEntry(g_RMSNoise_vsNavgPU_EB,"noise vs Num^{Int}_{True}","P");
  legend -> Draw("same");
  
  TString NamePlot = Form("c1_RMSNoise_EB_%s.png",suffix.Data());
  c1_RMSNoise_EB -> SaveAs(NamePlot.Data(),"png");
  
  
  
  TCanvas* c1_RMSNoise_EE = new TCanvas("c1_RMSNoise_EE","EE RMS noise");
  c1_RMSNoise_EE -> cd();
  c1_RMSNoise_EE -> SetGridx();
  c1_RMSNoise_EE -> SetGridy();
  
  g_RMSNoise_vsNvtx_EE -> SetMarkerColor(kRed+2);
  g_RMSNoise_vsNavgPU_EE -> SetMarkerColor(kGreen+2);
    
  g_RMSNoise_vsNvtx_EE -> GetXaxis() -> SetTitle("N_{vtx} or Num^{Int}_{True}");
  g_RMSNoise_vsNvtx_EE -> GetYaxis() -> SetTitle("noise RMS (GeV)");
  g_RMSNoise_vsNvtx_EE -> GetXaxis() -> SetRangeUser(0.,35.);
  g_RMSNoise_vsNvtx_EE -> GetYaxis() -> SetRangeUser(0.20,0.35);
      
  g_RMSNoise_vsNvtx_EE -> Draw("AP");
  g_RMSNoise_vsNavgPU_EE -> Draw("P,same");
  
  TF1* f_pol1_vsNvtx_EE   = new TF1("f_pol1_vsNvtx_EE","[0]+[1]*x",0.,35.);
  f_pol1_vsNvtx_EE -> SetLineColor(kRed+2);
  TF1* f_pol1_vsNavgPU_EE = new TF1("f_pol1_vsNavgPU_EE","[0]+[1]*x",0.,35.);
  f_pol1_vsNavgPU_EE -> SetLineColor(kGreen+2);  
  g_RMSNoise_vsNvtx_EE -> Fit("f_pol1_vsNvtx_EE","QS+","",5.,25.);
  g_RMSNoise_vsNavgPU_EE -> Fit("f_pol1_vsNavgPU_EE","QS+","",10.,25.);
  f_pol1_vsNvtx_EE -> Draw("same");
  f_pol1_vsNavgPU_EE -> Draw("same");
  
  legend -> Draw("same");
 
  NamePlot = Form("c1_RMSNoise_EE_%s.png",suffix.Data());
  c1_RMSNoise_EE -> SaveAs(NamePlot.Data(),"png");
  
  
  
  
  
  
  TGraphErrors* g_noiseAtZero_vsIeta_EB = new TGraphErrors();
  TGraphErrors* g_noiseSlope_vsIeta_EB = new TGraphErrors();
  TGraphErrors* g_addNoise_vsIeta_EB = new TGraphErrors();
  
  for(int iEtaBin = 1; iEtaBin <= nBins_iEta; ++iEtaBin)
  {
    float iEtaBinCenter  = h_occupancy_vsIeta -> GetBinCenter(iEtaBin);
    float iEtaBinLowEdge = h_occupancy_vsIeta -> GetBinLowEdge(iEtaBin);
    float iEtaBinHigEdge = h_occupancy_vsIeta -> GetBinLowEdge(iEtaBin) + h_occupancy_vsIeta_EB->GetBinWidth(bin);
    
    TGraphErrors* g_RMSNoise_vsNavgPU_vsIeta_EB = new TGraphErrors();
    
    int point = 0;
    for(int bin = 1; bin <= nBins_nAvgPU; ++bin)
    {  
      TH1F* histo;
      char histoName[50];
      
      float binCenter  = h_occupancy_vsNavgPU -> GetBinCenter(bin);
      float binLowEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin);
      float binHigEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin) + h_occupancy_vsNavgPU_EB->GetBinWidth(bin);
      
      if( binCenter < 8. ) continue;
      if( binCenter > 30. ) continue;    
      sprintf(histoName,"hEB_recHitE_nAvgPU%02.1f-%02.1f_iEta%02.1f-%02.1f",binLowEdge,binHigEdge,iEtaBinLowEdge,iEtaBinHigEdge);
      histo = (TH1F*)( f->Get(histoName) );
      
      g_RMSNoise_vsNavgPU_vsIeta_EB -> SetPoint(point,binCenter,histo->GetRMS());
      g_RMSNoise_vsNavgPU_vsIeta_EB -> SetPointError(point,0.,histo->GetRMSError());
      
      ++point;
    }
    
    char funcName[50];
    sprintf(funcName,"f_pol1_iEta%02.1f-%02.1f_EB",iEtaBinLowEdge,iEtaBinHigEdge);
    TF1* f_pol1_vsNavgPU_vsIeta_EB = new TF1(funcName,"[0]+[1]*x",0.,35.);
    g_RMSNoise_vsNavgPU_vsIeta_EB -> Fit(funcName,"QS+","",10.,25.);
    
    g_noiseAtZero_vsIeta_EB -> SetPoint(iEtaBin-1,iEtaBinCenter,f_pol1_vsNavgPU_vsIeta_EB->GetParameter(0.));
    g_noiseAtZero_vsIeta_EB -> SetPointError(iEtaBin-1,0.,f_pol1_vsNavgPU_vsIeta_EB->GetParError(0.));
    g_noiseSlope_vsIeta_EB -> SetPoint(iEtaBin-1,iEtaBinCenter,f_pol1_vsNavgPU_vsIeta_EB->GetParameter(1.));
    g_noiseSlope_vsIeta_EB -> SetPointError(iEtaBin-1,0.,f_pol1_vsNavgPU_vsIeta_EB->GetParError(1.));
    
    g_addNoise_vsIeta_EB -> SetPoint(iEtaBin-1,iEtaBinCenter,sqrt(pow(f_pol1_vsNavgPU_vsIeta_EB->GetParameter(0.)+20.*f_pol1_vsNavgPU_vsIeta_EB->GetParameter(1.),2)-pow(f_pol1_vsNavgPU_vsIeta_EB->GetParameter(0.),2)));
  }
  
  
  
  TCanvas* c1_noiseAtZero_vsIeta_EB = new TCanvas("c1_noiseAtZero_vsIeta_EB","EB noise at 0 PU vs iEta");
  c1_noiseAtZero_vsIeta_EB -> cd();
  c1_noiseAtZero_vsIeta_EB -> SetGridx();
  c1_noiseAtZero_vsIeta_EB -> SetGridy();
  
  g_noiseAtZero_vsIeta_EB -> GetXaxis() -> SetTitle("i#eta");
  g_noiseAtZero_vsIeta_EB -> GetYaxis() -> SetTitle("RMS noise at N_{PU}=0 (GeV)");
  g_noiseAtZero_vsIeta_EB -> Draw("AP");
  
  NamePlot = Form("c1_noiseAtZero_vsIeta_EB_%s.png",suffix.Data());
  c1_noiseAtZero_vsIeta_EB -> SaveAs(NamePlot.Data(),"png");

  
  
  TCanvas* c1_noiseSlope_vsIeta_EB = new TCanvas("c1_noiseSlope_vsIeta_EB","EB noise slope vs iEta");
  c1_noiseSlope_vsIeta_EB -> cd();
  c1_noiseSlope_vsIeta_EB -> SetGridx();
  c1_noiseSlope_vsIeta_EB -> SetGridy();
  
  g_noiseSlope_vsIeta_EB -> GetXaxis() -> SetTitle("i#eta");
  g_noiseSlope_vsIeta_EB -> GetYaxis() -> SetTitle("RMS noise slope wrt N_{PU} (GeV/N_{PU})");
  g_noiseSlope_vsIeta_EB -> Draw("AP");
  
  NamePlot = Form("c1_noiseSlope_vsIeta_EB_%s.png",suffix.Data());
  c1_noiseSlope_vsIeta_EB -> SaveAs(NamePlot.Data(),"png");
  
  TCanvas* c1_addNoise_vsIeta_EB = new TCanvas("c1_addNoise_vsIeta_EB","EB additional noise vs iEta");
  c1_addNoise_vsIeta_EB -> cd();
  c1_addNoise_vsIeta_EB -> SetGridx();
  c1_addNoise_vsIeta_EB -> SetGridy();
  
  g_addNoise_vsIeta_EB -> GetXaxis() -> SetTitle("i#eta");
  g_addNoise_vsIeta_EB -> GetYaxis() -> SetTitle("additional quad. noise at N_{PU}=20 (GeV)");
  g_addNoise_vsIeta_EB -> Draw("AP");


  NamePlot = Form("c1_addNoise_vsIeta_EB_%s.png",suffix.Data());
  c1_addNoise_vsIeta_EB -> SaveAs(NamePlot.Data(),"png");
  
 
  
  TGraphErrors* g_noiseAtZero_vsIring_EE = new TGraphErrors();
  TGraphErrors* g_noiseSlope_vsIring_EE = new TGraphErrors();
  TGraphErrors* g_addNoise_vsIring_EE = new TGraphErrors();
    
  for(int iRingBin = 1; iRingBin <= nBins_iRing; ++iRingBin)
  {
    float iRingBinCenter  = h_occupancy_vsIring -> GetBinCenter(iRingBin);
    float iRingBinLowEdge = h_occupancy_vsIring -> GetBinLowEdge(iRingBin);
    float iRingBinHigEdge = h_occupancy_vsIring -> GetBinLowEdge(iRingBin) + h_occupancy_vsIring_EE->GetBinWidth(bin);
    
    if( iRingBinCenter > 33 ) continue;
    
    TGraphErrors* g_RMSNoise_vsNavgPU_vsIring_EE = new TGraphErrors();
    
    int point = 0;
    for(int bin = 1; bin <= nBins_nAvgPU; ++bin)
    {  
      TH1F* histo;
      char histoName[50];
      
      float binCenter  = h_occupancy_vsNavgPU -> GetBinCenter(bin);
      float binLowEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin);
      float binHigEdge = h_occupancy_vsNavgPU -> GetBinLowEdge(bin) + h_occupancy_vsNavgPU_EE->GetBinWidth(bin);
      
      if( binCenter < 8. ) continue;
      if( binCenter > 30. ) continue;    
      sprintf(histoName,"hEE_recHitE_nAvgPU%02.1f-%02.1f_iRing%02.1f-%02.1f",binLowEdge,binHigEdge,iRingBinLowEdge,iRingBinHigEdge);
      histo = (TH1F*)( f->Get(histoName) );
      
      g_RMSNoise_vsNavgPU_vsIring_EE -> SetPoint(point,binCenter,histo->GetRMS());
      g_RMSNoise_vsNavgPU_vsIring_EE -> SetPointError(point,0.,histo->GetRMSError());
      
      ++point;
    }
    
    char funcName[50];
    sprintf(funcName,"f_pol1_iRing%02.1f-%02.1f_EE",iRingBinLowEdge,iRingBinHigEdge);
    TF1* f_pol1_vsNavgPU_vsIring_EE = new TF1(funcName,"[0]+[1]*x",0.,35.);
    g_RMSNoise_vsNavgPU_vsIring_EE -> Fit(funcName,"QS+","",10.,25.);
    
    g_noiseAtZero_vsIring_EE -> SetPoint(iRingBin-1,iRingBinCenter,f_pol1_vsNavgPU_vsIring_EE->GetParameter(0.));
    g_noiseAtZero_vsIring_EE -> SetPointError(iRingBin-1,0.,f_pol1_vsNavgPU_vsIring_EE->GetParError(0.));
    g_noiseSlope_vsIring_EE -> SetPoint(iRingBin-1,iRingBinCenter,f_pol1_vsNavgPU_vsIring_EE->GetParameter(1.));
    g_noiseSlope_vsIring_EE -> SetPointError(iRingBin-1,0.,f_pol1_vsNavgPU_vsIring_EE->GetParError(1.));
    
    g_addNoise_vsIring_EE -> SetPoint(iRingBin-1,iRingBinCenter,sqrt(pow(f_pol1_vsNavgPU_vsIring_EE->GetParameter(0.)+20.*f_pol1_vsNavgPU_vsIring_EE->GetParameter(1.),2)-pow(f_pol1_vsNavgPU_vsIring_EE->GetParameter(0.),2)));    
  }
  
  
  
  TCanvas* c1_noiseAtZero_vsIring_EE = new TCanvas("c1_noiseAtZero_vsIring_EE","EE noise at 0 PU vs iRing");
  c1_noiseAtZero_vsIring_EE -> cd();
  c1_noiseAtZero_vsIring_EE -> SetGridx();
  c1_noiseAtZero_vsIring_EE -> SetGridy();
  
  g_noiseAtZero_vsIring_EE -> GetXaxis() -> SetTitle("ring");
  g_noiseAtZero_vsIring_EE -> GetYaxis() -> SetTitle("RMS noise at N_{PU}=0 (GeV)");
  g_noiseAtZero_vsIring_EE -> Draw("AP");
  
  NamePlot = Form("c1_noiseAtZero_vsIring_EE_%s.png",suffix.Data());
  c1_noiseAtZero_vsIring_EE -> SaveAs(NamePlot.Data(),"png"); 
  
  
  TCanvas* c1_noiseSlope_vsIring_EE = new TCanvas("c1_noiseSlope_vsIring_EE","EE noise slope vs iRing");
  c1_noiseSlope_vsIring_EE -> cd();
  c1_noiseSlope_vsIring_EE -> SetGridx();
  c1_noiseSlope_vsIring_EE -> SetGridy();
  
  g_noiseSlope_vsIring_EE -> GetXaxis() -> SetTitle("ring");
  g_noiseSlope_vsIring_EE -> GetYaxis() -> SetTitle("RMS noise slope wrt N_{PU} (GeV/N_{PU})");
  g_noiseSlope_vsIring_EE -> Draw("AP");  
  
  NamePlot = Form("c1_noiseSlope_vsIring_EE _%s.png",suffix.Data());
  c1_noiseSlope_vsIring_EE  -> SaveAs(NamePlot.Data(),"png");
  
  
  
  TCanvas* c1_addNoise_vsIring_EE = new TCanvas("c1_addNoise_vsIring_EE","EE additional noise vs iEta");
  c1_addNoise_vsIring_EE -> cd();
  c1_addNoise_vsIring_EE -> SetGridx();
  c1_addNoise_vsIring_EE -> SetGridy();
  
  g_addNoise_vsIring_EE -> GetXaxis() -> SetTitle("ring");
  g_addNoise_vsIring_EE -> GetYaxis() -> SetTitle("additional quad. noise at N_{PU}=20 (GeV)");
  g_addNoise_vsIring_EE -> Draw("AP");

  NamePlot = Form("c1_addNoise_vsIring_EE_%s.png",suffix.Data());
  c1_addNoise_vsIring_EE-> SaveAs(NamePlot.Data(),"png");
}
void ClusterWidthAnalysisTreeMaker::FitHistos(std::map<ULong64_t , std::vector<TH1F*> > &HistSoN, string output_file, 
 std::vector< TH1F* > commonHistos, std::map<ULong64_t, TProfile* > Monitors){

  TFile * myFile = new TFile(output_file.c_str(), "recreate");

  ULong64_t detid;
  double voltage;
  double errvoltage;
  double Mean;
  double errMean;
  double RMS;
  double errRMS;
  int index;
  int nhits;
  TTree *tree = new TTree("T", "summary information");

  tree->Branch("DetID",&detid, "DetID/l");
  tree->Branch("Voltage",&voltage,"Voltage/D");
  tree->Branch("Index",&index,"Index/I");
  tree->Branch("errVoltage",&errvoltage,"errVoltage/D");
  tree->Branch("Mean",&Mean,"Mean/D");
  tree->Branch("errMean",&errMean,"errMean/D");
  tree->Branch("RMS",&RMS,"RMS/D");
  tree->Branch("errRMS",&errRMS,"errRMS/D");
  tree->Branch("Nhits",&nhits,"Nhits/I");


  //TCanvas* c1 = new TCanvas();
  TH1F* hNhits = new TH1F("hNhits", "hNhits", 1000, 0,1000); // N hits per module
  
  unsigned int nfitrm=0;

  for(std::map<ULong64_t , std::vector<TH1F*> >::iterator iter = HistSoN.begin(); iter != HistSoN.end(); ++iter){
    
	unsigned int i=0; // voltage index    
    std::set< int >::iterator itVolt;
	std::set< int > Voltage = VSmaker.getVoltageList();
    for( itVolt=Voltage.begin(); itVolt!=Voltage.end(); itVolt++){
      
      //std::cout<<"going through the measurement: " << i << std::endl;
            
      TString thestring;
      thestring.Form("DetID_%llu_%u",iter->first,i);
 	  
	  
      //std::cout << "searching for " << thestring.Data() << std::endl;
      //TH1F*  SoNHisto= (TH1F*)gROOT->FindObject( thestring.Data() );
	  
	  if(i>=iter->second.size()) 
       { std::cout<<" Wrong number of voltage steps. "<<std::endl; i++; continue;}
 	  TH1F*  Histo = iter->second[i];
	  
	  if(!Histo) 
       { std::cout<<" Histo "<<thestring.Data()<<"_"<<i<<" not found."<<std::endl; i++; continue;}
 
      if(Histo->GetEntries()) hNhits->Fill(Histo->Integral());
	  
	  if(Histo->Integral()<20) //0.1
	   { //std::cout<<" Not enought entries for histo "<<thestring.Data()<<std::endl;
	    i++; continue;}
 
	  
	  detid = iter->first;

	  bool rmfit=false;

      if( rmfit || 
      // TIB modules
          // TIB - 1.4.2.5
      detid==369121605 || detid==369121606 || detid==369121614 || 
      detid==369121613 || detid==369121610 || detid==369121609 ||
          // TIB - 1.2.2.1
      detid==369121390 || detid==369121382 || detid==369121386 || 
      detid==369121385 || detid==369121389 || detid==369121381 ||
          // others in TIB  
      detid==369121437 || detid==369142077 || detid==369121722 || 
      detid==369125534 || detid==369137018 || detid==369121689 ||
      detid==369121765 || detid==369137045 || detid==369169740 ||
      detid==369121689 ||
      // TOB modules 
	      // TOB + 4.3.3.8
      detid/10==436281512 || detid/10==436281528 || detid/10==436281508 ||
      detid/10==436281524 || detid/10==436281520 || detid/10==436281516 ||
          // others in TOB  
      detid/10==436228249 || detid/10==436232694 || detid/10==436228805 ||
      detid/10==436244722 || detid/10==436245110 || detid/10==436249546 ||
      detid/10==436310808 || detid/10==436312136 || detid/10==436315600 ||
	      // without 'sensors' option 
      detid==436281512 || detid==436281528 || detid==436281508 ||
      detid==436281524 || detid==436281520 || detid==436281516 ||
      detid==436228249 || detid==436232694 || detid==436228805 ||
      detid==436244722 || detid==436245110 || detid==436249546 ||
      detid==436310808 || detid==436312136 || detid==436315600 || 
      // TID modules
      detid==402664070 || detid==402664110 ||
	  // TEC modules in small scans
      detid==470148196 || detid==470148200 || detid==470148204 ||
      detid==470148228 || detid==470148232 || detid==470148236 ||
      detid==470148240 || detid==470148261 || detid==470148262 ||
	  detid==470148265 || detid==470148266 || detid==470148292 ||
	  detid==470148296 || detid==470148300 || detid==470148304 ||
	  detid==470148324 || detid==470148328 || detid==470148332 ||
	  detid==470148336 || detid==470148340 )  { 
	    Histo->Write();
        std::cout << " Saving histo : " << thestring.Data() << std::endl;
      }  


	  if(rmfit) {nfitrm++; i++; continue;}

          int subdet = ((detid>>25)&0x7);
          int TECgeom=0;
          if(subdet==6) TECgeom = ((detid>>5)&0x7);

      // save values
	  detid = iter->first;
	  voltage  = *itVolt;
	  index = i;
	  errvoltage = 2 ;
	  Mean = Histo->GetMean();
	  errMean = Histo->GetMeanError();
	  RMS = Histo->GetRMS();
	  errRMS = Histo->GetRMSError();
	  nhits = (int) Histo->Integral();
	  tree->Fill();
	    
	  i++;

    }  

  }
  
  tree->Write();
  hNhits->Write();
  

  for(unsigned int ih=0; ih<commonHistos.size(); ih++) commonHistos[ih]->Write();

  std::map<ULong64_t, TProfile* >::iterator itMon;
  for(itMon=Monitors.begin(); itMon!=Monitors.end(); itMon++)
  {
    itMon->second->GetXaxis()->SetTimeDisplay(1);
	itMon->second->GetXaxis()->SetTimeFormat("%H:%M");
	itMon->second->GetXaxis()->SetTimeOffset(t_monitor_start);
	itMon->second->Write();
  }
  
  //// If you want to store all the individual detId histograms uncomments this line !!!!
  //myFile->Write();
  myFile->Close();

}
Esempio n. 6
0
int main(int argc, char* argv[])
{
        string htitle = "Events rate, cloud ";
        htitle = htitle+string(argv[1]);
	string drootpath;
    
        if (strcmp(argv[2],"ttreecache")==0)
	{
                htitle = htitle + ", TTreeCache enabled, protocol: WebDAV";
		drootpath = "../../../Histograms/TDavix/";
        }
	else if (strcmp(argv[2],"xrootd")==0)
        {
		htitle = htitle + ", TTreeCache enabled xrootd";
		drootpath = "../../../Histograms/xrootd/";
        }
	else
        {
	        htitle = htitle + ", TTreeCache disabled, protocol: WebDAV ";
		drootpath = "../../../Histograms/Davix/";
	}

	string cloudpath = argv[1] ;
	cloudpath = cloudpath + "/";
	DIR* dcloudrep = opendir(string2char(drootpath+cloudpath));
	struct dirent* dcloudfichier = NULL;
	string allgrid;
	allgrid = string(argv[3]);

	vector<ratioMatrixValue> th2array;
	
	while ((dcloudfichier = readdir(dcloudrep))!=0)
	{
		if (dcloudfichier->d_name[0]=='.')
			continue;
		string dcloudpath = cloudpath + dcloudfichier->d_name + "/";
		//DIR* drootfile = opendir(string2char(drootpath+dcloudpath));
		//struct dirent* drootfichier = NULL;

		string dfilepath = drootpath + dcloudpath + allgrid + "/" + dcloudfichier->d_name + ".root";
		ratioMatrixValue column;

		TFile *dfr = TFile::Open(string2char(dfilepath));
		if (dfr==NULL)
			continue;

		column.analy = dcloudfichier->d_name;

		for (int i=0;i<dfr->GetListOfKeys()->GetEntries();i++)
		{
			string dstrRead = string2char(dfr->GetListOfKeys()->At(i)->GetName());
			TH1F* dhist = (TH1F*)dfr->Get(string2char(dstrRead));
			if (dhist==NULL)
				continue;
			string otherTitle = string(dhist->GetName()) + "No Zero";
			TH1F* histSansZeros = new TH1F(string2char(otherTitle),dhist->GetTitle(),3000.,0,3000);
			for ( int l=2;l<3000;l++)
				for (int k=0;k<dhist->GetBinContent(l);k++)
					histSansZeros->Fill(l-1);
			column.datadisk.push_back(string2char(dstrRead));
			column.ratio.push_back(histSansZeros->GetMean());
			column.error.push_back(histSansZeros->GetRMSError());
		}
		th2array.push_back(column);
	}



        TCanvas * c = new TCanvas("c", "c");
        c->SetLeftMargin(0.20);
        c->SetBottomMargin(0.15);
        c->SetWindowSize(2100,1500);

	/*for (unsigned int i=0;i<th2array.size();i++)
	{
		cout << th2array[i].analy << "\t";
		for (unsigned int j=0;j<th2array[i].datadisk.size();j++)
			cout << th2array[i].datadisk[j] << "\t" ;
		cout << endl;
	}*/

	cout << "--------------------------" << endl;

	th2array = ordenate(th2array,string(argv[1]));

	cout << "--------------------------" << endl;

	/*for (unsigned int i=0;i<th2array.size();i++)
	{
		cout << th2array[i].analy << "\t";
		for (unsigned int j=0;j<th2array[i].datadisk.size();j++)
			cout << th2array[i].datadisk[j] << "\t" ;
		cout << endl;
	}*/

	unsigned int datadisk_number=0;
	unsigned int analy_number=0;
	for (unsigned int i=0;i<th2array.size();i++)
	{
		if (datadisk_number < th2array[i].datadisk.size())
		{
			datadisk_number = th2array[i].datadisk.size();
		}
		if (th2array[i].datadisk.size()!=0)
			analy_number++;
	}

	char *title = string2char(htitle);
	TH2F *h = new TH2F("eventMatrix",title,analy_number,0.,analy_number,datadisk_number,0.,datadisk_number);
	for (unsigned int i=0;i<th2array.size();i++)
	{
		//cout << "coucou  " << th2array[i].analy << " " << th2array[i].datadisk.size() << endl; 
		for (unsigned int j=0;j<th2array[i].datadisk.size();j++)
		{
			h->Fill(th2array[i].analy,th2array[i].datadisk[j],th2array[i].ratio[j]);
			//cout << i << " " << j << " " << th2array[i].error[j] << endl;
			h->SetCellError(i+1,j+1,th2array[i].error[j]);
			//cout << i << " " << j << " " << h->GetBinErrorLow(i+1,j+1) << " " << h->GetBinErrorUp(i+1,j+1) << endl;
		}
	}
	const Int_t Number = 5;
        Double_t Red[Number] = { 1.00, 0.75, 1.00, 0.25, 0.00 };
        Double_t Green[Number] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
        Double_t Blue[Number] = { 0.00, 0.00, 0.00, 0.00, 0.00 };
        Double_t Stops[Number] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
        Int_t nb=50;
        TColor::CreateGradientColorTable(Number,Stops,Red,Green,Blue,nb);
        h->GetXaxis()->SetTitle("Processing site");
        h->GetXaxis()->CenterTitle();
        h->GetYaxis()->SetTitle("Data source site");
        h->GetYaxis()->CenterTitle();
        h->SetLabelSize(0.03,"Y");
        h->SetTitleOffset(2.3,"Y");
        h->SetLabelSize(0.03,"X");
        h->SetTitleOffset(2.0,"X");
        h->GetYaxis()->SetTitle("Data source site");
        h->Draw("COLZ");
        h->Draw("TEXTE SAME");
        gStyle->SetOptStat(0);
        //gStyle->SetTitleY(0.1f);
        h->SetMaximum(750);
        h->SetMinimum(0);

	c->Print(Form("canvas.eps"));
        return 0;
}