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