CMS 3D CMS Logo

AlCaECALRecHitReducer.cc
Go to the documentation of this file.
2 //#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
5 
10 
11 //#define ALLrecHits
12 //#define DEBUG
13 
14 //#define QUICK -> if commented loop over the recHits of the SC and add them to the list of recHits to be saved
15 // comment it if you want a faster module but be sure the window is large enough
16 
21 
24 {
25 
26  ebRecHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter< edm::InputTag > ("ebRecHitsLabel"));
27  eeRecHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter< edm::InputTag > ("eeRecHitsLabel"));
28  // esRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("esRecHitsLabel");
29 
30  std::vector<edm::InputTag> srcLabels = iConfig.getParameter< std::vector<edm::InputTag> >("srcLabels");
31  for ( auto inputTag = srcLabels.begin(); inputTag != srcLabels.end(); ++inputTag){
33  }
34 
35  //eleViewToken_ = consumes<edm::View <reco::RecoCandidate> > (iConfig.getParameter< edm::InputTag > ("electronLabel"));
36  photonToken_ = consumes<reco::PhotonCollection>(iConfig.getParameter< edm::InputTag > ("photonLabel"));
37  EESuperClusterToken_ = consumes<reco::SuperClusterCollection>(iConfig.getParameter< edm::InputTag>("EESuperClusterCollection"));
38 
39  minEta_highEtaSC_ = iConfig.getParameter< double >("minEta_highEtaSC");
40 
41  alcaBarrelHitsCollection_ = iConfig.getParameter<std::string>("alcaBarrelHitCollection");
42  alcaEndcapHitsCollection_ = iConfig.getParameter<std::string>("alcaEndcapHitCollection");
43  alcaCaloClusterCollection_ = iConfig.getParameter<std::string>("alcaCaloClusterCollection");
44 
45  // alcaPreshowerHitsCollection_ = iConfig.getParameter<std::string>("alcaPreshowerHitCollection");
46 
47  etaSize_ = iConfig.getParameter<int> ("etaSize");
48  phiSize_ = iConfig.getParameter<int> ("phiSize");
49  // FIXME: minimum size of etaSize_ and phiSize_
50  if ( phiSize_ % 2 == 0 || etaSize_ % 2 == 0)
51  edm::LogError("AlCaECALRecHitReducerError") << "Size of eta/phi should be odd numbers";
52 
53  // esNstrips_ = iConfig.getParameter<int> ("esNstrips");
54  // esNcolumns_ = iConfig.getParameter<int> ("esNcolumns");
55 
56  //register your products
57  produces< EBRecHitCollection > (alcaBarrelHitsCollection_) ;
58  produces< EERecHitCollection > (alcaEndcapHitsCollection_) ;
59  produces< reco::CaloClusterCollection > (alcaCaloClusterCollection_) ;
60  // produces< ESRecHitCollection > (alcaPreshowerHitsCollection_) ;
61 }
62 
63 
65 {}
66 
67 
68 // ------------ method called to produce the data ------------
69 void
71  const edm::EventSetup& iSetup)
72 {
73  using namespace edm;
74  //using namespace std;
75 
77 
78  edm::ESHandle<CaloTopology> theCaloTopology;
79  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
80  const CaloTopology *caloTopology = theCaloTopology.product();
81 
82 
83  // Get Photons
85  iEvent.getByToken(photonToken_, phoHandle);
86 
87  // get RecHits
88  Handle<EBRecHitCollection> barrelRecHitsHandle;
89  iEvent.getByToken(ebRecHitsToken_,barrelRecHitsHandle);
90  const EBRecHitCollection *barrelHitsCollection = barrelRecHitsHandle.product () ;
91 
92  // get RecHits
93  Handle<EERecHitCollection> endcapRecHitsHandle;
94  iEvent.getByToken(eeRecHitsToken_,endcapRecHitsHandle);
95  const EERecHitCollection *endcapHitsCollection = endcapRecHitsHandle.product () ;
96 
97  // // get ES RecHits
98  // Handle<ESRecHitCollection> preshowerRecHitsHandle;
99  // iEvent.getByToken(esRecHitsToken_,preshowerRecHitsHandle);
100 
101  // const ESRecHitCollection * preshowerHitsCollection = 0 ;
102  // if (preshowerIsFull)
103  // preshowerHitsCollection = preshowerRecHitsHandle.product () ;
104 
105  // // make a vector to store the used ES rechits:
106  // set<ESDetId> used_strips;
107  // used_strips.clear();
108 
109  // for Z->ele+SC
111  iEvent.getByToken(EESuperClusterToken_, EESCHandle);
112 
113  //Create empty output collections
114  auto miniEBRecHitCollection = std::make_unique<EBRecHitCollection>();
115  auto miniEERecHitCollection = std::make_unique<EERecHitCollection>();
116  // auto miniESRecHitCollection = std::make_unique<ESRecHitCollection>();
117 
118  std::set<DetId> reducedRecHit_EBmap;
119  std::set<DetId> reducedRecHit_EEmap;
120 
121  // std::set< edm::Ref<reco::CaloCluster> > reducedCaloClusters_map;
122 
123  auto reducedCaloClusterCollection = std::make_unique<reco::CaloClusterCollection>();
124 
125  //Photons:
126 #ifdef shervin
127  for (reco::PhotonCollection::const_iterator phoIt=phoHandle->begin(); phoIt!=phoHandle->end(); phoIt++) {
128  const reco::SuperCluster& sc = *(phoIt->superCluster()) ;
129 
130  if (phoIt->isEB()) {
131  AddMiniRecHitCollection(sc, reducedRecHit_EBmap, caloTopology);
132  } else { // endcap
133  AddMiniRecHitCollection(sc, reducedRecHit_EEmap, caloTopology);
134  } // end of endcap
135 
139  for ( ; it !=itend; ++it) {
140  reco::CaloCluster caloClus(**it);
141  reducedCaloClusterCollection->push_back(caloClus);
142  }
143  }
144 #endif
145 
147  for(auto iToken=eleViewTokens_.begin(); iToken!=eleViewTokens_.end(); iToken++){
148  iEvent.getByToken(*iToken, eleViewHandle);
149 
150  //Electrons:
151  for (auto eleIt=eleViewHandle->begin(); eleIt!=eleViewHandle->end(); eleIt++) {
152  const reco::SuperCluster& sc = *(eleIt->superCluster()) ;
153 
154  if (fabs(sc.eta())<1.479) {
155  AddMiniRecHitCollection(sc, reducedRecHit_EBmap, caloTopology);
156  } else { // endcap
157  AddMiniRecHitCollection(sc, reducedRecHit_EEmap, caloTopology);
158  } // end of endcap
159 
162  for ( ; it !=itend; ++it) {
163  reco::CaloCluster caloClus(**it);
164  reducedCaloClusterCollection->push_back(caloClus);
165  }
166  }
167  }
168 
169 
170 
171  //saving recHits for highEta SCs for highEta studies
172  for(reco::SuperClusterCollection::const_iterator SC_iter = EESCHandle->begin();
173  SC_iter!=EESCHandle->end();
174  SC_iter++){
175  if(fabs(SC_iter->eta()) < minEta_highEtaSC_) continue;
176  AddMiniRecHitCollection(*SC_iter, reducedRecHit_EEmap, caloTopology);
177 
178  const reco::SuperCluster& sc = *(SC_iter);
181  for ( ; it !=itend; ++it) {
182  reco::CaloCluster caloClus(**it);
183  reducedCaloClusterCollection->push_back(caloClus);
184  }
185  }
186 
187 
188  //------------------------------ fill the alcareco reduced recHit collection
189  for(std::set<DetId>::const_iterator itr = reducedRecHit_EBmap.begin();
190  itr != reducedRecHit_EBmap.end(); itr++){
191  if (barrelHitsCollection->find(*itr) != barrelHitsCollection->end())
192  miniEBRecHitCollection->push_back(*(barrelHitsCollection->find(*itr)));
193  }
194 
195  for(std::set<DetId>::const_iterator itr = reducedRecHit_EEmap.begin();
196  itr != reducedRecHit_EEmap.end(); itr++){
197  if (endcapHitsCollection->find(*itr) != endcapHitsCollection->end())
198  miniEERecHitCollection->push_back(*(endcapHitsCollection->find(*itr)));
199  }
200 
201 
202  //--------------------------------------- Put selected information in the event
203  iEvent.put(std::move(miniEBRecHitCollection),alcaBarrelHitsCollection_ );
204  iEvent.put(std::move(miniEERecHitCollection),alcaEndcapHitsCollection_ );
205  // iEvent.put(std::move(miniESRecHitCollection),alcaPreshowerHitsCollection_ );
206  iEvent.put(std::move(reducedCaloClusterCollection), alcaCaloClusterCollection_);
207 }
208 
210  std::set<DetId>& reducedRecHitMap,
211  const CaloTopology *caloTopology
212  ){
213  DetId seed=(sc.seed()->seed());
215  if(seed.subdetId()!=EcalBarrel){ // if not EB, take a square window
216  etaSize= std::max(phiSize_,etaSize_);
217  phiSize=etaSize;
218  }
219 
220  std::vector<DetId> recHit_window = caloTopology->getWindow(seed, phiSize, etaSize);
221  for(unsigned int i =0; i < recHit_window.size(); i++){
222  reducedRecHitMap.insert(recHit_window[i]);
223  }
224 
225  const std::vector< std::pair<DetId, float> > & scHits = sc.hitsAndFractions();
226  for(std::vector< std::pair<DetId, float> >::const_iterator scHit_itr = scHits.begin();
227  scHit_itr != scHits.end(); scHit_itr++){
228  // the map fills just one time (avoiding double insert of recHits)
229  reducedRecHitMap.insert(scHit_itr->first);
230  }
231 
232 
233  return;
234 }
235 
236 
238 
239 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< EcalRecHit >::const_iterator const_iterator
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:195
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:166
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void AddMiniRecHitCollection(const reco::SuperCluster &sc, std::set< DetId > &reducedRecHitMap, const CaloTopology *caloTopology)
int iEvent
Definition: GenABIO.cc:230
std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
Get the neighbors of the given cell in a window of given size.
Definition: CaloTopology.cc:72
edm::EDGetTokenT< reco::SuperClusterCollection > EESuperClusterToken_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
std::vector< edm::EDGetTokenT< edm::View< reco::RecoCandidate > > > eleViewTokens_
const_iterator end() const
Definition: DetId.h:18
AlCaECALRecHitReducer(const edm::ParameterSet &)
ctor
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:59
std::string alcaCaloClusterCollection_
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
iterator find(key_type k)
HLT enums.
edm::EDGetTokenT< EcalRecHitCollection > eeRecHitsToken_
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
void produce(edm::Event &, const edm::EventSetup &) override
producer
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EcalRecHitCollection > ebRecHitsToken_
def move(src, dest)
Definition: eostools.py:510
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78