CMS 3D CMS Logo

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