CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IslandClusterProducer.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
35 
36 // Class header file
38 
39 
41 {
42  // The verbosity level
43  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
44  if (verbosityString == "DEBUG") verbosity = IslandClusterAlgo::pDEBUG;
45  else if (verbosityString == "WARNING") verbosity = IslandClusterAlgo::pWARNING;
46  else if (verbosityString == "INFO") verbosity = IslandClusterAlgo::pINFO;
48 
49  // Parameters to identify the hit collections
50  barrelHitProducer_ = ps.getParameter<std::string>("barrelHitProducer");
51  endcapHitProducer_ = ps.getParameter<std::string>("endcapHitProducer");
52  barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
53  endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
54 
55  // The names of the produced cluster collections
56  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
57  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
58 
59  // Island algorithm parameters
60  double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
61  double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
62 
63  // Parameters for the position calculation:
64  edm::ParameterSet posCalcParameters =
65  ps.getParameter<edm::ParameterSet>("posCalcParameters");
66  posCalculator_ = PositionCalc(posCalcParameters);
67  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
68 
69  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
70  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
71 
72  //AssociationMap
73  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
74  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
75 
76  // Produces a collection of barrel and a collection of endcap clusters
77 
78  produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
79  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
80  produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
81  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
82  produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
83  produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
84 
85  island_p = new IslandClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_,verbosity);
86 
87  nEvt_ = 0;
88 }
89 
90 
92 {
93  delete island_p;
94 }
95 
96 
98 {
101  nEvt_++;
102 }
103 
104 
106  const std::string& hitProducer_,
107  const std::string& hitCollection_)
108 {
110  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
111  if (!(rhcHandle.isValid()))
112  {
113  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
114  edm::LogError("IslandClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
115  return 0;
116  } else {
117  return rhcHandle.product();
118  }
119 }
120 
122  const std::string& hitProducer,
123  const std::string& hitCollection,
124  const std::string& clusterCollection,
125  const std::string& clusterShapeAssociation,
126  const IslandClusterAlgo::EcalPart& ecalPart)
127 {
128  // get the hit collection from the event:
129  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
130 
131  // get the geometry and topology from the event setup:
132  edm::ESHandle<CaloGeometry> geoHandle;
133  es.get<CaloGeometryRecord>().get(geoHandle);
134 
135  const CaloSubdetectorGeometry *geometry_p;
136  CaloSubdetectorTopology *topology_p;
137 
138  std::string clustershapetag;
139  if (ecalPart == IslandClusterAlgo::barrel)
140  {
141  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
142  topology_p = new EcalBarrelTopology(geoHandle);
143  }
144  else
145  {
146  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
147  topology_p = new EcalEndcapTopology(geoHandle);
148  }
149 
150  const CaloSubdetectorGeometry *geometryES_p;
151  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
152 
153  // Run the clusterization algorithm:
155  clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
156 
157  //Create associated ClusterShape objects.
158  std::vector <reco::ClusterShape> ClusVec;
159  for (int erg=0;erg<int(clusters.size());++erg){
160  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
161  ClusVec.push_back(TestShape);
162  }
163 
164  //Put clustershapes in event, but retain a Handle on them.
165  std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
166  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
168  if (ecalPart == IslandClusterAlgo::barrel)
169  clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
170  else
171  clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
172 
173  // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
174  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
175  clusters_p->assign(clusters.begin(), clusters.end());
177  if (ecalPart == IslandClusterAlgo::barrel)
178  bccHandle = evt.put(clusters_p, barrelClusterCollection_);
179  else
180  bccHandle = evt.put(clusters_p, endcapClusterCollection_);
181 
182 
183  // BasicClusterShapeAssociationMap
184  std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
185  for (unsigned int i = 0; i < clusHandle->size(); i++){
186  shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
187  }
188  evt.put(shapeAssocs_p,clusterShapeAssociation);
189 
190  delete topology_p;
191 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
IslandClusterProducer(const edm::ParameterSet &ps)
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
virtual void produce(edm::Event &, const edm::EventSetup &)
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
std::string barrelClusterShapeAssociation_
bool isValid() const
Definition: HandleBase.h:76
IslandClusterAlgo * island_p
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const std::string &hitProducer, const std::string &hitCollection, const std::string &clusterCollection, const std::string &clusterShapeAssociation, const IslandClusterAlgo::EcalPart &ecalPart)
const T & get() const
Definition: EventSetup.h:55
std::string endcapClusterShapeAssociation_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T const * product() const
Definition: Handle.h:74
tuple cout
Definition: gather_cfg.py:121
IslandClusterAlgo::VerbosityLevel verbosity
const EcalRecHitCollection * getCollection(edm::Event &evt, const std::string &hitProducer_, const std::string &hitCollection_)