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

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 stringResolutionProvider_cfi::bin, gather_cfg::cout, compare_using_db::dirname, alignCSCRings::ff, CommonAnalyzer::getObject(), CommonAnalyzer::getRunList(), mps_fire::i, mps_fire::result, writedatasetfile::runs, CommonAnalyzer::setPath(), jetUpdater_cfi::sort, and AlCaHLTBitMon_QueryRunRegistry::string.

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