CMS 3D CMS Logo

L1TZDCAnalyzer.cc
Go to the documentation of this file.
1 //Copied from L1TStage2CaloAnalyzer on 2023.08.04 as it exists in CMSSW_13_1_0_pre4
2 //Modified by Chris McGinn to instead work for just ZDC etSums
3 //Contact at christopher.mc.ginn@cern.ch or cfmcginn @ github for bugs
4 
8 
10 
13 
16 
23 
24 //For the output
25 #include "TTree.h"
26 //string for some branch handling
27 #include <string>
28 
29 //
30 // class declaration
31 //
32 
33 namespace l1t {
34 
35  class L1TZDCAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
36  public:
37  explicit L1TZDCAnalyzer(const edm::ParameterSet&);
38  ~L1TZDCAnalyzer() override = default;
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43  void beginJob() override;
44  void analyze(const edm::Event&, const edm::EventSetup&) override;
45  void endJob() override;
46 
47  //fileservice
49  //Declare a tree, member and pointer
50  TTree* etSumZdcTree_;
51  //Declare the etSum max and bpx max
52  //MAX Here is effectively a hardcoded number - you just need to know it from the producer - realistically this is best handled by something passed but for now (2023.08.17) we hardcode
53  static const int maxBPX_ = 5;
56 
57  // ----------member data ---------------------------
59 
60  bool doHistos_;
61 
63  };
64 
65  //
66  // constants, enums and typedefs
67  //
68 
69  //
70  // static data member definitions
71  //
72 
73  //
74  // constructors and destructor
75  //
77  : doHistos_(iConfig.getUntrackedParameter<bool>("doHistos", true)) {
78  usesResource(TFileService::kSharedResource);
79  //now do what ever initialization is needed
80 
81  // register what you consume and keep token for later access:
82  edm::InputTag nullTag("None");
83 
84  edm::InputTag sumTag = iConfig.getParameter<edm::InputTag>("etSumTag");
85  sumToken_ = consumes<l1t::EtSumBxCollection>(sumTag);
86 
87  edm::LogInfo("L1TZDCAnalyzer") << "Processing " << sumTag.label() << std::endl;
88  }
89 
90  //
91  // member functions
92  //
93 
94  // ------------ method called for each event ------------
96  using namespace edm;
97 
98  // Handle<EtSumBxCollection> sums;
100  iEvent.getByToken(sumToken_, sums);
101 
102  int startBX = sums->getFirstBX();
103 
104  for (int ibx = startBX; ibx <= sums->getLastBX(); ++ibx) {
105  for (auto itr = sums->begin(ibx); itr != sums->end(ibx); ++itr) {
106  if (itr->getType() == l1t::EtSum::EtSumType::kZDCP)
107  etSumZdcP_[ibx - startBX] = itr->hwPt();
108  if (itr->getType() == l1t::EtSum::EtSumType::kZDCM)
109  etSumZdcM_[ibx - startBX] = itr->hwPt();
110  }
111  }
112 
113  etSumZdcTree_->Fill();
114  }
115 
116  // ------------ method called once each job just before starting event loop ------------
118  etSumZdcTree_ = fs_->make<TTree>("etSumZdcTree", "");
119  etSumZdcTree_->Branch("etSumZdcP", etSumZdcP_, ("etSumZdcP[" + std::to_string(maxBPX_) + "]/F").c_str());
120  etSumZdcTree_->Branch("etSumZdcM", etSumZdcM_, ("etSumZdcM[" + std::to_string(maxBPX_) + "]/F").c_str());
121  }
122 
123  // ------------ method called once each job just after ending the event loop ------------
125 
126  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
129 
130  desc.add<edm::InputTag>("etSumTag", edm::InputTag("l1tZDCEtSums", ""));
131  descriptions.add("l1tZDCAnalyzer", desc);
132  }
133 
134 } // namespace l1t
135 
136 using namespace l1t;
137 
138 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~L1TZDCAnalyzer() override=default
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const int maxBPX_
edm::Service< TFileService > fs_
float etSumZdcM_[maxBPX_]
delete x;
Definition: CaloConfig.h:22
edm::EDGetToken sumToken_
std::string const & label() const
Definition: InputTag.h:36
static std::string to_string(const XMLCh *ch)
int iEvent
Definition: GenABIO.cc:224
L1TZDCAnalyzer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TFileDirectory evtDispDir_
float etSumZdcP_[maxBPX_]
void beginJob() override
Log< level::Info, false > LogInfo
void endJob() override
void analyze(const edm::Event &, const edm::EventSetup &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64