CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecHitProducerHCAL.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
6 
11 
15 
19 
20 
26 
29 
31 
34 
36 
37 
38 using namespace std;
39 using namespace edm;
40 
42  : PFRecHitProducer( iConfig )
43 {
44 
45 
46 
47  // access to the collections of rechits
48 
49 
51  iConfig.getParameter<InputTag>("hcalRecHitsHBHE");
52 
54  iConfig.getParameter<InputTag>("hcalRecHitsHF");
55 
56 
58  iConfig.getParameter<InputTag>("caloTowers");
59 
60  thresh_HF_ =
61  iConfig.getParameter<double>("thresh_HF");
63  iConfig.getParameter<bool>("navigation_HF");
64  weight_HFem_ =
65  iConfig.getParameter<double>("weight_HFem");
67  iConfig.getParameter<double>("weight_HFhad");
68 
69  HCAL_Calib_ =
70  iConfig.getParameter<bool>("HCAL_Calib");
71  HF_Calib_ =
72  iConfig.getParameter<bool>("HF_Calib");
73  HCAL_Calib_29 =
74  iConfig.getParameter<double>("HCAL_Calib_29");
75  HF_Calib_29 =
76  iConfig.getParameter<double>("HF_Calib_29");
77 
78  shortFibre_Cut = iConfig.getParameter<double>("ShortFibre_Cut");
79  longFibre_Fraction = iConfig.getParameter<double>("LongFibre_Fraction");
80 
81  longFibre_Cut = iConfig.getParameter<double>("LongFibre_Cut");
82  shortFibre_Fraction = iConfig.getParameter<double>("ShortFibre_Fraction");
83 
84  applyLongShortDPG_ = iConfig.getParameter<bool>("ApplyLongShortDPG");
85 
86  longShortFibre_Cut = iConfig.getParameter<double>("LongShortFibre_Cut");
87  minShortTiming_Cut = iConfig.getParameter<double>("MinShortTiming_Cut");
88  maxShortTiming_Cut = iConfig.getParameter<double>("MaxShortTiming_Cut");
89  minLongTiming_Cut = iConfig.getParameter<double>("MinLongTiming_Cut");
90  maxLongTiming_Cut = iConfig.getParameter<double>("MaxLongTiming_Cut");
91 
92  applyTimeDPG_ = iConfig.getParameter<bool>("ApplyTimeDPG");
93  applyPulseDPG_ = iConfig.getParameter<bool>("ApplyPulseDPG");
94 
95  ECAL_Compensate_ = iConfig.getParameter<bool>("ECAL_Compensate");
96  ECAL_Threshold_ = iConfig.getParameter<double>("ECAL_Threshold");
97  ECAL_Compensation_ = iConfig.getParameter<double>("ECAL_Compensation");
98  ECAL_Dead_Code_ = iConfig.getParameter<unsigned int>("ECAL_Dead_Code");
99 
100  EM_Depth_ = iConfig.getParameter<double>("EM_Depth");
101  HAD_Depth_ = iConfig.getParameter<double>("HAD_Depth");
102 
103  //--ab
104  produces<reco::PFRecHitCollection>("HFHAD").setBranchAlias("HFHADRecHits");
105  produces<reco::PFRecHitCollection>("HFEM").setBranchAlias("HFEMRecHits");
106  //--ab
107 }
108 
109 
110 
112 
113 
114 
115 void PFRecHitProducerHCAL::createRecHits(vector<reco::PFRecHit>& rechits,
116  vector<reco::PFRecHit>& rechitsCleaned,
117  edm::Event& iEvent,
118  const edm::EventSetup& iSetup ) {
119 
120 
121  // this map is necessary to find the rechit neighbours efficiently
122  //C but I should think about using Florian's hashed index to do this.
123  //C in which case the map might not be necessary anymore
124  //C however the hashed index does not seem to be implemented for HCAL
125  //
126  // the key of this map is detId.
127  // the value is the index in the rechits vector
128  map<unsigned, unsigned > idSortedRecHits;
129  map<unsigned, unsigned > idSortedRecHitsHFEM;
130  map<unsigned, unsigned > idSortedRecHitsHFHAD;
131  typedef map<unsigned, unsigned >::iterator IDH;
132 
133 
134  edm::ESHandle<CaloGeometry> geoHandle;
135  iSetup.get<CaloGeometryRecord>().get(geoHandle);
136 
137  // get the hcalBarrel geometry
138  const CaloSubdetectorGeometry *hcalBarrelGeometry =
139  geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
140 
141  // get the endcap geometry
142  const CaloSubdetectorGeometry *hcalEndcapGeometry =
143  geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
144 
145  //--ab
146  auto_ptr< vector<reco::PFRecHit> > HFHADRecHits( new vector<reco::PFRecHit> );
147  auto_ptr< vector<reco::PFRecHit> > HFEMRecHits( new vector<reco::PFRecHit> );
148  //--ab
149 
150  // 2 possibilities to make HCAL clustering :
151  // - from the HCAL rechits
152  // - from the CaloTowers.
153  // ultimately, clustering will be done taking CaloTowers as an
154  // input. This possibility is currently under investigation, and
155  // was thus made optional.
156 
157  // in the first step, we will fill the map of PFRecHits hcalrechits
158  // either from CaloTowers or from HCAL rechits.
159 
160  // in the second step, we will perform clustering on this map.
161 
162  if( !(inputTagCaloTowers_ == InputTag()) ) {
163 
165  CaloTowerTopology caloTowerTopology;
166  const CaloSubdetectorGeometry *caloTowerGeometry = 0;
167  // = geometry_->getSubdetectorGeometry(id)
168 
169  // get calotowers
170  bool found = iEvent.getByLabel(inputTagCaloTowers_,
171  caloTowers);
172 
173  if(!found) {
174  ostringstream err;
175  err<<"could not find rechits "<<inputTagCaloTowers_;
176  LogError("PFRecHitProducerHCAL")<<err.str()<<endl;
177 
178  throw cms::Exception( "MissingProduct", err.str());
179  }
180  else {
181  assert( caloTowers.isValid() );
182 
183  // get HF rechits
185  found = iEvent.getByLabel(inputTagHcalRecHitsHF_,
186  hfHandle);
187 
188  if(!found) {
189  ostringstream err;
190  err<<"could not find HF rechits "<<inputTagHcalRecHitsHF_;
191  LogError("PFRecHitProducerHCAL")<<err.str()<<endl;
192 
193  throw cms::Exception( "MissingProduct", err.str());
194  }
195  else {
196  assert( hfHandle.isValid() );
197  }
198 
199  // get HBHE rechits
201  found = iEvent.getByLabel(inputTagHcalRecHitsHBHE_,
202  hbheHandle);
203 
204  if(!found) {
205  ostringstream err;
206  err<<"could not find HBHE rechits "<<inputTagHcalRecHitsHBHE_;
207  LogError("PFRecHitProducerHCAL")<<err.str()<<endl;
208 
209  throw cms::Exception( "MissingProduct", err.str());
210  }
211  else {
212  assert( hbheHandle.isValid() );
213  }
214 
215  // create rechits
217 
218  for(ICT ict=caloTowers->begin(); ict!=caloTowers->end();ict++) {
219 
220  const CaloTower& ct = (*ict);
221 
222  //C
223  if(!caloTowerGeometry)
224  caloTowerGeometry = geoHandle->getSubdetectorGeometry(ct.id());
225 
226 
227  // get the hadronic energy.
228 
229  // Mike: Just ask for the Hadronic part only now!
230  // Patrick : ARGH ! While this is ok for the HCAL, this is
231  // just wrong for the HF (in which em/had are artificially
232  // separated.
233  double energy = ct.hadEnergy();
234  //Auguste: Photons in HF have no hadEnergy in fastsim: -> all RecHit collections are empty with photons.
235  double energyEM = ct.emEnergy(); // For HF !
236  //so test the total energy to deal with the photons in HF:
237  if( (energy+energyEM) < 1e-9 ) continue;
238 
239  assert( ct.constituentsSize() );
240  //Mike: The DetId will be taken by the first Hadronic constituent
241  // of the tower. That is only what we need
242 
243 
244  //get the constituents of the tower
245  const std::vector<DetId>& hits = ct.constituents();
246  const std::vector<DetId>& allConstituents = theTowerConstituentsMap->constituentsOf(ct.id());
247 
248  /*
249  for(unsigned int i=0;i< hits.size();++i) {
250  if(hits[i].det()==DetId::Hcal) {
251  HcalDetId did = hits[i];
252  if ( did.subdet()==HcalEndcap || did.subdet()==HcalForward ) {
253  //double en = hits[i].energy();
254  int ieta = did.ieta();
255  const CaloCellGeometry *thisCell = hcalEndcapGeometry->getGeometry(did);
256  const GlobalPoint& position = thisCell->getPosition();
257  if ( abs(ieta) > 27 && abs(ieta) < 33 && energy > 10. ) {
258  std::cout << "HE/HF hit " << i << " at eta = " << ieta
259  << " with CT energy = " << energy
260  << " at eta, z (hit) = " << position.eta() << " " << position.z()
261  << " at eta, z (cte) = " << ct.emPosition().eta() << " " << ct.emPosition().z()
262  << " at eta, z (cth) = " << ct.hadPosition().eta() << " " << ct.hadPosition().z()
263  << " at eta, z (cto) = " << ct.eta() << " " << ct.vz()
264  << std::endl;
265  }
266  }
267  }
268  }
269  */
270 
271  //Reserve the DetId we are looking for:
272 
274  // EcalDetId edetid;
275  bool foundHCALConstituent = false;
276 
277 
278  //Loop on the calotower constituents and search for HCAL
279  double dead = 0.;
280  double alive = 0.;
281  for(unsigned int i=0;i< hits.size();++i) {
282  if(hits[i].det()==DetId::Hcal) {
283  foundHCALConstituent = true;
284  detid = hits[i];
285  // An HCAL tower was found: Look for dead ECAL channels in the same CaloTower.
286  if ( ECAL_Compensate_ && energy > ECAL_Threshold_ ) {
287  for(unsigned int j=0;j<allConstituents.size();++j) {
288  if ( allConstituents[j].det()==DetId::Ecal ) {
289  alive += 1.;
290  EcalChannelStatus::const_iterator chIt = theEcalChStatus->find(allConstituents[j]);
291  unsigned int dbStatus = chIt != theEcalChStatus->end() ? chIt->getStatusCode() : 0;
292  if ( dbStatus > ECAL_Dead_Code_ ) dead += 1.;
293  }
294  }
295  }
296  // Protection: tower 29 in HF is merged with tower 30.
297  // Just take the position of tower 30 in that case.
298  if ( detid.subdet() == HcalForward && abs(detid.ieta()) == 29 ) continue;
299  break;
300  }
301  }
302 
303  // In case of dead ECAL channel, rescale the HCAL energy...
304  double rescaleFactor = alive > 0. ? 1. + ECAL_Compensation_*dead/alive : 1.;
305 
306  reco::PFRecHit* pfrh = 0;
307  reco::PFRecHit* pfrhCleaned = 0;
308  //---ab: need 2 rechits for the HF:
309  reco::PFRecHit* pfrhHFEM = 0;
310  reco::PFRecHit* pfrhHFHAD = 0;
311  reco::PFRecHit* pfrhHFEMCleaned = 0;
312  reco::PFRecHit* pfrhHFHADCleaned = 0;
313  reco::PFRecHit* pfrhHFEMCleaned29 = 0;
314  reco::PFRecHit* pfrhHFHADCleaned29 = 0;
315 
316  if(foundHCALConstituent)
317  {
318  // std::cout << ", new Energy = " << energy << std::endl;
319  switch( detid.subdet() ) {
320  case HcalBarrel:
321  {
322  if(energy < thresh_Barrel_ ) continue;
323 
324  /*
325  // Check the timing
326  if ( energy > 5. ) {
327  for(unsigned int i=0;i< hits.size();++i) {
328  if( hits[i].det() != DetId::Hcal ) continue;
329  HcalDetId theDetId = hits[i];
330  typedef HBHERecHitCollection::const_iterator iHBHE;
331  iHBHE theHit = hbheHandle->find(theDetId);
332  if ( theHit != hbheHandle->end() )
333  std::cout << "HCAL hit : "
334  << theDetId.ieta() << " " << theDetId.iphi() << " "
335  << theHit->energy() << " " << theHit->time() << std::endl;
336  }
337  }
338  */
339 
340 
341  // if ( HCAL_Calib_ ) energy *= std::min(max_Calib_,myPFCorr->getValues(detid)->getValue());
342  //if ( rescaleFactor > 1. )
343  // std::cout << "Barrel HCAL energy rescaled from = " << energy << " to " << energy*rescaleFactor << std::endl;
344  if ( rescaleFactor > 1. ) {
345  pfrhCleaned = createHcalRecHit( detid,
346  energy,
348  hcalBarrelGeometry,
349  ct.id().rawId() );
350  pfrhCleaned->setRescale(rescaleFactor);
351  energy *= rescaleFactor;
352  }
353  pfrh = createHcalRecHit( detid,
354  energy,
356  hcalBarrelGeometry,
357  ct.id().rawId() );
358  pfrh->setRescale(rescaleFactor);
359  }
360  break;
361  case HcalEndcap:
362  {
363  if(energy < thresh_Endcap_ ) continue;
364 
365  /*
366  // Check the timing
367  if ( energy > 5. ) {
368  for(unsigned int i=0;i< hits.size();++i) {
369  if( hits[i].det() != DetId::Hcal ) continue;
370  HcalDetId theDetId = hits[i];
371  typedef HBHERecHitCollection::const_iterator iHBHE;
372  iHBHE theHit = hbheHandle->find(theDetId);
373  if ( theHit != hbheHandle->end() )
374  std::cout << "HCAL hit : "
375  << theDetId.ieta() << " " << theDetId.iphi() << " "
376  << theHit->energy() << " " << theHit->time() << std::endl;
377  }
378  }
379  */
380 
381  // Apply tower 29 calibration
382  if ( HCAL_Calib_ && abs(detid.ieta()) == 29 ) energy *= HCAL_Calib_29;
383  //if ( rescaleFactor > 1. )
384  // std::cout << "End-cap HCAL energy rescaled from = " << energy << " to " << energy*rescaleFactor << std::endl;
385  if ( rescaleFactor > 1. ) {
386  pfrhCleaned = createHcalRecHit( detid,
387  energy,
389  hcalEndcapGeometry,
390  ct.id().rawId() );
391  pfrhCleaned->setRescale(rescaleFactor);
392  energy *= rescaleFactor;
393  }
394  pfrh = createHcalRecHit( detid,
395  energy,
397  hcalEndcapGeometry,
398  ct.id().rawId() );
399  pfrh->setRescale(rescaleFactor);
400  }
401  break;
402  case HcalOuter:
403  {
404  }
405  break;
406  case HcalForward:
407  {
408  //---ab: 2 rechits for HF:
409  //double energyemHF = weight_HFem_*ct.emEnergy();
410  //double energyhadHF = weight_HFhad_*ct.hadEnergy();
411  double energyemHF = weight_HFem_ * energyEM;
412  double energyhadHF = weight_HFhad_ * energy;
413  // Some energy in the tower !
414  if((energyemHF+energyhadHF) < thresh_HF_ ) continue;
415 
416  // Some cleaning in the HF
417  double longFibre = energyemHF + energyhadHF/2.;
418  double shortFibre = energyhadHF/2.;
419  int ieta = detid.ieta();
420  int iphi = detid.iphi();
421  HcalDetId theLongDetId (HcalForward, ieta, iphi, 1);
422  HcalDetId theShortDetId (HcalForward, ieta, iphi, 2);
424  iHF theLongHit = hfHandle->find(theLongDetId);
425  iHF theShortHit = hfHandle->find(theShortDetId);
426  //
427  double theLongHitEnergy = 0.;
428  double theShortHitEnergy = 0.;
429  bool flagShortDPG = false;
430  bool flagLongDPG = false;
431  bool flagShortTimeDPG = false;
432  bool flagLongTimeDPG = false;
433  bool flagShortPulseDPG = false;
434  bool flagLongPulseDPG = false;
435  //
436  if ( theLongHit != hfHandle->end() ) {
437  theLongHitEnergy = theLongHit->energy();
438  flagLongDPG = applyLongShortDPG_ && theLongHit->flagField(HcalCaloFlagLabels::HFLongShort)==1;
439  flagLongTimeDPG = applyTimeDPG_ && theLongHit->flagField(HcalCaloFlagLabels::HFInTimeWindow)==1;
440  flagLongPulseDPG = applyPulseDPG_ && theLongHit->flagField(HcalCaloFlagLabels::HFDigiTime)==1;
441  }
442  //
443  if ( theShortHit != hfHandle->end() ) {
444  theShortHitEnergy = theShortHit->energy();
445  flagShortDPG = applyLongShortDPG_ && theShortHit->flagField(HcalCaloFlagLabels::HFLongShort)==1;
446  flagShortTimeDPG = applyTimeDPG_ && theShortHit->flagField(HcalCaloFlagLabels::HFInTimeWindow)==1;
447  flagShortPulseDPG = applyPulseDPG_ && theShortHit->flagField(HcalCaloFlagLabels::HFDigiTime)==1;
448  }
449 
450  // Then check the timing in short and long fibres in all other towers.
451  if ( theShortHitEnergy > longShortFibre_Cut &&
452  ( theShortHit->time() < minShortTiming_Cut ||
453  theShortHit->time() > maxShortTiming_Cut ||
454  flagShortTimeDPG || flagShortPulseDPG ) ) {
455  // rescaleFactor = 0. ;
456  pfrhHFHADCleaned = createHcalRecHit( detid,
457  theShortHitEnergy,
459  hcalEndcapGeometry,
460  ct.id().rawId() );
461  pfrhHFHADCleaned->setRescale(theShortHit->time());
462  /*
463  std::cout << "ieta/iphi = " << ieta << " " << iphi
464  << ", Energy em/had/long/short = "
465  << energyemHF << " " << energyhadHF << " "
466  << theLongHitEnergy << " " << theShortHitEnergy << " "
467  << ". Time = " << theShortHit->time() << " "
468  << ". The short and long flags : "
469  << flagShortDPG << " " << flagLongDPG << " "
470  << flagShortTimeDPG << " " << flagLongTimeDPG << " "
471  << flagShortPulseDPG << " " << flagLongPulseDPG << " "
472  << ". Short fibres were cleaned." << std::endl;
473  */
474  shortFibre -= theShortHitEnergy;
475  theShortHitEnergy = 0.;
476  }
477 
478 
479  if ( theLongHitEnergy > longShortFibre_Cut &&
480  ( theLongHit->time() < minLongTiming_Cut ||
481  theLongHit->time() > maxLongTiming_Cut ||
482  flagLongTimeDPG || flagLongPulseDPG ) ) {
483  //rescaleFactor = 0. ;
484  pfrhHFEMCleaned = createHcalRecHit( detid,
485  theLongHitEnergy,
487  hcalEndcapGeometry,
488  ct.id().rawId() );
489  pfrhHFEMCleaned->setRescale(theLongHit->time());
490  /*
491  std::cout << "ieta/iphi = " << ieta << " " << iphi
492  << ", Energy em/had/long/short = "
493  << energyemHF << " " << energyhadHF << " "
494  << theLongHitEnergy << " " << theShortHitEnergy << " "
495  << ". Time = " << theLongHit->time() << " "
496  << ". The short and long flags : "
497  << flagShortDPG << " " << flagLongDPG << " "
498  << flagShortTimeDPG << " " << flagLongTimeDPG << " "
499  << flagShortPulseDPG << " " << flagLongPulseDPG << " "
500  << ". Long fibres were cleaned." << std::endl;
501  */
502  longFibre -= theLongHitEnergy;
503  theLongHitEnergy = 0.;
504  }
505 
506  // Some energy must be in the long fibres is there is some energy in the short fibres !
507  if ( theShortHitEnergy > shortFibre_Cut &&
508  ( theLongHitEnergy/theShortHitEnergy < longFibre_Fraction ||
509  flagShortDPG ) ) {
510  // Check if the long-fibre hit was not cleaned already (because hot)
511  // In this case don't apply the cleaning
512  const HcalChannelStatus* theStatus = theHcalChStatus->getValues(theLongDetId);
513  unsigned theStatusValue = theStatus->getValue();
514  // The channel is killed
515  if ( !theStatusValue ) {
516  // rescaleFactor = 0. ;
517  pfrhHFHADCleaned = createHcalRecHit( detid,
518  theShortHitEnergy,
520  hcalEndcapGeometry,
521  ct.id().rawId() );
522  pfrhHFHADCleaned->setRescale(theShortHit->time());
523  /*
524  std::cout << "ieta/iphi = " << ieta << " " << iphi
525  << ", Energy em/had/long/short = "
526  << energyemHF << " " << energyhadHF << " "
527  << theLongHitEnergy << " " << theShortHitEnergy << " "
528  << ". Time = " << theShortHit->time() << " "
529  << ". The status value is " << theStatusValue
530  << ". The short and long flags : "
531  << flagShortDPG << " " << flagLongDPG << " "
532  << flagShortTimeDPG << " " << flagLongTimeDPG << " "
533  << flagShortPulseDPG << " " << flagLongPulseDPG << " "
534  << ". Short fibres were cleaned." << std::endl;
535  */
536  shortFibre -= theShortHitEnergy;
537  theShortHitEnergy = 0.;
538  }
539  }
540 
541  if ( theLongHitEnergy > longFibre_Cut &&
542  ( theShortHitEnergy/theLongHitEnergy < shortFibre_Fraction ||
543  flagLongDPG ) ) {
544  // Check if the long-fibre hit was not cleaned already (because hot)
545  // In this case don't apply the cleaning
546  const HcalChannelStatus* theStatus = theHcalChStatus->getValues(theShortDetId);
547  unsigned theStatusValue = theStatus->getValue();
548  // The channel is killed
549  if ( !theStatusValue ) {
550  //rescaleFactor = 0. ;
551  pfrhHFEMCleaned = createHcalRecHit( detid,
552  theLongHitEnergy,
554  hcalEndcapGeometry,
555  ct.id().rawId() );
556  pfrhHFEMCleaned->setRescale(theLongHit->time());
557  /*
558  std::cout << "ieta/iphi = " << ieta << " " << iphi
559  << ", Energy em/had/long/short = "
560  << energyemHF << " " << energyhadHF << " "
561  << theLongHitEnergy << " " << theShortHitEnergy << " "
562  << ". The status value is " << theStatusValue
563  << ". Time = " << theLongHit->time() << " "
564  << ". The short and long flags : "
565  << flagShortDPG << " " << flagLongDPG << " "
566  << flagShortTimeDPG << " " << flagLongTimeDPG << " "
567  << flagShortPulseDPG << " " << flagLongPulseDPG << " "
568  << ". Long fibres were cleaned." << std::endl;
569  */
570  longFibre -= theLongHitEnergy;
571  theLongHitEnergy = 0.;
572  }
573  }
574 
575  // Special treatment for tower 29
576  // A tower with energy only at ieta = +/- 29 is not physical -> Clean
577  if ( abs(ieta) == 29 ) {
578  // rescaleFactor = 0. ;
579  // Clean long fibres
580  if ( theLongHitEnergy > shortFibre_Cut/2. ) {
581  pfrhHFEMCleaned29 = createHcalRecHit( detid,
582  theLongHitEnergy,
584  hcalEndcapGeometry,
585  ct.id().rawId() );
586  pfrhHFEMCleaned29->setRescale(theLongHit->time());
587  /*
588  std::cout << "ieta/iphi = " << ieta << " " << iphi
589  << ", Energy em/had/long/short = "
590  << energyemHF << " " << energyhadHF << " "
591  << theLongHitEnergy << " " << theShortHitEnergy << " "
592  << ". Long fibres were cleaned." << std::endl;
593  */
594  longFibre -= theLongHitEnergy;
595  theLongHitEnergy = 0.;
596  }
597  // Clean short fibres
598  if ( theShortHitEnergy > shortFibre_Cut/2. ) {
599  pfrhHFHADCleaned29 = createHcalRecHit( detid,
600  theShortHitEnergy,
602  hcalEndcapGeometry,
603  ct.id().rawId() );
604  pfrhHFHADCleaned29->setRescale(theShortHit->time());
605  /*
606  std::cout << "ieta/iphi = " << ieta << " " << iphi
607  << ", Energy em/had/long/short = "
608  << energyemHF << " " << energyhadHF << " "
609  << theLongHitEnergy << " " << theShortHitEnergy << " "
610  << ". Short fibres were cleaned." << std::endl;
611  */
612  shortFibre -= theShortHitEnergy;
613  theShortHitEnergy = 0.;
614  }
615  }
616  // Check the timing of the long and short fibre rechits
617 
618  // First, check the timing of long and short fibre in eta = 29 if tower 30.
619  else if ( abs(ieta) == 30 ) {
620  int ieta29 = ieta > 0 ? 29 : -29;
621  HcalDetId theLongDetId29 (HcalForward, ieta29, iphi, 1);
622  HcalDetId theShortDetId29 (HcalForward, ieta29, iphi, 2);
623  iHF theLongHit29 = hfHandle->find(theLongDetId29);
624  iHF theShortHit29 = hfHandle->find(theShortDetId29);
625  //
626  double theLongHitEnergy29 = 0.;
627  double theShortHitEnergy29 = 0.;
628  bool flagShortDPG29 = false;
629  bool flagLongDPG29 = false;
630  bool flagShortTimeDPG29 = false;
631  bool flagLongTimeDPG29 = false;
632  bool flagShortPulseDPG29 = false;
633  bool flagLongPulseDPG29 = false;
634  //
635  if ( theLongHit29 != hfHandle->end() ) {
636  theLongHitEnergy29 = theLongHit29->energy() ;
637  flagLongDPG29 = applyLongShortDPG_ && theLongHit29->flagField(HcalCaloFlagLabels::HFLongShort)==1;
638  flagLongTimeDPG29 = applyTimeDPG_ && theLongHit29->flagField(HcalCaloFlagLabels::HFInTimeWindow)==1;
639  flagLongPulseDPG29 = applyPulseDPG_ && theLongHit29->flagField(HcalCaloFlagLabels::HFDigiTime)==1;
640  }
641  //
642  if ( theShortHit29 != hfHandle->end() ) {
643  theShortHitEnergy29 = theShortHit29->energy();
644  flagShortDPG29 = applyLongShortDPG_ && theShortHit29->flagField(HcalCaloFlagLabels::HFLongShort)==1;
645  flagShortTimeDPG29 = applyTimeDPG_ && theShortHit29->flagField(HcalCaloFlagLabels::HFInTimeWindow)==1;
646  flagShortPulseDPG29 = applyPulseDPG_ && theShortHit29->flagField(HcalCaloFlagLabels::HFDigiTime)==1;
647  }
648 
649  if ( theLongHitEnergy29 > longShortFibre_Cut &&
650  ( theLongHit29->time() < minLongTiming_Cut ||
651  theLongHit29->time() > maxLongTiming_Cut ||
652  flagLongTimeDPG29 || flagLongPulseDPG29 ) ) {
653  //rescaleFactor = 0. ;
654  pfrhHFEMCleaned29 = createHcalRecHit( detid,
655  theLongHitEnergy29,
657  hcalEndcapGeometry,
658  ct.id().rawId() );
659  pfrhHFEMCleaned29->setRescale(theLongHit29->time());
660  /*
661  std::cout << "ieta/iphi = " << ieta29 << " " << iphi
662  << ", Energy em/had/long/short = "
663  << energyemHF << " " << energyhadHF << " "
664  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
665  << ". Time = " << theLongHit29->time() << " "
666  << ". The short and long flags : "
667  << flagShortDPG29 << " " << flagLongDPG29 << " "
668  << flagShortTimeDPG29 << " " << flagLongTimeDPG29 << " "
669  << flagShortPulseDPG29 << " " << flagLongPulseDPG29 << " "
670  << ". Long fibres were cleaned." << std::endl;
671  */
672  longFibre -= theLongHitEnergy29;
673  theLongHitEnergy29 = 0;
674  }
675 
676  if ( theShortHitEnergy29 > longShortFibre_Cut &&
677  ( theShortHit29->time() < minShortTiming_Cut ||
678  theShortHit29->time() > maxShortTiming_Cut ||
679  flagShortTimeDPG29 || flagShortPulseDPG29 ) ) {
680  //rescaleFactor = 0. ;
681  pfrhHFHADCleaned29 = createHcalRecHit( detid,
682  theShortHitEnergy29,
684  hcalEndcapGeometry,
685  ct.id().rawId() );
686  pfrhHFHADCleaned29->setRescale(theShortHit29->time());
687  /*
688  std::cout << "ieta/iphi = " << ieta29 << " " << iphi
689  << ", Energy em/had/long/short = "
690  << energyemHF << " " << energyhadHF << " "
691  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
692  << ". Time = " << theShortHit29->time() << " "
693  << ". The short and long flags : "
694  << flagShortDPG29 << " " << flagLongDPG29 << " "
695  << flagShortTimeDPG29 << " " << flagLongTimeDPG29 << " "
696  << flagShortPulseDPG29 << " " << flagLongPulseDPG29 << " "
697  << ". Short fibres were cleaned." << std::endl;
698  */
699  shortFibre -= theShortHitEnergy29;
700  theShortHitEnergy29 = 0.;
701  }
702 
703  // Some energy must be in the long fibres is there is some energy in the short fibres !
704  if ( theShortHitEnergy29 > shortFibre_Cut &&
705  ( theLongHitEnergy29/theShortHitEnergy29 < 2.*longFibre_Fraction ||
706  flagShortDPG29 ) ) {
707  // Check if the long-fibre hit was not cleaned already (because hot)
708  // In this case don't apply the cleaning
709  const HcalChannelStatus* theStatus = theHcalChStatus->getValues(theLongDetId29);
710  unsigned theStatusValue = theStatus->getValue();
711  // The channel is killed
712  if ( !theStatusValue ) {
713  //rescaleFactor = 0. ;
714  pfrhHFHADCleaned29 = createHcalRecHit( detid,
715  theShortHitEnergy29,
717  hcalEndcapGeometry,
718  ct.id().rawId() );
719  pfrhHFHADCleaned29->setRescale(theShortHit29->time());
720  /*
721  std::cout << "ieta/iphi = " << ieta29 << " " << iphi
722  << ", Energy em/had/long/short = "
723  << energyemHF << " " << energyhadHF << " "
724  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
725  << ". Time = " << theShortHit29->time() << " "
726  << ". The status value is " << theStatusValue
727  << ". The short and long flags : "
728  << flagShortDPG29 << " " << flagLongDPG29 << " "
729  << flagShortTimeDPG29 << " " << flagLongTimeDPG29 << " "
730  << flagShortPulseDPG29 << " " << flagLongPulseDPG29 << " "
731  << ". Short fibres were cleaned." << std::endl;
732  */
733  shortFibre -= theShortHitEnergy29;
734  theShortHitEnergy29 = 0.;
735  }
736  }
737 
738  // Some energy must be in the short fibres is there is some energy in the long fibres !
739  if ( theLongHitEnergy29 > longFibre_Cut &&
740  ( theShortHitEnergy29/theLongHitEnergy29 < shortFibre_Fraction ||
741  flagLongDPG29 ) ) {
742  // Check if the long-fibre hit was not cleaned already (because hot)
743  // In this case don't apply the cleaning
744  const HcalChannelStatus* theStatus = theHcalChStatus->getValues(theShortDetId29);
745  unsigned theStatusValue = theStatus->getValue();
746  // The channel is killed
747  if ( !theStatusValue ) {
748  //rescaleFactor = 0. ;
749  pfrhHFEMCleaned29 = createHcalRecHit( detid,
750  theLongHitEnergy29,
752  hcalEndcapGeometry,
753  ct.id().rawId() );
754  pfrhHFEMCleaned29->setRescale(theLongHit29->time());
755  /*
756  std::cout << "ieta/iphi = " << ieta29 << " " << iphi
757  << ", Energy em/had/long/short = "
758  << energyemHF << " " << energyhadHF << " "
759  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
760  << ". The status value is " << theStatusValue
761  << ". Time = " << theLongHit29->time() << " "
762  << ". The short and long flags : "
763  << flagShortDPG29 << " " << flagLongDPG29 << " "
764  << flagShortTimeDPG29 << " " << flagLongTimeDPG29 << " "
765  << flagShortPulseDPG29 << " " << flagLongPulseDPG29 << " "
766  << ". Long fibres were cleaned." << std::endl;
767  */
768  longFibre -= theLongHitEnergy29;
769  theLongHitEnergy29 = 0.;
770  }
771  }
772 
773  // Check that the energy in tower 29 is smaller than in tower 30
774  // First in long fibres
775  if ( theLongHitEnergy29 > std::max(theLongHitEnergy,shortFibre_Cut/2) ) {
776  pfrhHFEMCleaned29 = createHcalRecHit( detid,
777  theLongHitEnergy29,
779  hcalEndcapGeometry,
780  ct.id().rawId() );
781  pfrhHFEMCleaned29->setRescale(theLongHit29->time());
782  /*
783  std::cout << "ieta/iphi = " << ieta29 << " " << iphi
784  << ", Energy L29/S29/L30/S30 = "
785  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
786  << theLongHitEnergy << " " << theShortHitEnergy << " "
787  << ". Long fibres were cleaned." << std::endl;
788  */
789  longFibre -= theLongHitEnergy29;
790  theLongHitEnergy29 = 0.;
791  }
792  // Second in short fibres
793  if ( theShortHitEnergy29 > std::max(theShortHitEnergy,shortFibre_Cut/2.) ) {
794  pfrhHFHADCleaned29 = createHcalRecHit( detid,
795  theShortHitEnergy29,
797  hcalEndcapGeometry,
798  ct.id().rawId() );
799  pfrhHFHADCleaned29->setRescale(theShortHit29->time());
800  /*
801  std::cout << "ieta/iphi = " << ieta << " " << iphi
802  << ", Energy L29/S29/L30/S30 = "
803  << theLongHitEnergy29 << " " << theShortHitEnergy29 << " "
804  << theLongHitEnergy << " " << theShortHitEnergy << " "
805  << ". Short fibres were cleaned." << std::endl;
806  */
807  shortFibre -= theShortHitEnergy29;
808  theShortHitEnergy29 = 0.;
809  }
810  }
811 
812 
813  // Determine EM and HAD after cleaning of short and long fibres
814  energyhadHF = 2.*shortFibre;
815  energyemHF = longFibre - shortFibre;
816 
817  // The EM energy might be negative, as it amounts to Long - Short
818  // In that case, put the EM "energy" in the HAD energy
819  // Just to avoid systematic positive bias due to "Short" high fluctuations
820  if ( energyemHF < thresh_HF_ ) {
821  energyhadHF += energyemHF;
822  energyemHF = 0.;
823  }
824 
825  // Apply HCAL calibration factors flor towers close to 29, if requested
826  if ( HF_Calib_ && abs(detid.ieta()) <= 32 ) {
827  energyhadHF *= HF_Calib_29;
828  energyemHF *= HF_Calib_29;
829  }
830 
831  // Create an EM and a HAD rechit if above threshold.
832  if ( energyemHF > thresh_HF_ || energyhadHF > thresh_HF_ ) {
833  pfrhHFEM = createHcalRecHit( detid,
834  energyemHF,
836  hcalEndcapGeometry,
837  ct.id().rawId() );
838  pfrhHFHAD = createHcalRecHit( detid,
839  energyhadHF,
841  hcalEndcapGeometry,
842  ct.id().rawId() );
843  pfrhHFEM->setEnergyUp(energyhadHF);
844  pfrhHFHAD->setEnergyUp(energyemHF);
845  }
846 
847  }
848  break;
849  default:
850  LogError("PFRecHitProducerHCAL")
851  <<"CaloTower constituent: unknown layer : "
852  <<detid.subdet()<<endl;
853  }
854 
855  if(pfrh) {
856  rechits.push_back( *pfrh );
857  delete pfrh;
858  idSortedRecHits.insert( make_pair(ct.id().rawId(),
859  rechits.size()-1 ) );
860  }
861  if(pfrhCleaned) {
862  rechitsCleaned.push_back( *pfrhCleaned );
863  delete pfrhCleaned;
864  }
865  //---ab: 2 rechits for HF:
866  if(pfrhHFEM) {
867  HFEMRecHits->push_back( *pfrhHFEM );
868  delete pfrhHFEM;
869  idSortedRecHitsHFEM.insert( make_pair(ct.id().rawId(),
870  HFEMRecHits->size()-1 ) );
871  }
872  if(pfrhHFHAD) {
873  HFHADRecHits->push_back( *pfrhHFHAD );
874  delete pfrhHFHAD;
875  idSortedRecHitsHFHAD.insert( make_pair(ct.id().rawId(),
876  HFHADRecHits->size()-1 ) );
877  }
878  //---ab
879  if(pfrhHFEMCleaned) {
880  rechitsCleaned.push_back( *pfrhHFEMCleaned );
881  delete pfrhHFEMCleaned;
882  }
883  if(pfrhHFHADCleaned) {
884  rechitsCleaned.push_back( *pfrhHFHADCleaned );
885  delete pfrhHFHADCleaned;
886  }
887  if(pfrhHFEMCleaned29) {
888  rechitsCleaned.push_back( *pfrhHFEMCleaned29 );
889  delete pfrhHFEMCleaned29;
890  }
891  if(pfrhHFHADCleaned29) {
892  rechitsCleaned.push_back( *pfrhHFHADCleaned29 );
893  delete pfrhHFHADCleaned29;
894  }
895  }
896  }
897  // do navigation
898  for(unsigned i=0; i<rechits.size(); i++ ) {
899  findRecHitNeighboursCT( rechits[i],
900  idSortedRecHits,
901  caloTowerTopology);
902  }
903  for(unsigned i=0; i<HFEMRecHits->size(); i++ ) {
904  findRecHitNeighboursCT( (*HFEMRecHits)[i],
905  idSortedRecHitsHFEM,
906  caloTowerTopology);
907  }
908  for(unsigned i=0; i<HFHADRecHits->size(); i++ ) {
909  findRecHitNeighboursCT( (*HFHADRecHits)[i],
910  idSortedRecHitsHFHAD,
911  caloTowerTopology);
912  }
913  iEvent.put( HFHADRecHits,"HFHAD" );
914  iEvent.put( HFEMRecHits,"HFEM" );
915  }
916  }
917  else if( !(inputTagHcalRecHitsHBHE_ == InputTag()) ) {
918  // clustering is not done on CaloTowers but on HCAL rechits.
919 
920 
921  // get the hcal topology
922  HcalTopology hcalTopology;
923 
924  // HCAL rechits
925  // vector<edm::Handle<HBHERecHitCollection> > hcalHandles;
927 
928 
930  hcalHandle );
931 
932  if(!found) {
933  ostringstream err;
934  err<<"could not find rechits "<<inputTagHcalRecHitsHBHE_;
935  LogError("PFRecHitProducerHCAL")<<err.str()<<endl;
936 
937  throw cms::Exception( "MissingProduct", err.str());
938  }
939  else {
940  assert( hcalHandle.isValid() );
941 
942  const edm::Handle<HBHERecHitCollection>& handle = hcalHandle;
943  for(unsigned irechit=0; irechit<handle->size(); irechit++) {
944  const HBHERecHit& hit = (*handle)[irechit];
945 
946  double energy = hit.energy();
947 
948  reco::PFRecHit* pfrh = 0;
949 
950 
951  const HcalDetId& detid = hit.detid();
952  switch( detid.subdet() ) {
953  case HcalBarrel:
954  {
955  if(energy < thresh_Barrel_ ) continue;
956  pfrh = createHcalRecHit( detid,
957  energy,
959  hcalBarrelGeometry );
960  }
961  break;
962  case HcalEndcap:
963  {
964  if(energy < thresh_Endcap_ ) continue;
965  pfrh = createHcalRecHit( detid,
966  energy,
968  hcalEndcapGeometry );
969  }
970  break;
971  case HcalForward:
972  {
973  if(energy < thresh_HF_ ) continue;
974  pfrh = createHcalRecHit( detid,
975  energy,
977  hcalEndcapGeometry );
978  }
979  break;
980  default:
981  LogError("PFRecHitProducerHCAL")
982  <<"HCAL rechit: unknown layer : "<<detid.subdet()<<endl;
983  continue;
984  }
985 
986  if(pfrh) {
987  rechits.push_back( *pfrh );
988  delete pfrh;
989  idSortedRecHits.insert( make_pair(detid.rawId(),
990  rechits.size()-1 ) );
991  }
992  }
993 
994 
995  // do navigation:
996  for(unsigned i=0; i<rechits.size(); i++ ) {
997 
998  findRecHitNeighbours( rechits[i], idSortedRecHits,
999  hcalTopology,
1000  *hcalBarrelGeometry,
1001  hcalTopology,
1002  *hcalEndcapGeometry);
1003  } // loop for navigation
1004  } // endif hcal rechits were found
1005  } // endif clustering on rechits in hcal
1006 }
1007 
1008 
1009 
1010 
1011 
1012 
1015  double energy,
1016  PFLayer::Layer layer,
1018  unsigned newDetId ) {
1019 
1020  const CaloCellGeometry *thisCell = geom->getGeometry(detid);
1021  if(!thisCell) {
1022  edm::LogError("PFRecHitProducerHCAL")
1023  <<"warning detid "<<detid.rawId()<<" not found in layer "
1024  <<layer<<endl;
1025  return 0;
1026  }
1027 
1028  const GlobalPoint& position = thisCell->getPosition();
1029 
1030  double depth_correction = 0.;
1031  switch ( layer ) {
1032  case PFLayer::HF_EM:
1033  depth_correction = position.z() > 0. ? EM_Depth_ : -EM_Depth_;
1034  break;
1035  case PFLayer::HF_HAD:
1036  depth_correction = position.z() > 0. ? HAD_Depth_ : -HAD_Depth_;
1037  break;
1038  default:
1039  break;
1040  }
1041 
1042  unsigned id = detid;
1043  if(newDetId) id = newDetId;
1044  reco::PFRecHit *rh =
1045  new reco::PFRecHit( id, layer, energy,
1046  position.x(), position.y(), position.z()+depth_correction,
1047  0,0,0 );
1048 
1049 
1050 
1051 
1052  // set the corners
1053  const CaloCellGeometry::CornersVec& corners = thisCell->getCorners();
1054 
1055  assert( corners.size() == 8 );
1056 
1057  rh->setNECorner( corners[0].x(), corners[0].y(), corners[0].z()+depth_correction );
1058  rh->setSECorner( corners[1].x(), corners[1].y(), corners[1].z()+depth_correction );
1059  rh->setSWCorner( corners[2].x(), corners[2].y(), corners[2].z()+depth_correction );
1060  rh->setNWCorner( corners[3].x(), corners[3].y(), corners[3].z()+depth_correction );
1061 
1062  return rh;
1063 }
1064 
1065 
1066 
1067 
1068 void
1071  const map<unsigned,unsigned >& sortedHits,
1072  const CaloSubdetectorTopology& barrelTopology,
1073  const CaloSubdetectorGeometry& barrelGeometry,
1074  const CaloSubdetectorTopology& endcapTopology,
1075  const CaloSubdetectorGeometry& endcapGeometry ) {
1076 
1077  //cout<<"------PFRecHitProducerHcaL:findRecHitNeighbours navigation value "<<navigation_HF_<<endl;
1078  if(navigation_HF_ == false){
1079  if( rh.layer() == PFLayer::HF_HAD )
1080  return;
1081  if( rh.layer() == PFLayer::HF_EM )
1082  return;
1083  }
1084  DetId detid( rh.detId() );
1085 
1086  const CaloSubdetectorTopology* topology = 0;
1087  const CaloSubdetectorGeometry* geometry = 0;
1088  const CaloSubdetectorGeometry* othergeometry = 0;
1089 
1090  switch( rh.layer() ) {
1091  case PFLayer::ECAL_ENDCAP:
1092  topology = &endcapTopology;
1093  geometry = &endcapGeometry;
1094  break;
1095  case PFLayer::ECAL_BARREL:
1096  topology = &barrelTopology;
1097  geometry = &barrelGeometry;
1098  break;
1099  case PFLayer::HCAL_ENDCAP:
1100  topology = &endcapTopology;
1101  geometry = &endcapGeometry;
1102  othergeometry = &barrelGeometry;
1103  break;
1104  case PFLayer::HCAL_BARREL1:
1105  topology = &barrelTopology;
1106  geometry = &barrelGeometry;
1107  othergeometry = &endcapGeometry;
1108  break;
1109  case PFLayer::PS1:
1110  case PFLayer::PS2:
1111  topology = &barrelTopology;
1112  geometry = &barrelGeometry;
1113  othergeometry = &endcapGeometry;
1114  break;
1115  default:
1116  assert(0);
1117  }
1118 
1119  assert( topology && geometry );
1120 
1121  CaloNavigator<DetId> navigator(detid, topology);
1122 
1123  DetId north = navigator.north();
1124 
1125  DetId northeast(0);
1126  if( north != DetId(0) ) {
1127  northeast = navigator.east();
1128  }
1129  navigator.home();
1130 
1131 
1132  DetId south = navigator.south();
1133 
1134 
1135 
1136  DetId southwest(0);
1137  if( south != DetId(0) ) {
1138  southwest = navigator.west();
1139  }
1140  navigator.home();
1141 
1142 
1143  DetId east = navigator.east();
1144  DetId southeast;
1145  if( east != DetId(0) ) {
1146  southeast = navigator.south();
1147  }
1148  navigator.home();
1149  DetId west = navigator.west();
1150  DetId northwest;
1151  if( west != DetId(0) ) {
1152  northwest = navigator.north();
1153  }
1154  navigator.home();
1155 
1156  IDH i = sortedHits.find( north.rawId() );
1157  if(i != sortedHits.end() )
1158  rh.add4Neighbour( i->second );
1159 
1160  i = sortedHits.find( northeast.rawId() );
1161  if(i != sortedHits.end() )
1162  rh.add8Neighbour( i->second );
1163 
1164  i = sortedHits.find( south.rawId() );
1165  if(i != sortedHits.end() )
1166  rh.add4Neighbour( i->second );
1167 
1168  i = sortedHits.find( southwest.rawId() );
1169  if(i != sortedHits.end() )
1170  rh.add8Neighbour( i->second );
1171 
1172  i = sortedHits.find( east.rawId() );
1173  if(i != sortedHits.end() )
1174  rh.add4Neighbour( i->second );
1175 
1176  i = sortedHits.find( southeast.rawId() );
1177  if(i != sortedHits.end() )
1178  rh.add8Neighbour( i->second );
1179 
1180  i = sortedHits.find( west.rawId() );
1181  if(i != sortedHits.end() )
1182  rh.add4Neighbour( i->second );
1183 
1184  i = sortedHits.find( northwest.rawId() );
1185  if(i != sortedHits.end() )
1186  rh.add8Neighbour( i->second );
1187 
1188 
1189 }
1190 
1191 
1192 void
1195  const map<unsigned, unsigned >& sortedHits,
1196  const CaloSubdetectorTopology& topology ) {
1197  //cout<<"------PFRecHitProducerHcaL:findRecHitNeighboursCT navigation value "<<navigation_HF_<<endl;
1198  // cout<<"----------- rechit print out"<<endl;
1199  // if(( rh.layer() == PFLayer::HF_HAD )||(rh.layer() == PFLayer::HF_EM)) {
1200 
1201  // cout<<rh<<endl;
1202  // }
1203  if(navigation_HF_ == false){
1204  if( rh.layer() == PFLayer::HF_HAD )
1205  return;
1206  if( rh.layer() == PFLayer::HF_EM )
1207  return;
1208  }
1209  CaloTowerDetId ctDetId( rh.detId() );
1210 
1211 
1212  vector<DetId> northids = topology.north(ctDetId);
1213  vector<DetId> westids = topology.west(ctDetId);
1214  vector<DetId> southids = topology.south(ctDetId);
1215  vector<DetId> eastids = topology.east(ctDetId);
1216 
1217 
1218  CaloTowerDetId badId;
1219 
1220  // all the following detids will be CaloTowerDetId
1221  CaloTowerDetId north;
1222  CaloTowerDetId northwest;
1223  CaloTowerDetId northwest2;
1224  CaloTowerDetId west;
1225  CaloTowerDetId west2;
1226  CaloTowerDetId southwest;
1227  CaloTowerDetId southwest2;
1228  CaloTowerDetId south;
1229  CaloTowerDetId southeast;
1230  CaloTowerDetId southeast2;
1231  CaloTowerDetId east;
1232  CaloTowerDetId east2;
1233  CaloTowerDetId northeast;
1234  CaloTowerDetId northeast2;
1235 
1236  // for north and south, there is no ambiguity : 1 or 0 neighbours
1237 
1238  switch( northids.size() ) {
1239  case 0:
1240  break;
1241  case 1:
1242  north = northids[0];
1243  break;
1244  default:
1245  stringstream err("PFRecHitProducerHCAL::findRecHitNeighboursCT : incorrect number of neighbours north: ");
1246  err<<northids.size();
1247  throw( err.str() );
1248  }
1249 
1250  switch( southids.size() ) {
1251  case 0:
1252  break;
1253  case 1:
1254  south = southids[0];
1255  break;
1256  default:
1257  stringstream err("PFRecHitProducerHCAL::findRecHitNeighboursCT : incorrect number of neighbours south: ");
1258  err<<southids.size();
1259  throw( err.str() );
1260  }
1261 
1262  // for east and west, one must take care
1263  // of the pitch change in HCAL endcap.
1264 
1265  switch( eastids.size() ) {
1266  case 0:
1267  break;
1268  case 1:
1269  east = eastids[0];
1270  northeast = getNorth(east, topology);
1271  southeast = getSouth(east, topology);
1272  break;
1273  case 2:
1274  // in this case, 0 is more on the north than 1
1275  east = eastids[0];
1276  east2 = eastids[1];
1277  northeast = getNorth(east, topology );
1278  southeast = getSouth(east2, topology);
1279  northeast2 = getNorth(northeast, topology );
1280  southeast2 = getSouth(southeast, topology);
1281  break;
1282  default:
1283  stringstream err("PFRecHitProducerHCAL::findRecHitNeighboursCT : incorrect number of neighbours eastids: ");
1284  err<<eastids.size();
1285  throw( err.str() );
1286  }
1287 
1288 
1289  switch( westids.size() ) {
1290  case 0:
1291  break;
1292  case 1:
1293  west = westids[0];
1294  northwest = getNorth(west, topology);
1295  southwest = getSouth(west, topology);
1296  break;
1297  case 2:
1298  // in this case, 0 is more on the north than 1
1299  west = westids[0];
1300  west2 = westids[1];
1301  northwest = getNorth(west, topology );
1302  southwest = getSouth(west2, topology );
1303  northwest2 = getNorth(northwest, topology );
1304  southwest2 = getSouth(southwest, topology );
1305  break;
1306  default:
1307  stringstream err("PFRecHitProducerHCAL::findRecHitNeighboursCT : incorrect number of neighbours westids: ");
1308  err<< westids.size();
1309  throw( err.str() );
1310  }
1311 
1312 
1313 
1314 
1315  // find and set neighbours
1316 
1317  IDH i = sortedHits.find( north.rawId() );
1318  if(i != sortedHits.end() )
1319  rh.add4Neighbour( i->second );
1320 
1321  i = sortedHits.find( northeast.rawId() );
1322  if(i != sortedHits.end() )
1323  rh.add8Neighbour( i->second );
1324 
1325  i = sortedHits.find( northeast2.rawId() );
1326  if(i != sortedHits.end() )
1327  rh.add8Neighbour( i->second );
1328 
1329  i = sortedHits.find( south.rawId() );
1330  if(i != sortedHits.end() )
1331  rh.add4Neighbour( i->second );
1332 
1333  i = sortedHits.find( southwest.rawId() );
1334  if(i != sortedHits.end() )
1335  rh.add8Neighbour( i->second );
1336 
1337  i = sortedHits.find( southwest2.rawId() );
1338  if(i != sortedHits.end() )
1339  rh.add8Neighbour( i->second );
1340 
1341  i = sortedHits.find( east.rawId() );
1342  if(i != sortedHits.end() )
1343  rh.add4Neighbour( i->second );
1344 
1345  i = sortedHits.find( east2.rawId() );
1346  if(i != sortedHits.end() )
1347  rh.add4Neighbour( i->second );
1348 
1349  i = sortedHits.find( southeast.rawId() );
1350  if(i != sortedHits.end() )
1351  rh.add8Neighbour( i->second );
1352 
1353  i = sortedHits.find( southeast2.rawId() );
1354  if(i != sortedHits.end() )
1355  rh.add8Neighbour( i->second );
1356 
1357  i = sortedHits.find( west.rawId() );
1358  if(i != sortedHits.end() )
1359  rh.add4Neighbour( i->second );
1360 
1361  i = sortedHits.find( west2.rawId() );
1362  if(i != sortedHits.end() )
1363  rh.add4Neighbour( i->second );
1364 
1365  i = sortedHits.find( northwest.rawId() );
1366  if(i != sortedHits.end() )
1367  rh.add8Neighbour( i->second );
1368 
1369  i = sortedHits.find( northwest2.rawId() );
1370  if(i != sortedHits.end() )
1371  rh.add8Neighbour( i->second );
1372 
1373  // cout<<"----------- rechit print out"<<endl;
1374  // if(( rh.layer() == PFLayer::HF_HAD )||(rh.layer() == PFLayer::HF_EM)) {
1375 
1376  // cout<<rh<<endl;
1377  // }
1378 }
1379 
1380 
1381 
1382 DetId
1384  const CaloSubdetectorTopology& topology) {
1385 
1386  DetId south;
1387  vector<DetId> sids = topology.south(id);
1388  if(sids.size() == 1)
1389  south = sids[0];
1390 
1391  return south;
1392 }
1393 
1394 
1395 
1396 DetId
1398  const CaloSubdetectorTopology& topology) {
1399 
1400  DetId north;
1401  vector<DetId> nids = topology.north(id);
1402  if(nids.size() == 1)
1403  north = nids[0];
1404 
1405  return north;
1406 }
1407 
1408 
void setSECorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:226
T getParameter(std::string const &) const
void add4Neighbour(unsigned index)
Definition: PFRecHit.cc:176
int i
Definition: DBlmapReader.cc:9
void add8Neighbour(unsigned index)
Definition: PFRecHit.cc:181
size_t constituentsSize() const
Definition: CaloTower.h:74
void setNECorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:231
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
void home() const
move the navigator back to the starting point
const DetId & detid() const
Definition: CaloRecHit.h:21
unsigned detId() const
rechit detId
Definition: PFRecHit.h:99
virtual T west() const
move the navigator west
Definition: CaloNavigator.h:81
std::vector< CaloTower >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:57
virtual std::vector< DetId > west(const DetId &id) const =0
#define abs(x)
Definition: mlp_lapack.h:159
reco::PFRecHit * createHcalRecHit(const DetId &detid, double energy, PFLayer::Layer layer, const CaloSubdetectorGeometry *geom, unsigned newDetId=0)
const EcalChannelStatus * theEcalChStatus
virtual T north() const
move the navigator north
Definition: CaloNavigator.h:51
double double double z
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:102
void setSWCorner(double posx, double posy, double posz)
Definition: PFRecHit.cc:221
edm::InputTag inputTagCaloTowers_
virtual T east() const
move the navigator east
Definition: CaloNavigator.h:71
int iEvent
Definition: GenABIO.cc:243
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
Base producer for particle flow rechits (PFRecHit)
double emEnergy() const
Definition: CaloTower.h:79
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
float energy() const
Definition: CaloRecHit.h:19
void setEnergyUp(double eUp)
Definition: PFRecHit.h:73
edm::InputTag inputTagHcalRecHitsHF_
T z() const
Definition: PV3DBase.h:58
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
tuple handle
Definition: patZpeak.py:22
int j
Definition: DBlmapReader.cc:9
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:73
DetId getSouth(const DetId &id, const CaloSubdetectorTopology &topology)
void setRescale(double factor)
Definition: PFRecHit.h:74
bool isValid() const
Definition: HandleBase.h:76
void setNWCorner(double posx, double posy, double posz)
search for pointers to neighbours, using neighbours&#39; DetId.
Definition: PFRecHit.cc:216
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
edm::InputTag inputTagHcalRecHitsHBHE_
void findRecHitNeighbours(reco::PFRecHit &rh, const std::map< unsigned, unsigned > &sortedHits, const CaloSubdetectorTopology &barrelTopo, const CaloSubdetectorGeometry &barrelGeom, const CaloSubdetectorTopology &endcapTopo, const CaloSubdetectorGeometry &endcapGeom)
void findRecHitNeighboursCT(reco::PFRecHit &rh, const std::map< unsigned, unsigned > &sortedHits, const CaloSubdetectorTopology &topology)
double hadEnergy() const
Definition: CaloTower.h:80
virtual std::vector< DetId > north(const DetId &id) const =0
Layer
layer definition
Definition: PFLayer.h:31
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
Definition: DetId.h:20
CaloTowerDetId id() const
Definition: CaloTower.h:72
const HcalChannelQuality * theHcalChStatus
void createRecHits(std::vector< reco::PFRecHit > &rechits, std::vector< reco::PFRecHit > &rechitsCleaned, edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
const CaloTowerConstituentsMap * theTowerConstituentsMap
ESHandle< TrackerGeometry > geometry
std::map< unsigned, unsigned >::const_iterator IDH
virtual std::vector< DetId > south(const DetId &id) const =0
const_iterator find(uint32_t rawId) const
double thresh_Barrel_
rechits with E &lt; threshold will not give rise to a PFRecHit
const_iterator end() const
double thresh_HF_
threshold for HF
DetId getNorth(const DetId &id, const CaloSubdetectorTopology &topology)
Definition: DDAxes.h:10
uint32_t getValue() const
virtual T south() const
move the navigator south
Definition: CaloNavigator.h:61
const Item * getValues(DetId fId) const
const GlobalPoint & getPosition() const
T x() const
Definition: PV3DBase.h:56
virtual std::vector< DetId > east(const DetId &id) const =0
PFRecHitProducerHCAL(const edm::ParameterSet &)
virtual const CornersVec & getCorners() const =0