CMS 3D CMS Logo

PreshowerClusterShapeProducer.cc
Go to the documentation of this file.
1 // authors A. Kyriakis, D. Maletic
2 
27 
28 #include <fstream>
29 #include <memory>
30 #include <sstream>
31 #include <vector>
32 
34 public:
36 
38 
40 
41  void produce(edm::Event& evt, const edm::EventSetup& es) override;
42 
43 private:
44  int nEvt_; // internal counter of events
45 
46  //clustering parameters:
47 
48  edm::EDGetTokenT<EcalRecHitCollection> preshHitToken_; // name of module/plugin/producer
49  // producing hits
51  // of endcap superclusters
53 
56 
57  EndcapPiZeroDiscriminatorAlgo* presh_pi0_algo; // algorithm doing the real work
58 };
59 
62 
63 using namespace std;
64 using namespace reco;
65 using namespace edm;
67 
69  // use configuration file to setup input/output collection names
70  // Parameters to identify the hit collections
71  preshHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
72  endcapSClusterToken_ =
73  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
74  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
75 
76  PreshowerClusterShapeCollectionX_ = ps.getParameter<string>("PreshowerClusterShapeCollectionX");
77  PreshowerClusterShapeCollectionY_ = ps.getParameter<string>("PreshowerClusterShapeCollectionY");
78 
79  produces<reco::PreshowerClusterShapeCollection>(PreshowerClusterShapeCollectionX_);
80  produces<reco::PreshowerClusterShapeCollection>(PreshowerClusterShapeCollectionY_);
81 
82  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
83  int preshNst = ps.getParameter<int>("preshPi0Nstrip");
84 
85  string debugString = ps.getParameter<string>("debugLevel");
86 
87  string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles", "RecoEcal/EgammaClusterProducers/data/");
88 
89  presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath);
90 
91  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated ";
92 
93  nEvt_ = 0;
94 }
95 
97 
99  ostringstream ostr; // use this stream for all messages in produce
100 
101  LogTrace("EcalClusters") << "\n ....... Event " << evt.id() << " with Number = " << nEvt_ + 1
102  << " is analyzing ....... ";
103 
105  Handle<SuperClusterCollection> pSuperClusters;
106 
107  // get the ECAL -> Preshower geometry and topology:
108  ESHandle<CaloGeometry> geoHandle = es.getHandle(caloGeometryToken_);
110  const CaloSubdetectorGeometry*& geometry_p = geometry;
111 
112  // create a unique_ptr to a PreshowerClusterShapeCollection
113  auto ps_cl_for_pi0_disc_x = std::make_unique<reco::PreshowerClusterShapeCollection>();
114  auto ps_cl_for_pi0_disc_y = std::make_unique<reco::PreshowerClusterShapeCollection>();
115 
116  std::unique_ptr<CaloSubdetectorTopology> topology_p;
117  if (geometry)
118  topology_p = std::make_unique<EcalPreshowerTopology>();
119 
120  // fetch the Preshower product (RecHits)
121  evt.getByToken(preshHitToken_, pRecHits);
122  // pointer to the object in the product
123  const EcalRecHitCollection* rechits = pRecHits.product();
124 
125  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: " << rechits->size();
126 
127  // if ( rechits->size() <= 0 ) return;
128 
129  // make the map of Preshower rechits:
130  map<DetId, EcalRecHit> rechits_map;
132  for (it = rechits->begin(); it != rechits->end(); it++) {
133  rechits_map.insert(make_pair(it->id(), *it));
134  }
135 
136  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size " << rechits_map.size()
137  << " was created!";
138 
139  reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
140 
141  //make cycle over Photon Collection
142  int SC_index = 0;
143  // Handle<PhotonCollection> correctedPhotonHandle;
144  // evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
145  // const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
146  // cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
147 
148  evt.getByToken(endcapSClusterToken_, pSuperClusters);
149  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
150  LogTrace("EcalClusters") << "### Total # Endcap Superclusters: " << SClusts->size();
151 
152  SuperClusterCollection::const_iterator it_s;
153  for (it_s = SClusts->begin(); it_s != SClusts->end(); it_s++) {
154  SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters, SC_index));
155 
156  float SC_eta = it_super->eta();
157 
158  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy()
159  << " superCl_Et = " << it_super->energy() * sin(2 * atan(exp(-it_super->eta())))
160  << " superCl_Eta = " << SC_eta << " superCl_Phi = " << it_super->phi();
161 
162  if (fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5) { // Use Preshower region only
163  if (geometry) {
164  const GlobalPoint pointSC(it_super->x(), it_super->y(), it_super->z()); // get the centroid of the SC
165  LogTrace("EcalClusters") << "SC centroind = " << pointSC;
166 
167  // Get the Preshower 2-planes RecHit vectors associated with the given SC
168 
169  DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
170  DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
171  ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
172  ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
173 
174  vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p.get());
175  vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p.get());
176 
177  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = ";
178  for (int k1 = 0; k1 < 11; k1++) {
179  LogTrace("EcalClusters") << vout_stripE1[k1] << " ";
180  }
181 
182  for (int k1 = 0; k1 < 11; k1++) {
183  LogTrace("EcalClusters") << vout_stripE2[k1] << " ";
184  }
185 
187  ps1.setSCRef(it_super);
188  ps_cl_x.push_back(ps1);
189 
191  ps2.setSCRef(it_super);
192  ps_cl_y.push_back(ps2);
193  }
194  SC_index++;
195  } // end of cycle over Endcap SC
196  }
197  // put collection of PreshowerClusterShape in the Event:
198  ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
199  ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
200 
201  evt.put(std::move(ps_cl_for_pi0_disc_x), PreshowerClusterShapeCollectionX_);
202  evt.put(std::move(ps_cl_for_pi0_disc_y), PreshowerClusterShapeCollectionY_);
203  LogTrace("EcalClusters") << "PreshowerClusterShapeCollection added to the event";
204 
205  nEvt_++;
206 
207  LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
208 }
EcalPreshowerTopology.h
reco::PreshowerClusterShape
Definition: PreshowerClusterShape.h:14
Handle.h
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
reco::PreshowerClusterShape::setSCRef
void setSCRef(const SuperClusterRef &r)
Definition: PreshowerClusterShape.h:36
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
EndcapPiZeroDiscriminatorAlgo.h
geometry
Definition: geometry.py:1
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
EDProducer.h
edm::SortedCollection< EcalRecHit >
relativeConstraints.geometry
geometry
Definition: relativeConstraints.py:39
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
ESDetId
Definition: ESDetId.h:15
ESDetId.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
EndcapPiZeroDiscriminatorAlgo
Definition: EndcapPiZeroDiscriminatorAlgo.h:15
edm::Ref< SuperClusterCollection >
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
DetId
Definition: DetId.h:17
MakerMacros.h
PreshowerClusterShapeProducer::caloGeometryToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: PreshowerClusterShapeProducer.cc:52
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PreshowerClusterShapeProducer
Definition: PreshowerClusterShapeProducer.cc:33
TruncatedPyramid.h
edm::ESHandle< CaloGeometry >
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
EcalPreshowerGeometry.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
Point3DBase< float, GlobalTag >
CaloGeometryRecord.h
reco::PreshowerClusterShapeCollection
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
Definition: PreshowerClusterShapeFwd.h:13
CaloSubdetectorGeometry.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
PreshowerClusterShapeProducer::PreshowerClusterShapeCollectionY_
std::string PreshowerClusterShapeCollectionY_
Definition: PreshowerClusterShapeProducer.cc:55
PreshowerClusterShapeProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: PreshowerClusterShapeProducer.cc:98
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::stream::EDProducer
Definition: EDProducer.h:36
PreshowerClusterShapeProducer::PreshowerClusterShapeCollectionX_
std::string PreshowerClusterShapeCollectionX_
Definition: PreshowerClusterShapeProducer.cc:54
edm::EventSetup
Definition: EventSetup.h:58
DetId::Ecal
Definition: DetId.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
PreshowerClusterShapeProducer::endcapSClusterToken_
edm::EDGetTokenT< reco::SuperClusterCollection > endcapSClusterToken_
Definition: PreshowerClusterShapeProducer.cc:50
PreshowerClusterShapeProducer::~PreshowerClusterShapeProducer
~PreshowerClusterShapeProducer() override
Definition: PreshowerClusterShapeProducer.cc:96
EcalPreshower
Definition: EcalSubdetector.h:10
CaloCellGeometry.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SuperClusterFwd.h
SuperCluster.h
CaloGeometry.h
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
Point3D.h
PreshowerClusterShapeProducer::Point
math::XYZPoint Point
Definition: PreshowerClusterShapeProducer.cc:35
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
PreshowerClusterShapeProducer::preshHitToken_
edm::EDGetTokenT< EcalRecHitCollection > preshHitToken_
Definition: PreshowerClusterShapeProducer.cc:48
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
PreshowerClusterShape.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::Event
Definition: Event.h:73
PreshowerClusterShapeProducer::PreshowerClusterShapeProducer
PreshowerClusterShapeProducer(const edm::ParameterSet &ps)
Definition: PreshowerClusterShapeProducer.cc:68
PreshowerClusterShapeProducer::presh_pi0_algo
EndcapPiZeroDiscriminatorAlgo * presh_pi0_algo
Definition: PreshowerClusterShapeProducer.cc:57
edm::InputTag
Definition: InputTag.h:15
PreshowerClusterShapeProducer::nEvt_
int nEvt_
Definition: PreshowerClusterShapeProducer.cc:44