CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Validation/RecoVertex/src/BeamSpotHistogramMaker.cc

Go to the documentation of this file.
00001 #include "Validation/RecoVertex/interface/BeamSpotHistogramMaker.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00006 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00007 #include "TH2F.h"
00008 #include "TH1F.h"
00009 #include "TProfile.h"
00010 
00011 
00012 BeamSpotHistogramMaker::BeamSpotHistogramMaker():
00013   _currdir(0), _histoParameters(), _rhm() { }
00014 
00015 BeamSpotHistogramMaker::BeamSpotHistogramMaker(const edm::ParameterSet& iConfig):
00016   _currdir(0),
00017   _histoParameters(iConfig.getUntrackedParameter<edm::ParameterSet>("histoParameters",edm::ParameterSet())),
00018   _rhm()
00019 { }
00020 
00021 
00022 BeamSpotHistogramMaker::~BeamSpotHistogramMaker() {
00023 
00024   delete _currdir;
00025 
00026 }
00027 
00028 
00029 void BeamSpotHistogramMaker::book(const std::string dirname) {
00030 
00031   edm::Service<TFileService> tfserv;
00032   TFileDirectory* currdir = &(*tfserv);
00033 
00034   if(dirname!="") {
00035     currdir = new TFileDirectory(tfserv->mkdir(dirname));
00036     _currdir = currdir;
00037   }
00038 
00039   edm::LogInfo("HistogramBooking") << "BeamSpot histogram booking in directory " << dirname;
00040 
00041   _hbsxrun = _rhm.makeTH1F("bsxrun","BeamSpot X position",
00042                             _histoParameters.getUntrackedParameter<unsigned int>("nBinX",200),
00043                             _histoParameters.getUntrackedParameter<double>("xMin",-1.),
00044                             _histoParameters.getUntrackedParameter<double>("xMax",1.));
00045 
00046   _hbsyrun = _rhm.makeTH1F("bsyrun","BeamSpot Y position",
00047                             _histoParameters.getUntrackedParameter<unsigned int>("nBinY",200),
00048                             _histoParameters.getUntrackedParameter<double>("yMin",-1.),
00049                             _histoParameters.getUntrackedParameter<double>("yMax",1.));
00050 
00051   _hbszrun = _rhm.makeTH1F("bszrun","BeamSpot Z position",
00052                             _histoParameters.getUntrackedParameter<unsigned int>("nBinZ",200),
00053                             _histoParameters.getUntrackedParameter<double>("zMin",-1.),
00054                             _histoParameters.getUntrackedParameter<double>("zMax",1.));
00055 
00056   _hbssigmaxrun = _rhm.makeTH1F("bssigmaxrun","BeamSpot sigmaX",
00057                                 _histoParameters.getUntrackedParameter<unsigned int>("nBinSigmaX",200),
00058                                 _histoParameters.getUntrackedParameter<double>("sigmaXMin",0.),
00059                                 _histoParameters.getUntrackedParameter<double>("sigmaXMax",0.025));
00060 
00061   _hbssigmayrun = _rhm.makeTH1F("bssigmayrun","BeamSpot sigmaY",
00062                                 _histoParameters.getUntrackedParameter<unsigned int>("nBinSigmaY",200),
00063                                 _histoParameters.getUntrackedParameter<double>("sigmaYMin",0.),
00064                                 _histoParameters.getUntrackedParameter<double>("sigmaYMax",0.025));
00065 
00066   _hbssigmazrun = _rhm.makeTH1F("bssigmazrun","BeamSpot sigmaZ",
00067                                 _histoParameters.getUntrackedParameter<unsigned int>("nBinSigmaZ",200),
00068                                 _histoParameters.getUntrackedParameter<double>("sigmaZMin",0.),
00069                                 _histoParameters.getUntrackedParameter<double>("sigmaZMax",15.));
00070 
00071   _hbsxvsorbrun = _rhm.makeTProfile("bsxvsorbrun","BeamSpot X position vs orbit number",1600,0.5,1600.*16384+0.5);
00072   _hbsyvsorbrun = _rhm.makeTProfile("bsyvsorbrun","BeamSpot Y position vs orbit number",1600,0.5,1600.*16384+0.5);
00073   _hbszvsorbrun = _rhm.makeTProfile("bszvsorbrun","BeamSpot Z position vs orbit number",1600,0.5,1600.*16384+0.5);
00074   _hbssigmaxvsorbrun = _rhm.makeTProfile("bssigmaxvsorbrun","BeamSpot sigmaX vs orbit number",1600,0.5,1600.*16384+0.5);
00075   _hbssigmayvsorbrun = _rhm.makeTProfile("bssigmayvsorbrun","BeamSpot sigmaY vs orbit number",1600,0.5,1600.*16384+0.5);
00076   _hbssigmazvsorbrun = _rhm.makeTProfile("bssigmazvsorbrun","BeamSpot sigmaZ vs orbit number",1600,0.5,1600.*16384+0.5);
00077 
00078 }
00079 
00080 void BeamSpotHistogramMaker::beginRun(const unsigned int nrun) {
00081 
00082   char runname[100];
00083   sprintf(runname,"run_%d",nrun);
00084 
00085   TFileDirectory* currdir = _currdir;
00086   if(currdir==0) {
00087     edm::Service<TFileService> tfserv;
00088     currdir = &(*tfserv);
00089   }
00090 
00091   _rhm.beginRun(nrun,*currdir);
00092 
00093   (*_hbsxrun)->GetXaxis()->SetTitle("X [cm]");   (*_hbsxrun)->GetYaxis()->SetTitle("Events"); 
00094   (*_hbsyrun)->GetXaxis()->SetTitle("Y [cm]");   (*_hbsyrun)->GetYaxis()->SetTitle("Events"); 
00095   (*_hbszrun)->GetXaxis()->SetTitle("Z [cm]");   (*_hbszrun)->GetYaxis()->SetTitle("Events"); 
00096   (*_hbssigmaxrun)->GetXaxis()->SetTitle("sigmaX [cm]");   (*_hbssigmaxrun)->GetYaxis()->SetTitle("Events"); 
00097   (*_hbssigmayrun)->GetXaxis()->SetTitle("sigmaY [cm]");   (*_hbssigmayrun)->GetYaxis()->SetTitle("Events"); 
00098   (*_hbssigmazrun)->GetXaxis()->SetTitle("sigmaZ [cm]");   (*_hbssigmazrun)->GetYaxis()->SetTitle("Events"); 
00099 
00100   (*_hbsxvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbsxvsorbrun)->GetYaxis()->SetTitle("X [cm]"); 
00101   (*_hbsxvsorbrun)->SetBit(TH1::kCanRebin);
00102   (*_hbsyvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbsyvsorbrun)->GetYaxis()->SetTitle("Y [cm]"); 
00103   (*_hbsyvsorbrun)->SetBit(TH1::kCanRebin);
00104   (*_hbszvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbszvsorbrun)->GetYaxis()->SetTitle("Z [cm]"); 
00105   (*_hbszvsorbrun)->SetBit(TH1::kCanRebin);
00106   (*_hbssigmaxvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbssigmaxvsorbrun)->GetYaxis()->SetTitle("sigmaX [cm]"); 
00107   (*_hbssigmaxvsorbrun)->SetBit(TH1::kCanRebin);
00108   (*_hbssigmayvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbssigmayvsorbrun)->GetYaxis()->SetTitle("sigmaY [cm]"); 
00109   (*_hbssigmayvsorbrun)->SetBit(TH1::kCanRebin);
00110   (*_hbssigmazvsorbrun)->GetXaxis()->SetTitle("time [orbit#]");   (*_hbssigmazvsorbrun)->GetYaxis()->SetTitle("sigmaZ [cm]"); 
00111   (*_hbssigmazvsorbrun)->SetBit(TH1::kCanRebin);
00112 
00113   
00114 }
00115 
00116 void BeamSpotHistogramMaker::fill(const unsigned int orbit, const reco::BeamSpot& bs) {
00117   
00118   if(_hbsxrun && *_hbsxrun )  (*_hbsxrun)->Fill(bs.x0());
00119   if(_hbsxvsorbrun && *_hbsxvsorbrun )  (*_hbsxvsorbrun)->Fill(orbit,bs.x0());
00120   
00121   if(_hbsyrun && *_hbsyrun )  (*_hbsyrun)->Fill(bs.y0());
00122   if(_hbsyvsorbrun && *_hbsyvsorbrun )  (*_hbsyvsorbrun)->Fill(orbit,bs.y0());
00123   
00124   if(_hbszrun && *_hbszrun )  (*_hbszrun)->Fill(bs.z0());
00125   if(_hbszvsorbrun && *_hbszvsorbrun )  (*_hbszvsorbrun)->Fill(orbit,bs.z0());
00126   
00127   if(_hbssigmaxrun && *_hbssigmaxrun )  (*_hbssigmaxrun)->Fill(bs.BeamWidthX());
00128   if(_hbssigmayrun && *_hbssigmayrun )  (*_hbssigmayrun)->Fill(bs.BeamWidthY());
00129   if(_hbssigmazrun && *_hbssigmazrun )  (*_hbssigmazrun)->Fill(bs.sigmaZ());
00130   if(_hbssigmaxvsorbrun && *_hbssigmaxvsorbrun )  (*_hbssigmaxvsorbrun)->Fill(orbit,bs.BeamWidthX());
00131   if(_hbssigmayvsorbrun && *_hbssigmayvsorbrun )  (*_hbssigmayvsorbrun)->Fill(orbit,bs.BeamWidthY());
00132   if(_hbssigmazvsorbrun && *_hbssigmazvsorbrun )  (*_hbssigmazvsorbrun)->Fill(orbit,bs.sigmaZ());
00133   
00134 }
00135