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