CMS 3D CMS Logo

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