CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/L1Trigger/CSCTrackFinder/plugins/CSCTFanalyzer.cc

Go to the documentation of this file.
00001 #include "CSCTFanalyzer.h"
00002 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00003 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
00004 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
00005 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
00006 #include <DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h>
00007 #include <DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h>
00008 
00009 CSCTFanalyzer::CSCTFanalyzer(edm::ParameterSet const& pset):edm::EDAnalyzer(){
00010         verbose           = pset.getUntrackedParameter<unsigned  int>("verbose",0);
00011         dataTrackProducer = pset.getUntrackedParameter<edm::InputTag>("dataTrackProducer",edm::InputTag("csctfDigis"));
00012         emulTrackProducer = pset.getUntrackedParameter<edm::InputTag>("emulTrackProducer",edm::InputTag("csctfTrackDigis"));
00013         lctProducer       = pset.getUntrackedParameter<edm::InputTag>("lctProducer",edm::InputTag("csctfDigis"));
00014         mbProducer        = pset.getUntrackedParameter<edm::InputTag>("mbProducer", edm::InputTag("csctfDigis"));
00015         file = new TFile("qwe.root","RECREATE");
00016         tree = new TTree("dy","QWE");
00017         tree->Branch("nDataMuons", &nDataMuons, "nDataMuons/I");
00018         tree->Branch("dphi1", &dphi1, "dphi1/D");
00019         tree->Branch("dphi2", &dphi2, "dphi2/D");
00020         tree->Branch("dphi3", &dphi3, "dphi3/D");
00021         tree->Branch("deta1", &deta1, "deta1/D");
00022         tree->Branch("deta2", &deta2, "deta2/D");
00023         tree->Branch("deta3", &deta3, "deta3/D");
00024         tree->Branch("dpt1",  &dpt1,  "dpt1/I");
00025         tree->Branch("dpt2",  &dpt2,  "dpt2/I");
00026         tree->Branch("dpt3",  &dpt3,  "dpt3/I");
00027         tree->Branch("dch1",  &dch1,  "dch1/I");
00028         tree->Branch("dch2",  &dch2,  "dch2/I");
00029         tree->Branch("dch3",  &dch3,  "dch3/I");
00030         tree->Branch("dbx1",  &dbx1,  "dbx1/I");
00031         tree->Branch("dbx2",  &dbx2,  "dbx2/I");
00032         tree->Branch("dbx3",  &dbx3,  "dbx3/I");
00033         tree->Branch("drank1",&drank1,"drank1/I");
00034         tree->Branch("drank2",&drank2,"drank2/I");
00035         tree->Branch("drank3",&drank3,"drank3/I");
00036         tree->Branch("dmode1",&dmode1,"dmode1/I");
00037         tree->Branch("dmode2",&dmode2,"dmode2/I");
00038         tree->Branch("dmode3",&dmode3,"dmode3/I");
00039         tree->Branch("dlcts1",&dlcts1,"dlcts1/I");
00040         tree->Branch("dlcts2",&dlcts2,"dlcts2/I");
00041         tree->Branch("dlcts3",&dlcts3,"dlcts3/I");
00042 
00043         tree->Branch("nEmulMuons", &nEmulMuons, "nEmulMuons/I");
00044         tree->Branch("ephi1", &ephi1, "ephi1/D");
00045         tree->Branch("ephi2", &ephi2, "ephi2/D");
00046         tree->Branch("ephi3", &ephi3, "ephi3/D");
00047         tree->Branch("eeta1", &eeta1, "eeta1/D");
00048         tree->Branch("eeta2", &eeta2, "eeta2/D");
00049         tree->Branch("eeta3", &eeta3, "eeta3/D");
00050         tree->Branch("ept1",  &ept1,  "ept1/I");
00051         tree->Branch("ept2",  &ept2,  "ept2/I");
00052         tree->Branch("ept3",  &ept3,  "ept3/I");
00053         tree->Branch("ech1",  &ech1,  "ech1/I");
00054         tree->Branch("ech2",  &ech2,  "ech2/I");
00055         tree->Branch("ech3",  &ech3,  "ech3/I");
00056         tree->Branch("ebx1",  &ebx1,  "ebx1/I");
00057         tree->Branch("ebx2",  &ebx2,  "ebx2/I");
00058         tree->Branch("ebx3",  &ebx3,  "ebx3/I");
00059         tree->Branch("erank1",&erank1,"erank1/I");
00060         tree->Branch("erank2",&erank2,"erank2/I");
00061         tree->Branch("erank3",&erank3,"erank3/I");
00062         tree->Branch("emode1",&emode1,"emode1/I");
00063         tree->Branch("emode2",&emode2,"emode2/I");
00064         tree->Branch("emode3",&emode3,"emode3/I");
00065 
00066         ts=0;
00067 }
00068 
00069 void CSCTFanalyzer::endJob(void){
00070         tree->Write();
00071         file->Write();
00072         file->Close();
00073 }
00074 
00075 void CSCTFanalyzer::analyze(edm::Event const& e, edm::EventSetup const& es){
00076         if(!ts){
00077                 edm::ESHandle< L1MuTriggerScales > scales;
00078                 es.get< L1MuTriggerScalesRcd >().get(scales);
00079                 ts = scales.product();
00080         }
00081 
00082         if( lctProducer.label() != "null" ){
00083                 edm::Handle<CSCCorrelatedLCTDigiCollection> LCTs;
00084                 e.getByLabel(lctProducer.label(),lctProducer.instance(), LCTs);
00085 
00086                 for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=LCTs.product()->begin(); csc!=LCTs.product()->end(); csc++){
00087                         int lctId=0;
00088 
00089                         CSCCorrelatedLCTDigiCollection::Range range1 = LCTs.product()->get((*csc).first);
00090                         for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++,lctId++){
00091                                 int station = (*csc).first.station()-1;
00092                                 int cscId   = (*csc).first.triggerCscId()-1;
00093                                 int sector  = (*csc).first.triggerSector()-1 + ( (*csc).first.endcap()==1 ? 0 : 6 );
00094                                 //int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00095                                 int tbin    = lct->getBX();
00096                                 //int fpga    = ( subSector ? subSector-1 : station+1 );
00097                                 if((verbose&1)==1)
00098                                         std::cout<<"LCT in station="<<(station+1)<<" sector="<<(sector+1)<<" cscId="<<(cscId+1)<<" bx="<<tbin<<std::endl;
00099                         }
00100                 }
00101         }
00102 
00103         if( mbProducer.label() != "null" ){
00104                 edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs;
00105                 e.getByLabel(mbProducer.label(),mbProducer.instance(),dtStubs);
00106                 if( dtStubs.isValid() ){
00107                         std::vector<csctf::TrackStub> vstubs = dtStubs->get();
00108                         for(std::vector<csctf::TrackStub>::const_iterator stub=vstubs.begin(); stub!=vstubs.end(); stub++){
00109                                 //int dtSector =(stub->sector()-1)*2 + stub->subsector()-1;
00110                                 //int dtEndcap = stub->endcap()-1;
00111                                 std::cout<<"   DT data: tbin="<<stub->BX()<<" (CSC) sector="<<stub->sector()<<" (CSC) subsector="<<stub->subsector()<<" station="<<stub->station()<<" endcap="<<stub->endcap()
00112                                         <<" phi="<<stub->phiPacked()<<" phiBend="<<stub->getBend()<<" quality="<<stub->getQuality()<<" id="<<stub->getMPCLink()<<" mb_bxn="<<stub->cscid()<<std::cout;
00113                         }
00114 
00115                 } else edm::LogInfo("CSCTFAnalyzer")<<"  No valid CSCTriggerContainer<csctf::TrackStub> products found";
00116         }
00117 
00118         nDataMuons = 0; nEmulMuons = 0;
00119         dphi1=-1; deta1=-1; dpt1=-1; dch1=-1, dbx1=-10;
00120         dphi2=-1; deta2=-1; dpt2=-1; dch2=-1, dbx2=-10;
00121         dphi3=-1; deta3=-1; dpt3=-1; dch3=-1, dbx3=-10;
00122         drank1=-1;drank2=-1;drank3=-1;
00123         dmode1=-1;dmode2=-1;dmode3=-1;
00124         dlcts1= 0;dlcts2= 0;dlcts3= 0;
00125         ephi1=-1; eeta1=-1; ept1=-1; ech1=-1, ebx1=-10;
00126         ephi2=-1; eeta2=-1; ept2=-1; ech2=-1, ebx2=-10;
00127         ephi3=-1; eeta3=-1; ept3=-1; ech3=-1, ebx3=-10;
00128         erank1=-1;erank2=-1;erank3=-1;
00129         emode1=-1;emode2=-1;emode3=-1;
00130 
00131         if( dataTrackProducer.label() != "null" ){
00132                 edm::Handle<L1CSCTrackCollection> tracks;
00133                 e.getByLabel(dataTrackProducer.label(),dataTrackProducer.instance(),tracks);
00134                 // Muon sorter emulation:
00135                 std::vector<csc::L1Track> result;
00136                 CSCTriggerContainer<csc::L1Track> stripped_tracks;
00137                 for(L1CSCTrackCollection::const_iterator tmp_trk=tracks->begin(); tmp_trk!=tracks->end(); tmp_trk++){
00138                         csc::L1Track qqq(tmp_trk->first);
00139                         qqq.setOutputLink(0);
00140                         CSCCorrelatedLCTDigiCollection qwe = tmp_trk->second;
00141                         for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=qwe.begin(); csc!=qwe.end(); csc++){
00142                                 CSCCorrelatedLCTDigiCollection::Range range1 = qwe.get((*csc).first);
00143                                 for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++)
00144                                         qqq.setOutputLink( qqq.outputLink()|(1<<(*csc).first.station()) );
00145                         }
00146                         stripped_tracks.push_back(qqq);
00147                 }
00148                 // First we sort and crop the incoming tracks based on their rank.
00149                 for(int bx = -3; bx <= 3; ++bx){ // switch back into signed BX
00150                         std::vector<csc::L1Track> tks = stripped_tracks.get(bx);
00151                         std::sort(tks.begin(),tks.end(),std::greater<csc::L1Track>());
00152                         if(tks.size() > 4) tks.resize(4); // resize to max number of muons the MS can output
00153                         for(std::vector<csc::L1Track>::iterator itr=tks.begin(); itr!=tks.end(); itr++){
00154                                 unsigned gbl_phi = itr->localPhi() + ((itr->sector() - 1)*24) + 6; // for now, convert using this.. LUT in the future
00155                                 if(gbl_phi > 143) gbl_phi -= 143;
00156                                 itr->setPhiPacked(gbl_phi & 0xff);
00157                                 unsigned eta_sign = (itr->endcap() == 1 ? 0 : 1);
00158                                 int gbl_eta = itr->eta_packed() | eta_sign << (L1MuRegionalCand::ETA_LENGTH - 1);
00159                                 itr->setEtaPacked(gbl_eta & 0x3f);
00160                                 itr->setQualityPacked((itr->rank()>>4) & 0x3);
00161                                 itr->setPtPacked(itr->rank() & 0x1f);
00162                                 if(!itr->empty()) result.push_back(*itr);
00163                         }
00164                 }
00165 //              for(std::vector<csc::L1Track>::const_iterator trk=result.begin(); trk!=result.end(); trk++){
00166                 for(L1CSCTrackCollection::const_iterator _trk=tracks->begin(); _trk!=tracks->end(); _trk++){ const csc::L1Track *trk = &(_trk->first);
00167                         switch(nDataMuons){
00168                                 case 0:
00169                                         dphi1 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
00170                                         deta1 = ts->getRegionalEtaScale(2)->getCenter( trk->eta_packed() );
00171                                         dpt1  = trk->pt_packed();
00172                                         dch1  = trk->charge_packed();
00173                                         dbx1  = trk->BX();
00174                                         dmode1= trk->mode();
00175                                         drank1= trk->rank();
00176                                         dlcts1= trk->outputLink();
00177                                 break;
00178                                 case 1:
00179                                         dphi2 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
00180                                         deta2 = ts->getRegionalEtaScale(2)->getCenter( trk->eta_packed() );
00181                                         dpt2  = trk->pt_packed();
00182                                         dch2  = trk->charge_packed();
00183                                         dbx2  = trk->BX();
00184                                         dmode2= trk->mode();
00185                                         drank2= trk->rank();
00186                                         dlcts2= trk->outputLink();
00187                                 break;
00188                                 case 2:
00189                                         dphi3 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
00190                                         deta3 = ts->getRegionalEtaScale(2)->getCenter( trk->eta_packed() );
00191                                         dpt3  = trk->pt_packed();
00192                                         dch3  = trk->charge_packed();
00193                                         dbx3  = trk->BX();
00194                                         dmode3= trk->mode();
00195                                         drank3= trk->rank();
00196                                         dlcts3= trk->outputLink();
00197                                 break;
00198                                 default: break;
00199                         }
00200                         if( (verbose&2)==2 )
00201                                 std::cout<<"Data: TRK in endcap="<<trk->endcap()<<" sector="<<trk->sector()<<" bx="<<trk->BX()
00202                                         <<" (rank="<<trk->rank()
00203                                         <<" localPhi="<<trk->localPhi()
00204                                         <<" etaPacked="<<trk->eta_packed()
00205                                         <<" me1D="<<trk->me1ID()
00206                                         <<" me2D="<<trk->me2ID()
00207                                         <<" me3D="<<trk->me3ID()
00208                                         <<" me4D="<<trk->me4ID()
00209                                         <<" mb1D="<<trk->mb1ID()
00210                                         <<" pTaddr="<<std::hex<<trk->ptLUTAddress()<<std::dec
00211                                         <<")"<<std::endl;
00212                         nDataMuons++;
00213                 }
00214         }
00215 
00216         if( emulTrackProducer.label() != "null" ){
00217                 edm::Handle<L1CSCTrackCollection> tracks;
00218                 e.getByLabel(emulTrackProducer.label(),emulTrackProducer.instance(),tracks);
00219                 for(L1CSCTrackCollection::const_iterator trk=tracks.product()->begin(); trk!=tracks.product()->end(); trk++){
00220                         switch(nEmulMuons){
00221                                 case 0:
00222                                         ephi1 = trk->first.localPhi();
00223                                         eeta1 = trk->first.eta_packed();
00224                                         ept1  = trk->first.pt_packed();
00225                                         ech1  = trk->first.charge_packed();
00226                                         ebx1  = trk->first.BX();
00227                                 break;
00228                                 case 1:
00229                                         ephi2 = trk->first.localPhi();
00230                                         eeta2 = trk->first.eta_packed();
00231                                         ept2  = trk->first.pt_packed();
00232                                         ech2  = trk->first.charge_packed();
00233                                         ebx2  = trk->first.BX();
00234                                 break;
00235                                 case 2:
00236                                         ephi3 = trk->first.localPhi();
00237                                         eeta3 = trk->first.eta_packed();
00238                                         ept3  = trk->first.pt_packed();
00239                                         ech3  = trk->first.charge_packed();
00240                                         ebx3  = trk->first.BX();
00241                                 break;
00242                                 default: break;
00243                         }
00244                         if( (verbose&2)==2 )
00245                                 std::cout<<"Emulator: TRK in endcap="<<trk->first.endcap()<<" sector="<<trk->first.sector()<<" bx="<<trk->first.BX()
00246                                         <<" (rank="<<trk->first.rank()
00247                                         <<" localPhi="<<trk->first.localPhi()
00248                                         <<" etaPacked="<<trk->first.eta_packed()
00249                                         <<" me1D="<<trk->first.me1ID()
00250                                         <<" me2D="<<trk->first.me2ID()
00251                                         <<" me3D="<<trk->first.me3ID()
00252                                         <<" me4D="<<trk->first.me4ID()
00253                                         <<" mb1D="<<trk->first.mb1ID()
00254                                         <<" pTaddr="<<std::hex<<trk->first.ptLUTAddress()<<std::dec
00255                                         <<")"<<std::endl;
00256                         nEmulMuons++;
00257                 }
00258         }
00259 
00260         tree->Fill();
00261 }