CMS 3D CMS Logo

DTTSS.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTSS.cpp
4 //
5 // Description: Implementation of DTTSS trigger algorithm
6 //
7 //
8 // Author List:
9 // C. Grandi
10 // Modifications:
11 // 04/01/2007 : C. Battilana local config update
12 //
13 //
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
20 
21 //-------------------------------
22 // Collaborating Class Headers --
23 //-------------------------------
26 
27 //---------------
28 // C++ Headers --
29 //---------------
30 #include <algorithm>
31 #include <iostream>
32 
33 //----------------
34 // Constructors --
35 //----------------
36 DTTSS::DTTSS(int n) : _n(n), _ignoreSecondTrack(0) {
37  // reserve the appropriate amount of space for vectors
38  //_tctrig[0].reserve(DTConfigTSPhi::NTCTSS);
39  //_tctrig[1].reserve(DTConfigTSPhi::NTCTSS);
40  //_outcand.reserve(2);
41  _logWord1 = "1/----";
42  _logWord2 = "2/----";
43 }
44 
45 //--------------
46 // Destructor --
47 //--------------
49 
50 //--------------
51 // Operations --
52 //--------------
53 
54 void DTTSS::clear() {
56  for (int itk = 0; itk <= 1; itk++) {
57  // content of _tctrig is deleted in the DTTSPhi
58  _tctrig[itk].clear();
59  }
60  // content of _outcand is deleted in the DTTSPhi
61  _outcand.clear();
62 
63  // log words
64  _logWord1 = "1/----";
65  _logWord2 = "2/----";
66 }
67 
68 void DTTSS::run() {
69  if (config()->debug()) {
70  std::cout << "DTTSS::run: Processing DTTSS number " << _n << " : ";
71  std::cout << nFirstT() << " first & " << nSecondT() << " second tracks" << std::endl;
72  }
73 
74  if (nFirstT() < 1)
75  return; // skip if no first tracks
76  //
77  // SORT 1
78  //
79  // debugging
80  if (config()->debug()) {
81  std::cout << "Vector of first tracks in DTTSS: " << std::endl;
82  std::vector<DTTSCand *>::const_iterator p;
83  for (p = _tctrig[0].begin(); p != _tctrig[0].end(); p++) {
84  (*p)->print();
85  }
86  }
87  // end debugging
88 
89  DTTSCand *first = sortTSS1();
90  if (first != nullptr) {
91  _outcand.push_back(first);
92  }
93 
94  if (nSecondT() < 1)
95  return; // skip if no second tracks
96  //
97  // SORT 2
98  //
99  // debugging
100  if (config()->debug()) {
101  std::vector<DTTSCand *>::const_iterator p;
102  std::cout << "Vector of second tracks (including carry) in DTTSS: " << std::endl;
103  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++) {
104  (*p)->print();
105  }
106  }
107  // end debugging
108 
109  DTTSCand *second = sortTSS2();
110  if (second != nullptr) {
111  _outcand.push_back(second);
112  }
113 }
114 
116  // Do a sort 1
117  DTTSCand *best = nullptr;
118  DTTSCand *carry = nullptr;
119  std::vector<DTTSCand *>::iterator p;
120  for (p = _tctrig[0].begin(); p != _tctrig[0].end(); p++) {
121  DTTSCand *curr = (*p) ? (*p) : nullptr;
122  if (curr == nullptr)
123  continue;
124  // SM sector collector Set bits for tss
125  curr->setBitsTss();
126  if (curr->dataword() == 0x1ff)
127  continue;
128  _logWord1[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
129  // std::cout << "Running TSS: --->curr->dataword() sort 1 " <<
130  // curr->dataword() << std::endl;
131  if (best == nullptr) {
132  best = curr;
133  } else if ((*curr) <= (*best)) {
134  carry = best;
135  best = curr;
136  } else if (carry == nullptr) {
137  carry = curr;
138  } else if ((*curr) <= (*carry)) {
139  carry = curr;
140  }
141  }
142 
143  // Ghost 1 suppression: use carry only if not suppressed
144 
145  if (carry != nullptr) { // A carry is present
146 
147  // Carry enabled if correlated and TRACO is next to best
148  bool inner_or_corr;
149  if (config()->TssGhost1Corr()) {
150  inner_or_corr = carry->isInner() || carry->isCorr();
151 
152  } else {
153  inner_or_corr = carry->isInner();
154  }
155  if (config()->TssGhost1Flag() < 2 && ( // Carry isn't always suppressed
156  config()->TssGhost1Flag() == 0 || // Carry always enabled
157  // carry->isInner() || // Carry is inner
158  inner_or_corr || // carry is inner or corr
159  abs(carry->TcPos() - best->TcPos()) != 1) // Carry not adj. to best
160  ) {
161  // add carry to second tracks for sort 2
162  carry->setSecondTrack(); // change value of first/second track bit
163  carry->setBitsTss(); // set quality bits as for second tracks
164  _tctrig[1].push_back(carry); // add to list of second tracks
165  } else {
166  _logWord1[1 + carry->TcPos()] = 'g';
167  }
168  }
169 
170  /*
171  if(carry!=0 && config()->TssGhost1Flag()<2){ // Carry isn't always suppressed
172  if(config()->TssGhost1Flag()==0 || // Carry always enabled
173  carry->isInner() || // Carry is inner
174  abs(carry->TcPos()-best->TcPos())!=1) { // Carry not adj. to best
175  // add carry to second tracks to for sort 2
176  carry->setSecondTrack(); // change value of first/second track bit
177  carry->setBitsTss(); // set quality bits as for second tracks
178  _tctrig[1].push_back(carry); // add to list of second tracks
179  }
180  }
181  */
182  // std::cout << " best TSS sort 1 = " << best->dataword() << std::endl;
183  // std::cout << " SM end of TSS sort 1: best = " << std::endl;
184  // best->print();
185 
186  return best;
187 }
188 
190  // Check if there are second tracks
191  if (nTracks() < 1) {
192  std::cout << "DTTSS::DTTSSsort2: called with no first track.";
193  std::cout << " empty pointer returned!" << std::endl;
194  return nullptr;
195  }
196 
197  if (_ignoreSecondTrack) {
198  // At the time being if a a first track at the following BX is present,
199  // the carry is thrown
200  // std::vector<DTTSCand*>::iterator p;
201  // for(p=_tctrig[1].begin(); p!=_tctrig[1].end(); p++) {
202  // if((*p)->isCarry()) return (*p);
203  // }
204  // Fill log word
205  std::vector<DTTSCand *>::iterator p;
206  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
207  if (!(*p)->isCarry())
208  _logWord2[1 + (*p)->TcPos()] = 'o'; // out of time
209  return nullptr;
210  }
211 
212  // If second tracks are always suppressed skip processing
213  if (config()->TssGhost2Flag() == 3) {
214  // Fill log word
215  std::vector<DTTSCand *>::iterator p;
216  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
217  _logWord2[1 + (*p)->TcPos()] = 'G';
218  return nullptr;
219  }
220 
221  // If no first tracks at the following BX, do a sort 2
222  DTTSCand *best = getTrack(1);
223  DTTSCand *second = nullptr;
224  std::vector<DTTSCand *>::iterator p;
225  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++) {
226  DTTSCand *curr = (*p);
227  // SM sector collector set bits for tss
228  curr->setBitsTss();
229  // std::cout << "Running TSS sort 2: --- curr->dataword() " <<
230  // curr->dataword() << std::endl;
231  if (!curr->isCarry()) {
232  _logWord2[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
233  if (curr->dataword() == 0x1ff)
234  continue;
235  }
236  // ghost 2 suppression: skip track if suppressed
237  if (config()->TssGhost2Flag() != 0) { // 2nd tracks not always enabled
238 
239  bool inner_or_corr;
240  if (config()->TssGhost2Corr()) {
241  inner_or_corr = curr->isInner() || curr->isCorr();
242 
243  } else {
244  inner_or_corr = curr->isInner();
245  }
246 
247  if (
249  !inner_or_corr && // outer and not corr
250  curr->TcPos() == best->TcPos()) { // same correlator of 1st track
251  if (config()->TssGhost2Flag() == 2 || // do not look to corr bit of 1st
252  ((!best->isCorr()) && config()->TssGhost2Flag() != 4) || // skip if best is not corr
253  ((!best->isCorr()) && best->isInner() &&
254  config()->TssGhost2Flag() == 4)) // skip only if best is inner and not corr
255  {
256  _logWord2[1 + curr->TcPos()] = 'G';
257  // std::cout << " skip sort 2 in TSS" << std::endl;
258  continue; // skip track
259  }
260  }
261  }
262  if (second == nullptr) {
263  second = curr;
264  } else if ((*curr) <= (*second)) {
265  second = curr;
266  }
267  }
268  // if(!second==0) {std::cout << " best sort 2 = " << second->dataword() <<
269  // std::endl;
270  // std::cout << " SM end of TSS sort 2: second = " << std::endl;
271  // second->print(); }
272 
273  return second;
274 }
275 
277  int ifs = (cand->isFirst()) ? 0 : 1;
278  // std::cout << "SM DTTSS::addDTTSCand ifs = " << ifs << std::endl;
279  _tctrig[ifs].push_back(cand);
280 }
281 
282 unsigned DTTSS::nTracoT(int ifs) const {
283  if (ifs < 1 || ifs > 2) {
284  std::cout << "DTTSS::nTracoT: wrong track number: " << ifs;
285  std::cout << " 0 returned!" << std::endl;
286  return 0;
287  }
288  return _tctrig[ifs - 1].size();
289 }
290 
291 DTTSCand *DTTSS::getDTTSCand(int ifs, unsigned n) const {
292  if (ifs < 1 || ifs > 2) {
293  std::cout << "DTTSS::getDTTSCand: wrong track number: " << ifs;
294  std::cout << " empty pointer returned!" << std::endl;
295  return nullptr;
296  }
297  if (n < 1 || n > nTracoT(ifs)) {
298  std::cout << "DTTSS::getDTTSCand: requested trigger not present: " << n;
299  std::cout << " empty pointer returned!" << std::endl;
300  return nullptr;
301  }
302  std::vector<DTTSCand *>::const_iterator p = _tctrig[ifs - 1].begin() + n - 1;
303  return (*p);
304 }
305 
306 const DTTracoTrigData *DTTSS::getTracoT(int ifs, unsigned n) const {
307  if (ifs < 1 || ifs > 2) {
308  std::cout << "DTTSS::getTracoT: wrong track number: " << ifs;
309  std::cout << " empty pointer returned!" << std::endl;
310  return nullptr;
311  }
312  if (n < 1 || n > nTracoT(ifs)) {
313  std::cout << "DTTSS::getTracoT: requested trigger not present: " << n;
314  std::cout << " empty pointer returned!" << std::endl;
315  return nullptr;
316  }
317  return getDTTSCand(ifs, n)->tracoTr();
318 }
319 
321  if (n < 1 || n > nTracks()) {
322  std::cout << "DTTSS::getTrack: requested track not present: " << n;
323  std::cout << " empty pointer returned!" << std::endl;
324  return nullptr;
325  }
326  std::vector<DTTSCand *>::const_iterator p = _outcand.begin() + n - 1;
327  return (*p);
328 }
329 
331  std::vector<DTTSCand *>::const_iterator p;
332  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
333  if ((*p)->isCarry())
334  return (*p);
335  return nullptr;
336 }
337 
339  std::string lw = "";
340  switch (n) {
341  case 1:
342  lw = _logWord1;
343  break;
344  case 2:
345  lw = _logWord2;
346  break;
347  default:
348  std::cout << "DTTSS::logWord: requested track not present: " << n;
349  std::cout << " empty string returned!" << std::endl;
350  }
351  return lw;
352 }
std::string _logWord2
Definition: DTTSS.h:115
void setBitsTss()
Set the quality bits for DTTSS analysis.
Definition: DTTSCand.cc:78
unsigned nTracoT(int ifs) const
Return the number of input tracks (first/second)
Definition: DTTSS.cc:282
std::vector< DTTSCand * > _tctrig[2]
Definition: DTTSS.h:105
DTTSS(int)
Constructor.
Definition: DTTSS.cc:36
int _n
Definition: DTTSS.h:102
void addDTTSCand(DTTSCand *cand)
Add a TS candidate to the TSS, ifs is first/second track flag.
Definition: DTTSS.cc:276
bool TssGhost2Corr() const
Correlated ghost 2 suppression option in TSS.
const DTConfigTSPhi * config() const
Configuration set.
Definition: DTTSS.h:69
DTTSCand * getCarry() const
Return the carry (for debugging)
Definition: DTTSS.cc:330
int _ignoreSecondTrack
Definition: DTTSS.h:111
U second(std::pair< T, U > const &p)
const DTTracoTrigData * getTracoT(int ifs, unsigned n) const
Return requested TRACO trigger.
Definition: DTTSS.cc:306
int isInner() const
Return Inner/Outer bit.
Definition: DTTSCand.h:104
const DTTracoTrigData * tracoTr() const
Return associated TRACO trigger.
Definition: DTTSCand.h:84
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int nSecondT() const
Return the number of input second tracks.
Definition: DTTSS.h:78
DTTSCand * sortTSS2()
Sort 2.
Definition: DTTSS.cc:189
std::vector< DTTSCand * > _outcand
Definition: DTTSS.h:108
int isCorr() const
Return correlation bit.
Definition: DTTSCand.h:107
DTTSCand * sortTSS1()
Sort 1.
Definition: DTTSS.cc:115
std::string _logWord1
Definition: DTTSS.h:114
int isCarry() const
Return the carry bit.
Definition: DTTSCand.h:110
DTTSCand * getDTTSCand(int ifs, unsigned n) const
Return requested TS candidate.
Definition: DTTSS.cc:291
#define debug
Definition: HDRShower.cc:19
std::string logWord(int n) const
Return the requested log word.
Definition: DTTSS.cc:338
unsigned dataword() const
Return an uint16 with the content of the data word (for debugging)
Definition: DTTSCand.h:132
~DTTSS()
Destructor.
Definition: DTTSS.cc:48
DTTSCand * getTrack(int n) const
Return the requested track.
Definition: DTTSS.cc:320
int nTracks() const
Return the number of sorted tracks.
Definition: DTTSS.h:90
void setSecondTrack()
Set the first track bit to second track (used for carry)
Definition: DTTSCand.h:63
int isFirst() const
Return the first/second track bit.
Definition: DTTSCand.h:99
int TssGhost2Flag() const
Ghost 2 suppression option in TSS.
bool TssGhost1Corr() const
Correlated ghost 1 suppression option in TSS.
int TcPos() const
Retrun the TRACO position inside the TSS.
Definition: DTTSCand.h:87
void run()
Run the TSS algorithm.
Definition: DTTSS.cc:68
int nFirstT() const
Return the number of input first tracks.
Definition: DTTSS.h:75
void clear()
Clear.
Definition: DTTSS.cc:54