Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 02:43:02

0001 // system include files
0002 #include <memory>
0003 
0004 // {fmt} headers
0005 #include <fmt/printf.h>
0006 
0007 // ROOT
0008 #include <TTree.h>
0009 
0010 // framework and data formats
0011 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0012 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0013 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0014 #include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 
0024 //
0025 // class declaration
0026 //
0027 
0028 class L1AXOTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0029 public:
0030   explicit L1AXOTreeProducer(edm::ParameterSet const &);
0031   ~L1AXOTreeProducer() override = default;
0032 
0033 private:
0034   void beginJob() override;
0035   void analyze(edm::Event const &, edm::EventSetup const &) override;
0036   void endJob() override;
0037 
0038 private:
0039   // output file
0040   edm::Service<TFileService> fs_;
0041 
0042   // pointers to the objects that will be stored as branches within the tree
0043   float anomaly_score;
0044 
0045   // tree
0046   TTree *tree_;
0047 
0048   // EDM input tokens
0049   const edm::EDGetTokenT<AXOL1TLScoreBxCollection> scoreToken_;
0050 };
0051 
0052 L1AXOTreeProducer::L1AXOTreeProducer(edm::ParameterSet const &config)
0053     : anomaly_score(0.0f),
0054       tree_(nullptr),
0055       scoreToken_(consumes<AXOL1TLScoreBxCollection>(config.getUntrackedParameter<edm::InputTag>("axoscoreToken"))) {
0056   usesResource(TFileService::kSharedResource);
0057   // set up the TTree and its branches
0058   tree_ = fs_->make<TTree>("L1AXOTree", "L1AXOTree");
0059   tree_->Branch("axo_score", &anomaly_score, "axo_score/F");
0060 }
0061 
0062 //
0063 // member functions
0064 //
0065 
0066 // ------------ method called to for each event  ------------
0067 void L1AXOTreeProducer::analyze(edm::Event const &event, edm::EventSetup const &setup) {
0068   //save axo score
0069   edm::Handle<AXOL1TLScoreBxCollection> axo;
0070   event.getByToken(scoreToken_, axo);
0071 
0072   float const *ptr;
0073 
0074   if (axo.isValid()) {
0075     ptr = &axo->at(0, 0).getAXOScore();
0076     anomaly_score = *ptr;
0077 
0078   } else {
0079     edm::LogWarning("MissingProduct") << "AXOL1TLScoreBxCollection not found. Branch will not be filled" << std::endl;
0080   }
0081 
0082   tree_->Fill();
0083 }
0084 
0085 // ------------ method called once each job just before starting event loop  ------------
0086 void L1AXOTreeProducer::beginJob(void) {}
0087 
0088 // ------------ method called once each job just after ending the event loop  ------------
0089 void L1AXOTreeProducer::endJob() {}
0090 
0091 //define this as a plug-in
0092 #include "FWCore/Framework/interface/MakerMacros.h"
0093 DEFINE_FWK_MODULE(L1AXOTreeProducer);