File indexing completed on 2024-04-06 12:10:28
0001 #include "FWCore/Framework/interface/ConsumesCollector.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Utilities/interface/InputTag.h"
0007
0008
0009 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0010 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
0011 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCStatusDigiCollection.h"
0012 #include "DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h"
0013 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
0014
0015 #include <TTree.h>
0016 #include <TFile.h>
0017
0018 class CSCTFAnalyzer : public edm::one::EDAnalyzer<> {
0019 private:
0020 edm::InputTag mbProducer, lctProducer, trackProducer, statusProducer;
0021 TTree *tree;
0022 TFile *file;
0023 int dtPhi[12][2];
0024
0025 edm::EDGetTokenT<L1CSCStatusDigiCollection> L1CSCS_Tok;
0026 edm::EDGetTokenT<CSCTriggerContainer<csctf::TrackStub> > CSCTC_Tok;
0027 edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> CSCCDC_Tok;
0028 edm::EDGetTokenT<L1CSCTrackCollection> L1CST_Tok;
0029
0030 public:
0031 void analyze(const edm::Event &e, const edm::EventSetup &c) override;
0032
0033 explicit CSCTFAnalyzer(const edm::ParameterSet &conf);
0034 ~CSCTFAnalyzer(void) override {
0035 file->cd();
0036 tree->Write();
0037 file->Close();
0038 }
0039 };
0040
0041 #include "DataFormats/Common/interface/Handle.h"
0042 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0043
0044 #include <strings.h>
0045 #include <cerrno>
0046 #include <iostream>
0047 #include <iomanip>
0048
0049 CSCTFAnalyzer::CSCTFAnalyzer(const edm::ParameterSet &conf) : edm::one::EDAnalyzer<>() {
0050 mbProducer = conf.getUntrackedParameter<edm::InputTag>("mbProducer", edm::InputTag("csctfunpacker"));
0051 lctProducer = conf.getUntrackedParameter<edm::InputTag>("lctProducer", edm::InputTag("csctfunpacker"));
0052 trackProducer = conf.getUntrackedParameter<edm::InputTag>("trackProducer", edm::InputTag("csctfunpacker"));
0053 statusProducer = conf.getUntrackedParameter<edm::InputTag>("statusProducer", edm::InputTag("csctfunpacker"));
0054 file = new TFile("ewq.root", "RECREATE");
0055 tree = new TTree("dy", "QWE");
0056 tree->Branch("dtPhi_1_plus", &dtPhi[0][0], "dtPhi_1_plus/I");
0057 tree->Branch("dtPhi_2_plus", &dtPhi[1][0], "dtPhi_2_plus/I");
0058 tree->Branch("dtPhi_3_plus", &dtPhi[2][0], "dtPhi_3_plus/I");
0059 tree->Branch("dtPhi_4_plus", &dtPhi[3][0], "dtPhi_4_plus/I");
0060 tree->Branch("dtPhi_5_plus", &dtPhi[4][0], "dtPhi_5_plus/I");
0061 tree->Branch("dtPhi_6_plus", &dtPhi[5][0], "dtPhi_6_plus/I");
0062 tree->Branch("dtPhi_7_plus", &dtPhi[6][0], "dtPhi_7_plus/I");
0063 tree->Branch("dtPhi_8_plus", &dtPhi[7][0], "dtPhi_8_plus/I");
0064 tree->Branch("dtPhi_9_plus", &dtPhi[8][0], "dtPhi_9_plus/I");
0065 tree->Branch("dtPhi_10_plus", &dtPhi[9][0], "dtPhi_10_plus/I");
0066 tree->Branch("dtPhi_11_plus", &dtPhi[10][0], "dtPhi_11_plus/I");
0067 tree->Branch("dtPhi_12_plus", &dtPhi[11][0], "dtPhi_12_plus/I");
0068 tree->Branch("dtPhi_1_minus", &dtPhi[0][1], "dtPhi_1_minus/I");
0069 tree->Branch("dtPhi_2_minus", &dtPhi[1][1], "dtPhi_2_minus/I");
0070 tree->Branch("dtPhi_3_minus", &dtPhi[2][1], "dtPhi_3_minus/I");
0071 tree->Branch("dtPhi_4_minus", &dtPhi[3][1], "dtPhi_4_minus/I");
0072 tree->Branch("dtPhi_5_minus", &dtPhi[4][1], "dtPhi_5_minus/I");
0073 tree->Branch("dtPhi_6_minus", &dtPhi[5][1], "dtPhi_6_minus/I");
0074 tree->Branch("dtPhi_7_minus", &dtPhi[6][1], "dtPhi_7_minus/I");
0075 tree->Branch("dtPhi_8_minus", &dtPhi[7][1], "dtPhi_8_minus/I");
0076 tree->Branch("dtPhi_9_minus", &dtPhi[8][1], "dtPhi_9_minus/I");
0077 tree->Branch("dtPhi_10_minus", &dtPhi[9][1], "dtPhi_10_minus/I");
0078 tree->Branch("dtPhi_11_minus", &dtPhi[10][1], "dtPhi_11_minus/I");
0079 tree->Branch("dtPhi_12_minus", &dtPhi[11][1], "dtPhi_12_minus/I");
0080
0081 L1CSCS_Tok = consumes<L1CSCStatusDigiCollection>(edm::InputTag(statusProducer.label(), statusProducer.instance()));
0082 CSCTC_Tok =
0083 consumes<CSCTriggerContainer<csctf::TrackStub> >(edm::InputTag(mbProducer.label(), mbProducer.instance()));
0084 CSCCDC_Tok = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(lctProducer.label(), lctProducer.instance()));
0085 L1CST_Tok = consumes<L1CSCTrackCollection>(edm::InputTag(trackProducer.label(), trackProducer.instance()));
0086 }
0087
0088 void CSCTFAnalyzer::analyze(const edm::Event &e, const edm::EventSetup &c) {
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 if (statusProducer.label() != "null") {
0103 edm::Handle<L1CSCStatusDigiCollection> status;
0104 e.getByToken(L1CSCS_Tok, status);
0105 if (status.isValid()) {
0106 edm::LogInfo("CSCTFAnalyzer") << " Unpacking Errors: " << status->first;
0107 for (std::vector<L1CSCSPStatusDigi>::const_iterator stat = status->second.begin(); stat != status->second.end();
0108 stat++) {
0109
0110 }
0111 } else
0112 edm::LogInfo("CSCTFAnalyzer") << " No valid L1CSCStatusDigiCollection products found";
0113 }
0114
0115 if (mbProducer.label() != "null") {
0116 bzero(dtPhi, sizeof(dtPhi));
0117 edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs;
0118 e.getByToken(CSCTC_Tok, dtStubs);
0119 if (dtStubs.isValid()) {
0120 std::vector<csctf::TrackStub> vstubs = dtStubs->get();
0121 std::cout << "DT size=" << vstubs.end() - vstubs.begin() << std::endl;
0122 for (std::vector<csctf::TrackStub>::const_iterator stub = vstubs.begin(); stub != vstubs.end(); stub++) {
0123 int dtSector = (stub->sector() - 1) * 2 + stub->subsector() - 1;
0124 int dtEndcap = stub->endcap() - 1;
0125 if (dtSector >= 0 && dtSector < 12 && dtEndcap >= 0 && dtEndcap < 2) {
0126 dtPhi[dtSector][dtEndcap] = stub->phiPacked();
0127 } else {
0128 edm::LogInfo("CSCTFAnalyzer: DT digi are out of range: ")
0129 << " dtSector=" << dtSector << " dtEndcap=" << dtEndcap;
0130 }
0131 edm::LogInfo("CSCTFAnalyzer") << " DT data: tbin=" << stub->BX() << " CSC sector=" << stub->sector()
0132 << " CSC subsector=" << stub->subsector() << " station=" << stub->station()
0133 << " endcap=" << stub->endcap() << " phi=" << stub->phiPacked()
0134 << " phiBend=" << stub->getBend() << " quality=" << stub->getQuality()
0135 << " mb_bxn=" << stub->cscid();
0136 }
0137 } else
0138 edm::LogInfo("CSCTFAnalyzer") << " No valid CSCTriggerContainer<csctf::TrackStub> products found";
0139 tree->Fill();
0140 }
0141
0142 if (lctProducer.label() != "null") {
0143 edm::Handle<CSCCorrelatedLCTDigiCollection> corrlcts;
0144 e.getByToken(CSCCDC_Tok, corrlcts);
0145 if (corrlcts.isValid()) {
0146 for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc = corrlcts.product()->begin();
0147 csc != corrlcts.product()->end();
0148 csc++) {
0149 int lctId = 0;
0150 CSCCorrelatedLCTDigiCollection::Range range1 = corrlcts.product()->get((*csc).first);
0151 for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second; lct++, lctId++) {
0152 int station = (*csc).first.station() - 1;
0153 int cscId = (*csc).first.triggerCscId() - 1;
0154 int sector = (*csc).first.triggerSector() - 1;
0155 int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
0156 int tbin = lct->getBX();
0157 int fpga = (subSector ? subSector - 1 : station + 1);
0158
0159 if (sector < 0 || sector > 11 || station < 0 || station > 3 || cscId < 0 || cscId > 8 || lctId < 0 ||
0160 lctId > 1) {
0161 edm::LogInfo("CSCTFAnalyzer: CSC digi are out of range: ");
0162 continue;
0163 }
0164 edm::LogInfo("CSCTFAnalyzer") << " Front data endcap: " << (*csc).first.endcap()
0165 << " station: " << (station + 1) << " sector: " << (sector + 1)
0166 << " subSector: " << subSector << " tbin: " << tbin
0167 << " cscId: " << (cscId + 1) << " fpga: " << (fpga + 1) << " "
0168 << "LCT(vp=" << lct->isValid() << ",qual=" << lct->getQuality()
0169 << ",wg=" << lct->getKeyWG() << ",strip=" << lct->getStrip()
0170 << ",link=" << lct->getMPCLink() << ")";
0171 }
0172 }
0173 } else
0174 edm::LogInfo("CSCTFAnalyzer") << " No valid CSCCorrelatedLCTDigiCollection products found";
0175 }
0176
0177 if (trackProducer.label() != "null") {
0178 edm::Handle<L1CSCTrackCollection> tracks;
0179 e.getByToken(L1CST_Tok, tracks);
0180 if (tracks.isValid()) {
0181 int nTrk = 0;
0182 for (L1CSCTrackCollection::const_iterator trk = tracks->begin(); trk < tracks->end(); trk++, nTrk++) {
0183 int sector = 6 * (trk->first.endcap() - 1) + trk->first.sector() - 1;
0184 int tbin = trk->first.BX();
0185 edm::LogInfo("CSCTFAnalyzer") << " Track sector: " << (sector + 1) << " tbin: " << tbin << " "
0186 << "TRK(mode=" << ((trk->first.ptLUTAddress() >> 16) & 0xF)
0187 << ",eta=" << trk->first.eta_packed() << ",phi=" << trk->first.localPhi()
0188 << ") IDs:"
0189 << " me1D=" << trk->first.me1ID() << " t1=" << trk->first.me1Tbin()
0190 << " me2D=" << trk->first.me2ID() << " t2=" << trk->first.me2Tbin()
0191 << " me3D=" << trk->first.me3ID() << " t3=" << trk->first.me3Tbin()
0192 << " me4D=" << trk->first.me4ID() << " t4=" << trk->first.me4Tbin()
0193 << " mb1D=" << trk->first.mb1ID() << " tb=" << trk->first.mb1Tbin();
0194
0195 for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc = trk->second.begin(); csc != trk->second.end();
0196 csc++) {
0197 int lctId = 0;
0198 CSCCorrelatedLCTDigiCollection::Range range1 = trk->second.get((*csc).first);
0199 for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second;
0200 lct++, lctId++) {
0201 int station = (*csc).first.station() - 1;
0202 int cscId = (*csc).first.triggerCscId() - 1;
0203 int sector = (*csc).first.triggerSector() - 1;
0204 int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
0205 int tbin = lct->getBX();
0206 int fpga = (subSector ? subSector - 1 : station + 1);
0207
0208 if (sector < 0 || sector > 11 || station < 0 || station > 3 || cscId < 0 || cscId > 8 || lctId < 0 ||
0209 lctId > 1) {
0210 edm::LogInfo("CSCTFAnalyzer: Digi are out of range: ");
0211 continue;
0212 }
0213 if (lct->getQuality() < 100)
0214 edm::LogInfo("CSCTFAnalyzer")
0215 << " Linked LCT: " << (*csc).first.endcap() << " station: " << (station + 1)
0216 << " sector: " << (sector + 1) << " subSector: " << subSector << " tbin: " << tbin
0217 << " cscId: " << (cscId + 1) << " fpga: " << (fpga + 1) << " LCT(vp=" << lct->isValid()
0218 << ",qual=" << lct->getQuality() << ",wg=" << lct->getKeyWG() << ",strip=" << lct->getStrip() << ")";
0219 else
0220 edm::LogInfo("CSCTFAnalyzer")
0221 << " Linked MB stub: " << (*csc).first.endcap() << " sector: " << (sector + 1)
0222 << " subSector: " << subSector << " tbin: " << tbin << " MB(vp=" << lct->isValid()
0223 << ",qual=" << (lct->getQuality() - 100) << ",cal=" << lct->getKeyWG() << ",flag=" << lct->getStrip()
0224 << ",bc0=" << lct->getPattern() << ",phiBend=" << lct->getBend() << ",tbin=" << lct->getBX()
0225 << ",id=" << lct->getMPCLink() << ",bx0=" << lct->getBX0() << ",se=" << lct->getSyncErr()
0226 << ",bxn=" << lct->getCSCID() << ",phi=" << lct->getTrknmb() << ")";
0227 }
0228 }
0229 }
0230 } else
0231 edm::LogInfo("CSCTFAnalyzer") << " No valid L1CSCTrackCollection products found";
0232 }
0233 }
0234
0235 #include "FWCore/Framework/interface/MakerMacros.h"
0236 DEFINE_FWK_MODULE(CSCTFAnalyzer);