CMS 3D CMS Logo

PFHFRecHitCreator.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFClusterProducer_PFHFRecHitCreator_h
2 #define RecoParticleFlow_PFClusterProducer_PFHFRecHitCreator_h
3 
5 
11 
18 
19 
21 
22 class PFHFRecHitCreator final : public PFRecHitCreatorBase {
23 
24  public:
26  PFRecHitCreatorBase(iConfig,iC)
27  {
29  EM_Depth_ = iConfig.getParameter<double>("EMDepthCorrection");
30  HAD_Depth_ = iConfig.getParameter<double>("HADDepthCorrection");
31  shortFibre_Cut = iConfig.getParameter<double>("ShortFibre_Cut");
32  longFibre_Fraction = iConfig.getParameter<double>("LongFibre_Fraction");
33  longFibre_Cut = iConfig.getParameter<double>("LongFibre_Cut");
34  shortFibre_Fraction = iConfig.getParameter<double>("ShortFibre_Fraction");
35  thresh_HF_ = iConfig.getParameter<double>("thresh_HF");
36  HFCalib_ = iConfig.getParameter<double>("HFCalib29");
37 
38  }
39 
40 
41 
42  void importRecHits(std::unique_ptr<reco::PFRecHitCollection>&out,std::unique_ptr<reco::PFRecHitCollection>& cleaned ,const edm::Event& iEvent,const edm::EventSetup& iSetup) override {
43 
44 
46 
47  beginEvent(iEvent,iSetup);
48 
50 
52  iSetup.get<CaloGeometryRecord>().get(geoHandle);
53 
54  // get the ecal geometry
55  const CaloSubdetectorGeometry *hcalGeo =
57 
58  iEvent.getByToken(recHitToken_,recHitHandle);
59  for( const auto& erh : *recHitHandle ) {
60  const HcalDetId& detid = (HcalDetId)erh.detid();
61  auto depth = detid.depth();
62 
63  // ATTN: skip dual anode in HF for now (should be fixed in upstream changes)
64  if( depth > 2 ) continue;
65 
66  auto energy = erh.energy();
67  auto time = erh.time();
68 
69  const CaloCellGeometry * thisCell= hcalGeo->getGeometry(detid);
70  auto zp = dynamic_cast<IdealZPrism const*>(thisCell);
71  assert(zp);
72  thisCell = zp->forPF();
73 
74  // find rechit geometry
75  if(!thisCell) {
76  edm::LogError("PFHFRecHitCreator")
77  <<"warning detid "<<detid.rawId()
78  <<" not found in geometry"<<std::endl;
79  continue;
80  }
81 
83 
84 
85  reco::PFRecHit rh(thisCell, detid.rawId(),layer,energy);
86  rh.setTime(time);
87  rh.setDepth(depth);
88 
89  bool rcleaned = false;
90  bool keep=true;
91 
92  //Apply Q tests
93  for( const auto& qtest : qualityTests_ ) {
94  if (!qtest->test(rh,erh,rcleaned)) {
95  keep = false;
96 
97  }
98  }
99 
100  if(keep) {
101  tmpOut.push_back(std::move(rh));
102  }
103  else if (rcleaned)
104  cleaned->push_back(std::move(rh));
105  }
106  //Sort by DetID the collection
108  if (!tmpOut.empty())
109  std::sort(tmpOut.begin(),tmpOut.end(),sorter);
110 
111 
113 
114  double lONG=0.;
115  double sHORT=0.;
116 
117  for (auto& hit : tmpOut) {
118  lONG=0.0;
119  sHORT=0.0;
120 
121  reco::PFRecHit newHit = hit;
122  const HcalDetId& detid = (HcalDetId)hit.detId();
123  if (detid.depth()==1) {
124  lONG=hit.energy();
125  //find the short hit
126  HcalDetId shortID (HcalForward, detid.ieta(), detid.iphi(), 2);
127  auto found_hit = std::lower_bound(tmpOut.begin(),tmpOut.end(),
128  shortID,
129  [](const reco::PFRecHit& a,
130  HcalDetId b){
131  return a.detId() < b.rawId();
132  });
133  if( found_hit != tmpOut.end() && found_hit->detId() == shortID.rawId() ) {
134  sHORT = found_hit->energy();
135  //Ask for fraction
136  double energy = lONG-sHORT;
137 
138  if (abs(detid.ieta())<=32)
139  energy*=HFCalib_;
140  newHit.setEnergy(energy);
141  if (!( lONG > longFibre_Cut &&
142  ( sHORT/lONG < shortFibre_Fraction)))
143  if (energy>thresh_HF_)
144  out->push_back(newHit);
145  }
146  else
147  {
148  //make only long hit
149  double energy = lONG;
150  if (abs(detid.ieta())<=32)
151  energy*=HFCalib_;
152  newHit.setEnergy(energy);
153 
154  if (energy>thresh_HF_)
155  out->push_back(newHit);
156 
157  }
158 
159  }
160  else {
161  sHORT=hit.energy();
162  HcalDetId longID (HcalForward, detid.ieta(), detid.iphi(), 1);
163  auto found_hit = std::lower_bound(tmpOut.begin(),tmpOut.end(),
164  longID,
165  [](const reco::PFRecHit& a,
166  HcalDetId b){
167  return a.detId() < b.rawId();
168  });
169  double energy = 2*sHORT;
170  if( found_hit != tmpOut.end() && found_hit->detId() == longID.rawId() ) {
171  lONG = found_hit->energy();
172  //Ask for fraction
173 
174  //If in this case lONG-sHORT<0 add the energy to the sHORT
175  if ((lONG-sHORT)<thresh_HF_)
176  energy = lONG+sHORT;
177 
178  if (abs(detid.ieta())<=32)
179  energy*=HFCalib_;
180 
181  newHit.setEnergy(energy);
182  if (!( sHORT > shortFibre_Cut &&
183  ( lONG/sHORT < longFibre_Fraction)))
184  if (energy>thresh_HF_)
185  out->push_back(newHit);
186 
187  }
188  else {
189  //only short hit!
190  if (abs(detid.ieta())<=32)
191  energy*=HFCalib_;
192  newHit.setEnergy(energy);
193  if (energy>thresh_HF_)
194  out->push_back(newHit);
195  }
196  }
197 
198 
199  }
200 
201  }
202 
203 
204 
205  protected:
207  double EM_Depth_;
208  double HAD_Depth_;
209  // Don't allow large energy in short fibres if there is no energy in long fibres
210  double shortFibre_Cut;
212 
213  // Don't allow large energy in long fibres if there is no energy in short fibres
214  double longFibre_Cut;
216  double thresh_HF_;
217  double HFCalib_;
218 
219  class DetIDSorter {
220  public:
221  DetIDSorter() = default;
222  ~DetIDSorter() = default;
223 
225  const reco::PFRecHit& b) {
226  if (DetId(a.detId()).det() == DetId::Hcal || DetId(b.detId()).det() == DetId::Hcal) return (HcalDetId)(a.detId()) < (HcalDetId)(b.detId());
227  else return a.detId() < b.detId();
228  }
229 
230  };
231 
232 
233 };
234 #endif
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
void importRecHits(std::unique_ptr< reco::PFRecHitCollection > &out, std::unique_ptr< reco::PFRecHitCollection > &cleaned, const edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::vector< std::unique_ptr< PFRecHitQTestBase > > qualityTests_
PFHFRecHitCreator(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
unsigned detId() const
rechit detId
Definition: PFRecHit.h:108
edm::EDGetTokenT< edm::SortedCollection< HFRecHit > > recHitToken_
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
Definition: PFRecHitFwd.h:9
bool operator()(const reco::PFRecHit &a, const reco::PFRecHit &b)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const int keep
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
int iEvent
Definition: GenABIO.cc:230
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void beginEvent(const edm::Event &event, const edm::EventSetup &setup)
void setTime(double time)
Definition: PFRecHit.h:79
Layer
layer definition
Definition: PFLayer.h:31
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void setEnergy(float energy)
Definition: PFRecHit.h:74
def move(src, dest)
Definition: eostools.py:510