CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTTPDigiProducer.cc
Go to the documentation of this file.
2 
11 #include <cstdio>
12 
13 // DO NOT MODIFY: Mapping between iphi (array index) and TTP input (value) for HF
14 const int HcalTTPDigiProducer::inputs_[] = { 30,66,4,44,4,44,0,68,
15  0,68,16,48,16,48,6,46,
16  6,46,2,70,2,70,18,50,
17  18,50,12,40,12,40,8,52,
18  8,52,20,36,20,36,14,42,
19  14,42,10,54,10,54,22,38,
20  22,38,24,56,24,56,32,60,
21  32,60,28,64,28,64,26,58,
22  26,58,34,62,34,62,30,66 } ;
23 
25 {
26  hfDigis_ = ps.getParameter<edm::InputTag>("HFDigiCollection") ;
27  maskedChannels_ = ps.getParameter< std::vector<unsigned int> >("maskedChannels") ;
28  bit_[0] = ps.getParameter<std::string>("defTT8") ;
29  bit_[1] = ps.getParameter<std::string>("defTT9") ;
30  bit_[2] = ps.getParameter<std::string>("defTT10") ;
31  bit_[3] = ps.getParameter<std::string>("defTTLocal") ;
32 
33  for (int i=0; i<4; i++) {
34  nHits_[i] = -1 ; nHFp_[i] = -1 ; nHFm_[i] = -1 ;
35  pReq_[i] = ' ' ; mReq_[i] = ' ' ; pmLogic_[i] = ' ' ;
36  calc_[i] = sscanf(bit_[i].c_str(),"hits>=%d:hfp%c=%d%chfm%c=%d",
37  &(nHits_[i]),&(pReq_[i]),&(nHFp_[i]),
38  &(pmLogic_[i]),&(mReq_[i]),&(nHFm_[i])) ;
39  if ( calc_[i] == 1 ) {
40  if ( nHits_[i] < 0 )
41  throw cms::Exception("HcalTTPDigiProducer")
42  << "Unable to read logic for technical trigger" ;
43  } else if ( calc_[i] == 6 ) {
44  if ( nHits_[i] < 0 || nHFp_[i] < 0 || nHFm_[i] < 0 )
45  throw cms::Exception("HcalTTPDigiProducer")
46  << "Unable to read logic for technical trigger" ;
47  if ( (pReq_[i] != '>' && pReq_[i] != '<') ||
48  (mReq_[i] != '>' && mReq_[i] != '<') ||
49  (pmLogic_[i] != ':' && pmLogic_[i] != '|') )
50  throw cms::Exception("HcalTTPDigiProducer")
51  << "Technical Trigger logic must obey the following format:\n"
52  "\"hits>=[A1]:hfp[B1]=[A2][C]hfm[B2]=[A3]\",\n"
53  "or \"hits>=[A1]\",\n"
54  "with A# >= 0, B# = (</>) and C = (:/|)" ;
55  } else {
56  throw cms::Exception("HcalTTPDigiProducer")
57  << "Unable to read logic for technical trigger" ;
58  }
59  }
60 
61  id_ = ps.getUntrackedParameter<int>("id",-1) ;
62  samples_ = ps.getParameter<int>("samples") ;
63  presamples_ = ps.getParameter<int>("presamples") ;
64  iEtaMin_ = ps.getParameter<int>("iEtaMin") ;
65  iEtaMax_ = ps.getParameter<int>("iEtaMax") ;
66  threshold_ = ps.getParameter<unsigned int>("threshold") ;
67  fwAlgo_ = ps.getParameter<int>("fwAlgorithm") ;
68 
69  SoI_ = ps.getParameter<int>("HFSoI") ;
70 
71  if ( samples_ > 8 ) {
72  samples_ = 8 ;
73  edm::LogWarning("HcalTTPDigiProducer") << "Samples forced to maximum value of 8" ;
74  }
75  if ( presamples_ - SoI_ > 0 ) { // Too many presamples
76  presamples_ = SoI_ ;
77  edm::LogWarning("HcalTTPDigiProducer") << "Presamples reset to HF SoI value" ;
78  }
79 
80  for (unsigned int i=0; i<maskedChannels_.size(); i++) {
81  HcalDetId id(maskedChannels_.at(i)) ;
82  if ( !id.validDetId(HcalForward,id.ieta(),id.iphi(),id.depth()) )
83  throw cms::Exception("HcalTTPDigiProducer") << "Invalid HCAL Det ID" ;
84  }
85 
86  produces<HcalTTPDigiCollection>();
87 }
88 
89 
91 }
92 
94 
95  for ( unsigned int i=0; i<maskedChannels_.size(); i++ )
96  if ( id.rawId() == maskedChannels_.at(i) ) return true ;
97  return false ;
98 }
99 
100 bool HcalTTPDigiProducer::decision(int nP, int nM, int bit) {
101 
102  bool pOK = false ; bool mOK = false ;
103  if ( (nP + nM) < nHits_[bit] ) return false ;
104  if ( calc_[bit] == 1 ) return ( (nP + nM) >= nHits_[bit] ) ;
105 
106  if ( pReq_[bit] == '>' ) pOK = ( nP >= nHFp_[bit] ) ;
107  else if ( pReq_[bit] == '<' ) pOK = ( nP <= nHFp_[bit] ) ;
108 
109  if ( mReq_[bit] == '>' ) mOK = ( nM >= nHFm_[bit] ) ;
110  else if ( mReq_[bit] == '<' ) mOK = ( nM <= nHFm_[bit] ) ;
111 
112  if ( pmLogic_[bit] == ':' ) return ( pOK && mOK ) ;
113  else if ( pmLogic_[bit] == '|' ) return ( pOK || mOK ) ;
114 
115  // Should not ever get here...need to create a warning message
116  edm::LogWarning("HcalTTPDigiProducer") << "Trigger logic exhausted. Returning false" ;
117  return false ;
118 }
119 
121 
122  // Step A: Get Inputs
123  edm::Handle<HFDigiCollection> hfDigiCollection ;
124  e.getByLabel(hfDigis_,hfDigiCollection) ;
125  edm::ESHandle<HcalTPGCoder> inputCoder ;
126  eventSetup.get<HcalTPGRecord>().get(inputCoder) ;
127 
128  // Step B: Create empty output
129  std::auto_ptr<HcalTTPDigiCollection> ttpResult(new HcalTTPDigiCollection()) ;
130 
131  // Step C: Compute TTP inputs
132  uint16_t trigInputs[40] ;
133  int nP[8] ; int nM[8] ;
134  for (int i=0; i<8; i++) {
135  nP[i] = 0 ; nM[i] = 0 ;
136  for (int j=0; j<5; j++) trigInputs[j*8+i] = 0 ;
137  }
138  for (HFDigiCollection::const_iterator theDigi=hfDigiCollection->begin();
139  theDigi!=hfDigiCollection->end(); theDigi++) {
140  HcalDetId id = HcalDetId(theDigi->id()) ;
141  if ( isMasked(id) ) continue ;
142  if ( id.ietaAbs() < iEtaMin_ || id.ietaAbs() > iEtaMax_ ) continue ;
143 
144  IntegerCaloSamples samples(id,theDigi->size()) ;
145  inputCoder->adc2Linear(*theDigi,samples) ;
146 
147  for (int relSample=-presamples_; relSample<(samples_-presamples_); relSample++) {
148  if ( samples[SoI_+relSample] >= threshold_ ) {
149  int linSample = presamples_ + relSample ;
150  int offset = (-1+id.zside())/2 ;
151  int shift = inputs_[id.iphi()+offset] ;
152  int group = 0 ;
153  while ( shift >= 16 ) { shift -= 16 ; group++ ; }
154  if ( !(trigInputs[(linSample*8)+group]&(1<<shift)) )
155  ( id.ieta() > 0 ) ? ( nP[linSample]++) : ( nM[linSample]++ ) ;
156  trigInputs[(linSample*8)+group] |= (1<<shift) ;
157  }
158  }
159  }
160 
161  // Step D: Compute trigger decision and fill TTP digi
162  uint8_t trigOutput[8] ;
163  uint32_t algoDepBits[8] ;
165  for (int linSample=0; linSample<8; linSample++) {
166  trigOutput[linSample] = 0 ; algoDepBits[linSample] = 0 ;
167  if ( linSample<samples_) {
168  for (int j=0; j<4; j++)
169  trigOutput[linSample] |= (decision(nP[linSample],nM[linSample],j)<<j) ;
170  int nT = nP[linSample] + nM[linSample] ;
171 
172  // Algorithm Dependent bits for FW flavor = 1
173  // NOTE: this disagrees with the fw var. names that implies (LSB) T,M,P (MSB)
174  if ( fwAlgo_ == 1 ) algoDepBits[linSample] = (nT&0x7F) | ((nP[linSample]&0x3F)<<7) | ((nM[linSample]&0x3F)<<13) ;
175  ttpDigi.setSample((linSample-presamples_),&trigInputs[linSample*8],algoDepBits[linSample],trigOutput[linSample]) ;
176  }
177  }
178  ttpResult->push_back( ttpDigi ) ;
179 
180  // Step E: Put outputs into event
181  e.put(ttpResult);
182 }
183 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &e, const edm::EventSetup &c)
std::vector< T >::const_iterator const_iterator
std::vector< unsigned int > maskedChannels_
bool isMasked(HcalDetId id)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
static const int inputs_[]
int j
Definition: DBlmapReader.cc:9
void setSample(int relativeSample, const uint16_t *triggerInputs, const uint32_t algodep, const uint8_t outputTrigger)
Definition: HcalTTPDigi.cc:24
bool decision(int nP, int nM, int bit)
unsigned int offset(bool)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const T & get() const
Definition: EventSetup.h:55
edm::SortedCollection< HcalTTPDigi > HcalTTPDigiCollection
static unsigned int const shift
HcalTTPDigiProducer(const edm::ParameterSet &ps)
bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)