File indexing completed on 2024-04-06 12:25:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <string>
0022
0023
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
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 PFhf = 14,
0063 PFhfPlus = 15,
0064 PFhfMinus = 16,
0065 Missing = 17
0066 };
0067
0068 public:
0069 explicit CentralityBinProducer(const edm::ParameterSet&);
0070 ~CentralityBinProducer() override;
0071
0072 private:
0073 void beginRun(edm::Run const& run, const edm::EventSetup& iSetup) override;
0074 void produce(edm::Event&, const edm::EventSetup&) override;
0075
0076
0077
0078 edm::Handle<reco::Centrality> chandle_;
0079 edm::EDGetTokenT<reco::Centrality> tag_;
0080 edm::ESHandle<CentralityTable> inputDB_;
0081 edm::ESGetToken<CentralityTable, HeavyIonRcd> inputDBToken_;
0082
0083 std::string centralityVariable_;
0084 std::string centralityLabel_;
0085 std::string centralityMC_;
0086 unsigned int prevRun_;
0087
0088 VariableType varType_;
0089 unsigned int pPbRunFlip_;
0090 };
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 CentralityBinProducer::CentralityBinProducer(const edm::ParameterSet& iConfig) : prevRun_(0), varType_(Missing) {
0104 using namespace edm;
0105 tag_ = consumes<reco::Centrality>(iConfig.getParameter<edm::InputTag>("Centrality"));
0106 centralityVariable_ = iConfig.getParameter<std::string>("centralityVariable");
0107 pPbRunFlip_ = iConfig.getParameter<unsigned int>("pPbRunFlip");
0108
0109 if (centralityVariable_ == "HFtowers")
0110 varType_ = HFtowers;
0111 if (centralityVariable_ == "HFtowersPlus")
0112 varType_ = HFtowersPlus;
0113 if (centralityVariable_ == "HFtowersMinus")
0114 varType_ = HFtowersMinus;
0115 if (centralityVariable_ == "HFtowersTrunc")
0116 varType_ = HFtowersTrunc;
0117 if (centralityVariable_ == "HFtowersPlusTrunc")
0118 varType_ = HFtowersPlusTrunc;
0119 if (centralityVariable_ == "HFtowersMinusTrunc")
0120 varType_ = HFtowersMinusTrunc;
0121 if (centralityVariable_ == "HFhits")
0122 varType_ = HFhits;
0123 if (centralityVariable_ == "PixelHits")
0124 varType_ = PixelHits;
0125 if (centralityVariable_ == "PixelTracks")
0126 varType_ = PixelTracks;
0127 if (centralityVariable_ == "Tracks")
0128 varType_ = Tracks;
0129 if (centralityVariable_ == "EB")
0130 varType_ = EB;
0131 if (centralityVariable_ == "EE")
0132 varType_ = EE;
0133 if (centralityVariable_ == "ZDChitsPlus")
0134 varType_ = ZDChitsPlus;
0135 if (centralityVariable_ == "ZDChitsMinus")
0136 varType_ = ZDChitsMinus;
0137 if (centralityVariable_ == "PFhf")
0138 varType_ = PFhf;
0139 if (centralityVariable_ == "PFhfPlus")
0140 varType_ = PFhfPlus;
0141 if (centralityVariable_ == "PFhfMinus")
0142 varType_ = PFhfMinus;
0143 if (varType_ == Missing) {
0144 std::string errorMessage =
0145 "Requested Centrality variable does not exist : " + centralityVariable_ + "\n" + "Supported variables are: \n" +
0146 "HFtowers HFtowersPlus HFtowersMinus HFtowersTrunc HFtowersPlusTrunc HFtowersMinusTrunc "
0147 "HFhits PixelHits PixelTracks Tracks EB EE ZDChitsPlus ZDChitsMinus PFhf PFhfPlus PFhfMinus" +
0148 "\n";
0149 throw cms::Exception("Configuration", errorMessage);
0150 }
0151
0152 if (iConfig.exists("nonDefaultGlauberModel")) {
0153 centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
0154 }
0155 centralityLabel_ = centralityVariable_ + centralityMC_;
0156 inputDBToken_ =
0157 esConsumes<CentralityTable, HeavyIonRcd, edm::Transition::BeginRun>(edm::ESInputTag("", centralityLabel_));
0158
0159 produces<int>(centralityVariable_);
0160 }
0161
0162 CentralityBinProducer::~CentralityBinProducer() {
0163
0164
0165 }
0166
0167
0168
0169
0170
0171
0172 void CentralityBinProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0173 iEvent.getByToken(tag_, chandle_);
0174
0175 double value = 0;
0176 switch (varType_) {
0177 case HFtowers:
0178 value = chandle_->EtHFtowerSum();
0179 break;
0180 case HFtowersPlus:
0181 value = chandle_->EtHFtowerSumPlus();
0182 break;
0183 case HFtowersMinus:
0184 value = chandle_->EtHFtowerSumMinus();
0185 break;
0186 case HFhits:
0187 value = chandle_->EtHFhitSum();
0188 break;
0189 case HFtowersTrunc:
0190 value = chandle_->EtHFtruncated();
0191 break;
0192 case HFtowersPlusTrunc:
0193 value = chandle_->EtHFtruncatedPlus();
0194 break;
0195 case HFtowersMinusTrunc:
0196 value = chandle_->EtHFtruncatedMinus();
0197 break;
0198 case PixelHits:
0199 value = chandle_->multiplicityPixel();
0200 break;
0201 case PixelTracks:
0202 value = chandle_->NpixelTracks();
0203 break;
0204 case Tracks:
0205 value = chandle_->Ntracks();
0206 break;
0207 case EB:
0208 value = chandle_->EtEBSum();
0209 break;
0210 case EE:
0211 value = chandle_->EtEESum();
0212 break;
0213 case ZDChitsPlus:
0214 value = chandle_->zdcSumPlus();
0215 break;
0216 case ZDChitsMinus:
0217 value = chandle_->zdcSumMinus();
0218 break;
0219 case PFhf:
0220 value = chandle_->EtPFhfSum();
0221 break;
0222 case PFhfPlus:
0223 value = chandle_->EtPFhfSumPlus();
0224 break;
0225 case PFhfMinus:
0226 value = chandle_->EtPFhfSumMinus();
0227 break;
0228 default:
0229 throw cms::Exception("CentralityBinProducer", "Centrality variable not recognized.");
0230 }
0231
0232 int bin = inputDB_->m_table.size() - 1;
0233 for (unsigned int i = 0; i < inputDB_->m_table.size(); ++i) {
0234 if (value >= inputDB_->m_table[i].bin_edge && value) {
0235 bin = i;
0236 break;
0237 }
0238 }
0239
0240 iEvent.put(std::make_unique<int>(bin), centralityVariable_);
0241 }
0242
0243 void CentralityBinProducer::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
0244 if (prevRun_ < pPbRunFlip_ && iRun.run() >= pPbRunFlip_) {
0245 if (centralityVariable_ == "HFtowersPlus")
0246 varType_ = HFtowersMinus;
0247 if (centralityVariable_ == "HFtowersMinus")
0248 varType_ = HFtowersPlus;
0249 if (centralityVariable_ == "HFtowersPlusTrunc")
0250 varType_ = HFtowersMinusTrunc;
0251 if (centralityVariable_ == "HFtowersMinusTrunc")
0252 varType_ = HFtowersPlusTrunc;
0253 if (centralityVariable_ == "ZDChitsPlus")
0254 varType_ = ZDChitsMinus;
0255 if (centralityVariable_ == "ZDChitsMinus")
0256 varType_ = ZDChitsPlus;
0257 if (centralityVariable_ == "PFhfPlus")
0258 varType_ = PFhfMinus;
0259 if (centralityVariable_ == "PFhfMinus")
0260 varType_ = PFhfPlus;
0261 }
0262 prevRun_ = iRun.run();
0263
0264 inputDB_ = iSetup.getHandle(inputDBToken_);
0265 }
0266
0267
0268 DEFINE_FWK_MODULE(CentralityBinProducer);