CMS 3D CMS Logo

IslandClusterProducer.cc
Go to the documentation of this file.
31 
32 #include <ctime>
33 #include <iostream>
34 #include <memory>
35 #include <vector>
36 
38 public:
40 
41  ~IslandClusterProducer() override;
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43  void produce(edm::Event&, const edm::EventSetup&) override;
44 
45 private:
46  int nMaxPrintout_; // max # of printouts
47  int nEvt_; // internal counter of events
48 
50 
54 
57 
60 
61  //BasicClusterShape AssociationMap
64 
65  PositionCalc posCalculator_; // position calculation algorithm
66  ClusterShapeAlgo shapeAlgo_; // cluster shape algorithm
68 
69  bool counterExceeded() const { return ((nEvt_ > nMaxPrintout_) || (nMaxPrintout_ < 0)); }
70 
72 
74  const edm::EventSetup& es,
77  const std::string& clusterShapeAssociation,
78  const IslandClusterAlgo::EcalPart& ecalPart);
79 
80  void outputValidationInfo(reco::CaloClusterPtrVector& clusterPtrVector);
81 };
82 
85 
87  // The verbosity level
88  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
89  if (verbosityString == "DEBUG")
91  else if (verbosityString == "WARNING")
93  else if (verbosityString == "INFO")
95  else
97 
98  // Parameters to identify the hit collections
99  barrelRecHits_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("barrelHits"));
100  endcapRecHits_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("endcapHits"));
101 
102  //EventSetup Token for CaloGeometry
103  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
104 
105  // The names of the produced cluster collections
106  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
107  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
108 
109  // Island algorithm parameters
110  double barrelSeedThreshold = ps.getParameter<double>("IslandBarrelSeedThr");
111  double endcapSeedThreshold = ps.getParameter<double>("IslandEndcapSeedThr");
112 
113  // Parameters for the position calculation:
117 
118  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
119  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
120 
121  //AssociationMap
122  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
123  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
124 
125  const std::vector<std::string> seedflagnamesEB =
126  ps.getParameter<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEB");
127  const std::vector<int> seedflagsexclEB = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEB);
128 
129  const std::vector<std::string> seedflagnamesEE =
130  ps.getParameter<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEE");
131  const std::vector<int> seedflagsexclEE = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEE);
132 
133  const std::vector<std::string> flagnamesEB = ps.getParameter<std::vector<std::string>>("RecHitFlagToBeExcludedEB");
134  const std::vector<int> flagsexclEB = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
135 
136  const std::vector<std::string> flagnamesEE = ps.getParameter<std::vector<std::string>>("RecHitFlagToBeExcludedEE");
137  const std::vector<int> flagsexclEE = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
138 
139  // Produces a collection of barrel and a collection of endcap clusters
140 
141  produces<reco::ClusterShapeCollection>(clustershapecollectionEE_);
142  produces<reco::BasicClusterCollection>(endcapClusterCollection_);
143  produces<reco::ClusterShapeCollection>(clustershapecollectionEB_);
144  produces<reco::BasicClusterCollection>(barrelClusterCollection_);
145  produces<reco::BasicClusterShapeAssociationCollection>(barrelClusterShapeAssociation_);
146  produces<reco::BasicClusterShapeAssociationCollection>(endcapClusterShapeAssociation_);
147 
148  island_p = new IslandClusterAlgo(barrelSeedThreshold,
149  endcapSeedThreshold,
151  seedflagsexclEB,
152  seedflagsexclEE,
153  flagsexclEB,
154  flagsexclEE,
155  verbosity);
156 
157  nEvt_ = 0;
158 }
159 
161 
164  desc.add<std::string>("VerbosityLevel", "ERROR");
165  desc.add<edm::InputTag>("barrelHits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
166  desc.add<edm::InputTag>("endcapHits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
167  desc.add<std::string>("barrelClusterCollection", "islandBarrelBasicClusters");
168  desc.add<std::string>("endcapClusterCollection", "islandEndcapBasicClusters");
169  desc.add<double>("IslandBarrelSeedThr", 0.5);
170  desc.add<double>("IslandEndcapSeedThr", 0.18);
171 
173  posCalcParameters.add<bool>("LogWeighted", true);
174  posCalcParameters.add<double>("T0_barl", 7.4);
175  posCalcParameters.add<double>("T0_endc", 3.1);
176  posCalcParameters.add<double>("T0_endcPresh", 1.2);
177  posCalcParameters.add<double>("W0", 4.2);
178  posCalcParameters.add<double>("X0", 0.89);
179  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcParameters);
180 
181  desc.add<std::string>("clustershapecollectionEE", "islandEndcapShape");
182  desc.add<std::string>("clustershapecollectionEB", "islandBarrelShape");
183  desc.add<std::string>("barrelShapeAssociation", "islandBarrelShapeAssoc");
184  desc.add<std::string>("endcapShapeAssociation", "islandEndcapShapeAssoc");
185  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEB", {});
186  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEE", {});
187  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEB", {});
188  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEE", {});
189  descriptions.add("IslandClusterProducer", desc);
190 }
191 
197  nEvt_++;
198 }
199 
203  evt.getByToken(token, rhcHandle);
204  return rhcHandle.product();
205 }
206 
208  const edm::EventSetup& es,
211  const std::string& clusterShapeAssociation,
212  const IslandClusterAlgo::EcalPart& ecalPart) {
213  // get the hit collection from the event:
214  const EcalRecHitCollection* hitCollection_p = getCollection(evt, token);
215 
216  // get the geometry and topology from the event setup:
218 
219  const CaloSubdetectorGeometry* geometry_p;
220  std::unique_ptr<CaloSubdetectorTopology> topology_p;
221 
222  std::string clustershapetag;
223  if (ecalPart == IslandClusterAlgo::barrel) {
224  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
225  topology_p = std::make_unique<EcalBarrelTopology>(*geoHandle);
226  } else {
227  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
228  topology_p = std::make_unique<EcalEndcapTopology>(*geoHandle);
229  }
230 
231  const CaloSubdetectorGeometry* geometryES_p;
232  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
233 
234  // Run the clusterization algorithm:
236  clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p.get(), geometryES_p, ecalPart);
237 
238  //Create associated ClusterShape objects.
239  std::vector<reco::ClusterShape> ClusVec;
240  for (int erg = 0; erg < int(clusters.size()); ++erg) {
241  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg], hitCollection_p, geometry_p, topology_p.get());
242  ClusVec.push_back(TestShape);
243  }
244 
245  //Put clustershapes in event, but retain a Handle on them.
246  auto clustersshapes_p = std::make_unique<reco::ClusterShapeCollection>();
247  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
249  if (ecalPart == IslandClusterAlgo::barrel)
250  clusHandle = evt.put(std::move(clustersshapes_p), clustershapecollectionEB_);
251  else
252  clusHandle = evt.put(std::move(clustersshapes_p), clustershapecollectionEE_);
253 
254  // create a unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
255  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
256  clusters_p->assign(clusters.begin(), clusters.end());
258  if (ecalPart == IslandClusterAlgo::barrel)
259  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
260  else
261  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
262 
263  // BasicClusterShapeAssociationMap
264  auto shapeAssocs_p = std::make_unique<reco::BasicClusterShapeAssociationCollection>(bccHandle, clusHandle);
265  for (unsigned int i = 0; i < clusHandle->size(); i++) {
266  shapeAssocs_p->insert(edm::Ref<reco::BasicClusterCollection>(bccHandle, i),
268  }
269  evt.put(std::move(shapeAssocs_p), clusterShapeAssociation);
270 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
IslandClusterProducer(const edm::ParameterSet &ps)
T const * product() const
Definition: Handle.h:70
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
edm::EDGetTokenT< EcalRecHitCollection > barrelRecHits_
edm::EDGetTokenT< EcalRecHitCollection > endcapRecHits_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string barrelClusterShapeAssociation_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
IslandClusterAlgo * island_p
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
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 >())
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string endcapClusterShapeAssociation_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
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)
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
void outputValidationInfo(reco::CaloClusterPtrVector &clusterPtrVector)
IslandClusterAlgo::VerbosityLevel verbosity
void produce(edm::Event &, const edm::EventSetup &) override
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
def move(src, dest)
Definition: eostools.py:511