Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-05 23:13:12

0001 // -*- C++ -*-
0002 //
0003 // Package:    TPGCheck
0004 // Class:      TPGCheck
0005 //
0006 /**\class TPGCheck TPGCheck.cc Validation/TPGSimulation/src/TPGCheck.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Muriel Cerutti
0015 //         Created:  Thu Oct 26 10:47:17 CEST 2006
0016 //
0017 
0018 // system include files
0019 #include <memory>
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include <string>
0032 #include <vector>
0033 
0034 #include "TFile.h"
0035 #include "TH1I.h"
0036 
0037 using namespace edm;
0038 using namespace std;
0039 
0040 //
0041 // class declaration
0042 //
0043 
0044 class TPGCheck : public edm::one::EDAnalyzer<> {
0045 public:
0046   explicit TPGCheck(const edm::ParameterSet &);
0047   ~TPGCheck() override;
0048 
0049 private:
0050   void beginJob() override;
0051   void analyze(const edm::Event &, const edm::EventSetup &) override;
0052   void endJob() override;
0053 
0054   // ----------member data ---------------------------
0055   TH1I *ecal_et_[2];
0056   TH1I *ecal_tt_[2];
0057   TH1I *ecal_fgvb_[2];
0058 
0059   TFile *histFile_;
0060   std::string label_;
0061   std::string producer_;
0062   std::vector<std::string> ecal_parts_;
0063   // fix for consumes
0064   edm::EDGetTokenT<EcalTrigPrimDigiCollection> ecal_tp_token_;
0065 };
0066 
0067 //
0068 // constructors and destructor
0069 //
0070 TPGCheck::TPGCheck(const edm::ParameterSet &iConfig) {
0071   // now do what ever initialization is needed
0072 
0073   ecal_parts_.push_back("Barrel");
0074   ecal_parts_.push_back("Endcap");
0075 
0076   histFile_ = new TFile("histos.root", "RECREATE");
0077   for (unsigned int i = 0; i < 2; ++i) {
0078     // Energy
0079     char t[30];
0080     sprintf(t, "%s_energy", ecal_parts_[i].c_str());
0081     ecal_et_[i] = new TH1I(t, "Et", 255, 0, 255);
0082 
0083     // Trigger Tower flag
0084     char titleTTF[30];
0085     sprintf(titleTTF, "%s_ttf", ecal_parts_[i].c_str());
0086     ecal_tt_[i] = new TH1I(titleTTF, "TTF", 10, 0, 10);
0087 
0088     // Fain Grain
0089     char titleFG[30];
0090     sprintf(titleFG, "%s_fgvb", ecal_parts_[i].c_str());
0091     ecal_fgvb_[i] = new TH1I(titleFG, "FGVB", 10, 0, 10);
0092   }
0093 
0094   label_ = iConfig.getParameter<std::string>("Label");
0095   producer_ = iConfig.getParameter<std::string>("Producer");
0096   ecal_tp_token_ = consumes<EcalTrigPrimDigiCollection>(edm::InputTag(label_, producer_));
0097 }
0098 
0099 TPGCheck::~TPGCheck() {
0100   // do anything here that needs to be done at desctruction time
0101   // (e.g. close files, deallocate resources etc.)
0102 
0103   histFile_->Write();
0104   histFile_->Close();
0105 }
0106 
0107 //
0108 // member functions
0109 //
0110 
0111 // ------------ method called to for each event  ------------
0112 void TPGCheck::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0113   // Get input
0114   edm::Handle<EcalTrigPrimDigiCollection> tp;
0115   iEvent.getByToken(ecal_tp_token_, tp);
0116   for (unsigned int i = 0; i < tp.product()->size(); i++) {
0117     EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
0118     int subdet = d.id().subDet() - 1;
0119     // for endcap, regroup double TP-s that are generated for the 2 interior
0120     // rings
0121     if (subdet == 0) {
0122       ecal_et_[subdet]->Fill(d.compressedEt());
0123     } else {
0124       if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
0125         if (i % 2)
0126           ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
0127       } else
0128         ecal_et_[subdet]->Fill(d.compressedEt());
0129     }
0130     ecal_tt_[subdet]->Fill(d.ttFlag());
0131     ecal_fgvb_[subdet]->Fill(d.fineGrain());
0132   }
0133 }
0134 
0135 // ------------ method called once each job just before starting event loop
0136 // ------------
0137 void TPGCheck::beginJob() {}
0138 
0139 // ------------ method called once each job just after ending the event loop
0140 // ------------
0141 void TPGCheck::endJob() {
0142   for (unsigned int i = 0; i < 2; ++i) {
0143     ecal_et_[i]->Write();
0144     ecal_tt_[i]->Write();
0145     ecal_fgvb_[i]->Write();
0146   }
0147 }
0148 
0149 // define this as a plug-in
0150 DEFINE_FWK_MODULE(TPGCheck);