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 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 
24 // user include files
29 
34 
36 
46 
52 
53 using namespace std;
54 
55 //
56 // class declaration
57 //
58 namespace reco{
59 
61  public:
62  explicit CentralityProducer(const edm::ParameterSet&);
64 
65  private:
66  virtual void beginJob() override ;
67  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
68  virtual void endJob() override ;
69 
70  // ----------member data ---------------------------
71 
72  bool recoLevel_;
73 
74  bool doFilter_;
83  bool reuseAny_;
85 
87 
89  double trackPtCut_;
90  double trackEtaCut_;
91 
102 
104 
107 
110 
111 };
112 
113 //
114 // constants, enums and typedefs
115 //
116 
117 
118 //
119 // static data member definitions
120 //
121 
122 //
123 // constructors and destructor
124 //
125  CentralityProducer::CentralityProducer(const edm::ParameterSet& iConfig) :
126  trackGeo_(0),
127  caloGeo_(0)
128 {
129  //register your products
130  doFilter_ = iConfig.getParameter<bool>("doFilter");
131  produceHFhits_ = iConfig.getParameter<bool>("produceHFhits");
132  produceHFtowers_ = iConfig.getParameter<bool>("produceHFtowers");
133  produceBasicClusters_ = iConfig.getParameter<bool>("produceBasicClusters");
134  produceEcalhits_ = iConfig.getParameter<bool>("produceEcalhits");
135  produceZDChits_ = iConfig.getParameter<bool>("produceZDChits");
136  produceETmidRap_ = iConfig.getParameter<bool>("produceETmidRapidity");
137  producePixelhits_ = iConfig.getParameter<bool>("producePixelhits");
138  produceTracks_ = iConfig.getParameter<bool>("produceTracks");
139  producePixelTracks_ = iConfig.getParameter<bool>("producePixelTracks");
140 
141  midRapidityRange_ = iConfig.getParameter<double>("midRapidityRange");
142  trackPtCut_ = iConfig.getParameter<double>("trackPtCut");
143  trackEtaCut_ = iConfig.getParameter<double>("trackEtaCut");
144 
145  if(produceHFhits_) srcHFhits_ = iConfig.getParameter<edm::InputTag>("srcHFhits");
146  if(produceHFtowers_ || produceETmidRap_) srcTowers_ = iConfig.getParameter<edm::InputTag>("srcTowers");
147 
148  if(produceEcalhits_){
149  srcEBhits_ = iConfig.getParameter<edm::InputTag>("srcEBhits");
150  srcEEhits_ = iConfig.getParameter<edm::InputTag>("srcEEhits");
151  }
152  if(produceBasicClusters_){
153  srcBasicClustersEE_ = iConfig.getParameter<edm::InputTag>("srcBasicClustersEE");
154  srcBasicClustersEB_ = iConfig.getParameter<edm::InputTag>("srcBasicClustersEB");
155  }
156  if(produceZDChits_) srcZDChits_ = iConfig.getParameter<edm::InputTag>("srcZDChits");
157  if(producePixelhits_){
158  srcPixelhits_ = iConfig.getParameter<edm::InputTag>("srcPixelhits");
159  doPixelCut_ = iConfig.getParameter<bool>("doPixelCut");
160  }
161  if(produceTracks_) srcTracks_ = iConfig.getParameter<edm::InputTag>("srcTracks");
162  if(producePixelTracks_) srcPixelTracks_ = iConfig.getParameter<edm::InputTag>("srcPixelTracks");
163 
164  reuseAny_ = !produceHFhits_ || !produceHFtowers_ || !produceBasicClusters_ || !produceEcalhits_ || !produceZDChits_;
165  if(reuseAny_) reuseTag_ = iConfig.getParameter<edm::InputTag>("srcReUse");
166 
167  useQuality_ = iConfig.getParameter<bool>("UseQuality");
169 
170  produces<reco::Centrality>();
171 
172 }
173 
174 
176 {
177 
178  // do anything here that needs to be done at desctruction time
179  // (e.g. close files, deallocate resources etc.)
180 
181 }
182 
183 
184 //
185 // member functions
186 //
187 
188 // ------------ method called to produce the data ------------
189 bool
191 {
192  using namespace edm;
193  using namespace reco;
194 
195  if(!trackGeo_ && doPixelCut_){
197  iSetup.get<TrackerDigiGeometryRecord>().get(tGeo);
198  trackGeo_ = tGeo.product();
199  }
200 
201  if(!caloGeo_ && 0){
203  iSetup.get<CaloGeometryRecord>().get(cGeo);
204  caloGeo_ = cGeo.product();
205  }
206 
207  std::auto_ptr<Centrality> creco(new Centrality());
208  Handle<Centrality> inputCentrality;
209 
210  if(reuseAny_) iEvent.getByLabel(reuseTag_,inputCentrality);
211 
212  if(produceHFhits_){
213  creco->etHFhitSumPlus_ = 0;
214  creco->etHFhitSumMinus_ = 0;
215 
217  iEvent.getByLabel(srcHFhits_,hits);
218  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
219  const HFRecHit & rechit = (*hits)[ ihit ];
220  if(rechit.id().ieta() > 0 )
221  creco->etHFhitSumPlus_ += rechit.energy();
222  if(rechit.id().ieta() < 0)
223  creco->etHFhitSumMinus_ += rechit.energy();
224  }
225  }else{
226  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
227  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
228  }
229 
231  creco->etHFtowerSumPlus_ = 0;
232  creco->etHFtowerSumMinus_ = 0;
233  creco->etMidRapiditySum_ = 0;
234 
236 
237  iEvent.getByLabel(srcTowers_,towers);
238 
239  for( size_t i = 0; i<towers->size(); ++ i){
240  const CaloTower & tower = (*towers)[ i ];
241  double eta = tower.eta();
242  bool isHF = tower.ietaAbs() > 29;
243  if(produceHFtowers_){
244  if(isHF && eta > 0){
245  creco->etHFtowerSumPlus_ += tower.pt();
246  }
247  if(isHF && eta < 0){
248  creco->etHFtowerSumMinus_ += tower.pt();
249  }
250  }else{
251  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
252  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
253  }
254  if(produceETmidRap_){
255  if(fabs(eta) < midRapidityRange_) creco->etMidRapiditySum_ += tower.pt()/(midRapidityRange_*2.);
256  }else creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
257  }
258  }else{
259  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
260  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
261  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
262  }
263 
265  creco->etEESumPlus_ = 0;
266  creco->etEESumMinus_ = 0;
267  creco->etEBSum_ = 0;
268 
270  iEvent.getByLabel(srcBasicClustersEE_, clusters);
271  for( size_t i = 0; i<clusters->size(); ++ i){
272  const BasicCluster & cluster = (*clusters)[ i ];
273  double eta = cluster.eta();
274  double tg = cluster.position().rho()/cluster.position().r();
275  double et = cluster.energy()*tg;
276  if(eta > 0)
277  creco->etEESumPlus_ += et;
278  if(eta < 0)
279  creco->etEESumMinus_ += et;
280  }
281 
282  iEvent.getByLabel(srcBasicClustersEB_, clusters);
283  for( size_t i = 0; i<clusters->size(); ++ i){
284  const BasicCluster & cluster = (*clusters)[ i ];
285  double tg = cluster.position().rho()/cluster.position().r();
286  double et = cluster.energy()*tg;
287  creco->etEBSum_ += et;
288  }
289  }else{
290  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
291  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
292  creco->etEBSum_ = inputCentrality->EtEBSum();
293  }
294 
295  if(producePixelhits_){
296  creco->pixelMultiplicity_ = 0;
299  iEvent.getByLabel(srcPixelhits_,rchts);
300  rechits = rchts.product();
301  int nPixel =0 ;
302  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it!=rechits->end();it++)
303  {
305  DetId detId = DetId(hits.detId());
306  SiPixelRecHitCollection::const_iterator recHitMatch = rechits->find(detId);
307  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
308  for ( SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
309  recHitIterator != recHitRange.end(); ++recHitIterator) {
310  // add selection if needed, now all hits.
311  if(doPixelCut_){
312  const SiPixelRecHit * recHit = &(*recHitIterator);
313  const PixelGeomDetUnit* pixelLayer = dynamic_cast<const PixelGeomDetUnit*> (trackGeo_->idToDet(recHit->geographicalId()));
314  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
315  math::XYZVector rechitPos(gpos.x(),gpos.y(),gpos.z());
316  double abeta = fabs(rechitPos.eta());
317  int clusterSize = recHit->cluster()->size();
318  if ( abeta < 0.5 && clusterSize < 1) continue;
319  if ( abeta > 0.5 && abeta < 1 && clusterSize < 2) continue;
320  if ( abeta > 1. && abeta < 1.5 && clusterSize < 3) continue;
321  if ( abeta > 1.5 && abeta < 2. && clusterSize < 4) continue;
322  if ( abeta > 2. && abeta < 2.5 && clusterSize < 6) continue;
323  if ( abeta > 2.5 && abeta < 5 && clusterSize < 9) continue;
324  }
325  nPixel++;
326  }
327  }
328  creco->pixelMultiplicity_ = nPixel;
329  }else{
330  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
331  }
332 
333  if(produceTracks_){
335  iEvent.getByLabel(srcTracks_,tracks);
336  int nTracks = 0;
337 
338  double trackCounter = 0;
339  double trackCounterEta = 0;
340  double trackCounterEtaPt = 0;
341 
342  for(unsigned int i = 0 ; i < tracks->size(); ++i){
343  const Track& track = (*tracks)[i];
344  if(useQuality_ && !track.quality(trackQuality_)) continue;
345  nTracks++;
346 
347  if( track.pt() > trackPtCut_) trackCounter++;
348  if(fabs(track.eta())<trackEtaCut_) {
349  trackCounterEta++;
350  if (track.pt() > trackPtCut_) trackCounterEtaPt++;
351  }
352  }
353 
354  creco->trackMultiplicity_ = nTracks;
355  creco->ntracksPtCut_ = trackCounter;
356  creco->ntracksEtaCut_ = trackCounterEta;
357  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
358 
359  }else{
360  creco->trackMultiplicity_ = inputCentrality->Ntracks();
361  creco->ntracksPtCut_= inputCentrality->NtracksPtCut();
362  creco->ntracksEtaCut_= inputCentrality->NtracksEtaCut();
363  creco->ntracksEtaPtCut_= inputCentrality->NtracksEtaPtCut();
364  }
365 
368  iEvent.getByLabel(srcPixelTracks_,pixeltracks);
369  int nPixelTracks = pixeltracks->size();
370  creco->nPixelTracks_ = nPixelTracks;
371  }
372  else{
373  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
374  }
375 
376  if(produceZDChits_){
377  creco->zdcSumPlus_ = 0;
378  creco->zdcSumMinus_ = 0;
379 
381  bool zdcAvailable = iEvent.getByLabel(srcZDChits_,hits);
382  if(zdcAvailable){
383  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
384  const ZDCRecHit & rechit = (*hits)[ ihit ];
385  if(rechit.id().zside() > 0 )
386  creco->zdcSumPlus_ += rechit.energy();
387  if(rechit.id().zside() < 0)
388  creco->zdcSumMinus_ += rechit.energy();
389  }
390  }else{
391  creco->zdcSumPlus_ = -9;
392  creco->zdcSumMinus_ = -9;
393  }
394  }else{
395  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
396  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
397  }
398 
399  iEvent.put(creco);
400  return true;
401 }
402 
403 // ------------ method called once each job just before starting event loop ------------
404 void
406 {
407 }
408 
409 // ------------ method called once each job just after ending the event loop ------------
410 void
412 }
413 }
414 
415 //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 end(bool update=false) const
virtual float pt() const
transverse momentum
TrackQuality
track quality
Definition: TrackBase.h:93
#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:47
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:34
T eta() const
void beginJob()
Definition: Breakpoints.cc:15
virtual bool filter(edm::Event &, const edm::EventSetup &) override
const CaloGeometry * caloGeo_
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
float energy() const
Definition: CaloRecHit.h:17
virtual float eta() const
momentum pseudorapidity
double pt() const
track transverse momentum
Definition: TrackBase.h:129
int ieta() const
get the cell ieta
Definition: HcalDetId.h:36
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void beginJob() override
Definition: DetId.h:18
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:30
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
id_type detId() const
Definition: DetSetNew.h:83
T const * product() const
Definition: Handle.h:81
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:375
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
int ietaAbs() const
Definition: CaloTower.h:170
virtual void endJob() override
iterator end()
Definition: DetSetNew.h:70
const TrackerGeometry * trackGeo_
HcalZDCDetId id() const
get the id
Definition: ZDCRecHit.h:19
HcalDetId id() const
Definition: HFRecHit.h:23
DetId geographicalId() const
virtual LocalPoint localPosition() const
const_iterator begin(bool update=false) const
Our base class.
Definition: SiPixelRecHit.h:23
iterator begin()
Definition: DetSetNew.h:67