Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:18:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    CentralityBinProducer
0004 // Class:      CentralityBinProducer
0005 //
0006 /**\class CentralityBinProducer CentralityBinProducer.cc RecoHI/CentralityBinProducer/src/CentralityBinProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Yetkin Yilmaz
0015 //         Created:  Thu Aug 12 05:34:11 EDT 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/Run.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 
0032 #include "FWCore/Utilities/interface/InputTag.h"
0033 
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 
0036 #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
0037 #include "CondFormats/HIObjects/interface/CentralityTable.h"
0038 #include "CondFormats/DataRecord/interface/HeavyIonRcd.h"
0039 #include "FWCore/Framework/interface/ESHandle.h"
0040 #include "FWCore/Framework/interface/ConsumesCollector.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 class CentralityBinProducer : public edm::stream::EDProducer<> {
0047   enum VariableType {
0048     HFtowers = 0,
0049     HFtowersPlus = 1,
0050     HFtowersMinus = 2,
0051     HFtowersTrunc = 3,
0052     HFtowersPlusTrunc = 4,
0053     HFtowersMinusTrunc = 5,
0054     HFhits = 6,
0055     PixelHits = 7,
0056     PixelTracks = 8,
0057     Tracks = 9,
0058     EB = 10,
0059     EE = 11,
0060     ZDChitsPlus = 12,
0061     ZDChitsMinus = 13,
0062     Missing = 14
0063   };
0064 
0065 public:
0066   explicit CentralityBinProducer(const edm::ParameterSet&);
0067   ~CentralityBinProducer() override;
0068 
0069 private:
0070   void beginRun(edm::Run const& run, const edm::EventSetup& iSetup) override;
0071   void produce(edm::Event&, const edm::EventSetup&) override;
0072 
0073   // ----------member data ---------------------------
0074 
0075   edm::Handle<reco::Centrality> chandle_;
0076   edm::EDGetTokenT<reco::Centrality> tag_;
0077   edm::ESHandle<CentralityTable> inputDB_;
0078   edm::ESGetToken<CentralityTable, HeavyIonRcd> inputDBToken_;
0079 
0080   std::string centralityVariable_;
0081   std::string centralityLabel_;
0082   std::string centralityMC_;
0083   unsigned int prevRun_;
0084 
0085   VariableType varType_;
0086   unsigned int pPbRunFlip_;
0087 };
0088 
0089 //
0090 // constants, enums and typedefs
0091 //
0092 
0093 //
0094 // static data member definitions
0095 //
0096 
0097 //
0098 // constructors and destructor
0099 //
0100 CentralityBinProducer::CentralityBinProducer(const edm::ParameterSet& iConfig) : prevRun_(0), varType_(Missing) {
0101   using namespace edm;
0102   tag_ = consumes<reco::Centrality>(iConfig.getParameter<edm::InputTag>("Centrality"));
0103   centralityVariable_ = iConfig.getParameter<std::string>("centralityVariable");
0104   pPbRunFlip_ = iConfig.getParameter<unsigned int>("pPbRunFlip");
0105 
0106   if (centralityVariable_ == "HFtowers")
0107     varType_ = HFtowers;
0108   if (centralityVariable_ == "HFtowersPlus")
0109     varType_ = HFtowersPlus;
0110   if (centralityVariable_ == "HFtowersMinus")
0111     varType_ = HFtowersMinus;
0112   if (centralityVariable_ == "HFtowersTrunc")
0113     varType_ = HFtowersTrunc;
0114   if (centralityVariable_ == "HFtowersPlusTrunc")
0115     varType_ = HFtowersPlusTrunc;
0116   if (centralityVariable_ == "HFtowersMinusTrunc")
0117     varType_ = HFtowersMinusTrunc;
0118   if (centralityVariable_ == "HFhits")
0119     varType_ = HFhits;
0120   if (centralityVariable_ == "PixelHits")
0121     varType_ = PixelHits;
0122   if (centralityVariable_ == "PixelTracks")
0123     varType_ = PixelTracks;
0124   if (centralityVariable_ == "Tracks")
0125     varType_ = Tracks;
0126   if (centralityVariable_ == "EB")
0127     varType_ = EB;
0128   if (centralityVariable_ == "EE")
0129     varType_ = EE;
0130   if (centralityVariable_ == "ZDChitsPlus")
0131     varType_ = ZDChitsPlus;
0132   if (centralityVariable_ == "ZDChitsMinus")
0133     varType_ = ZDChitsMinus;
0134   if (varType_ == Missing) {
0135     std::string errorMessage = "Requested Centrality variable does not exist : " + centralityVariable_ + "\n" +
0136                                "Supported variables are: \n" +
0137                                "HFtowers HFtowersPlus HFtowersMinus HFtowersTrunc HFtowersPlusTrunc HFtowersMinusTrunc "
0138                                "HFhits PixelHits PixelTracks Tracks EB EE" +
0139                                "\n";
0140     throw cms::Exception("Configuration", errorMessage);
0141   }
0142 
0143   if (iConfig.exists("nonDefaultGlauberModel")) {
0144     centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
0145   }
0146   centralityLabel_ = centralityVariable_ + centralityMC_;
0147   inputDBToken_ =
0148       esConsumes<CentralityTable, HeavyIonRcd, edm::Transition::BeginRun>(edm::ESInputTag("", centralityLabel_));
0149 
0150   produces<int>(centralityVariable_);
0151 }
0152 
0153 CentralityBinProducer::~CentralityBinProducer() {
0154   // do anything here that needs to be done at desctruction time
0155   // (e.g. close files, deallocate resources etc.)
0156 }
0157 
0158 //
0159 // member functions
0160 //
0161 
0162 // ------------ method called to produce the data  ------------
0163 void CentralityBinProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0164   iEvent.getByToken(tag_, chandle_);
0165 
0166   double value = 0;
0167   switch (varType_) {
0168     case HFtowers:
0169       value = chandle_->EtHFtowerSum();
0170       break;
0171     case HFtowersPlus:
0172       value = chandle_->EtHFtowerSumPlus();
0173       break;
0174     case HFtowersMinus:
0175       value = chandle_->EtHFtowerSumMinus();
0176       break;
0177     case HFhits:
0178       value = chandle_->EtHFhitSum();
0179       break;
0180     case HFtowersTrunc:
0181       value = chandle_->EtHFtruncated();
0182       break;
0183     case HFtowersPlusTrunc:
0184       value = chandle_->EtHFtruncatedPlus();
0185       break;
0186     case HFtowersMinusTrunc:
0187       value = chandle_->EtHFtruncatedMinus();
0188       break;
0189     case PixelHits:
0190       value = chandle_->multiplicityPixel();
0191       break;
0192     case PixelTracks:
0193       value = chandle_->NpixelTracks();
0194       break;
0195     case Tracks:
0196       value = chandle_->Ntracks();
0197       break;
0198     case EB:
0199       value = chandle_->EtEBSum();
0200       break;
0201     case EE:
0202       value = chandle_->EtEESum();
0203       break;
0204     case ZDChitsPlus:
0205       value = chandle_->zdcSumPlus();
0206       break;
0207     case ZDChitsMinus:
0208       value = chandle_->zdcSumMinus();
0209       break;
0210     default:
0211       throw cms::Exception("CentralityBinProducer", "Centrality variable not recognized.");
0212   }
0213 
0214   int bin = inputDB_->m_table.size() - 1;
0215   for (unsigned int i = 0; i < inputDB_->m_table.size(); ++i) {
0216     if (value >= inputDB_->m_table[i].bin_edge && value) {
0217       bin = i;
0218       break;
0219     }
0220   }
0221 
0222   iEvent.put(std::make_unique<int>(bin), centralityVariable_);
0223 }
0224 
0225 void CentralityBinProducer::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
0226   if (prevRun_ < pPbRunFlip_ && iRun.run() >= pPbRunFlip_) {
0227     if (centralityVariable_ == "HFtowersPlus")
0228       varType_ = HFtowersMinus;
0229     if (centralityVariable_ == "HFtowersMinus")
0230       varType_ = HFtowersPlus;
0231     if (centralityVariable_ == "HFtowersPlusTrunc")
0232       varType_ = HFtowersMinusTrunc;
0233     if (centralityVariable_ == "HFtowersMinusTrunc")
0234       varType_ = HFtowersPlusTrunc;
0235     if (centralityVariable_ == "ZDChitsPlus")
0236       varType_ = ZDChitsMinus;
0237     if (centralityVariable_ == "ZDChitsMinus")
0238       varType_ = ZDChitsPlus;
0239   }
0240   prevRun_ = iRun.run();
0241 
0242   inputDB_ = iSetup.getHandle(inputDBToken_);
0243 }
0244 
0245 //define this as a plug-in
0246 DEFINE_FWK_MODULE(CentralityBinProducer);