CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PreshowerPhiClusterProducer.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <memory>
3 
37 #include <fstream>
38 
40 
41 using namespace edm;
42 using namespace std;
43 
45 
46  // use configuration file to setup input/output collection names
47  preshHitToken_ =
48  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
49 
50  // Name of a SuperClusterCollection to make associations:
51  endcapSClusterToken_ =
52  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
53 
54  // Output collections:
55  preshClusterCollectionX_ = ps.getParameter<std::string>("preshClusterCollectionX");
56  preshClusterCollectionY_ = ps.getParameter<std::string>("preshClusterCollectionY");
57 
58  assocSClusterCollection_ = ps.getParameter<std::string>("assocSClusterCollection");
59 
60  produces< reco::PreshowerClusterCollection >(preshClusterCollectionX_);
61  produces< reco::PreshowerClusterCollection >(preshClusterCollectionY_);
62  produces< reco::SuperClusterCollection >(assocSClusterCollection_);
63 
64  float esStripECut = ps.getParameter<double>("esStripEnergyCut");
65  esPhiClusterDeltaEta_ = ps.getParameter<double>("esPhiClusterDeltaEta");
66  esPhiClusterDeltaPhi_ = ps.getParameter<double>("esPhiClusterDeltaPhi");
67 
68  etThresh_ = ps.getParameter<double>("etThresh");
69 
70  presh_algo = new PreshowerPhiClusterAlgo(esStripECut);
71 }
72 
74  delete presh_algo;
75 }
76 
78 
81 
82  // get the ECAL geometry:
84  es.get<CaloGeometryRecord>().get(geoHandle);
85 
86  // retrieve ES-EE intercalibration constants and channel status
87  set(es);
88  const ESChannelStatus *channelStatus = esChannelStatus_.product();
89 
90  const CaloSubdetectorGeometry *geometry = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
91  const CaloSubdetectorGeometry *& geometry_p = geometry;
92 
93  // create auto_ptr to a PreshowerClusterCollection
94  std::auto_ptr< reco::PreshowerClusterCollection > clusters_p1(new reco::PreshowerClusterCollection);
95  std::auto_ptr< reco::PreshowerClusterCollection > clusters_p2(new reco::PreshowerClusterCollection);
96  // create new collection of corrected super clusters
97  std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
98 
99  CaloSubdetectorTopology * topology_p=0;
100  if (geometry)
101  topology_p = new EcalPreshowerTopology(geoHandle);
102 
103  // fetch the product (pSuperClusters)
104  evt.getByToken(endcapSClusterToken_, pSuperClusters);
105  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
106 
107  // fetch the product (RecHits)
108  evt.getByToken( preshHitToken_, pRecHits);
109  // pointer to the object in the product
110  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
111 
112  LogTrace("EcalClusters") << "PreshowerPhiClusterProducerInfo: ### Total # of preshower RecHits: "<< rechits->size();
113 
114  // make the map of rechits:
115  std::map<DetId, EcalRecHit> rechits_map;
117  for (it = rechits->begin(); it != rechits->end(); it++) {
118  // remove bad ES rechits
119  if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
120  //Make the map of DetID, EcalRecHit pairs
121  rechits_map.insert(std::make_pair(it->id(), *it));
122  }
123  // The set of used DetID's for a given event:
124  std::set<DetId> used_strips;
125  used_strips.clear();
126  LogTrace("EcalClusters") << "PreshowerPhiClusterProducerInfo: ### rechits_map of size " << rechits_map.size() <<" was created!";
127 
128  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
129  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
130 
131  //make cycle over super clusters
132  reco::SuperClusterCollection::const_iterator it_super;
133  int isc = 0;
134  for (it_super=SClusts->begin(); it_super!=SClusts->end(); ++it_super) {
135 
136  float e1 = 0;
137  float e2 = 0;
138  float deltaE = 0;
139 
141  ++isc;
142  LogTrace("EcalClusters")<< " superE = " << it_super->energy() << " superETA = " << it_super->eta() << " superPHI = " << it_super->phi() ;
143 
144  //cout<<"=== new SC ==="<<endl;
145  //cout<<"superE = "<<it_super->energy()<<" superETA = "<<it_super->eta()<<" superPHI = "<<it_super->phi()<<endl;
146 
147  int nBC = 0;
148  int condP1 = 1; // 0: dead channel; 1: active channel
149  int condP2 = 1;
150  float maxDeltaPhi = 0;
151  float minDeltaPhi = 0;
152  float refPhi = 0;
153 
154  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
155  for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter) {
156  if (nBC == 0) {
157  refPhi = (*bc_iter)->phi();
158  } else {
159  if (reco::deltaPhi((*bc_iter)->phi(), refPhi) > 0 && reco::deltaPhi((*bc_iter)->phi(), refPhi) > maxDeltaPhi)
160  maxDeltaPhi = reco::deltaPhi((*bc_iter)->phi(), refPhi);
161  if (reco::deltaPhi((*bc_iter)->phi(), refPhi) < 0 && reco::deltaPhi((*bc_iter)->phi(), refPhi) < minDeltaPhi)
162  minDeltaPhi = reco::deltaPhi((*bc_iter)->phi(), refPhi);
163  //cout<<"delta phi : "<<reco::deltaPhi((*bc_iter)->phi(), refPhi)<<endl;
164  }
165  //cout<<"BC : "<<nBC<<" "<<(*bc_iter)->energy()<<" "<<(*bc_iter)->eta()<<" "<<(*bc_iter)->phi()<<endl;
166  nBC++;
167  }
168  maxDeltaPhi += esPhiClusterDeltaPhi_;
169  minDeltaPhi -= esPhiClusterDeltaPhi_;
170 
171  nBC = 0;
172  for (bc_iter = it_super->clustersBegin() ; bc_iter !=it_super->clustersEnd(); ++bc_iter) {
173  if (geometry) {
174 
175  // Get strip position at intersection point of the line EE - Vertex:
176  double X = (*bc_iter)->x();
177  double Y = (*bc_iter)->y();
178  double Z = (*bc_iter)->z();
179  const GlobalPoint point(X,Y,Z);
180 
181  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
182  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
183  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
184  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
185 
186  if (nBC == 0) {
187  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
188  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
189  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
190  if (status_p1->getStatusCode() == 1) condP1 = 0;
191  if (status_p2->getStatusCode() == 1) condP2 = 0;
192  } else if (strip1 == ESDetId(0)) {
193  condP1 = 0;
194  } else if (strip2 == ESDetId(0)) {
195  condP2 = 0;
196  }
197 
198  //cout<<"starting cluster : "<<maxDeltaPhi<<" "<<minDeltaPhi<<" "<<esPhiClusterDeltaEta_<<endl;
199  //cout<<"do plane 1 === "<<strip1.zside()<<" "<<strip1.plane()<<" "<<strip1.six()<<" "<<strip1.siy()<<" "<<strip1.strip()<<endl;
200  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
201  reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p,esPhiClusterDeltaEta_,minDeltaPhi,maxDeltaPhi);
202  cl1.setBCRef(*bc_iter);
203  clusters1.push_back(cl1);
204  e1 += cl1.energy();
205 
206  //cout<<"do plane 2 === "<<strip2.zside()<<" "<<strip2.plane()<<" "<<strip2.six()<<" "<<strip2.siy()<<" "<<strip2.strip()<<endl;
207  reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p,esPhiClusterDeltaEta_,minDeltaPhi,maxDeltaPhi);
208  cl2.setBCRef(*bc_iter);
209  clusters2.push_back(cl2);
210  e2 += cl2.energy();
211  }
212  }
213 
214  new_BC.push_back(*bc_iter);
215  nBC++;
216  } // end of cycle over BCs
217 
218  LogTrace("EcalClusters") << " For SC #" << isc-1 << ", containing "
219  << it_super->clustersSize()
220  << " basic clusters, PreshowerPhiClusterAlgo made "
221  << clusters1.size() << " in X plane and "
222  << clusters2.size()
223  << " in Y plane " << " preshower clusters " ;
224 
225  // update energy of the SuperCluster
226  if(e1+e2 > 1.0e-10) {
227 
228  e1 = e1 / mip_; // GeV to #MIPs
229  e2 = e2 / mip_;
230 
231  if (condP1 == 1 && condP2 == 1) {
232  deltaE = gamma0_*(e1 + alpha0_*e2);
233  } else if (condP1 == 1 && condP2 == 0) {
234  deltaE = gamma1_*(e1 + alpha1_*e2);
235  } else if (condP1 == 0 && condP2 == 1) {
236  deltaE = gamma2_*(e1 + alpha2_*e2);
237  } else if (condP1 == 0 && condP2 == 0) {
238  deltaE = gamma3_*(e1 + alpha3_*e2);
239  }
240  }
241 
242  //corrected Energy
243  float E = it_super->energy() + deltaE;
244 
245  LogTrace("EcalClusters") << " Creating corrected SC ";
246 
247  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
248  sc.setPreshowerEnergyPlane1(e1*mip_);
249  sc.setPreshowerEnergyPlane2(e2*mip_);
250  if (condP1 == 1 && condP2 == 1) sc.setPreshowerPlanesStatus(0);
251  else if (condP1 == 1 && condP2 == 0) sc.setPreshowerPlanesStatus(1);
252  else if (condP1 == 0 && condP2 == 1) sc.setPreshowerPlanesStatus(2);
253  else if (condP1 == 0 && condP2 == 0) sc.setPreshowerPlanesStatus(3);
254 
255  if (etThresh_>0){ // calling postion().theta can be expensive
256  if (sc.energy()*sin(sc.position().theta())>etThresh_ )
257  new_SC.push_back(sc);
258  } else {
259  new_SC.push_back(sc);
260  }
261 
262  } // end of cycle over SCs
263 
264  // copy the preshower clusters into collections and put in the Event:
265  clusters_p1->assign(clusters1.begin(), clusters1.end());
266  clusters_p2->assign(clusters2.begin(), clusters2.end());
267  // put collection of preshower clusters to the event
268  evt.put( clusters_p1, preshClusterCollectionX_ );
269  evt.put( clusters_p2, preshClusterCollectionY_ );
270  LogTrace("EcalClusters") << "Preshower clusters added to the event" ;
271 
272  // put collection of corrected super clusters to the event
273  superclusters_p->assign(new_SC.begin(), new_SC.end());
274  evt.put(superclusters_p, assocSClusterCollection_);
275  LogTrace("EcalClusters") << "Corrected SClusters added to the event" ;
276 
277  if (topology_p) delete topology_p;
278 }
279 
281 
282  es.get<ESGainRcd>().get(esgain_);
283  const ESGain *gain = esgain_.product();
284 
285  double ESGain = gain->getESGain();
286 
287  es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
288  const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
289 
290  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
291 
292  es.get<ESChannelStatusRcd>().get(esChannelStatus_);
293 
294  es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
295  const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
296 
297  // both planes work
298  gamma0_ = (ESGain == 1) ? esEEInterCalib->getGammaLow0() : esEEInterCalib->getGammaHigh0();
299  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
300 
301  // only first plane works
302  gamma1_ = (ESGain == 1) ? esEEInterCalib->getGammaLow1() : esEEInterCalib->getGammaHigh1();
303  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
304 
305  // only second plane works
306  gamma2_ = (ESGain == 1) ? esEEInterCalib->getGammaLow2() : esEEInterCalib->getGammaHigh2();
307  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
308 
309  // both planes do not work
310  gamma3_ = (ESGain == 1) ? esEEInterCalib->getGammaLow3() : esEEInterCalib->getGammaHigh3();
311  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
312 
313  es.get<ESMissingEnergyCalibrationRcd>().get(esMissingECalib_);
314  const ESMissingEnergyCalibration * esMissingECalib = esMissingECalib_.product();
315 
316  // |eta| < 1.9
317  aEta_[0] = esMissingECalib->getConstAEta0();
318  bEta_[0] = esMissingECalib->getConstBEta0();
319 
320  // 1.9 < |eta| < 2.1
321  aEta_[1] = esMissingECalib->getConstAEta1();
322  bEta_[1] = esMissingECalib->getConstBEta1();
323 
324  // 2.1 < |eta| < 2.3
325  aEta_[2] = esMissingECalib->getConstAEta2();
326  bEta_[2] = esMissingECalib->getConstBEta2();
327 
328  // 2.3 < |eta| < 2.5
329  aEta_[3] = esMissingECalib->getConstAEta3();
330  bEta_[3] = esMissingECalib->getConstBEta3();
331 
332 }
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Definition: ESGain.h:7
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:138
const self & getMap() const
float getESValueLow() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalRecHit >::const_iterator const_iterator
#define X(str)
Definition: MuonsGrabber.cc:48
void set(const edm::EventSetup &es)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
void setBCRef(const CaloClusterPtr &r)
DetIds of component RecHits – now inherited from CaloCluster.
const_iterator find(uint32_t rawId) const
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
double energy() const
cluster energy
Definition: CaloCluster.h:120
#define LogTrace(id)
const_iterator end() const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
Definition: DetId.h:18
float getESGain() const
Definition: ESGain.h:13
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:81
std::vector< Item >::const_iterator const_iterator
ESHandle< TrackerGeometry > geometry
size_type size() const
float getESValueHigh() const
void setPreshowerEnergyPlane1(double preshowerEnergy1)
Definition: SuperCluster.h:60
PreshowerPhiClusterProducer(const edm::ParameterSet &ps)
*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