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
56 
57  iEvent.getByToken(recHitToken_,recHitHandle);
58  for( const auto& erh : *recHitHandle ) {
59  const HcalDetId& detid = (HcalDetId)erh.detid();
60  auto depth = detid.depth();
61 
62  // ATTN: skip dual anode in HF for now (should be fixed in upstream changes)
63  if( depth > 2 ) continue;
64 
65  auto energy = erh.energy();
66  auto time = erh.time();
67 
68  std::shared_ptr<const CaloCellGeometry> thisCell= hcalGeo->getGeometry(detid);
69  auto zp = dynamic_cast<IdealZPrism const*>(thisCell.get());
70  assert(zp);
71  thisCell = zp->forPF();
72 
73  // find rechit geometry
74  if(!thisCell) {
75  edm::LogError("PFHFRecHitCreator")
76  <<"warning detid "<<detid.rawId()
77  <<" not found in geometry"<<std::endl;
78  continue;
79  }
80 
82 
83 
84  reco::PFRecHit rh(thisCell, detid.rawId(),layer,energy);
85  rh.setTime(time);
86  rh.setDepth(depth);
87 
88  bool rcleaned = false;
89  bool keep=true;
90 
91  //Apply Q tests
92  for( const auto& qtest : qualityTests_ ) {
93  if (!qtest->test(rh,erh,rcleaned)) {
94  keep = false;
95 
96  }
97  }
98 
99  if(keep) {
100  tmpOut.push_back(std::move(rh));
101  }
102  else if (rcleaned)
103  cleaned->push_back(std::move(rh));
104  }
105  //Sort by DetID the collection
107  if (!tmpOut.empty())
108  std::sort(tmpOut.begin(),tmpOut.end(),sorter);
109 
110 
112 
113  for (auto& hit : tmpOut) {
114  reco::PFRecHit newHit = hit;
115  const HcalDetId& detid = (HcalDetId)hit.detId();
116  if (detid.depth()==1) {
117  double lONG=hit.energy();
118  //find the short hit
119  HcalDetId shortID (HcalForward, detid.ieta(), detid.iphi(), 2);
120  auto found_hit = std::lower_bound(tmpOut.begin(),tmpOut.end(),
121  shortID,
122  [](const reco::PFRecHit& a,
123  HcalDetId b){
124  return a.detId() < b.rawId();
125  });
126  if( found_hit != tmpOut.end() && found_hit->detId() == shortID.rawId() ) {
127  double sHORT = found_hit->energy();
128  //Ask for fraction
129  double energy = lONG-sHORT;
130 
131  if (abs(detid.ieta())<=32)
132  energy*=HFCalib_;
133  newHit.setEnergy(energy);
134  if (!( lONG > longFibre_Cut &&
135  ( sHORT/lONG < shortFibre_Fraction)))
136  if (energy>thresh_HF_)
137  out->push_back(newHit);
138  }
139  else
140  {
141  //make only long hit
142  double energy = lONG;
143  if (abs(detid.ieta())<=32)
144  energy*=HFCalib_;
145  newHit.setEnergy(energy);
146 
147  if (energy>thresh_HF_)
148  out->push_back(newHit);
149 
150  }
151 
152  }
153  else {
154  double sHORT=hit.energy();
155  HcalDetId longID (HcalForward, detid.ieta(), detid.iphi(), 1);
156  auto found_hit = std::lower_bound(tmpOut.begin(),tmpOut.end(),
157  longID,
158  [](const reco::PFRecHit& a,
159  HcalDetId b){
160  return a.detId() < b.rawId();
161  });
162  double energy = 2*sHORT;
163  if( found_hit != tmpOut.end() && found_hit->detId() == longID.rawId() ) {
164  double lONG = found_hit->energy();
165  //Ask for fraction
166 
167  //If in this case lONG-sHORT<0 add the energy to the sHORT
168  if ((lONG-sHORT)<thresh_HF_)
169  energy = lONG+sHORT;
170 
171  if (abs(detid.ieta())<=32)
172  energy*=HFCalib_;
173 
174  newHit.setEnergy(energy);
175  if (!( sHORT > shortFibre_Cut &&
176  ( lONG/sHORT < longFibre_Fraction)))
177  if (energy>thresh_HF_)
178  out->push_back(newHit);
179 
180  }
181  else {
182  //only short hit!
183  if (abs(detid.ieta())<=32)
184  energy*=HFCalib_;
185  newHit.setEnergy(energy);
186  if (energy>thresh_HF_)
187  out->push_back(newHit);
188  }
189  }
190 
191 
192  }
193 
194  }
195 
196 
197 
198  protected:
200  double EM_Depth_;
201  double HAD_Depth_;
202  // Don't allow large energy in short fibres if there is no energy in long fibres
203  double shortFibre_Cut;
205 
206  // Don't allow large energy in long fibres if there is no energy in short fibres
207  double longFibre_Cut;
209  double thresh_HF_;
210  double HFCalib_;
211 
212  class DetIDSorter {
213  public:
214  DetIDSorter() = default;
215  ~DetIDSorter() = default;
216 
218  const reco::PFRecHit& b) {
219  if (DetId(a.detId()).det() == DetId::Hcal || DetId(b.detId()).det() == DetId::Hcal) return (HcalDetId)(a.detId()) < (HcalDetId)(b.detId());
220  else return a.detId() < b.detId();
221  }
222 
223  };
224 
225 
226 };
227 #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:49
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:579
unsigned detId() const
rechit detId
Definition: PFRecHit.h:108
edm::EDGetTokenT< edm::SortedCollection< HFRecHit > > recHitToken_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
Definition: PFRecHitFwd.h:9
bool operator()(const reco::PFRecHit &a, const reco::PFRecHit &b)
const int keep
int depth() const
get the tower depth
Definition: HcalDetId.h:162
int iEvent
Definition: GenABIO.cc:230
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:32
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
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.h:157
Definition: DetId.h:18
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void setEnergy(float energy)
Definition: PFRecHit.h:74
T get() const
Definition: EventSetup.h:63
def move(src, dest)
Definition: eostools.py:510