CMS 3D CMS Logo

PreshowerClusterShapeProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <vector>
3 #include <memory>
4 
5 // user include files
8 
16 
17 // Reconstruction Classes
20 
30 #include <fstream>
31 #include <sstream>
32 
34 
35 using namespace std;
36 using namespace reco;
37 using namespace edm;
39 
41  // use configuration file to setup input/output collection names
42  // Parameters to identify the hit collections
43  preshHitToken_ =
44  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
45  endcapSClusterToken_ =
46  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
47 
48  PreshowerClusterShapeCollectionX_ = ps.getParameter<string>("PreshowerClusterShapeCollectionX");
49  PreshowerClusterShapeCollectionY_ = ps.getParameter<string>("PreshowerClusterShapeCollectionY");
50 
51  produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionX_);
52  produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionY_);
53 
54  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
55  int preshNst = ps.getParameter<int>("preshPi0Nstrip");
56 
57  string debugString = ps.getParameter<string>("debugLevel");
58 
59 
60  string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles","RecoEcal/EgammaClusterProducers/data/");
61 
62  presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath);
63 
64  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated " ;
65 
66 
67  nEvt_ = 0;
68 
69 }
70 
71 
73  delete presh_pi0_algo;
74 }
75 
76 
78 
79  ostringstream ostr; // use this stream for all messages in produce
80 
81  LogTrace("EcalClusters") << "\n ....... Event " << evt.id() << " with Number = " << nEvt_+1 << " is analyzing ....... " ;
82 
83 
85  Handle< SuperClusterCollection > pSuperClusters;
86 
87  // get the ECAL -> Preshower geometry and topology:
88  ESHandle<CaloGeometry> geoHandle;
89  es.get<CaloGeometryRecord>().get(geoHandle);
91  const CaloSubdetectorGeometry *& geometry_p = geometry;
92 
93 
94  // create a unique_ptr to a PreshowerClusterShapeCollection
95  auto ps_cl_for_pi0_disc_x = std::make_unique<reco::PreshowerClusterShapeCollection>();
96  auto ps_cl_for_pi0_disc_y = std::make_unique<reco::PreshowerClusterShapeCollection>();
97 
98 
99  std::unique_ptr<CaloSubdetectorTopology> topology_p;
100  if (geometry)
101  topology_p = std::make_unique<EcalPreshowerTopology>();
102 
103 
104  // fetch the Preshower product (RecHits)
105  evt.getByToken( preshHitToken_, pRecHits);
106  // pointer to the object in the product
107  const EcalRecHitCollection* rechits = pRecHits.product();
108 
109  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: " << rechits->size() ;
110 
111  // if ( rechits->size() <= 0 ) return;
112 
113  // make the map of Preshower rechits:
114  map<DetId, EcalRecHit> rechits_map;
116  for (it = rechits->begin(); it != rechits->end(); it++) {
117  rechits_map.insert(make_pair(it->id(), *it));
118  }
119 
120  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size " << rechits_map.size() <<" was created!" ;
121 
122  reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
123 
124  //make cycle over Photon Collection
125  int SC_index = 0;
126 // Handle<PhotonCollection> correctedPhotonHandle;
127 // evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
128 // const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
129 // cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
130 
131  evt.getByToken(endcapSClusterToken_, pSuperClusters);
132  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
133  LogTrace("EcalClusters") << "### Total # Endcap Superclusters: " << SClusts->size() ;
134 
135  SuperClusterCollection::const_iterator it_s;
136  for ( it_s=SClusts->begin(); it_s!=SClusts->end(); it_s++ ) {
137 
138  SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters,SC_index));
139 
140  float SC_eta = it_super->eta();
141 
142  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy() << " superCl_Et = " << it_super->energy()*sin(2*atan(exp(-it_super->eta()))) << " superCl_Eta = " << SC_eta << " superCl_Phi = " << it_super->phi() ;
143 
144 
145  if(fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5)
146  { // Use Preshower region only
147  if (geometry)
148  {
149  const GlobalPoint pointSC(it_super->x(),it_super->y(),it_super->z()); // get the centroid of the SC
150  LogTrace("EcalClusters") << "SC centroind = " << pointSC ;
151 
152  // Get the Preshower 2-planes RecHit vectors associated with the given SC
153 
154  DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
155  DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
156  ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
157  ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
158 
159  vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p.get());
160  vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p.get());
161 
162  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = " ;
163  for(int k1=0;k1<11;k1++) {
164  LogTrace("EcalClusters") << vout_stripE1[k1] << " " ;
165  }
166 
167  for(int k1=0;k1<11;k1++) {
168  LogTrace("EcalClusters") << vout_stripE2[k1] << " " ;
169  }
170 
172  ps1.setSCRef(it_super);
173  ps_cl_x.push_back(ps1);
174 
176  ps2.setSCRef(it_super);
177  ps_cl_y.push_back(ps2);
178 
179  }
180  SC_index++;
181  } // end of cycle over Endcap SC
182  }
183  // put collection of PreshowerClusterShape in the Event:
184  ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
185  ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
186 
187  evt.put(std::move(ps_cl_for_pi0_disc_x), PreshowerClusterShapeCollectionX_);
188  evt.put(std::move(ps_cl_for_pi0_disc_y), PreshowerClusterShapeCollectionY_);
189  LogTrace("EcalClusters") << "PreshowerClusterShapeCollection added to the event" ;
190 
191  nEvt_++;
192 
193  LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
194 }
#define LogDebug(id)
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
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void setSCRef(const SuperClusterRef &r)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
#define LogTrace(id)
const_iterator end() const
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:74
ESHandle< TrackerGeometry > geometry
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
PreshowerClusterShapeProducer(const edm::ParameterSet &ps)
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const