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
16 
21 
23 
28 
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;
57 
58  private:
59  void beginJob() override;
60  void produce(edm::Event&, const edm::EventSetup&) override;
61  void endJob() override;
62 
63  // ----------member data ---------------------------
64 
65  bool recoLevel_;
66 
74  bool reuseAny_;
76 
78 
80  double trackPtCut_;
81  double trackEtaCut_;
82  double hfEtaCut_;
83 
85 
96 
99 
103  };
104 
105  //
106  // constants, enums and typedefs
107  //
108 
109  //
110  // static data member definitions
111  //
112 
113  //
114  // constructors and destructor
115  //
116  CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig) {
117  //register your products
118  produceHFhits_ = iConfig.getParameter<bool>("produceHFhits");
119  produceHFtowers_ = iConfig.getParameter<bool>("produceHFtowers");
120  produceEcalhits_ = iConfig.getParameter<bool>("produceEcalhits");
121  produceZDChits_ = iConfig.getParameter<bool>("produceZDChits");
122  produceETmidRap_ = iConfig.getParameter<bool>("produceETmidRapidity");
123  producePixelhits_ = iConfig.getParameter<bool>("producePixelhits");
124  produceTracks_ = iConfig.getParameter<bool>("produceTracks");
125  producePixelTracks_ = iConfig.getParameter<bool>("producePixelTracks");
126 
127  midRapidityRange_ = iConfig.getParameter<double>("midRapidityRange");
128  trackPtCut_ = iConfig.getParameter<double>("trackPtCut");
129  trackEtaCut_ = iConfig.getParameter<double>("trackEtaCut");
130 
131  hfEtaCut_ = iConfig.getParameter<double>("hfEtaCut");
132 
133  if (produceHFhits_)
134  srcHFhits_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcHFhits"));
135  if (produceHFtowers_ || produceETmidRap_)
136  srcTowers_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("srcTowers"));
137 
138  if (produceEcalhits_) {
139  srcEBhits_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEBhits"));
140  srcEEhits_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEEhits"));
141  }
142  if (produceZDChits_) {
143  srcZDChits_ = consumes<ZDCRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcZDChits"));
144  lowGainZDC_ = iConfig.getParameter<bool>("lowGainZDC");
145  }
146  if (producePixelhits_) {
147  srcPixelhits_ = consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcPixelhits"));
148  doPixelCut_ = iConfig.getParameter<bool>("doPixelCut");
149  srcVertex_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("srcVertex"));
150  }
151  if (produceTracks_) {
152  srcTracks_ = consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"));
153  srcVertex_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("srcVertex"));
154  }
155  if (producePixelTracks_)
156  srcPixelTracks_ = consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcPixelTracks"));
157 
158  reuseAny_ = iConfig.getParameter<bool>("reUseCentrality");
159  if (reuseAny_)
160  reuseTag_ = consumes<Centrality>(iConfig.getParameter<edm::InputTag>("srcReUse"));
161 
162  useQuality_ = iConfig.getParameter<bool>("UseQuality");
163  trackQuality_ = TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
164 
165  produces<Centrality>();
166  }
167 
168  CentralityProducer::~CentralityProducer() {
169  // do anything here that needs to be done at desctruction time
170  // (e.g. close files, deallocate resources etc.)
171  }
172 
173  //
174  // member functions
175  //
176 
177  // ------------ method called to produce the data ------------
178  void CentralityProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
179  if (producePixelhits_)
180  iSetup.get<TrackerDigiGeometryRecord>().get(tGeo);
181  if (produceEcalhits_)
182  iSetup.get<CaloGeometryRecord>().get(cGeo);
183  if (producePixelhits_)
184  iSetup.get<TrackerTopologyRcd>().get(topo_);
185 
186  auto creco = std::make_unique<Centrality>();
187  Handle<Centrality> inputCentrality;
188 
189  if (reuseAny_)
190  iEvent.getByToken(reuseTag_, inputCentrality);
191 
192  if (produceHFhits_) {
193  creco->etHFhitSumPlus_ = 0;
194  creco->etHFhitSumMinus_ = 0;
195 
197  iEvent.getByToken(srcHFhits_, hits);
198  for (size_t ihit = 0; ihit < hits->size(); ++ihit) {
199  const HFRecHit& rechit = (*hits)[ihit];
200  if (rechit.id().ieta() > 0)
201  creco->etHFhitSumPlus_ += rechit.energy();
202  if (rechit.id().ieta() < 0)
203  creco->etHFhitSumMinus_ += rechit.energy();
204  }
205  } else {
206  if (reuseAny_) {
207  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
208  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
209  }
210  }
211 
212  if (produceHFtowers_ || produceETmidRap_) {
213  creco->etHFtowerSumPlus_ = 0;
214  creco->etHFtowerSumMinus_ = 0;
215  creco->etHFtowerSumECutPlus_ = 0;
216  creco->etHFtowerSumECutMinus_ = 0;
217  creco->etMidRapiditySum_ = 0;
218 
220 
221  iEvent.getByToken(srcTowers_, towers);
222 
223  for (size_t i = 0; i < towers->size(); ++i) {
224  const CaloTower& tower = (*towers)[i];
225  double eta = tower.eta();
226  bool isHF = tower.ietaAbs() > 29;
227  if (produceHFtowers_) {
228  if (isHF && eta > 0) {
229  creco->etHFtowerSumPlus_ += tower.pt();
230  if (tower.energy() > 1.5)
231  creco->etHFtowerSumECutPlus_ += tower.pt();
232  if (eta > hfEtaCut_)
233  creco->etHFtruncatedPlus_ += tower.pt();
234  }
235  if (isHF && eta < 0) {
236  creco->etHFtowerSumMinus_ += tower.pt();
237  if (tower.energy() > 1.5)
238  creco->etHFtowerSumECutMinus_ += tower.pt();
239  if (eta < -hfEtaCut_)
240  creco->etHFtruncatedMinus_ += tower.pt();
241  }
242  } else {
243  if (reuseAny_) {
244  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
245  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
246  creco->etHFtowerSumECutMinus_ = inputCentrality->EtHFtowerSumECutMinus();
247  creco->etHFtowerSumECutPlus_ = inputCentrality->EtHFtowerSumECutPlus();
248  creco->etHFtruncatedMinus_ = inputCentrality->EtHFtruncatedMinus();
249  creco->etHFtruncatedPlus_ = inputCentrality->EtHFtruncatedPlus();
250  }
251  }
252  if (produceETmidRap_) {
253  if (std::abs(eta) < midRapidityRange_)
254  creco->etMidRapiditySum_ += tower.pt() / (midRapidityRange_ * 2.);
255  } else if (reuseAny_)
256  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
257  }
258  } else {
259  if (reuseAny_) {
260  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
261  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
262  creco->etHFtowerSumECutMinus_ = inputCentrality->EtHFtowerSumECutMinus();
263  creco->etHFtowerSumECutPlus_ = inputCentrality->EtHFtowerSumECutPlus();
264  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
265  }
266  }
267 
268  if (produceEcalhits_) {
269  creco->etEESumPlus_ = 0;
270  creco->etEESumMinus_ = 0;
271  creco->etEBSum_ = 0;
272 
275 
276  iEvent.getByToken(srcEBhits_, ebHits);
277  iEvent.getByToken(srcEEhits_, eeHits);
278 
279  for (unsigned int i = 0; i < ebHits->size(); ++i) {
280  const EcalRecHit& hit = (*ebHits)[i];
281  const GlobalPoint& pos = cGeo->getPosition(hit.id());
282  double et = hit.energy() * (pos.perp() / pos.mag());
283  creco->etEBSum_ += et;
284  }
285 
286  for (unsigned int i = 0; i < eeHits->size(); ++i) {
287  const EcalRecHit& hit = (*eeHits)[i];
288  const GlobalPoint& pos = cGeo->getPosition(hit.id());
289  double et = hit.energy() * (pos.perp() / pos.mag());
290  if (pos.z() > 0) {
291  creco->etEESumPlus_ += et;
292  } else {
293  creco->etEESumMinus_ += et;
294  }
295  }
296  } else {
297  if (reuseAny_) {
298  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
299  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
300  creco->etEBSum_ = inputCentrality->EtEBSum();
301  }
302  }
303 
304  if (producePixelhits_) {
305  creco->pixelMultiplicity_ = 0;
308  iEvent.getByToken(srcPixelhits_, rchts);
309  rechits = rchts.product();
310  int nPixel = 0;
311  int nPixel_plus = 0;
312  int nPixel_minus = 0;
313  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it != rechits->end(); it++) {
315  DetId detId = DetId(hits.detId());
316  SiPixelRecHitCollection::const_iterator recHitMatch = rechits->find(detId);
317  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
318  for (SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
319  recHitIterator != recHitRange.end();
320  ++recHitIterator) {
321  // add selection if needed, now all hits.
322  const SiPixelRecHit* recHit = &(*recHitIterator);
323  const PixelGeomDetUnit* pixelLayer =
324  dynamic_cast<const PixelGeomDetUnit*>(tGeo->idToDet(recHit->geographicalId()));
325  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
326  math::XYZVector rechitPos(gpos.x(), gpos.y(), gpos.z());
327  double eta = rechitPos.eta();
328  double abeta = std::abs(rechitPos.eta());
329  int clusterSize = recHit->cluster()->size();
330  unsigned layer = topo_->layer(detId);
331  if (doPixelCut_) {
332  if (detId.det() == DetId::Tracker && detId.subdetId() == PixelSubdetector::PixelBarrel) {
333  if (layer == 1 && 18 * abeta - 40 > clusterSize)
334  continue;
335  if (layer == 2 && 6 * abeta - 7.2 > clusterSize)
336  continue;
337  if ((layer == 3 || layer == 4) && 4 * abeta - 2.4 > clusterSize)
338  continue;
339  }
340  }
341  nPixel++;
342  if (eta >= 0)
343  nPixel_plus++;
344  if (eta < 0)
345  nPixel_minus++;
346  }
347  }
348  creco->pixelMultiplicity_ = nPixel;
349  creco->pixelMultiplicityPlus_ = nPixel_plus;
350  creco->pixelMultiplicityMinus_ = nPixel_minus;
351  } else {
352  if (reuseAny_) {
353  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
354  creco->pixelMultiplicityPlus_ = inputCentrality->multiplicityPixelPlus();
355  creco->pixelMultiplicityMinus_ = inputCentrality->multiplicityPixelMinus();
356  }
357  }
358 
359  if (produceTracks_) {
360  double vx = -999.;
361  double vy = -999.;
362  double vz = -999.;
363  double vxError = -999.;
364  double vyError = -999.;
365  double vzError = -999.;
366  math::XYZVector vtxPos(0, 0, 0);
367 
368  Handle<VertexCollection> recoVertices;
369  iEvent.getByToken(srcVertex_, recoVertices);
370  unsigned int daughter = 0;
371  int greatestvtx = 0;
372 
373  for (unsigned int i = 0; i < recoVertices->size(); ++i) {
374  daughter = (*recoVertices)[i].tracksSize();
375  if (daughter > (*recoVertices)[greatestvtx].tracksSize())
376  greatestvtx = i;
377  }
378 
379  if (!recoVertices->empty()) {
380  vx = (*recoVertices)[greatestvtx].position().x();
381  vy = (*recoVertices)[greatestvtx].position().y();
382  vz = (*recoVertices)[greatestvtx].position().z();
383  vxError = (*recoVertices)[greatestvtx].xError();
384  vyError = (*recoVertices)[greatestvtx].yError();
385  vzError = (*recoVertices)[greatestvtx].zError();
386  }
387 
388  vtxPos = math::XYZVector(vx, vy, vz);
389 
391  iEvent.getByToken(srcTracks_, tracks);
392  int nTracks = 0;
393 
394  double trackCounter = 0;
395  double trackCounterEta = 0;
396  double trackCounterEtaPt = 0;
397 
398  for (unsigned int i = 0; i < tracks->size(); ++i) {
399  const Track& track = (*tracks)[i];
400  if (useQuality_ && !track.quality(trackQuality_))
401  continue;
402 
403  if (track.pt() > trackPtCut_)
404  trackCounter++;
405  if (std::abs(track.eta()) < trackEtaCut_) {
406  trackCounterEta++;
407  if (track.pt() > trackPtCut_)
408  trackCounterEtaPt++;
409  }
410 
411  math::XYZPoint v1(vx, vy, vz);
412  double dz = track.dz(v1);
413  double dzsigma2 = track.dzError() * track.dzError() + vzError * vzError;
414  double dxy = track.dxy(v1);
415  double dxysigma2 = track.dxyError() * track.dxyError() + vxError * vyError;
416 
417  const double pterrcut = 0.1;
418  const double dzrelcut = 3.0;
419  const double dxyrelcut = 3.0;
420 
421  if (track.quality(trackQuality_) && track.pt() > 0.4 && std::abs(track.eta()) < 2.4 &&
422  track.ptError() / track.pt() < pterrcut && dz * dz < dzrelcut * dzrelcut * dzsigma2 &&
423  dxy * dxy < dxyrelcut * dxyrelcut * dxysigma2) {
424  nTracks++;
425  }
426  }
427 
428  creco->trackMultiplicity_ = nTracks;
429  creco->ntracksPtCut_ = trackCounter;
430  creco->ntracksEtaCut_ = trackCounterEta;
431  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
432 
433  } else {
434  if (reuseAny_) {
435  creco->trackMultiplicity_ = inputCentrality->Ntracks();
436  creco->ntracksPtCut_ = inputCentrality->NtracksPtCut();
437  creco->ntracksEtaCut_ = inputCentrality->NtracksEtaCut();
438  creco->ntracksEtaPtCut_ = inputCentrality->NtracksEtaPtCut();
439  }
440  }
441 
442  if (producePixelTracks_) {
443  Handle<TrackCollection> pixeltracks;
444  iEvent.getByToken(srcPixelTracks_, pixeltracks);
445  int nPixelTracks = pixeltracks->size();
446  int nPixelTracksPlus = 0;
447  int nPixelTracksMinus = 0;
448 
449  for (auto const& track : *pixeltracks) {
450  if (track.eta() < 0)
451  nPixelTracksMinus++;
452  else
453  nPixelTracksPlus++;
454  }
455  creco->nPixelTracks_ = nPixelTracks;
456  creco->nPixelTracksPlus_ = nPixelTracksPlus;
457  creco->nPixelTracksMinus_ = nPixelTracksMinus;
458  } else {
459  if (reuseAny_) {
460  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
461  creco->nPixelTracksPlus_ = inputCentrality->NpixelTracksPlus();
462  creco->nPixelTracksMinus_ = inputCentrality->NpixelTracksMinus();
463  }
464  }
465 
466  if (produceZDChits_) {
467  creco->zdcSumPlus_ = 0;
468  creco->zdcSumMinus_ = 0;
469 
471  bool zdcAvailable = iEvent.getByToken(srcZDChits_, hits);
472  if (zdcAvailable) {
473  for (size_t ihit = 0; ihit < hits->size(); ++ihit) {
474  const ZDCRecHit& rechit = (*hits)[ihit];
475  if (rechit.id().zside() > 0) {
476  if (lowGainZDC_) {
477  creco->zdcSumPlus_ += rechit.lowGainEnergy();
478  } else {
479  creco->zdcSumPlus_ += rechit.energy();
480  }
481  }
482  if (rechit.id().zside() < 0) {
483  if (lowGainZDC_) {
484  creco->zdcSumMinus_ += rechit.lowGainEnergy();
485  } else {
486  creco->zdcSumMinus_ += rechit.energy();
487  }
488  }
489  }
490  } else {
491  creco->zdcSumPlus_ = -9;
492  creco->zdcSumMinus_ = -9;
493  }
494  } else {
495  if (reuseAny_) {
496  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
497  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
498  }
499  }
500 
501  iEvent.put(std::move(creco));
502  }
503 
504  // ------------ method called once each job just before starting event loop ------------
506 
507  // ------------ method called once each job just after ending the event loop ------------
508  void CentralityProducer::endJob() {}
509 
510  //define this as a plug-in
512 
513 } // namespace reco
constexpr float energy() const
Definition: CaloRecHit.h:29
reco::TrackBase::TrackQuality trackQuality_
T getParameter(std::string const &) const
const unsigned int nTracks(const reco::Vertex &sv)
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< EcalRecHitCollection > srcEBhits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< Centrality > reuseTag_
TrackQuality
track quality
Definition: TrackBase.h:150
double dxyError() const
error on dxy
Definition: TrackBase.h:716
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:39
double pt() const final
transverse momentum
edm::EDGetTokenT< VertexCollection > srcVertex_
void beginJob()
Definition: Breakpoints.cc:14
edm::EDGetTokenT< CaloTowerCollection > srcTowers_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
double pt() const
track transverse momentum
Definition: TrackBase.h:602
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:696
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
double energy() const final
energy
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
edm::EDGetTokenT< HFRecHitCollection > srcHFhits_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float energy() const
Definition: EcalRecHit.h:68
float lowGainEnergy() const
Definition: ZDCRecHit.h:20
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:596
double dzError() const
error on dz
Definition: TrackBase.h:725
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
DetId id() const
get the id
Definition: EcalRecHit.h:77
T const * product() const
Definition: Handle.h:69
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
edm::EDGetTokenT< ZDCRecHitCollection > srcZDChits_
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
id_type detId() const
Definition: DetSetNew.h:66
bool isHF(int etabin, int depth)
edm::ESHandle< CaloGeometry > cGeo
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
const_iterator find(id_type i, bool update=false) const
edm::EDGetTokenT< SiPixelRecHitCollection > srcPixelhits_
int ietaAbs() const
Definition: CaloTower.h:205
fixed size matrix
HLT enums.
iterator end()
Definition: DetSetNew.h:56
edm::ESHandle< TrackerTopology > topo_
size_type size() const
edm::EDGetTokenT< TrackCollection > srcPixelTracks_
T get() const
Definition: EventSetup.h:73
edm::EDGetTokenT< TrackCollection > srcTracks_
HcalZDCDetId id() const
get the id
Definition: ZDCRecHit.h:18
LocalPoint localPosition() const final
edm::ESHandle< TrackerGeometry > tGeo
HcalDetId id() const
Definition: HFRecHit.h:26
DetId geographicalId() const
edm::EDGetTokenT< EcalRecHitCollection > srcEEhits_
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:587
def move(src, dest)
Definition: eostools.py:511
const_iterator begin(bool update=false) const
Our base class.
Definition: SiPixelRecHit.h:23
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
iterator begin()
Definition: DetSetNew.h:54