CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/CSCTFRawToDigi/plugins/CSCTFAnalyzer.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCTFRawToDigi/interface/CSCTFAnalyzer.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 
00006 #include <strings.h>
00007 #include <errno.h>
00008 #include <iostream>
00009 #include <iomanip>
00010 
00011 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00012 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCTrackCollection.h"
00013 #include "DataFormats/L1CSCTrackFinder/interface/L1CSCStatusDigiCollection.h"
00014 #include "DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h"
00015 #include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
00016 
00017 CSCTFAnalyzer::CSCTFAnalyzer(const edm::ParameterSet &conf):edm::EDAnalyzer(){
00018         mbProducer    = conf.getUntrackedParameter<edm::InputTag>("mbProducer",edm::InputTag("csctfunpacker"));
00019         lctProducer   = conf.getUntrackedParameter<edm::InputTag>("lctProducer",edm::InputTag("csctfunpacker"));
00020         trackProducer = conf.getUntrackedParameter<edm::InputTag>("trackProducer",edm::InputTag("csctfunpacker"));
00021         statusProducer= conf.getUntrackedParameter<edm::InputTag>("statusProducer",edm::InputTag("csctfunpacker"));
00022         file = new TFile("ewq.root","RECREATE");
00023         tree = new TTree("dy","QWE");
00024         tree->Branch("dtPhi_1_plus",&dtPhi[0][0],"dtPhi_1_plus/I");
00025         tree->Branch("dtPhi_2_plus",&dtPhi[1][0],"dtPhi_2_plus/I");
00026         tree->Branch("dtPhi_3_plus",&dtPhi[2][0],"dtPhi_3_plus/I");
00027         tree->Branch("dtPhi_4_plus",&dtPhi[3][0],"dtPhi_4_plus/I");
00028         tree->Branch("dtPhi_5_plus",&dtPhi[4][0],"dtPhi_5_plus/I");
00029         tree->Branch("dtPhi_6_plus",&dtPhi[5][0],"dtPhi_6_plus/I");
00030         tree->Branch("dtPhi_7_plus",&dtPhi[6][0],"dtPhi_7_plus/I");
00031         tree->Branch("dtPhi_8_plus",&dtPhi[7][0],"dtPhi_8_plus/I");
00032         tree->Branch("dtPhi_9_plus",&dtPhi[8][0],"dtPhi_9_plus/I");
00033         tree->Branch("dtPhi_10_plus",&dtPhi[9][0],"dtPhi_10_plus/I");
00034         tree->Branch("dtPhi_11_plus",&dtPhi[10][0],"dtPhi_11_plus/I");
00035         tree->Branch("dtPhi_12_plus",&dtPhi[11][0],"dtPhi_12_plus/I");
00036         tree->Branch("dtPhi_1_minus",&dtPhi[0][1],"dtPhi_1_minus/I");
00037         tree->Branch("dtPhi_2_minus",&dtPhi[1][1],"dtPhi_2_minus/I");
00038         tree->Branch("dtPhi_3_minus",&dtPhi[2][1],"dtPhi_3_minus/I");
00039         tree->Branch("dtPhi_4_minus",&dtPhi[3][1],"dtPhi_4_minus/I");
00040         tree->Branch("dtPhi_5_minus",&dtPhi[4][1],"dtPhi_5_minus/I");
00041         tree->Branch("dtPhi_6_minus",&dtPhi[5][1],"dtPhi_6_minus/I");
00042         tree->Branch("dtPhi_7_minus",&dtPhi[6][1],"dtPhi_7_minus/I");
00043         tree->Branch("dtPhi_8_minus",&dtPhi[7][1],"dtPhi_8_minus/I");
00044         tree->Branch("dtPhi_9_minus",&dtPhi[8][1],"dtPhi_9_minus/I");
00045         tree->Branch("dtPhi_10_minus",&dtPhi[9][1],"dtPhi_10_minus/I");
00046         tree->Branch("dtPhi_11_minus",&dtPhi[10][1],"dtPhi_11_minus/I");
00047         tree->Branch("dtPhi_12_minus",&dtPhi[11][1],"dtPhi_12_minus/I");
00048 }
00049 
00050 void CSCTFAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& c){
00051 /*      edm::Handle<FEDRawDataCollection> rawdata;
00052         e.getByLabel("source","",rawdata);
00053 
00054         const FEDRawData& fedData = rawdata->FEDData(750);
00055         if( fedData.size()==0 ) return;
00056         unsigned short *data = (unsigned short *)fedData.data();
00057         unsigned int    size = fedData.size()/2;
00058         std::cout<<"New event:"<<std::endl;
00059         for(unsigned i=0; i<size/4; i++)
00060                 std::cout<<std::hex<<" "<<std::setw(6)<<data[i*4+0]<<" "<<std::setw(6)<<data[i*4+1]<<" "<<std::setw(6)<<data[i*4+2]<<" "<<std::setw(6)<<data[i*4+3]<<std::dec<<std::endl;
00061         std::cout<<"End of event"<<std::endl;
00062         return;
00063 */
00064         if( statusProducer.label() != "null" ){
00065                 edm::Handle<L1CSCStatusDigiCollection> status;
00066                 e.getByLabel(statusProducer.label(),statusProducer.instance(),status);
00067                 if( status.isValid() ){
00068                         edm::LogInfo("CSCTFAnalyzer") << "  Unpacking Errors: "<<status->first;
00069                         for(std::vector<L1CSCSPStatusDigi>::const_iterator stat=status->second.begin();
00070                                 stat!=status->second.end(); stat++){
00071                                 //edm::LogInfo("CSCTFAnalyzer") << "   Status: SP in slot "<<stat->slot()<<"  FMM: "<<stat->FMM()<<" SE: 0x"<<std::hex<<stat->SEs()<<" VP: 0x"<<stat->VPs()<<std::dec;
00072                         }
00073                 } else edm::LogInfo("CSCTFAnalyzer")<<"  No valid L1CSCStatusDigiCollection products found";
00074         }
00075 
00076         if( mbProducer.label() != "null" ){
00077                 bzero(dtPhi,sizeof(dtPhi));
00078                 edm::Handle<CSCTriggerContainer<csctf::TrackStub> > dtStubs;
00079                 e.getByLabel(mbProducer.label(),mbProducer.instance(),dtStubs);
00080                 if( dtStubs.isValid() ){
00081                         std::vector<csctf::TrackStub> vstubs = dtStubs->get();
00082                         std::cout<<"DT size="<<vstubs.end()-vstubs.begin()<<std::endl;
00083                         for(std::vector<csctf::TrackStub>::const_iterator stub=vstubs.begin(); stub!=vstubs.end(); stub++){
00084                                 int dtSector =(stub->sector()-1)*2 + stub->subsector()-1;
00085                                 int dtEndcap = stub->endcap()-1;
00086                                 if( dtSector>=0 && dtSector<12 && dtEndcap>=0 && dtEndcap<2 ){
00087                                         dtPhi[dtSector][dtEndcap] = stub->phiPacked();
00088                                 } else {
00089                                         edm::LogInfo("CSCTFAnalyzer: DT digi are out of range: ")<<" dtSector="<<dtSector<<" dtEndcap="<<dtEndcap;
00090                                 }
00091                                 edm::LogInfo("CSCTFAnalyzer")<<"   DT data: tbin="<<stub->BX()<<" CSC sector="<<stub->sector()<<" CSC subsector="<<stub->subsector()<<" station="<<stub->station()<<" endcap="<<stub->endcap()
00092                                                 <<" phi="<<stub->phiPacked()<<" phiBend="<<stub->getBend()<<" quality="<<stub->getQuality()<<" mb_bxn="<<stub->cscid();
00093                         }
00094                 } else edm::LogInfo("CSCTFAnalyzer")<<"  No valid CSCTriggerContainer<csctf::TrackStub> products found";
00095                 tree->Fill();
00096         }
00097 
00098         if( lctProducer.label() != "null" ){
00099                 edm::Handle<CSCCorrelatedLCTDigiCollection> corrlcts;
00100                 e.getByLabel(lctProducer.label(),lctProducer.instance(),corrlcts);
00101                 if( corrlcts.isValid() ){
00102                         for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=corrlcts.product()->begin(); csc!=corrlcts.product()->end(); csc++){
00103                                 int lctId=0;
00104                                 CSCCorrelatedLCTDigiCollection::Range range1 = corrlcts.product()->get((*csc).first);
00105                                 for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++,lctId++){
00106                                         int station = (*csc).first.station()-1;
00107                                         int cscId   = (*csc).first.triggerCscId()-1;
00108                                         int sector  = (*csc).first.triggerSector()-1;// + ( (*csc).first.endcap()==1 ? 0 : 6 );
00109                                         int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00110                                         int tbin    = lct->getBX();
00111                                         int fpga    = ( subSector ? subSector-1 : station+1 );
00112                                         // If Det Id is within range
00113                                         if( sector<0 || sector>11 || station<0 || station>3 || cscId<0 || cscId>8 || lctId<0 || lctId>1){
00114                                                 edm::LogInfo("CSCTFAnalyzer: CSC digi are out of range: ");
00115                                                 continue;
00116                                         }
00117                                         edm::LogInfo("CSCTFAnalyzer")<<"   Front data   endcap: "<<(*csc).first.endcap()<<"  station: "<<(station+1)<<"  sector: "<<(sector+1)<<"  subSector: "<<subSector<<"  tbin: "<<tbin<<"  cscId: "<<(cscId+1)<<"  fpga: "<<(fpga+1)<<" "<<
00118                                                 "LCT(vp="<<lct->isValid()<<",qual="<<lct->getQuality()<<",wg="<<lct->getKeyWG()<<",strip="<<lct->getStrip()<<",link="<<lct->getMPCLink()<<")";
00119                                 }
00120                         }
00121                 } else edm::LogInfo("CSCTFAnalyzer")<<"  No valid CSCCorrelatedLCTDigiCollection products found";
00122         }
00123 
00124         if( trackProducer.label() != "null" ){
00125                 edm::Handle<L1CSCTrackCollection> tracks;
00126                 e.getByLabel(trackProducer.label(),trackProducer.instance(),tracks);
00127                 if( tracks.isValid() ){
00128                         int nTrk=0;
00129                         for(L1CSCTrackCollection::const_iterator trk=tracks->begin(); trk<tracks->end(); trk++,nTrk++){
00130                                 int sector = 6*(trk->first.endcap()-1)+trk->first.sector()-1;
00131                                 int tbin   = trk->first.BX();
00132                                 edm::LogInfo("CSCTFAnalyzer") << "   Track sector: "<<(sector+1)<<"  tbin: "<<tbin<<" "<<
00133                                         "TRK(mode="<<((trk->first.ptLUTAddress()>>16)&0xF)<<",eta="<<trk->first.eta_packed()<<",phi="<<trk->first.localPhi()<<") IDs:"
00134                                         <<" me1D="<<trk->first.me1ID()<<" t1="<<trk->first.me1Tbin()
00135                                         <<" me2D="<<trk->first.me2ID()<<" t2="<<trk->first.me2Tbin()
00136                                         <<" me3D="<<trk->first.me3ID()<<" t3="<<trk->first.me3Tbin()
00137                                         <<" me4D="<<trk->first.me4ID()<<" t4="<<trk->first.me4Tbin()
00138                                         <<" mb1D="<<trk->first.mb1ID()<<" tb="<<trk->first.mb1Tbin();
00139 
00140                         for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=trk->second.begin(); csc!=trk->second.end(); csc++){
00141                                 int lctId=0;
00142                                 CSCCorrelatedLCTDigiCollection::Range range1 = trk->second.get((*csc).first);
00143                                 for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++,lctId++){
00144                                         int station = (*csc).first.station()-1;
00145                                         int cscId   = (*csc).first.triggerCscId()-1;
00146                                         int sector  = (*csc).first.triggerSector()-1;// + ( (*csc).first.endcap()==1 ? 0 : 6 );
00147                                         int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
00148                                         int tbin    = lct->getBX();
00149                                         int fpga    = ( subSector ? subSector-1 : station+1 );
00150                                         // If Det Id is within range
00151                                         if( sector<0 || sector>11 || station<0 || station>3 || cscId<0 || cscId>8 || lctId<0 || lctId>1){
00152                                                 edm::LogInfo("CSCTFAnalyzer: Digi are out of range: ");
00153                                                 continue;
00154                                         }
00155                                         if( lct->getQuality() < 100 )
00156                                                 edm::LogInfo("CSCTFAnalyzer")<<"       Linked LCT: "<<(*csc).first.endcap()<<"  station: "<<(station+1)<<"  sector: "<<(sector+1)<<"  subSector: "<<subSector<<"  tbin: "<<tbin
00157                                                         <<"  cscId: "<<(cscId+1)<<"  fpga: "<<(fpga+1)<<" LCT(vp="<<lct->isValid()<<",qual="<<lct->getQuality()<<",wg="<<lct->getKeyWG()<<",strip="<<lct->getStrip()<<")";
00158                                         else
00159                                                 edm::LogInfo("CSCTFAnalyzer")<<"       Linked MB stub: "<<(*csc).first.endcap()<<"  sector: "<<(sector+1)<<"  subSector: "<<subSector<<"  tbin: "<<tbin
00160                                                         <<" MB(vp="<<lct->isValid()<<",qual="<<(lct->getQuality()-100)<<",cal="<<lct->getKeyWG()<<",flag="<<lct->getStrip()<<",bc0="<<lct->getPattern()<<",phiBend="<<lct->getBend()
00161                                                         <<",tbin="<<lct->getBX()<<",id="<<lct->getMPCLink()<<",bx0="<<lct->getBX0()<<",se="<<lct->getSyncErr()<<",bxn="<<lct->getCSCID()<<",phi="<<lct->getTrknmb()<<")";
00162                                 }
00163                         }
00164                         }
00165                 } else edm::LogInfo("CSCTFAnalyzer")<<"  No valid L1CSCTrackCollection products found";
00166         }
00167 }