CMS 3D CMS Logo

PFHBHERecHitCreatorMaxSample.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFClusterProducer_PFHBHeRecHitCreatorMaxSample_h
2 #define RecoParticleFlow_PFClusterProducer_PFHBHeRecHitCreatorMaxSample_h
3 
5 
11 
17 
22 
24 
25 
27 
28 
30 
31 
33 
34  public:
36  PFRecHitCreatorBase(iConfig,iC)
37  {
39  }
40 
41 
42  ~PFHBHERecHitCreatorMaxSample() override = default;
43 
44 
45  void importRecHits(std::unique_ptr<reco::PFRecHitCollection>&out,std::unique_ptr<reco::PFRecHitCollection>& cleaned ,const edm::Event& iEvent,const edm::EventSetup& iSetup) override {
46 
47  beginEvent(iEvent,iSetup);
48 
50 
52  iSetup.get<CaloGeometryRecord>().get(geoHandle);
53 
54 
56  iSetup.get<HcalDbRecord > ().get(conditions);
57 
58  // get the ecal geometry
59  const CaloSubdetectorGeometry *hcalBarrelGeo = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
60  const CaloSubdetectorGeometry *hcalEndcapGeo = geoHandle->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
61 
62  iEvent.getByToken(recHitToken_,recHitHandle);
63  for( const auto& erh : *recHitHandle ) {
64  const HcalDetId detid = erh.idFront();
66 
67 
68  //CUSTOM ENERGY AND TIME RECO
69 
70  CaloSamples tool;
71  const HcalCalibrations& calibrations = conditions->getHcalCalibrations(detid);
72  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detid);
73  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
74  HcalCoderDb coder(*channelCoder, *shape);
75  int auxwd1 = erh.auxHBHE(); // TS = 0,1,2,3 info
76  int auxwd2 = erh.aux(); // TS = 4,5,6,7 info
77 
78  int adc[8];
79  int capid[8];
80 
81  adc[0] = (auxwd1) & 0x7F;
82  adc[1] = (auxwd1 >> 7) & 0x7F;
83  adc[2] = (auxwd1 >> 14) & 0x7F;
84  adc[3] = (auxwd1 >> 21) & 0x7F;
85 
86  capid[0] = (auxwd1 >> 28) & 0x3; // rotating through 4 values: 0,1,2,3
87  capid[1] = (capid[0] + 1 <= 3) ? capid[0] + 1 : 0;
88  capid[2] = (capid[1] + 1 <= 3) ? capid[1] + 1 : 0;
89  capid[3] = (capid[2] + 1 <= 3) ? capid[2] + 1 : 0;
90 
91  adc[4] = (auxwd2) & 0x7F;
92  adc[5] = (auxwd2 >> 7) & 0x7F;
93  adc[6] = (auxwd2 >> 14) & 0x7F;
94  adc[7] = (auxwd2 >> 21) & 0x7F;
95 
96  capid[4] = (auxwd2 >> 28) & 0x3;
97  capid[5] = (capid[4] + 1 <= 3) ? capid[4] + 1 : 0;
98  capid[6] = (capid[5] + 1 <= 3) ? capid[5] + 1 : 0;
99  capid[7] = (capid[6] + 1 <= 3) ? capid[6] + 1 : 0;
100 
101  // Pack the above into HBHEDataFrame for subsequent linearization to fC
102  HBHEDataFrame digi(detid);
103  digi.setSize(10);
104  digi.setPresamples(4);
105  for (int ii = 0; ii < 8; ii++) {
106  HcalQIESample s (adc[ii], capid[ii], 0, 0);
107  digi.setSample(ii,s);
108  }
109  coder.adc2fC(digi, tool);
110  HcalGenericDetId hcalGenDetId(erh.id());
111  std::array<double,8> samples;
112 
113 
114  //store the samples over thresholds
115  for (int ii = 0; ii < 8; ii++) {
116  double sampleE = calibrations.respcorrgain(capid[ii]) *
117  (tool[ii] - calibrations.pedestal(capid[ii]));
118  if (sampleE>sampleCut_)
119  samples[ii] = sampleE;
120  else
121  samples[ii] = 0.0;
122 
123  }
124 
125 
126  //run the algorithm
127  double energy=0.0;
128  double energy2=0.0;
129  double time=0.0;
130  double s2=0.0;
131  std::vector<double> hitEnergies;
132  std::vector<double> hitTimes;
133 
134  for (int ii = 0; ii < 8; ii++) {
135  energy=energy+samples[ii];
136  s2=samples[ii]*samples[ii];
137  time = time+(-100. + ii*25.0)*s2;
138  energy2=energy2+s2;
139 
140  if (ii>0 && ii<7) {
141  if (samples[ii]<=samples[ii-1] && samples[ii]<samples[ii+1] && energy>0) {
142  hitEnergies.push_back(energy);
143  hitTimes.push_back(time/energy2);
144  energy=0.0;
145  energy2=0.0;
146  time=0.0;
147  }
148 
149  }
150  else if (ii==7 && energy>0) {
151  hitEnergies.push_back(energy);
152  hitTimes.push_back(time/energy2);
153  energy=0.0;
154  energy2=0.0;
155  time=0.0;
156  }
157 
158  }
159 
160  if (hitEnergies.empty())
161  continue;
162 
163  int depth = detid.depth();
164 
165  std::shared_ptr<const CaloCellGeometry> thisCell = nullptr;
167  switch(esd) {
168  case HcalBarrel:
169  thisCell = hcalBarrelGeo->getGeometry(detid);
170  layer = PFLayer::HCAL_BARREL1;
171  break;
172 
173  case HcalEndcap:
174  thisCell = hcalEndcapGeo->getGeometry(detid);
175  layer = PFLayer::HCAL_ENDCAP;
176  break;
177  default:
178  break;
179  }
180 
181  // find rechit geometry
182  if(!thisCell) {
183  edm::LogError("PFHBHERecHitCreatorMaxSample")
184  <<"warning detid "<<detid.rawId()
185  <<" not found in geometry"<<std::endl;
186  continue;
187  }
188 
189 
190 
191  reco::PFRecHit rh(thisCell, detid.rawId(),layer,
192  energy);
193 
194  rh.setDepth(depth);
195 
196 
197 
198  // for (unsigned int i=0;i<hitEnergies.size();++i)
199  // printf(" %f / %f ,",hitEnergies[i],hitTimes[i]);
200 
201  //now find the best hit
202  auto best_hit = std::min_element(hitTimes.begin(),hitTimes.end(),
203  [](const double& a,
204  const double& b){
205  return fabs(a) < fabs(b);
206  });
207 
208 
209  rh.setTime(*best_hit);
210  rh.setEnergy(hitEnergies[std::distance(hitTimes.begin(),best_hit)]);
211  // printf("Best = %f %f\n",rh.energy(),rh.time());
212 
213  //Apply Q tests
214  bool rcleaned = false;
215  bool keep=true;
216 
217  for( const auto& qtest : qualityTests_ ) {
218  if (!qtest->test(rh,erh,rcleaned)) {
219  keep = false;
220  }
221  }
222 
223  if(keep) {
224  out->push_back(rh);
225  }
226  else if (rcleaned)
227  cleaned->push_back(rh);
228  }
229  }
230 
231 
232  protected:
234  const double sampleCut_ = 0.6; // minimalistic threshold just to reduce the iterations
235 
236 };
237 
238 
239 
240 
241 
242 #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 setDepth(int depth)
Definition: PFRecHit.h:80
std::vector< std::unique_ptr< PFRecHitQTestBase > > qualityTests_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
~PFHBHERecHitCreatorMaxSample() override=default
void setSize(int size)
Definition: HBHEDataFrame.h:65
const int keep
int depth() const
get the tower depth
Definition: HcalDetId.h:166
void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const override
Definition: HcalCoderDb.cc:68
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::SortedCollection< HBHERecHit > > recHitToken_
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:32
void setPresamples(int ps)
Definition: HBHEDataFrame.h:70
void setSample(int i, const HcalQIESample &sam)
Definition: HBHEDataFrame.h:80
void importRecHits(std::unique_ptr< reco::PFRecHitCollection > &out, std::unique_ptr< reco::PFRecHitCollection > &cleaned, const edm::Event &iEvent, const edm::EventSetup &iSetup) override
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
HcalSubdetector
Definition: HcalAssistant.h:31
void beginEvent(const edm::Event &event, const edm::EventSetup &setup)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
ii
Definition: cuy.py:590
Layer
layer definition
Definition: PFLayer.h:31
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
PFHBHERecHitCreatorMaxSample(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
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
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
double a
Definition: hdecay.h:121
T get() const
Definition: EventSetup.h:71
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
constexpr double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3