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