CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaECALRecHitReducer.cc
Go to the documentation of this file.
24 
25 //#define ALLrecHits
26 //#define DEBUG
27 
28 //#define QUICK -> if commented loop over the recHits of the SC and add them to the list of recHits to be saved
29 // comment it if you want a faster module but be sure the window is large enough
30 
32 {
33 
34  ebRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("ebRecHitsLabel");
35  eeRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("eeRecHitsLabel");
36  // esRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("esRecHitsLabel");
37  electronLabel_ = iConfig.getParameter< edm::InputTag > ("electronLabel");
38 
39  alcaBarrelHitsCollection_ = iConfig.getParameter<std::string>("alcaBarrelHitCollection");
40  alcaEndcapHitsCollection_ = iConfig.getParameter<std::string>("alcaEndcapHitCollection");
41  // alcaPreshowerHitsCollection_ = iConfig.getParameter<std::string>("alcaPreshowerHitCollection");
42 
43  etaSize_ = iConfig.getParameter<int> ("etaSize");
44  phiSize_ = iConfig.getParameter<int> ("phiSize");
45  // FIXME: minimum size of etaSize_ and phiSize_
46  if ( phiSize_ % 2 == 0 || etaSize_ % 2 == 0)
47  edm::LogError("AlCaECALRecHitReducerError") << "Size of eta/phi should be odd numbers";
48 
49  weight_= iConfig.getParameter<double> ("eventWeight");
50 
51  // esNstrips_ = iConfig.getParameter<int> ("esNstrips");
52  // esNcolumns_ = iConfig.getParameter<int> ("esNcolumns");
53 
54  //register your products
55  produces< EBRecHitCollection > (alcaBarrelHitsCollection_) ;
56  produces< EERecHitCollection > (alcaEndcapHitsCollection_) ;
57  // produces< ESRecHitCollection > (alcaPreshowerHitsCollection_) ;
58  produces< double > ("weight") ;
59 }
60 
61 
63 {}
64 
65 
66 // ------------ method called to produce the data ------------
67 void
69  const edm::EventSetup& iSetup)
70 {
71  using namespace edm;
72  using namespace std;
73 
75 
76  // get the ECAL geometry:
77  ESHandle<CaloGeometry> geoHandle;
78  iSetup.get<CaloGeometryRecord>().get(geoHandle);
79 
80  edm::ESHandle<CaloTopology> theCaloTopology;
81  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
82  const CaloTopology *caloTopology = theCaloTopology.product();
83 
84  // Get GSFElectrons
86  iEvent.getByLabel(electronLabel_, pElectrons);
87  if (!pElectrons.isValid()) {
88  edm::LogError ("reading") << electronLabel_ << " not found" ;
89  // std::cerr << "[AlCaECALRecHitReducer]" << electronLabel_ << " not found" ;
90  return ;
91  }
92 
93  const reco::GsfElectronCollection * electronCollection =
94  pElectrons.product();
95 
96  // get RecHits
97  Handle<EBRecHitCollection> barrelRecHitsHandle;
98  bool barrelIsFull = true ;
99 
100  iEvent.getByLabel(ebRecHitsLabel_,barrelRecHitsHandle);
101  if (!barrelRecHitsHandle.isValid()) {
102  edm::LogError ("reading") << ebRecHitsLabel_ << " not found" ;
103  barrelIsFull = false ;
104  }
105 
106  const EBRecHitCollection * barrelHitsCollection = 0 ;
107  if (barrelIsFull)
108  barrelHitsCollection = barrelRecHitsHandle.product () ;
109 
110  // get RecHits
111  Handle<EERecHitCollection> endcapRecHitsHandle;
112  bool endcapIsFull = true ;
113 
114  iEvent.getByLabel(eeRecHitsLabel_,endcapRecHitsHandle);
115  if (!endcapRecHitsHandle.isValid()) {
116  edm::LogError ("reading") << eeRecHitsLabel_ << " not found" ;
117  endcapIsFull = false ;
118  }
119 
120  const EERecHitCollection * endcapHitsCollection = 0 ;
121  if (endcapIsFull)
122  endcapHitsCollection = endcapRecHitsHandle.product () ;
123  // const EERecHitCollection * endcapHitsCollection = endcapRecHitsHandle.product();
124 
125  // // get ES RecHits
126  // Handle<ESRecHitCollection> preshowerRecHitsHandle;
127  // bool preshowerIsFull = true ;
128 
129  // iEvent.getByLabel(esRecHitsLabel_,preshowerRecHitsHandle);
130  // if (!preshowerRecHitsHandle.isValid()) {
131  // edm::LogError ("reading") << esRecHitsLabel_ << " not found" ;
132  // preshowerIsFull = false ;
133  // }
134 
135  // const ESRecHitCollection * preshowerHitsCollection = 0 ;
136  // if (preshowerIsFull)
137  // preshowerHitsCollection = preshowerRecHitsHandle.product () ;
138 
139  // // make a vector to store the used ES rechits:
140  // set<ESDetId> used_strips;
141  // used_strips.clear();
142 
143  //Create empty output collections
144  std::auto_ptr< EBRecHitCollection > miniEBRecHitCollection (new EBRecHitCollection) ;
145  std::auto_ptr< EERecHitCollection > miniEERecHitCollection (new EERecHitCollection) ;
146  // std::auto_ptr< ESRecHitCollection > miniESRecHitCollection (new ESRecHitCollection) ;
147  std::auto_ptr< double > weight (new double(1));
148  (*weight) = weight_;
149 
150  // loop on SiStrip Electrons
151 
152  reco::GsfElectronCollection::const_iterator eleIt;
153  int nEle_EB=0;
154  int nEle_EE=0;
155 
156  std::set<DetId> reducedRecHit_EBmap;
157  std::set<DetId> reducedRecHit_EEmap;
158 
159  for (eleIt=electronCollection->begin(); eleIt!=electronCollection->end(); eleIt++) {
160  // barrel
161  const reco::SuperCluster& sc = *(eleIt->superCluster()) ;
162 
163  if (eleIt->isEB()) {
164  nEle_EB++;
165 
166  // find the seed
167  EBDetId seed=(sc.seed()->seed());
168 
169  std::vector<DetId> recHit_window = caloTopology->getWindow(seed, phiSize_, etaSize_);
170  for(unsigned int i =0; i < recHit_window.size(); i++){
171 #ifdef DEBUG2
172  std::cout << i << "/" << recHit_window.size() << "\t" << recHit_window[i]() << std::endl;
173 #endif
174  reducedRecHit_EBmap.insert(recHit_window[i]);
175 #ifdef DEBUG2
176  EBDetId ebrechit(recHit_window[i]);
177  std::cout << ebrechit.ieta() << "\t" << ebrechit.iphi() << std::endl;
178 #endif
179  }
180 
181 #ifdef DEBUG
182  // find the most energetic crystal
183  float energy_recHit_max=-999;
184 
185  if(reducedRecHit_EBmap.size() < sc.size())
186  std::cerr << "[WARNING] number of recHit in selected window < RECO SC recHits!" << std::endl;
187 #endif
188 
189 #ifndef QUICK
190  const std::vector< std::pair<DetId, float> > & scHits = sc.hitsAndFractions();
191 
192 #ifdef DEBUG
193  std::vector< std::pair<DetId, float> >::const_iterator scHit_max_itr = scHits.end();
194 #endif
195  for(std::vector< std::pair<DetId, float> >::const_iterator scHit_itr = scHits.begin();
196  scHit_itr != scHits.end(); scHit_itr++){
197  // the map fills just one time (avoiding double insert of recHits)
198  reducedRecHit_EBmap.insert(scHit_itr->first);
199 
200 #ifdef DEBUG2
201  const EcalRecHit ecalRecHit = *(barrelHitsCollection->find( (*scHit_itr).first ));
202  if(energy_recHit_max < ecalRecHit.energy()){
203  scHit_max_itr = scHit_itr;
204  energy_recHit_max=ecalRecHit.energy();
205  }
206 #endif
207  }
208 #endif
209 
210 #ifdef DEBUG2
211  // cross check, the seed should be the highest energetic crystal in the SC
212  if(EBDetId(scHit_max_itr->first) != seed)
213  std::cerr << "[ERROR] highest energetic crystal is not the seed of the SC" << std::endl;
214 
215  else{
216 
217  std::cout << "[DEBUG] highest energetic crystal = " << EBDetId(scHit_max_itr->first) << std::endl;
218  std::cout << "[DEBUG] seed of the SC = " << seed << std::endl;
219  }
220 #endif
221  // (id, phi, eta)
222 
223  if(reducedRecHit_EBmap.size() < sc.size()){
224  if(eleIt->ecalDrivenSeed())
225  edm::LogError("AlCaSavedRecHitsEB") << "[ERROR] ecalDrivenSeed: number of saved recHits < RECO SC recHits!: " << reducedRecHit_EBmap.size() << " < " << sc.size() << std::endl;
226  else
227  edm::LogWarning("AlCaSavedRecHitsEB") << "[WARNING] trackerDrivenSeed: number of saved recHits < RECO SC recHits!: " << reducedRecHit_EBmap.size() << " < " << sc.size() << std::endl;
228 
229  }
230 
231  } else { // endcap
232  nEle_EE++;
233 
234  // find the seed
235  EEDetId seed=(sc.seed()->seed());
236 
237  // get detId for a window around the seed of the SC
238  int sideSize = std::max(phiSize_,etaSize_);
239  std::vector<DetId> recHit_window = caloTopology->getWindow(seed, sideSize, sideSize);
240 
241  // fill the recHit map with the DetId of the window
242  for(std::vector<DetId>::const_iterator window_itr = recHit_window.begin();
243  window_itr != recHit_window.end(); window_itr++){
244  reducedRecHit_EEmap.insert(*window_itr);
245  }
246 #ifdef DEBUG
247  if(reducedRecHit_EEmap.size() < sc.size())
248  std::cerr << "[WARNING] number of recHit in selected window < RECO SC recHits!" << std::endl;
249 #endif
250 
251  const std::vector< std::pair<DetId, float> > & scHits = sc.hitsAndFractions();
252 
253 #ifndef QUICK
254  // fill the recHit map with the DetId of the SC recHits
255 
256  for(std::vector< std::pair<DetId, float> >::const_iterator scHit_itr = scHits.begin();
257  scHit_itr != scHits.end(); scHit_itr++){
258  // the map fills just one time (avoiding double insert of recHits)
259  reducedRecHit_EEmap.insert(scHit_itr->first);
260 
261  }
262 #endif
263 
264  if(reducedRecHit_EEmap.size() < sc.size()){
265  if(eleIt->ecalDrivenSeed())
266  edm::LogError("AlCaSavedRecHitsEE") << "[ERROR] ecalDrivenSeed: number of saved recHits < RECO SC recHits!: " << reducedRecHit_EEmap.size() << " < " << sc.size() << std::endl;
267  else
268  edm::LogWarning("AlCaSavedRecHitsEE") << "[WARNING] trackerDrivenSeed: number of saved recHits < RECO SC recHits!: " << reducedRecHit_EEmap.size() << " < " << sc.size() << std::endl;
269 
270  }
271 
272  } // end of endcap
273  }
274 
275 #ifndef ALLrecHits
276  for(std::set<DetId>::const_iterator itr = reducedRecHit_EBmap.begin();
277  itr != reducedRecHit_EBmap.end(); itr++){
278  if (barrelHitsCollection->find(*itr) != barrelHitsCollection->end())
279  miniEBRecHitCollection->push_back(*(barrelHitsCollection->find(*itr)));
280  }
281 #else
282  for(EcalRecHitCollection::const_iterator recHits_itr = barrelHitsCollection->begin();
283  recHits_itr != barrelHitsCollection->end();
284  recHits_itr++){
285  miniEBRecHitCollection->push_back(*recHits_itr);
286  }
287 #endif
288 
289  // fill the alcareco reduced recHit collection
290  for(std::set<DetId>::const_iterator itr = reducedRecHit_EEmap.begin();
291  itr != reducedRecHit_EEmap.end(); itr++){
292  if (endcapHitsCollection->find(*itr) != endcapHitsCollection->end())
293  miniEERecHitCollection->push_back(*(endcapHitsCollection->find(*itr)));
294  }
295 
296 
297 
298 #ifdef DEBUG
299  std::cout << "nEle_EB= " << nEle_EB << "\tnEle_EE = " << nEle_EE << std::endl;
300  if(nEle_EB > 0 && miniEBRecHitCollection->size() < (unsigned int) phiSize_*etaSize_)
301  edm::LogError("AlCaECALRecHitReducerError") << "Size EBRecHitCollection < " << phiSize_*etaSize_ << ": " << miniEBRecHitCollection->size() ;
302 
303  int side = phiSize_ ;
304  if (phiSize_ < etaSize_) side = etaSize_ ;
305 
306  if(nEle_EE > 0 && miniEERecHitCollection->size() < (unsigned int )side*side)
307  edm::LogError("AlCaECALRecHitReducerError") << "Size EERecHitCollection < " << side*side << ": " << miniEERecHitCollection->size() ;
308 #endif
309 
310  //Put selected information in the event
311  iEvent.put( miniEBRecHitCollection,alcaBarrelHitsCollection_ );
312  iEvent.put( miniEERecHitCollection,alcaEndcapHitsCollection_ );
313  // iEvent.put( miniESRecHitCollection,alcaPreshowerHitsCollection_ );
314  iEvent.put( weight, "weight");
315 }
316 
317 
319 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &)
producer
#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:190
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
return((rh^lh)&mask)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
float energy() const
Definition: EcalRecHit.h:68
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
AlCaECALRecHitReducer(const edm::ParameterSet &)
ctor
const T & get() const
Definition: EventSetup.h:55
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:167
tuple cout
Definition: gather_cfg.py:121
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50