CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicClusterProducer.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 
40 {
41  // The verbosity level
42  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
43  if (verbosityString == "DEBUG") verbosity = CosmicClusterAlgo::pDEBUG;
44  else if (verbosityString == "WARNING") verbosity = CosmicClusterAlgo::pWARNING;
45  else if (verbosityString == "INFO") verbosity = CosmicClusterAlgo::pINFO;
47 
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  barrelUHitProducer_ = ps.getParameter<std::string>("barrelUnHitProducer");
55  endcapUHitProducer_ = ps.getParameter<std::string>("endcapUnHitProducer");
56  barrelUHitCollection_ = ps.getParameter<std::string>("barrelUnHitCollection");
57  endcapUHitCollection_ = ps.getParameter<std::string>("endcapUnHitCollection");
58 
59  // The names of the produced cluster collections
60  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
61  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
62 
63  // Island algorithm parameters
64  double barrelSeedThreshold = ps.getParameter<double>("BarrelSeedThr");
65  double barrelSingleThreshold = ps.getParameter<double>("BarrelSingleThr");
66  double barrelSecondThreshold = ps.getParameter<double>("BarrelSecondThr");
67  double barrelSupThreshold = ps.getParameter<double>("BarrelSupThr");
68  double endcapSeedThreshold = ps.getParameter<double>("EndcapSeedThr");
69  double endcapSingleThreshold = ps.getParameter<double>("EndcapSingleThr");
70  double endcapSecondThreshold = ps.getParameter<double>("EndcapSecondThr");
71  double endcapSupThreshold = ps.getParameter<double>("EndcapSupThr");
72 
73  // Parameters for the position calculation:
74  edm::ParameterSet posCalcParameters =
75  ps.getParameter<edm::ParameterSet>("posCalcParameters");
76 
77  posCalculator_ = PositionCalc(posCalcParameters);
78  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
79 
80  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
81  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
82 
83  //AssociationMap
84  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
85  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
86 
87  // Produces a collection of barrel and a collection of endcap clusters
88 
89  produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
90  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
91  produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
92  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
93  produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
94  produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
95 
96  island_p = new CosmicClusterAlgo(barrelSeedThreshold, barrelSingleThreshold, barrelSecondThreshold, barrelSupThreshold, endcapSeedThreshold, endcapSingleThreshold, endcapSecondThreshold, endcapSupThreshold, posCalculator_,verbosity);
97 
98  nEvt_ = 0;
99 }
100 
101 
103 {
104  delete island_p;
105 }
106 
107 
109 {
112  nEvt_++;
113 }
114 
115 
117  const std::string& hitProducer_,
118  const std::string& hitCollection_)
119 {
121  try
122  {
123  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
124  if (!(rhcHandle.isValid()))
125  {
126  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
127  return 0;
128  }
129  }
130  catch ( cms::Exception& ex )
131  {
132  edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
133  return 0;
134  }
135  return rhcHandle.product();
136 }
137 
139  const std::string& hitProducer_,
140  const std::string& hitCollection_)
141 {
143  try
144  {
145  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
146  if (!(rhcHandle.isValid()))
147  {
148  std::cout << "could not get a handle on the EcalUncalibratedRecHitCollection!" << std::endl;
149  return 0;
150  }
151  }
152  catch ( cms::Exception& ex )
153  {
154  edm::LogError("CosmicClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
155  return 0;
156  }
157  return rhcHandle.product();
158 }
159 
160 
162  const std::string& hitProducer,
163  const std::string& hitCollection,
164  const std::string& uhitProducer,
165  const std::string& uhitCollection,
166  const std::string& clusterCollection,
167  const std::string& clusterShapeAssociation,
168  const CosmicClusterAlgo::EcalPart& ecalPart)
169 {
170  // get the hit collection from the event:
171 
172  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
173  const EcalUncalibratedRecHitCollection *uhitCollection_p = getUCollection(evt, uhitProducer, uhitCollection);
174 
175  // get the geometry and topology from the event setup:
176  edm::ESHandle<CaloGeometry> geoHandle;
177  es.get<CaloGeometryRecord>().get(geoHandle);
178 
179  const CaloSubdetectorGeometry *geometry_p;
180  CaloSubdetectorTopology *topology_p;
181 
182  std::string clustershapetag;
183  if (ecalPart == CosmicClusterAlgo::barrel)
184  {
185  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
186  topology_p = new EcalBarrelTopology(geoHandle);
187  }
188  else
189  {
190  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
191  topology_p = new EcalEndcapTopology(geoHandle);
192  }
193 
194  const CaloSubdetectorGeometry *geometryES_p;
195  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
196 
197  // Run the clusterization algorithm:
199  clusters = island_p->makeClusters(hitCollection_p, uhitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
200 
201  //Create associated ClusterShape objects.
202  std::vector <reco::ClusterShape> ClusVec;
203 
204  for (int erg=0;erg<int(clusters.size());++erg){
205  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
206  ClusVec.push_back(TestShape);
207  }
208 
209  //Put clustershapes in event, but retain a Handle on them.
210  std::auto_ptr< reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
211  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
213  if (ecalPart == CosmicClusterAlgo::barrel)
214  clusHandle= evt.put(clustersshapes_p, clustershapecollectionEB_);
215  else
216  clusHandle= evt.put(clustersshapes_p, clustershapecollectionEE_);
217 
218  // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
219  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
220  clusters_p->assign(clusters.begin(), clusters.end());
222 
223  if (ecalPart == CosmicClusterAlgo::barrel)
224  bccHandle = evt.put(clusters_p, barrelClusterCollection_);
225  else
226  bccHandle = evt.put(clusters_p, endcapClusterCollection_);
227 
228 
229  // BasicClusterShapeAssociationMap
230  std::auto_ptr<reco::BasicClusterShapeAssociationCollection> shapeAssocs_p(new reco::BasicClusterShapeAssociationCollection);
231  for (unsigned int i = 0; i < clusHandle->size(); i++){
232  shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
233  }
234  evt.put(shapeAssocs_p,clusterShapeAssociation);
235 
236  delete topology_p;
237 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const EcalRecHitCollection * getCollection(edm::Event &evt, const std::string &hitProducer_, const std::string &hitCollection_)
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
CosmicClusterAlgo * island_p
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const EcalUncalibratedRecHitCollection *uncalibhits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
CosmicClusterProducer(const edm::ParameterSet &ps)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
CosmicClusterAlgo::VerbosityLevel verbosity
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const std::string &hitProducer, const std::string &hitCollection, const std::string &uhitProducer, const std::string &uhitCollection, const std::string &clusterCollection, const std::string &clusterShapeAssociation, const CosmicClusterAlgo::EcalPart &ecalPart)
std::string endcapClusterShapeAssociation_
const EcalUncalibratedRecHitCollection * getUCollection(edm::Event &evt, const std::string &hitProducer_, const std::string &hitCollection_)
const T & get() const
Definition: EventSetup.h:55
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T const * product() const
Definition: Handle.h:74
tuple cout
Definition: gather_cfg.py:41
std::string barrelClusterShapeAssociation_