Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:21

0001 #include "L1Trigger/L1TNtuples/interface/L1AnalysisCSCTF.h"
0002 
0003 L1Analysis::L1AnalysisCSCTF::L1AnalysisCSCTF() {}
0004 
0005 L1Analysis::L1AnalysisCSCTF::~L1AnalysisCSCTF() {}
0006 
0007 void L1Analysis::L1AnalysisCSCTF::SetTracks(const edm::Handle<L1CSCTrackCollection> csctfTrks,
0008                                             const L1MuTriggerScales* ts,
0009                                             const L1MuTriggerPtScale* tpts,
0010                                             CSCSectorReceiverLUT* srLUTs_[5][2],
0011                                             CSCTFPtLUT* ptLUTs_) {
0012   //for (int i =0; i<MAXCSCTFTR; i++) csctf_.trSector[i]=0;
0013 
0014   csctf_.trSize = csctfTrks->size();
0015   //cout << " csctf_.trSize: " << csctf_.trSize << endl;
0016 
0017   int nTrk = 0;
0018   for (L1CSCTrackCollection::const_iterator trk = csctfTrks->begin(); trk < csctfTrks->end(); trk++) {
0019     nTrk++;
0020 
0021     // trk->first.endcap() = 2 for - endcap
0022     //                     = 1 for + endcap
0023     csctf_.trEndcap.push_back(trk->first.endcap() == 2 ? trk->first.endcap() - 3 : trk->first.endcap());
0024     //sectors: 1->6 (plus endcap), 7->12 (minus endcap)
0025     csctf_.trSector.push_back(6 * (trk->first.endcap() - 1) + trk->first.sector());
0026     csctf_.trBx.push_back(trk->first.BX());
0027 
0028     csctf_.trME1ID.push_back(trk->first.me1ID());
0029     csctf_.trME2ID.push_back(trk->first.me2ID());
0030     csctf_.trME3ID.push_back(trk->first.me3ID());
0031     csctf_.trME4ID.push_back(trk->first.me4ID());
0032     csctf_.trMB1ID.push_back(trk->first.mb1ID());
0033 
0034     csctf_.trME1TBin.push_back(trk->first.me1Tbin());
0035     csctf_.trME2TBin.push_back(trk->first.me2Tbin());
0036     csctf_.trME3TBin.push_back(trk->first.me3Tbin());
0037     csctf_.trME4TBin.push_back(trk->first.me4Tbin());
0038     csctf_.trMB1TBin.push_back(trk->first.mb1Tbin());
0039 
0040     // output link of the track
0041     csctf_.trOutputLink.push_back(trk->first.outputLink());
0042 
0043     // PtAddress gives an handle on other parameters
0044     ptadd thePtAddress(trk->first.ptLUTAddress());
0045 
0046     csctf_.trPhiSign.push_back(thePtAddress.delta_phi_sign);
0047     csctf_.trPhi12.push_back(thePtAddress.delta_phi_12);
0048     csctf_.trPhi23.push_back(thePtAddress.delta_phi_23);
0049     csctf_.trMode.push_back(thePtAddress.track_mode);
0050     csctf_.trForR.push_back(thePtAddress.track_fr);
0051     csctf_.trCharge.push_back(trk->first.chargeValue());
0052 
0053     //Pt needs some more workaround since it is not in the unpacked data
0054     ////ptdat thePtData  = ptLUT->Pt(thePtAddress);
0055     ptdat thePtData = ptLUTs_->Pt(thePtAddress);
0056 
0057     // front or rear bit?
0058     if (thePtAddress.track_fr) {
0059       csctf_.trPtBit.push_back(thePtData.front_rank & 0x1f);
0060       csctf_.trQuality.push_back((thePtData.front_rank >> 5) & 0x3);
0061       csctf_.trChargeValid.push_back(thePtData.charge_valid_front);
0062     } else {
0063       csctf_.trPtBit.push_back(thePtData.rear_rank & 0x1f);
0064       csctf_.trQuality.push_back((thePtData.rear_rank >> 5) & 0x3);
0065       csctf_.trChargeValid.push_back(thePtData.charge_valid_rear);
0066     }
0067 
0068     // convert the Pt in human readable values (GeV/c)
0069     csctf_.trPt.push_back(tpts->getPtScale()->getLowEdge(csctf_.trPtBit.back()));
0070 
0071     // track's Eta and Phi in bit...
0072     csctf_.trEtaBit.push_back(trk->first.eta_packed());
0073     csctf_.trPhiBit.push_back(trk->first.localPhi());
0074 
0075     //... in radians
0076     // Type 2 is CSC
0077     //csctf_.trEta.push_back(theTriggerScales->getRegionalEtaScale(2)->getCenter(trk->first.eta_packed()));
0078     //csctf_.trPhi.push_back(theTriggerScales->getPhiScale()->getLowEdge(trk->first.localPhi()));
0079     csctf_.trEta.push_back(ts->getRegionalEtaScale(2)->getCenter(trk->first.eta_packed()));
0080     csctf_.trPhi.push_back(ts->getPhiScale()->getLowEdge(trk->first.localPhi()));
0081     //Phi in one sector varies from [0,62] degrees -> Rescale manually to global coords.
0082     csctf_.trPhi_02PI.push_back(
0083         fmod(csctf_.trPhi[nTrk - 1] + ((trk->first.sector() - 1) * TMath::Pi() / 3) +  //sector 1 starts at 15 degrees
0084                  (TMath::Pi() / 12),
0085              2 * TMath::Pi()));
0086 
0087     //  //csctf lcts of tracks
0088     //  if( csctfLCTSource_.label() != "none" ){
0089 
0090     // For each trk, get the list of its LCTs
0091     CSCCorrelatedLCTDigiCollection lctsOfTracks = trk->second;
0092 
0093     int LctTrkId_ = 0;
0094 
0095     for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator lctOfTrks = lctsOfTracks.begin();
0096          lctOfTrks != lctsOfTracks.end();
0097          lctOfTrks++) {
0098       int lctTrkId = 0;
0099 
0100       CSCCorrelatedLCTDigiCollection::Range lctRange = lctsOfTracks.get((*lctOfTrks).first);
0101 
0102       for (CSCCorrelatedLCTDigiCollection::const_iterator lctTrk = lctRange.first; lctTrk != lctRange.second;
0103            lctTrk++, lctTrkId++) {
0104         csctf_.trLctEndcap[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.zendcap();
0105         if ((*lctOfTrks).first.zendcap() > 0)
0106           csctf_.trLctSector[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.triggerSector();
0107         else
0108           csctf_.trLctSector[nTrk - 1][LctTrkId_] = 6 + (*lctOfTrks).first.triggerSector();
0109         csctf_.trLctSubSector[nTrk - 1][LctTrkId_] =
0110             CSCTriggerNumbering::triggerSubSectorFromLabels((*lctOfTrks).first);
0111         ;
0112         csctf_.trLctBx[nTrk - 1][LctTrkId_] = lctTrk->getBX();
0113         csctf_.trLctBx0[nTrk - 1][LctTrkId_] = lctTrk->getBX0();
0114 
0115         csctf_.trLctStation[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.station();
0116         csctf_.trLctRing[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.ring();
0117         csctf_.trLctChamber[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.chamber();
0118         csctf_.trLctTriggerCSCID[nTrk - 1][LctTrkId_] = (*lctOfTrks).first.triggerCscId();
0119         csctf_.trLctFpga[nTrk - 1][LctTrkId_] =
0120             (csctf_.trLctSubSector[nTrk - 1][LctTrkId_] ? csctf_.trLctSubSector[nTrk - 1][LctTrkId_]
0121                                                         : (*lctOfTrks).first.station() + 1);
0122 
0123         // Check if DetId is within range
0124         if (csctf_.trLctSector[nTrk - 1][LctTrkId_] < 1 || csctf_.trLctSector[nTrk - 1][LctTrkId_] > 12 ||
0125             csctf_.trLctStation[nTrk - 1][LctTrkId_] < 1 || csctf_.trLctStation[nTrk - 1][LctTrkId_] > 4 ||
0126             csctf_.trLctTriggerCSCID[nTrk - 1][LctTrkId_] < 1 || csctf_.trLctTriggerCSCID[nTrk - 1][LctTrkId_] > 9 ||
0127             lctTrkId < 0 || lctTrkId > 1) {
0128           edm::LogInfo("L1NtupleProducer") << "  TRACK ERROR: CSC digi are out of range: ";
0129 
0130           continue;
0131         }
0132 
0133         // handles not to overload the method: mostly for readability
0134         int endcap = (*lctOfTrks).first.zendcap();
0135         if (endcap < 0)
0136           endcap = 0;
0137 
0138         int StationLctTrk = (*lctOfTrks).first.station();
0139         int CscIdLctTrk = (*lctOfTrks).first.triggerCscId();
0140         int SubSectorLctTrk = CSCTriggerNumbering::triggerSubSectorFromLabels((*lctOfTrks).first);
0141 
0142         int FPGALctTrk = (SubSectorLctTrk ? SubSectorLctTrk - 1 : StationLctTrk);
0143 
0144         // local Phi
0145         lclphidat lclPhi;
0146 
0147         try {
0148           csctf_.trLctstripNum[nTrk - 1][LctTrkId_] = lctTrk->getStrip();
0149           lclPhi = srLUTs_[FPGALctTrk][endcap]->localPhi(
0150               lctTrk->getStrip(), lctTrk->getPattern(), lctTrk->getQuality(), lctTrk->getBend());
0151 
0152           csctf_.trLctlocalPhi[nTrk - 1][LctTrkId_] = lclPhi.phi_local;
0153           //csctf_.trLctlocalPhi_bend[nTrk-1][LctTrkId_] = lclPhi.phi_bend_local;
0154           //csctf_.trLctCLCT_pattern[nTrk-1][LctTrkId_] = lctTrk->getPattern();
0155           csctf_.trLctQuality[nTrk - 1][LctTrkId_] = lctTrk->getQuality();
0156 
0157           //std::cout <<"lctTrk->getPattern() =  " << lctTrk->getPattern() << std::endl;
0158         } catch (...) {
0159           bzero(&lclPhi, sizeof(lclPhi));
0160           csctf_.trLctlocalPhi[nTrk - 1][LctTrkId_] = -999;
0161           //csctf_.trLctlocalPhi_bend[nTrk-1][LctTrkId_] = -999;
0162           //csctf_.trLctCLCT_pattern[nTrk-1][LctTrkId_] = -999;
0163           csctf_.trLctQuality[nTrk - 1][LctTrkId_] = -999;
0164         }
0165         // clct pattern
0166         lclphiadd lclPattern;
0167         try {
0168           //std::cout <<"lclPattern.clct_pattern = " << lclPattern.clct_pattern << std::endl;
0169           //std::cout <<"lclPattern.pattern_type = " << lclPattern.pattern_type << std::endl;
0170 
0171         } catch (...) {
0172         }
0173 
0174         // Global Phi
0175         gblphidat gblPhi;
0176 
0177         try {
0178           csctf_.trLctwireGroup[nTrk - 1][LctTrkId_] = lctTrk->getKeyWG();
0179           gblPhi = srLUTs_[FPGALctTrk][endcap]->globalPhiME(lclPhi.phi_local, lctTrk->getKeyWG(), CscIdLctTrk);
0180 
0181           csctf_.trLctglobalPhi[nTrk - 1][LctTrkId_] = gblPhi.global_phi;
0182 
0183         } catch (...) {
0184           bzero(&gblPhi, sizeof(gblPhi));
0185           csctf_.trLctglobalPhi[nTrk - 1][LctTrkId_] = -999;
0186         }
0187 
0188         // Global Eta
0189         gbletadat gblEta;
0190 
0191         try {
0192           gblEta = srLUTs_[FPGALctTrk][endcap]->globalEtaME(
0193               lclPhi.phi_bend_local, lclPhi.phi_local, lctTrk->getKeyWG(), CscIdLctTrk);
0194           csctf_.trLctglobalEta[nTrk - 1][LctTrkId_] = gblEta.global_eta;
0195           csctf_.trLctCLCT_pattern[nTrk - 1][LctTrkId_] = gblEta.global_bend;
0196         } catch (...) {
0197           bzero(&gblEta, sizeof(gblEta));
0198           csctf_.trLctglobalEta[nTrk - 1][LctTrkId_] = -999;
0199           csctf_.trLctCLCT_pattern[nTrk - 1][LctTrkId_] = -999;
0200         }
0201 
0202         ++LctTrkId_;
0203 
0204       }  // for(CSCCorrelatedLCTDigiCollection::const_iterator lctTrk
0205     }    // for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator lctOfTrks
0206 
0207     csctf_.trNumLCTs.push_back(LctTrkId_);
0208     //}
0209     //else
0210     // edm::LogInfo("L1NtupleProducer")<<"  No valid CSCCorrelatedLCTDigiCollection products found";
0211 
0212     ////delete ptLUT;
0213 
0214   }  //for(L1CSCTrackCollection::const_iterator trk=csctfTrks->begin(); trk<csctfTrks->end(); trk++,nTrk++){
0215 }
0216 
0217 //ALL csctf lcts
0218 void L1Analysis::L1AnalysisCSCTF::SetLCTs(const edm::Handle<CSCCorrelatedLCTDigiCollection> corrlcts,
0219                                           CSCSectorReceiverLUT* srLUTs_[5][2]) {
0220   int nLCT = 0;
0221   for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator corrLct = corrlcts.product()->begin();
0222        corrLct != corrlcts.product()->end();
0223        corrLct++) {
0224     nLCT++;
0225 
0226     int lctId = 0;
0227 
0228     CSCCorrelatedLCTDigiCollection::Range lctRange = corrlcts.product()->get((*corrLct).first);
0229 
0230     for (CSCCorrelatedLCTDigiCollection::const_iterator lct = lctRange.first; lct != lctRange.second; lct++, lctId++) {
0231       csctf_.lctEndcap.push_back((*corrLct).first.zendcap());
0232       if ((*corrLct).first.zendcap() > 0)
0233         csctf_.lctSector.push_back((*corrLct).first.triggerSector());
0234       else
0235         csctf_.lctSector.push_back(6 + (*corrLct).first.triggerSector());
0236 
0237       csctf_.lctSubSector.push_back(CSCTriggerNumbering::triggerSubSectorFromLabels((*corrLct).first));
0238       csctf_.lctBx.push_back(lct->getBX());
0239       csctf_.lctBx0.push_back(lct->getBX0());
0240 
0241       csctf_.lctStation.push_back((*corrLct).first.station());
0242       csctf_.lctRing.push_back((*corrLct).first.ring());
0243       csctf_.lctChamber.push_back((*corrLct).first.chamber());
0244       csctf_.lctTriggerCSCID.push_back((*corrLct).first.triggerCscId());
0245       csctf_.lctFpga.push_back(
0246           (csctf_.lctSubSector.back() ? csctf_.lctSubSector.back() : (*corrLct).first.station() + 1));
0247 
0248       // Check if DetId is within range
0249       if (csctf_.lctSector.back() < 1 || csctf_.lctSector.back() > 12 || csctf_.lctStation.back() < 1 ||
0250           csctf_.lctStation.back() > 4 || csctf_.lctTriggerCSCID.back() < 1 || csctf_.lctTriggerCSCID.back() > 9 ||
0251           lctId < 0 || lctId > 1) {
0252         edm::LogInfo("L1NtupleProducer") << "  LCT ERROR: CSC digi are out of range: ";
0253 
0254         continue;
0255       }
0256 
0257       // handles not to overload the method: mostly for readability
0258       int endcap = (*corrLct).first.zendcap();
0259       if (endcap < 0)
0260         endcap = 0;
0261 
0262       int StationLct = (*corrLct).first.station();
0263       int CscIdLct = (*corrLct).first.triggerCscId();
0264       int SubSectorLct = CSCTriggerNumbering::triggerSubSectorFromLabels((*corrLct).first);
0265 
0266       int FPGALct = (SubSectorLct ? SubSectorLct - 1 : StationLct);
0267 
0268       // local Phi
0269       lclphidat lclPhi;
0270 
0271       /*
0272     try {
0273       
0274       csctf_.lctstripNum.push_back(lct->getStrip());
0275 
0276       
0277       csctf_.lctlocalPhi.push_back(lclPhi.phi_local);
0278     } 
0279     catch(...) { 
0280       bzero(&lclPhi,sizeof(lclPhi)); 
0281       csctf_.lctlocalPhi.push_back(-999);
0282     }
0283         
0284 */
0285       try {
0286         csctf_.lctstripNum.push_back(lct->getStrip());
0287         lclPhi =
0288             srLUTs_[FPGALct][endcap]->localPhi(lct->getStrip(), lct->getPattern(), lct->getQuality(), lct->getBend());
0289 
0290         csctf_.lctlocalPhi.push_back(lclPhi.phi_local);
0291         //csctf_.lctlocalPhi_bend.push_back(lclPhi.phi_bend_local);
0292         //csctf_.lctCLCT_pattern.push_back(lct->getPattern());
0293         csctf_.lctQuality.push_back(lct->getQuality());
0294         //std::cout <<"localPhi: lclPhi.phi_bend_local = " << lclPhi.phi_bend_local << std::endl;
0295         //std::cout <<"localPhi: lct->getBend() = " << lct->getBend() << std::endl;
0296 
0297       } catch (...) {
0298         bzero(&lclPhi, sizeof(lclPhi));
0299         csctf_.lctlocalPhi.push_back(-999);
0300         //csctf_.lctlocalPhi_bend.push_back(-999);
0301         //csctf_.lctCLCT_pattern.push_back(-999);
0302         csctf_.lctQuality.push_back(-999);
0303       }
0304 
0305       // Global Phi
0306       gblphidat gblPhi;
0307 
0308       try {
0309         csctf_.lctwireGroup.push_back(lct->getKeyWG());
0310 
0311         //std::cout << "lclPhi.phi_local: " << lclPhi.phi_local << std::endl;
0312         //std::cout << "lct->getKeyWG(): " << lct->getKeyWG() << std::endl;
0313         //std::cout << "CscIdLct: " << CscIdLct << std::endl;
0314 
0315         gblPhi = srLUTs_[FPGALct][endcap]->globalPhiME(lclPhi.phi_local, lct->getKeyWG(), CscIdLct);
0316         csctf_.lctglobalPhi.push_back(gblPhi.global_phi);
0317 
0318       } catch (...) {
0319         bzero(&gblPhi, sizeof(gblPhi));
0320         csctf_.lctglobalPhi.push_back(-999);
0321       }
0322 
0323       // Global Eta
0324       gbletadat gblEta;
0325 
0326       try {
0327         gblEta =
0328             srLUTs_[FPGALct][endcap]->globalEtaME(lclPhi.phi_bend_local, lclPhi.phi_local, lct->getKeyWG(), CscIdLct);
0329         //std::cout <<"gblEta: lclPhi.phi_bend_local = " << lclPhi.phi_bend_local << std::endl;
0330         csctf_.lctglobalEta.push_back(gblEta.global_eta);
0331         csctf_.lctCLCT_pattern.push_back(gblEta.global_bend);
0332       } catch (...) {
0333         bzero(&gblEta, sizeof(gblEta));
0334         csctf_.lctglobalEta.push_back(-999);
0335         csctf_.lctCLCT_pattern.push_back(-999);
0336       }
0337 
0338     }  // for(CSCCorrelatedLCTDigiCollection::const_iterator lct
0339   }    // for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator lct
0340 
0341   csctf_.lctSize = nLCT;
0342 }
0343 
0344 void L1Analysis::L1AnalysisCSCTF::SetStatus(const edm::Handle<L1CSCStatusDigiCollection> status) {
0345   int nStat = 0;
0346   for (std::vector<L1CSCSPStatusDigi>::const_iterator stat = status->second.begin(); stat != status->second.end();
0347        stat++) {
0348     // fill the Ntuple
0349     if (stat->VPs() != 0) {
0350       csctf_.stSPslot.push_back(stat->slot());
0351       csctf_.stL1A_BXN.push_back(stat->BXN());
0352       csctf_.stTrkCounter.push_back((const_cast<L1CSCSPStatusDigi*>(&(*stat)))->track_counter());
0353       csctf_.stOrbCounter.push_back((const_cast<L1CSCSPStatusDigi*>(&(*stat)))->orbit_counter());
0354 
0355       nStat++;
0356     }
0357   }
0358 
0359   csctf_.nsp = nStat;
0360 }
0361 
0362 //DT Stubs added by Alex Ji
0363 //Code modeled from DQM/L1TMonitor/src/L1TCSCTF.cc, v1.36
0364 void L1Analysis::L1AnalysisCSCTF::SetDTStubs(const edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs) {
0365   //get the vector of DT Stubs
0366   std::vector<csctf::TrackStub> vstubs = dtStubs->get();
0367   //iterate through DT Stubs
0368   for (std::vector<csctf::TrackStub>::const_iterator stub = vstubs.begin(); stub != vstubs.end(); stub++) {
0369     csctf_.dtBXN.push_back(stub->BX());
0370     csctf_.dtFLAG.push_back(stub->getStrip());  //getStrip() is actually the "FLAG" bit
0371     csctf_.dtCAL.push_back(stub->getKeyWG());   //getKeyWG() is actually the "CAL" bit
0372 
0373     csctf_.dtSector.push_back(6 * (stub->endcap() - 1) + stub->sector());
0374     csctf_.dtSubSector.push_back(stub->subsector());
0375 
0376     csctf_.dtBX0.push_back(stub->getBX0());  //it is unclear what this variable is...
0377     csctf_.dtPhiBend.push_back(stub->getBend());
0378     csctf_.dtPhiPacked.push_back(stub->phiPacked());
0379     csctf_.dtQuality.push_back(stub->getQuality());
0380   }
0381 
0382   csctf_.dtSize = vstubs.size();
0383 }