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 
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 
102 
103 };
104 
105 //
106 // constants, enums and typedefs
107 //
108 
109 
110 //
111 // static data member definitions
112 //
113 
114 //
115 // constructors and destructor
116 //
117  CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig) {
118  //register your products
119  produceHFhits_ = iConfig.getParameter<bool>("produceHFhits");
120  produceHFtowers_ = iConfig.getParameter<bool>("produceHFtowers");
121  produceEcalhits_ = iConfig.getParameter<bool>("produceEcalhits");
122  produceZDChits_ = iConfig.getParameter<bool>("produceZDChits");
123  produceETmidRap_ = iConfig.getParameter<bool>("produceETmidRapidity");
124  producePixelhits_ = iConfig.getParameter<bool>("producePixelhits");
125  produceTracks_ = iConfig.getParameter<bool>("produceTracks");
126  producePixelTracks_ = iConfig.getParameter<bool>("producePixelTracks");
127 
128  midRapidityRange_ = iConfig.getParameter<double>("midRapidityRange");
129  trackPtCut_ = iConfig.getParameter<double>("trackPtCut");
130  trackEtaCut_ = iConfig.getParameter<double>("trackEtaCut");
131 
132  hfEtaCut_ = iConfig.getParameter<double>("hfEtaCut");
133 
134  if(produceHFhits_) srcHFhits_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcHFhits"));
135  if(produceHFtowers_ || produceETmidRap_) srcTowers_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("srcTowers"));
136 
137  if(produceEcalhits_){
138  srcEBhits_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEBhits"));
139  srcEEhits_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcEEhits"));
140  }
141  if(produceZDChits_){
142  srcZDChits_ = consumes<ZDCRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcZDChits"));
143  lowGainZDC_ = iConfig.getParameter<bool>("lowGainZDC");
144  }
145  if(producePixelhits_){
146  srcPixelhits_ = consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("srcPixelhits"));
147  doPixelCut_ = iConfig.getParameter<bool>("doPixelCut");
148  srcVertex_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("srcVertex"));
149  }
150  if(produceTracks_) {
151  srcTracks_ = consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"));
152  srcVertex_ = consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("srcVertex"));
153  }
154  if(producePixelTracks_) srcPixelTracks_ = consumes<TrackCollection>(iConfig.getParameter<edm::InputTag>("srcPixelTracks"));
155 
156  reuseAny_ = iConfig.getParameter<bool>("reUseCentrality");
157  if(reuseAny_) reuseTag_ = consumes<Centrality>(iConfig.getParameter<edm::InputTag>("srcReUse"));
158 
159  useQuality_ = iConfig.getParameter<bool>("UseQuality");
160  trackQuality_ = TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
161 
162  produces<Centrality>();
163 
164 }
165 
166 
167 CentralityProducer::~CentralityProducer()
168 {
169 
170  // do anything here that needs to be done at desctruction time
171  // (e.g. close files, deallocate resources etc.)
172 
173 }
174 
175 
176 //
177 // member functions
178 //
179 
180 // ------------ method called to produce the data ------------
181 void
182 CentralityProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
183 {
184 
185  if(producePixelhits_) iSetup.get<TrackerDigiGeometryRecord>().get(tGeo);
186  if(produceEcalhits_) iSetup.get<CaloGeometryRecord>().get(cGeo);
187 
188  auto creco = std::make_unique<Centrality>();
189  Handle<Centrality> inputCentrality;
190 
191  if(reuseAny_) iEvent.getByToken(reuseTag_,inputCentrality);
192 
193  if(produceHFhits_){
194  creco->etHFhitSumPlus_ = 0;
195  creco->etHFhitSumMinus_ = 0;
196 
198  iEvent.getByToken(srcHFhits_,hits);
199  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
200  const HFRecHit & rechit = (*hits)[ ihit ];
201  if(rechit.id().ieta() > 0 )
202  creco->etHFhitSumPlus_ += rechit.energy();
203  if(rechit.id().ieta() < 0)
204  creco->etHFhitSumMinus_ += rechit.energy();
205  }
206  }else{
207  if(reuseAny_){
208  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
209  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
210  }
211  }
212 
213  if(produceHFtowers_ || produceETmidRap_){
214  creco->etHFtowerSumPlus_ = 0;
215  creco->etHFtowerSumMinus_ = 0;
216  creco->etMidRapiditySum_ = 0;
217 
219 
220  iEvent.getByToken(srcTowers_,towers);
221 
222  for( size_t i = 0; i<towers->size(); ++ i){
223  const CaloTower & tower = (*towers)[ i ];
224  double eta = tower.eta();
225  bool isHF = tower.ietaAbs() > 29;
226  if(produceHFtowers_){
227  if(isHF && eta > 0){
228  creco->etHFtowerSumPlus_ += tower.pt();
229  if(eta > hfEtaCut_) creco->etHFtruncatedPlus_ += tower.pt();
230  }
231  if(isHF && eta < 0){
232  creco->etHFtowerSumMinus_ += tower.pt();
233  if(eta < -hfEtaCut_) creco->etHFtruncatedMinus_ += tower.pt();
234  }
235  }else{
236  if(reuseAny_){
237  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
238  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
239  creco->etHFtruncatedMinus_ = inputCentrality->EtHFtruncatedMinus();
240  creco->etHFtruncatedPlus_ = inputCentrality->EtHFtruncatedPlus();
241  }
242  }
243  if(produceETmidRap_){
244  if(std::abs(eta) < midRapidityRange_) creco->etMidRapiditySum_ += tower.pt()/(midRapidityRange_*2.);
245  }else if(reuseAny_) creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
246  }
247  }else{
248  if(reuseAny_){
249  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
250  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
251  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
252  }
253  }
254 
255  if(produceEcalhits_){
256  creco->etEESumPlus_ = 0;
257  creco->etEESumMinus_ = 0;
258  creco->etEBSum_ = 0;
259 
262 
263  iEvent.getByToken(srcEBhits_,ebHits);
264  iEvent.getByToken(srcEEhits_,eeHits);
265 
266  for(unsigned int i = 0; i < ebHits->size(); ++i){
267  const EcalRecHit & hit= (*ebHits)[i];
268  const GlobalPoint& pos=cGeo->getPosition(hit.id());
269  double et = hit.energy()*(pos.perp()/pos.mag());
270  creco->etEBSum_ += et;
271  }
272 
273  for(unsigned int i = 0; i < eeHits->size(); ++i){
274  const EcalRecHit & hit= (*eeHits)[i];
275  const GlobalPoint& pos=cGeo->getPosition(hit.id());
276  double et = hit.energy()*(pos.perp()/pos.mag());
277  if(pos.z() > 0){
278  creco->etEESumPlus_ += et;
279  }else{
280  creco->etEESumMinus_ += et;
281  }
282  }
283  }else{
284  if(reuseAny_){
285  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
286  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
287  creco->etEBSum_ = inputCentrality->EtEBSum();
288  }
289  }
290 
291  if(producePixelhits_){
292  creco->pixelMultiplicity_ = 0;
295  iEvent.getByToken(srcPixelhits_,rchts);
296  rechits = rchts.product();
297  int nPixel =0 ;
298  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it!=rechits->end();it++)
299  {
301  DetId detId = DetId(hits.detId());
302  SiPixelRecHitCollection::const_iterator recHitMatch = rechits->find(detId);
303  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
304  for ( SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
305  recHitIterator != recHitRange.end(); ++recHitIterator) {
306  // add selection if needed, now all hits.
307  if(doPixelCut_){
308  const SiPixelRecHit * recHit = &(*recHitIterator);
309  const PixelGeomDetUnit* pixelLayer = dynamic_cast<const PixelGeomDetUnit*> (tGeo->idToDet(recHit->geographicalId()));
310  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
311  math::XYZVector rechitPos(gpos.x(),gpos.y(),gpos.z());
312  double abeta = std::abs(rechitPos.eta());
313  int clusterSize = recHit->cluster()->size();
314  if ( abeta < 0.5 && clusterSize < 1) continue;
315  if ( abeta > 0.5 && abeta < 1 && clusterSize < 2) continue;
316  if ( abeta > 1. && abeta < 1.5 && clusterSize < 3) continue;
317  if ( abeta > 1.5 && abeta < 2. && clusterSize < 4) continue;
318  if ( abeta > 2. && abeta < 2.5 && clusterSize < 6) continue;
319  if ( abeta > 2.5 && abeta < 5 && clusterSize < 9) continue;
320  }
321  nPixel++;
322  }
323  }
324  creco->pixelMultiplicity_ = nPixel;
325  }else{
326  if(reuseAny_){
327  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
328  }
329  }
330 
331  if(produceTracks_){
332 
333  double vx=-999.;
334  double vy=-999.;
335  double vz=-999.;
336  double vxError=-999.;
337  double vyError=-999.;
338  double vzError=-999.;
339  math::XYZVector vtxPos(0,0,0);
340 
341  Handle<VertexCollection> recoVertices;
342  iEvent.getByToken(srcVertex_,recoVertices);
343  unsigned int daughter = 0;
344  int greatestvtx = 0;
345 
346  for (unsigned int i = 0 ; i< recoVertices->size(); ++i){
347  daughter = (*recoVertices)[i].tracksSize();
348  if( daughter > (*recoVertices)[greatestvtx].tracksSize()) greatestvtx = i;
349  }
350 
351  if(!recoVertices->empty()){
352  vx = (*recoVertices)[greatestvtx].position().x();
353  vy = (*recoVertices)[greatestvtx].position().y();
354  vz = (*recoVertices)[greatestvtx].position().z();
355  vxError = (*recoVertices)[greatestvtx].xError();
356  vyError = (*recoVertices)[greatestvtx].yError();
357  vzError = (*recoVertices)[greatestvtx].zError();
358  }
359 
360  vtxPos = math::XYZVector(vx,vy,vz);
361 
363  iEvent.getByToken(srcTracks_,tracks);
364  int nTracks = 0;
365 
366  double trackCounter = 0;
367  double trackCounterEta = 0;
368  double trackCounterEtaPt = 0;
369 
370  for(unsigned int i = 0 ; i < tracks->size(); ++i){
371  const Track& track = (*tracks)[i];
372  if(useQuality_ && !track.quality(trackQuality_)) continue;
373 
374  if( track.pt() > trackPtCut_) trackCounter++;
375  if(std::abs(track.eta())<trackEtaCut_) {
376  trackCounterEta++;
377  if (track.pt() > trackPtCut_) trackCounterEtaPt++;
378  }
379 
380  math::XYZPoint v1(vx,vy, vz);
381  double dz= track.dz(v1);
382  double dzsigma2 = track.dzError()*track.dzError()+vzError*vzError;
383  double dxy= track.dxy(v1);
384  double dxysigma2 = track.dxyError()*track.dxyError()+vxError*vyError;
385 
386  const double pterrcut = 0.1;
387  const double dzrelcut = 3.0;
388  const double dxyrelcut = 3.0;
389 
390  if( track.quality(trackQuality_) &&
391  track.pt()>0.4 && std::abs(track.eta())<2.4 &&
392  track.ptError()/track.pt() < pterrcut &&
393  dz*dz < dzrelcut*dzrelcut * dzsigma2 &&
394  dxy*dxy < dxyrelcut*dxyrelcut * dxysigma2 ){
395  nTracks++;
396  }
397  }
398 
399  creco->trackMultiplicity_ = nTracks;
400  creco->ntracksPtCut_ = trackCounter;
401  creco->ntracksEtaCut_ = trackCounterEta;
402  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
403 
404  }else{
405  if(reuseAny_){
406  creco->trackMultiplicity_ = inputCentrality->Ntracks();
407  creco->ntracksPtCut_= inputCentrality->NtracksPtCut();
408  creco->ntracksEtaCut_= inputCentrality->NtracksEtaCut();
409  creco->ntracksEtaPtCut_= inputCentrality->NtracksEtaPtCut();
410  }
411  }
412 
413  if(producePixelTracks_){
414  Handle<TrackCollection> pixeltracks;
415  iEvent.getByToken(srcPixelTracks_,pixeltracks);
416  int nPixelTracks = pixeltracks->size();
417  creco->nPixelTracks_ = nPixelTracks;
418  }
419  else{
420  if(reuseAny_){
421  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
422  }
423  }
424 
425  if(produceZDChits_){
426  creco->zdcSumPlus_ = 0;
427  creco->zdcSumMinus_ = 0;
428 
430  bool zdcAvailable = iEvent.getByToken(srcZDChits_,hits);
431  if(zdcAvailable){
432  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
433  const ZDCRecHit & rechit = (*hits)[ ihit ];
434  if(rechit.id().zside() > 0 ) {
435  if(lowGainZDC_){
436  creco->zdcSumPlus_ += rechit.lowGainEnergy();
437  }else{
438  creco->zdcSumPlus_ += rechit.energy();
439  }
440  }
441  if(rechit.id().zside() < 0) {
442  if(lowGainZDC_){
443  creco->zdcSumMinus_ += rechit.lowGainEnergy();
444  }else{
445  creco->zdcSumMinus_ += rechit.energy();
446  }
447  }
448  }
449  }else{
450  creco->zdcSumPlus_ = -9;
451  creco->zdcSumMinus_ = -9;
452  }
453  }else{
454  if(reuseAny_){
455  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
456  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
457  }
458  }
459 
460  iEvent.put(std::move(creco));
461 
462 }
463 
464 // ------------ method called once each job just before starting event loop ------------
465 void
467 {
468 }
469 
470 // ------------ method called once each job just after ending the event loop ------------
471 void
472 CentralityProducer::endJob()
473 {
474 }
475 
476 
477 //define this as a plug-in
479 
480 }
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:136
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< EcalRecHitCollection > srcEBhits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::EDGetTokenT< Centrality > reuseTag_
TrackQuality
track quality
Definition: TrackBase.h:151
double dxyError() const
error on dxy
Definition: TrackBase.h:796
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:15
edm::EDGetTokenT< CaloTowerCollection > srcTowers_
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
float energy() const
Definition: CaloRecHit.h:17
double pt() const
track transverse momentum
Definition: TrackBase.h:621
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:763
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
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:609
double dzError() const
error on dz
Definition: TrackBase.h:814
Definition: DetId.h:18
DetId id() const
get the id
Definition: EcalRecHit.h:77
T const * product() const
Definition: Handle.h:81
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
const T & get() const
Definition: EventSetup.h:59
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:510
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
size_type size() const
edm::EDGetTokenT< TrackCollection > srcPixelTracks_
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:23
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:591
def move(src, dest)
Definition: eostools.py:510
const_iterator begin(bool update=false) const
Our base class.
Definition: SiPixelRecHit.h:23
iterator begin()
Definition: DetSetNew.h:67