CMS 3D CMS Logo

CentralityProducer.cc
Go to the documentation of this file.
1 //
2 // Original Author: Yetkin Yilmaz, Young Soo Park
3 // Created: Wed Jun 11 15:31:41 CEST 2008
4 //
5 //
6 
7 // system include files
8 #include <memory>
9 #include <iostream>
10 
11 // user include files
17 
23 
25 
29 
37 
43 
44 using namespace std;
45 using namespace edm;
46 using namespace reco;
47 
48 //
49 // class declaration
50 //
51 
52 namespace reco {
54  public:
55  explicit CentralityProducer(const edm::ParameterSet&);
56  ~CentralityProducer() override = default;
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59  private:
60  void beginJob() override;
61  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
62  void endJob() override;
63 
64  // ----------member data ---------------------------
65 
66  const bool produceHFhits_;
67  const bool produceHFtowers_;
68  const bool produceEcalhits_;
69  const bool produceZDChits_;
70  const bool lowGainZDC_;
71  const bool produceETmidRap_;
72  const bool producePixelhits_;
73  const bool doPixelCut_;
74  const bool produceTracks_;
75  const bool producePixelTracks_;
76 
77  const double midRapidityRange_;
78  const double trackPtCut_;
79  const double trackEtaCut_;
80  const double hfEtaCut_;
81 
82  const bool reuseAny_;
83  const bool useQuality_;
85 
96 
100  };
101 
102  //
103  // constants, enums and typedefs
104  //
105 
106  //
107  // static data member definitions
108  //
109 
110  //
111  // constructors and destructor
112  //
113  CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig)
114  : produceHFhits_(iConfig.getParameter<bool>("produceHFhits")),
115  produceHFtowers_(iConfig.getParameter<bool>("produceHFtowers")),
116  produceEcalhits_(iConfig.getParameter<bool>("produceEcalhits")),
117  produceZDChits_(iConfig.getParameter<bool>("produceZDChits")),
118  lowGainZDC_(iConfig.getParameter<bool>("lowGainZDC")),
119  produceETmidRap_(iConfig.getParameter<bool>("produceETmidRapidity")),
120  producePixelhits_(iConfig.getParameter<bool>("producePixelhits")),
121  doPixelCut_(iConfig.getParameter<bool>("doPixelCut")),
122  produceTracks_(iConfig.getParameter<bool>("produceTracks")),
123  producePixelTracks_(iConfig.getParameter<bool>("producePixelTracks")),
124  midRapidityRange_(iConfig.getParameter<double>("midRapidityRange")),
125  trackPtCut_(iConfig.getParameter<double>("trackPtCut")),
126  trackEtaCut_(iConfig.getParameter<double>("trackEtaCut")),
127  hfEtaCut_(iConfig.getParameter<double>("hfEtaCut")),
128  reuseAny_(iConfig.getParameter<bool>("reUseCentrality")),
129  useQuality_(iConfig.getParameter<bool>("useQuality")),
130  trackQuality_(TrackBase::qualityByName(iConfig.getParameter<std::string>("trackQuality"))),
131  srcHFhits_(produceHFhits_ ? consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcHFhits"))
133  srcTowers_((produceHFtowers_ || produceETmidRap_)
134  ? consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("srcTowers"))
136  srcEBhits_(produceEcalhits_ ? consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEBhits"))
138  srcEEhits_(produceEcalhits_ ? consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEEhits"))
140  srcZDChits_(produceZDChits_ ? consumes<ZDCRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcZDChits"))
142  srcPixelhits_(producePixelhits_
143  ? consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcPixelhits"))
145  srcTracks_(produceTracks_ ? consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"))
147  srcPixelTracks_(producePixelTracks_
148  ? consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcPixelTracks"))
150  srcVertex_((produceTracks_ || producePixelTracks_)
151  ? consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("srcVertex"))
153  reuseTag_(reuseAny_ ? consumes<Centrality>(iConfig.getParameter<edm::InputTag>("srcReUse"))
154  : edm::EDGetTokenT<Centrality>()),
155  caloGeom_(produceEcalhits_ ? esConsumes<CaloGeometry, CaloGeometryRecord>()
157  trackerGeom_(producePixelhits_ ? esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()
159  trackerTopo_(producePixelhits_ ? esConsumes<TrackerTopology, TrackerTopologyRcd>()
161  produces<Centrality>();
162  }
163 
164  //
165  // member functions
166  //
167 
168  // ------------ method called to produce the data ------------
170  auto creco = std::make_unique<Centrality>();
171  Handle<Centrality> inputCentrality;
172  if (reuseAny_)
173  iEvent.getByToken(reuseTag_, inputCentrality);
174 
175  if (produceHFhits_) {
176  creco->etHFhitSumPlus_ = 0;
177  creco->etHFhitSumMinus_ = 0;
179  iEvent.getByToken(srcHFhits_, hits);
180  for (size_t ihit = 0; ihit < hits->size(); ++ihit) {
181  const HFRecHit& rechit = (*hits)[ihit];
182  if (rechit.id().ieta() > 0)
183  creco->etHFhitSumPlus_ += rechit.energy();
184  if (rechit.id().ieta() < 0)
185  creco->etHFhitSumMinus_ += rechit.energy();
186  }
187  } else {
188  if (reuseAny_) {
189  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
190  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
191  }
192  }
193 
195  creco->etHFtowerSumPlus_ = 0;
196  creco->etHFtowerSumMinus_ = 0;
197  creco->etHFtowerSumECutPlus_ = 0;
198  creco->etHFtowerSumECutMinus_ = 0;
199  creco->etMidRapiditySum_ = 0;
200 
202  iEvent.getByToken(srcTowers_, towers);
203 
204  for (size_t i = 0; i < towers->size(); ++i) {
205  const CaloTower& tower = (*towers)[i];
206  double eta = tower.eta();
207  if (produceHFtowers_) {
208  bool isHF = tower.ietaAbs() > 29;
209  if (isHF && eta > 0) {
210  creco->etHFtowerSumPlus_ += tower.pt();
211  if (tower.energy() > 1.5)
212  creco->etHFtowerSumECutPlus_ += tower.pt();
213  if (eta > hfEtaCut_)
214  creco->etHFtruncatedPlus_ += tower.pt();
215  } else if (isHF && eta < 0) {
216  creco->etHFtowerSumMinus_ += tower.pt();
217  if (tower.energy() > 1.5)
218  creco->etHFtowerSumECutMinus_ += tower.pt();
219  if (eta < -hfEtaCut_)
220  creco->etHFtruncatedMinus_ += tower.pt();
221  }
222  } else {
223  if (reuseAny_) {
224  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
225  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
226  creco->etHFtowerSumECutMinus_ = inputCentrality->EtHFtowerSumECutMinus();
227  creco->etHFtowerSumECutPlus_ = inputCentrality->EtHFtowerSumECutPlus();
228  creco->etHFtruncatedMinus_ = inputCentrality->EtHFtruncatedMinus();
229  creco->etHFtruncatedPlus_ = inputCentrality->EtHFtruncatedPlus();
230  }
231  }
232  if (produceETmidRap_) {
234  creco->etMidRapiditySum_ += tower.pt() / (midRapidityRange_ * 2.);
235  } else if (reuseAny_)
236  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
237  }
238  } else {
239  if (reuseAny_) {
240  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
241  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
242  creco->etHFtowerSumECutMinus_ = inputCentrality->EtHFtowerSumECutMinus();
243  creco->etHFtowerSumECutPlus_ = inputCentrality->EtHFtowerSumECutPlus();
244  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
245  }
246  }
247 
248  if (produceEcalhits_) {
249  creco->etEESumPlus_ = 0;
250  creco->etEESumMinus_ = 0;
251  creco->etEBSum_ = 0;
252 
255  iEvent.getByToken(srcEBhits_, ebHits);
256  iEvent.getByToken(srcEEhits_, eeHits);
257 
259  for (unsigned int i = 0; i < ebHits->size(); ++i) {
260  const EcalRecHit& hit = (*ebHits)[i];
261  const GlobalPoint& pos = cGeo->getPosition(hit.id());
262  double et = hit.energy() * (pos.perp() / pos.mag());
263  creco->etEBSum_ += et;
264  }
265 
266  for (unsigned int i = 0; i < eeHits->size(); ++i) {
267  const EcalRecHit& hit = (*eeHits)[i];
268  const GlobalPoint& pos = cGeo->getPosition(hit.id());
269  double et = hit.energy() * (pos.perp() / pos.mag());
270  if (pos.z() > 0) {
271  creco->etEESumPlus_ += et;
272  } else {
273  creco->etEESumMinus_ += et;
274  }
275  }
276  } else {
277  if (reuseAny_) {
278  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
279  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
280  creco->etEBSum_ = inputCentrality->EtEBSum();
281  }
282  }
283 
284  if (producePixelhits_) {
287  creco->pixelMultiplicity_ = 0;
290  iEvent.getByToken(srcPixelhits_, rchts);
291  rechits = rchts.product();
292  int nPixel = 0;
293  int nPixel_plus = 0;
294  int nPixel_minus = 0;
295  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it != rechits->end(); it++) {
297  DetId detId = DetId(hits.detId());
299  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
300  for (SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
301  recHitIterator != recHitRange.end();
302  ++recHitIterator) {
303  // add selection if needed, now all hits.
304  const SiPixelRecHit* recHit = &(*recHitIterator);
305  const PixelGeomDetUnit* pixelLayer =
306  dynamic_cast<const PixelGeomDetUnit*>(tGeo->idToDet(recHit->geographicalId()));
307  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
308  math::XYZVector rechitPos(gpos.x(), gpos.y(), gpos.z());
309  double eta = rechitPos.eta();
310  int clusterSize = recHit->cluster()->size();
311  unsigned layer = topo->layer(detId);
312  if (doPixelCut_) {
313  if (detId.det() == DetId::Tracker && detId.subdetId() == PixelSubdetector::PixelBarrel) {
314  double abeta = std::abs(eta);
315  if (layer == 1) {
316  if (18 * abeta - 40 > clusterSize)
317  continue;
318  } else if (layer == 2) {
319  if (6 * abeta - 7.2 > clusterSize)
320  continue;
321  } else if (layer == 3 || layer == 4) {
322  if (4 * abeta - 2.4 > clusterSize)
323  continue;
324  }
325  }
326  }
327  nPixel++;
328  if (eta >= 0)
329  nPixel_plus++;
330  else if (eta < 0)
331  nPixel_minus++;
332  }
333  }
334  creco->pixelMultiplicity_ = nPixel;
335  creco->pixelMultiplicityPlus_ = nPixel_plus;
336  creco->pixelMultiplicityMinus_ = nPixel_minus;
337  } else {
338  if (reuseAny_) {
339  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
340  creco->pixelMultiplicityPlus_ = inputCentrality->multiplicityPixelPlus();
341  creco->pixelMultiplicityMinus_ = inputCentrality->multiplicityPixelMinus();
342  }
343  }
344 
345  if (produceTracks_) {
346  double vx = -999.;
347  double vy = -999.;
348  double vz = -999.;
349  double vxError = -999.;
350  double vyError = -999.;
351  double vzError = -999.;
352  math::XYZVector vtxPos(0, 0, 0);
353 
354  Handle<VertexCollection> recoVertices;
355  iEvent.getByToken(srcVertex_, recoVertices);
356  unsigned int daughter = 0;
357  int greatestvtx = 0;
358 
359  for (unsigned int i = 0; i < recoVertices->size(); ++i) {
360  daughter = (*recoVertices)[i].tracksSize();
361  if (daughter > (*recoVertices)[greatestvtx].tracksSize())
362  greatestvtx = i;
363  }
364 
365  if (!recoVertices->empty()) {
366  vx = (*recoVertices)[greatestvtx].position().x();
367  vy = (*recoVertices)[greatestvtx].position().y();
368  vz = (*recoVertices)[greatestvtx].position().z();
369  vxError = (*recoVertices)[greatestvtx].xError();
370  vyError = (*recoVertices)[greatestvtx].yError();
371  vzError = (*recoVertices)[greatestvtx].zError();
372  }
373 
374  vtxPos = math::XYZVector(vx, vy, vz);
375 
377  iEvent.getByToken(srcTracks_, tracks);
378  int nTracks = 0;
379 
380  double trackCounter = 0;
381  double trackCounterEta = 0;
382  double trackCounterEtaPt = 0;
383 
384  for (unsigned int i = 0; i < tracks->size(); ++i) {
385  const Track& track = (*tracks)[i];
386  if (useQuality_ && !track.quality(trackQuality_))
387  continue;
388 
389  if (track.pt() > trackPtCut_)
390  trackCounter++;
391  if (std::abs(track.eta()) < trackEtaCut_) {
392  trackCounterEta++;
393  if (track.pt() > trackPtCut_)
394  trackCounterEtaPt++;
395  }
396 
397  math::XYZPoint v1(vx, vy, vz);
398  double dz = track.dz(v1);
399  double dzsigma2 = track.dzError() * track.dzError() + vzError * vzError;
400  double dxy = track.dxy(v1);
401  double dxysigma2 = track.dxyError() * track.dxyError() + vxError * vyError;
402 
403  const double pterrcut = 0.1;
404  const double dzrelcut = 3.0;
405  const double dxyrelcut = 3.0;
406 
407  if (track.quality(trackQuality_) && track.pt() > 0.4 && std::abs(track.eta()) < 2.4 &&
408  track.ptError() / track.pt() < pterrcut && dz * dz < dzrelcut * dzrelcut * dzsigma2 &&
409  dxy * dxy < dxyrelcut * dxyrelcut * dxysigma2) {
410  nTracks++;
411  }
412  }
413 
414  creco->trackMultiplicity_ = nTracks;
415  creco->ntracksPtCut_ = trackCounter;
416  creco->ntracksEtaCut_ = trackCounterEta;
417  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
418 
419  } else {
420  if (reuseAny_) {
421  creco->trackMultiplicity_ = inputCentrality->Ntracks();
422  creco->ntracksPtCut_ = inputCentrality->NtracksPtCut();
423  creco->ntracksEtaCut_ = inputCentrality->NtracksEtaCut();
424  creco->ntracksEtaPtCut_ = inputCentrality->NtracksEtaPtCut();
425  }
426  }
427 
428  if (producePixelTracks_) {
429  Handle<TrackCollection> pixeltracks;
430  iEvent.getByToken(srcPixelTracks_, pixeltracks);
431  int nPixelTracks = pixeltracks->size();
432  int nPixelTracksPlus = 0;
433  int nPixelTracksMinus = 0;
434 
435  for (auto const& track : *pixeltracks) {
436  if (track.eta() < 0)
437  nPixelTracksMinus++;
438  else
439  nPixelTracksPlus++;
440  }
441  creco->nPixelTracks_ = nPixelTracks;
442  creco->nPixelTracksPlus_ = nPixelTracksPlus;
443  creco->nPixelTracksMinus_ = nPixelTracksMinus;
444  } else {
445  if (reuseAny_) {
446  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
447  creco->nPixelTracksPlus_ = inputCentrality->NpixelTracksPlus();
448  creco->nPixelTracksMinus_ = inputCentrality->NpixelTracksMinus();
449  }
450  }
451 
452  if (produceZDChits_) {
453  creco->zdcSumPlus_ = 0;
454  creco->zdcSumMinus_ = 0;
455 
457  bool zdcAvailable = iEvent.getByToken(srcZDChits_, hits);
458  if (zdcAvailable) {
459  for (size_t ihit = 0; ihit < hits->size(); ++ihit) {
460  const ZDCRecHit& rechit = (*hits)[ihit];
461  if (rechit.id().zside() > 0) {
462  if (lowGainZDC_) {
463  creco->zdcSumPlus_ += rechit.lowGainEnergy();
464  } else {
465  creco->zdcSumPlus_ += rechit.energy();
466  }
467  }
468  if (rechit.id().zside() < 0) {
469  if (lowGainZDC_) {
470  creco->zdcSumMinus_ += rechit.lowGainEnergy();
471  } else {
472  creco->zdcSumMinus_ += rechit.energy();
473  }
474  }
475  }
476  } else {
477  creco->zdcSumPlus_ = -9;
478  creco->zdcSumMinus_ = -9;
479  }
480  } else {
481  if (reuseAny_) {
482  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
483  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
484  }
485  }
486 
487  iEvent.put(std::move(creco));
488  }
489 
492  desc.add<bool>("produceHFhits", true);
493  desc.add<bool>("produceHFtowers", true);
494  desc.add<bool>("produceEcalhits", true);
495  desc.add<bool>("produceZDChits", true);
496  desc.add<bool>("produceETmidRapidity", true);
497  desc.add<bool>("producePixelhits", true);
498  desc.add<bool>("produceTracks", true);
499  desc.add<bool>("producePixelTracks", true);
500  desc.add<bool>("reUseCentrality", false);
501  desc.add<edm::InputTag>("srcHFhits", edm::InputTag("hfreco"));
502  desc.add<edm::InputTag>("srcTowers", edm::InputTag("towerMaker"));
503  desc.add<edm::InputTag>("srcEBhits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
504  desc.add<edm::InputTag>("srcEEhits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
505  desc.add<edm::InputTag>("srcZDChits", edm::InputTag("zdcreco"));
506  desc.add<edm::InputTag>("srcPixelhits", edm::InputTag("siPixelRecHits"));
507  desc.add<edm::InputTag>("srcTracks", edm::InputTag("hiGeneralTracks"));
508  desc.add<edm::InputTag>("srcVertex", edm::InputTag("hiSelectedVertex"));
509  desc.add<edm::InputTag>("srcReUse", edm::InputTag("hiCentrality"));
510  desc.add<edm::InputTag>("srcPixelTracks", edm::InputTag("hiPixel3PrimTracks"));
511  desc.add<bool>("doPixelCut", true);
512  desc.add<bool>("useQuality", true);
513  desc.add<string>("trackQuality", "highPurity");
514  desc.add<double>("trackEtaCut", 2);
515  desc.add<double>("trackPtCut", 1);
516  desc.add<double>("hfEtaCut", 4)->setComment("hf above the absolute value of this cut is used");
517  desc.add<double>("midRapidityRange", 1);
518  desc.add<bool>("lowGainZDC", true);
519 
520  descriptions.addDefault(desc);
521  }
522 
523  // ------------ method called once each job just before starting event loop ------------
525 
526  // ------------ method called once each job just after ending the event loop ------------
528 
529  //define this as a plug-in
531 
532 } // namespace reco
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< EcalRecHitCollection > srcEEhits_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeom_
const edm::EDGetTokenT< TrackCollection > srcTracks_
Quality qualityByName(std::string const &name)
const edm::EDGetTokenT< SiPixelRecHitCollection > srcPixelhits_
TrackQuality
track quality
Definition: TrackBase.h:150
size_type size() const
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const edm::EDGetTokenT< CaloTowerCollection > srcTowers_
const reco::TrackBase::TrackQuality trackQuality_
const edm::EDGetTokenT< VertexCollection > srcVertex_
unsigned int layer(const DetId &id) const
constexpr float energy() const
Definition: CaloRecHit.h:29
void beginJob()
Definition: Breakpoints.cc:14
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
constexpr HcalDetId id() const
Definition: HFRecHit.h:26
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
float lowGainEnergy() const
Definition: ZDCRecHit.h:20
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopo_
const edm::EDGetTokenT< ZDCRecHitCollection > srcZDChits_
const edm::EDGetTokenT< TrackCollection > srcPixelTracks_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeom_
const edm::EDGetTokenT< HFRecHitCollection > srcHFhits_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const TrackerGeomDet * idToDet(DetId) const override
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
unsigned int id
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< Centrality > reuseTag_
bool isHF(int etabin, int depth)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
fixed size matrix
HcalZDCDetId id() const
get the id
Definition: ZDCRecHit.h:18
HLT enums.
iterator end()
Definition: DetSetNew.h:53
const edm::EDGetTokenT< EcalRecHitCollection > srcEBhits_
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
def move(src, dest)
Definition: eostools.py:511
Our base class.
Definition: SiPixelRecHit.h:23
iterator begin()
Definition: DetSetNew.h:51