CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/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 //   $Date: 2010/08/04 14:50:12 $
00012 //   $Revision: 1.20 $
00013 //
00014 //   Modifications:
00015 //
00016 //-----------------------------------------------------------------------------
00017 
00018 #include <L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.h>
00019 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboard.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  =
00036                                   CSCTriggerNumbering::minTriggerSectorId();
00037 const int CSCTriggerPrimitivesBuilder::max_sector  =
00038                                   CSCTriggerNumbering::maxTriggerSectorId();
00039 const int CSCTriggerPrimitivesBuilder::min_subsector =
00040                                   CSCTriggerNumbering::minTriggerSubSectorId();
00041 const int CSCTriggerPrimitivesBuilder::max_subsector =
00042                                   CSCTriggerNumbering::maxTriggerSubSectorId();
00043 const int CSCTriggerPrimitivesBuilder::min_chamber =
00044                                   CSCTriggerNumbering::minTriggerCscId();
00045 const int CSCTriggerPrimitivesBuilder::max_chamber =
00046                                   CSCTriggerNumbering::maxTriggerCscId();
00047 
00048 //-------------
00049 // Constructor
00050 //-------------
00051 CSCTriggerPrimitivesBuilder::CSCTriggerPrimitivesBuilder(const edm::ParameterSet& conf) {
00052   // Receives ParameterSet percolated down from EDProducer.
00053 
00054   // ORCA way of initializing boards.
00055   for (int endc = min_endcap; endc <= max_endcap; endc++) {
00056     for (int stat = min_station; stat <= max_station; stat++) {
00057       int numsubs = ((stat == 1) ? max_subsector : 1);
00058       for (int sect = min_sector; sect <= max_sector; sect++) {
00059         for (int subs = min_subsector; subs <= numsubs; subs++) {
00060           for (int cham = min_chamber; cham <= max_chamber; cham++) {
00061             if ((endc <= 0 || endc > MAX_ENDCAPS)    ||
00062                 (stat <= 0 || stat > MAX_STATIONS)   ||
00063                 (sect <= 0 || sect > MAX_SECTORS)    ||
00064                 (subs <= 0 || subs > MAX_SUBSECTORS) ||
00065                 (cham <= 0 || stat > MAX_CHAMBERS)) {
00066               edm::LogError("L1CSCTPEmulatorSetupError")
00067                 << "+++ trying to instantiate TMB of illegal CSC id ["
00068                 << " endcap = "  << endc << " station = "   << stat
00069                 << " sector = "  << sect << " subsector = " << subs
00070                 << " chamber = " << cham << "]; skipping it... +++\n";
00071               continue;
00072             }
00073             // When the motherboard is instantiated, it instantiates ALCT
00074             // and CLCT processors.
00075             tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] =
00076               new CSCMotherboard(endc, stat, sect, subs, cham, conf);
00077           }
00078         }
00079       }
00080     }
00081   }
00082 
00083   // Get min and max BX to sort LCTs in MPC.
00084   m_minBX = conf.getParameter<int>("MinBX");
00085   m_maxBX = conf.getParameter<int>("MaxBX");
00086 
00087   // Init MPC
00088   m_muonportcard = new CSCMuonPortCard();
00089 }
00090 
00091 //------------
00092 // Destructor
00093 //------------
00094 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder() {
00095   for (int endc = min_endcap; endc <= max_endcap; endc++) {
00096     for (int stat = min_station; stat <= max_station; stat++) {
00097       int numsubs = ((stat == 1) ? max_subsector : 1);
00098       for (int sect = min_sector; sect <= max_sector; sect++) {
00099         for (int subs = min_subsector; subs <= numsubs; subs++) {
00100           for (int cham = min_chamber; cham <= max_chamber; cham++) {
00101             delete tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00102           }
00103         }
00104       }
00105     }
00106   }
00107   delete m_muonportcard;
00108 }
00109 
00110 //------------
00111 // Operations
00112 //------------
00113 // Set configuration parameters obtained via EventSetup mechanism.
00114 void CSCTriggerPrimitivesBuilder::setConfigParameters(const CSCDBL1TPParameters* conf) {
00115   // Receives CSCDBL1TPParameters percolated down from ESProducer.
00116 
00117   for (int endc = min_endcap; endc <= max_endcap; endc++) {
00118     for (int stat = min_station; stat <= max_station; stat++) {
00119       int numsubs = ((stat == 1) ? max_subsector : 1);
00120       for (int sect = min_sector; sect <= max_sector; sect++) {
00121         for (int subs = min_subsector; subs <= numsubs; subs++) {
00122           for (int cham = min_chamber; cham <= max_chamber; cham++) {
00123             CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00124             tmb->setConfigParameters(conf);
00125           }
00126         }
00127       }
00128     }
00129   }
00130 }
00131 
00132 // Build anode, cathode, and correlated LCTs in each chamber and fill them
00133 // into output collections.  Pass collections of wire and comparator digis
00134 // to Trigger MotherBoard (TMB) processors, which, in turn, pass them to
00135 // ALCT and CLCT processors.  Up to 2 anode and 2 cathode LCTs can be found
00136 // in each chamber during any bunch crossing.  The 2 projections are then
00137 // combined into three-dimensional "correlated" LCTs in the TMB.  Finally,
00138 // MPC processor sorts up to 18 LCTs from 9 TMBs and writes collections of
00139 // up to 3 best LCTs per (sub)sector into Event (to be used by the Sector
00140 // Receiver).
00141 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
00142                                         const CSCWireDigiCollection* wiredc,
00143                                         const CSCComparatorDigiCollection* compdc,
00144                                         CSCALCTDigiCollection& oc_alct,
00145                                         CSCCLCTDigiCollection& oc_clct,
00146                                         CSCCLCTPreTriggerCollection & oc_pretrig,
00147                                         CSCCorrelatedLCTDigiCollection& oc_lct,
00148                                         CSCCorrelatedLCTDigiCollection& oc_sorted_lct) {
00149   // CSC geometry.
00150   CSCTriggerGeomManager* theGeom = CSCTriggerGeometry::get();
00151 
00152   for (int endc = min_endcap; endc <= max_endcap; endc++) {
00153     for (int stat = min_station; stat <= max_station; stat++) {
00154       int numsubs = ((stat == 1) ? max_subsector : 1);
00155       for (int sect = min_sector; sect <= max_sector; sect++) {
00156         for (int subs = min_subsector; subs <= numsubs; subs++) {
00157           for (int cham = min_chamber; cham <= max_chamber; cham++) {
00158             CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00159 
00160             // Run processors only if chamber exists in geometry.
00161             if (tmb != 0 &&
00162                 theGeom->chamber(endc, stat, sect, subs, cham) != 0) {
00163 
00164               // Calculate DetId.
00165               int ring =
00166                 CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00167               int chid =
00168                 CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs,
00169                                                               stat, cham);
00170               // 0th layer means whole chamber.
00171               CSCDetId detid(endc, stat, ring, chid, 0);
00172 
00173               // Skip chambers marked as bad (includes most of ME4/2 chambers).
00174               if (badChambers->isInBadChamber(detid)) continue;
00175 
00176               std::vector<CSCCorrelatedLCTDigi> lctV = tmb->run(wiredc,compdc);
00177 
00178               std::vector<CSCALCTDigi> alctV = tmb->alct->readoutALCTs();
00179               std::vector<CSCCLCTDigi> clctV = tmb->clct->readoutCLCTs();
00180               std::vector<int> preTriggerBXs = tmb->clct->preTriggerBXs();
00181 
00182               // Skip to next chamber if there are no LCTs to save.
00183               if (alctV.empty() && clctV.empty() && lctV.empty()) continue;
00184 
00185               // Correlated LCTs.
00186               if (!lctV.empty()) {
00187                 LogTrace("L1CSCTrigger")
00188                   << "Put " << lctV.size() << " LCT digi"
00189                   << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00190                 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00191               }
00192 
00193               // Anode LCTs.
00194               if (!alctV.empty()) {
00195                 LogTrace("L1CSCTrigger")
00196                   << "Put " << alctV.size() << " ALCT digi"
00197                   << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00198                 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00199               }
00200 
00201               // Cathode LCTs.
00202               if (!clctV.empty()) {
00203                 LogTrace("L1CSCTrigger")
00204                   << "Put " << clctV.size() << " CLCT digi"
00205                   << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00206                 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00207               }
00208 
00209               // Cathode LCTs pretriggers
00210               if (!preTriggerBXs.empty()) {
00211                 LogTrace("L1CSCTrigger")
00212                   << "Put " << preTriggerBXs.size() << " CLCT pretriggers"
00213                   << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00214                 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00215               }
00216             }
00217           }
00218         }
00219       }
00220     }
00221   }
00222 
00223   // run MPC simulation
00224   m_muonportcard->loadDigis(oc_lct);
00225 
00226   std::vector<csctf::TrackStub> result;
00227   for(int bx = m_minBX; bx <= m_maxBX; ++bx)
00228     for(int e = min_endcap; e <= max_endcap; ++e)
00229       for(int st = min_station; st <= max_station; ++st)
00230         for(int se = min_sector; se <= max_sector; ++se)
00231           {
00232             if(st == 1)
00233               {
00234                 std::vector<csctf::TrackStub> subs1, subs2;
00235                 subs1 = m_muonportcard->sort(e, st, se, 1, bx);
00236                 subs2 = m_muonportcard->sort(e, st, se, 2, bx);
00237                 result.insert(result.end(), subs1.begin(), subs1.end());
00238                 result.insert(result.end(), subs2.begin(), subs2.end());
00239               }
00240             else
00241               {
00242                 std::vector<csctf::TrackStub> sector;
00243                 sector = m_muonportcard->sort(e, st, se, 0, bx);
00244                 result.insert(result.end(), sector.begin(), sector.end());
00245               }
00246           }
00247 
00248   std::vector<csctf::TrackStub>::const_iterator itr = result.begin();
00249   for (; itr != result.end(); itr++) {
00250     oc_sorted_lct.insertDigi(CSCDetId(itr->getDetId().rawId()), *(itr->getDigi()));
00251     LogDebug("L1CSCTrigger")
00252       << "MPC " << *(itr->getDigi()) << " found in ME"
00253       << ((itr->endcap() == 1) ? "+" : "-") << itr->station() << "/"
00254       << CSCDetId(itr->getDetId().rawId()).ring() << "/"
00255       << CSCDetId(itr->getDetId().rawId()).chamber()
00256       << " (sector " << itr->sector()
00257       << " trig id. " << itr->cscid() << ")" << "\n";
00258   }
00259 }