CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.cc

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 //   Class: CSCTriggerPrimitivesBuilder
00004 //
00005 //   Description: Algorithm to build anode, cathode, and correlated LCTs
00006 //                in each endcap muon CSC chamber from wire and comparator
00007 //                digis.
00008 //
00009 //   Author List: S. Valuev, UCLA.
00010 //
00011 //   $Id: CSCTriggerPrimitivesBuilder.cc,v 1.22 2012/12/05 21:14:23 khotilov Exp $
00012 //
00013 //   Modifications:
00014 //
00015 //-----------------------------------------------------------------------------
00016 
00017 #include <L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.h>
00018 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboard.h>
00019 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboardME11.h>
00020 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMuonPortCard.h>
00021 
00022 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00023 
00024 #include <L1Trigger/CSCCommonTrigger/interface/CSCTriggerGeometry.h>
00025 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00026 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00027 
00028 //------------------
00029 // Static variables
00030 //------------------
00031 const int CSCTriggerPrimitivesBuilder::min_endcap  = CSCDetId::minEndcapId();
00032 const int CSCTriggerPrimitivesBuilder::max_endcap  = CSCDetId::maxEndcapId();
00033 const int CSCTriggerPrimitivesBuilder::min_station = CSCDetId::minStationId();
00034 const int CSCTriggerPrimitivesBuilder::max_station = CSCDetId::maxStationId();
00035 const int CSCTriggerPrimitivesBuilder::min_sector  = CSCTriggerNumbering::minTriggerSectorId();
00036 const int CSCTriggerPrimitivesBuilder::max_sector  = CSCTriggerNumbering::maxTriggerSectorId();
00037 const int CSCTriggerPrimitivesBuilder::min_subsector = CSCTriggerNumbering::minTriggerSubSectorId();
00038 const int CSCTriggerPrimitivesBuilder::max_subsector = CSCTriggerNumbering::maxTriggerSubSectorId();
00039 const int CSCTriggerPrimitivesBuilder::min_chamber = CSCTriggerNumbering::minTriggerCscId();
00040 const int CSCTriggerPrimitivesBuilder::max_chamber = CSCTriggerNumbering::maxTriggerCscId();
00041 
00042 //-------------
00043 // Constructor
00044 //-------------
00045 CSCTriggerPrimitivesBuilder::CSCTriggerPrimitivesBuilder(const edm::ParameterSet& conf)
00046 {
00047   // Receives ParameterSet percolated down from EDProducer.
00048 
00049   // special configuration parameters for ME11 treatment
00050   edm::ParameterSet commonParams = conf.getParameter<edm::ParameterSet>("commonParam");
00051   smartME1aME1b = commonParams.getUntrackedParameter<bool>("smartME1aME1b", false);
00052   disableME1a = commonParams.getUntrackedParameter<bool>("disableME1a", false);
00053   disableME42 = commonParams.getUntrackedParameter<bool>("disableME42", false);
00054 
00055   checkBadChambers_ = conf.getUntrackedParameter<bool>("checkBadChambers", true);
00056 
00057   // ORCA way of initializing boards.
00058   for (int endc = min_endcap; endc <= max_endcap; endc++)
00059   {
00060     for (int stat = min_station; stat <= max_station; stat++)
00061     {
00062       int numsubs = ((stat == 1) ? max_subsector : 1);
00063       for (int sect = min_sector; sect <= max_sector; sect++)
00064       {
00065         for (int subs = min_subsector; subs <= numsubs; subs++)
00066         {
00067           for (int cham = min_chamber; cham <= max_chamber; cham++)
00068           {
00069             if ((endc <= 0 || endc > MAX_ENDCAPS)    ||
00070                 (stat <= 0 || stat > MAX_STATIONS)   ||
00071                 (sect <= 0 || sect > MAX_SECTORS)    ||
00072                 (subs <= 0 || subs > MAX_SUBSECTORS) ||
00073                 (cham <= 0 || stat > MAX_CHAMBERS))
00074             {
00075               edm::LogError("L1CSCTPEmulatorSetupError")
00076                 << "+++ trying to instantiate TMB of illegal CSC id ["
00077                 << " endcap = "  << endc << " station = "   << stat
00078                 << " sector = "  << sect << " subsector = " << subs
00079                 << " chamber = " << cham << "]; skipping it... +++\n";
00080               continue;
00081             }
00082             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00083             // When the motherboard is instantiated, it instantiates ALCT
00084             // and CLCT processors.
00085             if (stat==1 && ring==1 && smartME1aME1b)
00086               tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboardME11(endc, stat, sect, subs, cham, conf);
00087             else
00088               tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboard(endc, stat, sect, subs, cham, conf);
00089           }
00090         }
00091       }
00092     }
00093   }
00094 
00095   // Get min and max BX to sort LCTs in MPC.
00096   m_minBX = conf.getParameter<int>("MinBX");
00097   m_maxBX = conf.getParameter<int>("MaxBX");
00098 
00099   // Init MPC
00100   m_muonportcard = new CSCMuonPortCard(conf);
00101 }
00102 
00103 //------------
00104 // Destructor
00105 //------------
00106 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder()
00107 {
00108   for (int endc = min_endcap; endc <= max_endcap; endc++)
00109   {
00110     for (int stat = min_station; stat <= max_station; stat++)
00111     {
00112       int numsubs = ((stat == 1) ? max_subsector : 1);
00113       for (int sect = min_sector; sect <= max_sector; sect++)
00114       {
00115         for (int subs = min_subsector; subs <= numsubs; subs++)
00116         {
00117           for (int cham = min_chamber; cham <= max_chamber; cham++)
00118           {
00119             delete tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00120           }
00121         }
00122       }
00123     }
00124   }
00125   delete m_muonportcard;
00126 }
00127 
00128 //------------
00129 // Operations
00130 //------------
00131 // Set configuration parameters obtained via EventSetup mechanism.
00132 void CSCTriggerPrimitivesBuilder::setConfigParameters(const CSCDBL1TPParameters* conf)
00133 {
00134   // Receives CSCDBL1TPParameters percolated down from ESProducer.
00135 
00136   for (int endc = min_endcap; endc <= max_endcap; endc++)
00137   {
00138     for (int stat = min_station; stat <= max_station; stat++)
00139     {
00140       int numsubs = ((stat == 1) ? max_subsector : 1);
00141       for (int sect = min_sector; sect <= max_sector; sect++)
00142       {
00143         for (int subs = min_subsector; subs <= numsubs; subs++)
00144         {
00145           for (int cham = min_chamber; cham <= max_chamber; cham++)
00146           {
00147             CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00148             tmb->setConfigParameters(conf);
00149           }
00150         }
00151       }
00152     }
00153   }
00154 }
00155 
00156 // Build anode, cathode, and correlated LCTs in each chamber and fill them
00157 // into output collections.  Pass collections of wire and comparator digis
00158 // to Trigger MotherBoard (TMB) processors, which, in turn, pass them to
00159 // ALCT and CLCT processors.  Up to 2 anode and 2 cathode LCTs can be found
00160 // in each chamber during any bunch crossing.  The 2 projections are then
00161 // combined into three-dimensional "correlated" LCTs in the TMB.  Finally,
00162 // MPC processor sorts up to 18 LCTs from 9 TMBs and writes collections of
00163 // up to 3 best LCTs per (sub)sector into Event (to be used by the Sector
00164 // Receiver).
00165 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
00166                                         const CSCWireDigiCollection* wiredc,
00167                                         const CSCComparatorDigiCollection* compdc,
00168                                         CSCALCTDigiCollection& oc_alct,
00169                                         CSCCLCTDigiCollection& oc_clct,
00170                                         CSCCLCTPreTriggerCollection & oc_pretrig,
00171                                         CSCCorrelatedLCTDigiCollection& oc_lct,
00172                                         CSCCorrelatedLCTDigiCollection& oc_sorted_lct)
00173 {
00174   // CSC geometry.
00175   CSCTriggerGeomManager* theGeom = CSCTriggerGeometry::get();
00176 
00177   for (int endc = min_endcap; endc <= max_endcap; endc++)
00178   {
00179     for (int stat = min_station; stat <= max_station; stat++)
00180     {
00181       int numsubs = ((stat == 1) ? max_subsector : 1);
00182       for (int sect = min_sector; sect <= max_sector; sect++)
00183       {
00184         for (int subs = min_subsector; subs <= numsubs; subs++)
00185         {
00186           for (int cham = min_chamber; cham <= max_chamber; cham++)
00187           {
00188             
00189             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00190             
00191             if (disableME42 && stat==4 && ring==2) continue;
00192 
00193             CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00194 
00195             // Run processors only if chamber exists in geometry.
00196             if (tmb == 0 || theGeom->chamber(endc, stat, sect, subs, cham) == 0) continue;
00197 
00198             int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
00199 
00200             // 0th layer means whole chamber.
00201             CSCDetId detid(endc, stat, ring, chid, 0);
00202 
00203             // Skip chambers marked as bad (usually includes most of ME4/2 chambers;
00204             // also, there's no ME1/a-1/b separation, it's whole ME1/1)
00205             if (checkBadChambers_ && badChambers->isInBadChamber(detid)) continue;
00206 
00207 
00208             // running upgraded ME1/1 TMBs (non-upgraded)
00209             if (stat==1 && ring==1 && smartME1aME1b)
00210             {
00211               CSCMotherboardME11* tmb11 = static_cast<CSCMotherboardME11*>(tmb);
00212  
00213               //LogTrace("CSCTriggerPrimitivesBuilder")<<"CSCTriggerPrimitivesBuilder::build in E:"<<endc<<" S:"<<stat<<" R:"<<ring;
00214  
00215               tmb11->run(wiredc,compdc);
00216               std::vector<CSCCorrelatedLCTDigi> lctV = tmb11->readoutLCTs1b();
00217               std::vector<CSCCorrelatedLCTDigi> lctV1a = tmb11->readoutLCTs1a();
00218  
00219               std::vector<CSCALCTDigi> alctV1a, alctV = tmb11->alct->readoutALCTs();
00220 
00221               std::vector<CSCCLCTDigi> clctV = tmb11->clct->readoutCLCTs();
00222               std::vector<int> preTriggerBXs = tmb11->clct->preTriggerBXs();
00223               std::vector<CSCCLCTDigi> clctV1a = tmb11->clct1a->readoutCLCTs();
00224               std::vector<int> preTriggerBXs1a = tmb11->clct1a->preTriggerBXs();
00225 
00226               // perform simple separation of ALCTs into 1/a and 1/b
00227               // for 'smart' case. Some duplication occurs for WG [10,15]
00228               std::vector<CSCALCTDigi> tmpV(alctV);
00229               alctV.clear();
00230               for (unsigned int al=0; al < tmpV.size(); al++)
00231               {
00232                 if (tmpV[al].getKeyWG()<=15) alctV1a.push_back(tmpV[al]);
00233                 if (tmpV[al].getKeyWG()>=10) alctV.push_back(tmpV[al]);
00234               }
00235               //LogTrace("CSCTriggerPrimitivesBuilder")<<"CSCTriggerPrimitivesBuilder:: a="<<alctV.size()<<" c="<<clctV.size()<<" l="<<lctV.size()
00236               //  <<"   1a: a="<<alctV1a.size()<<" c="<<clctV1a.size()<<" l="<<lctV1a.size();
00237  
00238               // ME1/b
00239 
00240               if (!(lctV.empty()&&alctV.empty()&&clctV.empty())) {
00241                 LogTrace("L1CSCTrigger")
00242                   << "CSCTriggerPrimitivesBuilder results in " <<detid; 
00243               }
00244 
00245               // Correlated LCTs.
00246               if (!lctV.empty()) {
00247                 LogTrace("L1CSCTrigger")
00248                   << "Put " << lctV.size() << " ME1b LCT digi"
00249                   << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00250                 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00251               }
00252  
00253               // Anode LCTs.
00254               if (!alctV.empty()) {
00255                 LogTrace("L1CSCTrigger")
00256                   << "Put " << alctV.size() << " ME1b ALCT digi"
00257                   << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00258                 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00259               }
00260  
00261               // Cathode LCTs.
00262               if (!clctV.empty()) {
00263                 LogTrace("L1CSCTrigger")
00264                   << "Put " << clctV.size() << " ME1b CLCT digi"
00265                   << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00266                 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00267               }
00268 
00269               // Cathode LCTs pretriggers
00270               if (!preTriggerBXs.empty()) {
00271                 LogTrace("L1CSCTrigger")
00272                   << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00273                   << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00274                 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00275               }            
00276 
00277               // ME1/a
00278 
00279               if (disableME1a) continue;
00280 
00281               CSCDetId detid1a(endc, stat, 4, chid, 0);
00282 
00283               if (!(lctV1a.empty()&&alctV1a.empty()&&clctV1a.empty())){
00284                 LogTrace("L1CSCTrigger") << "CSCTriggerPrimitivesBuilder results in " <<detid1a;
00285               }
00286  
00287               // Correlated LCTs.
00288               if (!lctV1a.empty()) {
00289                 LogTrace("L1CSCTrigger")
00290                   << "Put " << lctV1a.size() << " ME1a LCT digi"
00291                   << ((lctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00292                 oc_lct.put(std::make_pair(lctV1a.begin(),lctV1a.end()), detid1a);
00293               }
00294  
00295               // Anode LCTs.
00296               if (!alctV1a.empty()) {
00297                 LogTrace("L1CSCTrigger")
00298                   << "Put " << alctV1a.size() << " ME1a ALCT digi"
00299                   << ((alctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00300                 oc_alct.put(std::make_pair(alctV1a.begin(),alctV1a.end()), detid1a);
00301               }
00302  
00303               // Cathode LCTs.
00304               if (!clctV1a.empty()) {
00305                 LogTrace("L1CSCTrigger")
00306                   << "Put " << clctV1a.size() << " ME1a CLCT digi"
00307                   << ((clctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00308                 oc_clct.put(std::make_pair(clctV1a.begin(),clctV1a.end()), detid1a);
00309               }
00310               
00311               // Cathode LCTs pretriggers
00312               if (!preTriggerBXs1a.empty()) {
00313                 LogTrace("L1CSCTrigger")
00314                   << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00315                   << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00316                 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00317               }
00318             } // upgraded TMB
00319 
00320             // running non-upgraded TMB
00321             else
00322             {
00323               tmb->run(wiredc,compdc);
00324 
00325               std::vector<CSCCorrelatedLCTDigi> lctV = tmb->readoutLCTs();
00326               std::vector<CSCALCTDigi> alctV = tmb->alct->readoutALCTs();
00327               std::vector<CSCCLCTDigi> clctV = tmb->clct->readoutCLCTs();
00328               std::vector<int> preTriggerBXs = tmb->clct->preTriggerBXs();
00329 
00330               if (!(alctV.empty() && clctV.empty() && lctV.empty())) {
00331                 LogTrace("L1CSCTrigger")
00332                   << "CSCTriggerPrimitivesBuilder got results in " <<detid;
00333               }
00334 
00335               /*
00336               // tmp kludge: tightening of ME1a LCTs
00337               if (stat==1 && ring==1) {
00338                 std::vector<CSCCorrelatedLCTDigi> lctV11;
00339                 for (unsigned t=0;t<lctV.size();t++){
00340                   if (lctV[t].getStrip() < 127) lctV11.push_back(lctV[t]);
00341                   else if (lctV[t].getQuality() >= 14) lctV11.push_back(lctV[t]);
00342                 }
00343                 lctV = lctV11;
00344               }
00345               */
00346 
00347               // Correlated LCTs.
00348               if (!lctV.empty()) {
00349                 LogTrace("L1CSCTrigger")
00350                   << "Put " << lctV.size() << " LCT digi"
00351                   << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00352                 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00353               }
00354 
00355               // Anode LCTs.
00356               if (!alctV.empty()) {
00357                 LogTrace("L1CSCTrigger")
00358                   << "Put " << alctV.size() << " ALCT digi"
00359                   << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00360                 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00361               }
00362 
00363               // Cathode LCTs.
00364               if (!clctV.empty()) {
00365                 LogTrace("L1CSCTrigger")
00366                   << "Put " << clctV.size() << " CLCT digi"
00367                   << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00368                 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00369               }
00370 
00371               // Cathode LCTs pretriggers
00372               if (!preTriggerBXs.empty()) {
00373                 LogTrace("L1CSCTrigger")
00374                   << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00375                   << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00376                 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00377               }
00378             } // non-upgraded TMB
00379           }
00380         }
00381       }
00382     }
00383   }
00384 
00385   // run MPC simulation
00386   m_muonportcard->loadDigis(oc_lct);
00387 
00388   std::vector<csctf::TrackStub> result;
00389   for(int bx = m_minBX; bx <= m_maxBX; ++bx)
00390     for(int e = min_endcap; e <= max_endcap; ++e)
00391       for(int st = min_station; st <= max_station; ++st)
00392         for(int se = min_sector; se <= max_sector; ++se)
00393         {
00394           if(st == 1)
00395           {
00396             std::vector<csctf::TrackStub> subs1, subs2;
00397             subs1 = m_muonportcard->sort(e, st, se, 1, bx);
00398             subs2 = m_muonportcard->sort(e, st, se, 2, bx);
00399             result.insert(result.end(), subs1.begin(), subs1.end());
00400             result.insert(result.end(), subs2.begin(), subs2.end());
00401           }
00402           else
00403           {
00404             std::vector<csctf::TrackStub> sector;
00405             sector = m_muonportcard->sort(e, st, se, 0, bx);
00406             result.insert(result.end(), sector.begin(), sector.end());
00407           }
00408         }
00409 
00410   std::vector<csctf::TrackStub>::const_iterator itr = result.begin();
00411   for (; itr != result.end(); itr++)
00412   {
00413     oc_sorted_lct.insertDigi(CSCDetId(itr->getDetId().rawId()), *(itr->getDigi()));
00414     LogDebug("L1CSCTrigger")
00415       << "MPC " << *(itr->getDigi()) << " found in ME"
00416       << ((itr->endcap() == 1) ? "+" : "-") << itr->station() << "/"
00417       << CSCDetId(itr->getDetId().rawId()).ring() << "/"
00418       << CSCDetId(itr->getDetId().rawId()).chamber()
00419       << " (sector " << itr->sector()
00420       << " trig id. " << itr->cscid() << ")" << "\n";
00421   }
00422 }