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  int numberOfSamplesHF, int numberOfPresamplesHF,
19  uint32_t minSignalThreshold, uint32_t PMT_NoiseThreshold)
20  : incoder_(0), outcoder_(0),
21  theThreshold(0), peakfind_(pf), weights_(w), latency_(latency),
22  FG_threshold_(FG_threshold), ZS_threshold_(ZS_threshold),
23  numberOfSamples_(numberOfSamples),
24  numberOfPresamples_(numberOfPresamples),
25  numberOfSamplesHF_(numberOfSamplesHF),
26  numberOfPresamplesHF_(numberOfPresamplesHF),
27  minSignalThreshold_(minSignalThreshold),
28  PMT_NoiseThreshold_(PMT_NoiseThreshold),
29  peak_finder_algorithm_(2)
30 {
31  //No peak finding setting (for Fastsim)
32  if (!peakfind_){
33  numberOfSamples_ = 1;
35  numberOfSamplesHF_ = 1;
37  }
38  // Switch to integer for comparisons - remove compiler warning
40 }
41 
42 
44 }
45 
46 
48  const HcalTPGCompressor* outcoder,
49  const HBHEDigiCollection& hbheDigis,
50  const HFDigiCollection& hfDigis,
52  const HcalTrigTowerGeometry* trigTowerGeometry,
53  float rctlsb) {
54  theTrigTowerGeometry = trigTowerGeometry;
55 
56  incoder_=dynamic_cast<const HcaluLUTTPGCoder*>(incoder);
57  outcoder_=outcoder;
58 
59  theSumMap.clear();
60  theTowerMapFGSum.clear();
61  HF_Veto.clear();
62  fgMap_.clear();
63 
64  // do the HB/HE digis
65  for(HBHEDigiCollection::const_iterator hbheItr = hbheDigis.begin();
66  hbheItr != hbheDigis.end(); ++hbheItr) {
67  addSignal(*hbheItr);
68  }
69 
70  // and the HF digis
71  for(HFDigiCollection::const_iterator hfItr = hfDigis.begin();
72  hfItr != hfDigis.end(); ++hfItr) {
73  addSignal(*hfItr);
74 
75  }
76 
77  for(SumMap::iterator mapItr = theSumMap.begin(); mapItr != theSumMap.end(); ++mapItr) {
78  result.push_back(HcalTriggerPrimitiveDigi(mapItr->first));
79  HcalTrigTowerDetId detId(mapItr->second.id());
80  if(detId.ietaAbs() >= theTrigTowerGeometry->firstHFTower())
81  { analyzeHF(mapItr->second, result.back(), rctlsb);}
82  else{analyze(mapItr->second, result.back());}
83  }
84  return;
85 }
86 
87 
89  //Hack for 300_pre10, should be removed.
90  if (frame.id().depth()==5) return;
91 
92  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
93  assert(ids.size() == 1 || ids.size() == 2);
94  IntegerCaloSamples samples1(ids[0], int(frame.size()));
95 
96  samples1.setPresamples(frame.presamples());
97  incoder_->adc2Linear(frame, samples1);
98 
99  std::vector<bool> msb;
100  incoder_->lookupMSB(frame, msb);
101 
102  if(ids.size() == 2) {
103  // make a second trigprim for the other one, and split the energy
104  IntegerCaloSamples samples2(ids[1], samples1.size());
105  for(int i = 0; i < samples1.size(); ++i) {
106  samples1[i] = uint32_t(samples1[i]*0.5);
107  samples2[i] = samples1[i];
108  }
109  samples2.setPresamples(frame.presamples());
110  addSignal(samples2);
111  addFG(ids[1], msb);
112  }
113  addSignal(samples1);
114  addFG(ids[0], msb);
115 }
116 
117 
119 
120  if(frame.id().depth() == 1 || frame.id().depth() == 2) {
121  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
122  assert(ids.size() == 1);
123  IntegerCaloSamples samples(ids[0], frame.size());
124  samples.setPresamples(frame.presamples());
125  incoder_->adc2Linear(frame, samples);
126 
127  // Don't add to final collection yet
128  // HF PMT veto sum is calculated in analyzerHF()
129  IntegerCaloSamples zero_samples(ids[0], frame.size());
130  zero_samples.setPresamples(frame.presamples());
131  addSignal(zero_samples);
132 
133  // Mask off depths: fgid is the same for both depths
134  uint32_t fgid = (frame.id().maskDepth());
135 
136  if ( theTowerMapFGSum.find(ids[0]) == theTowerMapFGSum.end() ) {
137  SumFGContainer sumFG;
138  theTowerMapFGSum.insert(std::pair<HcalTrigTowerDetId, SumFGContainer >(ids[0], sumFG));
139  }
140 
141  SumFGContainer& sumFG = theTowerMapFGSum[ids[0]];
142  SumFGContainer::iterator sumFGItr;
143  for ( sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
144  if (sumFGItr->id() == fgid) break;
145  }
146  // If find
147  if (sumFGItr != sumFG.end()) {
148  for (int i=0; i<samples.size(); ++i) (*sumFGItr)[i] += samples[i];
149  }
150  else {
151  //Copy samples (change to fgid)
152  IntegerCaloSamples sumFGSamples(DetId(fgid), samples.size());
153  sumFGSamples.setPresamples(samples.presamples());
154  for (int i=0; i<samples.size(); ++i) sumFGSamples[i] = samples[i];
155  sumFG.push_back(sumFGSamples);
156  }
157 
158  // set veto to true if Long or Short less than threshold
159  if (HF_Veto.find(fgid) == HF_Veto.end()) {
160  vector<bool> vetoBits(samples.size(), false);
161  HF_Veto[fgid] = vetoBits;
162  }
163  for (int i=0; i<samples.size(); ++i)
164  if (samples[i] < minSignalThreshold_)
165  HF_Veto[fgid][i] = true;
166  }
167 }
168 
169 
171  HcalTrigTowerDetId id(samples.id());
172  SumMap::iterator itr = theSumMap.find(id);
173  if(itr == theSumMap.end()) {
174  theSumMap.insert(std::make_pair(id, samples));
175  }
176  else {
177  // wish CaloSamples had a +=
178  for(int i = 0; i < samples.size(); ++i) {
179  (itr->second)[i] += samples[i];
180  }
181  }
182 }
183 
184 
186  int shrink = weights_.size() - 1;
187  std::vector<bool>& msb = fgMap_[samples.id()];
188  IntegerCaloSamples sum(samples.id(), samples.size());
189 
190  //slide algo window
191  for(int ibin = 0; ibin < int(samples.size())- shrink; ++ibin) {
192  int algosumvalue = 0;
193  for(unsigned int i = 0; i < weights_.size(); i++) {
194  //add up value * scale factor
195  algosumvalue += int(samples[ibin+i] * weights_[i]);
196  }
197  if (algosumvalue<0) sum[ibin]=0; // low-side
198  //high-side
199  //else if (algosumvalue>0x3FF) sum[ibin]=0x3FF;
200  else sum[ibin] = algosumvalue; //assign value to sum[]
201  }
202 
203  // Align digis and TP
204  int dgPresamples=samples.presamples();
205  int tpPresamples=numberOfPresamples_;
206  int shift = dgPresamples - tpPresamples;
207  int dgSamples=samples.size();
208  int tpSamples=numberOfSamples_;
209  if(peakfind_){
210  if((shift<shrink) || (shift + tpSamples + shrink > dgSamples - (peak_finder_algorithm_ - 1) ) ){
211  edm::LogInfo("HcalTriggerPrimitiveAlgo::analyze") <<
212  "TP presample or size from the configuration file is out of the accessible range. Using digi values from data instead...";
213  shift=shrink;
214  tpPresamples=dgPresamples-shrink;
215  tpSamples=dgSamples-(peak_finder_algorithm_-1)-shrink-shift;
216  }
217  }
218 
219  std::vector<bool> finegrain(tpSamples,false);
220 
221  IntegerCaloSamples output(samples.id(), tpSamples);
222  output.setPresamples(tpPresamples);
223 
224  for (int ibin = 0; ibin < tpSamples; ++ibin) {
225  // ibin - index for output TP
226  // idx - index for samples + shift
227  int idx = ibin + shift;
228 
229  //Peak finding
230  if (peakfind_) {
231  bool isPeak = false;
232  switch (peak_finder_algorithm_) {
233  case 1 :
234  isPeak = (samples[idx] > samples[idx-1] && samples[idx] >= samples[idx+1] && samples[idx] > theThreshold);
235  break;
236  case 2:
237  isPeak = (sum[idx] > sum[idx-1] && sum[idx] >= sum[idx+1] && sum[idx] > theThreshold);
238  break;
239  default:
240  break;
241  }
242 
243  if (isPeak){
244  output[ibin] = std::min<unsigned int>(sum[idx],0x3FF);
245  finegrain[ibin] = msb[idx];
246  }
247  // Not a peak
248  else output[ibin] = 0;
249  }
250  else { // No peak finding, just output running sum
251  output[ibin] = std::min<unsigned int>(sum[idx],0x3FF);
252  finegrain[ibin] = msb[idx];
253  }
254 
255  // Only Pegged for 1-TS algo.
256  if (peak_finder_algorithm_ == 1) {
257  if (samples[idx] >= 0x3FF)
258  output[ibin] = 0x3FF;
259  }
260  }
261  outcoder_->compress(output, finegrain, result);
262 }
263 
264 
266  HcalTrigTowerDetId detId(samples.id());
267 
268  // Align digis and TP
269  int dgPresamples=samples.presamples();
270  int tpPresamples=numberOfPresamplesHF_;
271  int shift = dgPresamples - tpPresamples;
272  int dgSamples=samples.size();
273  int tpSamples=numberOfSamplesHF_;
274  if(shift<0 || shift+tpSamples>dgSamples){
275  edm::LogInfo("HcalTriggerPrimitiveAlgo::analyzeHF") <<
276  "TP presample or size from the configuration file is out of the accessible range. Using digi values from data instead...";
277  tpPresamples=dgPresamples;
278  shift=0;
279  tpSamples=dgSamples;
280  }
281 
282  std::vector<bool> finegrain(tpSamples, false);
283 
284  TowerMapFGSum::const_iterator tower2fg = theTowerMapFGSum.find(detId);
285  assert(tower2fg != theTowerMapFGSum.end());
286 
287  const SumFGContainer& sumFG = tower2fg->second;
288  // Loop over all L+S pairs that mapped from samples.id()
289  // Note: 1 samples.id() = 6 x (L+S) without noZS
290  for (SumFGContainer::const_iterator sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
291  const std::vector<bool>& veto = HF_Veto[sumFGItr->id().rawId()];
292  for (int ibin = 0; ibin < tpSamples; ++ibin) {
293  int idx = ibin + shift;
294  // if not vetod, add L+S to total sum and calculate FG
295  bool vetoed = idx<int(veto.size()) && veto[idx];
296  if (!(vetoed && (*sumFGItr)[idx] > PMT_NoiseThreshold_)) {
297  samples[idx] += (*sumFGItr)[idx];
298  finegrain[ibin] = (finegrain[ibin] || (*sumFGItr)[idx] >= FG_threshold_);
299  }
300  }
301  }
302 
303  IntegerCaloSamples output(samples.id(), tpSamples);
304  output.setPresamples(tpPresamples);
305 
306  for (int ibin = 0; ibin < tpSamples; ++ibin) {
307  int idx = ibin + shift;
308  output[ibin] = samples[idx] / (rctlsb == 0.25 ? 4 : 8);
309  if (output[ibin] > 0x3FF) output[ibin] = 0x3FF;
310  }
311  outcoder_->compress(output, finegrain, result);
312 }
313 
315  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
316  bool ZS = true;
317  for (int i=0; i<tp->size(); ++i) {
318  if (tp->sample(i).compressedEt() > ZS_threshold_I_) {
319  ZS=false;
320  break;
321  }
322  }
323  if (ZS) tp->setZSInfo(false,true);
324  else tp->setZSInfo(true,false);
325  }
326 }
327 
329  const HcalElectronicsMap *emap,
331  ){
332  std::set<uint32_t> FrontEndErrors;
333 
335  const FEDRawData& raw = rawraw->FEDData(i);
336  if (raw.size()<12) continue;
337  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
338  if(!dccHeader) continue;
339  HcalHTRData htr;
340  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
341  if (!dccHeader->getSpigotPresent(spigot)) continue;
342  dccHeader->getSpigotData(spigot,htr,raw.size());
343  int dccid = dccHeader->getSourceId();
344  int errWord = htr.getErrorsWord() & 0x1FFFF;
345  bool HTRError = (!htr.check() || htr.isHistogramEvent() || (errWord & 0x800)!=0);
346 
347  if(HTRError) {
348  bool valid =false;
349  for(int fchan=0; fchan<3 && !valid; fchan++) {
350  for(int fib=0; fib<9 && !valid; fib++) {
351  HcalElectronicsId eid(fchan,fib,spigot,dccid-FEDNumbering::MINHCALFEDID);
352  eid.setHTR(htr.readoutVMECrateId(),htr.htrSlot(),htr.htrTopBottom());
353  DetId detId = emap->lookup(eid);
354  if(detId.null()) continue;
355  HcalSubdetector subdet=(HcalSubdetector(detId.subdetId()));
356  if (detId.det()!=4||
357  (subdet!=HcalBarrel && subdet!=HcalEndcap &&
358  subdet!=HcalForward )) continue;
359  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(detId);
360  for (std::vector<HcalTrigTowerDetId>::const_iterator triggerId=ids.begin(); triggerId != ids.end(); ++triggerId) {
361  FrontEndErrors.insert(triggerId->rawId());
362  }
363  //valid = true;
364  }
365  }
366  }
367  }
368  }
369 
370  // Loop over TP collection
371  // Set TP to zero if there is FE Format Error
372  HcalTriggerPrimitiveSample zeroSample(0);
373  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
374  if (FrontEndErrors.find(tp->id().rawId()) != FrontEndErrors.end()) {
375  for (int i=0; i<tp->size(); ++i) tp->setSample(i, zeroSample);
376  }
377  }
378 }
379 
380 void HcalTriggerPrimitiveAlgo::addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb){
381  FGbitMap::iterator itr = fgMap_.find(id);
382  if (itr != fgMap_.end()){
383  std::vector<bool>& _msb = itr->second;
384  for (size_t i=0; i<msb.size(); ++i)
385  _msb[i] = _msb[i] || msb[i];
386  }
387  else fgMap_[id] = msb;
388 }
389 
391  if (algo <=0 && algo>2)
392  throw cms::Exception("ERROR: Only algo 1 & 2 are supported.") << std::endl;
394 }
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
HcalTriggerPrimitiveAlgo(bool pf, const std::vector< double > &w, int latency, uint32_t FG_threshold, uint32_t ZS_threshold, int numberOfSamples, int numberOfPresamples, int numberOfSamplesHF, int numberOfPresamplesHF, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
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
assert(m_qm.get())
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
uint32_t maskDepth() const
get the tower depth
Definition: HcalDetId.h:57
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
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:55
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
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:157
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