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 //
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 
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&);
58 
59  private:
60  virtual void beginJob() ;
61  virtual void produce(edm::Event&, const edm::EventSetup&);
62  virtual void endJob() ;
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 
96 
98 
101 
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_ = iConfig.getParameter<edm::InputTag>("srcHFhits");
137  if(produceHFtowers_ || produceETmidRap_) srcTowers_ = iConfig.getParameter<edm::InputTag>("srcTowers");
138 
139  if(produceEcalhits_){
140  srcEBhits_ = iConfig.getParameter<edm::InputTag>("srcEBhits");
141  srcEEhits_ = iConfig.getParameter<edm::InputTag>("srcEEhits");
142  }
143  if(produceZDChits_){
144  srcZDChits_ = iConfig.getParameter<edm::InputTag>("srcZDChits");
145  lowGainZDC_ = iConfig.getUntrackedParameter<bool>("lowGainZDC",0);
146  }
147  if(producePixelhits_){
148  srcPixelhits_ = iConfig.getParameter<edm::InputTag>("srcPixelhits");
149  doPixelCut_ = iConfig.getParameter<bool>("doPixelCut");
150  srcVertex_ = iConfig.getParameter<edm::InputTag>("srcVertex");
151  }
152  if(produceTracks_) {
153  srcTracks_ = iConfig.getParameter<edm::InputTag>("srcTracks");
154  srcVertex_ = iConfig.getParameter<edm::InputTag>("srcVertex");
155  }
156  if(producePixelTracks_) srcPixelTracks_ = iConfig.getParameter<edm::InputTag>("srcPixelTracks");
157 
158  reuseAny_ = iConfig.getParameter<bool>("reUseCentrality");
159  if(reuseAny_) reuseTag_ = iConfig.getParameter<edm::InputTag>("srcReUse");
160 
161  useQuality_ = iConfig.getParameter<bool>("UseQuality");
162  trackQuality_ = TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
163 
164  produces<reco::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 
190  std::auto_ptr<Centrality> creco(new Centrality());
191  Handle<Centrality> inputCentrality;
192 
193  if(reuseAny_) iEvent.getByLabel(reuseTag_,inputCentrality);
194 
195  if(produceHFhits_){
196  creco->etHFhitSumPlus_ = 0;
197  creco->etHFhitSumMinus_ = 0;
198 
200  iEvent.getByLabel(srcHFhits_,hits);
201  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
202  const HFRecHit & rechit = (*hits)[ ihit ];
203  if(rechit.id().ieta() > 0 )
204  creco->etHFhitSumPlus_ += rechit.energy();
205  if(rechit.id().ieta() < 0)
206  creco->etHFhitSumMinus_ += rechit.energy();
207  }
208  }else{
209  if(reuseAny_){
210  creco->etHFhitSumMinus_ = inputCentrality->EtHFhitSumMinus();
211  creco->etHFhitSumPlus_ = inputCentrality->EtHFhitSumPlus();
212  }
213  }
214 
215  if(produceHFtowers_ || produceETmidRap_){
216  creco->etHFtowerSumPlus_ = 0;
217  creco->etHFtowerSumMinus_ = 0;
218  creco->etMidRapiditySum_ = 0;
219 
221 
222  iEvent.getByLabel(srcTowers_,towers);
223 
224  for( size_t i = 0; i<towers->size(); ++ i){
225  const CaloTower & tower = (*towers)[ i ];
226  double eta = tower.eta();
227  bool isHF = tower.ietaAbs() > 29;
228  if(produceHFtowers_){
229  if(isHF && eta > 0){
230  creco->etHFtowerSumPlus_ += tower.pt();
231  if(eta > hfEtaCut_) creco->etHFtruncatedPlus_ += tower.pt();
232  }
233  if(isHF && eta < 0){
234  creco->etHFtowerSumMinus_ += tower.pt();
235  if(eta < -hfEtaCut_) creco->etHFtruncatedMinus_ += tower.pt();
236  }
237  }else{
238  if(reuseAny_){
239  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
240  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
241  creco->etHFtruncatedMinus_ = inputCentrality->EtHFtruncatedMinus();
242  creco->etHFtruncatedPlus_ = inputCentrality->EtHFtruncatedPlus();
243  }
244  }
245  if(produceETmidRap_){
246  if(fabs(eta) < midRapidityRange_) creco->etMidRapiditySum_ += tower.pt()/(midRapidityRange_*2.);
247  }else if(reuseAny_) creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
248  }
249  }else{
250  if(reuseAny_){
251  creco->etHFtowerSumMinus_ = inputCentrality->EtHFtowerSumMinus();
252  creco->etHFtowerSumPlus_ = inputCentrality->EtHFtowerSumPlus();
253  creco->etMidRapiditySum_ = inputCentrality->EtMidRapiditySum();
254  }
255  }
256 
257  if(produceEcalhits_){
258  creco->etEESumPlus_ = 0;
259  creco->etEESumMinus_ = 0;
260  creco->etEBSum_ = 0;
261 
264 
265  iEvent.getByLabel(srcEBhits_,ebHits);
266  iEvent.getByLabel(srcEEhits_,eeHits);
267 
268  for(unsigned int i = 0; i < ebHits->size(); ++i){
269  const EcalRecHit & hit= (*ebHits)[i];
270  const GlobalPoint& pos=cGeo->getPosition(hit.id());
271  double et = hit.energy()*sin(pos.theta());
272  creco->etEBSum_ += et;
273  }
274 
275  for(unsigned int i = 0; i < eeHits->size(); ++i){
276  const EcalRecHit & hit= (*eeHits)[i];
277  const GlobalPoint& pos=cGeo->getPosition(hit.id());
278  double et = hit.energy()*sin(pos.theta());
279  double eta = pos.eta();
280  if(eta > 0){
281  creco->etEESumPlus_ += et;
282  }else{
283  creco->etEESumMinus_ += et;
284  }
285  }
286  }else{
287  if(reuseAny_){
288  creco->etEESumMinus_ = inputCentrality->EtEESumMinus();
289  creco->etEESumPlus_ = inputCentrality->EtEESumPlus();
290  creco->etEBSum_ = inputCentrality->EtEBSum();
291  }
292  }
293 
294  if(producePixelhits_){
295  creco->pixelMultiplicity_ = 0;
298  iEvent.getByLabel(srcPixelhits_,rchts);
299  rechits = rchts.product();
300  int nPixel =0 ;
301  for (SiPixelRecHitCollection::const_iterator it = rechits->begin(); it!=rechits->end();it++)
302  {
304  DetId detId = DetId(hits.detId());
305  SiPixelRecHitCollection::const_iterator recHitMatch = rechits->find(detId);
306  const SiPixelRecHitCollection::DetSet recHitRange = *recHitMatch;
307  for ( SiPixelRecHitCollection::DetSet::const_iterator recHitIterator = recHitRange.begin();
308  recHitIterator != recHitRange.end(); ++recHitIterator) {
309  // add selection if needed, now all hits.
310  if(doPixelCut_){
311  const SiPixelRecHit * recHit = &(*recHitIterator);
312  const PixelGeomDetUnit* pixelLayer = dynamic_cast<const PixelGeomDetUnit*> (tGeo->idToDet(recHit->geographicalId()));
313  GlobalPoint gpos = pixelLayer->toGlobal(recHit->localPosition());
314  math::XYZVector rechitPos(gpos.x(),gpos.y(),gpos.z());
315  double abeta = fabs(rechitPos.eta());
316  int clusterSize = recHit->cluster()->size();
317  if ( abeta < 0.5 && clusterSize < 1) continue;
318  if ( abeta > 0.5 && abeta < 1 && clusterSize < 2) continue;
319  if ( abeta > 1. && abeta < 1.5 && clusterSize < 3) continue;
320  if ( abeta > 1.5 && abeta < 2. && clusterSize < 4) continue;
321  if ( abeta > 2. && abeta < 2.5 && clusterSize < 6) continue;
322  if ( abeta > 2.5 && abeta < 5 && clusterSize < 9) continue;
323  }
324  nPixel++;
325  }
326  }
327  creco->pixelMultiplicity_ = nPixel;
328  }else{
329  if(reuseAny_){
330  creco->pixelMultiplicity_ = inputCentrality->multiplicityPixel();
331  }
332  }
333 
334  if(produceTracks_){
335 
336  double vx=-999.;
337  double vy=-999.;
338  double vz=-999.;
339  double vxError=-999.;
340  double vyError=-999.;
341  double vzError=-999.;
342  math::XYZVector vtxPos(0,0,0);
343 
345  iEvent.getByLabel(srcVertex_,recoVertices);
346  unsigned int daughter = 0;
347  int greatestvtx = 0;
348 
349  for (unsigned int i = 0 ; i< recoVertices->size(); ++i){
350  daughter = (*recoVertices)[i].tracksSize();
351  if( daughter > (*recoVertices)[greatestvtx].tracksSize()) greatestvtx = i;
352  }
353 
354  if(recoVertices->size()>0){
355  vx = (*recoVertices)[greatestvtx].position().x();
356  vy = (*recoVertices)[greatestvtx].position().y();
357  vz = (*recoVertices)[greatestvtx].position().z();
358  vxError = (*recoVertices)[greatestvtx].xError();
359  vyError = (*recoVertices)[greatestvtx].yError();
360  vzError = (*recoVertices)[greatestvtx].zError();
361  }
362 
363  vtxPos = math::XYZVector(vx,vy,vz);
364 
366  iEvent.getByLabel(srcTracks_,tracks);
367  int nTracks = 0;
368 
369  double trackCounter = 0;
370  double trackCounterEta = 0;
371  double trackCounterEtaPt = 0;
372 
373  for(unsigned int i = 0 ; i < tracks->size(); ++i){
374  const Track& track = (*tracks)[i];
375  if(useQuality_ && !track.quality(trackQuality_)) continue;
376 
377  if( track.pt() > trackPtCut_) trackCounter++;
378  if(fabs(track.eta())<trackEtaCut_) {
379  trackCounterEta++;
380  if (track.pt() > trackPtCut_) trackCounterEtaPt++;
381  }
382 
383  math::XYZPoint v1(vx,vy, vz);
384  double dz= track.dz(v1);
385  double dzsigma = sqrt(track.dzError()*track.dzError()+vzError*vzError);
386  double dxy= track.dxy(v1);
387  double dxysigma = sqrt(track.dxyError()*track.dxyError()+vxError*vyError);
388  if( track.quality(trackQuality_) && track.pt()>0.4 && fabs(track.eta())<2.4 && track.ptError()/track.pt()<0.1 && fabs(dz/dzsigma)<3.0 && fabs(dxy/dxysigma)<3.0) nTracks++;
389 
390  }
391 
392  creco->trackMultiplicity_ = nTracks;
393  creco->ntracksPtCut_ = trackCounter;
394  creco->ntracksEtaCut_ = trackCounterEta;
395  creco->ntracksEtaPtCut_ = trackCounterEtaPt;
396 
397  }else{
398  if(reuseAny_){
399  creco->trackMultiplicity_ = inputCentrality->Ntracks();
400  creco->ntracksPtCut_= inputCentrality->NtracksPtCut();
401  creco->ntracksEtaCut_= inputCentrality->NtracksEtaCut();
402  creco->ntracksEtaPtCut_= inputCentrality->NtracksEtaPtCut();
403  }
404  }
405 
406  if(producePixelTracks_){
408  iEvent.getByLabel(srcPixelTracks_,pixeltracks);
409  int nPixelTracks = pixeltracks->size();
410  creco->nPixelTracks_ = nPixelTracks;
411  }
412  else{
413  if(reuseAny_){
414  creco->nPixelTracks_ = inputCentrality->NpixelTracks();
415  }
416  }
417 
418  if(produceZDChits_){
419  creco->zdcSumPlus_ = 0;
420  creco->zdcSumMinus_ = 0;
421 
423  bool zdcAvailable = iEvent.getByLabel(srcZDChits_,hits);
424  if(zdcAvailable){
425  for( size_t ihit = 0; ihit<hits->size(); ++ ihit){
426  const ZDCRecHit & rechit = (*hits)[ ihit ];
427  if(rechit.id().zside() > 0 ) {
428  if(lowGainZDC_){
429  creco->zdcSumPlus_ += rechit.lowGainEnergy();
430  }else{
431  creco->zdcSumPlus_ += rechit.energy();
432  }
433  }
434  if(rechit.id().zside() < 0) {
435  if(lowGainZDC_){
436  creco->zdcSumMinus_ += rechit.lowGainEnergy();
437  }else{
438  creco->zdcSumMinus_ += rechit.energy();
439  }
440  }
441  }
442  }else{
443  creco->zdcSumPlus_ = -9;
444  creco->zdcSumMinus_ = -9;
445  }
446  }else{
447  if(reuseAny_){
448  creco->zdcSumMinus_ = inputCentrality->zdcSumMinus();
449  creco->zdcSumPlus_ = inputCentrality->zdcSumPlus();
450  }
451  }
452 
453  iEvent.put(creco);
454 
455 }
456 
457 // ------------ method called once each job just before starting event loop ------------
458 void
460 {
461 }
462 
463 // ------------ method called once each job just after ending the event loop ------------
464 void
465 CentralityProducer::endJob()
466 {
467 }
468 
469 
470 //define this as a plug-in
472 
473 }
reco::TrackBase::TrackQuality trackQuality_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T 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
double dxyError() const
error on dxy
Definition: TrackBase.h:209
#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
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
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
virtual double eta() const
momentum pseudorapidity
void beginJob()
Definition: Breakpoints.cc:15
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:85
float energy() const
Definition: CaloRecHit.h:19
T sqrt(T t)
Definition: SSEVec.h:46
double pt() const
track transverse momentum
Definition: TrackBase.h:131
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:194
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
const_iterator end() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
float lowGainEnergy() const
Definition: ZDCRecHit.h:23
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:127
double dzError() const
error on dz
Definition: TrackBase.h:215
Definition: DetId.h:20
bool isHF(int etabin, int depth)
DetId id() const
get the id
Definition: EcalRecHit.h:76
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
virtual double pt() const
transverse momentum
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
id_type detId() const
Definition: DetSetNew.h:72
T const * product() const
Definition: Handle.h:74
edm::ESHandle< CaloGeometry > cGeo
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
HcalZDCDetId id() const
get the id
Definition: ZDCRecHit.h:21
edm::ESHandle< TrackerGeometry > tGeo
HcalDetId id() const
get the id
Definition: HFRecHit.h:21
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:121
Pixel Reconstructed Hit.
iterator begin()
Definition: DetSetNew.h:56