CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronRecalibSuperClusterAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 
5 // user include files
6 
11 
16 
17 #include <iostream>
18 
19 //#define DEBUG 1
20 
21 using namespace reco;
22 using namespace edm;
23 
25 {
26 #ifdef DEBUG
27  std::cout<< "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator" << std::endl;
28 #endif
29 
30  //register your products
31  produces<GsfElectronCollection>();
32  produces<GsfElectronCoreCollection>() ;
33  produces<SuperClusterCollection>();
34 
35  scProducer_ = iConfig.getParameter<std::string>("scProducer");
36  scCollection_ = iConfig.getParameter<std::string>("scCollection");
37 
38  scIslandProducer_ = iConfig.getParameter<std::string>("scIslandProducer");
39  scIslandCollection_ = iConfig.getParameter<std::string>("scIslandCollection");
40 
41  electronProducer_ = iConfig.getParameter<std::string > ("electronProducer");
42  electronCollection_ = iConfig.getParameter<std::string > ("electronCollection");
43 #ifdef DEBUG
44  std::cout<< "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator::end" << std::endl;
45 #endif
46 }
47 
49 {
50 }
51 
52 // ------------ method called to produce the data ------------
54 {
55 #ifdef DEBUG
56  std::cout<< "ElectronRecalibSuperClusterAssociator::produce" << std::endl;
57 #endif
58  // Create the output collections
59  std::auto_ptr<GsfElectronCollection> pOutEle(new GsfElectronCollection);
60  std::auto_ptr<GsfElectronCoreCollection> pOutEleCore(new GsfElectronCoreCollection);
61  std::auto_ptr<SuperClusterCollection> pOutNewEndcapSC(new SuperClusterCollection);
62 
65 
66  //Get Hybrid SuperClusters
68  e.getByLabel(scProducer_, scCollection_, pSuperClusters);
69  if (!pSuperClusters.isValid()) {
70  std::cerr << "Error! can't get the product SuperClusterCollection "<< std::endl;
71  }
72  const reco::SuperClusterCollection* scCollection = pSuperClusters.product();
73 
74 #ifdef DEBUG
75  std::cout<<"scCollection->size()"<<scCollection->size()<<std::endl;
76 #endif
77 
78  //Get Island SuperClusters
79  Handle<reco::SuperClusterCollection> pIslandSuperClusters;
80  e.getByLabel(scIslandProducer_, scIslandCollection_, pIslandSuperClusters);
81  if (!pIslandSuperClusters.isValid()) {
82  std::cerr << "Error! can't get the product IslandSuperClusterCollection "<< std::endl;
83  }
84  const reco::SuperClusterCollection* scIslandCollection = pIslandSuperClusters.product();
85 
86 #ifdef DEBUG
87  std::cout<<"scEECollection->size()"<<scIslandCollection->size()<<std::endl;
88 #endif
89 
90  // Get Electrons
92  e.getByLabel(electronProducer_, electronCollection_, pElectrons);
93  if (!pElectrons.isValid()) {
94  std::cerr << "Error! can't get the product ElectronCollection "<< std::endl;
95  }
96  const reco::GsfElectronCollection* electronCollection = pElectrons.product();
97 
98  for(reco::GsfElectronCollection::const_iterator eleIt = electronCollection->begin(); eleIt != electronCollection->end(); eleIt++)
99  {
100  float DeltaRMineleSCbarrel(0.15);
101  float DeltaRMineleSCendcap(0.15);
102  const reco::SuperCluster* nearestSCbarrel=0;
103  const reco::SuperCluster* nearestSCendcap=0;
104  int iscRef=-1;
105  int iSC=0;
106 
107  // first loop is on EB superClusters
108  for(reco::SuperClusterCollection::const_iterator scIt = scCollection->begin();
109  scIt != scCollection->end(); scIt++){
110 #ifdef DEBUG
111  std::cout << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << " " << eleIt->eta() << " " << eleIt->phi() << std::endl;
112 #endif
113 
114  double DeltaReleSC = sqrt ( pow( eleIt->eta() - scIt->eta(),2) + pow(eleIt->phi() - scIt->phi(),2));
115 
116  if(DeltaReleSC<DeltaRMineleSCbarrel)
117  {
118  DeltaRMineleSCbarrel = DeltaReleSC;
119  nearestSCbarrel = &*scIt;
120  iscRef = iSC;
121  }
122  iSC++;
123  }
124  iSC = 0;
125 
126  // second loop is on EE superClusters
127 
128  for(reco::SuperClusterCollection::const_iterator scItEndcap = scIslandCollection->begin();
129  scItEndcap != scIslandCollection->end(); scItEndcap++){
130 #ifdef DEBUG
131  std::cout << "EE " << scItEndcap->energy() << " " << scItEndcap->eta() << " " << scItEndcap->phi() << " " << eleIt->eta() << " " << eleIt->phi() << std::endl;
132 #endif
133 
134  double DeltaReleSC = sqrt ( pow( eleIt->eta() - scItEndcap->eta(),2) + pow(eleIt->phi() - scItEndcap->phi(),2));
135 
136  if(DeltaReleSC<DeltaRMineleSCendcap)
137  {
138  DeltaRMineleSCendcap = DeltaReleSC;
139  nearestSCendcap = &*scItEndcap;
140  }
141  iSC++;
142  }
144 
147 
148  if(nearestSCbarrel && !nearestSCendcap){
149  reco::GsfElectronCore newEleCore(*(eleIt->core()));
150  newEleCore.setGsfTrack(eleIt->gsfTrack());
151  reco::SuperClusterRef scRef(reco::SuperClusterRef(pSuperClusters, iscRef));
152  newEleCore.setSuperCluster(scRef);
153  reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
154  pOutEleCore->push_back(newEleCore);
155  reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
156 // TrackRef(),GsfTrackRefVector());
158  newEle.setP4(eleIt->p4()*(nearestSCbarrel->energy()/eleIt->ecalEnergy()));
159 
160  pOutEle->push_back(newEle);
161 #ifdef DEBUG
162  std::cout << "Association is with EB superCluster "<< std::endl;
163 #endif
164  }
165 
166  if(!nearestSCbarrel && nearestSCendcap)
167  {
168 #ifdef DEBUG
169  std::cout << "Starting Association is with EE superCluster "<< std::endl;
170 #endif
171 
172  float preshowerEnergy=eleIt->superCluster()->preshowerEnergy();
173 #ifdef DEBUG
174  std::cout << "preshowerEnergy"<< preshowerEnergy << std::endl;
175 #endif
176  CaloClusterPtrVector newBCRef;
178  for (CaloCluster_iterator bcRefIt=nearestSCendcap->clustersBegin();bcRefIt!=nearestSCendcap->clustersEnd();++bcRefIt){
179  CaloClusterPtr cPtr(*bcRefIt);
180  newBCRef.push_back(cPtr);
181  }
182 
183 
184  reco::SuperCluster newSC(nearestSCendcap->energy() + preshowerEnergy, nearestSCendcap->position() , nearestSCendcap->seed(),newBCRef , preshowerEnergy );
185  pOutNewEndcapSC->push_back(newSC);
186  reco::SuperClusterRef scRef(reco::SuperClusterRef(rSC, idxSC ++));
187 
188  reco::GsfElectronCore newEleCore(*(eleIt->core()));
189  newEleCore.setGsfTrack(eleIt->gsfTrack());
190  newEleCore.setSuperCluster(scRef);
191  reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
192  pOutEleCore->push_back(newEleCore);
193  reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
194 // TrackRef(),GsfTrackRefVector());
196 
197  newEle.setP4(eleIt->p4()*(newSC.energy()/eleIt->ecalEnergy())) ;
198  pOutEle->push_back(newEle);
199 
200 #ifdef DEBUG
201  std::cout << "Association is with EE superCluster "<< std::endl;
202 #endif
203  }
204 
205  if(nearestSCbarrel && nearestSCendcap){
206  reco::GsfElectronCore newEleCore(*(eleIt->core()));
207  newEleCore.setGsfTrack(eleIt->gsfTrack());
208 
209 
210  if(DeltaRMineleSCendcap>=DeltaRMineleSCbarrel)
211  {
212  reco::SuperClusterRef scRef(reco::SuperClusterRef(pSuperClusters, iscRef));
213  newEleCore.setSuperCluster(scRef);
214  reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
215  pOutEleCore->push_back(newEleCore);
216  reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
217 // TrackRef(),GsfTrackRefVector());
219  newEle.setP4(eleIt->p4()*(nearestSCbarrel->energy()/eleIt->ecalEnergy()));
220  pOutEle->push_back(newEle);
221 
222 
223 #ifdef DEBUG
224  std::cout << "Association is with EB superCluster, after quarrel "<< std::endl;
225 #endif
226  }
227  else if(DeltaRMineleSCendcap<DeltaRMineleSCbarrel)
228  {
229  float preshowerEnergy=eleIt->superCluster()->preshowerEnergy();
230  CaloClusterPtrVector newBCRef;
231  for (CaloCluster_iterator bcRefIt=nearestSCendcap->clustersBegin();bcRefIt!=nearestSCendcap->clustersEnd();++bcRefIt){
232  CaloClusterPtr cPtr(*bcRefIt);
233  newBCRef.push_back(*bcRefIt);}
234  reco::SuperCluster newSC(nearestSCendcap->energy() + preshowerEnergy, nearestSCendcap->position() , nearestSCendcap->seed(), newBCRef , preshowerEnergy );
235  pOutNewEndcapSC->push_back(newSC);
236  reco::SuperClusterRef scRef(reco::SuperClusterRef(rSC, idxSC ++));
237  newEleCore.setSuperCluster(scRef);
238  reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
239  pOutEleCore->push_back(newEleCore);
240  reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
241 // TrackRef(),GsfTrackRefVector());
243  newEle.setP4(eleIt->p4()*(newSC.energy()/eleIt->ecalEnergy())) ;
244  pOutEle->push_back(newEle);
245 #ifdef DEBUG
246  std::cout << "Association is with EE superCluster, after quarrel "<< std::endl;
247 #endif
248  }
249 
250  }
251 
252 
253  }
254 
255 
256 
257 #ifdef DEBUG
258  std::cout << "Filled new electrons " << pOutEle->size() << std::endl;
259  std::cout << "Filled new electronsCore " << pOutEleCore->size() << std::endl;
260  std::cout << "Filled new endcapSC " << pOutNewEndcapSC->size() << std::endl;
261 #endif
262 
263  // put result into the Event
264 
265  e.put(pOutEle);
266  e.put(pOutEleCore);
267  e.put(pOutNewEndcapSC);
268 
269 }
270 
271 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:178
void setGsfTrack(const GsfTrackRef &gsfTrack)
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:137
edm::Ptr< CaloCluster > CaloClusterPtr
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
ElectronRecalibSuperClusterAssociator(const edm::ParameterSet &conf)
void setSuperCluster(const SuperClusterRef &scl)
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.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:85
T sqrt(T t)
Definition: SSEVec.h:46
virtual void produce(edm::Event &e, const edm::EventSetup &c)
std::vector< GsfElectronCore > GsfElectronCoreCollection
edm::RefVector< GsfTrackCollection > GsfTrackRefVector
vector of reference to GsfTrack in the same collection
Definition: GsfTrackFwd.h:17
double energy() const
cluster energy
Definition: CaloCluster.h:120
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
RefProd< PROD > getRefBeforePut()
Definition: Event.h:97
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
T const * product() const
Definition: Handle.h:74
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:65
tuple cout
Definition: gather_cfg.py:121
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:62
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:68