test
CMS 3D CMS Logo

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