CMS 3D CMS Logo

HiEvtPlaneFlatProducer.cc
Go to the documentation of this file.
1 #include <memory>
4 
7 
9 #include "Math/Vector3D.h"
10 
15 
17 
34 
42 
44 #include "TList.h"
45 #include "TString.h"
46 #include <ctime>
47 #include <cstdlib>
48 
51 
52 using namespace std;
53 using namespace hi;
54 
55 #include <vector>
56 using std::vector;
57 
58 //
59 // class declaration
60 //
61 
63 public:
65  ~HiEvtPlaneFlatProducer() override;
66 
67 private:
68  void produce(edm::Event&, const edm::EventSetup&) override;
69 
70  // ----------member data ---------------------------
71 
75 
78 
81 
84 
87 
91 
94 
95  const int FlatOrder_;
97  double caloCentRef_;
100  int Noffmin_;
101  int Noffmax_;
104  double nCentBins_;
105 };
106 //
107 // constants, enums and typedefs
108 //
109 
110 typedef std::vector<TrackingParticle> TrackingParticleCollection;
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  : centralityVariable_(iConfig.getParameter<std::string>("centralityVariable")),
122  centralityBinTag_(iConfig.getParameter<edm::InputTag>("centralityBinTag")),
123  centralityTag_(iConfig.getParameter<edm::InputTag>("centralityTag")),
124  vertexTag_(iConfig.getParameter<edm::InputTag>("vertexTag")),
125  inputPlanesTag_(iConfig.getParameter<edm::InputTag>("inputPlanesTag")),
126  trackTag_(iConfig.getParameter<edm::InputTag>("trackTag")),
127  FlatOrder_(iConfig.getParameter<int>("FlatOrder")),
128  NumFlatBins_(iConfig.getParameter<int>("NumFlatBins")),
129  caloCentRef_(iConfig.getParameter<double>("caloCentRef")),
130  caloCentRefWidth_(iConfig.getParameter<double>("caloCentRefWidth")),
131  CentBinCompression_(iConfig.getParameter<int>("CentBinCompression")),
132  Noffmin_(iConfig.getParameter<int>("Noffmin")),
133  Noffmax_(iConfig.getParameter<int>("Noffmax")),
134  useOffsetPsi_(iConfig.getParameter<bool>("useOffsetPsi")) {
135  // UseEtHF = kFALSE;
136  nCentBins_ = 200.;
137 
138  if (iConfig.exists("nonDefaultGlauberModel")) {
139  centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
140  }
142 
143  centralityBinToken = consumes<int>(centralityBinTag_);
144 
145  centralityToken = consumes<reco::Centrality>(centralityTag_);
146 
147  vertexToken = consumes<std::vector<reco::Vertex>>(vertexTag_);
148 
149  trackToken = consumes<reco::TrackCollection>(trackTag_);
150 
151  inputPlanesToken = consumes<reco::EvtPlaneCollection>(inputPlanesTag_);
152 
153  //register your products
154  produces<reco::EvtPlaneCollection>();
155  //now do what ever other initialization is needed
156  for (int i = 0; i < NumEPNames; i++) {
157  flat[i] = new HiEvtPlaneFlatten();
159  }
160 }
161 
163  // do anything here that needs to be done at desctruction time
164  // (e.g. close files, deallocate resources etc.)
165  for (int i = 0; i < NumEPNames; i++) {
166  delete flat[i];
167  }
168 }
169 
170 //
171 // member functions
172 //
173 
174 // ------------ method called to produce the data ------------
176  using namespace edm;
177  using namespace std;
178  using namespace reco;
179 
180  //
181  //Get Flattening Parameters
182  //
183  if (hiWatcher.check(iSetup)) {
184  //
185  //Get Size of Centrality Table
186  //
188  iSetup.get<HeavyIonRcd>().get(centralityLabel_, centDB_);
189  nCentBins_ = centDB_->m_table.size();
190  for (int i = 0; i < NumEPNames; i++) {
191  flat[i]->setCaloCentRefBins(-1, -1);
192  if (caloCentRef_ > 0) {
193  int minbin = (caloCentRef_ - caloCentRefWidth_ / 2.) * nCentBins_ / 100.;
194  int maxbin = (caloCentRef_ + caloCentRefWidth_ / 2.) * nCentBins_ / 100.;
195  minbin /= CentBinCompression_;
196  maxbin /= CentBinCompression_;
197  if (minbin > 0 && maxbin >= minbin) {
198  if (EPDet[i] == HF || EPDet[i] == Castor)
199  flat[i]->setCaloCentRefBins(minbin, maxbin);
200  }
201  }
202  }
203  }
204 
205  if (hirpWatcher.check(iSetup)) {
206  edm::ESHandle<RPFlatParams> flatparmsDB_;
207  iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
208  LoadEPDB db(flatparmsDB_, flat);
209  if (!db.IsSuccess())
210  return;
211  }
212  //
213  //Get Centrality
214  //
215 
216  int bin = 0;
217  edm::Handle<int> cbin_;
218  iEvent.getByToken(centralityBinToken, cbin_);
219  int cbin = *cbin_;
220  bin = cbin / CentBinCompression_;
221 
222  if (Noffmin_ >= 0) {
223  edm::Handle<reco::Centrality> centrality_;
224  iEvent.getByToken(centralityToken, centrality_);
225  int Noff = centrality_->Ntracks();
226  if ((Noff < Noffmin_) or (Noff >= Noffmax_)) {
227  return;
228  }
229  }
230  //
231  //Get Vertex
232  //
233  int vs_sell; // vertex collection size
234  float vzr_sell;
236  iEvent.getByToken(vertexToken, vertex_);
237  const reco::VertexCollection* vertices3 = vertex_.product();
238  vs_sell = vertices3->size();
239  if (vs_sell > 0) {
240  vzr_sell = vertices3->begin()->z();
241  } else
242  vzr_sell = -999.9;
243 
244  //
245  //Get Event Planes
246  //
247 
249  iEvent.getByToken(inputPlanesToken, evtPlanes_);
250 
251  if (!evtPlanes_.isValid()) {
252  // cout << "Error! Can't get hiEvtPlane product!" << endl;
253  return;
254  }
255 
256  auto evtplaneOutput = std::make_unique<EvtPlaneCollection>();
258  for (int i = 0; i < NumEPNames; i++) {
259  ep[i] = nullptr;
260  }
261  int indx = 0;
262  for (EvtPlaneCollection::const_iterator rp = evtPlanes_->begin(); rp != evtPlanes_->end(); rp++) {
263  double psiOffset = rp->angle(0);
264  double s = rp->sumSin(0);
265  double c = rp->sumCos(0);
266  uint m = rp->mult();
267 
268  double soff = s;
269  double coff = c;
270  if (useOffsetPsi_) {
271  soff = flat[indx]->getSoffset(s, vzr_sell, bin);
272  coff = flat[indx]->getCoffset(c, vzr_sell, bin);
273  psiOffset = flat[indx]->getOffsetPsi(soff, coff);
274  }
275  double psiFlat = flat[indx]->getFlatPsi(psiOffset, vzr_sell, bin);
276  ep[indx] =
277  new EvtPlane(indx, 2, psiFlat, soff, coff, rp->sumw(), rp->sumw2(), rp->sumPtOrEt(), rp->sumPtOrEt2(), m);
278  ep[indx]->addLevel(0, rp->angle(0), s, c);
279  ep[indx]->addLevel(3, 0., rp->sumSin(3), rp->sumCos(3));
280  if (useOffsetPsi_)
281  ep[indx]->addLevel(1, psiOffset, soff, coff);
282  ++indx;
283  }
284 
285  for (int i = 0; i < NumEPNames; i++) {
286  if (ep[i] != nullptr)
287  evtplaneOutput->push_back(*ep[i]);
288  }
289  iEvent.put(std::move(evtplaneOutput));
290  for (int i = 0; i < indx; i++)
291  delete ep[i];
292 }
293 
294 //define this as a plug-in
void init(int order, int nbins, std::string tag, int vord)
void addLevel(int level, double ang, double sumsin, double sumcos)
Definition: EvtPlane.cc:24
T getParameter(std::string const &) const
const int EPOrder[]
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::vector< CBin > m_table
const int EPDet[]
double Ntracks() const
Definition: Centrality.h:46
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool IsSuccess()
Definition: LoadEPDB.h:114
edm::EDGetTokenT< reco::Centrality > centralityToken
edm::ESWatcher< HeavyIonRcd > hiWatcher
double getSoffset(double s, double vtx, int centbin) const
double getOffsetPsi(double s, double c) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
TrackingParticleRefVector::iterator tp_iterator
void setCaloCentRefBins(const int caloCentRefMinBin, const int caloCentRefMaxBin)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
HiEvtPlaneFlatten * flat[NumEPNames]
const std::string EPNames[]
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexToken
edm::EDGetTokenT< reco::TrackCollection > trackToken
double getCoffset(double c, double vtx, int centbin) const
bool isValid() const
Definition: HandleBase.h:70
double getFlatPsi(double psi, double vtx, int centbin) const
T const * product() const
Definition: Handle.h:69
HiEvtPlaneFlatProducer(const edm::ParameterSet &)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
fixed size matrix
edm::Handle< reco::TrackCollection > trackCollection_
HLT enums.
edm::ESWatcher< HeavyIonRPRcd > hirpWatcher
T get() const
Definition: EventSetup.h:73
edm::EDGetTokenT< int > centralityBinToken
edm::EDGetTokenT< reco::EvtPlaneCollection > inputPlanesToken
static const int NumEPNames
def move(src, dest)
Definition: eostools.py:511