CMS 3D CMS Logo

HiSuperClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 #include <sstream>
6 
7 // Framework
16 
17 // Reconstruction Classes
21 
22 // Class header file
24 
25 
27 {
28  // The verbosity level
29  std::string verbosityString = ps.getParameter<std::string>("VerbosityLevel");
30  if (verbosityString == "DEBUG") verbosity = HiBremRecoveryClusterAlgo::pDEBUG;
31  else if (verbosityString == "WARNING") verbosity = HiBremRecoveryClusterAlgo::pWARNING;
32  else if (verbosityString == "INFO") verbosity = HiBremRecoveryClusterAlgo::pINFO;
34 
35 
36  endcapSuperclusterCollection_ = ps.getParameter<std::string>("endcapSuperclusterCollection");
37  barrelSuperclusterCollection_ = ps.getParameter<std::string>("barrelSuperclusterCollection");
38 
39  doBarrel_ = ps.getParameter<bool>("doBarrel");
40  doEndcaps_ = ps.getParameter<bool>("doEndcaps");
41 
42 
43  barrelEtaSearchRoad_ = ps.getParameter<double>("barrelEtaSearchRoad");
44  barrelPhiSearchRoad_ = ps.getParameter<double>("barrelPhiSearchRoad");
45  endcapEtaSearchRoad_ = ps.getParameter<double>("endcapEtaSearchRoad");
46  endcapPhiSearchRoad_ = ps.getParameter<double>("endcapPhiSearchRoad");
47  seedTransverseEnergyThreshold_ = ps.getParameter<double>("seedTransverseEnergyThreshold");
48  barrelBCEnergyThreshold_ = ps.getParameter<double>("barrelBCEnergyThreshold");
49  endcapBCEnergyThreshold_ = ps.getParameter<double>("endcapBCEnergyThreshold");
50 
51  if (verbosityString == "INFO") {
52  std::cout <<"Barrel BC Energy threshold = "<<barrelBCEnergyThreshold_<<std::endl;
53  std::cout <<"Endcap BC Energy threshold = "<<endcapBCEnergyThreshold_<<std::endl;
54  }
55 
56  bremAlgo_p = new HiBremRecoveryClusterAlgo(barrelEtaSearchRoad_, barrelPhiSearchRoad_,
57  endcapEtaSearchRoad_, endcapPhiSearchRoad_,
58  seedTransverseEnergyThreshold_,
59  barrelBCEnergyThreshold_,
60  endcapBCEnergyThreshold_,
61  verbosity);
62 
63  produces< reco::SuperClusterCollection >(endcapSuperclusterCollection_);
64  produces< reco::SuperClusterCollection >(barrelSuperclusterCollection_);
65 
66  eeClustersToken_ = consumes<reco::BasicClusterCollection>(edm::InputTag(ps.getParameter<std::string>("endcapClusterProducer"),
67  ps.getParameter<std::string>("endcapClusterCollection")));
68  ebClustersToken_ = consumes<reco::BasicClusterCollection>(edm::InputTag(ps.getParameter<std::string>("barrelClusterProducer"),
69  ps.getParameter<std::string>("barrelClusterCollection")));
70 
71  totalE = 0;
72  noSuperClusters = 0;
73  nEvt_ = 0;
74 }
75 
76 
78 {
79  delete bremAlgo_p;
80 }
81 
83  double averEnergy = 0.;
84  std::ostringstream str;
85  str << "HiSuperClusterProducer::endJob()\n"
86  << " total # reconstructed super clusters: " << noSuperClusters << "\n"
87  << " total energy of all clusters: " << totalE << "\n";
88  if(noSuperClusters>0) {
89  averEnergy = totalE / noSuperClusters;
90  str << " average SuperCluster energy = " << averEnergy << "\n";
91  }
92  edm::LogInfo("HiSuperClusterProducerInfo") << str.str() << "\n";
93 
94 }
95 
96 
98 {
99  if(doEndcaps_)
101 
102  if(doBarrel_)
104 
105  nEvt_++;
106 }
107 
108 
112 {
113  // get the cluster collection out and turn it to a BasicClusterRefVector:
114  reco::CaloClusterPtrVector *clusterPtrVector_p = new reco::CaloClusterPtrVector;
115  getClusterPtrVector(evt, clustersToken, clusterPtrVector_p);
116 
117  // run the brem recovery and get the SC collection
118  auto superclusters_ap = std::make_unique<reco::SuperClusterCollection>(bremAlgo_p->makeSuperClusters(*clusterPtrVector_p));
119 
120  // count the total energy and the number of superclusters
121  reco::SuperClusterCollection::iterator it;
122  for (it = superclusters_ap->begin(); it != superclusters_ap->end(); it++)
123  {
124  totalE += it->energy();
125  noSuperClusters++;
126  }
127 
128  // put the SC collection in the event
129  evt.put(std::move(superclusters_ap), superclusterCollection);
130 
131  delete clusterPtrVector_p;
132 }
133 
134 
136 {
138 
139  evt.getByToken(clustersToken, bccHandle);
140 
141  if (!(bccHandle.isValid()))
142  {
143  edm::LogError("HiSuperClusterProducerError") << "could not get a handle on the BasicCluster Collection!";
144  clusterPtrVector_p = nullptr;
145  }
146 
147  const reco::BasicClusterCollection *clusterCollection_p = bccHandle.product();
148  for (unsigned int i = 0; i < clusterCollection_p->size(); i++)
149  {
150  clusterPtrVector_p->push_back(reco::CaloClusterPtr(bccHandle, i));
151  }
152 }
153 
154 
155 
156 //define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BasicClusterCollection > ebClustersToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void produce(edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
edm::EDGetTokenT< reco::BasicClusterCollection > eeClustersToken_
reco::SuperClusterCollection makeSuperClusters(reco::CaloClusterPtrVector &clusters)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produceSuperclustersForECALPart(edm::Event &evt, const edm::EDGetTokenT< reco::BasicClusterCollection > &clustersToken, std::string superclusterColection)
void getClusterPtrVector(edm::Event &evt, const edm::EDGetTokenT< reco::BasicClusterCollection > &clustersToken, reco::CaloClusterPtrVector *)
edm::PtrVector< CaloCluster > CaloClusterPtrVector
HiSuperClusterProducer(const edm::ParameterSet &ps)
bool isValid() const
Definition: HandleBase.h:74
HiBremRecoveryClusterAlgo::VerbosityLevel verbosity
T const * product() const
Definition: Handle.h:74
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
HiBremRecoveryClusterAlgo * bremAlgo_p
#define str(s)
def move(src, dest)
Definition: eostools.py:511