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  if (debugString == "DEBUG") debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pDEBUG;
58  else if (debugString == "INFO") debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pINFO;
59  else debugL_pi0 = EndcapPiZeroDiscriminatorAlgo::pERROR;
60 
61  string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles","RecoEcal/EgammaClusterProducers/data/");
62 
63  presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath.c_str(), debugL_pi0);
64 
65  if ( debugL_pi0 == EndcapPiZeroDiscriminatorAlgo::pDEBUG )
66  cout << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated " << endl;
67 
68  nEvt_ = 0;
69 
70 }
71 
72 
74  delete presh_pi0_algo;
75 }
76 
77 
79 
80  ostringstream ostr; // use this stream for all messages in produce
81 
82  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG )
83  cout << "\n ....... Event " << evt.id() << " with Number = " << nEvt_+1
84  << " is analyzing ....... " << endl << endl;
85 
87  Handle< SuperClusterCollection > pSuperClusters;
88 
89  // get the ECAL -> Preshower geometry and topology:
90  ESHandle<CaloGeometry> geoHandle;
91  es.get<CaloGeometryRecord>().get(geoHandle);
92  const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
93  const CaloSubdetectorGeometry *& geometry_p = geometry;
94 
95 
96  // create an auto_ptr to a PreshowerClusterShapeCollection
97  std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_x(new reco::PreshowerClusterShapeCollection);
98  std::auto_ptr< reco::PreshowerClusterShapeCollection > ps_cl_for_pi0_disc_y(new reco::PreshowerClusterShapeCollection);
99 
100 
101  CaloSubdetectorTopology* topology_p=0;
102  if (geometry)
103  topology_p = new EcalPreshowerTopology(geoHandle);
104 
105 
106  // fetch the Preshower product (RecHits)
107  evt.getByLabel( preshHitProducer_, pRecHits);
108  // pointer to the object in the product
109  const EcalRecHitCollection* rechits = pRecHits.product();
110 
111  if ( debugL_pi0 == EndcapPiZeroDiscriminatorAlgo::pDEBUG )
112  cout << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: "
113  << rechits->size() << endl;
114 
115  // if ( rechits->size() <= 0 ) return;
116 
117  // make the map of Preshower rechits:
118  map<DetId, EcalRecHit> rechits_map;
120  for (it = rechits->begin(); it != rechits->end(); it++) {
121  rechits_map.insert(make_pair(it->id(), *it));
122  }
123  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout
124  << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size "
125  << rechits_map.size() <<" was created!" << endl;
126 
127  reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
128 
129  //make cycle over Photon Collection
130  int SC_index = 0;
131 // Handle<PhotonCollection> correctedPhotonHandle;
132 // evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
133 // const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
134 // cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
135 
136  evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
137  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
138  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout <<"### Total # Endcap Superclusters: " << SClusts->size() << endl;
139  SuperClusterCollection::const_iterator it_s;
140  for ( it_s=SClusts->begin(); it_s!=SClusts->end(); it_s++ ) {
141 
142  SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters,SC_index));
143 
144  float SC_Et = it_super->energy()*sin(2*atan(exp(-it_super->eta())));
145  float SC_eta = it_super->eta();
146  float SC_phi = it_super->phi();
147 
148  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) {
149  cout << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy()
150  << " superCl_Et = " << SC_Et
151  << " superCl_Eta = " << SC_eta
152  << " superCl_Phi = " << SC_phi << endl;
153  }
154 
155  if(fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5)
156  { // Use Preshower region only
157  if (geometry)
158  {
159  const GlobalPoint pointSC(it_super->x(),it_super->y(),it_super->z()); // get the centroid of the SC
160  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout << "SC centroind = " << pointSC << endl;
161 
162  // Get the Preshower 2-planes RecHit vectors associated with the given SC
163 
164  DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
165  DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
166  ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
167  ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
168 
169  vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p);
170  vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p);
171 
172  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) {
173  cout << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = " ;
174  for(int k1=0;k1<11;k1++) {
175  cout << vout_stripE1[k1] << " " ;
176  }
177  for(int k1=0;k1<11;k1++) {
178  cout << vout_stripE2[k1] << " " ;
179  }
180  cout << endl;
181  }
182 
184  ps1.setSCRef(it_super);
185  ps_cl_x.push_back(ps1);
186 
188  ps2.setSCRef(it_super);
189  ps_cl_y.push_back(ps2);
190 
191  }
192  SC_index++;
193  } // end of cycle over Endcap SC
194  }
195  // put collection of PreshowerClusterShape in the Event:
196  ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
197  ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
198 
199  evt.put(ps_cl_for_pi0_disc_x, PreshowerClusterShapeCollectionX_);
200  evt.put(ps_cl_for_pi0_disc_y, PreshowerClusterShapeCollectionY_);
201 
202  if ( debugL_pi0 <= EndcapPiZeroDiscriminatorAlgo::pDEBUG ) cout << "PreshowerClusterShapeCollection added to the event" << endl;
203 
204  if (topology_p)
205  delete topology_p;
206 
207  nEvt_++;
208 
209  LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
210 }
#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< T >::const_iterator const_iterator
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
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)
tuple cout
Definition: gather_cfg.py:41
PreshowerClusterShapeProducer(const edm::ParameterSet &ps)
const_iterator begin() const