CMS 3D CMS Logo

MultiplicityPlotMacros.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <string>
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TProfile.h"
10 #include "TDirectory.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TLegend.h"
14 
15 void PlotPixelMultVtxPos(TFile* ff, const char* module) {
16  CommonAnalyzer camult(ff, "", module);
17  // camult.setPath("VtxPosCorr");
18 
19  std::vector<std::string> labels;
20  labels.push_back("FPIX_m");
21  labels.push_back("BPIX_L1_mod_1");
22  labels.push_back("BPIX_L1_mod_2");
23  labels.push_back("BPIX_L1_mod_3");
24  labels.push_back("BPIX_L1_mod_4");
25  labels.push_back("BPIX_L1_mod_5");
26  labels.push_back("BPIX_L1_mod_6");
27  labels.push_back("BPIX_L1_mod_7");
28  labels.push_back("BPIX_L1_mod_8");
29  labels.push_back("FPIX_p");
30  labels.push_back("BPIX_L1");
31  labels.push_back("BPIX_L2");
32  labels.push_back("BPIX_L3");
33  labels.push_back("Lumi");
34 
35  std::vector<TProfile*> profs;
36 
37  for (unsigned int i = 0; i < labels.size(); ++i) {
38  std::string path = "VtxPosCorr/" + labels[i];
39  camult.setPath(path.c_str());
40 
41  std::string hname = "n" + labels[i] + "digivsvtxposprof";
42  profs.push_back((TProfile*)camult.getObject(hname.c_str()));
43  }
44 
45  TCanvas* cc = new TCanvas("BPIX L1 details", "BPIX L1 details", 1000, 1000);
46  gPad->Divide(2, 2);
47 
48  for (unsigned int i = 1; i < 5; ++i) {
49  cc->cd(i);
50  if (profs[i] && profs[9 - i]) {
51  profs[i]->Draw();
52  profs[9 - i]->SetLineColor(kRed);
53  profs[9 - i]->SetMarkerColor(kRed);
54  profs[9 - i]->Draw("same");
55  TLegend* leg = new TLegend(0.4, 0.8, 0.6, 0.9, "Occupancy");
56  leg->SetFillStyle(0);
57  leg->AddEntry(profs[i], labels[i].c_str(), "l");
58  leg->AddEntry(profs[9 - i], labels[9 - i].c_str(), "l");
59  leg->Draw();
60  }
61  }
62  new TCanvas("FPIX", "FPIX");
63  if (profs[0] && profs[9]) {
64  profs[0]->Draw();
65  profs[9]->SetLineColor(kRed);
66  profs[9]->SetMarkerColor(kRed);
67  profs[9]->Draw("same");
68  TLegend* leg = new TLegend(0.4, 0.8, 0.6, 0.9, "Occupancy");
69  leg->SetFillStyle(0);
70  leg->AddEntry(profs[0], labels[0].c_str(), "l");
71  leg->AddEntry(profs[9], labels[9].c_str(), "l");
72  leg->Draw();
73  }
74 
75  gStyle->SetOptStat(11);
76  gStyle->SetOptFit(11);
77  new TCanvas("BPIXL1", "BPIX L1");
78  profs[10]->Fit("pol2");
79  new TCanvas("BPIXL2", "BPIX L2");
80  profs[11]->Fit("pol2");
81  new TCanvas("BPIXL3", "BPIX L3");
82  profs[12]->Fit("pol2");
83 
84  new TCanvas("LumiAdd", "LumiAdd");
85  TH1D* hlumi = profs[11]->ProjectionX("lumi");
86  TH1D* hbpixl3 = profs[12]->ProjectionX("bpixl3");
87  TH1D* hfpixm = profs[0]->ProjectionX("fpixm");
88  TH1D* hfpixp = profs[9]->ProjectionX("fpixp");
89  hlumi->SetTitle("BPIX L2+L3 + FPIX multiplicity vs vtx z position");
90  hlumi->Add(hbpixl3);
91  hlumi->Add(hfpixm);
92  hlumi->Add(hfpixp);
93  hlumi->Fit("pol2");
94  new TCanvas("Lumi", "Lumi");
95  profs[13]->Fit("pol2");
96 }
97 
99  const char* module,
100  const bool excludeLastBins = false,
101  const char* histo = "nTKdigivsorbrun") {
102  CommonAnalyzer camult(&ff, "", module);
103 
104  TH1D* clusmult = new TH1D("clusmult", "Average Multiplicity vs run", 10, 0., 10.);
105  clusmult->SetCanExtend(TH1::kXaxis);
106 
107  std::vector<unsigned int> runs = camult.getRunList();
108  std::sort(runs.begin(), runs.end());
109 
110  {
111  for (unsigned int i = 0; i < runs.size(); ++i) {
112  char runlabel[100];
113  sprintf(runlabel, "%d", runs[i]);
114  char runpath[100];
115  sprintf(runpath, "run_%d", runs[i]);
116  camult.setPath(runpath);
117 
118  TProfile* multvstime = nullptr;
119  if (multvstime == nullptr)
120  multvstime = (TProfile*)camult.getObject(histo);
121  if (multvstime) {
122  // compute mean exlucing the last filled bins
123 
124  if (excludeLastBins) {
125  int lastbin = multvstime->GetNbinsX() + 1;
126  int firstbin = 1;
127  for (int ibin = multvstime->GetNbinsX() + 1; ibin > 0; --ibin) {
128  if (multvstime->GetBinEntries(ibin) != 0) {
129  lastbin = ibin;
130  break;
131  }
132  }
133 
134  std::cout << "Restricted range: " << firstbin << " " << lastbin << std::endl;
135  multvstime->GetXaxis()->SetRangeUser(multvstime->GetBinLowEdge(firstbin),
136  multvstime->GetBinLowEdge(lastbin - 2));
137  }
138  // fill the summary
139  clusmult->Fill(runlabel, multvstime->GetMean(2));
140  }
141  }
142  }
143  return clusmult;
144 }
TH1D * AverageRunMultiplicity(TFile &ff, const char *module, const bool excludeLastBins=false, const char *histo="nTKdigivsorbrun")
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
TObject * getObject(const char *name) const
void PlotPixelMultVtxPos(TFile *ff, const char *module)
void setPath(const char *path)
const std::vector< unsigned int > getRunList() const