CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Multi5x5ClusterProducer.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
29 
30 // EgammaCoreTools
32 
33 // Class header file
35 
36 
38 {
39  // The verbosity level
40  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
41  if (verbosityString == "DEBUG") verbosity = Multi5x5ClusterAlgo::pDEBUG;
42  else if (verbosityString == "WARNING") verbosity = Multi5x5ClusterAlgo::pWARNING;
43  else if (verbosityString == "INFO") verbosity = Multi5x5ClusterAlgo::pINFO;
45 
46  // Parameters to identify the hit collections
47  barrelHitProducer_ = ps.getParameter<std::string>("barrelHitProducer");
48  endcapHitProducer_ = ps.getParameter<std::string>("endcapHitProducer");
49  barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
50  endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
51 
52  // should cluster algo be run in barrel and endcap?
53  doEndcap_ = ps.getParameter<bool>("doEndcap");
54  doBarrel_ = ps.getParameter<bool>("doBarrel");
55 
56  // The names of the produced cluster collections
57  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
58  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
59 
60  // Island algorithm parameters
61  double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
62  double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
63 
64  std::vector<int> v_chstatus = ps.getParameter<std::vector<int> >("RecHitFlagToBeExcluded");
65 
66  // Parameters for the position calculation:
67  edm::ParameterSet posCalcParameters =
68  ps.getParameter<edm::ParameterSet>("posCalcParameters");
69  posCalculator_ = PositionCalc(posCalcParameters);
70 
71  // Produces a collection of barrel and a collection of endcap clusters
72  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
73  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
74 
75  island_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_,verbosity);
76 
77  nEvt_ = 0;
78 }
79 
80 
82 {
83  delete island_p;
84 }
85 
86 
88 {
89 
90  if (doEndcap_) {
92  }
93  if (doBarrel_) {
95  }
96 
97  nEvt_++;
98 }
99 
100 
102  const std::string& hitProducer_,
103  const std::string& hitCollection_)
104 {
106  try
107  {
108  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
109  if (!(rhcHandle.isValid()))
110  {
111  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
112  return 0;
113  }
114  }
115  catch ( cms::Exception& ex )
116  {
117  edm::LogError("Multi5x5ClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
118  return 0;
119  }
120  return rhcHandle.product();
121 }
122 
123 
125  const std::string& hitProducer,
126  const std::string& hitCollection,
127  const std::string& clusterCollection,
129 {
130  // get the hit collection from the event:
131  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
132 
133  // get the geometry and topology from the event setup:
134  edm::ESHandle<CaloGeometry> geoHandle;
135  es.get<CaloGeometryRecord>().get(geoHandle);
136 
137  const CaloSubdetectorGeometry *geometry_p;
138  CaloSubdetectorTopology *topology_p;
139 
140  if (detector == reco::CaloID::DET_ECAL_BARREL)
141  {
142  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
143  topology_p = new EcalBarrelTopology(geoHandle);
144  }
145  else
146  {
147  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
148  topology_p = new EcalEndcapTopology(geoHandle);
149  }
150 
151  const CaloSubdetectorGeometry *geometryES_p;
152  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
153 
154  // Run the clusterization algorithm:
156  clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector);
157 
158  // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
159  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
160  clusters_p->assign(clusters.begin(), clusters.end());
162  if (detector == reco::CaloID::DET_ECAL_BARREL)
163  bccHandle = evt.put(clusters_p, barrelClusterCollection_);
164  else
165  bccHandle = evt.put(clusters_p, endcapClusterCollection_);
166 
167  delete topology_p;
168 }
T getParameter(std::string const &) const
Multi5x5ClusterProducer(const edm::ParameterSet &ps)
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const std::string &hitProducer, const std::string &hitCollection, const std::string &clusterCollection, const reco::CaloID::Detectors detector)
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, reco::CaloID::Detectors detector, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
const EcalRecHitCollection * getCollection(edm::Event &evt, const std::string &hitProducer_, const std::string &hitCollection_)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
virtual void produce(edm::Event &, const edm::EventSetup &)
bool isValid() const
Definition: HandleBase.h:76
Multi5x5ClusterAlgo * island_p
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
const T & get() const
Definition: EventSetup.h:55
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T const * product() const
Definition: Handle.h:74
Multi5x5ClusterAlgo::VerbosityLevel verbosity
tuple cout
Definition: gather_cfg.py:41