Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:44

0001 #include <memory>
0002 
0003 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCTriggerPrimitivesBuilder.h"
0004 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCMotherboard.h"
0005 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCGEMMotherboard.h"
0006 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCMuonPortCard.h"
0007 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0008 
0009 const int CSCTriggerPrimitivesBuilder::min_endcap = CSCDetId::minEndcapId();
0010 const int CSCTriggerPrimitivesBuilder::max_endcap = CSCDetId::maxEndcapId();
0011 const int CSCTriggerPrimitivesBuilder::min_station = CSCDetId::minStationId();
0012 const int CSCTriggerPrimitivesBuilder::max_station = CSCDetId::maxStationId();
0013 const int CSCTriggerPrimitivesBuilder::min_sector = CSCTriggerNumbering::minTriggerSectorId();
0014 const int CSCTriggerPrimitivesBuilder::max_sector = CSCTriggerNumbering::maxTriggerSectorId();
0015 const int CSCTriggerPrimitivesBuilder::min_subsector = CSCTriggerNumbering::minTriggerSubSectorId();
0016 const int CSCTriggerPrimitivesBuilder::max_subsector = CSCTriggerNumbering::maxTriggerSubSectorId();
0017 const int CSCTriggerPrimitivesBuilder::min_chamber = CSCTriggerNumbering::minTriggerCscId();
0018 const int CSCTriggerPrimitivesBuilder::max_chamber = CSCTriggerNumbering::maxTriggerCscId();
0019 
0020 CSCTriggerPrimitivesBuilder::CSCTriggerPrimitivesBuilder(const edm::ParameterSet& conf) {
0021   // special configuration parameters for ME11 treatment
0022   edm::ParameterSet commonParams = conf.getParameter<edm::ParameterSet>("commonParam");
0023   runPhase2_ = commonParams.getParameter<bool>("runPhase2");
0024   infoV = commonParams.getParameter<int>("verbosity");
0025   disableME42_ = commonParams.getParameter<bool>("disableME42");
0026 
0027   checkBadChambers_ = conf.getParameter<bool>("checkBadChambers");
0028   selectedChambers_ = conf.getParameter<std::vector<std::string>>("selectedChambers");
0029 
0030   runME11Up_ = commonParams.getParameter<bool>("runME11Up");
0031   runME21Up_ = commonParams.getParameter<bool>("runME21Up");
0032 
0033   runME11ILT_ = commonParams.getParameter<bool>("runME11ILT");
0034   runME21ILT_ = commonParams.getParameter<bool>("runME21ILT");
0035 
0036   // Initializing boards.
0037   CSCBaseboard::Parameters baseparams(conf);
0038   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0039     for (int stat = min_station; stat <= max_station; stat++) {
0040       int numsubs = ((stat == 1) ? max_subsector : 1);
0041       for (int sect = min_sector; sect <= max_sector; sect++) {
0042         for (int subs = min_subsector; subs <= numsubs; subs++) {
0043           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0044             if ((endc <= 0 || endc > MAX_ENDCAPS) || (stat <= 0 || stat > MAX_STATIONS) ||
0045                 (sect <= 0 || sect > MAX_SECTORS) || (subs <= 0 || subs > MAX_SUBSECTORS) ||
0046                 (cham <= 0 || cham > MAX_CHAMBERS)) {
0047               edm::LogError("CSCTriggerPrimitivesBuilder|SetupError")
0048                   << "+++ trying to instantiate TMB of illegal CSC id ["
0049                   << " endcap = " << endc << " station = " << stat << " sector = " << sect << " subsector = " << subs
0050                   << " chamber = " << cham << "]; skipping it... +++\n";
0051               continue;
0052             }
0053             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
0054             // When the motherboard is instantiated, it instantiates ALCT
0055             // and CLCT processors.
0056 
0057             const bool upgrade = runPhase2_ and ring == 1;
0058             const bool upgradeGE11 = upgrade and stat == 1 and runME11Up_ and runME11ILT_;
0059             const bool upgradeGE21 = upgrade and stat == 2 and runME21Up_ and runME21ILT_;
0060 
0061             // GE1/1-ME1/1 integrated local trigger or GE2/1-ME2/1 integrated local trigger
0062             if (upgradeGE11 or upgradeGE21)
0063               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1] =
0064                   std::make_unique<CSCGEMMotherboard>(endc, stat, sect, subs, cham, baseparams);
0065             // default case
0066             else
0067               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1] =
0068                   std::make_unique<CSCMotherboard>(endc, stat, sect, subs, cham, baseparams);
0069           }
0070         }
0071         // Init MPC
0072         mpc_[endc - 1][stat - 1][sect - 1] = std::make_unique<CSCMuonPortCard>(endc, stat, sect, conf);
0073       }
0074     }
0075   }
0076 }
0077 
0078 //------------
0079 // Destructor
0080 //------------
0081 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder() {}
0082 
0083 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
0084                                         const CSCWireDigiCollection* wiredc,
0085                                         const CSCComparatorDigiCollection* compdc,
0086                                         const GEMPadDigiClusterCollection* gemClusters,
0087                                         const BuildContext& context,
0088                                         CSCALCTDigiCollection& oc_alct,
0089                                         CSCCLCTDigiCollection& oc_clct,
0090                                         CSCALCTPreTriggerDigiCollection& oc_alctpretrigger,
0091                                         CSCCLCTPreTriggerDigiCollection& oc_pretrigger,
0092                                         CSCCLCTPreTriggerCollection& oc_pretrig,
0093                                         CSCCorrelatedLCTDigiCollection& oc_lct,
0094                                         CSCCorrelatedLCTDigiCollection& oc_sorted_lct,
0095                                         CSCShowerDigiCollection& oc_shower_anode,
0096                                         CSCShowerDigiCollection& oc_shower_cathode,
0097                                         CSCShowerDigiCollection& oc_shower,
0098                                         GEMCoPadDigiCollection& oc_gemcopad) {
0099   // CSC geometry.
0100   CSCMotherboard::RunContext mbcontext{
0101       context.cscgeom_, context.cclut_, context.me11ilt_, context.me21ilt_, context.parameters_};
0102 
0103   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0104     for (int stat = min_station; stat <= max_station; stat++) {
0105       int numsubs = ((stat == 1) ? max_subsector : 1);
0106       for (int sect = min_sector; sect <= max_sector; sect++) {
0107         for (int subs = min_subsector; subs <= numsubs; subs++) {
0108           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0109             // extract the ring number
0110             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
0111 
0112             // case when you want to ignore ME42
0113             if (disableME42_ && stat == 4 && ring == 2)
0114               continue;
0115 
0116             CSCMotherboard* tmb = tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1].get();
0117 
0118             // actual chamber number =/= trigger chamber number
0119             int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
0120 
0121             // 0th layer means whole chamber.
0122             CSCDetId detid(endc, stat, ring, chid, 0);
0123 
0124             // Run processors only if chamber exists in geometry.
0125             if (tmb == nullptr || context.cscgeom_->chamber(detid) == nullptr)
0126               continue;
0127 
0128             // Skip chambers marked as bad (usually includes most of ME4/2 chambers;
0129             // also, there's no ME1/a-1/b separation, it's whole ME1/1)
0130             if (checkBadChambers_ && badChambers->isInBadChamber(detid))
0131               continue;
0132 
0133             //only process the selected chambers when selectedChambers is not empty
0134             if (!selectedChambers_.empty()) {
0135               if (std::find(selectedChambers_.begin(), selectedChambers_.end(), detid.chamberName()) ==
0136                   selectedChambers_.end()) {
0137                 continue;
0138               }
0139             }
0140             const bool upgrade = runPhase2_ and ring == 1;
0141             const bool upgradeGE11 = upgrade and stat == 1 and runME11Up_ and runME11ILT_;
0142             const bool upgradeGE21 = upgrade and stat == 2 and runME21Up_ and runME21ILT_;
0143 
0144             // GE1/1-ME1/1 integrated local trigger or GE2/1-ME2/1 integrated local trigger
0145             if (upgradeGE11 or upgradeGE21) {
0146               // run the TMB
0147               CSCGEMMotherboard::RunContext c{context.gemgeom_,
0148                                               context.cscgeom_,
0149                                               context.cclut_,
0150                                               context.me11ilt_,
0151                                               context.me21ilt_,
0152                                               context.parameters_};
0153               CSCGEMMotherboard* tmbGEM = static_cast<CSCGEMMotherboard*>(tmb);
0154               tmbGEM->run(wiredc, compdc, gemClusters, c);
0155 
0156               // 0th layer means whole chamber.
0157               GEMDetId gemId(detid.zendcap(), 1, stat, 0, chid, 0);
0158               const std::vector<GEMCoPadDigi>& copads = tmbGEM->clusterProc()->readoutCoPads();
0159               put(copads, oc_gemcopad, gemId, " GEM coincidence pad");
0160             }
0161             // default case: regular TMBs and OTMBs without GEMs
0162             else {
0163               // run the TMB
0164               tmb->run(wiredc, compdc, mbcontext);
0165             }
0166 
0167             // get the collections
0168 
0169             // trigger primitives
0170             const std::vector<CSCALCTDigi>& alctV = tmb->alctProc->readoutALCTs();
0171             const std::vector<CSCCLCTDigi>& clctV = tmb->clctProc->readoutCLCTs();
0172             const std::vector<CSCCorrelatedLCTDigi>& lctV = tmb->readoutLCTs();
0173 
0174             // pre-triggers
0175             const std::vector<int>& preTriggerBXs = tmb->clctProc->preTriggerBXs();
0176             const std::vector<CSCCLCTPreTriggerDigi>& pretriggerV = tmb->clctProc->preTriggerDigis();
0177             const std::vector<CSCALCTPreTriggerDigi>& alctpretriggerV = tmb->alctProc->preTriggerDigis();
0178 
0179             // showers
0180             const std::vector<CSCShowerDigi>& shower = tmb->readoutShower();
0181             const std::vector<CSCShowerDigi>& anodeShower = tmb->alctProc->readoutShower();
0182             const std::vector<CSCShowerDigi>& cathodeShower = tmb->clctProc->readoutShower();
0183 
0184             put(alctV, oc_alct, detid, tmb->getCSCName() + " ALCT digi");
0185             put(clctV, oc_clct, detid, tmb->getCSCName() + " CLCT digi");
0186             put(lctV, oc_lct, detid, tmb->getCSCName() + " LCT digi");
0187 
0188             put(preTriggerBXs, oc_pretrig, detid, tmb->getCSCName() + " CLCT pre-trigger BX");
0189             put(pretriggerV, oc_pretrigger, detid, tmb->getCSCName() + " CLCT pre-trigger digi");
0190             put(alctpretriggerV, oc_alctpretrigger, detid, tmb->getCSCName() + " ALCT pre-trigger digi");
0191 
0192             put(shower, oc_shower, detid, tmb->getCSCName() + "TMB shower");
0193             put(anodeShower, oc_shower_anode, detid, tmb->getCSCName() + "Anode shower");
0194             put(cathodeShower, oc_shower_cathode, detid, tmb->getCSCName() + "Cathode shower");
0195             //if (shower.isValid())
0196             //  oc_shower.insertDigi(detid, shower);
0197             //if (anodeShower.isValid())
0198             //  oc_shower_anode.insertDigi(detid, anodeShower);
0199             //if (cathodeShower.isValid())
0200             //  oc_shower_cathode.insertDigi(detid, cathodeShower);
0201 
0202             if (!(alctV.empty() && clctV.empty() && lctV.empty()) and infoV > 1) {
0203               LogTrace("L1CSCTrigger") << "CSCTriggerPrimitivesBuilder got results in " << detid;
0204             }
0205           }  // end loop on cham
0206         }  // end loop on subs
0207       }  // end loop on sect
0208     }  // end loop on stat
0209   }  // end loop on endc
0210 
0211   // run MPC simulation
0212   // there are 2 x 4 x 6 MPC VME cards
0213   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0214     for (int stat = min_station; stat <= max_station; stat++) {
0215       for (int sect = min_sector; sect <= max_sector; sect++) {
0216         auto mpc = mpc_[endc - 1][stat - 1][sect - 1].get();
0217 
0218         // load the LCTs relevant for this MPC
0219         mpc->loadLCTs(oc_lct);
0220 
0221         // sort and select the LCTs (if applicable)
0222         mpc->sortLCTs();
0223 
0224         // get sorted+selected LCTs
0225         const auto& result = mpc->getLCTs();
0226 
0227         // now convert csctf::TrackStub back into CSCCorrelatedLCTDigi
0228         // put MPC stubs into the event
0229         for (const auto& lct : result) {
0230           oc_sorted_lct.insertDigi(CSCDetId(lct.getDetId().rawId()), *(lct.getDigi()));
0231           if (infoV > 1)
0232             LogDebug("CSCTriggerPrimitivesBuilder")
0233                 << "MPC " << *(lct.getDigi()) << " found in ME" << ((lct.endcap() == 1) ? "+" : "-") << lct.station()
0234                 << "/" << CSCDetId(lct.getDetId().rawId()).ring() << "/" << CSCDetId(lct.getDetId().rawId()).chamber()
0235                 << " (sector " << lct.sector() << " trig id. " << lct.cscid() << ")"
0236                 << "\n";
0237         }
0238       }
0239     }
0240   }
0241 }