CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTNxNClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 //#include <iostream>
3 //#include <vector>
4 
5 // Reconstruction Classes
12 
21 
23 #include "TVector3.h"
24 
26  doBarrel_ (ps.getParameter<bool>("doBarrel")),
27  doEndcaps_ (ps.getParameter<bool>("doEndcaps")),
28  barrelHitProducer_ (consumes<EcalRecHitCollection>(ps.getParameter< edm::InputTag > ("barrelHitProducer"))),
29  endcapHitProducer_ (consumes<EcalRecHitCollection>(ps.getParameter< edm::InputTag > ("endcapHitProducer"))),
30  clusEtaSize_ (ps.getParameter<int> ("clusEtaSize")),
31  clusPhiSize_ (ps.getParameter<int> ("clusPhiSize")),
32  barrelClusterCollection_(ps.getParameter<std::string>("barrelClusterCollection")),
33  endcapClusterCollection_(ps.getParameter<std::string>("endcapClusterCollection")),
34  clusSeedThr_ (ps.getParameter<double> ("clusSeedThr")),
35  clusSeedThrEndCap_ (ps.getParameter<double> ("clusSeedThrEndCap")),
36  useRecoFlag_ (ps.getParameter<bool>("useRecoFlag")),
37  flagLevelRecHitsToUse_ (ps.getParameter<int>("flagLevelRecHitsToUse")),
38  useDBStatus_ (ps.getParameter<bool>("useDBStatus")),
39  statusLevelRecHitsToUse_(ps.getParameter<int>("statusLevelRecHitsToUse")),
40  maxNumberofSeeds_ (ps.getParameter<int> ("maxNumberofSeeds")),
41  maxNumberofClusters_ (ps.getParameter<int> ("maxNumberofClusters")),
42  debug_ (ps.getParameter<int> ("debugLevel")),
43  posCalculator_ (PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters"))) {
44 
45  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
46  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
47 }
48 
49 
51 {}
52 
54 
56  desc.add<bool>(("doBarrel"), true);
57  desc.add<bool>(("doEndcaps"), true);
58  desc.add<edm::InputTag>(("barrelHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEB"));
59  desc.add<edm::InputTag>(("endcapHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEE"));
60  desc.add<int>(("clusEtaSize"), 3);
61  desc.add<int>(("clusPhiSize"), 3);
62  desc.add<std::string>(("barrelClusterCollection"), "Simple3x3ClustersBarrel");
63  desc.add<std::string>(("endcapClusterCollection"), "Simple3x3ClustersEndcap");
64  desc.add<double>(("clusSeedThr"), 0.5);
65  desc.add<double>(("clusSeedThrEndCap"), 1.0);
66  desc.add<bool>(("useRecoFlag"), false);
67  desc.add<int>(("flagLevelRecHitsToUse"), 1);
68  desc.add<bool>(("useDBStatus"), true);
69  desc.add<int>(("statusLevelRecHitsToUse"), 1);
70 
71  edm::ParameterSetDescription posCalcPSET;
72  posCalcPSET.add<double>("T0_barl", 7.4);
73  posCalcPSET.add<double>("T0_endc", 3.1);
74  posCalcPSET.add<double>("T0_endcPresh", 1.2);
75  posCalcPSET.add<double>("W0", 4.2);
76  posCalcPSET.add<double>("X0", 0.89);
77  posCalcPSET.add<bool>("LogWeighted", true);
78  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
79 
80  desc.add<int>(("maxNumberofSeeds"), 1000);
81  desc.add<int>(("maxNumberofClusters"), 200);
82  desc.add<int>(("debugLevel"), 0);
83  descriptions.add(("hltEgammaHLTNxNClusterProducer"), desc);
84 }
85 
87 
88  if(doBarrel_) {
89  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
90  evt.getByToken(barrelHitProducer_, barrelRecHitsHandle);
91  if (!barrelRecHitsHandle.isValid()) {
92  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product eb hit!" << std::endl;
93  }
94 
95  const EcalRecHitCollection *hits_eb = barrelRecHitsHandle.product();
96  if( debug_>=2 )
97  LogDebug("")<<"EgammaHLTNxNClusterProducer nEBrechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_eb->size()<<std::endl;
98 
100 
101  }
102 
103 
104  if(doEndcaps_) {
105  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
106  evt.getByToken(endcapHitProducer_, endcapRecHitsHandle);
107  if (!endcapRecHitsHandle.isValid()) {
108  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product ee hit!" << std::endl;
109  }
110 
111  const EcalRecHitCollection *hits_ee = endcapRecHitsHandle.product();
112  if( debug_>=2 )
113  LogDebug("")<<"EgammaHLTNxNClusterProducer nEErechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_ee->size()<<std::endl;
115  }
116 }
117 
118 
119 
121 
122  if(useRecoFlag_ ){
123  int flag = rh.recoFlag();
124  if( flagLevelRecHitsToUse_ ==0){
125  if( flag != 0) return false;
126  }
127  else if( flagLevelRecHitsToUse_ ==1){
128  if( flag !=0 && flag != 4 ) return false;
129  }
130  else if( flagLevelRecHitsToUse_ ==2){
131  if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
132  }
133  }
134  if ( useDBStatus_){
135  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
136  if ( status > statusLevelRecHitsToUse_ ) return false;
137  }
138 
139  return true;
140 }
141 
142 
143 
144 
146  const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector)
147 {
148 
149 
152  if ( useDBStatus_ ) es.get<EcalChannelStatusRcd>().get(csHandle);
153  const EcalChannelStatus &channelStatus = *csHandle;
154 
155 
156  std::vector<EcalRecHit> seeds;
157 
158  double clusterSeedThreshold ;
159  if (detector == reco::CaloID::DET_ECAL_BARREL){
160  clusterSeedThreshold = clusSeedThr_;
161  }else{
162  clusterSeedThreshold = clusSeedThrEndCap_;
163  }
164 
165 
166  for(EcalRecHitCollection::const_iterator itt = hits->begin(); itt != hits->end(); itt++){
167  double energy = itt->energy();
168  if( ! checkStatusOfEcalRecHit(channelStatus, *itt) ) continue;
169  if (energy > clusterSeedThreshold ) seeds.push_back(*itt);
170 
171  if( int(seeds.size()) > maxNumberofSeeds_){ //too many seeds, like beam splash events
172  seeds.clear();
173  break;
174  }
175  }
176 
177  // get the geometry and topology from the event setup:
178  edm::ESHandle<CaloGeometry> geoHandle;
179  es.get<CaloGeometryRecord>().get(geoHandle);
180 
181  const CaloSubdetectorGeometry *geometry_p;
182  CaloSubdetectorTopology *topology_p;
183  if (detector == reco::CaloID::DET_ECAL_BARREL) {
184  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
185  topology_p = new EcalBarrelTopology(geoHandle);
186  }else {
187  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
188  topology_p = new EcalEndcapTopology(geoHandle);
189  }
190 
191  const CaloSubdetectorGeometry *geometryES_p;
192  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
193 
194 
195 
196  std::vector<reco::BasicCluster> clusters;
197  std::vector<DetId> usedXtals;
198 
199  // sort seed according to Energy
200  sort(seeds.begin(), seeds.end(), ecalRecHitSort());
201 
202 
203 
204  for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
205  DetId seed_id = itseed->id();
206  std::vector<DetId>::const_iterator usedIds;
207 
208  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),seed_id);
209  if(itdet != usedXtals.end()) continue;
210 
211  std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
212  std::vector<std::pair<DetId, float> > clus_used;
213 
214  float clus_energy = 0;
215 
216  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
217  DetId detid = *det;
218 
219  //not yet used
220  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),detid);
221  if(itdet != usedXtals.end()) continue;
222  //inside the collection
224  if( hit == hits->end()) continue;
225 
226  if( ! checkStatusOfEcalRecHit(channelStatus, *hit) ) continue;
227 
228  usedXtals.push_back(detid);
229  clus_used.push_back(std::pair<DetId, float>(detid, 1.) );
230  clus_energy += hit->energy();
231 
232  }
233 
234  if( clus_energy <= 0 ) continue;
235 
236  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hits,geometry_p,geometryES_p);
237 
238  if (debug_>=2 ) LogDebug("")<<"nxn_cluster in run "<< evt.id().run()<<" event "<<evt.id().event()<<" energy: "<<clus_energy <<" eta: "<< clus_pos.Eta()<<" phi: "<< clus_pos.Phi()<<" nRecHits: "<< clus_used.size() <<std::endl;
239 
240  clusters.push_back(reco::BasicCluster(clus_energy, clus_pos, reco::CaloID(detector), clus_used, reco::CaloCluster::island, seed_id));
241  if( int(clusters.size()) > maxNumberofClusters_){
242  clusters.clear();
243  break;
244  }
245 
246  }
247 
248 
249  //Create empty output collections
250  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
251  clusters_p->assign(clusters.begin(), clusters.end());
252  if (detector == reco::CaloID::DET_ECAL_BARREL){
253  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in barrel"<<std::endl;
254  evt.put(clusters_p, barrelClusterCollection_);
255  }
256  else {
257  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in endcap"<<std::endl;
258  evt.put(clusters_p, endcapClusterCollection_);
259  }
260 
261 }
262 
263 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
std::vector< EcalRecHit >::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
EgammaHLTNxNClusterProducer(const edm::ParameterSet &ps)
const edm::EDGetTokenT< EcalRecHitCollection > endcapHitProducer_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:75
const_iterator end() const
Definition: DetId.h:18
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
DetId id() const
get the id
Definition: EcalRecHit.h:76
T const * product() const
Definition: Handle.h:81
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.h:189
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
void produce(edm::Event &, const edm::EventSetup &) override
edm::EventID id() const
Definition: EventBase.h:60
iterator find(key_type k)
void makeNxNClusters(edm::Event &evt, const edm::EventSetup &es, const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector)
size_type size() const
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=0)
Definition: PositionCalc.h:68
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
tuple status
Definition: ntuplemaker.py:245
const edm::EDGetTokenT< EcalRecHitCollection > barrelHitProducer_
const_iterator begin() const