test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
20 // system include files
21 #include <memory>
22 #include <string>
23 
24 // user include files
27 
31 
33 
35 
41 
42 
43 //
44 // class declaration
45 //
46 
49  public:
52 
53  private:
54  virtual void beginRun(edm::Run const& run, const edm::EventSetup& iSetup) override;
55  virtual void produce(edm::Event&, const edm::EventSetup&) override;
56 
57  // ----------member data ---------------------------
58 
59 
63 
67  unsigned int prevRun_;
68 
70  unsigned int pPbRunFlip_;
71 
72 };
73 
74 //
75 // constants, enums and typedefs
76 //
77 
78 
79 //
80 // static data member definitions
81 //
82 
83 //
84 // constructors and destructor
85 //
87  prevRun_(0),
88  varType_(Missing)
89 {
90  using namespace edm;
91  tag_ = consumes<reco::Centrality>(iConfig.getParameter<edm::InputTag>("Centrality"));
92  centralityVariable_ = iConfig.getParameter<std::string>("centralityVariable");
93  pPbRunFlip_ = iConfig.getParameter<unsigned int>("pPbRunFlip");
94 
95  if(centralityVariable_.compare("HFtowers") == 0) varType_ = HFtowers;
96  if(centralityVariable_.compare("HFtowersPlus") == 0) varType_ = HFtowersPlus;
97  if(centralityVariable_.compare("HFtowersMinus") == 0) varType_ = HFtowersMinus;
98  if(centralityVariable_.compare("HFtowersTrunc") == 0) varType_ = HFtowersTrunc;
99  if(centralityVariable_.compare("HFtowersPlusTrunc") == 0) varType_ = HFtowersPlusTrunc;
100  if(centralityVariable_.compare("HFtowersMinusTrunc") == 0) varType_ = HFtowersMinusTrunc;
101  if(centralityVariable_.compare("HFhits") == 0) varType_ = HFhits;
102  if(centralityVariable_.compare("PixelHits") == 0) varType_ = PixelHits;
103  if(centralityVariable_.compare("PixelTracks") == 0) varType_ = PixelTracks;
104  if(centralityVariable_.compare("Tracks") == 0) varType_ = Tracks;
105  if(centralityVariable_.compare("EB") == 0) varType_ = EB;
106  if(centralityVariable_.compare("EE") == 0) varType_ = EE;
107  if(centralityVariable_.compare("ZDChitsPlus") == 0) varType_ = ZDChitsPlus;
108  if(centralityVariable_.compare("ZDChitsMinus") == 0) varType_ = ZDChitsMinus;
109  if(varType_ == Missing){
110  std::string errorMessage="Requested Centrality variable does not exist : "+centralityVariable_+"\n" +
111  "Supported variables are: \n" + "HFtowers HFtowersPlus HFtowersMinus HFtowersTrunc HFtowersPlusTrunc HFtowersMinusTrunc HFhits PixelHits PixelTracks Tracks EB EE" + "\n";
112  throw cms::Exception("Configuration",errorMessage);
113  }
114 
115  if(iConfig.exists("nonDefaultGlauberModel")){
116  centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
117  }
119 
120  produces<int>(centralityVariable_.data());
121 }
122 
123 
125 {
126 
127  // do anything here that needs to be done at desctruction time
128  // (e.g. close files, deallocate resources etc.)
129 
130 }
131 
132 
133 //
134 // member functions
135 //
136 
137 // ------------ method called to produce the data ------------
138 void
140 {
141 
142  iEvent.getByToken(tag_,chandle_);
143 
144  double value = 0;
145  switch(varType_){
146  case HFtowers : value = chandle_->EtHFtowerSum();break;
147  case HFtowersPlus : value = chandle_->EtHFtowerSumPlus();break;
148  case HFtowersMinus : value = chandle_->EtHFtowerSumMinus();break;
149  case HFhits : value = chandle_->EtHFhitSum();break;
150  case HFtowersTrunc : value = chandle_->EtHFtruncated();break;
151  case HFtowersPlusTrunc : value = chandle_->EtHFtruncatedPlus();break;
152  case HFtowersMinusTrunc : value = chandle_->EtHFtruncatedMinus();break;
153  case PixelHits : value = chandle_->multiplicityPixel();break;
154  case PixelTracks : value = chandle_->NpixelTracks();break;
155  case Tracks : value = chandle_->Ntracks();break;
156  case EB : value = chandle_->EtEBSum();break;
157  case EE : value = chandle_->EtEESum();break;
158  case ZDChitsPlus : value = chandle_->zdcSumPlus();break;
159  case ZDChitsMinus : value = chandle_->zdcSumMinus();break;
160  default:
161  throw cms::Exception("CentralityBinProducer","Centrality variable not recognized.");
162  }
163 
164  int bin = inputDB_->m_table.size() - 1;
165  for(unsigned int i = 0; i < inputDB_->m_table.size(); ++i){
166 
167  if(value >= inputDB_->m_table[i].bin_edge && value){
168  bin = i; break;
169  }
170 
171  }
172 
173  iEvent.put(std::make_unique<int>(bin),centralityVariable_.data());
174 
175 }
176 
177 
178 void
180 {
181 
182  if(prevRun_ < pPbRunFlip_ && iRun.run() >= pPbRunFlip_){
183  if(centralityVariable_.compare("HFtowersPlus") == 0) varType_ = HFtowersMinus;
184  if(centralityVariable_.compare("HFtowersMinus") == 0) varType_ = HFtowersPlus;
185  if(centralityVariable_.compare("HFtowersPlusTrunc") == 0) varType_ = HFtowersMinusTrunc;
186  if(centralityVariable_.compare("HFtowersMinusTrunc") == 0) varType_ = HFtowersPlusTrunc;
187  if(centralityVariable_.compare("ZDChitsPlus") == 0) varType_ = ZDChitsMinus;
188  if(centralityVariable_.compare("ZDChitsMinus") == 0) varType_ = ZDChitsPlus;
189  }
190  prevRun_ = iRun.run();
191 
192  iSetup.get<HeavyIonRcd>().get(centralityLabel_,inputDB_);
193 
194 }
195 
196 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
RunNumber_t run() const
Definition: RunBase.h:40
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:230
virtual void beginRun(edm::Run const &run, const edm::EventSetup &iSetup) override
edm::Handle< reco::Centrality > chandle_
virtual void produce(edm::Event &, const edm::EventSetup &) override
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< reco::Centrality > tag_
Definition: Run.h:42