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 
27  doBarrel_ = ps.getParameter<bool>("doBarrel");
28  doEndcaps_ = ps.getParameter<bool>("doEndcaps");
29 
30  barrelHitProducer_ = consumes<EcalRecHitCollection>(ps.getParameter< edm::InputTag > ("barrelHitProducer"));
31  endcapHitProducer_ = consumes<EcalRecHitCollection>(ps.getParameter< edm::InputTag > ("endcapHitProducer"));
32 
33  clusEtaSize_ = ps.getParameter<int> ("clusEtaSize");
34  clusPhiSize_ = ps.getParameter<int> ("clusPhiSize");
35 
36  // The names of the produced cluster collections
37  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
38  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
39 
40  clusSeedThr_ = ps.getParameter<double> ("clusSeedThr");
41  clusSeedThrEndCap_ = ps.getParameter<double> ("clusSeedThrEndCap");
42 
43  useRecoFlag_ = ps.getParameter<bool>("useRecoFlag");
44  flagLevelRecHitsToUse_ = ps.getParameter<int>("flagLevelRecHitsToUse");
45 
46  useDBStatus_ = ps.getParameter<bool>("useDBStatus");
47  statusLevelRecHitsToUse_ = ps.getParameter<int>("statusLevelRecHitsToUse");
48 
49  // Parameters for the position calculation:
50  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
51 
52  //max number of seeds / clusters, once reached, then return 0
53  maxNumberofSeeds_ = ps.getParameter<int> ("maxNumberofSeeds");
54  maxNumberofClusters_ = ps.getParameter<int> ("maxNumberofClusters");
55 
56  debug_ = ps.getParameter<int> ("debugLevel");
57 
58  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
59  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
60 }
61 
62 
64 {}
65 
67 
69  desc.add<bool>(("doBarrel"), true);
70  desc.add<bool>(("doEndcaps"), true);
71  desc.add<edm::InputTag>(("barrelHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEB"));
72  desc.add<edm::InputTag>(("endcapHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEE"));
73  desc.add<int>(("clusEtaSize"), 3);
74  desc.add<int>(("clusPhiSize"), 3);
75  desc.add<std::string>(("barrelClusterCollection"), "Simple3x3ClustersBarrel");
76  desc.add<std::string>(("endcapClusterCollection"), "Simple3x3ClustersEndcap");
77  desc.add<double>(("clusSeedThr"), 0.5);
78  desc.add<double>(("clusSeedThrEndCap"), 1.0);
79  desc.add<bool>(("useRecoFlag"), false);
80  desc.add<int>(("flagLevelRecHitsToUse"), 1);
81  desc.add<bool>(("useDBStatus"), true);
82  desc.add<int>(("statusLevelRecHitsToUse"), 1);
83 
84  edm::ParameterSetDescription posCalcPSET;
85  posCalcPSET.add<double>("T0_barl", 7.4);
86  posCalcPSET.add<double>("T0_endc", 3.1);
87  posCalcPSET.add<double>("T0_endcPresh", 1.2);
88  posCalcPSET.add<double>("W0", 4.2);
89  posCalcPSET.add<double>("X0", 0.89);
90  posCalcPSET.add<bool>("LogWeighted", true);
91  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
92 
93  desc.add<int>(("maxNumberofSeeds"), 1000);
94  desc.add<int>(("maxNumberofClusters"), 200);
95  desc.add<int>(("debugLevel"), 0);
96  descriptions.add(("hltEgammaHLTNxNClusterProducer"), desc);
97 }
98 
100 
101  if(doBarrel_) {
102  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
103  evt.getByToken(barrelHitProducer_, barrelRecHitsHandle);
104  if (!barrelRecHitsHandle.isValid()) {
105  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product eb hit!" << std::endl;
106  }
107 
108  const EcalRecHitCollection *hits_eb = barrelRecHitsHandle.product();
109  if( debug_>=2 )
110  LogDebug("")<<"EgammaHLTNxNClusterProducer nEBrechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_eb->size()<<std::endl;
111 
113 
114  }
115 
116 
117  if(doEndcaps_) {
118  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
119  evt.getByToken(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 )
126  LogDebug("")<<"EgammaHLTNxNClusterProducer nEErechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_ee->size()<<std::endl;
128  }
129 }
130 
131 
132 
134 
135  if(useRecoFlag_ ){
136  int flag = rh.recoFlag();
137  if( flagLevelRecHitsToUse_ ==0){
138  if( flag != 0) return false;
139  }
140  else if( flagLevelRecHitsToUse_ ==1){
141  if( flag !=0 && flag != 4 ) return false;
142  }
143  else if( flagLevelRecHitsToUse_ ==2){
144  if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
145  }
146  }
147  if ( useDBStatus_){
148  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
149  if ( status > statusLevelRecHitsToUse_ ) return false;
150  }
151 
152  return true;
153 }
154 
155 
156 
157 
159  const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector)
160 {
161 
162 
165  if ( useDBStatus_ ) es.get<EcalChannelStatusRcd>().get(csHandle);
166  const EcalChannelStatus &channelStatus = *csHandle;
167 
168 
169  std::vector<EcalRecHit> seeds;
170 
171  double clusterSeedThreshold ;
172  if (detector == reco::CaloID::DET_ECAL_BARREL){
173  clusterSeedThreshold = clusSeedThr_;
174  }else{
175  clusterSeedThreshold = clusSeedThrEndCap_;
176  }
177 
178 
179  for(EcalRecHitCollection::const_iterator itt = hits->begin(); itt != hits->end(); itt++){
180  double energy = itt->energy();
181  if( ! checkStatusOfEcalRecHit(channelStatus, *itt) ) continue;
182  if (energy > clusterSeedThreshold ) seeds.push_back(*itt);
183 
184  if( int(seeds.size()) > maxNumberofSeeds_){ //too many seeds, like beam splash events
185  seeds.clear();
186  break;
187  }
188  }
189 
190  // get the geometry and topology from the event setup:
191  edm::ESHandle<CaloGeometry> geoHandle;
192  es.get<CaloGeometryRecord>().get(geoHandle);
193 
194  const CaloSubdetectorGeometry *geometry_p;
195  CaloSubdetectorTopology *topology_p;
196  if (detector == reco::CaloID::DET_ECAL_BARREL) {
197  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
198  topology_p = new EcalBarrelTopology(geoHandle);
199  }else {
200  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
201  topology_p = new EcalEndcapTopology(geoHandle);
202  }
203 
204  const CaloSubdetectorGeometry *geometryES_p;
205  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
206 
207 
208 
209  std::vector<reco::BasicCluster> clusters;
210  std::vector<DetId> usedXtals;
211 
212  // sort seed according to Energy
213  sort(seeds.begin(), seeds.end(), ecalRecHitSort());
214 
215 
216 
217  for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
218  DetId seed_id = itseed->id();
219  std::vector<DetId>::const_iterator usedIds;
220 
221  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),seed_id);
222  if(itdet != usedXtals.end()) continue;
223 
224  std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
225  std::vector<std::pair<DetId, float> > clus_used;
226 
227  float clus_energy = 0;
228 
229  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
230  DetId detid = *det;
231 
232  //not yet used
233  std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),detid);
234  if(itdet != usedXtals.end()) continue;
235  //inside the collection
237  if( hit == hits->end()) continue;
238 
239  if( ! checkStatusOfEcalRecHit(channelStatus, *hit) ) continue;
240 
241  usedXtals.push_back(detid);
242  clus_used.push_back(std::pair<DetId, float>(detid, 1.) );
243  clus_energy += hit->energy();
244 
245  }
246 
247  if( clus_energy <= 0 ) continue;
248 
249  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hits,geometry_p,geometryES_p);
250 
251  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;
252 
253  clusters.push_back(reco::BasicCluster(clus_energy, clus_pos, reco::CaloID(detector), clus_used, reco::CaloCluster::island, seed_id));
254  if( int(clusters.size()) > maxNumberofClusters_){
255  clusters.clear();
256  break;
257  }
258 
259  }
260 
261 
262  //Create empty output collections
263  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
264  clusters_p->assign(clusters.begin(), clusters.end());
265  if (detector == reco::CaloID::DET_ECAL_BARREL){
266  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in barrel"<<std::endl;
267  evt.put(clusters_p, barrelClusterCollection_);
268  }
269  else {
270  if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in endcap"<<std::endl;
271  evt.put(clusters_p, endcapClusterCollection_);
272  }
273 
274 }
275 
276 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:76
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
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
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)
edm::EDGetTokenT< EcalRecHitCollection > endcapHitProducer_
tuple status
Definition: ntuplemaker.py:245
virtual void produce(edm::Event &, const edm::EventSetup &)
const_iterator begin() const
edm::EDGetTokenT< EcalRecHitCollection > barrelHitProducer_