CMS 3D CMS Logo

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