CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTriggerPrimitiveAlgo.cc
Go to the documentation of this file.
3 
4 #include <iostream>
12 
13 using namespace std;
14 
15 HcalTriggerPrimitiveAlgo::HcalTriggerPrimitiveAlgo( bool pf, const std::vector<double>& w, int latency,
16  uint32_t FG_threshold, uint32_t ZS_threshold,
17  int numberOfSamples, int numberOfPresamples,
18  uint32_t minSignalThreshold, uint32_t PMT_NoiseThreshold)
19  : incoder_(0), outcoder_(0),
20  theThreshold(0), peakfind_(pf), weights_(w), latency_(latency),
21  FG_threshold_(FG_threshold), ZS_threshold_(ZS_threshold),
22  numberOfSamples_(numberOfSamples),
23  numberOfPresamples_(numberOfPresamples),
24  minSignalThreshold_(minSignalThreshold),
25  PMT_NoiseThreshold_(PMT_NoiseThreshold),
26  peak_finder_algorithm_(2)
27 {
28  //No peak finding setting (for Fastsim)
29  if (!peakfind_){
30  numberOfSamples_ = 1;
32  }
33  // Switch to integer for comparisons - remove compiler warning
35 }
36 
37 
39 }
40 
41 
43  const HcalTPGCompressor* outcoder,
44  const HBHEDigiCollection& hbheDigis,
45  const HFDigiCollection& hfDigis,
47  const HcalTrigTowerGeometry* trigTowerGeometry,
48  float rctlsb) {
49  theTrigTowerGeometry = trigTowerGeometry;
50 
51  incoder_=dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
52  outcoder_=outcoder;
53 
54  theSumMap.clear();
55  theTowerMapFGSum.clear();
56  HF_Veto.clear();
57  fgMap_.clear();
58 
59  // do the HB/HE digis
60  for(HBHEDigiCollection::const_iterator hbheItr = hbheDigis.begin();
61  hbheItr != hbheDigis.end(); ++hbheItr) {
62  addSignal(*hbheItr);
63  }
64 
65  // and the HF digis
66  for(HFDigiCollection::const_iterator hfItr = hfDigis.begin();
67  hfItr != hfDigis.end(); ++hfItr) {
68  addSignal(*hfItr);
69 
70  }
71 
72  for(SumMap::iterator mapItr = theSumMap.begin(); mapItr != theSumMap.end(); ++mapItr) {
73  result.push_back(HcalTriggerPrimitiveDigi(mapItr->first));
74  HcalTrigTowerDetId detId(mapItr->second.id());
75  if(detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower())
76  { analyzeHF(mapItr->second, result.back(), rctlsb);}
77  else{analyze(mapItr->second, result.back());}
78  }
79  return;
80 }
81 
82 
84  //Hack for 300_pre10, should be removed.
85  if (frame.id().depth()==5) return;
86 
87  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
88  assert(ids.size() == 1 || ids.size() == 2);
89  IntegerCaloSamples samples1(ids[0], int(frame.size()));
90 
91  samples1.setPresamples(frame.presamples());
92  incoder_->adc2Linear(frame, samples1);
93 
94  std::vector<bool> msb;
95  incoder_->lookupMSB(frame, msb);
96 
97  if(ids.size() == 2) {
98  // make a second trigprim for the other one, and split the energy
99  IntegerCaloSamples samples2(ids[1], samples1.size());
100  for(int i = 0; i < samples1.size(); ++i) {
101  samples1[i] = uint32_t(samples1[i]*0.5);
102  samples2[i] = samples1[i];
103  }
104  samples2.setPresamples(frame.presamples());
105  addSignal(samples2);
106  addFG(ids[1], msb);
107  }
108  addSignal(samples1);
109  addFG(ids[0], msb);
110 }
111 
112 
114 
115  if(frame.id().depth() == 1 || frame.id().depth() == 2) {
116  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
117  assert(ids.size() == 1);
118  IntegerCaloSamples samples(ids[0], frame.size());
119  samples.setPresamples(frame.presamples());
120  incoder_->adc2Linear(frame, samples);
121 
122  // Don't add to final collection yet
123  // HF PMT veto sum is calculated in analyzerHF()
124  IntegerCaloSamples zero_samples(ids[0], frame.size());
125  zero_samples.setPresamples(frame.presamples());
126  addSignal(zero_samples);
127 
128  // Mask off depths: fgid is the same for both depths
129  uint32_t fgid = (frame.id().rawId() | 0x1c000) ;
130 
131  if ( theTowerMapFGSum.find(ids[0]) == theTowerMapFGSum.end() ) {
132  SumFGContainer sumFG;
133  theTowerMapFGSum.insert(std::pair<HcalTrigTowerDetId, SumFGContainer >(ids[0], sumFG));
134  }
135 
136  SumFGContainer& sumFG = theTowerMapFGSum[ids[0]];
137  SumFGContainer::iterator sumFGItr;
138  for ( sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
139  if (sumFGItr->id() == fgid) break;
140  }
141  // If find
142  if (sumFGItr != sumFG.end()) {
143  for (int i=0; i<samples.size(); ++i) (*sumFGItr)[i] += samples[i];
144  }
145  else {
146  //Copy samples (change to fgid)
147  IntegerCaloSamples sumFGSamples(DetId(fgid), samples.size());
148  sumFGSamples.setPresamples(samples.presamples());
149  for (int i=0; i<samples.size(); ++i) sumFGSamples[i] = samples[i];
150  sumFG.push_back(sumFGSamples);
151  }
152 
153  // set veto to true if Long or Short less than threshold
154  if (HF_Veto.find(fgid) == HF_Veto.end()) {
155  vector<bool> vetoBits(samples.size(), false);
156  HF_Veto[fgid] = vetoBits;
157  }
158  for (int i=0; i<samples.size(); ++i)
159  if (samples[i] < minSignalThreshold_)
160  HF_Veto[fgid][i] = true;
161  }
162 }
163 
164 
166  HcalTrigTowerDetId id(samples.id());
167  SumMap::iterator itr = theSumMap.find(id);
168  if(itr == theSumMap.end()) {
169  theSumMap.insert(std::make_pair(id, samples));
170  }
171  else {
172  // wish CaloSamples had a +=
173  for(int i = 0; i < samples.size(); ++i) {
174  (itr->second)[i] += samples[i];
175  }
176  }
177 }
178 
179 
181  int shrink = weights_.size() - 1;
182  std::vector<bool> finegrain(numberOfSamples_,false);
183  std::vector<bool>& msb = fgMap_[samples.id()];
184  IntegerCaloSamples sum(samples.id(), samples.size());
185 
186  //slide algo window
187  for(int ibin = 0; ibin < int(samples.size())- shrink; ++ibin) {
188  int algosumvalue = 0;
189  for(unsigned int i = 0; i < weights_.size(); i++) {
190  //add up value * scale factor
191  algosumvalue += int(samples[ibin+i] * weights_[i]);
192  }
193  if (algosumvalue<0) sum[ibin]=0; // low-side
194  //high-side
195  //else if (algosumvalue>0x3FF) sum[ibin]=0x3FF;
196  else sum[ibin] = algosumvalue; //assign value to sum[]
197  }
198 
200  output.setPresamples(numberOfPresamples_);
201 
202  // Align digis and TP
203  int shift = samples.presamples() - numberOfPresamples_;
204  if (peakfind_) {
205  assert (shift >= (peakfind_ ? shrink : 0));
206  assert(shift + numberOfSamples_ + shrink <= samples.size() - (peak_finder_algorithm_ - 1));
207  }
208 
209 
210  for (int ibin = 0; ibin < numberOfSamples_; ++ibin) {
211  // ibin - index for output TP
212  // idx - index for samples + shift
213  int idx = ibin + shift;
214 
215  //Peak finding
216  if (peakfind_) {
217  bool isPeak = false;
218  switch (peak_finder_algorithm_) {
219  case 1 :
220  isPeak = (samples[idx] > samples[idx-1] && samples[idx] >= samples[idx+1] && samples[idx] > theThreshold);
221  break;
222  case 2:
223  isPeak = (sum[idx] > sum[idx-1] && sum[idx] >= sum[idx+1] && sum[idx] > theThreshold);
224  break;
225  default:
226  break;
227  }
228 
229  if (isPeak){
230  output[ibin] = std::min<unsigned int>(sum[idx],0x3FF);
231  finegrain[ibin] = msb[idx];
232  }
233  // Not a peak
234  else output[ibin] = 0;
235  }
236  else { // No peak finding, just output running sum
237  output[ibin] = std::min<unsigned int>(sum[idx],0x3FF);
238  finegrain[ibin] = msb[idx];
239  }
240 
241  // Only Pegged for 1-TS algo.
242  if (peak_finder_algorithm_ == 1) {
243  if (samples[idx] >= 0x3FF)
244  output[ibin] = 0x3FF;
245  }
246  outcoder_->compress(output, finegrain, result);
247  }
248 }
249 
250 
252  std::vector<bool> finegrain(numberOfSamples_, false);
253  HcalTrigTowerDetId detId(samples.id());
254 
255  // Align digis and TP
256  int shift = samples.presamples() - numberOfPresamples_;
257  assert(shift >= 0);
258  assert((shift + numberOfSamples_) <= samples.size());
259 
260  TowerMapFGSum::const_iterator tower2fg = theTowerMapFGSum.find(detId);
261  assert(tower2fg != theTowerMapFGSum.end());
262 
263  const SumFGContainer& sumFG = tower2fg->second;
264  // Loop over all L+S pairs that mapped from samples.id()
265  // Note: 1 samples.id() = 6 x (L+S) without noZS
266  for (SumFGContainer::const_iterator sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
267  const std::vector<bool>& veto = HF_Veto[sumFGItr->id().rawId()];
268  for (int ibin = 0; ibin < numberOfSamples_; ++ibin) {
269  int idx = ibin + shift;
270  // if not vetod, add L+S to total sum and calculate FG
271  if (!(veto[idx] && (*sumFGItr)[idx] > PMT_NoiseThreshold_)) {
272  samples[idx] += (*sumFGItr)[idx];
273  finegrain[ibin] = (finegrain[ibin] || (*sumFGItr)[idx] >= FG_threshold_);
274  }
275  }
276  }
277 
279  output.setPresamples(numberOfPresamples_);
280 
281  for (int ibin = 0; ibin < numberOfSamples_; ++ibin) {
282  int idx = ibin + shift;
283  output[ibin] = samples[idx] / (rctlsb == 0.25 ? 4 : 8);
284  if (output[ibin] > 0x3FF) output[ibin] = 0x3FF;
285  }
286  outcoder_->compress(output, finegrain, result);
287 }
288 
290  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
291  bool ZS = true;
292  for (int i=0; i<tp->size(); ++i) {
293  if (tp->sample(i).compressedEt() > ZS_threshold_I_) {
294  ZS=false;
295  break;
296  }
297  }
298  if (ZS) tp->setZSInfo(false,true);
299  else tp->setZSInfo(true,false);
300  }
301 }
302 
304  const HcalElectronicsMap *emap,
306  ){
307  std::set<uint32_t> FrontEndErrors;
308 
310  const FEDRawData& raw = rawraw->FEDData(i);
311  if (raw.size()<12) continue;
312  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
313  if(!dccHeader) continue;
314  HcalHTRData htr;
315  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
316  if (!dccHeader->getSpigotPresent(spigot)) continue;
317  dccHeader->getSpigotData(spigot,htr,raw.size());
318  int dccid = dccHeader->getSourceId();
319  int errWord = htr.getErrorsWord() & 0x1FFFF;
320  bool HTRError = (!htr.check() || htr.isHistogramEvent() || (errWord & 0x800)!=0);
321 
322  if(HTRError) {
323  bool valid =false;
324  for(int fchan=0; fchan<3 && !valid; fchan++) {
325  for(int fib=0; fib<9 && !valid; fib++) {
326  HcalElectronicsId eid(fchan,fib,spigot,dccid-FEDNumbering::MINHCALFEDID);
327  eid.setHTR(htr.readoutVMECrateId(),htr.htrSlot(),htr.htrTopBottom());
328  DetId detId = emap->lookup(eid);
329  if(detId.null()) continue;
330  HcalSubdetector subdet=(HcalSubdetector(detId.subdetId()));
331  if (detId.det()!=4||
332  (subdet!=HcalBarrel && subdet!=HcalEndcap &&
333  subdet!=HcalForward )) continue;
334  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(detId);
335  for (std::vector<HcalTrigTowerDetId>::const_iterator triggerId=ids.begin(); triggerId != ids.end(); ++triggerId) {
336  FrontEndErrors.insert(triggerId->rawId());
337  }
338  //valid = true;
339  }
340  }
341  }
342  }
343  }
344 
345  // Loop over TP collection
346  // Set TP to zero if there is FE Format Error
347  HcalTriggerPrimitiveSample zeroSample(0);
348  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
349  if (FrontEndErrors.find(tp->id().rawId()) != FrontEndErrors.end()) {
350  for (int i=0; i<tp->size(); ++i) tp->setSample(i, zeroSample);
351  }
352  }
353 }
354 
355 void HcalTriggerPrimitiveAlgo::addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb){
356  FGbitMap::iterator itr = fgMap_.find(id);
357  if (itr != fgMap_.end()){
358  std::vector<bool>& _msb = itr->second;
359  for (size_t i=0; i<msb.size(); ++i)
360  _msb[i] = _msb[i] || msb[i];
361  }
362  else fgMap_[id] = msb;
363 }
364 
366  if (algo <=0 && algo>2)
367  throw cms::Exception("ERROR: Only algo 1 & 2 are supported.") << std::endl;
368  peak_finder_algorithm_ = algo;
369 }
void analyze(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result)
adds the actual RecHits
int i
Definition: DBlmapReader.cc:9
void runFEFormatError(const FEDRawDataCollection *rawraw, const HcalElectronicsMap *emap, HcalTrigPrimDigiCollection &result)
int presamples() const
access presample information
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
std::vector< HcalTrigTowerDetId > towerIds(const HcalDetId &cellId) const
the mapping to and from DetIds
const double w
Definition: UKUtility.cc:23
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
Definition: HcalHTRData.cc:342
int size() const
total number of samples in the digi
Definition: HBHEDataFrame.h:26
std::vector< HBHEDataFrame >::const_iterator const_iterator
void push_back(T const &t)
const HcalTPGCompressor * outcoder_
void setPresamples(int pre)
set presample information
void addFG(const HcalTrigTowerDetId &id, std::vector< bool > &msb)
void run(const HcalTPGCoder *incoder, const HcalTPGCompressor *outcoder, const HBHEDigiCollection &hbheDigis, const HFDigiCollection &hfDigis, HcalTrigPrimDigiCollection &result, const HcalTrigTowerGeometry *trigTowerGeometry, float rctlsb)
void analyzeHF(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, float rctlsb)
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::vector< IntegerCaloSamples > SumFGContainer
int size() const
get the size
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
Definition: HcalHTRData.cc:338
int depth() const
get the tower depth
Definition: HcalDetId.h:40
const HcalTrigTowerGeometry * theTrigTowerGeometry
void lookupMSB(const HBHEDataFrame &df, std::vector< bool > &msb) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
tuple result
Definition: query.py:137
HcalSubdetector
Definition: HcalAssistant.h:31
HcalTriggerPrimitiveAlgo(bool pf, const std::vector< double > &w, int latency, uint32_t FG_threshold, uint32_t ZS_threshold, int numberOfSamples, int numberOfPresamples, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
std::vector< double > weights_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
Definition: HBHEDataFrame.h:28
void runZS(HcalTrigPrimDigiCollection &tp)
std::vector< HcalTriggerPrimitiveDigi >::iterator iterator
const_iterator end() const
int getSourceId() const
Definition: HcalDCCHeader.h:32
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
int size() const
total number of samples in the digi
Definition: HFDataFrame.h:26
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned int getErrorsWord() const
Get the errors word.
Definition: HcalHTRData.h:156
bool null() const
is this a null id ?
Definition: DetId.h:45
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
Definition: HcalHTRData.cc:346
const HcaluLUTTPGCoder * incoder_
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
static unsigned int const shift
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
virtual void adc2Linear(const HBHEDataFrame &df, IntegerCaloSamples &ics) const
void compress(const IntegerCaloSamples &ics, const std::vector< bool > &fineGrain, HcalTriggerPrimitiveDigi &digi) const
int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
Definition: HFDataFrame.h:28
const HcalDetId & id() const
Definition: HFDataFrame.h:22
DetId id() const
get the (generic) id
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Readout chain identification for Hcal.
void addSignal(const HBHEDataFrame &frame)
adds the signal to the map
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
const_iterator begin() const
const_reference back() const