Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-02 08:36:18

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   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0038     for (int stat = min_station; stat <= max_station; stat++) {
0039       int numsubs = ((stat == 1) ? max_subsector : 1);
0040       for (int sect = min_sector; sect <= max_sector; sect++) {
0041         for (int subs = min_subsector; subs <= numsubs; subs++) {
0042           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0043             if ((endc <= 0 || endc > MAX_ENDCAPS) || (stat <= 0 || stat > MAX_STATIONS) ||
0044                 (sect <= 0 || sect > MAX_SECTORS) || (subs <= 0 || subs > MAX_SUBSECTORS) ||
0045                 (cham <= 0 || cham > MAX_CHAMBERS)) {
0046               edm::LogError("CSCTriggerPrimitivesBuilder|SetupError")
0047                   << "+++ trying to instantiate TMB of illegal CSC id ["
0048                   << " endcap = " << endc << " station = " << stat << " sector = " << sect << " subsector = " << subs
0049                   << " chamber = " << cham << "]; skipping it... +++\n";
0050               continue;
0051             }
0052             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
0053             // When the motherboard is instantiated, it instantiates ALCT
0054             // and CLCT processors.
0055 
0056             const bool upgrade = runPhase2_ and ring == 1;
0057             const bool upgradeGE11 = upgrade and stat == 1 and runME11Up_ and runME11ILT_;
0058             const bool upgradeGE21 = upgrade and stat == 2 and runME21Up_ and runME21ILT_;
0059 
0060             // GE1/1-ME1/1 integrated local trigger or GE2/1-ME2/1 integrated local trigger
0061             if (upgradeGE11 or upgradeGE21)
0062               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1] =
0063                   std::make_unique<CSCGEMMotherboard>(endc, stat, sect, subs, cham, conf);
0064             // default case
0065             else
0066               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1] =
0067                   std::make_unique<CSCMotherboard>(endc, stat, sect, subs, cham, conf);
0068           }
0069         }
0070         // Init MPC
0071         mpc_[endc - 1][stat - 1][sect - 1] = std::make_unique<CSCMuonPortCard>(endc, stat, sect, conf);
0072       }
0073     }
0074   }
0075 }
0076 
0077 //------------
0078 // Destructor
0079 //------------
0080 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder() {}
0081 
0082 void CSCTriggerPrimitivesBuilder::setConfigParameters(const CSCDBL1TPParameters* conf) {
0083   // Receives CSCDBL1TPParameters percolated down from ESProducer.
0084 
0085   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0086     for (int stat = min_station; stat <= max_station; stat++) {
0087       int numsubs = ((stat == 1) ? max_subsector : 1);
0088       for (int sect = min_sector; sect <= max_sector; sect++) {
0089         for (int subs = min_subsector; subs <= numsubs; subs++) {
0090           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0091             tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->setConfigParameters(conf);
0092           }
0093         }
0094       }
0095     }
0096   }
0097 }
0098 
0099 void CSCTriggerPrimitivesBuilder::setESLookupTables(const CSCL1TPLookupTableCCLUT* conf) {
0100   // Receives CSCL1TPLookupTableCCLUT percolated down from ESProducer.
0101   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0102     for (int stat = min_station; stat <= max_station; stat++) {
0103       int numsubs = ((stat == 1) ? max_subsector : 1);
0104       for (int sect = min_sector; sect <= max_sector; sect++) {
0105         for (int subs = min_subsector; subs <= numsubs; subs++) {
0106           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0107             tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->setESLookupTables(conf);
0108           }
0109         }
0110       }
0111     }
0112   }
0113 }
0114 
0115 void CSCTriggerPrimitivesBuilder::setESLookupTables(const CSCL1TPLookupTableME11ILT* conf) {
0116   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0117     for (int stat = min_station; stat <= max_station; stat++) {
0118       int numsubs = ((stat == 1) ? max_subsector : 1);
0119       for (int sect = min_sector; sect <= max_sector; sect++) {
0120         for (int subs = min_subsector; subs <= numsubs; subs++) {
0121           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0122             if (tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->id().isME11())
0123               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->setESLookupTables(conf);
0124           }
0125         }
0126       }
0127     }
0128   }
0129 }
0130 
0131 void CSCTriggerPrimitivesBuilder::setESLookupTables(const CSCL1TPLookupTableME21ILT* conf) {
0132   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0133     for (int stat = min_station; stat <= max_station; stat++) {
0134       int numsubs = ((stat == 1) ? max_subsector : 1);
0135       for (int sect = min_sector; sect <= max_sector; sect++) {
0136         for (int subs = min_subsector; subs <= numsubs; subs++) {
0137           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0138             if (tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->id().isME21())
0139               tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1]->setESLookupTables(conf);
0140           }
0141         }
0142       }
0143     }
0144   }
0145 }
0146 
0147 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
0148                                         const CSCWireDigiCollection* wiredc,
0149                                         const CSCComparatorDigiCollection* compdc,
0150                                         const GEMPadDigiClusterCollection* gemClusters,
0151                                         CSCALCTDigiCollection& oc_alct,
0152                                         CSCCLCTDigiCollection& oc_clct,
0153                                         CSCALCTPreTriggerDigiCollection& oc_alctpretrigger,
0154                                         CSCCLCTPreTriggerDigiCollection& oc_pretrigger,
0155                                         CSCCLCTPreTriggerCollection& oc_pretrig,
0156                                         CSCCorrelatedLCTDigiCollection& oc_lct,
0157                                         CSCCorrelatedLCTDigiCollection& oc_sorted_lct,
0158                                         CSCShowerDigiCollection& oc_shower_anode,
0159                                         CSCShowerDigiCollection& oc_shower_cathode,
0160                                         CSCShowerDigiCollection& oc_shower,
0161                                         GEMCoPadDigiCollection& oc_gemcopad) {
0162   // CSC geometry.
0163   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0164     for (int stat = min_station; stat <= max_station; stat++) {
0165       int numsubs = ((stat == 1) ? max_subsector : 1);
0166       for (int sect = min_sector; sect <= max_sector; sect++) {
0167         for (int subs = min_subsector; subs <= numsubs; subs++) {
0168           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0169             // extract the ring number
0170             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
0171 
0172             // case when you want to ignore ME42
0173             if (disableME42_ && stat == 4 && ring == 2)
0174               continue;
0175 
0176             CSCMotherboard* tmb = tmb_[endc - 1][stat - 1][sect - 1][subs - 1][cham - 1].get();
0177 
0178             tmb->setCSCGeometry(csc_g);
0179 
0180             // actual chamber number =/= trigger chamber number
0181             int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
0182 
0183             // 0th layer means whole chamber.
0184             CSCDetId detid(endc, stat, ring, chid, 0);
0185 
0186             // Run processors only if chamber exists in geometry.
0187             if (tmb == nullptr || csc_g->chamber(detid) == nullptr)
0188               continue;
0189 
0190             // Skip chambers marked as bad (usually includes most of ME4/2 chambers;
0191             // also, there's no ME1/a-1/b separation, it's whole ME1/1)
0192             if (checkBadChambers_ && badChambers->isInBadChamber(detid))
0193               continue;
0194 
0195             //only process the selected chambers when selectedChambers is not empty
0196             if (!selectedChambers_.empty()) {
0197               if (std::find(selectedChambers_.begin(), selectedChambers_.end(), detid.chamberName()) ==
0198                   selectedChambers_.end()) {
0199                 continue;
0200               }
0201             }
0202             const bool upgrade = runPhase2_ and ring == 1;
0203             const bool upgradeGE11 = upgrade and stat == 1 and runME11Up_ and runME11ILT_;
0204             const bool upgradeGE21 = upgrade and stat == 2 and runME21Up_ and runME21ILT_;
0205 
0206             // GE1/1-ME1/1 integrated local trigger or GE2/1-ME2/1 integrated local trigger
0207             if (upgradeGE11 or upgradeGE21) {
0208               // run the TMB
0209               CSCGEMMotherboard* tmbGEM = static_cast<CSCGEMMotherboard*>(tmb);
0210               tmbGEM->setGEMGeometry(gem_g);
0211               tmbGEM->setCSCGeometry(csc_g);
0212               tmbGEM->run(wiredc, compdc, gemClusters);
0213 
0214               // 0th layer means whole chamber.
0215               GEMDetId gemId(detid.zendcap(), 1, stat, 0, chid, 0);
0216               const std::vector<GEMCoPadDigi>& copads = tmbGEM->clusterProc()->readoutCoPads();
0217               put(copads, oc_gemcopad, gemId, " GEM coincidence pad");
0218             }
0219             // default case: regular TMBs and OTMBs without GEMs
0220             else {
0221               // run the TMB
0222               tmb->run(wiredc, compdc);
0223             }
0224 
0225             // get the collections
0226 
0227             // trigger primitives
0228             const std::vector<CSCALCTDigi>& alctV = tmb->alctProc->readoutALCTs();
0229             const std::vector<CSCCLCTDigi>& clctV = tmb->clctProc->readoutCLCTs();
0230             const std::vector<CSCCorrelatedLCTDigi>& lctV = tmb->readoutLCTs();
0231 
0232             // pre-triggers
0233             const std::vector<int>& preTriggerBXs = tmb->clctProc->preTriggerBXs();
0234             const std::vector<CSCCLCTPreTriggerDigi>& pretriggerV = tmb->clctProc->preTriggerDigis();
0235             const std::vector<CSCALCTPreTriggerDigi>& alctpretriggerV = tmb->alctProc->preTriggerDigis();
0236 
0237             // showers
0238             const std::vector<CSCShowerDigi>& shower = tmb->readoutShower();
0239             const std::vector<CSCShowerDigi>& anodeShower = tmb->alctProc->readoutShower();
0240             const std::vector<CSCShowerDigi>& cathodeShower = tmb->clctProc->readoutShower();
0241 
0242             put(alctV, oc_alct, detid, tmb->getCSCName() + " ALCT digi");
0243             put(clctV, oc_clct, detid, tmb->getCSCName() + " CLCT digi");
0244             put(lctV, oc_lct, detid, tmb->getCSCName() + " LCT digi");
0245 
0246             put(preTriggerBXs, oc_pretrig, detid, tmb->getCSCName() + " CLCT pre-trigger BX");
0247             put(pretriggerV, oc_pretrigger, detid, tmb->getCSCName() + " CLCT pre-trigger digi");
0248             put(alctpretriggerV, oc_alctpretrigger, detid, tmb->getCSCName() + " ALCT pre-trigger digi");
0249 
0250             put(shower, oc_shower, detid, tmb->getCSCName() + "TMB shower");
0251             put(anodeShower, oc_shower_anode, detid, tmb->getCSCName() + "Anode shower");
0252             put(cathodeShower, oc_shower_cathode, detid, tmb->getCSCName() + "Cathode shower");
0253             //if (shower.isValid())
0254             //  oc_shower.insertDigi(detid, shower);
0255             //if (anodeShower.isValid())
0256             //  oc_shower_anode.insertDigi(detid, anodeShower);
0257             //if (cathodeShower.isValid())
0258             //  oc_shower_cathode.insertDigi(detid, cathodeShower);
0259 
0260             if (!(alctV.empty() && clctV.empty() && lctV.empty()) and infoV > 1) {
0261               LogTrace("L1CSCTrigger") << "CSCTriggerPrimitivesBuilder got results in " << detid;
0262             }
0263           }  // end loop on cham
0264         }    // end loop on subs
0265       }      // end loop on sect
0266     }        // end loop on stat
0267   }          // end loop on endc
0268 
0269   // run MPC simulation
0270   // there are 2 x 4 x 6 MPC VME cards
0271   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0272     for (int stat = min_station; stat <= max_station; stat++) {
0273       for (int sect = min_sector; sect <= max_sector; sect++) {
0274         auto mpc = mpc_[endc - 1][stat - 1][sect - 1].get();
0275 
0276         // load the LCTs relevant for this MPC
0277         mpc->loadLCTs(oc_lct);
0278 
0279         // sort and select the LCTs (if applicable)
0280         mpc->sortLCTs();
0281 
0282         // get sorted+selected LCTs
0283         const auto& result = mpc->getLCTs();
0284 
0285         // now convert csctf::TrackStub back into CSCCorrelatedLCTDigi
0286         // put MPC stubs into the event
0287         for (const auto& lct : result) {
0288           oc_sorted_lct.insertDigi(CSCDetId(lct.getDetId().rawId()), *(lct.getDigi()));
0289           if (infoV > 1)
0290             LogDebug("CSCTriggerPrimitivesBuilder")
0291                 << "MPC " << *(lct.getDigi()) << " found in ME" << ((lct.endcap() == 1) ? "+" : "-") << lct.station()
0292                 << "/" << CSCDetId(lct.getDetId().rawId()).ring() << "/" << CSCDetId(lct.getDetId().rawId()).chamber()
0293                 << " (sector " << lct.sector() << " trig id. " << lct.cscid() << ")"
0294                 << "\n";
0295         }
0296       }
0297     }
0298   }
0299 }