CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  // SM sector collector Set bits for tss
123  curr->setBitsTss();
124  if (curr->dataword() == 0x1ff)
125  continue;
126  _logWord1[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
127  // std::cout << "Running TSS: --->curr->dataword() sort 1 " <<
128  // curr->dataword() << std::endl;
129  if (best == nullptr) {
130  best = curr;
131  } else if ((*curr) <= (*best)) {
132  carry = best;
133  best = curr;
134  } else if (carry == nullptr) {
135  carry = curr;
136  } else if ((*curr) <= (*carry)) {
137  carry = curr;
138  }
139  }
140 
141  // Ghost 1 suppression: use carry only if not suppressed
142 
143  if (carry != nullptr) { // A carry is present
144 
145  // Carry enabled if correlated and TRACO is next to best
146  bool inner_or_corr;
147  if (config()->TssGhost1Corr()) {
148  inner_or_corr = carry->isInner() || carry->isCorr();
149 
150  } else {
151  inner_or_corr = carry->isInner();
152  }
153  if (config()->TssGhost1Flag() < 2 && ( // Carry isn't always suppressed
154  config()->TssGhost1Flag() == 0 || // Carry always enabled
155  // carry->isInner() || // Carry is inner
156  inner_or_corr || // carry is inner or corr
157  abs(carry->TcPos() - best->TcPos()) != 1) // Carry not adj. to best
158  ) {
159  // add carry to second tracks for sort 2
160  carry->setSecondTrack(); // change value of first/second track bit
161  carry->setBitsTss(); // set quality bits as for second tracks
162  _tctrig[1].push_back(carry); // add to list of second tracks
163  } else {
164  _logWord1[1 + carry->TcPos()] = 'g';
165  }
166  }
167 
168  /*
169  if(carry!=0 && config()->TssGhost1Flag()<2){ // Carry isn't always suppressed
170  if(config()->TssGhost1Flag()==0 || // Carry always enabled
171  carry->isInner() || // Carry is inner
172  abs(carry->TcPos()-best->TcPos())!=1) { // Carry not adj. to best
173  // add carry to second tracks to for sort 2
174  carry->setSecondTrack(); // change value of first/second track bit
175  carry->setBitsTss(); // set quality bits as for second tracks
176  _tctrig[1].push_back(carry); // add to list of second tracks
177  }
178  }
179  */
180  // std::cout << " best TSS sort 1 = " << best->dataword() << std::endl;
181  // std::cout << " SM end of TSS sort 1: best = " << std::endl;
182  // best->print();
183 
184  return best;
185 }
186 
188  // Check if there are second tracks
189  if (nTracks() < 1) {
190  std::cout << "DTTSS::DTTSSsort2: called with no first track.";
191  std::cout << " empty pointer returned!" << std::endl;
192  return nullptr;
193  }
194 
195  if (_ignoreSecondTrack) {
196  // At the time being if a a first track at the following BX is present,
197  // the carry is thrown
198  // std::vector<DTTSCand*>::iterator p;
199  // for(p=_tctrig[1].begin(); p!=_tctrig[1].end(); p++) {
200  // if((*p)->isCarry()) return (*p);
201  // }
202  // Fill log word
203  std::vector<DTTSCand *>::iterator p;
204  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
205  if (!(*p)->isCarry())
206  _logWord2[1 + (*p)->TcPos()] = 'o'; // out of time
207  return nullptr;
208  }
209 
210  // If second tracks are always suppressed skip processing
211  if (config()->TssGhost2Flag() == 3) {
212  // Fill log word
213  std::vector<DTTSCand *>::iterator p;
214  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
215  _logWord2[1 + (*p)->TcPos()] = 'G';
216  return nullptr;
217  }
218 
219  // If no first tracks at the following BX, do a sort 2
220  DTTSCand *best = getTrack(1);
221  DTTSCand *second = nullptr;
222  std::vector<DTTSCand *>::iterator p;
223  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++) {
224  DTTSCand *curr = (*p);
225  // SM sector collector set bits for tss
226  curr->setBitsTss();
227  // std::cout << "Running TSS sort 2: --- curr->dataword() " <<
228  // curr->dataword() << std::endl;
229  if (!curr->isCarry()) {
230  _logWord2[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
231  if (curr->dataword() == 0x1ff)
232  continue;
233  }
234  // ghost 2 suppression: skip track if suppressed
235  if (config()->TssGhost2Flag() != 0) { // 2nd tracks not always enabled
236 
237  bool inner_or_corr;
238  if (config()->TssGhost2Corr()) {
239  inner_or_corr = curr->isInner() || curr->isCorr();
240 
241  } else {
242  inner_or_corr = curr->isInner();
243  }
244 
245  if (
247  !inner_or_corr && // outer and not corr
248  curr->TcPos() == best->TcPos()) { // same correlator of 1st track
249  if (config()->TssGhost2Flag() == 2 || // do not look to corr bit of 1st
250  ((!best->isCorr()) && config()->TssGhost2Flag() != 4) || // skip if best is not corr
251  ((!best->isCorr()) && best->isInner() &&
252  config()->TssGhost2Flag() == 4)) // skip only if best is inner and not corr
253  {
254  _logWord2[1 + curr->TcPos()] = 'G';
255  // std::cout << " skip sort 2 in TSS" << std::endl;
256  continue; // skip track
257  }
258  }
259  }
260  if (second == nullptr) {
261  second = curr;
262  } else if ((*curr) <= (*second)) {
263  second = curr;
264  }
265  }
266  // if(!second==0) {std::cout << " best sort 2 = " << second->dataword() <<
267  // std::endl;
268  // std::cout << " SM end of TSS sort 2: second = " << std::endl;
269  // second->print(); }
270 
271  return second;
272 }
273 
275  int ifs = (cand->isFirst()) ? 0 : 1;
276  // std::cout << "SM DTTSS::addDTTSCand ifs = " << ifs << std::endl;
277  _tctrig[ifs].push_back(cand);
278 }
279 
280 unsigned DTTSS::nTracoT(int ifs) const {
281  if (ifs < 1 || ifs > 2) {
282  std::cout << "DTTSS::nTracoT: wrong track number: " << ifs;
283  std::cout << " 0 returned!" << std::endl;
284  return 0;
285  }
286  return _tctrig[ifs - 1].size();
287 }
288 
289 DTTSCand *DTTSS::getDTTSCand(int ifs, unsigned n) const {
290  if (ifs < 1 || ifs > 2) {
291  std::cout << "DTTSS::getDTTSCand: wrong track number: " << ifs;
292  std::cout << " empty pointer returned!" << std::endl;
293  return nullptr;
294  }
295  if (n < 1 || n > nTracoT(ifs)) {
296  std::cout << "DTTSS::getDTTSCand: requested trigger not present: " << n;
297  std::cout << " empty pointer returned!" << std::endl;
298  return nullptr;
299  }
300  std::vector<DTTSCand *>::const_iterator p = _tctrig[ifs - 1].begin() + n - 1;
301  return (*p);
302 }
303 
304 const DTTracoTrigData *DTTSS::getTracoT(int ifs, unsigned n) const {
305  if (ifs < 1 || ifs > 2) {
306  std::cout << "DTTSS::getTracoT: wrong track number: " << ifs;
307  std::cout << " empty pointer returned!" << std::endl;
308  return nullptr;
309  }
310  if (n < 1 || n > nTracoT(ifs)) {
311  std::cout << "DTTSS::getTracoT: requested trigger not present: " << n;
312  std::cout << " empty pointer returned!" << std::endl;
313  return nullptr;
314  }
315  return getDTTSCand(ifs, n)->tracoTr();
316 }
317 
319  if (n < 1 || n > nTracks()) {
320  std::cout << "DTTSS::getTrack: requested track not present: " << n;
321  std::cout << " empty pointer returned!" << std::endl;
322  return nullptr;
323  }
324  std::vector<DTTSCand *>::const_iterator p = _outcand.begin() + n - 1;
325  return (*p);
326 }
327 
329  std::vector<DTTSCand *>::const_iterator p;
330  for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
331  if ((*p)->isCarry())
332  return (*p);
333  return nullptr;
334 }
335 
337  std::string lw = "";
338  switch (n) {
339  case 1:
340  lw = _logWord1;
341  break;
342  case 2:
343  lw = _logWord2;
344  break;
345  default:
346  std::cout << "DTTSS::logWord: requested track not present: " << n;
347  std::cout << " empty string returned!" << std::endl;
348  }
349  return lw;
350 }
std::string _logWord2
Definition: DTTSS.h:115
void setBitsTss()
Set the quality bits for DTTSS analysis.
Definition: DTTSCand.cc:78
std::vector< DTTSCand * > _tctrig[2]
Definition: DTTSS.h:105
DTTSS(int)
Constructor.
Definition: DTTSS.cc:36
int nTracks() const
Return the number of sorted tracks.
Definition: DTTSS.h:90
int _n
Definition: DTTSS.h:102
std::string logWord(int n) const
Return the requested log word.
Definition: DTTSS.cc:336
void addDTTSCand(DTTSCand *cand)
Add a TS candidate to the TSS, ifs is first/second track flag.
Definition: DTTSS.cc:274
int nFirstT() const
Return the number of input first tracks.
Definition: DTTSS.h:75
DTTSCand * getCarry() const
Return the carry (for debugging)
Definition: DTTSS.cc:328
unsigned dataword() const
Return an uint16 with the content of the data word (for debugging)
Definition: DTTSCand.h:132
int _ignoreSecondTrack
Definition: DTTSS.h:111
U second(std::pair< T, U > const &p)
int isFirst() const
Return the first/second track bit.
Definition: DTTSCand.h:99
int nSecondT() const
Return the number of input second tracks.
Definition: DTTSS.h:78
DTTSCand * getTrack(int n) const
Return the requested track.
Definition: DTTSS.cc:318
const DTConfigTSPhi * config() const
Configuration set.
Definition: DTTSS.h:69
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int isCarry() const
Return the carry bit.
Definition: DTTSCand.h:110
DTTSCand * sortTSS2()
Sort 2.
Definition: DTTSS.cc:187
std::vector< DTTSCand * > _outcand
Definition: DTTSS.h:108
DTTSCand * sortTSS1()
Sort 1.
Definition: DTTSS.cc:115
std::string _logWord1
Definition: DTTSS.h:114
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:84
int TssGhost2Flag() const
Ghost 2 suppression option in TSS.
~DTTSS()
Destructor.
Definition: DTTSS.cc:48
int isInner() const
Return Inner/Outer bit.
Definition: DTTSCand.h:104
void setSecondTrack()
Set the first track bit to second track (used for carry)
Definition: DTTSCand.h:63
bool TssGhost2Corr() const
Correlated ghost 2 suppression option in TSS.
tuple cout
Definition: gather_cfg.py:144
const DTTracoTrigData * getTracoT(int ifs, unsigned n) const
Return requested TRACO trigger.
Definition: DTTSS.cc:304
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 isCorr() const
Return correlation bit.
Definition: DTTSCand.h:107
unsigned nTracoT(int ifs) const
Return the number of input tracks (first/second)
Definition: DTTSS.cc:280
DTTSCand * getDTTSCand(int ifs, unsigned n) const
Return requested TS candidate.
Definition: DTTSS.cc:289
void clear()
Clear.
Definition: DTTSS.cc:54