CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/L1Trigger/CSCTrackFinder/src/CSCTFTrackBuilder.cc

Go to the documentation of this file.
00001 #include <L1Trigger/CSCTrackFinder/src/CSCTFTrackBuilder.h>
00002 
00003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00004 
00005 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00006 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00007 #include <DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h>
00008 
00009 #include <DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h>
00010 #include <L1Trigger/CSCTrackFinder/interface/CSCTFSectorProcessor.h>
00011 
00012 #include "CondFormats/L1TObjects/interface/L1MuCSCTFConfiguration.h"
00013 #include "CondFormats/DataRecord/interface/L1MuCSCTFConfigurationRcd.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include <sstream>
00016 #include <stdlib.h>
00017 
00018 CSCTFTrackBuilder::CSCTFTrackBuilder(const edm::ParameterSet& pset, bool TMB07,
00019                                      const L1MuTriggerScales* scales,
00020                                      const L1MuTriggerPtScale* ptScale ){
00021   m_minBX = pset.getParameter<int>("MinBX");
00022   m_maxBX = pset.getParameter<int>("MaxBX");
00023 
00024   for(int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
00025     {
00026       for(int s = CSCTriggerNumbering::minTriggerSectorId();
00027           s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s)
00028         {
00029           // All SPs work with the same configuration (impossible to make it more exclusive in this framework)
00030           my_SPs[e-1][s-1] = new CSCTFSectorProcessor(e, s, pset, TMB07,
00031                                                       scales, ptScale);
00032         }
00033     }
00034 }
00035 
00036 void CSCTFTrackBuilder::initialize(const edm::EventSetup& c){
00037  //my_dtrc->initialize(c);
00038         for(int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
00039         {
00040                 for(int s = CSCTriggerNumbering::minTriggerSectorId(); s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s)
00041                 {
00042                         my_SPs[e-1][s-1]->initialize(c);
00043                 }
00044         }
00045 }
00046 
00047 CSCTFTrackBuilder::~CSCTFTrackBuilder()
00048 {
00049   for(int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
00050     {
00051       for(int s = CSCTriggerNumbering::minTriggerSectorId();
00052           s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s)
00053         {
00054           delete my_SPs[e-1][s-1];
00055           my_SPs[e-1][s-1] = NULL;
00056         }
00057     }
00058 }
00059 
00060 void CSCTFTrackBuilder::buildTracks(const CSCCorrelatedLCTDigiCollection* lcts, 
00061                                     const CSCTriggerContainer<csctf::TrackStub>* dtstubss, //const L1MuDTChambPhContainer* dttrig,
00062                                     L1CSCTrackCollection* trkcoll, CSCTriggerContainer<csctf::TrackStub>* stubs_to_dt)
00063 {
00064   std::vector<csc::L1Track> trks;
00065   CSCTriggerContainer<csctf::TrackStub> stub_list;
00066 
00067   CSCCorrelatedLCTDigiCollection::DigiRangeIterator Citer;
00068 
00069   for(Citer = lcts->begin(); Citer != lcts->end(); Citer++)
00070     {
00071       CSCCorrelatedLCTDigiCollection::const_iterator Diter = (*Citer).second.first;
00072       CSCCorrelatedLCTDigiCollection::const_iterator Dend = (*Citer).second.second;
00073 
00074           for(; Diter != Dend; Diter++)
00075         {
00076           csctf::TrackStub theStub((*Diter),(*Citer).first);
00077           stub_list.push_back(theStub);
00078         }
00079     }
00080 
00081   // Now we append the track stubs the the DT Sector Collector
00082   // after processing from the DT Receiver.
00083 
00084 //  CSCTriggerContainer<csctf::TrackStub> dtstubs = my_dtrc->process(dttrig);
00085 //  stub_list.push_many(dtstubs);
00086   stub_list.push_many(*dtstubss);
00087 
00088   // run each sector processor in the TF
00089   for(int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e)
00090   {
00091       for(int s = CSCTriggerNumbering::minTriggerSectorId();
00092         s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s)
00093       {
00094          CSCTriggerContainer<csctf::TrackStub> current_e_s = stub_list.get(e, s);
00095          int spReturnValue = my_SPs[e-1][s-1]->run(current_e_s);
00096          if(spReturnValue == -1) //Major Error, returning with empty Coll's
00097          {
00098            trkcoll->clear();
00099            stubs_to_dt->clear();
00100            return;
00101          }
00102          else if(spReturnValue)
00103          {
00104            std::vector<csc::L1Track> theTracks = my_SPs[e-1][s-1]->tracks().get();
00105            trks.insert(trks.end(), theTracks.begin(), theTracks.end());
00106          }
00107          stubs_to_dt->push_many(my_SPs[e-1][s-1]->dtStubs()); // send stubs whether or not we find a track!!!
00108       }
00109   }
00110 
00111   // Now to combine tracks with their track stubs and send them off.
00112   trkcoll->resize(trks.size());
00113   std::vector<csc::L1Track>::const_iterator titr = trks.begin();
00114   L1CSCTrackCollection::iterator tcitr = trkcoll->begin();
00115 
00116   for(; titr != trks.end(); titr++)
00117     {
00118       tcitr->first = (*titr);
00119       std::vector<csctf::TrackStub> possible_stubs = my_SPs[titr->endcap()-1][titr->sector()-1]->filteredStubs();
00120       std::vector<csctf::TrackStub>::const_iterator tkstbs = possible_stubs.begin();
00121 
00122       int me1ID    = titr->me1ID();
00123       int me2ID    = titr->me2ID();
00124       int me3ID    = titr->me3ID();
00125       int me4ID    = titr->me4ID();
00126       int mb1ID    = titr->mb1ID();
00127       int me1delay = titr->me1Tbin();
00128       int me2delay = titr->me2Tbin();
00129       int me3delay = titr->me3Tbin();
00130       int me4delay = titr->me4Tbin();
00131       int mb1delay = titr->mb1Tbin();
00132       // BX analyzer: some stub could be delayed by BXA so that all the stubs will run through the core at the same BX;
00133       //  then there is a rule of "second earlies LCT": resulting track will be placed at BX of the "second earliest LCT";
00134       //  in the end there are two parameters in place: the delay by BXA w.r.t to the last LCT and track tbin assignment
00135       std::map< int, std::list<int> > timeline;
00136       if( me1ID ) timeline[me1delay].push_back(1);
00137       if( me2ID ) timeline[me2delay].push_back(2);
00138       if( me3ID ) timeline[me3delay].push_back(3);
00139       if( me4ID ) timeline[me4delay].push_back(4);
00140       int earliest_tbin=0, second_earliest_tbin=0;
00141       for(int bx=7; bx>=0; bx--){
00142          std::list<int>::const_iterator iter = timeline[bx].begin();
00143          while( iter != timeline[bx].end() ){
00144             if( earliest_tbin==0 ) earliest_tbin=bx;
00145             else if( second_earliest_tbin==0 ) second_earliest_tbin=bx;
00146             iter++;
00147          }
00148       }
00149       // Core's input was loaded in a relative time window BX=[0-7)
00150       // To relate it to time window of tracks (centred at BX=0) we introduce a shift:
00151       int shift   = (m_maxBX + m_minBX)/2 - m_minBX + m_minBX;
00152       int me1Tbin = titr->bx() - me1delay + second_earliest_tbin + shift;
00153       int me2Tbin = titr->bx() - me2delay + second_earliest_tbin + shift;
00154       int me3Tbin = titr->bx() - me3delay + second_earliest_tbin + shift;
00155       int me4Tbin = titr->bx() - me4delay + second_earliest_tbin + shift;
00156       int mb1Tbin = titr->bx() - mb1delay + second_earliest_tbin + shift;
00157 
00158       for(; tkstbs != possible_stubs.end(); tkstbs++)
00159         {
00160           switch(tkstbs->station())
00161             {
00162             case 1:
00163               if((tkstbs->getMPCLink()
00164                   +(3*(CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(tkstbs->getDetId().rawId())) - 1))) == me1ID && me1ID != 0 && me1Tbin == tkstbs->BX() )
00165                 {
00166                   tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
00167                 }
00168               break;
00169             case 2:
00170               if(tkstbs->getMPCLink() == me2ID && me2ID != 0 && me2Tbin == tkstbs->BX() )
00171                 {
00172                   tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
00173                 }
00174               break;
00175             case 3:
00176               if(tkstbs->getMPCLink() == me3ID && me3ID != 0 && me3Tbin == tkstbs->BX() )
00177                 {
00178                   tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
00179                 }
00180               break;
00181             case 4:
00182               if(tkstbs->getMPCLink() == me4ID && me4ID != 0 && me4Tbin == tkstbs->BX() )
00183                 {
00184                   tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
00185                 }
00186               break;
00187             case 5:
00188               if(tkstbs->getMPCLink() == mb1ID && mb1ID != 0 && mb1Tbin == tkstbs->BX() )
00189               {
00191               }
00192               break;
00193             default:
00194               edm::LogWarning("CSCTFTrackBuilder::buildTracks()") << "SERIOUS ERROR: STATION " << tkstbs->station() << " NOT IN RANGE [1,5]\n";
00195             };
00196         }
00197       tcitr++; // increment to next track in the collection
00198     }
00199 
00200 }
00201