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 #include <memory>
5 
6 // Framework
13 
14 // Reconstruction Classes
21 
22 // Geometry
31 
32 
33 // EgammaCoreTools
35 
36 
37 // Class header file
39 
40 
41 
42 using namespace edm;
43 using namespace std;
44 
46 {
47 
48 
49  doBarrel_ = ps.getParameter<bool>("doBarrel");
50  doEndcaps_ = ps.getParameter<bool>("doEndcaps");
51 
52  barrelHitProducer_ = ps.getParameter< edm::InputTag > ("barrelHitProducer");
53  endcapHitProducer_ = ps.getParameter< edm::InputTag > ("endcapHitProducer");
54 
55  clusEtaSize_ = ps.getParameter<int> ("clusEtaSize");
56  clusPhiSize_ = ps.getParameter<int> ("clusPhiSize");
57 
58 
59 
60  // The names of the produced cluster collections
61  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
62  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
63 
64 
65  clusSeedThr_ = ps.getParameter<double> ("clusSeedThr");
66  clusSeedThrEndCap_ = ps.getParameter<double> ("clusSeedThrEndCap");
67 
68  useRecoFlag_ = ps.getParameter<bool>("useRecoFlag");
69  flagLevelRecHitsToUse_ = ps.getParameter<int>("flagLevelRecHitsToUse");
70 
71  useDBStatus_ = ps.getParameter<bool>("useDBStatus");
72  statusLevelRecHitsToUse_ = ps.getParameter<int>("statusLevelRecHitsToUse");
73 
74  // Parameters for the position calculation:
75  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
76 
77  //max number of seeds / clusters, once reached, then return 0
78  maxNumberofSeeds_ = ps.getParameter<int> ("maxNumberofSeeds");
79  maxNumberofClusters_ = ps.getParameter<int> ("maxNumberofClusters");
80 
81 
82  debug_ = ps.getParameter<int> ("debugLevel");
83 
84  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
85  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
86 
87 
88 
89 }
90 
91 
93 {
94  //delete island_p;
95 }
96 
97 
99 {
100 
101 
102  if(doBarrel_){
103  Handle<EcalRecHitCollection> barrelRecHitsHandle;
104  evt.getByLabel(barrelHitProducer_,barrelRecHitsHandle);
105  if (!barrelRecHitsHandle.isValid()) {
106  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product eb hit!" << std::endl;
107  }
108 
109  const EcalRecHitCollection *hits_eb = barrelRecHitsHandle.product();
110  if( debug_>=2 ) LogDebug("")<<"EgammaHLTNxNClusterProducer nEBrechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_eb->size()<<std::endl;
111 
112  makeNxNClusters(evt,es,hits_eb, reco::CaloID::DET_ECAL_BARREL);
113 
114  }
115 
116 
117  if(doEndcaps_){
118  Handle<EcalRecHitCollection> endcapRecHitsHandle;
119  evt.getByLabel(endcapHitProducer_,endcapRecHitsHandle);
120  if (!endcapRecHitsHandle.isValid()) {
121  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product ee hit!" << std::endl;
122  }
123 
124  const EcalRecHitCollection *hits_ee = endcapRecHitsHandle.product();
125  if( debug_>=2 ) LogDebug("")<<"EgammaHLTNxNClusterProducer nEErechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_ee->size()<<std::endl;
126  makeNxNClusters(evt,es,hits_ee, reco::CaloID::DET_ECAL_ENDCAP);
127  }
128 
129 
130 
131 }
132 
133 
134 
136 
137  if(useRecoFlag_ ){
138  int flag = rh.recoFlag();
139  if( flagLevelRecHitsToUse_ ==0){
140  if( flag != 0) return false;
141  }
142  else if( flagLevelRecHitsToUse_ ==1){
143  if( flag !=0 && flag != 4 ) return false;
144  }
145  else if( flagLevelRecHitsToUse_ ==2){
146  if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
147  }
148  }
149  if ( useDBStatus_){
150  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
151  if ( status > statusLevelRecHitsToUse_ ) return false;
152  }
153 
154  return true;
155 }
156 
157 
158 
159 
161  const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector)
162 {
163 
164 
167  if ( useDBStatus_ ) es.get<EcalChannelStatusRcd>().get(csHandle);
168  const EcalChannelStatus &channelStatus = *csHandle;
169 
170 
171  std::vector<EcalRecHit> seeds;
172 
173  double clusterSeedThreshold ;
174  if (detector == reco::CaloID::DET_ECAL_BARREL){
175  clusterSeedThreshold = clusSeedThr_;
176  }else{
177  clusterSeedThreshold = clusSeedThrEndCap_;
178  }
179 
180 
181  for(EcalRecHitCollection::const_iterator itt = hits->begin(); itt != hits->end(); itt++){
182  double energy = itt->energy();
183  if( ! checkStatusOfEcalRecHit(channelStatus, *itt) ) continue;
184  if (energy > clusterSeedThreshold ) seeds.push_back(*itt);
185 
186  if( int(seeds.size()) > maxNumberofSeeds_){ //too many seeds, like beam splash events
187  seeds.clear();
188  break;
189  }
190  }
191 
192  // get the geometry and topology from the event setup:
193  edm::ESHandle<CaloGeometry> geoHandle;
194  es.get<CaloGeometryRecord>().get(geoHandle);
195 
196  const CaloSubdetectorGeometry *geometry_p;
197  CaloSubdetectorTopology *topology_p;
198  if (detector == reco::CaloID::DET_ECAL_BARREL) {
199  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
200  topology_p = new EcalBarrelTopology(geoHandle);
201  }else {
202  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
203  topology_p = new EcalEndcapTopology(geoHandle);
204  }
205 
206  const CaloSubdetectorGeometry *geometryES_p;
207  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
208 
209 
210 
211  std::vector<reco::BasicCluster> clusters;
212  std::vector<DetId> usedXtals;
213 
214  // sort seed according to Energy
215  sort(seeds.begin(), seeds.end(), ecalRecHitSort());
216 
217 
218 
219  for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
220  DetId seed_id = itseed->id();
221  std::vector<DetId>::const_iterator usedIds;
222 
223  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),seed_id);
224  if(itdet != usedXtals.end()) continue;
225 
226  std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
227  std::vector<std::pair<DetId, float> > clus_used;
228 
229  float clus_energy = 0;
230 
231  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
232  DetId detid = *det;
233 
234  //not yet used
235  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),detid);
236  if(itdet != usedXtals.end()) continue;
237  //inside the collection
239  if( hit == hits->end()) continue;
240 
241  if( ! checkStatusOfEcalRecHit(channelStatus, *hit) ) continue;
242 
243  usedXtals.push_back(detid);
244  clus_used.push_back(std::pair<DetId, float>(detid, 1.) );
245  clus_energy += hit->energy();
246 
247  }
248 
249  if( clus_energy <= 0 ) continue;
250 
251  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hits,geometry_p,geometryES_p);
252 
253  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;
254 
255  clusters.push_back(reco::BasicCluster(clus_energy, clus_pos, reco::CaloID(detector), clus_used, reco::CaloCluster::island, seed_id));
256  if( int(clusters.size()) > maxNumberofClusters_){
257  clusters.clear();
258  break;
259  }
260 
261  }
262 
263 
264  //Create empty output collections
265  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
266  clusters_p->assign(clusters.begin(), clusters.end());
267  if (detector == reco::CaloID::DET_ECAL_BARREL){
268  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in barrel"<<std::endl;
269  evt.put(clusters_p, barrelClusterCollection_);
270  }
271  else {
272  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in endcap"<<std::endl;
273  evt.put(clusters_p, endcapClusterCollection_);
274  }
275 
276 }
277 
278 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
long int flag
Definition: mlp_lapack.h:47
std::vector< EcalRecHit >::const_iterator const_iterator
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.cc:133
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:45
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
EgammaHLTNxNClusterProducer(const edm::ParameterSet &ps)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const_iterator end() const
Definition: DetId.h:20
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
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:56
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
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
tuple status
Definition: ntuplemaker.py:245
virtual void produce(edm::Event &, const edm::EventSetup &)
const_iterator begin() const