CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronSeedProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ElectronProducers
4 // Class: ElectronSeedProducer
5 //
13 //
14 // Original Author: Ursula Berthon, Claude Charlot
15 // Created: Mon Mar 27 13:22:06 CEST 2006
16 //
17 //
18 
19 #include "ElectronSeedProducer.h"
20 
22 //#include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
23 
28 
33 
38 
46 
47 #include <string>
48 
49 using namespace reco ;
50 
52  : //conf_(iConfig),
53  applyHOverECut_(true), hcalHelper_(0),
54  caloGeom_(0), caloGeomCacheId_(0), caloTopo_(0), caloTopoCacheId_(0)
55  {
56  conf_ = iConfig.getParameter<edm::ParameterSet>("SeedConfiguration") ;
57 
58  initialSeeds_ = consumes<TrajectorySeedCollection>(conf_.getParameter<edm::InputTag>("initialSeeds")) ;
59  SCEtCut_ = conf_.getParameter<double>("SCEtCut") ;
60  fromTrackerSeeds_ = conf_.getParameter<bool>("fromTrackerSeeds") ;
61  prefilteredSeeds_ = conf_.getParameter<bool>("preFilteredSeeds") ;
62 
63  // new beamSpot tag
64  if (conf_.exists("beamSpot")) {
65  beamSpotTag_ = consumes<reco::BeamSpot>(conf_.getParameter<edm::InputTag>("beamSpot"));
66  } else {
67  beamSpotTag_ = consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
68  }
69 
70  // for H/E
71 // if (conf_.exists("applyHOverECut"))
72 // { applyHOverECut_ = conf_.getParameter<bool>("applyHOverECut") ; }
73  applyHOverECut_ = conf_.getParameter<bool>("applyHOverECut") ;
74  if (applyHOverECut_)
75  {
77  hcalCfg.hOverEConeSize = conf_.getParameter<double>("hOverEConeSize") ;
78  if (hcalCfg.hOverEConeSize>0)
79  {
80  hcalCfg.useTowers = true ;
81  hcalCfg.hcalTowers =
82  consumes<CaloTowerCollection>(conf_.getParameter<edm::InputTag>("hcalTowers")) ;
83  hcalCfg.hOverEPtMin = conf_.getParameter<double>("hOverEPtMin") ;
84  }
85  hcalHelper_ = new ElectronHcalHelper(hcalCfg) ;
86  maxHOverEBarrel_=conf_.getParameter<double>("maxHOverEBarrel") ;
87  maxHOverEEndcaps_=conf_.getParameter<double>("maxHOverEEndcaps") ;
88  maxHBarrel_=conf_.getParameter<double>("maxHBarrel") ;
89  maxHEndcaps_=conf_.getParameter<double>("maxHEndcaps") ;
90 // hOverEConeSize_=conf_.getParameter<double>("hOverEConeSize") ;
91 // hOverEHBMinE_=conf_.getParameter<double>("hOverEHBMinE") ;
92 // hOverEHFMinE_=conf_.getParameter<double>("hOverEHFMinE") ;
93  }
94 
95  if( conf_.exists("RegionPSet") ) {
96  edm::ParameterSet rpset =
97  conf_.getParameter<edm::ParameterSet>("RegionPSet");
98  filterVtxTag_ =
99  consumes<std::vector<reco::Vertex> >(rpset.getParameter<edm::InputTag> ("VertexProducer"));
100  }
101 
103  esg_tokens.token_bs = beamSpotTag_;
104  if(conf_.exists("vertices")) {
105  esg_tokens.token_vtx =
106  mayConsume<reco::VertexCollection>(conf_.getParameter<edm::InputTag>("vertices"));
107  } else {
108  esg_tokens.token_vtx =
109  mayConsume<reco::VertexCollection>(edm::InputTag("offlinePrimaryVerticesWithBS"));
110  }
111  matcher_ = new ElectronSeedGenerator(conf_,esg_tokens) ;
112 
113  // get collections from config'
114  superClusters_[0]=
115  consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("barrelSuperClusters")) ;
116  superClusters_[1]=
117  consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("endcapSuperClusters")) ;
118 
119  // Construction of SeedFilter was in beginRun() with the comment
120  // below, but it has to be done here because of ConsumesCollector
121  //
122  // FIXME: because of a bug presumably in tracker seeding,
123  // perhaps in CombinedHitPairGenerator, badly caching some EventSetup product,
124  // we must redo the SeedFilter for each run.
125  if (prefilteredSeeds_) {
126  SeedFilter::Tokens sf_tokens;
127  sf_tokens.token_bs = beamSpotTag_;
128  sf_tokens.token_vtx = filterVtxTag_;
130  seedFilter_.reset(new SeedFilter(conf_, sf_tokens, iC));
131  }
132 
133  //register your products
134  produces<ElectronSeedCollection>() ;
135 }
136 
137 
139 }
140 
142  {
143  }
144 
146  {
147  delete hcalHelper_ ;
148  delete matcher_ ;
149  }
150 
152  {
153  LogDebug("ElectronSeedProducer") <<"[ElectronSeedProducer::produce] entering " ;
154 
155  edm::Handle<reco::BeamSpot> theBeamSpot ;
156  e.getByToken(beamSpotTag_,theBeamSpot) ;
157 
158  if (hcalHelper_)
159  {
160  hcalHelper_->checkSetup(iSetup) ;
161  hcalHelper_->readEvent(e) ;
162  }
163 
164  // get calo geometry
166  iSetup.get<CaloGeometryRecord>().get(caloGeom_);
167  caloGeomCacheId_=iSetup.get<CaloGeometryRecord>().cacheIdentifier();
168  }
170  caloTopoCacheId_=iSetup.get<CaloTopologyRecord>().cacheIdentifier();
171  iSetup.get<CaloTopologyRecord>().get(caloTopo_);
172  }
173 
174  matcher_->setupES(iSetup);
175 
176  // get initial TrajectorySeeds if necessary
177  if (fromTrackerSeeds_)
178  {
179  if (!prefilteredSeeds_)
180  {
182  e.getByToken(initialSeeds_, hSeeds);
183  theInitialSeedColl = const_cast<TrajectorySeedCollection *> (hSeeds.product());
184  }
185  else
187  }
188  else
189  { theInitialSeedColl = 0 ; } // not needed in this case
190 
192 
193  // loop over barrel + endcap
194  for (unsigned int i=0; i<2; i++) {
196  e.getByToken(superClusters_[i],clusters);
197  SuperClusterRefVector clusterRefs ;
198  std::vector<float> hoe1s, hoe2s ;
199  filterClusters(*theBeamSpot,clusters,/*mhbhe_,*/clusterRefs,hoe1s,hoe2s);
201  { filterSeeds(e,iSetup,clusterRefs) ; }
202  matcher_->run(e,iSetup,clusterRefs,hoe1s,hoe2s,theInitialSeedColl,*seeds);
203  }
204 
205  // store the accumulated result
206  std::auto_ptr<ElectronSeedCollection> pSeeds(seeds) ;
207  ElectronSeedCollection::iterator is ;
208  for ( is=pSeeds->begin() ; is!=pSeeds->end() ; is++ ) {
209  edm::RefToBase<CaloCluster> caloCluster = is->caloCluster() ;
210  SuperClusterRef superCluster = caloCluster.castTo<SuperClusterRef>() ;
211  LogDebug("ElectronSeedProducer")
212  << "new seed with "
213  << (*is).nHits() << " hits"
214  << ", charge " << (*is).getCharge()
215  << " and cluster energy " << superCluster->energy()
216  << " PID "<<superCluster.id() ;
217  }
218  e.put(pSeeds) ;
220  }
221 
222 
223 //===============================
224 // Filter the superclusters
225 // - with EtCut
226 // - with HoE using calo cone
227 //===============================
228 
230  ( const reco::BeamSpot & bs,
231  const edm::Handle<reco::SuperClusterCollection> & superClusters,
232  /*HBHERecHitMetaCollection * mhbhe,*/ SuperClusterRefVector & sclRefs,
233  std::vector<float> & hoe1s, std::vector<float> & hoe2s )
234  {
235  for (unsigned int i=0;i<superClusters->size();++i)
236  {
237  const SuperCluster & scl = (*superClusters)[i] ;
238  double sclEta = EleRelPoint(scl.position(),bs.position()).eta() ;
239  if (scl.energy()/cosh(sclEta)>SCEtCut_)
240  {
241 // if ((applyHOverECut_==true)&&((hcalHelper_->hcalESum(scl)/scl.energy()) > maxHOverE_))
242 // { continue ; }
243 // sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
244  double had1, had2, had, scle ;
245  bool HoeVeto = false ;
246  if (applyHOverECut_==true)
247  {
248  had1 = hcalHelper_->hcalESumDepth1(scl);
249  had2 = hcalHelper_->hcalESumDepth2(scl);
250  had = had1+had2 ;
251  scle = scl.energy() ;
252  int detector = scl.seed()->hitsAndFractions()[0].first.subdetId() ;
253  if (detector==EcalBarrel && (had<maxHBarrel_ || had/scle<maxHOverEBarrel_)) HoeVeto=true;
254  else if (detector==EcalEndcap && (had<maxHEndcaps_ || had/scle<maxHOverEEndcaps_)) HoeVeto=true;
255  if (HoeVeto)
256  {
257  sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
258  hoe1s.push_back(had1/scle) ;
259  hoe2s.push_back(had2/scle) ;
260  }
261  }
262  else
263  {
264  sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
265  hoe1s.push_back(std::numeric_limits<float>::infinity()) ;
266  hoe2s.push_back(std::numeric_limits<float>::infinity()) ;
267  }
268  }
269  }
270  LogDebug("ElectronSeedProducer")<<"Filtered out "<<sclRefs.size()<<" superclusters from "<<superClusters->size() ;
271  }
272 
275  reco::SuperClusterRefVector & sclRefs )
276  {
277  for ( unsigned int i=0 ; i<sclRefs.size() ; ++i )
278  {
279  seedFilter_->seeds(event,setup,sclRefs[i],theInitialSeedColl) ;
280  LogDebug("ElectronSeedProducer")<<"Number of Seeds: "<<theInitialSeedColl->size() ;
281  }
282  }
#define LogDebug(id)
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:124
int i
Definition: DBlmapReader.cc:9
virtual void endRun(edm::Run const &, edm::EventSetup const &) overridefinal
edm::EDGetTokenT< reco::BeamSpot > token_bs
void readEvent(const edm::Event &)
void setupES(const edm::EventSetup &setup)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void beginRun(edm::Run const &, edm::EventSetup const &) overridefinal
unsigned long long caloGeomCacheId_
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< std::vector< reco::Vertex > > filterVtxTag_
void checkSetup(const edm::EventSetup &)
edm::EDGetTokenT< TrajectorySeedCollection > initialSeeds_
T eta() const
void run(edm::Event &, const edm::EventSetup &setup, const reco::SuperClusterRefVector &, const std::vector< float > &hoe1s, const std::vector< float > &hoe2s, TrajectorySeedCollection *seeds, reco::ElectronSeedCollection &)
edm::ESHandle< CaloTopology > caloTopo_
void filterClusters(const reco::BeamSpot &bs, const edm::Handle< reco::SuperClusterCollection > &superClusters, reco::SuperClusterRefVector &sclRefs, std::vector< float > &hoe1s, std::vector< float > &hoe2s)
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const double infinity
ElectronSeedProducer(const edm::ParameterSet &)
double energy() const
cluster energy
Definition: CaloCluster.h:120
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::unique_ptr< SeedFilter > seedFilter_
edm::ParameterSet conf_
edm::ESHandle< CaloGeometry > caloGeom_
ElectronSeedGenerator * matcher_
TrajectorySeedCollection * theInitialSeedColl
const T & get() const
Definition: EventSetup.h:55
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:241
edm::EDGetTokenT< reco::SuperClusterCollection > superClusters_[2]
T const * product() const
Definition: Handle.h:81
unsigned long long caloTopoCacheId_
edm::EDGetTokenT< reco::BeamSpot > token_bs
Definition: SeedFilter.h:34
void filterSeeds(edm::Event &e, const edm::EventSetup &setup, reco::SuperClusterRefVector &sclRefs)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
edm::EDGetTokenT< CaloTowerCollection > hcalTowers
const Point & position() const
position
Definition: BeamSpot.h:62
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
volatile std::atomic< bool > shutdown_flag false
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
edm::EDGetTokenT< std::vector< reco::Vertex > > token_vtx
ElectronHcalHelper * hcalHelper_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::EDGetTokenT< std::vector< reco::Vertex > > token_vtx
Definition: SeedFilter.h:33
Definition: Run.h:41
virtual void produce(edm::Event &, const edm::EventSetup &) overridefinal