Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:28

0001 #include "CSCTFanalyzer.h"
0002 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0003 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
0004 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
0005 #include <DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h>
0006 #include <DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h>
0007 
0008 CSCTFanalyzer::CSCTFanalyzer(edm::ParameterSet const& pset) {
0009   verbose = pset.getUntrackedParameter<unsigned int>("verbose", 0);
0010   dataTrackProducer = pset.getUntrackedParameter<edm::InputTag>("dataTrackProducer", edm::InputTag("csctfDigis"));
0011   emulTrackProducer = pset.getUntrackedParameter<edm::InputTag>("emulTrackProducer", edm::InputTag("csctfTrackDigis"));
0012   lctProducer = pset.getUntrackedParameter<edm::InputTag>("lctProducer", edm::InputTag("csctfDigis"));
0013   mbProducer = pset.getUntrackedParameter<edm::InputTag>("mbProducer", edm::InputTag("csctfDigis"));
0014   scalesToken = esConsumes<L1MuTriggerScales, L1MuTriggerScalesRcd>();
0015   file = new TFile("qwe.root", "RECREATE");
0016   tree = new TTree("dy", "QWE");
0017   tree->Branch("nDataMuons", &nDataMuons, "nDataMuons/I");
0018   tree->Branch("dphi1", &dphi1, "dphi1/D");
0019   tree->Branch("dphi2", &dphi2, "dphi2/D");
0020   tree->Branch("dphi3", &dphi3, "dphi3/D");
0021   tree->Branch("deta1", &deta1, "deta1/D");
0022   tree->Branch("deta2", &deta2, "deta2/D");
0023   tree->Branch("deta3", &deta3, "deta3/D");
0024   tree->Branch("dpt1", &dpt1, "dpt1/I");
0025   tree->Branch("dpt2", &dpt2, "dpt2/I");
0026   tree->Branch("dpt3", &dpt3, "dpt3/I");
0027   tree->Branch("dch1", &dch1, "dch1/I");
0028   tree->Branch("dch2", &dch2, "dch2/I");
0029   tree->Branch("dch3", &dch3, "dch3/I");
0030   tree->Branch("dbx1", &dbx1, "dbx1/I");
0031   tree->Branch("dbx2", &dbx2, "dbx2/I");
0032   tree->Branch("dbx3", &dbx3, "dbx3/I");
0033   tree->Branch("drank1", &drank1, "drank1/I");
0034   tree->Branch("drank2", &drank2, "drank2/I");
0035   tree->Branch("drank3", &drank3, "drank3/I");
0036   tree->Branch("dmode1", &dmode1, "dmode1/I");
0037   tree->Branch("dmode2", &dmode2, "dmode2/I");
0038   tree->Branch("dmode3", &dmode3, "dmode3/I");
0039   tree->Branch("dlcts1", &dlcts1, "dlcts1/I");
0040   tree->Branch("dlcts2", &dlcts2, "dlcts2/I");
0041   tree->Branch("dlcts3", &dlcts3, "dlcts3/I");
0042 
0043   tree->Branch("nEmulMuons", &nEmulMuons, "nEmulMuons/I");
0044   tree->Branch("ephi1", &ephi1, "ephi1/D");
0045   tree->Branch("ephi2", &ephi2, "ephi2/D");
0046   tree->Branch("ephi3", &ephi3, "ephi3/D");
0047   tree->Branch("eeta1", &eeta1, "eeta1/D");
0048   tree->Branch("eeta2", &eeta2, "eeta2/D");
0049   tree->Branch("eeta3", &eeta3, "eeta3/D");
0050   tree->Branch("ept1", &ept1, "ept1/I");
0051   tree->Branch("ept2", &ept2, "ept2/I");
0052   tree->Branch("ept3", &ept3, "ept3/I");
0053   tree->Branch("ech1", &ech1, "ech1/I");
0054   tree->Branch("ech2", &ech2, "ech2/I");
0055   tree->Branch("ech3", &ech3, "ech3/I");
0056   tree->Branch("ebx1", &ebx1, "ebx1/I");
0057   tree->Branch("ebx2", &ebx2, "ebx2/I");
0058   tree->Branch("ebx3", &ebx3, "ebx3/I");
0059   tree->Branch("erank1", &erank1, "erank1/I");
0060   tree->Branch("erank2", &erank2, "erank2/I");
0061   tree->Branch("erank3", &erank3, "erank3/I");
0062   tree->Branch("emode1", &emode1, "emode1/I");
0063   tree->Branch("emode2", &emode2, "emode2/I");
0064   tree->Branch("emode3", &emode3, "emode3/I");
0065 
0066   ts = nullptr;
0067 }
0068 
0069 void CSCTFanalyzer::endJob(void) {
0070   tree->Write();
0071   file->Write();
0072   file->Close();
0073 }
0074 
0075 void CSCTFanalyzer::analyze(edm::Event const& e, edm::EventSetup const& es) {
0076   if (!ts) {
0077     edm::ESHandle<L1MuTriggerScales> scales = es.getHandle(scalesToken);
0078     ts = scales.product();
0079   }
0080 
0081   if (lctProducer.label() != "null") {
0082     edm::Handle<CSCCorrelatedLCTDigiCollection> LCTs;
0083     e.getByLabel(lctProducer.label(), lctProducer.instance(), LCTs);
0084 
0085     for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc = LCTs.product()->begin(); csc != LCTs.product()->end();
0086          csc++) {
0087       int lctId = 0;
0088 
0089       CSCCorrelatedLCTDigiCollection::Range range1 = LCTs.product()->get((*csc).first);
0090       for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second; lct++, lctId++) {
0091         int station = (*csc).first.station() - 1;
0092         int cscId = (*csc).first.triggerCscId() - 1;
0093         int sector = (*csc).first.triggerSector() - 1 + ((*csc).first.endcap() == 1 ? 0 : 6);
0094         //int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
0095         int tbin = lct->getBX();
0096         //int fpga    = ( subSector ? subSector-1 : station+1 );
0097         if ((verbose & 1) == 1)
0098           std::cout << "LCT in station=" << (station + 1) << " sector=" << (sector + 1) << " cscId=" << (cscId + 1)
0099                     << " bx=" << tbin << std::endl;
0100       }
0101     }
0102   }
0103 
0104   if (mbProducer.label() != "null") {
0105     edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs;
0106     e.getByLabel(mbProducer.label(), mbProducer.instance(), dtStubs);
0107     if (dtStubs.isValid()) {
0108       std::vector<csctf::TrackStub> vstubs = dtStubs->get();
0109       for (std::vector<csctf::TrackStub>::const_iterator stub = vstubs.begin(); stub != vstubs.end(); stub++) {
0110         //int dtSector =(stub->sector()-1)*2 + stub->subsector()-1;
0111         //int dtEndcap = stub->endcap()-1;
0112         std::cout << "   DT data: tbin=" << stub->BX() << " (CSC) sector=" << stub->sector()
0113                   << " (CSC) subsector=" << stub->subsector() << " station=" << stub->station()
0114                   << " endcap=" << stub->endcap() << " phi=" << stub->phiPacked() << " phiBend=" << stub->getBend()
0115                   << " quality=" << stub->getQuality() << " id=" << stub->getMPCLink() << " mb_bxn=" << stub->cscid()
0116                   << std::endl;
0117       }
0118 
0119     } else
0120       edm::LogInfo("CSCTFAnalyzer") << "  No valid CSCTriggerContainer<csctf::TrackStub> products found";
0121   }
0122 
0123   nDataMuons = 0;
0124   nEmulMuons = 0;
0125   dphi1 = -1;
0126   deta1 = -1;
0127   dpt1 = -1;
0128   dch1 = -1, dbx1 = -10;
0129   dphi2 = -1;
0130   deta2 = -1;
0131   dpt2 = -1;
0132   dch2 = -1, dbx2 = -10;
0133   dphi3 = -1;
0134   deta3 = -1;
0135   dpt3 = -1;
0136   dch3 = -1, dbx3 = -10;
0137   drank1 = -1;
0138   drank2 = -1;
0139   drank3 = -1;
0140   dmode1 = -1;
0141   dmode2 = -1;
0142   dmode3 = -1;
0143   dlcts1 = 0;
0144   dlcts2 = 0;
0145   dlcts3 = 0;
0146   ephi1 = -1;
0147   eeta1 = -1;
0148   ept1 = -1;
0149   ech1 = -1, ebx1 = -10;
0150   ephi2 = -1;
0151   eeta2 = -1;
0152   ept2 = -1;
0153   ech2 = -1, ebx2 = -10;
0154   ephi3 = -1;
0155   eeta3 = -1;
0156   ept3 = -1;
0157   ech3 = -1, ebx3 = -10;
0158   erank1 = -1;
0159   erank2 = -1;
0160   erank3 = -1;
0161   emode1 = -1;
0162   emode2 = -1;
0163   emode3 = -1;
0164 
0165   if (dataTrackProducer.label() != "null") {
0166     edm::Handle<L1CSCTrackCollection> tracks;
0167     e.getByLabel(dataTrackProducer.label(), dataTrackProducer.instance(), tracks);
0168     // Muon sorter emulation:
0169     std::vector<csc::L1Track> result;
0170     CSCTriggerContainer<csc::L1Track> stripped_tracks;
0171     for (L1CSCTrackCollection::const_iterator tmp_trk = tracks->begin(); tmp_trk != tracks->end(); tmp_trk++) {
0172       csc::L1Track qqq(tmp_trk->first);
0173       qqq.setOutputLink(0);
0174       CSCCorrelatedLCTDigiCollection qwe = tmp_trk->second;
0175       for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc = qwe.begin(); csc != qwe.end(); csc++) {
0176         CSCCorrelatedLCTDigiCollection::Range range1 = qwe.get((*csc).first);
0177         for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second; lct++)
0178           qqq.setOutputLink(qqq.outputLink() | (1 << (*csc).first.station()));
0179       }
0180       stripped_tracks.push_back(qqq);
0181     }
0182     // First we sort and crop the incoming tracks based on their rank.
0183     for (int bx = -3; bx <= 3; ++bx) {  // switch back into signed BX
0184       std::vector<csc::L1Track> tks = stripped_tracks.get(bx);
0185       std::sort(tks.begin(), tks.end(), std::greater<csc::L1Track>());
0186       if (tks.size() > 4)
0187         tks.resize(4);  // resize to max number of muons the MS can output
0188       for (std::vector<csc::L1Track>::iterator itr = tks.begin(); itr != tks.end(); itr++) {
0189         unsigned gbl_phi =
0190             itr->localPhi() + ((itr->sector() - 1) * 24) + 6;  // for now, convert using this.. LUT in the future
0191         if (gbl_phi > 143)
0192           gbl_phi -= 143;
0193         itr->setPhiPacked(gbl_phi & 0xff);
0194         unsigned eta_sign = (itr->endcap() == 1 ? 0 : 1);
0195         int gbl_eta = itr->eta_packed() | eta_sign << (L1MuRegionalCand::ETA_LENGTH - 1);
0196         itr->setEtaPacked(gbl_eta & 0x3f);
0197         itr->setQualityPacked((itr->rank() >> 4) & 0x3);
0198         itr->setPtPacked(itr->rank() & 0x1f);
0199         if (!itr->empty())
0200           result.push_back(*itr);
0201       }
0202     }
0203     //      for(std::vector<csc::L1Track>::const_iterator trk=result.begin(); trk!=result.end(); trk++){
0204     for (L1CSCTrackCollection::const_iterator _trk = tracks->begin(); _trk != tracks->end(); _trk++) {
0205       const csc::L1Track* trk = &(_trk->first);
0206       switch (nDataMuons) {
0207         case 0:
0208           dphi1 = ts->getPhiScale()->getLowEdge(trk->phi_packed());
0209           deta1 = ts->getRegionalEtaScale(2)->getCenter(trk->eta_packed());
0210           dpt1 = trk->pt_packed();
0211           dch1 = trk->charge_packed();
0212           dbx1 = trk->BX();
0213           dmode1 = trk->mode();
0214           drank1 = trk->rank();
0215           dlcts1 = trk->outputLink();
0216           break;
0217         case 1:
0218           dphi2 = ts->getPhiScale()->getLowEdge(trk->phi_packed());
0219           deta2 = ts->getRegionalEtaScale(2)->getCenter(trk->eta_packed());
0220           dpt2 = trk->pt_packed();
0221           dch2 = trk->charge_packed();
0222           dbx2 = trk->BX();
0223           dmode2 = trk->mode();
0224           drank2 = trk->rank();
0225           dlcts2 = trk->outputLink();
0226           break;
0227         case 2:
0228           dphi3 = ts->getPhiScale()->getLowEdge(trk->phi_packed());
0229           deta3 = ts->getRegionalEtaScale(2)->getCenter(trk->eta_packed());
0230           dpt3 = trk->pt_packed();
0231           dch3 = trk->charge_packed();
0232           dbx3 = trk->BX();
0233           dmode3 = trk->mode();
0234           drank3 = trk->rank();
0235           dlcts3 = trk->outputLink();
0236           break;
0237         default:
0238           break;
0239       }
0240       if ((verbose & 2) == 2)
0241         std::cout << "Data: TRK in endcap=" << trk->endcap() << " sector=" << trk->sector() << " bx=" << trk->BX()
0242                   << " (rank=" << trk->rank() << " localPhi=" << trk->localPhi() << " etaPacked=" << trk->eta_packed()
0243                   << " me1D=" << trk->me1ID() << " me2D=" << trk->me2ID() << " me3D=" << trk->me3ID()
0244                   << " me4D=" << trk->me4ID() << " mb1D=" << trk->mb1ID() << " pTaddr=" << std::hex
0245                   << trk->ptLUTAddress() << std::dec << ")" << std::endl;
0246       nDataMuons++;
0247     }
0248   }
0249 
0250   if (emulTrackProducer.label() != "null") {
0251     edm::Handle<L1CSCTrackCollection> tracks;
0252     e.getByLabel(emulTrackProducer.label(), emulTrackProducer.instance(), tracks);
0253     for (L1CSCTrackCollection::const_iterator trk = tracks.product()->begin(); trk != tracks.product()->end(); trk++) {
0254       switch (nEmulMuons) {
0255         case 0:
0256           ephi1 = trk->first.localPhi();
0257           eeta1 = trk->first.eta_packed();
0258           ept1 = trk->first.pt_packed();
0259           ech1 = trk->first.charge_packed();
0260           ebx1 = trk->first.BX();
0261           break;
0262         case 1:
0263           ephi2 = trk->first.localPhi();
0264           eeta2 = trk->first.eta_packed();
0265           ept2 = trk->first.pt_packed();
0266           ech2 = trk->first.charge_packed();
0267           ebx2 = trk->first.BX();
0268           break;
0269         case 2:
0270           ephi3 = trk->first.localPhi();
0271           eeta3 = trk->first.eta_packed();
0272           ept3 = trk->first.pt_packed();
0273           ech3 = trk->first.charge_packed();
0274           ebx3 = trk->first.BX();
0275           break;
0276         default:
0277           break;
0278       }
0279       if ((verbose & 2) == 2)
0280         std::cout << "Emulator: TRK in endcap=" << trk->first.endcap() << " sector=" << trk->first.sector()
0281                   << " bx=" << trk->first.BX() << " (rank=" << trk->first.rank()
0282                   << " localPhi=" << trk->first.localPhi() << " etaPacked=" << trk->first.eta_packed()
0283                   << " me1D=" << trk->first.me1ID() << " me2D=" << trk->first.me2ID() << " me3D=" << trk->first.me3ID()
0284                   << " me4D=" << trk->first.me4ID() << " mb1D=" << trk->first.mb1ID() << " pTaddr=" << std::hex
0285                   << trk->first.ptLUTAddress() << std::dec << ")" << std::endl;
0286       nEmulMuons++;
0287     }
0288   }
0289 
0290   tree->Fill();
0291 }