CMS 3D CMS Logo

DTBtiChip.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTBtiChip
00004 //
00005 //   Description: Implementation of DTBtiChip 
00006 //                trigger algorithm
00007 //
00008 //
00009 //   Author List:
00010 //   C. Grandi
00011 //   Modifications: 
00012 //   S. Vanini
00013 //   30/IX/03 SV : wire dead time = ST added
00014 //   22/VI/04 SV : last trigger code update
00015 //   15/I/07  SV : new DTConfig setup
00016 //   17/III/07 SV : distp2 truncation bug fixed 
00017 //--------------------------------------------------
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "L1Trigger/DTBti/interface/DTBtiHit.h"
00028 #include "L1Trigger/DTBti/interface/DTBtiTrig.h"
00029 
00030 #include <DataFormats/MuonDetId/interface/DTChamberId.h>
00031 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
00032 #include <DataFormats/MuonDetId/interface/DTSuperLayerId.h>
00033 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00034 
00035 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00036 //---------------
00037 // C++ Headers --
00038 //---------------
00039 #include <iostream>
00040 #include <cmath>
00041 
00042 using namespace std;
00043 
00044 //----------------
00045 // Constructors --
00046 //----------------
00047 
00048 DTBtiChip::DTBtiChip(DTTrigGeom* geom, int supl, int n, DTConfigBti* conf): _geom(geom), _config(conf) {
00049 
00050 
00051  // original constructor
00052  setSnap();
00053  reSumSet(); 
00054 
00055  // Debugging...
00056   if(config()->debug()>2){
00057     cout << "DTBtiChip constructor called for BTI number " << n;
00058     cout << " in superlayer " << supl << endl;
00059   }
00060 
00061   // reserve the appropriate amount of space for vectors
00062   int i=0;
00063   for(i=0;i<DTConfig::NSTEPL - DTConfig::NSTEPF;i++) {
00064     _trigs[i].reserve(2);
00065   }
00066 
00067   for(i=0;i<9;i++) {
00068     _digis[i].reserve(10);
00069     _hits[i].reserve(10);
00070   }
00071 
00072   //SV wire dead time init
00073   int DEAD = config()->DEADpar();
00074   for(int cell=1; cell<=9; cell++){
00075     _busyStart_clock[cell-1] = - DEAD -1;
00076   }
00077 
00078   // Identifier
00079   DTChamberId sid = _geom->statId();
00080   _id = DTBtiId(sid, supl, n);
00081 
00082   //all this is obsolete, in new DTConfig setup... SV 15/I/2007
00083   //if(config()->trigSetupGeom()){
00084     //set K acceptance for each bti! SV
00085     //_MinKleftTraco = config()->LL_bti(n,supl);
00086     //_MaxKleftTraco = config()->LH_bti(n,supl);
00087     //_MinKcenterTraco = config()->CL_bti(n,supl);
00088     //_MaxKcenterTraco = config()->CH_bti(n,supl);
00089     //_MinKrightTraco = config()->RL_bti(n,supl);
00090     //_MaxKrightTraco = config()->RH_bti(n,supl);
00091 
00092     //if(config()->debug()>2){
00093       //cout << "K acceptance:" << endl;
00094       //cout << "  for left traco "<<_MinKleftTraco<<"<K<"<<_MaxKleftTraco<<endl;
00095       //cout << "  for center traco "<<_MinKcenterTraco<<"<K<"<<_MaxKcenterTraco<<endl;
00096       //cout << "  for right traco "<<_MinKrightTraco<<"<K<"<<_MaxKrightTraco<<endl;
00097     //}
00098     // end debugging
00099   //}
00100 
00101 
00102   //if(config()->trigSetupGeom() == 0){
00103     // set K acceptance for this BTI: 6 bit resolution....  
00104     _MinKAcc = 0;
00105     _MaxKAcc = 63;
00106         
00107 /*         DTBtiId _id1 = DTBtiId(sid,supl,1);
00108            
00109            cout <<"superlayer" << _id.superlayer()<< "BTI1   " <<  _id1.bti()  << " BTICur " << _id.bti()<< endl;
00110            cout <<endl;
00111            GlobalPoint gp1 = _geom->CMSPosition(_id1);
00112            cout << "pos of BTI "<<  _id1.bti()  << gp1 <<endl;
00113            // K of tracks from vertex
00114            GlobalPoint gp = CMSPosition();
00115            cout << "pos of BTI" << _id.bti()  << gp <<endl;        
00116            cout << endl ; */
00117            
00118            
00119 //     // theta bti acceptance cut is in bti chip (no traco in theta!)
00120 //     // acceptance from orca geom: bti theta angle in CMS frame +-2 in K units 
00121 //     if(_id.superlayer()==2){
00122 //       float distp2 = (int)(2*_geom->cellH()*config()->ST()/_geom->cellPitch());
00123 //       float K0 = config()->ST();
00124 
00125 // /*      DTBtiId _id1 = DTBtiId(sid,supl,1);
00126       
00127 //       cout << "BTI1   " <<  _id1.bti() << endl;
00128 //       cout << "BTICur " << _id.bti() <<endl;
00129 //       GlobalPoint gp1 = _geom->CMSPosition(_id1);
00130 //       cout << "pos of BTI 1 " << gp1 <<endl;*/
00131           
00132 //       // K of tracks from vertex
00133 //       GlobalPoint gp = CMSPosition();
00134 //       if(config()->debug()>3){
00135 //         cout << "Position: R=" << gp.perp() << "cm, Phi=" << gp.phi()*180/3.14159;
00136 //         cout << " deg, Z=" << gp.z() << " cm" << endl;
00137 //       }
00138 //       // CB TEST WITH NEW GEOMETRY
00139 //       // new geometry: modified wrt old due to specularity of theta SLs (still to understand on wheel zero) 19/06/06
00140 //       float theta;
00141 //       if (_id.wheel()==0){ 
00142 //      if(_id.sector()%4>1) theta = atan( gp.z()/gp.perp() );
00143 //      else theta = atan( -gp.z()/gp.perp() );
00144 //       }
00145 //       else theta = atan( fabs(gp.z())/gp.perp() );
00146 //       // .11 =TAN(6.3 deg) ==> k=2 (e' ancora vero? forse questa parte va aggiornata sena ripassare per gli angoli) 19/6/06
00147 //       float thetamin = theta-config()->KAccTheta()*0.055;
00148 //       float thetamax = theta+config()->KAccTheta()*0.055;
00149 
00150 //       float fktmin = tan(thetamin)*distp2 + K0;
00151 //       int ktmin = (fktmin>0) ? (int)(fktmin+0.5) : (int)(fktmin-0.5);
00152 //       float fktmax = tan(thetamax)*distp2 + K0;
00153 //       int ktmax = (fktmax>0) ? (int)(fktmax+0.5) : (int)(fktmax-0.5);
00154 // //      float fkbti = -gp.z()/gp.perp()*distp2;
00155 // //      int kbti = (fkbti>0) ? (int)(fkbti+0.5) : (int)(fkbti-0.5);
00156 // //      // K acceptance to point to vertex
00157 // //      int ktmin = kbti-config()->KAccTheta();  // minimum
00158 // //      int ktmax = kbti+config()->KAccTheta();  // maximum
00159 //       if(ktmin>_MinKAcc)_MinKAcc=ktmin;
00160 //       if(ktmax<_MaxKAcc)_MaxKAcc=ktmax;
00161 //     }
00162 
00163 //     // debugging
00164 //     if(config()->debug()>2){
00165 //       cout << "CMS position:" << CMSPosition() << endl;
00166 //       cout << "K acceptance:" << _MinKAcc << "," << _MaxKAcc << endl;
00167 //     }
00168 //     // end debugging
00169 // theta bti acceptance cut is in bti chip (no traco in theta!)
00170     // acceptance is determined about BTI angle wrt vertex with programmable value 
00171     if(_id.superlayer()==2){
00172 //      float distp2 = (int)(2*_geom->cellH()*config()->ST()/_geom->cellPitch());   SV fix 17/III/07
00173       float distp2 = 2*_geom->cellH()*config()->ST()/_geom->cellPitch();
00174       float K0 = config()->ST();
00175 
00176       // position of BTI 1 and of current one
00177       DTBtiId _id1 = DTBtiId(sid,supl,1);
00178       GlobalPoint gp1 = _geom->CMSPosition(_id1); 
00179       GlobalPoint gp = CMSPosition();
00180       if(config()->debug()>3){
00181         cout << "Position: R=" << gp.perp() << "cm, Phi=" << gp.phi()*180/3.14159;
00182         cout << " deg, Z=" << gp.z() << " cm" << endl;
00183       }
00184 // new geometry: modified wrt old due to specularity of theta SLs --> fixed 6/9/06 
00185       float theta;
00186       if(gp1.z() < 0.0) 
00187         theta = atan( -(gp.z())/gp.perp() );                            
00188       else 
00189         theta = atan( (gp.z())/gp.perp() );
00190 
00191 // set BTI acceptance window : fixed wrt ORCA on 6/9/06  
00192       float fktmin = tan(theta)*distp2+K0 ;
00193           int ktmin = static_cast<int>(fktmin)-config()->KAccTheta();
00194       float fktmax = tan(theta)*distp2+K0+1;
00195           int ktmax = static_cast<int>(fktmax)+config()->KAccTheta();
00196       if(ktmin>_MinKAcc)_MinKAcc=ktmin;
00197       if(ktmax<_MaxKAcc)_MaxKAcc=ktmax;
00198     }//end theta acceptance computation 
00199 
00200     // debugging
00201     if(config()->debug()>2){
00202       cout << "CMS position:" << CMSPosition() << endl;
00203       cout << "K acceptance:" << _MinKAcc << "," << _MaxKAcc  << endl;
00204     }
00205     // end debugging
00206   //}// end if trigSetupGeom=0
00207 
00208 
00209   //SV flag for initialization....
00210   init_done = 0; 
00211 
00212 }
00213 
00214 
00215 DTBtiChip::DTBtiChip(const DTBtiChip& bti) :
00216   _geom(bti._geom), _id(bti._id),
00217   _curStep(bti._curStep), _nStepUsedHits(bti._nStepUsedHits){
00218 
00219   setSnap();
00220   reSumSet();
00221 
00222   int i=0;
00223   for(i=0;i<DTConfig::NSTEPL - DTConfig::NSTEPF;i++) {
00224     _trigs[i].reserve(2);
00225     vector<DTBtiTrig*>::const_iterator p;
00226     for(p=bti._trigs[i].begin();p<bti._trigs[i].end();p++){
00227       _trigs[i].push_back(*p);
00228     }
00229   }
00230   for(i=0;i<9;i++) {
00231     _digis[i].reserve(10);
00232     vector<const DTDigi*>::const_iterator p;
00233     for(p=bti._digis[i].begin();p<bti._digis[i].end();p++){
00234       _digis[i].push_back(*p);
00235     }
00236     _hits[i].reserve(10);
00237     vector<DTBtiHit*>::const_iterator p1;
00238     for(p1=bti._hits[i].begin();p1<bti._hits[i].end();p1++){
00239       _hits[i].push_back(*p1);
00240     }
00241     _thisStepUsedTimes[i] = bti._thisStepUsedTimes[i];
00242     _thisStepUsedHit[i] = _thisStepUsedHit[i];
00243   }
00244   for(i=0;i<25;i++){
00245     _sums[i] = bti._sums[i];
00246     _difs[i] = bti._difs[i];
00247   }
00248   for(i=0;i<26;i++){
00249     int j = 0;
00250     for(j=0;j<6;j++){
00251       _Keq[i][j] = bti._Keq[i][j];
00252     }
00253     for(j=0;j<3;j++){
00254       _JTR[i][j] = bti._JTR[i][j];
00255     }
00256     for(j=0;j<2;j++){
00257       _Xeq[i][j] = bti._Xeq[i][j];
00258       _KTR[i][j] = bti._KTR[i][j];
00259     }
00260   }
00261   _MinKAcc = bti._MinKAcc;
00262   _MaxKAcc = bti._MaxKAcc;
00263 
00264 
00265 
00266 }
00267 //--------------
00268 // Destructor --
00269 //--------------
00270 DTBtiChip::~DTBtiChip(){
00271   clear();
00272 }
00273 
00274 //--------------
00275 // Operations --
00276 //--------------
00277 DTBtiChip& 
00278 DTBtiChip::operator=(const DTBtiChip& bti) {
00279   if(this != &bti){
00280     _geom = bti._geom;
00281     _id = bti._id;
00282     _curStep = bti._curStep;
00283     _nStepUsedHits = bti._nStepUsedHits;
00284     int i=0;
00285     for(i=0;i<DTConfig::NSTEPL - DTConfig::NSTEPF;i++) {
00286       _trigs[i].reserve(2);
00287       vector<DTBtiTrig*>::const_iterator p;
00288       for(p=bti._trigs[i].begin();p<bti._trigs[i].end();p++){
00289         _trigs[i].push_back(*p);
00290       }
00291     }
00292     for(i=0;i<9;i++) {
00293       _digis[i].reserve(10);
00294       vector<const DTDigi*>::const_iterator p;
00295       for(p=bti._digis[i].begin();p<bti._digis[i].end();p++){
00296         _digis[i].push_back(*p);
00297       }
00298       _hits[i].reserve(10);
00299       vector<DTBtiHit*>::const_iterator p1;
00300       for(p1=bti._hits[i].begin();p1<bti._hits[i].end();p1++){
00301         _hits[i].push_back(*p1);
00302       }
00303       _thisStepUsedTimes[i] = bti._thisStepUsedTimes[i];
00304       _thisStepUsedHit[i] = _thisStepUsedHit[i];
00305     }
00306     for(i=0;i<25;i++){
00307       _sums[i] = bti._sums[i];
00308       _difs[i] = bti._difs[i];
00309     }
00310     for(i=0;i<26;i++){
00311       int j = 0;
00312       for(j=0;j<6;j++){
00313         _Keq[i][j] = bti._Keq[i][j];
00314       }
00315       for(j=0;j<3;j++){
00316         _JTR[i][j] = bti._JTR[i][j];
00317       }
00318       for(j=0;j<2;j++){
00319         _Xeq[i][j] = bti._Xeq[i][j];
00320         _KTR[i][j] = bti._KTR[i][j];
00321       }
00322     }
00323     _MinKAcc = bti._MinKAcc;
00324     _MaxKAcc = bti._MaxKAcc;
00325   }
00326   return *this;
00327 }
00328 
00329 void 
00330 DTBtiChip::add_digi(int cell, const DTDigi* digi) {
00331 
00332   if(_id.bti()<1 || _id.bti() >_geom->nCell(superlayer()))return;
00333   if(cell<1 || cell>9){
00334     cout << "DTBtiChip::add_digi : wrong cell number: " << cell;
00335     cout << ". Digi not added!" << endl;
00336     return;
00337   }
00338 
00339   int DEAD = config()->DEADpar();
00340   float stepTimeTdc = DTBtiHit::_stepTimeTdc;
00341 
00342 
00343   if( int(digi->countsTDC()/stepTimeTdc) - _busyStart_clock[cell-1] > DEAD ){
00344     _busyStart_clock[cell-1] = int(digi->countsTDC()/stepTimeTdc);
00345     _digis[cell-1].push_back(digi);
00346 
00347     // debugging
00348     if(config()->debug()>1){
00349     cout << "DTBtiChip::add_digi: DTBtiChip # " <<_id.bti() <<
00350     " cell " << cell << " --> drift time (tdc units)= " << digi->countsTDC()<< endl;
00351     digi->print();
00352     }
00353   }
00354   else {
00355   // debugging
00356   if(config()->debug()>1)
00357     cout << "DTBtiChip::add_digi: DTBtiChip # " <<_id.bti() <<
00358      " cell " << cell << " in dead time -> digi not added! " << endl;
00359   }
00360 
00361 }
00362 
00363 
00364 void 
00365 DTBtiChip::add_digi_clock(int cell, int digi) {
00366 
00367   if(cell<1 || cell>9){
00368     cout << "DTBtiChip::add_digi_clock : wrong cell number: " << cell;
00369     cout << ". Digi not added!" << endl;
00370     return;
00371   }
00372 
00373   int DEAD = config()->DEADpar();
00374 
00375   if( digi - _busyStart_clock[cell-1] > DEAD ){
00376     _busyStart_clock[cell-1] = digi;
00377     _digis_clock[cell-1].push_back(digi);
00378     // debugging
00379     if(config()->debug()>1)
00380       cout << "DTBtiChip::add_digi_clock: DTBtiChip # " <<number() <<
00381       " cell " << cell << " --> clock time = " << digi << endl;
00382   }
00383   else{
00384   // debugging
00385   if(config()->debug()>1)
00386     cout << "DTBtiChip::add_digi_clock: DTBtiChip # " << number() <<
00387      " cell " << cell << " in dead time -> digi not added! " << endl;
00388   }
00389 }
00390 
00391 
00392 int
00393 DTBtiChip::nCellHit() const {
00394   int n=0;
00395   int i=0;
00396   for(i=0;i<9;i++) {
00397     if( _digis[i].size() >0 ) n++;
00398   }
00399   if(config()->debug()>2) {
00400     cout << n << " cells with hits found:" << endl;
00401   }
00402   if(config()->debug()>2) {
00403     for(i=0;i<9;i++) {
00404       vector<const DTDigi*>::const_iterator p;
00405       for(p=_digis[i].begin();p<_digis[i].end();p++) {
00406         cout << "DTBtiChip # " << 
00407         _id.bti() << 
00408         " cell " << i+1;
00409         cout << " --> drift time (tdc units): " << (*p)->countsTDC() << endl;
00410         (*p)->print();
00411       }
00412     }
00413   }
00414   return n;
00415 /*
00416  //SV 2/IV/03 counting hits from _hits
00417   int n=0;
00418   int i=0;
00419   for(i=0;i<9;i++) {
00420     if( _hits[i].size() >0 ) n++;
00421   }
00422   if(config()->debug()>2) {
00423     cout << n << " cells with hits found:" << endl;
00424   }
00425   if(config()->debug()>2) {
00426     for(i=0;i<9;i++) {
00427       vector<const DTBtiHit*>::const_iterator p;
00428       for(p=_hits[i].begin();p<_hits[i].end();p++) {
00429         cout << "DTBtiChip # " << 
00430         number() << 
00431         " cell " << i+1;
00432         if((*p)->curTime()!=4000)
00433           cout << " --> drift time: " << (*p)->curTime() << endl;
00434         else
00435           cout << " --> clock time: " << (*p)->clockTime() << endl;
00436       }
00437     }
00438   }
00439   return n;
00440 */
00441 }
00442 
00443 void 
00444 DTBtiChip::addTrig(int step, DTBtiTrig* btitrig) { 
00445   if(step>=DTConfig::NSTEPF&&step<=DTConfig::NSTEPL){
00446     if(config()->debug()>3) 
00447       cout << "DTBtiChip: adding trigger..." <<endl;
00448     _trigs[step-DTConfig::NSTEPF].push_back(btitrig);
00449   } else {
00450     if(config()->debug()>3){    
00451       cout << "DTBtiChip::addTrig: step " << step ;
00452       cout << " outside range. Trigger not added" << endl;
00453     }
00454   } 
00455 }
00456 
00457 int
00458 DTBtiChip::nTrig(int step) const {
00459   if(step<DTConfig::NSTEPF||step>DTConfig::NSTEPL){
00460     cout << "DTBtiChip::nTrig: step out of range: " << step ;
00461     cout << " 0 returned" << endl;
00462     return 0;
00463   }
00464   return _trigs[step-DTConfig::NSTEPF].size(); 
00465 }
00466 
00467 vector<DTBtiTrig*>
00468 DTBtiChip::trigList(int step) const {
00469   if(step<DTConfig::NSTEPF||step>DTConfig::NSTEPL){
00470     cout << "DTBtiChip::trigList: step out of range: " << step ;
00471     cout << " empty pointer returned" << endl;
00472     //return 0;
00473   } 
00474   return _trigs[step-DTConfig::NSTEPF]; 
00475 }
00476 
00477 DTBtiTrig*
00478 DTBtiChip::trigger(int step, unsigned n) const {
00479   if(step<DTConfig::NSTEPF||step>DTConfig::NSTEPL){
00480     cout << "DTBtiChip::trigger: step out of range: " << step ;
00481     cout << " empty pointer returned" << endl;
00482     return 0;
00483   } 
00484   if(n<1 || n>_trigs[step-DTConfig::NSTEPF].size()) {
00485     cout << "DTBtiChip::trigger: requested trigger does not exist: " << n;
00486     cout << " empty pointer returned!" << endl;
00487     return 0;
00488   }
00489   vector<DTBtiTrig*>::const_iterator p = _trigs[step-DTConfig::NSTEPF].begin();
00490   return (*(p+n-1));
00491 }
00492 
00493 DTBtiTrigData
00494 DTBtiChip::triggerData(int step, unsigned n) const {
00495   if(step<DTConfig::NSTEPF||step>DTConfig::NSTEPL){
00496     cout << "DTBtiChip::triggerData: step out of range: " << step ;
00497     cout << " dummy trigger returned" << endl;
00498     return DTBtiTrigData();
00499   } 
00500   if(n<1 || n>_trigs[step-DTConfig::NSTEPF].size()) {
00501     cout << "DTBtiChip::triggerData: requested trig. doesn't exist: " << n;
00502     cout << " dummy trigger returned!" << endl;
00503     return DTBtiTrigData();
00504   }
00505   vector<DTBtiTrig*>::const_iterator p = _trigs[step-DTConfig::NSTEPF].begin();
00506   return (*(p+n-1))->data();
00507 }
00508 
00509 void
00510 DTBtiChip::eraseTrigger(int step, unsigned n) {
00511   if(step<DTConfig::NSTEPF||step>DTConfig::NSTEPL){
00512     cout << "DTBtiChip::eraseTrigger: step out of range: " << step ;
00513     cout << " trigger not deleted!" << endl;
00514   } 
00515   if(n<1 || n>_trigs[step-DTConfig::NSTEPF].size()) {
00516     cout << "DTBtiChip::trigger: requested trigger does not exist: " << n;
00517     cout << " trigger not deleted!" << endl;
00518   }
00519   vector<DTBtiTrig*>::iterator p = _trigs[step-DTConfig::NSTEPF].begin()+n-1;
00520   if(&(*p))delete (*p);
00521   _trigs[step-DTConfig::NSTEPF].erase(p);
00522 }
00523 
00524 void
00525 DTBtiChip::clear() {
00526 
00527   if(config()->debug()>3)
00528     cout << "DTBtiChip::clear()" << endl;
00529 
00530   for(int c=0;c<9;c++) {
00531 
00532     _digis[c].clear();
00533     _digis_clock[c].clear();
00534 
00535     vector<DTBtiHit*>::iterator p;
00536     for(p=_hits[c].begin();p<_hits[c].end();p++){
00537       delete (*p);
00538     }
00539     _hits[c].clear();
00540   }
00541 
00542   vector<DTBtiTrig*>::iterator p1;
00543   for(int is=0;is<DTConfig::NSTEPL-DTConfig::NSTEPF+1;is++){
00544     for(p1=_trigs[is].begin();p1<_trigs[is].end();p1++){
00545       delete (*p1);
00546     }
00547     _trigs[is].clear();
00548   }
00549 }
00550 
00551 void
00552 DTBtiChip::init() {
00553 
00554   if(config()->debug()>3)
00555     cout << "DTBtiChip::init() -> initializing bti chip" << endl;
00556 
00557   _curStep=0;
00558   for(int i=0;i<25;i++) {
00559     _sums[i] = 1000;
00560     _difs[i] = 1000;
00561   } 
00562 
00563   for(int cell=0;cell<9;cell++) {
00564     int WEN = config()->WENflag(cell+1);
00565     if( WEN==1 ){
00566       _thisStepUsedHit[cell]=0;
00567       vector<const DTDigi*>::const_iterator p;
00568       for(p=_digis[cell].begin();p<_digis[cell].end();p++){
00569         DTBtiHit* hit = new DTBtiHit(*p,config());
00570         //int clockTime = (int)(fabs(((*p)->time()+config()->SetupTime())/12.5));
00571         //DTBtiHit* hit = new DTBtiHit(clockTime,config());
00572         _hits[cell].push_back(hit);
00573       }
00574 
00575       //debugging
00576       if(config()->debug()>2){
00577         vector<DTBtiHit*>::const_iterator p1;
00578         for(p1=_hits[cell].begin();p1<_hits[cell].end();p1++){
00579                 cout << " Filling hit in cell " << cell+1;
00580                 if((*p1)->curTime()!=4000) 
00581                   cout << " raw time in trigger: " << (*p1)->curTime() << endl;
00582                 cout << " time (clock units): " << (*p1)->clockTime() << endl; 
00583         }
00584       }
00585       // end debugging
00586     }
00587   }
00588 }
00589 
00590 
00591 void
00592 DTBtiChip::init_clock() {
00593 
00594   if(config()->debug()>3)
00595     cout << "DTBtiChip::init_clock() -> initializing bti chip" << endl;
00596 
00597   init_done = 1;
00598   _curStep=0;
00599 
00600   for(int i=0;i<25;i++) {
00601     _sums[i] = 1000;
00602     _difs[i] = 1000;
00603   } 
00604 
00605   for(int cell=0;cell<9;cell++) {
00606     int WEN = config()->WENflag(cell+1);
00607     if( WEN==1 ){
00608       _thisStepUsedHit[cell]=0;
00609     for(int i=0; i<_digis_clock[cell].size(); i++){
00610       const int clockTime = (_digis_clock[cell])[i];
00611       DTBtiHit* hit = new DTBtiHit(clockTime,config());
00612       _hits[cell].push_back(hit);
00613     }
00614         
00615     //debugging
00616     if(config()->debug()>2){
00617       vector<DTBtiHit*>::const_iterator p1;
00618       for(p1=_hits[cell].begin();p1<_hits[cell].end();p1++){
00619         cout << " Filling hit in cell " << cell+1;
00620         if((*p1)->curTime()!=4000) 
00621           cout << " time: " << (*p1)->curTime() << endl;
00622         else
00623           cout << " time (clock units): " << (*p1)->clockTime() << endl; 
00624         }
00625       }
00626       // end debugging
00627     }
00628   }
00629 }
00630 
00631 
00632 void 
00633 DTBtiChip::run() {
00634 
00635   // Debugging...
00636   if(config()->debug()>2){
00637     cout << "DTBtiChip::run: Processing BTI " << _id.bti() << endl;
00638     cout << " in SL " << _id.superlayer() << endl;
00639   }
00640   // End debugging
00641 
00642   if(_id.bti()<1 || _id.bti() >_geom->nCell(superlayer())) {
00643     if(config()->debug()>1)
00644       cout << "DTBtiChip::run : wrong BTI number: " << _id.bti() << endl;
00645     return;
00646   }
00647 
00648   // run algorithm
00649   if(!init_done)
00650     init();
00651   if( nCellHit()<3 ) return;   // check that at least 3 cell have hits
00652 
00653   for(int ints=0; ints<2*DTConfig::NSTEPL; ints++) { // 80 MHz 
00654     tick(); // Do a 12.5 ns step
00655 
00656     // In electronics equations are computed every 12.5 ns
00657     // but since triggers are searched for only every 25 ns, skip
00658     // also equation's computing at odd values of internal step
00659     if((currentIntStep()/2)*2!=currentIntStep())continue;
00660     //if((currentIntStep()/2)*2==currentIntStep())continue; 
00661 
00662 
00663     if(config()->debug()>2){
00664       cout << "DTBtiChip::run : internal step " << currentIntStep();
00665       cout << " number of JTRIG hits is " << _nStepUsedHits << endl;
00666     }
00667     if(currentStep()>=DTConfig::NSTEPF && _nStepUsedHits>2) { 
00668       // at least 3 good hits in this step -> run algorithm
00669       computeSums();
00670       computeEqs();
00671       findTrig();
00672     }
00673   }
00674   if( config()->LTS()>0 ) doLTS(); // low trigger suppression
00675 }
00676 
00677 void
00678 DTBtiChip::tick() {
00679   //
00680   // fills the DTBtiChip registers ( _thisStepUsedHit[cell] )
00681   // for a given clock (Syncronizer and Shaper functionalities)
00682   //
00683 
00684   _curStep++; // increase internal step (12.5 ns --> 80 MHz)
00685 
00686   // debugging
00687   if(config()->debug()>2){
00688     cout << "DTBtiChip::tick: internal step is now " << currentIntStep()<< endl; 
00689   }
00690   // end debugging
00691 
00692   // Loop on cells
00693   _nStepUsedHits=0;
00694   for(int cell=0;cell<9;cell++) {
00695 
00696     // decrease drift time by 12.5 ns for each hit
00697     vector<DTBtiHit*>::const_iterator p;
00698     for(p=_hits[cell].begin();p<_hits[cell].end();p++){
00699       (*p)->stepDownTime();
00700     }
00701 
00702     // loop on hits
00703     _thisStepUsedHit[cell]=0;
00704     for(p=_hits[cell].begin();p<_hits[cell].end();p++){
00705       if       ( (*p)->isDrifting() ) { // hit is drifting
00706         break;                          //   --> don't consider others
00707       } else if( (*p)->isInsideReg() ) {  // hit is already in registers
00708         _thisStepUsedHit[cell]=(*p);
00709         _nStepUsedHits++;
00710         // debugging
00711         if(config()->debug()>2){
00712           if((*p)->curTime() != 4000)
00713             cout << "DTBtiChip::tick: hit in register: time=" << (*p)->curTime();
00714           else
00715             cout << "DTBtiChip::tick: hit in register! " << endl;
00716           cout <<                           " jtrig=" << (*p)->jtrig() << endl;
00717 
00718         }
00719         // end debugging
00720         break;                          //   --> don't consider other triggers
00721       }
00722       // hit is not drifting and not in registers: it is gone out of register, but
00723       // jtrig value is still=ST ; save in array and consider next one if exists
00724     } // end loop on cell hits
00725 
00726     // debugging...
00727     if(config()->debug()>2){
00728       if(_thisStepUsedHit[cell]!=0){
00729         cout << "int. step=" << currentIntStep() << " cell=" << cell+1;
00730         cout << " jtrig=" << _thisStepUsedHit[cell]->jtrig();
00731         if( _thisStepUsedHit[cell]->curTime() != 4000 )  
00732           cout << " (time=" << _thisStepUsedHit[cell]->curTime() << ")" << endl;
00733         else 
00734           cout << endl;
00735       }
00736     } 
00737     // end debugging
00738 
00739   } // end loop on cells
00740 
00741 }
00742 
00743 void
00744 DTBtiChip::doLTS() {
00745  
00746   if(config()->debug()>2)
00747     cout<<"Do LTS"<<endl;
00748   int lts = config()->LTS();
00749   int nbxlts = config()->SET();
00750 
00751   // Do LTS only on the requested SL
00752   //if (superlayer()==2 && lts==1) return;
00753   //if (superlayer()!=2 && lts==2) return;
00754   //new DTConfig: do LTS only is LTS!=0  --> somewhat redundant !
00755   if (lts==0) return;
00756 
00757   // loop on steps
00758   for(int is=DTConfig::NSTEPF; is<=DTConfig::NSTEPL; is++) {
00759     if(nTrig(is)>0) { // non empty step
00760       if( trigger(is,1)->code()==8 ) { // HTRIG at this step
00761         // do LTS on nbxLTS[superlayer] following steps
00762         for(int js=is+1;(js<=is+nbxlts&&js<=DTConfig::NSTEPL);js++){
00763           if(nTrig(js)>0) { // non empty step
00764             DTBtiTrig* tr = trigger(js,1);
00765             if( tr->code()<8 && (lts==1 || lts==3)) {
00766               if(config()->debug()>3)
00767                 cout<<"LTS: erasing trigger!"<<endl; 
00768               eraseTrigger(js,1); // delete trigger
00769             }
00770           }
00771         }
00772         // do LTS on previous step
00773         if(is>DTConfig::NSTEPF && nTrig(is-1)>0) { // non empty step
00774           DTBtiTrig* tr = trigger(is-1,1);
00775           if( tr->code()<8 && (lts==2 || lts==3) ) {
00776             if(config()->debug()>3)
00777                 cout<<"LTS: erasing trigger!"<<endl;                                
00778             eraseTrigger(is-1,1); // delete trigger
00779           }
00780         }
00781 
00782       }
00783     }
00784   }
00785 }
00786 
00787 int
00788 DTBtiChip::store(const int eq, const int code, const int K, const int X, 
00789                      float KeqAB, float KeqBC, float KeqCD, 
00790                      float KeqAC, float KeqBD, float KeqAD) {
00791 
00792   // remove negative position triggers
00793   if(X<0)return 0;
00794 
00795   
00796   // accept in range triggers (acceptances defined in constructor)
00797   if(K>=_MinKAcc && K<=_MaxKAcc) 
00798   {
00799     int trig_step = currentStep();
00800 
00801 /*
00802     //SV test 27/I/2003 1-clock delay for critical patterns in default ACx configuration 
00803     int AC1 = config()->AccPattAC1(); //default 0
00804     int AC2 = config()->AccPattAC2(); //default 3
00805     int ACH = config()->AccPattACH(); //default 1
00806     int ACL = config()->AccPattACL(); //default 2     
00807 
00808     if(AC1==0 && AC2==3 && ACH==1 && ACL==2){
00809       if(eq==1 || eq==4 || eq==7 || eq==8 || eq==9 || eq==12 || eq==15
00810         || eq==19 || eq==22 || eq==23 || eq==24 || eq==25 || eq==27 )
00811            trig_step = currentStep()+1;
00812     }
00813 */     
00814     //store strobe: SV no strobe defined for this setup SV 15/I/2007
00815     int strobe=-1;
00816 
00817     // create a new trigger
00818     float Keq[6] = {KeqAB,KeqBC,KeqCD,KeqAC,KeqBD,KeqAD};
00819     //DTBtiTrig* trg = new DTBtiTrig(this,code,K,X,currentStep(),eq);
00820     DTBtiTrig* trg = new DTBtiTrig(this,code,K,X,trig_step,eq,strobe,Keq);
00821 
00822     // store also the digis
00823     for(int c=0; c<9; c++) {
00824       if(_thisStepUsedHit[c]) {
00825         const DTDigi* digi = _thisStepUsedHit[c]->hitDigi();
00826         if(digi)
00827           trg->addDigi(digi);
00828       }
00829     }
00830 
00831     //addTrig(currentStep(),trg);
00832     addTrig(trig_step,trg);
00833 
00834     // Debugging...
00835     if(config()->debug()>1)
00836       trg->print();
00837     // end debugging
00838     
00839     return 1;
00840   }
00841   else{
00842     // remove out of range triggers (acceptances defined in constructor)
00843     if(config()->debug()>2){
00844       cout << "DTBtiChip::store, at step "<< currentStep();
00845       cout << " allowed K range is: [";
00846       cout << _MinKAcc << ","<< _MaxKAcc << "]";
00847       cout << "K value is " << K << endl; 
00848     }
00849     return 0;
00850   }//end else
00851 }//end store
00852 
00853 
00854 void
00855 DTBtiChip::setSnap(){
00856 
00857  //set the internally calculated drift velocity parameters
00858   ST43 = config()->ST43();
00859   RE43 = config()->RE43();
00860   ST23 = int(double(ST43)/2.);
00861   RE23 = (RE43==1) ? 2 : int(double(RE43)/2.);
00862 
00863 
00864   ST =  int(  double(ST43) * 3./4. + double(RE43) * 1./4.     );
00865   ST2 = int( (double(ST43) * 3./4. + double(RE43) * 1./4.)*2. );
00866   ST3 = int( (double(ST43) * 3./4. + double(RE43) * 1./4.)*3. );
00867   ST4 = int( (double(ST43) * 3./4. + double(RE43) * 1./4.)*4. );
00868   ST5 = int( (double(ST43) * 3./4. + double(RE43) * 1./4.)*5. );
00869   ST7 = int( (double(ST43) * 3./4. + double(RE43) * 1./4.)*7. );
00870 
00871   if(config()->debug()>3){
00872     cout << "Snap register dump: " << endl;
00873     cout << "ST43 = " << ST43 << endl;
00874     cout << "RE43 = " << RE43 << endl;
00875     cout << "ST23 = " << ST23 << endl;
00876     cout << "RE23 = " << RE23 << endl;
00877     cout << "ST = " << ST << endl;
00878     cout << "ST2 = " << ST2 << endl;
00879     cout << "ST3 = " << ST3 << endl;
00880     cout << "ST4 = " << ST4 << endl;
00881     cout << "ST5 = " << ST5 << endl;
00882     cout << "ST7 = " << ST7 << endl;
00883   }
00884 }
00885 

Generated on Tue Jun 9 17:39:59 2009 for CMSSW by  doxygen 1.5.4