CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PreshowerClusterProducer.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
39 #include <fstream>
40 
42 
43 
44 using namespace edm;
45 using namespace std;
46 
47 
49 
50  // use configuration file to setup input/output collection names
51  preshHitProducer_ = ps.getParameter<edm::InputTag>("preshRecHitProducer");
52 
53  // Name of a SuperClusterCollection to make associations:
54  endcapSClusterProducer_ = ps.getParameter<edm::InputTag>("endcapSClusterProducer");
55 
56  // Output collections:
57  preshClusterCollectionX_ = ps.getParameter<std::string>("preshClusterCollectionX");
58  preshClusterCollectionY_ = ps.getParameter<std::string>("preshClusterCollectionY");
59  preshNclust_ = ps.getParameter<int>("preshNclust");
60 
61  etThresh_ = ps.getParameter<double>("etThresh");
62 
63  assocSClusterCollection_ = ps.getParameter<std::string>("assocSClusterCollection");
64 
65  produces< reco::PreshowerClusterCollection >(preshClusterCollectionX_);
66  produces< reco::PreshowerClusterCollection >(preshClusterCollectionY_);
67  produces< reco::SuperClusterCollection >(assocSClusterCollection_);
68 
69  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
70  int preshSeededNst = ps.getParameter<int>("preshSeededNstrip");
71  preshClustECut = ps.getParameter<double>("preshClusterEnergyCut");
72 
73  // The debug level
74  std::string debugString = ps.getParameter<std::string>("debugLevel");
75  if (debugString == "DEBUG") debugL = PreshowerClusterAlgo::pDEBUG;
76  else if (debugString == "INFO") debugL = PreshowerClusterAlgo::pINFO;
77  else debugL = PreshowerClusterAlgo::pERROR;
78 
79  presh_algo = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst,debugL);
80 
81  nEvt_ = 0;
82 
83 }
84 
85 
87  delete presh_algo;
88 }
89 
90 
92 
95 
96  // get the ECAL geometry:
98  es.get<CaloGeometryRecord>().get(geoHandle);
99 
100  // retrieve ES-EE intercalibration constants
101  set(es);
102 
103  const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
104  const CaloSubdetectorGeometry *& geometry_p = geometry;
105 
106  // create auto_ptr to a PreshowerClusterCollection
107  std::auto_ptr< reco::PreshowerClusterCollection > clusters_p1(new reco::PreshowerClusterCollection);
108  std::auto_ptr< reco::PreshowerClusterCollection > clusters_p2(new reco::PreshowerClusterCollection);
109  // create new collection of corrected super clusters
110  std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
111 
112  CaloSubdetectorTopology * topology_p=0;
113  if (geometry)
114  topology_p = new EcalPreshowerTopology(geoHandle);
115 
116  // fetch the product (pSuperClusters)
117  evt.getByLabel(endcapSClusterProducer_, pSuperClusters);
118  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
119  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout <<"### Total # Endcap Superclusters: " << SClusts->size() << std::endl;
120 
121  // fetch the product (RecHits)
122  evt.getByLabel( preshHitProducer_, pRecHits);
123  // pointer to the object in the product
124  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
125  if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: "
126  << rechits->size() << std::endl;
127 
128  // make the map of rechits:
129  std::map<DetId, EcalRecHit> rechits_map;
131  for (it = rechits->begin(); it != rechits->end(); it++) {
132  // remove bad ES rechits
133  if (it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
134  //Make the map of DetID, EcalRecHit pairs
135  rechits_map.insert(std::make_pair(it->id(), *it));
136  }
137  // The set of used DetID's for a given event:
138  std::set<DetId> used_strips;
139  used_strips.clear();
140 
141  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "PreshowerClusterProducerInfo: ### rechits_map of size "
142  << rechits_map.size() <<" was created!" << std::endl;
143 
144  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
145  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
146 
147  if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << " Making a cycle over Superclusters ..." << std::endl;
148  //make cycle over super clusters
149  reco::SuperClusterCollection::const_iterator it_super;
150  int isc = 0;
151  for ( it_super=SClusts->begin(); it_super!=SClusts->end(); it_super++ ) {
152  float e1=0;
153  float e2=0;
154  float deltaE=0;
156  ++isc;
157 
158  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " superE = " << it_super->energy() << " superETA = " << it_super->eta()
159  << " superPHI = " << it_super->phi() << std::endl;
160  if ( debugL == PreshowerClusterAlgo::pINFO ) std::cout << " This SC contains " << it_super->clustersSize() << " BCs" << std::endl;
161 
162  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
163  for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
164  if (geometry)
165  {
166  // Get strip position at intersection point of the line EE - Vertex:
167  double X = (*bc_iter)->x();
168  double Y = (*bc_iter)->y();
169  double Z = (*bc_iter)->z();
170  const GlobalPoint point(X,Y,Z);
171 
172  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
173  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
174  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
175  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
176 
177  if ( debugL <= PreshowerClusterAlgo::pINFO ) {
178  if ( strip1 != ESDetId(0) && strip2 != ESDetId(0) ) {
179  std::cout << " Intersected preshower strips are: " << std::endl;
180  std::cout << strip1 << std::endl;
181  std::cout << strip2 << std::endl;
182  }
183  else if ( strip1 == ESDetId(0) )
184  std::cout << " No intersected strip in plane 1 " << std::endl;
185  else if ( strip2 == ESDetId(0) )
186  std::cout << " No intersected strip in plane 2 " << std::endl;
187  }
188 
189  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
190  for (int i=0; i<preshNclust_; i++) {
191  reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
192  cl1.setBCRef(*bc_iter);
193  if ( cl1.energy() > preshClustECut) {
194  clusters1.push_back(cl1);
195  e1 += cl1.energy();
196  }
197  reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
198  cl2.setBCRef(*bc_iter);
199 
200  if ( cl2.energy() > preshClustECut) {
201  clusters2.push_back(cl2);
202  e2 += cl2.energy();
203  }
204  } // end of cycle over ES clusters
205  }
206  new_BC.push_back(*bc_iter);
207  } // end of cycle over BCs
208 
209  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " For SC #" << isc-1 << ", containing " << it_super->clustersSize()
210  << " basic clusters, PreshowerClusterAlgo made "
211  << clusters1.size() << " in X plane and " << clusters2.size()
212  << " in Y plane " << " preshower clusters " << std::endl;
213 
214  // update energy of the SuperCluster
215  if(e1+e2 > 1.0e-10) {
216  // GeV to #MIPs
217  e1 = e1 / mip_;
218  e2 = e2 / mip_;
219  deltaE = gamma_*(e1+alpha_*e2);
220  }
221 
222  //corrected Energy
223  float E = it_super->energy() + deltaE;
224 
225  if ( debugL == PreshowerClusterAlgo::pDEBUG ) std::cout << " Creating corrected SC " << std::endl;
226  reco::SuperCluster sc( E, it_super->position(), it_super->seed(), new_BC, deltaE);
227 
228  if(sc.energy()*sin(sc.position().theta())>etThresh_)
229  new_SC.push_back(sc);
230  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << " SuperClusters energies: new E = " << sc.energy()
231  << " vs. old E =" << it_super->energy() << std::endl;
232 
233  } // end of cycle over SCs
234 
235 
236 
237  // copy the preshower clusters into collections and put in the Event:
238  clusters_p1->assign(clusters1.begin(), clusters1.end());
239  clusters_p2->assign(clusters2.begin(), clusters2.end());
240  // put collection of preshower clusters to the event
241  evt.put( clusters_p1, preshClusterCollectionX_ );
242  evt.put( clusters_p2, preshClusterCollectionY_ );
243  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "Preshower clusters added to the event" << std::endl;
244 
245  // put collection of corrected super clusters to the event
246  superclusters_p->assign(new_SC.begin(), new_SC.end());
247  evt.put(superclusters_p, assocSClusterCollection_);
248  if ( debugL <= PreshowerClusterAlgo::pINFO ) std::cout << "Corrected SClusters added to the event" << std::endl;
249 
250  if (topology_p)
251  delete topology_p;
252 
253  nEvt_++;
254 
255 }
256 
258 
259  es.get<ESGainRcd>().get(esgain_);
260  const ESGain *gain = esgain_.product();
261 
262  es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
263  const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
264 
265  es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
266  const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
267 
268  double ESGain = gain->getESGain();
269  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
270  gamma_ = (ESGain == 1) ? esEEInterCalib->getGammaLow0() : esEEInterCalib->getGammaHigh0();
271  alpha_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
272 }
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
Definition: ESGain.h:5
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:135
float getESValueLow() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< T >::const_iterator const_iterator
#define X(str)
Definition: MuonsGrabber.cc:49
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void setBCRef(const CaloClusterPtr &r)
DetIds of component RecHits – now inherited from CaloCluster.
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
double energy() const
cluster energy
Definition: CaloCluster.h:109
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
const_iterator end() const
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
Definition: DetId.h:20
float getESGain() const
Definition: ESGain.h:11
const T & get() const
Definition: EventSetup.h:55
PreshowerClusterProducer(const edm::ParameterSet &ps)
void set(const edm::EventSetup &es)
T const * product() const
Definition: Handle.h:74
ESHandle< TrackerGeometry > geometry
size_type size() const
tuple cout
Definition: gather_cfg.py:41
float getESValueHigh() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
const_iterator begin() const