CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTBCalo/EcalTBHodoscopeReconstructor/src/EcalTBHodoscopeRawInfoDumper.cc

Go to the documentation of this file.
00001 #include "RecoTBCalo/EcalTBHodoscopeReconstructor/interface/EcalTBHodoscopeRawInfoDumper.h"
00002 #include "TBDataFormats/EcalTBObjects/interface/EcalTBHodoscopeRawInfo.h"
00003 #include "DataFormats/Common/interface/EDCollection.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 
00008 #include <TFile.h>
00009 #include <FWCore/Framework/interface/MakerMacros.h>
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011     
00012 EcalTBHodoscopeRawInfoDumper::EcalTBHodoscopeRawInfoDumper(edm::ParameterSet const& ps)
00013 {
00014   rawInfoCollection_ = ps.getParameter<std::string>("rawInfoCollection");
00015   rawInfoProducer_   = ps.getParameter<std::string>("rawInfoProducer");
00016   rootfile_          = ps.getUntrackedParameter<std::string>("rootfile","ecalHodoscopeRawInfoPlots.root");
00017 }
00018 
00019 EcalTBHodoscopeRawInfoDumper::~EcalTBHodoscopeRawInfoDumper() {
00020 }
00021 
00022 //========================================================================
00023 void
00024 EcalTBHodoscopeRawInfoDumper::beginJob() {
00025 //========================================================================
00026 
00027   char histoName[100];
00028   char histoTitle[100];
00029   
00030   for (int i=0; i<4; i++)
00031     {
00032       sprintf(histoName,"h_numberOfFiredHits_%d",i);
00033       sprintf(histoTitle,"NumberOfFiredHits Plane %d",i);
00034       h_numberOfFiredHits_[i]=new TH1F(histoName,histoTitle,10,0.,10.);
00035     }
00036 
00037   for (int i=0; i<4; i++)
00038     {
00039       sprintf(histoName,"h_firedHits_%d",i);
00040       sprintf(histoTitle,"firedHits Plane %d",i);
00041       h_firedHits_[i]=new TH1F(histoName,histoTitle,64,-0.5,63.5);
00042     }  
00043 }
00044 
00045 //========================================================================
00046 void
00047 EcalTBHodoscopeRawInfoDumper::endJob() {
00048 //========================================================================
00049 
00050   TFile f(rootfile_.c_str(),"RECREATE");
00051   
00052   for (int i=0; i<4; i++)
00053     h_numberOfFiredHits_[i]->Write();
00054   
00055   for (int i=0; i<4; i++)
00056     h_firedHits_[i]->Write();
00057 
00058   f.Close();
00059 }
00060 
00061 void EcalTBHodoscopeRawInfoDumper::analyze(const edm::Event& e, const edm::EventSetup& es)
00062 {
00063   // Get input
00064    edm::Handle<EcalTBHodoscopeRawInfo> ecalRawHodoscope;  
00065    const EcalTBHodoscopeRawInfo* hodoscopeRawInfo = 0;
00066    //evt.getByLabel( digiProducer_, digiCollection_, pDigis);
00067    e.getByLabel( rawInfoProducer_, ecalRawHodoscope);
00068    if (!ecalRawHodoscope.isValid()) {
00069      edm::LogError("EcalTBHodoscopeRecInfoError") << "Error! can't get the product " << rawInfoCollection_.c_str() ;
00070    } else {
00071      hodoscopeRawInfo = ecalRawHodoscope.product();
00072    }
00073 
00074    if (hodoscopeRawInfo)
00075      for (int i=0; i<4; i++)
00076        {
00077          std::ostringstream str;
00078          str << " Hits " ;
00079          std::vector<int> firedHits;
00080          h_numberOfFiredHits_[i]->Fill((*hodoscopeRawInfo)[i].numberOfFiredHits());
00081          for (int j=0;j<64;j++)
00082            if ((*hodoscopeRawInfo)[i][j])
00083              {
00084                h_firedHits_[i]->Fill(j);
00085                firedHits.push_back(j);
00086                str << j << " " ;
00087              }
00088          LogDebug("EcalTBHodoscope") << "Looking plane " << i << " number of hits " << (*hodoscopeRawInfo)[i].numberOfFiredHits() << str.str();
00089        }
00090   // Create empty output
00091 } 
00092 
00093