CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Validation/EcalTriggerPrimitives/src/TPGCheck.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TPGCheck
00004 // Class:      TPGCheck
00005 // 
00013 //
00014 // Original Author:  Muriel Cerutti
00015 //         Created:  Thu Oct 26 10:47:17 CEST 2006
00016 // $Id: TPGCheck.cc,v 1.3 2009/12/18 20:45:11 wmtan Exp $
00017 // $Id: TPGCheck.cc,v 1.3 2009/12/18 20:45:11 wmtan Exp $
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00033 
00034 #include <vector>
00035 #include <string>
00036 
00037 #include "TH1I.h"
00038 #include "TFile.h"
00039 
00040 using namespace edm;
00041 using namespace std;
00042 
00043 //
00044 // class declaration
00045 //
00046 
00047 class TPGCheck : public edm::EDAnalyzer {
00048    public:
00049       explicit TPGCheck(const edm::ParameterSet&);
00050       ~TPGCheck();
00051 
00052 
00053    private:
00054       virtual void beginJob() ;
00055       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00056       virtual void endJob() ;
00057 
00058       // ----------member data ---------------------------
00059       TH1I *ecal_et_[2];
00060       TH1I *ecal_tt_[2];
00061       TH1I * ecal_fgvb_[2];
00062       
00063       TFile *histFile_;
00064       std::string label_;
00065       std::string producer_;
00066       std::vector<std::string> ecal_parts_;
00067 };
00068 
00069 //
00070 // constructors and destructor
00071 //
00072 TPGCheck::TPGCheck(const edm::ParameterSet& iConfig)
00073 {
00074    //now do what ever initialization is needed
00075    
00076   ecal_parts_.push_back("Barrel");
00077   ecal_parts_.push_back("Endcap");
00078 
00079   histFile_=new TFile("histos.root","RECREATE");
00080   for (unsigned int i=0;i<2;++i) {
00081     // Energy
00082     char t[30];
00083     sprintf(t,"%s_energy",ecal_parts_[i].c_str());  
00084     ecal_et_[i]=new TH1I(t,"Et",255,0,255);
00085     
00086     // Trigger Tower flag
00087     char titleTTF[30];
00088     sprintf(titleTTF,"%s_ttf",ecal_parts_[i].c_str());
00089     ecal_tt_[i]=new TH1I(titleTTF,"TTF",10,0,10);
00090     
00091     // Fain Grain
00092     char titleFG[30];
00093     sprintf(titleFG,"%s_fgvb",ecal_parts_[i].c_str());
00094     ecal_fgvb_[i]=new TH1I(titleFG,"FGVB",10,0,10);
00095   }
00096   
00097   label_= iConfig.getParameter<std::string>("Label");
00098   producer_= iConfig.getParameter<std::string>("Producer");
00099   
00100 }
00101 
00102 
00103 TPGCheck::~TPGCheck()
00104 {
00105  
00106    // do anything here that needs to be done at desctruction time
00107    // (e.g. close files, deallocate resources etc.)
00108    
00109    histFile_->Write();
00110    histFile_->Close();
00111 
00112 }
00113 
00114 
00115 //
00116 // member functions
00117 //
00118 
00119 // ------------ method called to for each event  ------------
00120 void
00121 TPGCheck::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00122 {
00123   
00124   // Get input
00125   edm::Handle<EcalTrigPrimDigiCollection> tp;
00126   iEvent.getByLabel(label_,producer_,tp);
00127   for (unsigned int i=0;i<tp.product()->size();i++) {  
00128     EcalTriggerPrimitiveDigi d=(*(tp.product()))[i]; 
00129     int subdet=d.id().subDet()-1;
00130     // for endcap, regroup double TP-s that are generated for the 2 interior rings
00131     if (subdet==0) {
00132       ecal_et_[subdet]->Fill(d.compressedEt());
00133     }
00134     else {
00135       if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) {
00136         if (i%2) ecal_et_[subdet]->Fill(d.compressedEt()*2.);
00137       }
00138       else ecal_et_[subdet]->Fill(d.compressedEt());
00139     }
00140     ecal_tt_[subdet]->Fill(d.ttFlag());
00141     ecal_fgvb_[subdet]->Fill(d.fineGrain());
00142   }
00143 }
00144 
00145 
00146 // ------------ method called once each job just before starting event loop  ------------
00147 void 
00148 TPGCheck::beginJob()
00149 {
00150 }
00151 
00152 // ------------ method called once each job just after ending the event loop  ------------
00153 void 
00154 TPGCheck::endJob() {
00155    for (unsigned int i=0;i<2;++i) {
00156     ecal_et_[i]->Write();
00157     ecal_tt_[i]->Write();
00158     ecal_fgvb_[i]->Write();
00159   }
00160 }
00161 
00162 //define this as a plug-in
00163 DEFINE_FWK_MODULE(TPGCheck);