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