CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSC.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTSC.cpp
4 //
5 // Description: Implementation of DTSectColl trigger algorithm
6 //
7 //
8 // Author List:
9 // S. Marcellini
10 // Modifications:
11 // 11/11/06 C. Battilana : theta cand added
12 // 12/12/06 C. Battilana : _stat added
13 // 09/01/07 C. Battilana : updated to local conf
14 //
15 //
16 //--------------------------------------------------
17 
18 
19 //-----------------------
20 // This Class's Header --
21 //-----------------------
23 
24 //-------------------------------
25 // Collaborating Class Headers --
26 //-------------------------------
31 
32 //---------------
33 // C++ Headers --
34 //---------------
35 #include <iostream>
36 #include <algorithm>
37 
38 //----------------
39 // Constructors --
40 //----------------
41 
42 DTSC::DTSC(int istat) : _ignoreSecondTrack(0) ,_stat(istat){
43 
44  // reserve the appropriate amount of space for vectors
45  // test _incand[0].reserve(DTConfigSectColl::NTSMSC);
46  // test_incand[1].reserve(DTConfigSectColl::NTSMSC);
47  // test _outcand.reserve(2);
48 
49 }
50 
51 
52 //--------------
53 // Destructor --
54 //--------------
56 
57  clear();
58 
59 }
60 
61 
62 //--------------
63 // Operations --
64 //--------------
65 
66 void
68 
70 
71  for(int itk=0;itk<=1;itk++){
72 
73  _incand_ph[itk].clear();
74  }
75 
76  _outcand_ph.clear();
77  _cand_th.clear();
78 
79 }
80 
81 
82 //
83 void
85 
86  if(config()->debug()){
87  std::cout << "DTSC::run: Processing DTSectColl: ";
88  std::cout << nFirstTPh() << " first & " << nSecondTPh() << " second Phi tracks ";
89  std::cout << " - "<< nCandTh() << " Theta tracks" << std::endl;
90 
91  }
92 
93  if(nFirstTPh()<1)return; // skip if no first tracks
94  //
95  // SORT 1
96  //
97 
98  // debugging
99  if(config()->debug()){
100  std::cout << "Vector of first Phi tracks in DTSectColl: " << std::endl;
101  std::vector<DTSectCollPhCand*>::const_iterator p;
102  for(p=_incand_ph[0].begin(); p!=_incand_ph[0].end(); p++) {
103  (*p)->print();
104  }
105  }
106  // end debugging
107 
109  if(config()->debug()){
110  std::cout << "SC: DTSC::run: first Phi track is = " << first << std::endl;
111  }
112  if(first!=0) {
113  _outcand_ph.push_back(first);
114 
115  }
116  if(nSecondTPh()<1)return; // skip if no second tracks
117 
118  //
119  // SORT 2
120  //
121 
122  // debugging
123  if(config()->debug()){
124  std::vector<DTSectCollPhCand*>::const_iterator p;
125  std::cout << "Vector of second Phi tracks in DTSectColl: " << std::endl;
126  for(p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
127  (*p)->print();
128  }
129  }
130  // end debugging
131 
133  if(second!=0) {
134  _outcand_ph.push_back(second);
135  }
136 
137 }
138 
139 
142 
143  // Do a sort 1
144  DTSectCollPhCand* best=0;
145  DTSectCollPhCand* carry=0;
146  std::vector<DTSectCollPhCand*>::iterator p;
147  for(p=_incand_ph[0].begin(); p!=_incand_ph[0].end(); p++) {
148  DTSectCollPhCand* curr=(*p);
149 
150  curr->setBitsSectColl(); // SM sector collector set bits in dataword to make SC sorting
151 
152  // NO Carry in Sector Collector sorting in default
153  if(config()->SCGetCarryFlag(_stat)) { // get carry
154 
155  if(best==0){
156  best=curr;
157  }
158  else if((*curr)<(*best)){
159  carry=best;
160  best=curr;
161  }
162  else if(carry==0){
163  carry=curr;
164  }
165  else if((*curr)<(*carry)){
166  carry=curr;
167  }
168 
169  }
170  else if(config()->SCGetCarryFlag(_stat)==0){ // no carry (default)
171  if(best==0){
172  best=curr;
173  }
174  else if((*curr)<(*best)){
175 
176  best=curr;
177  }
178 
179  }
180 
181  if(carry!=0 && config()->SCGetCarryFlag(_stat)) { // reassign carry to sort 2 candidates
182  carry->setSecondTrack(); // change value of 1st/2nd track bit
183  _incand_ph[1].push_back(carry); // add to list of 2nd track
184 
185  }
186  }
187 
188  return best;
189 
190 }
191 
192 
195 
196  // Check if there are second tracks
197 
198  if(nTracksPh()<1){
199  std::cout << "DTSC::DTSectCollsort2: called with no first Phi track.";
200  std::cout << " empty pointer returned!" << std::endl;
201  return 0;
202  }
203  // If a first track at the following BX is present, ignore second tracks of any kind
204  if(_ignoreSecondTrack){
205 
206  for(std::vector<DTSectCollPhCand*>::iterator p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
207 
208  }
209  return 0;
210  }
211 
212  // If no first tracks at the following BX, do a sort 2
213  // DTSectCollCand* best=getTrack(1); ! not needed as lons as there is no comparison with best in sort 2
215  std::vector<DTSectCollPhCand*>::iterator p;
216  for(p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
217  DTSectCollPhCand* curr=(*p);
218  curr->setBitsSectColl(); // SM sector collector set bits in dataword to make SC sorting
219 
220  if(second==0){
221  second=curr;
222  }
223  else if((*curr)<(*second)){
224  second=curr;
225  }
226 
227  }
228 
229  return second;
230 
231 }
232 
233 
234 void
236 
237  _incand_ph[(1-cand->isFirst())].push_back(cand);
238 
239 }
240 
241 void
243 
244  _cand_th.push_back(cand);
245 
246 }
247 
248 
249 unsigned
250 DTSC::nCandPh(int ifs) const {
251 
252  if(ifs<1||ifs>2){
253  std::cout << "DTSC::nCandPh: wrong track number: " << ifs;
254  std::cout << " 0 returned!" << std::endl;
255  return 0;
256  }
257  return _incand_ph[ifs-1].size();
258 
259 }
260 
261 unsigned
262 DTSC::nCandTh() const {
263 
264  return _cand_th.size();
265 
266 }
267 
268 
270 DTSC::getDTSectCollPhCand(int ifs, unsigned n) const {
271 
272  if(ifs<1||ifs>2){
273  std::cout << "DTSC::getDTSectCollPhCand: wrong track number: " << ifs;
274  std::cout << " empty pointer returned!" << std::endl;
275  return 0;
276  }
277  if(n<1 || n>nCandPh(ifs)) {
278  std::cout << "DTSC::getDTSectCollPhCand: requested trigger not present: " << n;
279  std::cout << " empty pointer returned!" << std::endl;
280  return 0;
281  }
282 
283  std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs-1].begin()+n-1;
284  return (*p);
285 
286 }
287 
289 DTSC::getDTSectCollThCand(unsigned n) const {
290 
291  if(n<1 || n>nCandTh()) {
292  std::cout << "DTSC::getDTSectCollThCand: requested trigger not present: " << n;
293  std::cout << " empty pointer returned!" << std::endl;
294  return 0;
295  }
296 
297  std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin()+n-1;
298  return (*p);
299 
300 }
301 
302 void
304 
305  int ifs = (cand->isFirst()) ? 0 : 1;
306 
307  _incand_ph[ifs].push_back(cand);
308 
309 }
310 
312 DTSC::getTrackPh(int n) const {
313 
314  if(n<1 || n>nTracksPh()) {
315  std::cout << "DTSC::getTrackPh: requested track not present: " << n;
316  std::cout << " empty pointer returned!" << std::endl;
317  return 0;
318  }
319 
320  std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin()+n-1;
321 
322  return (*p);
323 
324 }
325 
326 
328 DTSC::getTrackTh(int n) const {
329 
330  if(n<1 || n>nTracksTh()) {
331  std::cout << "DTSC::getTrackTh: requested track not present: " << n;
332  std::cout << " empty pointer returned!" << std::endl;
333  return 0;
334  }
335 
336  std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin()+n-1;
337 
338  return (*p);
339 
340 }
int nFirstTPh() const
Return the number of input first tracks.
Definition: DTSC.h:96
std::vector< DTSectCollPhCand * > _incand_ph[2]
Definition: DTSC.h:125
unsigned nCandPh(int ifs) const
Return the number of Phi input tracks (first/second)
Definition: DTSC.cc:250
std::vector< DTSectCollThCand * > _cand_th
Definition: DTSC.h:131
int isFirst() const
Return first/second track bit value.
int _stat
Definition: DTSC.h:137
DTSectCollPhCand * DTSectCollsort2()
Phi Sort 2.
Definition: DTSC.cc:194
void setBitsSectColl()
Set the bits for DTTSM analysis.
DTSC(int istat)
Constructor.
Definition: DTSC.cc:42
DTSectCollThCand * getTrackTh(int n) const
Return the requested Theta track.
Definition: DTSC.cc:328
U second(std::pair< T, U > const &p)
DTSectCollPhCand * getDTSectCollPhCand(int ifs, unsigned n) const
Return requested TSS candidate.
Definition: DTSC.cc:270
void addDTSectCollPhCand(DTSectCollPhCand *cand)
Add a Sector Collector.
Definition: DTSC.cc:303
std::vector< DTSectCollPhCand * > _outcand_ph
Definition: DTSC.h:128
void addThCand(DTSectCollThCand *cand)
Add a Theta candidate to sect coll.
Definition: DTSC.cc:242
void addPhCand(DTSectCollPhCand *cand)
Add a TSM candidate to the Sect Coll, ifs is first/second track flag.
Definition: DTSC.cc:235
bool first
Definition: L1TdeRCT.cc:94
DTSectCollPhCand * getTrackPh(int n) const
Return the requested Phi track.
Definition: DTSC.cc:312
int _ignoreSecondTrack
Definition: DTSC.h:134
void run()
Run the Sector Collector algorithm.
Definition: DTSC.cc:84
DTSectCollThCand * getDTSectCollThCand(unsigned n) const
Return requested Theta candidate.
Definition: DTSC.cc:289
~DTSC()
Destructor.
Definition: DTSC.cc:55
int nTracksPh() const
Return the number of output Phi tracks.
Definition: DTSC.h:108
DTSectCollPhCand * DTSectCollsort1()
Phi Sort 1.
Definition: DTSC.cc:141
unsigned nCandTh() const
Return the number of Theta input tracks.
Definition: DTSC.cc:262
void clear()
Clear.
Definition: DTSC.cc:67
DTConfigSectColl * config() const
Configuration set.
Definition: DTSC.h:87
int nSecondTPh() const
Return the number of input second tracks.
Definition: DTSC.h:99
#define begin
Definition: vmac.h:31
int nTracksTh() const
Return the number of output Theta tracks.
Definition: DTSC.h:111
tuple cout
Definition: gather_cfg.py:121
#define debug
Definition: MEtoEDMFormat.h:34
void setSecondTrack()
Set the first track bit to second track (used for carry)