File indexing completed on 2024-04-06 12:06:32
0001 #include <iostream>
0002 #include <algorithm>
0003 #include <vector>
0004 #include <string>
0005 #include "MultiplicityPlotMacros.h"
0006 #include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
0007 #include "TFile.h"
0008 #include "TH1D.h"
0009 #include "TProfile.h"
0010 #include "TDirectory.h"
0011 #include "TCanvas.h"
0012 #include "TStyle.h"
0013 #include "TLegend.h"
0014
0015 void PlotPixelMultVtxPos(TFile* ff, const char* module) {
0016 CommonAnalyzer camult(ff, "", module);
0017
0018
0019 std::vector<std::string> labels;
0020 labels.push_back("FPIX_m");
0021 labels.push_back("BPIX_L1_mod_1");
0022 labels.push_back("BPIX_L1_mod_2");
0023 labels.push_back("BPIX_L1_mod_3");
0024 labels.push_back("BPIX_L1_mod_4");
0025 labels.push_back("BPIX_L1_mod_5");
0026 labels.push_back("BPIX_L1_mod_6");
0027 labels.push_back("BPIX_L1_mod_7");
0028 labels.push_back("BPIX_L1_mod_8");
0029 labels.push_back("FPIX_p");
0030 labels.push_back("BPIX_L1");
0031 labels.push_back("BPIX_L2");
0032 labels.push_back("BPIX_L3");
0033 labels.push_back("Lumi");
0034
0035 std::vector<TProfile*> profs;
0036
0037 for (unsigned int i = 0; i < labels.size(); ++i) {
0038 std::string path = "VtxPosCorr/" + labels[i];
0039 camult.setPath(path.c_str());
0040
0041 std::string hname = "n" + labels[i] + "digivsvtxposprof";
0042 profs.push_back((TProfile*)camult.getObject(hname.c_str()));
0043 }
0044
0045 TCanvas* cc = new TCanvas("BPIX L1 details", "BPIX L1 details", 1000, 1000);
0046 gPad->Divide(2, 2);
0047
0048 for (unsigned int i = 1; i < 5; ++i) {
0049 cc->cd(i);
0050 if (profs[i] && profs[9 - i]) {
0051 profs[i]->Draw();
0052 profs[9 - i]->SetLineColor(kRed);
0053 profs[9 - i]->SetMarkerColor(kRed);
0054 profs[9 - i]->Draw("same");
0055 TLegend* leg = new TLegend(0.4, 0.8, 0.6, 0.9, "Occupancy");
0056 leg->SetFillStyle(0);
0057 leg->AddEntry(profs[i], labels[i].c_str(), "l");
0058 leg->AddEntry(profs[9 - i], labels[9 - i].c_str(), "l");
0059 leg->Draw();
0060 }
0061 }
0062 new TCanvas("FPIX", "FPIX");
0063 if (profs[0] && profs[9]) {
0064 profs[0]->Draw();
0065 profs[9]->SetLineColor(kRed);
0066 profs[9]->SetMarkerColor(kRed);
0067 profs[9]->Draw("same");
0068 TLegend* leg = new TLegend(0.4, 0.8, 0.6, 0.9, "Occupancy");
0069 leg->SetFillStyle(0);
0070 leg->AddEntry(profs[0], labels[0].c_str(), "l");
0071 leg->AddEntry(profs[9], labels[9].c_str(), "l");
0072 leg->Draw();
0073 }
0074
0075 gStyle->SetOptStat(11);
0076 gStyle->SetOptFit(11);
0077 new TCanvas("BPIXL1", "BPIX L1");
0078 profs[10]->Fit("pol2");
0079 new TCanvas("BPIXL2", "BPIX L2");
0080 profs[11]->Fit("pol2");
0081 new TCanvas("BPIXL3", "BPIX L3");
0082 profs[12]->Fit("pol2");
0083
0084 new TCanvas("LumiAdd", "LumiAdd");
0085 TH1D* hlumi = profs[11]->ProjectionX("lumi");
0086 TH1D* hbpixl3 = profs[12]->ProjectionX("bpixl3");
0087 TH1D* hfpixm = profs[0]->ProjectionX("fpixm");
0088 TH1D* hfpixp = profs[9]->ProjectionX("fpixp");
0089 hlumi->SetTitle("BPIX L2+L3 + FPIX multiplicity vs vtx z position");
0090 hlumi->Add(hbpixl3);
0091 hlumi->Add(hfpixm);
0092 hlumi->Add(hfpixp);
0093 hlumi->Fit("pol2");
0094 new TCanvas("Lumi", "Lumi");
0095 profs[13]->Fit("pol2");
0096 }
0097
0098 TH1D* AverageRunMultiplicity(TFile& ff,
0099 const char* module,
0100 const bool excludeLastBins = false,
0101 const char* histo = "nTKdigivsorbrun") {
0102 CommonAnalyzer camult(&ff, "", module);
0103
0104 TH1D* clusmult = new TH1D("clusmult", "Average Multiplicity vs run", 10, 0., 10.);
0105 clusmult->SetCanExtend(TH1::kXaxis);
0106
0107 std::vector<unsigned int> runs = camult.getRunList();
0108 std::sort(runs.begin(), runs.end());
0109
0110 {
0111 for (unsigned int i = 0; i < runs.size(); ++i) {
0112 char runlabel[100];
0113 sprintf(runlabel, "%d", runs[i]);
0114 char runpath[100];
0115 sprintf(runpath, "run_%d", runs[i]);
0116 camult.setPath(runpath);
0117
0118 TProfile* multvstime = nullptr;
0119 if (multvstime == nullptr)
0120 multvstime = (TProfile*)camult.getObject(histo);
0121 if (multvstime) {
0122
0123
0124 if (excludeLastBins) {
0125 int lastbin = multvstime->GetNbinsX() + 1;
0126 int firstbin = 1;
0127 for (int ibin = multvstime->GetNbinsX() + 1; ibin > 0; --ibin) {
0128 if (multvstime->GetBinEntries(ibin) != 0) {
0129 lastbin = ibin;
0130 break;
0131 }
0132 }
0133
0134 std::cout << "Restricted range: " << firstbin << " " << lastbin << std::endl;
0135 multvstime->GetXaxis()->SetRangeUser(multvstime->GetBinLowEdge(firstbin),
0136 multvstime->GetBinLowEdge(lastbin - 2));
0137 }
0138
0139 clusmult->Fill(runlabel, multvstime->GetMean(2));
0140 }
0141 }
0142 }
0143 return clusmult;
0144 }