CMS 3D CMS Logo

Functions
BSvsPVPlots.cc File Reference
#include "BSvsPVPlots.h"
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include "TPad.h"
#include "TH1D.h"
#include "TFile.h"
#include "TH2F.h"
#include "TH1F.h"
#include "TF1.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TText.h"
#include "TLegend.h"

Go to the source code of this file.

Functions

void BSvsPVPlots (const char *fullname, const char *module, const char *label, const char *postfix, const char *shortname, const char *outtrunk)
 

Function Documentation

◆ BSvsPVPlots()

void BSvsPVPlots ( const char *  fullname,
const char *  module,
const char *  label,
const char *  postfix,
const char *  shortname,
const char *  outtrunk 
)

Definition at line 22 of file BSvsPVPlots.cc.

References newFWLiteAna::bin, gather_cfg::cout, BTVHLTOfflineSource_cfi::dirname, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), mps_fire::i, label, callgraph::module, mps_fire::result, writedatasetfile::runs, CommonAnalyzer::setPath(), jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

27  {
28  char modfull[300];
29  sprintf(modfull, "%s%s", module, postfix);
30  char labfull[300];
31  sprintf(labfull, "%s%s", label, postfix);
32 
33  char dirname[400];
34  sprintf(dirname, "%s", shortname);
35 
36  // char fullname[300];
37  // if(strlen(family)==0) { sprintf(fullname,"rootfiles/Tracking_PFG_%s.root",filename);}
38  // else { sprintf(fullname,"rootfiles/%s.root",dirname); }
39 
40  std::string workdir = outtrunk;
41  workdir += dirname;
42  gSystem->cd(workdir.c_str());
43  gSystem->MakeDirectory(labfull);
44  // gSystem->cd("/afs/cern.ch/cms/tracking/output");
45 
46  TFile ff(fullname);
47 
48  gStyle->SetOptStat(111111);
49  // Colliding events
50 
51  CommonAnalyzer castat(&ff, "", modfull);
52  {
53  TH1F* deltax = (TH1F*)castat.getObject("deltax");
54  if (deltax && deltax->GetEntries() > 0) {
55  deltax->Draw();
56  gPad->SetLogy(1);
57  std::string plotfilename;
58  plotfilename += outtrunk;
59  plotfilename += dirname;
60  plotfilename += "/";
61  plotfilename += labfull;
62  plotfilename += "/deltax_";
63  plotfilename += labfull;
64  plotfilename += "_";
65  plotfilename += dirname;
66  plotfilename += ".gif";
67  gPad->Print(plotfilename.c_str());
68  gPad->SetLogy(0);
69  delete deltax;
70  }
71  TH1F* deltay = (TH1F*)castat.getObject("deltay");
72  if (deltay && deltay->GetEntries() > 0) {
73  deltay->Draw();
74  gPad->SetLogy(1);
75  std::string plotfilename;
76  plotfilename += outtrunk;
77  plotfilename += dirname;
78  plotfilename += "/";
79  plotfilename += labfull;
80  plotfilename += "/deltay_";
81  plotfilename += labfull;
82  plotfilename += "_";
83  plotfilename += dirname;
84  plotfilename += ".gif";
85  gPad->Print(plotfilename.c_str());
86  gPad->SetLogy(0);
87  delete deltay;
88  }
89  TH1F* deltaz = (TH1F*)castat.getObject("deltaz");
90  if (deltaz && deltaz->GetEntries() > 0) {
91  deltaz->Draw();
92  gPad->SetLogy(1);
93  std::string plotfilename;
94  plotfilename += outtrunk;
95  plotfilename += dirname;
96  plotfilename += "/";
97  plotfilename += labfull;
98  plotfilename += "/deltaz_";
99  plotfilename += labfull;
100  plotfilename += "_";
101  plotfilename += dirname;
102  plotfilename += ".gif";
103  gPad->Print(plotfilename.c_str());
104  gPad->SetLogy(0);
105  delete deltaz;
106  }
107  gStyle->SetOptStat(111);
108  gStyle->SetOptFit(111);
109  TProfile* deltaxvsz = (TProfile*)castat.getObject("deltaxvsz");
110  if (deltaxvsz && deltaxvsz->GetEntries() > 0) {
111  // deltaxvsz->Draw();
112  deltaxvsz->Fit("pol1", "", "", -10., 10.);
113  if (deltaxvsz->GetFunction("pol1")) {
114  deltaxvsz->GetFunction("pol1")->SetLineColor(kRed);
115  deltaxvsz->GetFunction("pol1")->SetLineWidth(1);
116  }
117  deltaxvsz->GetYaxis()->SetRangeUser(-0.001, 0.001);
118  std::string plotfilename;
119  plotfilename += outtrunk;
120  plotfilename += dirname;
121  plotfilename += "/";
122  plotfilename += labfull;
123  plotfilename += "/deltaxvsz_";
124  plotfilename += labfull;
125  plotfilename += "_";
126  plotfilename += dirname;
127  plotfilename += ".gif";
128  gPad->Print(plotfilename.c_str());
129  delete deltaxvsz;
130  }
131  TProfile* deltayvsz = (TProfile*)castat.getObject("deltayvsz");
132  if (deltayvsz && deltayvsz->GetEntries() > 0) {
133  // deltayvsz->Draw();
134  deltayvsz->Fit("pol1", "", "", -10., 10.);
135  if (deltayvsz->GetFunction("pol1")) {
136  deltayvsz->GetFunction("pol1")->SetLineColor(kRed);
137  deltayvsz->GetFunction("pol1")->SetLineWidth(1);
138  }
139  deltayvsz->GetYaxis()->SetRangeUser(-0.001, 0.001);
140  std::string plotfilename;
141  plotfilename += outtrunk;
142  plotfilename += dirname;
143  plotfilename += "/";
144  plotfilename += labfull;
145  plotfilename += "/deltayvsz_";
146  plotfilename += labfull;
147  plotfilename += "_";
148  plotfilename += dirname;
149  plotfilename += ".gif";
150  gPad->Print(plotfilename.c_str());
151  delete deltayvsz;
152  }
153  }
154  gStyle->SetOptStat(111111);
155  gStyle->SetOptFit(1111);
156 
157  // Define fitting functions
158  TF1* fdoubleg = new TF1("doubleg",
159  "[1]*exp(-0.5*((x-[0])/[2])**2)+[3]*exp(-0.5*((x-[0])/[4])**2)+[5]*exp(sqrt((x-[0])**2)*[6])",
160  -.2,
161  .2);
162  fdoubleg->SetLineColor(kRed);
163  fdoubleg->SetLineWidth(1);
164  /*
165  fdoubleg->SetParLimits(1,0.,1e9);
166  fdoubleg->SetParLimits(3,0.,1e9);
167  fdoubleg->SetParLimits(5,0.,1e9);
168  */
169 
170  gStyle->SetOptFit(1111);
171 
172  // Summary histograms
173  TH1D* deltaxsum = new TH1D("deltaxsum", "(PV-BS) Fitted X position vs run", 10, 0., 10.);
174  deltaxsum->SetCanExtend(TH1::kAllAxes);
175  TH1D* deltaysum = new TH1D("deltaysum", "(PV-BS) Fitted Y position vs run", 10, 0., 10.);
176  deltaysum->SetCanExtend(TH1::kAllAxes);
177 
178  TH1D* deltaxmeansum = new TH1D("deltaxmeansum", "(PV-BS) Mean X position vs run", 10, 0., 10.);
179  deltaxmeansum->SetCanExtend(TH1::kAllAxes);
180  TH1D* deltaymeansum = new TH1D("deltaymeansum", "(PV-BS) Mean Y position vs run", 10, 0., 10.);
181  deltaymeansum->SetCanExtend(TH1::kAllAxes);
182 
183  TH1D* deltazmeansum = new TH1D("deltazmeansum", "(PV-BS) Mean Z position vs run", 10, 0., 10.);
184  deltazmeansum->SetCanExtend(TH1::kAllAxes);
185 
186  std::vector<unsigned int> runs = castat.getRunList();
187  std::sort(runs.begin(), runs.end());
188 
189  {
190  std::cout << "Found " << runs.size() << " runs" << std::endl;
191 
192  for (unsigned int i = 0; i < runs.size(); ++i) {
193  char runlabel[100];
194  sprintf(runlabel, "%d", runs[i]);
195  char runpath[100];
196  sprintf(runpath, "run_%d", runs[i]);
197  castat.setPath(runpath);
198  std::cout << runpath << std::endl;
199 
200  TH1F* deltax = (TH1F*)castat.getObject("deltaxrun");
201  if (deltax && deltax->GetEntries() > 0) {
202  // deltax->Draw();
203  fdoubleg->SetParameter(0, deltax->GetMean());
204  fdoubleg->SetParameter(2, deltax->GetRMS());
205  fdoubleg->SetParameter(4, deltax->GetRMS());
206  fdoubleg->SetParameter(1, deltax->GetMaximum());
207  fdoubleg->SetParameter(3, 0.1 * deltax->GetMaximum());
208  fdoubleg->SetParameter(5, 0.1 * deltax->GetMaximum());
209  const int result = deltax->Fit(fdoubleg, "b", "", -.05, .05);
210  gPad->SetLogy(1);
211  char tresult[100];
212  sprintf(tresult, "%d", result);
213  TText res;
214  res.SetTextColor(kRed);
215  if (result != 0)
216  res.DrawTextNDC(.2, .8, tresult);
217 
218  int bin = deltaxsum->Fill(runlabel, fdoubleg->GetParameter(0));
219  deltaxsum->SetBinError(bin, fdoubleg->GetParError(0));
220 
221  bin = deltaxmeansum->Fill(runlabel, deltax->GetMean());
222  deltaxmeansum->SetBinError(bin, deltax->GetMeanError());
223 
224  std::string plotfilename;
225  plotfilename += outtrunk;
226  plotfilename += dirname;
227  plotfilename += "/";
228  plotfilename += labfull;
229  plotfilename += "/deltaxrun_";
230  plotfilename += labfull;
231  plotfilename += "_";
232  plotfilename += dirname;
233  plotfilename += "_";
234  plotfilename += runpath;
235  plotfilename += ".gif";
236  gPad->Print(plotfilename.c_str());
237  gPad->SetLogy(0);
238  delete deltax;
239  }
240  TH1F* deltay = (TH1F*)castat.getObject("deltayrun");
241  if (deltay && deltay->GetEntries() > 0) {
242  deltay->Draw();
243  fdoubleg->SetParameter(0, deltay->GetMean());
244  fdoubleg->SetParameter(2, deltay->GetRMS());
245  fdoubleg->SetParameter(4, deltay->GetRMS());
246  fdoubleg->SetParameter(1, deltay->GetMaximum());
247  fdoubleg->SetParameter(3, 0.1 * deltay->GetMaximum());
248  fdoubleg->SetParameter(5, 0.1 * deltay->GetMaximum());
249  const int result = deltay->Fit(fdoubleg, "b", "", -.05, .05);
250  gPad->SetLogy(1);
251  char tresult[100];
252  sprintf(tresult, "%d", result);
253  TText res;
254  res.SetTextColor(kRed);
255  if (result != 0)
256  res.DrawTextNDC(.2, .8, tresult);
257 
258  int bin = deltaysum->Fill(runlabel, fdoubleg->GetParameter(0));
259  deltaysum->SetBinError(bin, fdoubleg->GetParError(0));
260 
261  bin = deltaymeansum->Fill(runlabel, deltay->GetMean());
262  deltaymeansum->SetBinError(bin, deltay->GetMeanError());
263 
264  std::string plotfilename;
265  plotfilename += outtrunk;
266  plotfilename += dirname;
267  plotfilename += "/";
268  plotfilename += labfull;
269  plotfilename += "/deltayrun_";
270  plotfilename += labfull;
271  plotfilename += "_";
272  plotfilename += dirname;
273  plotfilename += "_";
274  plotfilename += runpath;
275  plotfilename += ".gif";
276  gPad->Print(plotfilename.c_str());
277  gPad->SetLogy(0);
278  delete deltay;
279  }
280  TH1F* deltaz = (TH1F*)castat.getObject("deltazrun");
281  if (deltaz && deltaz->GetEntries() > 0) {
282  deltaz->Draw();
283  gPad->SetLogy(1);
284 
285  int bin = deltazmeansum->Fill(runlabel, deltaz->GetMean());
286  deltazmeansum->SetBinError(bin, deltaz->GetMeanError());
287 
288  std::string plotfilename;
289  plotfilename += outtrunk;
290  plotfilename += dirname;
291  plotfilename += "/";
292  plotfilename += labfull;
293  plotfilename += "/deltazrun_";
294  plotfilename += labfull;
295  plotfilename += "_";
296  plotfilename += dirname;
297  plotfilename += "_";
298  plotfilename += runpath;
299  plotfilename += ".gif";
300  gPad->Print(plotfilename.c_str());
301  gPad->SetLogy(0);
302  delete deltaz;
303  }
304 
305  TProfile* deltaxvsz = (TProfile*)castat.getObject("deltaxvszrun");
306  if (deltaxvsz && deltaxvsz->GetEntries() > 0) {
307  deltaxvsz->Draw();
308  std::string plotfilename;
309  plotfilename += outtrunk;
310  plotfilename += dirname;
311  plotfilename += "/";
312  plotfilename += labfull;
313  plotfilename += "/deltaxvszrun_";
314  plotfilename += labfull;
315  plotfilename += "_";
316  plotfilename += dirname;
317  plotfilename += "_";
318  plotfilename += runpath;
319  plotfilename += ".gif";
320  gPad->Print(plotfilename.c_str());
321  delete deltaxvsz;
322  }
323 
324  TProfile* deltayvsz = (TProfile*)castat.getObject("deltayvszrun");
325  if (deltayvsz && deltayvsz->GetEntries() > 0) {
326  deltayvsz->Draw();
327  std::string plotfilename;
328  plotfilename += outtrunk;
329  plotfilename += dirname;
330  plotfilename += "/";
331  plotfilename += labfull;
332  plotfilename += "/deltayvszrun_";
333  plotfilename += labfull;
334  plotfilename += "_";
335  plotfilename += dirname;
336  plotfilename += "_";
337  plotfilename += runpath;
338  plotfilename += ".gif";
339  gPad->Print(plotfilename.c_str());
340  delete deltayvsz;
341  }
342 
343  TH1F* deltaxvsorb = (TH1F*)castat.getObject("deltaxvsorbrun");
344  if (deltaxvsorb && deltaxvsorb->GetEntries() > 0) {
345  deltaxvsorb->Draw();
346  std::string plotfilename;
347  plotfilename += outtrunk;
348  plotfilename += dirname;
349  plotfilename += "/";
350  plotfilename += labfull;
351  plotfilename += "/deltaxvsorb_";
352  plotfilename += labfull;
353  plotfilename += "_";
354  plotfilename += dirname;
355  plotfilename += "_";
356  plotfilename += runpath;
357  plotfilename += ".gif";
358  gPad->Print(plotfilename.c_str());
359  delete deltaxvsorb;
360  }
361  TH1F* deltayvsorb = (TH1F*)castat.getObject("deltayvsorbrun");
362  if (deltayvsorb && deltayvsorb->GetEntries() > 0) {
363  deltayvsorb->Draw();
364  std::string plotfilename;
365  plotfilename += outtrunk;
366  plotfilename += dirname;
367  plotfilename += "/";
368  plotfilename += labfull;
369  plotfilename += "/deltayvsorb_";
370  plotfilename += labfull;
371  plotfilename += "_";
372  plotfilename += dirname;
373  plotfilename += "_";
374  plotfilename += runpath;
375  plotfilename += ".gif";
376  gPad->Print(plotfilename.c_str());
377  delete deltayvsorb;
378  }
379  TH1F* deltazvsorb = (TH1F*)castat.getObject("deltazvsorbrun");
380  if (deltazvsorb && deltazvsorb->GetEntries() > 0) {
381  deltazvsorb->Draw();
382  std::string plotfilename;
383  plotfilename += outtrunk;
384  plotfilename += dirname;
385  plotfilename += "/";
386  plotfilename += labfull;
387  plotfilename += "/deltazvsorb_";
388  plotfilename += labfull;
389  plotfilename += "_";
390  plotfilename += dirname;
391  plotfilename += "_";
392  plotfilename += runpath;
393  plotfilename += ".gif";
394  gPad->Print(plotfilename.c_str());
395  delete deltazvsorb;
396  }
397  }
398  }
399 
400  gStyle->SetOptStat(1111);
401  gStyle->SetOptFit(0);
402 
403  if (!runs.empty()) {
404  std::string plotfilename;
405 
406  plotfilename = outtrunk;
407  plotfilename += dirname;
408  plotfilename += "/";
409  plotfilename += labfull;
410  plotfilename += "/deltaxsum_";
411  plotfilename += labfull;
412  plotfilename += "_";
413  plotfilename += dirname;
414  plotfilename += ".gif";
415 
416  TCanvas* cwidedeltax = new TCanvas(plotfilename.c_str(), plotfilename.c_str(), 1500, 500);
417 
418  deltaxsum->SetLineColor(kRed);
419  deltaxsum->SetMarkerColor(kRed);
420  deltaxsum->GetYaxis()->SetRangeUser(-.002, .002);
421  deltaxsum->GetYaxis()->SetTitle("#Delta x (cm)");
422  deltaxsum->Draw();
423  deltaxmeansum->Draw("esame");
424  TLegend deltaxleg(.7, .8, .85, .9, "#Delta(x)");
425  deltaxleg.AddEntry(deltaxsum, "fitted mean", "l");
426  deltaxleg.AddEntry(deltaxmeansum, "aritm. mean", "l");
427  deltaxleg.Draw();
428  gPad->Print(plotfilename.c_str());
429  delete cwidedeltax;
430 
431  plotfilename = outtrunk;
432  plotfilename += dirname;
433  plotfilename += "/";
434  plotfilename += labfull;
435  plotfilename += "/deltaysum_";
436  plotfilename += labfull;
437  plotfilename += "_";
438  plotfilename += dirname;
439  plotfilename += ".gif";
440 
441  TCanvas* cwidedeltay = new TCanvas(plotfilename.c_str(), plotfilename.c_str(), 1500, 500);
442 
443  deltaysum->SetLineColor(kRed);
444  deltaysum->SetMarkerColor(kRed);
445  deltaysum->GetYaxis()->SetRangeUser(-.002, .002);
446  deltaysum->GetYaxis()->SetTitle("#Delta y (cm)");
447  deltaysum->Draw();
448  deltaymeansum->Draw("esame");
449  TLegend deltayleg(.7, .8, .85, .9, "#Delta(y)");
450  deltayleg.AddEntry(deltaysum, "fitted mean", "l");
451  deltayleg.AddEntry(deltaymeansum, "aritm. mean", "l");
452  deltayleg.Draw();
453  gPad->Print(plotfilename.c_str());
454  delete cwidedeltay;
455 
456  plotfilename = outtrunk;
457  plotfilename += dirname;
458  plotfilename += "/";
459  plotfilename += labfull;
460  plotfilename += "/deltazsum_";
461  plotfilename += labfull;
462  plotfilename += "_";
463  plotfilename += dirname;
464  plotfilename += ".gif";
465 
466  TCanvas* cwidedeltaz = new TCanvas(plotfilename.c_str(), plotfilename.c_str(), 1500, 500);
467 
468  deltazmeansum->GetYaxis()->SetRangeUser(-2., 2.);
469  deltazmeansum->GetYaxis()->SetTitle("#Delta z (cm)");
470  deltazmeansum->Draw();
471  gPad->Print(plotfilename.c_str());
472  delete cwidedeltaz;
473  }
474  delete deltaxsum;
475  delete deltaysum;
476  delete deltaxmeansum;
477  delete deltaymeansum;
478  delete deltazmeansum;
479 
480  ff.Close();
481  delete fdoubleg;
482 }
Definition: Electron.h:6
char const * label