CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CentralityBinProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CentralityBinProducer
4 // Class: CentralityBinProducer
5 //
13 //
14 // Original Author: Yetkin Yilmaz
15 // Created: Thu Aug 12 05:34:11 EDT 2010
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <string>
22 
23 // user include files
26 
31 
33 
35 
41 
42 //
43 // class declaration
44 //
45 
47  enum VariableType {
48  HFtowers = 0,
54  HFhits = 6,
55  PixelHits = 7,
57  Tracks = 9,
58  EB = 10,
59  EE = 11,
62  Missing = 14
63  };
64 
65 public:
67  ~CentralityBinProducer() override;
68 
69 private:
70  void beginRun(edm::Run const& run, const edm::EventSetup& iSetup) override;
71  void produce(edm::Event&, const edm::EventSetup&) override;
72 
73  // ----------member data ---------------------------
74 
79 
83  unsigned int prevRun_;
84 
86  unsigned int pPbRunFlip_;
87 };
88 
89 //
90 // constants, enums and typedefs
91 //
92 
93 //
94 // static data member definitions
95 //
96 
97 //
98 // constructors and destructor
99 //
101  using namespace edm;
102  tag_ = consumes<reco::Centrality>(iConfig.getParameter<edm::InputTag>("Centrality"));
103  centralityVariable_ = iConfig.getParameter<std::string>("centralityVariable");
104  pPbRunFlip_ = iConfig.getParameter<unsigned int>("pPbRunFlip");
105 
106  if (centralityVariable_ == "HFtowers")
107  varType_ = HFtowers;
108  if (centralityVariable_ == "HFtowersPlus")
110  if (centralityVariable_ == "HFtowersMinus")
112  if (centralityVariable_ == "HFtowersTrunc")
114  if (centralityVariable_ == "HFtowersPlusTrunc")
116  if (centralityVariable_ == "HFtowersMinusTrunc")
118  if (centralityVariable_ == "HFhits")
119  varType_ = HFhits;
120  if (centralityVariable_ == "PixelHits")
122  if (centralityVariable_ == "PixelTracks")
124  if (centralityVariable_ == "Tracks")
125  varType_ = Tracks;
126  if (centralityVariable_ == "EB")
127  varType_ = EB;
128  if (centralityVariable_ == "EE")
129  varType_ = EE;
130  if (centralityVariable_ == "ZDChitsPlus")
132  if (centralityVariable_ == "ZDChitsMinus")
134  if (varType_ == Missing) {
135  std::string errorMessage = "Requested Centrality variable does not exist : " + centralityVariable_ + "\n" +
136  "Supported variables are: \n" +
137  "HFtowers HFtowersPlus HFtowersMinus HFtowersTrunc HFtowersPlusTrunc HFtowersMinusTrunc "
138  "HFhits PixelHits PixelTracks Tracks EB EE" +
139  "\n";
140  throw cms::Exception("Configuration", errorMessage);
141  }
142 
143  if (iConfig.exists("nonDefaultGlauberModel")) {
144  centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
145  }
147  inputDBToken_ =
148  esConsumes<CentralityTable, HeavyIonRcd, edm::Transition::BeginRun>(edm::ESInputTag("", centralityLabel_));
149 
150  produces<int>(centralityVariable_);
151 }
152 
154  // do anything here that needs to be done at desctruction time
155  // (e.g. close files, deallocate resources etc.)
156 }
157 
158 //
159 // member functions
160 //
161 
162 // ------------ method called to produce the data ------------
164  iEvent.getByToken(tag_, chandle_);
165 
166  double value = 0;
167  switch (varType_) {
168  case HFtowers:
169  value = chandle_->EtHFtowerSum();
170  break;
171  case HFtowersPlus:
172  value = chandle_->EtHFtowerSumPlus();
173  break;
174  case HFtowersMinus:
175  value = chandle_->EtHFtowerSumMinus();
176  break;
177  case HFhits:
178  value = chandle_->EtHFhitSum();
179  break;
180  case HFtowersTrunc:
181  value = chandle_->EtHFtruncated();
182  break;
183  case HFtowersPlusTrunc:
184  value = chandle_->EtHFtruncatedPlus();
185  break;
186  case HFtowersMinusTrunc:
187  value = chandle_->EtHFtruncatedMinus();
188  break;
189  case PixelHits:
190  value = chandle_->multiplicityPixel();
191  break;
192  case PixelTracks:
193  value = chandle_->NpixelTracks();
194  break;
195  case Tracks:
196  value = chandle_->Ntracks();
197  break;
198  case EB:
199  value = chandle_->EtEBSum();
200  break;
201  case EE:
202  value = chandle_->EtEESum();
203  break;
204  case ZDChitsPlus:
205  value = chandle_->zdcSumPlus();
206  break;
207  case ZDChitsMinus:
208  value = chandle_->zdcSumMinus();
209  break;
210  default:
211  throw cms::Exception("CentralityBinProducer", "Centrality variable not recognized.");
212  }
213 
214  int bin = inputDB_->m_table.size() - 1;
215  for (unsigned int i = 0; i < inputDB_->m_table.size(); ++i) {
216  if (value >= inputDB_->m_table[i].bin_edge && value) {
217  bin = i;
218  break;
219  }
220  }
221 
222  iEvent.put(std::make_unique<int>(bin), centralityVariable_);
223 }
224 
225 void CentralityBinProducer::beginRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {
226  if (prevRun_ < pPbRunFlip_ && iRun.run() >= pPbRunFlip_) {
227  if (centralityVariable_ == "HFtowersPlus")
229  if (centralityVariable_ == "HFtowersMinus")
231  if (centralityVariable_ == "HFtowersPlusTrunc")
233  if (centralityVariable_ == "HFtowersMinusTrunc")
235  if (centralityVariable_ == "ZDChitsPlus")
237  if (centralityVariable_ == "ZDChitsMinus")
239  }
240  prevRun_ = iRun.run();
241 
242  inputDB_ = iSetup.getHandle(inputDBToken_);
243 }
244 
245 //define this as a plug-in
edm::ESGetToken< CentralityTable, HeavyIonRcd > inputDBToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
RunNumber_t run() const
Definition: RunBase.h:40
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool exists(std::string const &parameterName) const
checks if a parameter exists
CentralityBinProducer(const edm::ParameterSet &)
edm::ESHandle< CentralityTable > inputDB_
int iEvent
Definition: GenABIO.cc:224
void beginRun(edm::Run const &run, const edm::EventSetup &iSetup) override
edm::Handle< reco::Centrality > chandle_
void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::Centrality > tag_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Definition: Run.h:45