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 
76  edm::ESHandle<CaloTopology> theCaloTopology;
77  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
78  const CaloTopology *caloTopology = theCaloTopology.product();
79 
80 
81  // Get Photons
83  iEvent.getByToken(photonToken_, phoHandle);
84 
85  // get RecHits
86  Handle<EBRecHitCollection> barrelRecHitsHandle;
87  iEvent.getByToken(ebRecHitsToken_,barrelRecHitsHandle);
88  const EBRecHitCollection *barrelHitsCollection = barrelRecHitsHandle.product () ;
89 
90  // get RecHits
91  Handle<EERecHitCollection> endcapRecHitsHandle;
92  iEvent.getByToken(eeRecHitsToken_,endcapRecHitsHandle);
93  const EERecHitCollection *endcapHitsCollection = endcapRecHitsHandle.product () ;
94 
95  // // get ES RecHits
96  // Handle<ESRecHitCollection> preshowerRecHitsHandle;
97  // iEvent.getByToken(esRecHitsToken_,preshowerRecHitsHandle);
98 
99  // const ESRecHitCollection * preshowerHitsCollection = 0 ;
100  // if (preshowerIsFull)
101  // preshowerHitsCollection = preshowerRecHitsHandle.product () ;
102 
103  // // make a vector to store the used ES rechits:
104  // set<ESDetId> used_strips;
105  // used_strips.clear();
106 
107  // for Z->ele+SC
109  iEvent.getByToken(EESuperClusterToken_, EESCHandle);
110 
111  //Create empty output collections
112  auto miniEBRecHitCollection = std::make_unique<EBRecHitCollection>();
113  auto miniEERecHitCollection = std::make_unique<EERecHitCollection>();
114  // auto miniESRecHitCollection = std::make_unique<ESRecHitCollection>();
115 
116  std::set<DetId> reducedRecHit_EBmap;
117  std::set<DetId> reducedRecHit_EEmap;
118 
119  // std::set< edm::Ref<reco::CaloCluster> > reducedCaloClusters_map;
120 
121  auto reducedCaloClusterCollection = std::make_unique<reco::CaloClusterCollection>();
122 
123  //Photons:
124 #ifdef shervin
125  for (reco::PhotonCollection::const_iterator phoIt=phoHandle->begin(); phoIt!=phoHandle->end(); phoIt++) {
126  const reco::SuperCluster& sc = *(phoIt->superCluster()) ;
127 
128  if (phoIt->isEB()) {
129  AddMiniRecHitCollection(sc, reducedRecHit_EBmap, caloTopology);
130  } else { // endcap
131  AddMiniRecHitCollection(sc, reducedRecHit_EEmap, caloTopology);
132  } // end of endcap
133 
137  for ( ; it !=itend; ++it) {
138  reco::CaloCluster caloClus(**it);
139  reducedCaloClusterCollection->push_back(caloClus);
140  }
141  }
142 #endif
143 
145  for(auto iToken=eleViewTokens_.begin(); iToken!=eleViewTokens_.end(); iToken++){
146  iEvent.getByToken(*iToken, eleViewHandle);
147 
148  //Electrons:
149  for (auto eleIt=eleViewHandle->begin(); eleIt!=eleViewHandle->end(); eleIt++) {
150  const reco::SuperCluster& sc = *(eleIt->superCluster()) ;
151 
152  if (fabs(sc.eta())<1.479) {
153  AddMiniRecHitCollection(sc, reducedRecHit_EBmap, caloTopology);
154  } else { // endcap
155  AddMiniRecHitCollection(sc, reducedRecHit_EEmap, caloTopology);
156  } // end of endcap
157 
160  for ( ; it !=itend; ++it) {
161  reco::CaloCluster caloClus(**it);
162  reducedCaloClusterCollection->push_back(caloClus);
163  }
164  }
165  }
166 
167 
168 
169  //saving recHits for highEta SCs for highEta studies
170  for(reco::SuperClusterCollection::const_iterator SC_iter = EESCHandle->begin();
171  SC_iter!=EESCHandle->end();
172  SC_iter++){
173  if(fabs(SC_iter->eta()) < minEta_highEtaSC_) continue;
174  AddMiniRecHitCollection(*SC_iter, reducedRecHit_EEmap, caloTopology);
175 
176  const reco::SuperCluster& sc = *(SC_iter);
179  for ( ; it !=itend; ++it) {
180  reco::CaloCluster caloClus(**it);
181  reducedCaloClusterCollection->push_back(caloClus);
182  }
183  }
184 
185 
186  //------------------------------ fill the alcareco reduced recHit collection
187  for(std::set<DetId>::const_iterator itr = reducedRecHit_EBmap.begin();
188  itr != reducedRecHit_EBmap.end(); itr++){
189  if (barrelHitsCollection->find(*itr) != barrelHitsCollection->end())
190  miniEBRecHitCollection->push_back(*(barrelHitsCollection->find(*itr)));
191  }
192 
193  for(std::set<DetId>::const_iterator itr = reducedRecHit_EEmap.begin();
194  itr != reducedRecHit_EEmap.end(); itr++){
195  if (endcapHitsCollection->find(*itr) != endcapHitsCollection->end())
196  miniEERecHitCollection->push_back(*(endcapHitsCollection->find(*itr)));
197  }
198 
199 
200  //--------------------------------------- Put selected information in the event
201  iEvent.put(std::move(miniEBRecHitCollection),alcaBarrelHitsCollection_ );
202  iEvent.put(std::move(miniEERecHitCollection),alcaEndcapHitsCollection_ );
203  // iEvent.put(std::move(miniESRecHitCollection),alcaPreshowerHitsCollection_ );
204  iEvent.put(std::move(reducedCaloClusterCollection), alcaCaloClusterCollection_);
205 }
206 
208  std::set<DetId>& reducedRecHitMap,
209  const CaloTopology *caloTopology
210  ){
211  DetId seed=(sc.seed()->seed());
213  if(seed.subdetId()!=EcalBarrel){ // if not EB, take a square window
214  etaSize= std::max(phiSize_,etaSize_);
215  phiSize=etaSize;
216  }
217 
218  std::vector<DetId> recHit_window = caloTopology->getWindow(seed, phiSize, etaSize);
219  for(unsigned int i =0; i < recHit_window.size(); i++){
220  reducedRecHitMap.insert(recHit_window[i]);
221  }
222 
223  const std::vector< std::pair<DetId, float> > & scHits = sc.hitsAndFractions();
224  for(std::vector< std::pair<DetId, float> >::const_iterator scHit_itr = scHits.begin();
225  scHit_itr != scHits.end(); scHit_itr++){
226  // the map fills just one time (avoiding double insert of recHits)
227  reducedRecHitMap.insert(scHit_itr->first);
228  }
229 
230 
231  return;
232 }
233 
234 
236 
237 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:197
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:168
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:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:67
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
edm::EDGetTokenT< reco::SuperClusterCollection > EESuperClusterToken_
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:74
std::string alcaCaloClusterCollection_
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
iterator find(key_type k)
HLT enums.
T get() const
Definition: EventSetup.h:71
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:511
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78