CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CentralityProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CentralityProducer
4 // Class: CentralityProducer
5 //
13 //
14 // Original Author: Yetkin Yilmaz, Young Soo Park
15 // Created: Wed Jun 11 15:31:41 CEST 2008
16 // $Id: CentralityProducer.cc,v 1.40 2012/12/26 23:38:37 wmtan Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <iostream>
24 
25 // user include files
30 
35 
37 
47 
53 
54 using namespace std;
55 
56 //
57 // class declaration
58 //
59 namespace reco{
60 
62  public:
63  explicit CentralityProducer(const edm::ParameterSet&);
65 
66  private:
67  virtual void beginJob() ;
68  virtual bool filter(edm::Event&, const edm::EventSetup&);
69  virtual void endJob() ;
70 
71  // ----------member data ---------------------------
72 
73  bool recoLevel_;
74 
75  bool doFilter_;
84  bool reuseAny_;
86 
88 
90  double trackPtCut_;
91  double trackEtaCut_;
92 
103 
105 
108 
111 
112 };
113 
114 //
115 // constants, enums and typedefs
116 //
117 
118 
119 //
120 // static data member definitions
121 //
122 
123 //
124 // constructors and destructor
125 //
126  CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig) :
127  trackGeo_(0),
128  caloGeo_(0)
129 {
130  //register your products
131  doFilter_ = iConfig.getParameter<bool>("doFilter");
132  produceHFhits_ = iConfig.getParameter<bool>("produceHFhits");
133  produceHFtowers_ = iConfig.getParameter<bool>("produceHFtowers");
134  produceBasicClusters_ = iConfig.getParameter<bool>("produceBasicClusters");
135  produceEcalhits_ = iConfig.getParameter<bool>("produceEcalhits");
136  produceZDChits_ = iConfig.getParameter<bool>("produceZDChits");
137  produceETmidRap_ = iConfig.getParameter<bool>("produceETmidRapidity");
138  producePixelhits_ = iConfig.getParameter<bool>("producePixelhits");
139  produceTracks_ = iConfig.getParameter<bool>("produceTracks");
140  producePixelTracks_ = iConfig.getParameter<bool>("producePixelTracks");
141 
142  midRapidityRange_ = iConfig.getParameter<double>("midRapidityRange");
143  trackPtCut_ = iConfig.getParameter<double>("trackPtCut");
144  trackEtaCut_ = iConfig.getParameter<double>("trackEtaCut");
145 
146  if(produceHFhits_) srcHFhits_ = iConfig.getParameter<edm::InputTag>("srcHFhits");
147  if(produceHFtowers_ || produceETmidRap_) srcTowers_ = iConfig.getParameter<edm::InputTag>("srcTowers");
148 
149  if(produceEcalhits_){
150  srcEBhits_ = iConfig.getParameter<edm::InputTag>("srcEBhits");
151  srcEEhits_ = iConfig.getParameter<edm::InputTag>("srcEEhits");
152  }
153  if(produceBasicClusters_){
154  srcBasicClustersEE_ = iConfig.getParameter<edm::InputTag>("srcBasicClustersEE");
155  srcBasicClustersEB_ = iConfig.getParameter<edm::InputTag>("srcBasicClustersEB");
156  }
157  if(produceZDChits_) srcZDChits_ = iConfig.getParameter<edm::InputTag>("srcZDChits");
158  if(producePixelhits_){
159  srcPixelhits_ = iConfig.getParameter<edm::InputTag>("srcPixelhits");
160  doPixelCut_ = iConfig.getParameter<bool>("doPixelCut");
161  }
162  if(produceTracks_) srcTracks_ = iConfig.getParameter<edm::InputTag>("srcTracks");
163  if(producePixelTracks_) srcPixelTracks_ = iConfig.getParameter<edm::InputTag>("srcPixelTracks");
164 
165  reuseAny_ = !produceHFhits_ || !produceHFtowers_ || !produceBasicClusters_ || !produceEcalhits_ || !produceZDChits_;
166  if(reuseAny_) reuseTag_ = iConfig.getParameter<edm::InputTag>("srcReUse");
167 
168  useQuality_ = iConfig.getParameter<bool>("UseQuality");
170 
171  produces<reco::Centrality>();
172 
173 }
174 
175 
177 {
178 
179  // do anything here that needs to be done at desctruction time
180  // (e.g. close files, deallocate resources etc.)
181 
182 }
183 
184 
185 //
186 // member functions
187 //
188 
189 // ------------ method called to produce the data ------------
190 bool
192 {
193  using namespace edm;
194  using namespace reco;
195 
196  if(!trackGeo_ && doPixelCut_){
198  iSetup.get<TrackerDigiGeometryRecord>().get(tGeo);
199  trackGeo_ = tGeo.product();
200  }
201 
202  if(!caloGeo_ && 0){
204  iSetup.get<CaloGeometryRecord>().get(cGeo);
205  caloGeo_ = cGeo.product();
206  }
207 
208  std::auto_ptr<Centrality> creco(new Centrality());
209  Handle<Centrality> inputCentrality;
210 
211  if(reuseAny_) iEvent.getByLabel(reuseTag_,inputCentrality);
212 
213  if(produceHFhits_){
214  creco->etHFhitSumPlus_ = 0;
215  creco->etHFhitSumMinus_ = 0;
216 
218  iEvent.getByLabel(srcHFhits_,hits);
219  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
220  const HFRecHit & rechit = (*hits)[ ihit ];
221  if(rechit.id().ieta() > 0 )
222  creco->etHFhitSumPlus_ += rechit.energy();
223  if(rechit.id().ieta() < 0)
224  creco->etHFhitSumMinus_ += rechit.energy();
225  }
226  }else{
227  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
228  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
229  }
230 
232  creco->etHFtowerSumPlus_ = 0;
233  creco->etHFtowerSumMinus_ = 0;
234  creco->etMidRapiditySum_ = 0;
235 
237 
238  iEvent.getByLabel(srcTowers_,towers);
239 
240  for( size_t i = 0; i<towers->size(); ++ i){
241  const CaloTower & tower = (*towers)[ i ];
242  double eta = tower.eta();
243  bool isHF = tower.ietaAbs() > 29;
244  if(produceHFtowers_){
245  if(isHF && eta > 0){
246  creco->etHFtowerSumPlus_ += tower.pt();
247  }
248  if(isHF && eta < 0){
249  creco->etHFtowerSumMinus_ += tower.pt();
250  }
251  }else{
252  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
253  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
254  }
255  if(produceETmidRap_){
256  if(fabs(eta) < midRapidityRange_) creco->etMidRapiditySum_ += tower.pt()/(midRapidityRange_*2.);
257  }else creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
258  }
259  }else{
260  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
261  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
262  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
263  }
264 
266  creco->etEESumPlus_ = 0;
267  creco->etEESumMinus_ = 0;
268  creco->etEBSum_ = 0;
269 
271  iEvent.getByLabel(srcBasicClustersEE_, clusters);
272  for( size_t i = 0; i<clusters->size(); ++ i){
273  const BasicCluster & cluster = (*clusters)[ i ];
274  double eta = cluster.eta();
275  double tg = cluster.position().rho()/cluster.position().r();
276  double et = cluster.energy()*tg;
277  if(eta > 0)
278  creco->etEESumPlus_ += et;
279  if(eta < 0)
280  creco->etEESumMinus_ += et;
281  }
282 
283  iEvent.getByLabel(srcBasicClustersEB_, clusters);
284  for( size_t i = 0; i<clusters->size(); ++ i){
285  const BasicCluster & cluster = (*clusters)[ i ];
286  double tg = cluster.position().rho()/cluster.position().r();
287  double et = cluster.energy()*tg;
288  creco->etEBSum_ += et;
289  }
290  }else{
291  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
292  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
293  creco->etEBSum_ = inputCentrality->EtEBSum();
294  }
295 
296  if(producePixelhits_){
297  creco->pixelMultiplicity_ = 0;
300  iEvent.getByLabel(srcPixelhits_,rchts);
301  rechits = rchts.product();
302  int nPixel =0 ;
303  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it!=rechits->end();it++)
304  {
306  DetId detId = DetId(hits.detId());
307  SiPixelRecHitCollection::const_iterator recHitMatch = rechits->find(detId);
308  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
309  for ( SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
310  recHitIterator != recHitRange.end(); ++recHitIterator) {
311  // add selection if needed, now all hits.
312  if(doPixelCut_){
313  const SiPixelRecHit * recHit = &(*recHitIterator);
314  const PixelGeomDetUnit* pixelLayer = dynamic_cast<const PixelGeomDetUnit*> (trackGeo_->idToDet(recHit->geographicalId()));
315  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
316  math::XYZVector rechitPos(gpos.x(),gpos.y(),gpos.z());
317  double abeta = fabs(rechitPos.eta());
318  int clusterSize = recHit->cluster()->size();
319  if ( abeta < 0.5 && clusterSize < 1) continue;
320  if ( abeta > 0.5 && abeta < 1 && clusterSize < 2) continue;
321  if ( abeta > 1. && abeta < 1.5 && clusterSize < 3) continue;
322  if ( abeta > 1.5 && abeta < 2. && clusterSize < 4) continue;
323  if ( abeta > 2. && abeta < 2.5 && clusterSize < 6) continue;
324  if ( abeta > 2.5 && abeta < 5 && clusterSize < 9) continue;
325  }
326  nPixel++;
327  }
328  }
329  creco->pixelMultiplicity_ = nPixel;
330  }else{
331  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
332  }
333 
334  if(produceTracks_){
336  iEvent.getByLabel(srcTracks_,tracks);
337  int nTracks = 0;
338 
339  double trackCounter = 0;
340  double trackCounterEta = 0;
341  double trackCounterEtaPt = 0;
342 
343  for(unsigned int i = 0 ; i < tracks->size(); ++i){
344  const Track& track = (*tracks)[i];
345  if(useQuality_ && !track.quality(trackQuality_)) continue;
346  nTracks++;
347 
348  if( track.pt() > trackPtCut_) trackCounter++;
349  if(fabs(track.eta())<trackEtaCut_) {
350  trackCounterEta++;
351  if (track.pt() > trackPtCut_) trackCounterEtaPt++;
352  }
353  }
354 
355  creco->trackMultiplicity_ = nTracks;
356  creco->ntracksPtCut_ = trackCounter;
357  creco->ntracksEtaCut_ = trackCounterEta;
358  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
359 
360  }else{
361  creco->trackMultiplicity_ = inputCentrality->Ntracks();
362  creco->ntracksPtCut_= inputCentrality->NtracksPtCut();
363  creco->ntracksEtaCut_= inputCentrality->NtracksEtaCut();
364  creco->ntracksEtaPtCut_= inputCentrality->NtracksEtaPtCut();
365  }
366 
369  iEvent.getByLabel(srcPixelTracks_,pixeltracks);
370  int nPixelTracks = pixeltracks->size();
371  creco->nPixelTracks_ = nPixelTracks;
372  }
373  else{
374  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
375  }
376 
377  if(produceZDChits_){
378  creco->zdcSumPlus_ = 0;
379  creco->zdcSumMinus_ = 0;
380 
382  bool zdcAvailable = iEvent.getByLabel(srcZDChits_,hits);
383  if(zdcAvailable){
384  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
385  const ZDCRecHit & rechit = (*hits)[ ihit ];
386  if(rechit.id().zside() > 0 )
387  creco->zdcSumPlus_ += rechit.energy();
388  if(rechit.id().zside() < 0)
389  creco->zdcSumMinus_ += rechit.energy();
390  }
391  }else{
392  creco->zdcSumPlus_ = -9;
393  creco->zdcSumMinus_ = -9;
394  }
395  }else{
396  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
397  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
398  }
399 
400  iEvent.put(creco);
401  return true;
402 }
403 
404 // ------------ method called once each job just before starting event loop ------------
405 void
407 {
408 }
409 
410 // ------------ method called once each job just after ending the event loop ------------
411 void
413 }
414 }
415 
416 //define this as a plug-in
reco::TrackBase::TrackQuality trackQuality_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin() const
TrackQuality
track quality
Definition: TrackBase.h:95
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:36
T eta() const
const_iterator find(id_type i) const
void beginJob()
Definition: Breakpoints.cc:15
const CaloGeometry * caloGeo_
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
float energy() const
Definition: CaloRecHit.h:19
virtual bool filter(edm::Event &, const edm::EventSetup &)
double pt() const
track transverse momentum
Definition: TrackBase.h:131
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
const_iterator end() const
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
Definition: DetId.h:20
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
bool isHF(int etabin, int depth)
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
id_type detId() const
Definition: DetSetNew.h:72
T const * product() const
Definition: Handle.h:74
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:377
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
int ietaAbs() const
Definition: CaloTower.h:155
iterator end()
Definition: DetSetNew.h:59
const TrackerGeometry * trackGeo_
HcalZDCDetId id() const
get the id
Definition: ZDCRecHit.h:21
HcalDetId id() const
Definition: HFRecHit.h:25
virtual float pt() const GCC11_FINAL
transverse momentum
Pixel Reconstructed Hit.
iterator begin()
Definition: DetSetNew.h:56