CMS 3D CMS Logo

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  ebHitsToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("barrelHits"));
51  eeHitsToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("endcapHits"));
52 
53  ebUHitsToken_ = consumes<EcalUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("barrelUncalibHits"));
54  eeUHitsToken_ = consumes<EcalUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("endcapUncalibHits"));
55 
56 
57  // The names of the produced cluster collections
58  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
59  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
60 
61  // Island algorithm parameters
62  double barrelSeedThreshold = ps.getParameter<double>("BarrelSeedThr");
63  double barrelSingleThreshold = ps.getParameter<double>("BarrelSingleThr");
64  double barrelSecondThreshold = ps.getParameter<double>("BarrelSecondThr");
65  double barrelSupThreshold = ps.getParameter<double>("BarrelSupThr");
66  double endcapSeedThreshold = ps.getParameter<double>("EndcapSeedThr");
67  double endcapSingleThreshold = ps.getParameter<double>("EndcapSingleThr");
68  double endcapSecondThreshold = ps.getParameter<double>("EndcapSecondThr");
69  double endcapSupThreshold = ps.getParameter<double>("EndcapSupThr");
70 
71  // Parameters for the position calculation:
73  ps.getParameter<edm::ParameterSet>("posCalcParameters");
74 
75  posCalculator_ = PositionCalc(posCalcParameters);
76  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
77 
78  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
79  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
80 
81  //AssociationMap
82  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
83  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
84 
85  // Produces a collection of barrel and a collection of endcap clusters
86 
87  produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
88  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
89  produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
90  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
91  produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
92  produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
93 
94  island_p = new CosmicClusterAlgo(barrelSeedThreshold, barrelSingleThreshold, barrelSecondThreshold, barrelSupThreshold, endcapSeedThreshold, endcapSingleThreshold, endcapSecondThreshold, endcapSupThreshold, posCalculator_,verbosity);
95 
96  nEvt_ = 0;
97 }
98 
99 
101 {
102  delete island_p;
103 }
104 
105 
107 {
110  nEvt_++;
111 }
112 
113 
114 
115 
119  const std::string& clusterCollection,
120  const std::string& clusterShapeAssociation,
121  const CosmicClusterAlgo::EcalPart& ecalPart)
122 {
123  // get the hit collection from the event:
124 
127 
128  evt.getByToken(hitsToken,hits_h);
129  evt.getByToken(uhitsToken,uhits_h);
130 
131  const EcalRecHitCollection *hitCollection_p = hits_h.product();
132  const EcalUncalibratedRecHitCollection *uhitCollection_p = uhits_h.product();
133 
134  // get the geometry and topology from the event setup:
135  edm::ESHandle<CaloGeometry> geoHandle;
136  es.get<CaloGeometryRecord>().get(geoHandle);
137 
138  const CaloSubdetectorGeometry *geometry_p;
139  CaloSubdetectorTopology *topology_p;
140 
141  std::string clustershapetag;
142  if (ecalPart == CosmicClusterAlgo::barrel)
143  {
144  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
145  topology_p = new EcalBarrelTopology(geoHandle);
146  }
147  else
148  {
149  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
150  topology_p = new EcalEndcapTopology(geoHandle);
151  }
152 
153  const CaloSubdetectorGeometry *geometryES_p;
154  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
155 
156  // Run the clusterization algorithm:
158  clusters = island_p->makeClusters(hitCollection_p, uhitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart);
159 
160  //Create associated ClusterShape objects.
161  std::vector <reco::ClusterShape> ClusVec;
162 
163  for (int erg=0;erg<int(clusters.size());++erg){
164  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p);
165  ClusVec.push_back(TestShape);
166  }
167 
168  //Put clustershapes in event, but retain a Handle on them.
169  auto clustersshapes_p = std::make_unique<reco::ClusterShapeCollection>();
170  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
172  if (ecalPart == CosmicClusterAlgo::barrel)
173  clusHandle= evt.put(std::move(clustersshapes_p), clustershapecollectionEB_);
174  else
175  clusHandle= evt.put(std::move(clustersshapes_p), clustershapecollectionEE_);
176 
177  // create a unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
178  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
179  clusters_p->assign(clusters.begin(), clusters.end());
181 
182  if (ecalPart == CosmicClusterAlgo::barrel)
183  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
184  else
185  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
186 
187 
188  // BasicClusterShapeAssociationMap
189  auto shapeAssocs_p = std::make_unique<reco::BasicClusterShapeAssociationCollection>(bccHandle, clusHandle);
190 
191  for (unsigned int i = 0; i < clusHandle->size(); i++){
192  shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
193  }
194  evt.put(std::move(shapeAssocs_p),clusterShapeAssociation);
195 
196  delete topology_p;
197 }
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const edm::EDGetTokenT< EcalRecHitCollection > &hitsToken, const edm::EDGetTokenT< EcalUncalibratedRecHitCollection > &uhitsToken, const std::string &clusterCollection, const std::string &clusterShapeAssociation, const CosmicClusterAlgo::EcalPart &ecalPart)
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)
edm::EDGetTokenT< EcalRecHitCollection > eeHitsToken_
CosmicClusterAlgo::VerbosityLevel verbosity
std::string endcapClusterShapeAssociation_
edm::EDGetTokenT< EcalRecHitCollection > ebHitsToken_
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
edm::EDGetTokenT< EcalUncalibratedRecHitCollection > eeUHitsToken_
edm::EDGetTokenT< EcalUncalibratedRecHitCollection > ebUHitsToken_
def move(src, dest)
Definition: eostools.py:510
std::string barrelClusterShapeAssociation_