CMS 3D CMS Logo

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
15 
16 // Reconstruction Classes
22 
23 // Geometry
30 
31 // EgammaCoreTools
36 
37 // Class header file
39 
40 
42 {
43  // The verbosity level
44  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
45  if (verbosityString == "DEBUG") verbosity = IslandClusterAlgo::pDEBUG;
46  else if (verbosityString == "WARNING") verbosity = IslandClusterAlgo::pWARNING;
47  else if (verbosityString == "INFO") verbosity = IslandClusterAlgo::pINFO;
49 
50  // Parameters to identify the hit collections
52  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("barrelHits"));
54  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("endcapHits"));
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  // Parameters for the position calculation:
66  ps.getParameter<edm::ParameterSet>("posCalcParameters");
67  posCalculator_ = PositionCalc(posCalcParameters);
68  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
69 
70  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
71  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
72 
73  //AssociationMap
74  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
75  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
76 
77  const std::vector<std::string> seedflagnamesEB = ps.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEB");
78  const std::vector<int> seedflagsexclEB = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEB);
79 
80  const std::vector<std::string> seedflagnamesEE = ps.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEE");
81  const std::vector<int> seedflagsexclEE = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEE);
82 
83  const std::vector<std::string> flagnamesEB = ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
84  const std::vector<int> flagsexclEB = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
85 
86  const std::vector<std::string> flagnamesEE = ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
87  const std::vector<int> flagsexclEE = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
88 
89  // Produces a collection of barrel and a collection of endcap clusters
90 
91  produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);
92  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
93  produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);
94  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
95  produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);
96  produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);
97 
98  island_p = new IslandClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_, seedflagsexclEB, seedflagsexclEE, flagsexclEB, flagsexclEE, verbosity);
99 
100  nEvt_ = 0;
101 }
102 
103 
105 {
106  delete island_p;
107 }
108 
110 
112  desc.add<std::string>("VerbosityLevel", "ERROR");
113  desc.add<edm::InputTag>("barrelHits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
114  desc.add<edm::InputTag>("endcapHits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
115  desc.add<std::string>("barrelClusterCollection", "islandBarrelBasicClusters");
116  desc.add<std::string>("endcapClusterCollection", "islandEndcapBasicClusters");
117  desc.add<double>("IslandBarrelSeedThr", 0.5);
118  desc.add<double>("IslandEndcapSeedThr", 0.18);
119 
121  posCalcParameters.add<bool>("LogWeighted", true);
122  posCalcParameters.add<double>("T0_barl", 7.4);
123  posCalcParameters.add<double>("T0_endc", 3.1);
124  posCalcParameters.add<double>("T0_endcPresh", 1.2);
125  posCalcParameters.add<double>("W0", 4.2);
126  posCalcParameters.add<double>("X0", 0.89);
127  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcParameters);
128 
129  desc.add<std::string>("clustershapecollectionEE", "islandEndcapShape");
130  desc.add<std::string>("clustershapecollectionEB", "islandBarrelShape");
131  desc.add<std::string>("barrelShapeAssociation", "islandBarrelShapeAssoc");
132  desc.add<std::string>("endcapShapeAssociation", "islandEndcapShapeAssoc");
133  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEB", {});
134  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEE", {});
135  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEB", {});
136  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEE", {});
137  descriptions.add("IslandClusterProducer", desc);
138 }
139 
141 {
144  nEvt_++;
145 }
146 
147 
149 {
151  evt.getByToken(token, rhcHandle);
152  return rhcHandle.product();
153 
154 }
155 
157  const std::string& clusterShapeAssociation,
158  const IslandClusterAlgo::EcalPart& ecalPart)
159 {
160  // get the hit collection from the event:
161  const EcalRecHitCollection *hitCollection_p = getCollection(evt,token);
162 
163  // get the geometry and topology from the event setup:
164  edm::ESHandle<CaloGeometry> geoHandle;
165  es.get<CaloGeometryRecord>().get(geoHandle);
166 
167  const CaloSubdetectorGeometry *geometry_p;
168  std::unique_ptr<CaloSubdetectorTopology> topology_p;
169 
170  std::string clustershapetag;
171  if (ecalPart == IslandClusterAlgo::barrel)
172  {
173  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
174  topology_p = std::make_unique<EcalBarrelTopology>(*geoHandle);
175  }
176  else
177  {
178  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
179  topology_p = std::make_unique<EcalEndcapTopology>(*geoHandle);
180  }
181 
182  const CaloSubdetectorGeometry *geometryES_p;
183  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
184 
185  // Run the clusterization algorithm:
187  clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p.get(), geometryES_p, ecalPart);
188 
189  //Create associated ClusterShape objects.
190  std::vector <reco::ClusterShape> ClusVec;
191  for (int erg=0;erg<int(clusters.size());++erg){
192  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],hitCollection_p,geometry_p,topology_p.get());
193  ClusVec.push_back(TestShape);
194  }
195 
196  //Put clustershapes in event, but retain a Handle on them.
197  auto clustersshapes_p = std::make_unique<reco::ClusterShapeCollection>();
198  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
200  if (ecalPart == IslandClusterAlgo::barrel)
201  clusHandle= evt.put(std::move(clustersshapes_p), clustershapecollectionEB_);
202  else
203  clusHandle= evt.put(std::move(clustersshapes_p), clustershapecollectionEE_);
204 
205  // create a unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
206  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
207  clusters_p->assign(clusters.begin(), clusters.end());
209  if (ecalPart == IslandClusterAlgo::barrel)
210  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
211  else
212  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
213 
214 
215  // BasicClusterShapeAssociationMap
216  auto shapeAssocs_p = std::make_unique<reco::BasicClusterShapeAssociationCollection>(bccHandle, clusHandle);
217  for (unsigned int i = 0; i < clusHandle->size(); i++){
218  shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle,i),edm::Ref<reco::ClusterShapeCollection>(clusHandle,i));
219  }
220  evt.put(std::move(shapeAssocs_p),clusterShapeAssociation);
221 }
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:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
IslandClusterProducer(const edm::ParameterSet &ps)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
edm::EDGetTokenT< EcalRecHitCollection > barrelRecHits_
edm::EDGetTokenT< EcalRecHitCollection > endcapRecHits_
std::string barrelClusterShapeAssociation_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
IslandClusterAlgo * island_p
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< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
T const * product() const
Definition: Handle.h:74
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string endcapClusterShapeAssociation_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T get() const
Definition: EventSetup.h:71
const EcalRecHitCollection * getCollection(edm::Event &evt, const edm::EDGetTokenT< EcalRecHitCollection > &token)
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const edm::EDGetTokenT< EcalRecHitCollection > &token, const std::string &clusterCollection, const std::string &clusterShapeAssociation, const IslandClusterAlgo::EcalPart &ecalPart)
IslandClusterAlgo::VerbosityLevel verbosity
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511