CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  preshHitProducer_ = ps.getParameter<edm::InputTag>("preshRecHitProducer");
44  endcapSClusterProducer_ = ps.getParameter<edm::InputTag>("endcapSClusterProducer");
45 
46  PreshowerClusterShapeCollectionX_ = ps.getParameter<string>("PreshowerClusterShapeCollectionX");
47  PreshowerClusterShapeCollectionY_ = ps.getParameter<string>("PreshowerClusterShapeCollectionY");
48 
49  produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionX_);
50  produces< reco::PreshowerClusterShapeCollection >(PreshowerClusterShapeCollectionY_);
51 
52  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
53  int preshNst = ps.getParameter<int>("preshPi0Nstrip");
54 
55  string debugString = ps.getParameter<string>("debugLevel");
56 
57 
58  string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles","RecoEcal/EgammaClusterProducers/data/");
59 
60  presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath.c_str());
61 
62  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated " ;
63 
64 
65  nEvt_ = 0;
66 
67 }
68 
69 
71  delete presh_pi0_algo;
72 }
73 
74 
76 
77  ostringstream ostr; // use this stream for all messages in produce
78 
79  LogTrace("EcalClusters") << "\n ....... Event " << evt.id() << " with Number = " << nEvt_+1 << " is analyzing ....... " ;
80 
81 
83  Handle< SuperClusterCollection > pSuperClusters;
84 
85  // get the ECAL -> Preshower geometry and topology:
86  ESHandle<CaloGeometry> geoHandle;
87  es.get<CaloGeometryRecord>().get(geoHandle);
88  const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
89  const CaloSubdetectorGeometry *& geometry_p = geometry;
90 
91 
92  // create an auto_ptr to a PreshowerClusterShapeCollection
93  std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_x(new reco::PreshowerClusterShapeCollection);
94  std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_y(new reco::PreshowerClusterShapeCollection);
95 
96 
97  CaloSubdetectorTopology* topology_p=0;
98  if (geometry)
99  topology_p = new EcalPreshowerTopology(geoHandle);
100 
101 
102  // fetch the Preshower product (RecHits)
103  evt.getByLabel( preshHitProducer_, pRecHits);
104  // pointer to the object in the product
105  const EcalRecHitCollection* rechits = pRecHits.product();
106 
107  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: " << rechits->size() ;
108 
109  // if ( rechits->size() <= 0 ) return;
110 
111  // make the map of Preshower rechits:
112  map<DetId, EcalRecHit> rechits_map;
114  for (it = rechits->begin(); it != rechits->end(); it++) {
115  rechits_map.insert(make_pair(it->id(), *it));
116  }
117 
118  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size " << rechits_map.size() <<" was created!" ;
119 
120  reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
121 
122  //make cycle over Photon Collection
123  int SC_index = 0;
124 // Handle<PhotonCollection> correctedPhotonHandle;
125 // evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
126 // const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
127 // cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
128 
129  evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
130  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
131  LogTrace("EcalClusters") << "### Total # Endcap Superclusters: " << SClusts->size() ;
132 
133  SuperClusterCollection::const_iterator it_s;
134  for ( it_s=SClusts->begin(); it_s!=SClusts->end(); it_s++ ) {
135 
136  SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters,SC_index));
137 
138  float SC_Et = it_super->energy()*sin(2*atan(exp(-it_super->eta())));
139  float SC_eta = it_super->eta();
140  float SC_phi = it_super->phi();
141 
142  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy() << " superCl_Et = " << SC_Et << " superCl_Eta = " << SC_eta << " superCl_Phi = " << SC_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);
160  vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p);
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(ps_cl_for_pi0_disc_x, PreshowerClusterShapeCollectionX_);
188  evt.put(ps_cl_for_pi0_disc_y, PreshowerClusterShapeCollectionY_);
189  LogTrace("EcalClusters") << "PreshowerClusterShapeCollection added to the event" ;
190 
191  if (topology_p)
192  delete topology_p;
193 
194  nEvt_++;
195 
196  LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
197 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setSCRef(const SuperClusterRef &r)
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
#define LogTrace(id)
const_iterator end() const
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:74
ESHandle< TrackerGeometry > geometry
edm::EventID id() const
Definition: EventBase.h:56
size_type size() const
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
PreshowerClusterShapeProducer(const edm::ParameterSet &ps)
const_iterator begin() const