CMS 3D CMS Logo

DTTSM.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTSM.cpp
4 //
5 // Description: Implementation of DTTSM trigger algorithm
6 //
7 //
8 // Author List:
9 // C. Grandi
10 // Modifications:
11 // S. Marcellini, D. Bonacorsi
12 // 04/01/2007 : C.Battilana local config update
13 //
14 //
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
21 
22 //-------------------------------
23 // Collaborating Class Headers --
24 //-------------------------------
27 
28 //---------------
29 // C++ Headers --
30 //---------------
31 #include <algorithm>
32 #include <iostream>
33 
34 //----------------
35 // Constructors --
36 //----------------
37 // DBSM-doubleTSM
38 DTTSM::DTTSM(int n) : _n(n), _ignoreSecondTrack(0) {
39  // reserve the appropriate amount of space for vectors
40  _incand[0].reserve(DTConfigTSPhi::NTSSTSM);
41  _incand[1].reserve(DTConfigTSPhi::NTSSTSM);
42  _outcand.reserve(2);
43 }
44 
45 //--------------
46 // Destructor --
47 //--------------
49 
50 //--------------
51 // Operations --
52 //--------------
53 
54 void DTTSM::clear() {
56  for (int itk = 0; itk <= 1; itk++) {
57  // content of _incand is deleted by DTTSPhi
58  _incand[itk].clear();
59  }
60  // content of _outcand is deleted by DTTSPhi
61  _outcand.clear();
62 }
63 
64 void DTTSM::run(int bkmod) {
65 
66  if (config()->debug()) {
67  std::cout << "DTTSM::run: Processing DTTSM: ";
68  std::cout << nFirstT() << " first & " << nSecondT() << " second tracks"
69  << std::endl;
70  }
71 
72  if (nFirstT() < 1)
73  return; // skip if no first tracks
74  //
75  // SORT 1
76  //
77 
78  // debugging
79  if (config()->debug()) {
80  std::cout << "Vector of first tracks in DTTSM: " << std::endl;
81  std::vector<DTTSCand *>::const_iterator p;
82  for (p = _incand[0].begin(); p != _incand[0].end(); p++) {
83  (*p)->print();
84  }
85  }
86  // end debugging
87 
88  DTTSCand *first = sortTSM1(bkmod);
89  if (first != nullptr) {
90  _outcand.push_back(first);
91  }
92  if (nSecondT() < 1)
93  return; // skip if no second tracks
94 
95  //
96  // SORT 2
97  //
98 
99  // debugging
100  if (config()->debug()) {
101  std::vector<DTTSCand *>::const_iterator p;
102  std::cout << "Vector of second tracks (including carry) in DTTSM: "
103  << std::endl;
104  for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
105  (*p)->print();
106  }
107  }
108  // end debugging
109 
110  DTTSCand *second = sortTSM2(bkmod);
111  if (second != nullptr) {
112 
113  _outcand.push_back(second);
114  }
115 }
116 
118  // Do a sort 1
119  DTTSCand *best = nullptr;
120  DTTSCand *carry = nullptr;
121  std::vector<DTTSCand *>::iterator p;
122  for (p = _incand[0].begin(); p != _incand[0].end(); p++) {
123  DTTSCand *curr = (*p);
124 
125  if (bkmod == 1) { // NORMAL mode ---> sorting on dataword
126  curr->setBitsTss(); // maybe not necessary, as they are the same as for
127  // TSS in the default
128  } else if (bkmod ==
129  0) { // { // BACKUP mode ---> sorting on modified dataword
130  curr->setBitsBkmod();
131  } else {
132  std::cout << "DTTSM::sortTSM1: bkmod not properly assigned!"
133  << std::endl;
134  }
135 
136  if (best == nullptr) {
137  best = curr;
138  } else if ((*curr) < (*best)) {
139  carry = best;
140  best = curr;
141  } else if (carry == nullptr) {
142  carry = curr;
143  } else if ((*curr) < (*carry)) {
144  carry = curr;
145  } // else { }
146  }
147 
148  // Ghost 1 suppression: use carry only if not suppressed
149  if (carry != nullptr) { // A carry is present
150 
151  // Carry enabled if correlated and TRACO is next to best
152  bool inner_or_corr;
153  if (config()->TsmGhost1Corr()) {
154  inner_or_corr = carry->isInner() || carry->isCorr();
155  } else {
156  inner_or_corr = carry->isInner();
157  }
158 
159  if (config()->TsmGhost1Flag() < 2) { // Carry isn't always suppressed
160  // check if adjacent DTTracoChips
161  int adj =
162  (carry->tssNumber() == best->tssNumber() + 1 && // next DTTracoChip
163  best->TcPos() == DTConfigTSPhi::NTCTSS && carry->TcPos() == 1) ||
164  (carry->tssNumber() == best->tssNumber() - 1 && // prev DTTracoChip
165  best->TcPos() == 1 && carry->TcPos() == DTConfigTSPhi::NTCTSS) ||
166  (carry->tssNumber() == best->tssNumber() && // same DTTracoChip
167  abs(carry->TcPos() - best->TcPos()) == 1);
168 
169  if (config()->TsmGhost1Flag() == 0 || // Carry always enabled
170  // carry->isInner() || //
171  // Carry is inner
172  inner_or_corr || // Carry is inner or corr
173  !adj) { // Carry not adj. to best
174  // add carry to second tracks to for sort 2
175  carry->setSecondTrack(); // change value of first/second track bit
176  // NEW DESIGN: DTTSM is not configurable!
177  // carry->setBitsTsm(); // set quality bits as for second tracks
178  _incand[1].push_back(carry); // add to list of second tracks
179  }
180  }
181  }
182  // best->print();
183  return best;
184 }
185 
187 
188  // If second tracks are always suppressed skip processing
189  if (config()->TsmGhost2Flag() == 3)
190  return nullptr;
191 
192  // Check if there are second tracks
193  if (nTracks() < 1) {
194  std::cout << "DTTSM::sortTSM2: called with no first track.";
195  std::cout << " empty pointer returned!" << std::endl;
196  return nullptr;
197  }
198 
199  // If a first track at the following BX is present, ignore second tracks of
200  // any kind
201  if (_ignoreSecondTrack) {
202  std::vector<DTTSCand *>::iterator p;
203  for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
204  if ((*p)->isCarry())
205  return (*p);
206  }
207  return nullptr;
208  }
209 
210  // If no first tracks at the following BX, do a sort 2
211  DTTSCand *best = getTrack(1);
212  DTTSCand *second = nullptr;
213  std::vector<DTTSCand *>::iterator p;
214  for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
215  DTTSCand *curr = (*p);
216  // ghost 2 suppression: skip track if suppressed
217  // this is not needed if config of DTTSM == config of DTTSS
218 
219  bool inner_or_corr;
220  if (config()->TsmGhost2Corr()) {
221  inner_or_corr = curr->isInner() || curr->isCorr();
222  } else {
223  inner_or_corr = curr->isInner();
224  }
225 
226  if (config()->TsmGhost2Flag() != 0) { // 2nd tracks not always enabled
227  if (
229  !inner_or_corr && // outer and not corr
230  (curr->tssNumber() == best->tssNumber() &&
231  curr->TcPos() == best->TcPos())) { // same correlator of 1st track
232  if (config()->TsmGhost2Flag() == 2 || // do not look to corr bit of 1st
233  ((!best->isCorr()) &&
234  config()->TsmGhost2Flag() != 4) || // skip if best is not corr
235  ((!best->isCorr()) && best->isInner() &&
236  config()->TsmGhost2Flag() ==
237  4)) // skip only if best is inner and not corr
238  {
239  continue; // skip track
240  }
241  }
242  }
243 
244  // added DBSM
245  // SM double TSM if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
246  if (bkmod == 1) { // NORMAL mode ---> sorting on dataword
247  curr->setBitsTss(); // maybe not necessary, as they are the same as for
248  // TSS in the default
249  } else if (bkmod ==
250  0) { // { // BACKUP mode ---> sorting on modified dataword
251  curr->setBitsBkmod();
252  } else {
253  std::cout << " DTTSM::sortTSM2 bkmod not properly assigned!" << std::endl;
254  }
255 
256  // added DBSM
257  // SM double TSM if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
258 
259  if (second == nullptr) {
260  second = curr;
261  } else if ((*curr) < (*second)) {
262  second = curr;
263  }
264  }
265  return second;
266 }
267 
269  // NEW DESIGN: DTTSM is not configurable!
270  // cand->resetCarry(); // reset carry information
271  // cand->setBitsTsm(); // set quality bits for DTTSM sorting
272  _incand[(1 - cand->isFirst())].push_back(cand);
273 }
274 
275 unsigned DTTSM::nCand(int ifs) const {
276  if (ifs < 1 || ifs > 2) {
277  std::cout << "DTTSM::nCand: wrong track number: " << ifs;
278  std::cout << " 0 returned!" << std::endl;
279  return 0;
280  }
281 
282  return _incand[ifs - 1].size();
283 }
284 
285 DTTSCand *DTTSM::getDTTSCand(int ifs, unsigned n) const {
286  if (ifs < 1 || ifs > 2) {
287  std::cout << "DTTSM::getDTTSCand: wrong track number: " << ifs;
288  std::cout << " empty pointer returned!" << std::endl;
289  return nullptr;
290  }
291  if (n < 1 || n > nCand(ifs)) {
292  std::cout << "DTTSM::getDTTSCand: requested trigger not present: " << n;
293  std::cout << " empty pointer returned!" << std::endl;
294  return nullptr;
295  }
296  std::vector<DTTSCand *>::const_iterator p = _incand[ifs - 1].begin() + n - 1;
297  return (*p);
298 }
299 
300 const DTTracoTrigData *DTTSM::getTracoT(int ifs, unsigned n) const {
301  if (ifs < 1 || ifs > 2) {
302  std::cout << "DTTSM::getTracoT: wrong track number: " << ifs;
303  std::cout << " empty pointer returned!" << std::endl;
304  return nullptr;
305  }
306  if (n < 1 || n > nCand(ifs)) {
307  std::cout << "DTTSM::getTracoT: requested trigger not present: " << n;
308  std::cout << " empty pointer returned!" << std::endl;
309  return nullptr;
310  }
311  return getDTTSCand(ifs, n)->tracoTr();
312 }
313 
315 
316  if (n < 1 || n > nTracks()) {
317  std::cout << "DTTSM::getTrack: requested track not present: " << n;
318  std::cout << " empty pointer returned!" << std::endl;
319  return nullptr;
320  }
321  std::vector<DTTSCand *>::const_iterator p = _outcand.begin() + n - 1;
322  return (*p);
323 }
std::vector< DTTSCand * > _outcand
Definition: DTTSM.h:108
void setBitsTss()
Set the quality bits for DTTSS analysis.
Definition: DTTSCand.cc:80
DTTSCand * sortTSM2(int bkmod)
Sort 2.
Definition: DTTSM.cc:186
DTTSCand * getTrack(int n) const
Return the requested track.
Definition: DTTSM.cc:314
bool TsmGhost2Corr() const
Correlated ghost 2 suppression option in TSM.
static const int NTSSTSM
Constant: maximum number of TSS in input to the TSM.
Definition: DTConfigTSPhi.h:42
void run(int bkmod)
Run the TSM algorithm.
Definition: DTTSM.cc:64
U second(std::pair< T, U > const &p)
int isFirst() const
Return the first/second track bit.
Definition: DTTSCand.h:100
DTTSCand * getDTTSCand(int ifs, unsigned n) const
Return requested TS candidate.
Definition: DTTSM.cc:285
int tssNumber() const
Return the DTTSS number.
Definition: DTTSCand.h:94
DTTSM(int)
Constructor.
Definition: DTTSM.cc:38
static const int NTCTSS
Constant: number of TRACOs in input to a TSS.
Definition: DTConfig.h:41
int nTracks() const
Return the number of sorted tracks.
Definition: DTTSM.h:92
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned nCand(int ifs) const
Return the number of input tracks (first/second)
Definition: DTTSM.cc:275
int nSecondT() const
Return the number of input second tracks.
Definition: DTTSM.h:83
~DTTSM()
Destructor.
Definition: DTTSM.cc:48
const DTTracoTrigData * getTracoT(int ifs, unsigned n) const
Return requested TRACO trigger.
Definition: DTTSM.cc:300
int TsmGhost1Flag() const
Ghost 1 suppression option in TSM.
int nFirstT() const
Return the number of input first tracks.
Definition: DTTSM.h:80
int _ignoreSecondTrack
Definition: DTTSM.h:111
#define debug
Definition: HDRShower.cc:19
const DTTracoTrigData * tracoTr() const
Return associated TRACO trigger.
Definition: DTTSCand.h:85
void clear()
Clear.
Definition: DTTSM.cc:54
std::vector< DTTSCand * > _incand[2]
Definition: DTTSM.h:105
int TsmGhost2Flag() const
Ghost 2 suppression option in TSM.
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
DTTSCand * sortTSM1(int bkmod)
Sort 1.
Definition: DTTSM.cc:117
void addCand(DTTSCand *cand)
Add a TSS candidate to the TSM, ifs is first/second track flag.
Definition: DTTSM.cc:268
int TcPos() const
Retrun the TRACO position inside the TSS.
Definition: DTTSCand.h:88
const DTConfigTSPhi * config() const
Configuration set.
Definition: DTTSM.h:74
void setBitsBkmod()
Set the bits for TSM back-up mode.
Definition: DTTSCand.cc:154
int isCorr() const
Return correlation bit.
Definition: DTTSCand.h:110