CMS 3D CMS Logo

CSCTFUnpacker Class Reference

#include <EventFilter/CSCTFRawToDigi/interface/CSCTFUnpacker.h>

Inheritance diagram for CSCTFUnpacker:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 CSCTFUnpacker (const edm::ParameterSet &pset)
void produce (edm::Event &e, const edm::EventSetup &c)
 ~CSCTFUnpacker (void)

Private Attributes

int m_maxBX
int m_minBX
CSCTriggerMappingmapping
edm::InputTag producer
std::vector< intslot2sector
bool swapME1strips
CSCTFEvent tfEvent


Detailed Description

Definition at line 16 of file CSCTFUnpacker.h.


Constructor & Destructor Documentation

CSCTFUnpacker::CSCTFUnpacker ( const edm::ParameterSet pset  ) 

Definition at line 36 of file CSCTFUnpacker.cc.

References CSCTriggerMapping::addRecord(), GeomDetEnumerators::endcap, Exception, edm::pset::fill(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), LogDebug, m_maxBX, m_minBX, mapping, producer, slot2sector, and swapME1strips.

00036                                                        :edm::EDProducer(),mapping(0){
00037         LogDebug("CSCTFUnpacker|ctor")<<"Started ...";
00038 
00039         // Edges of the time window, which LCTs are put into (unlike tracks, which are always centred around 0):
00040         m_minBX = pset.getParameter<int>("MinBX"); //3
00041         m_maxBX = pset.getParameter<int>("MaxBX"); //9
00042 
00043         // Swap: if(swapME1strips && me1b && !zplus) strip = 65 - strip; // 1-64 -> 64-1 :
00044         swapME1strips = pset.getParameter<bool>("swapME1strips");
00045 
00046         // Initialize slot<->sector assignment
00047         slot2sector = pset.getParameter< std::vector<int> >("slot2sector");
00048         LogDebug("CSCTFUnpacker|ctor")<<"Verifying slot<->sector map from 'untracked vint32 slot2sector'";
00049         for(int slot=0; slot<22; slot++)
00050                 if( slot2sector[slot]<0 || slot2sector[slot]>12 )
00051                         throw cms::Exception("Invalid configuration")<<"CSCTFUnpacker: sector index is set out of range (slot2sector["<<slot<<"]="<<slot2sector[slot]<<", should be [0-12])";
00052         // Just for safety (in case of bad data):
00053         slot2sector.resize(32);
00054 
00055         // As we use standard CSC digi containers, we have to initialize mapping:
00056         std::string mappingFile = pset.getParameter<std::string>("mappingFile");
00057         if( mappingFile.length() ){
00058                 LogDebug("CSCTFUnpacker|ctor") << "Define ``mapping'' only if you want to screw up real geometry";
00059                 mapping = new CSCTriggerMappingFromFile(mappingFile);
00060         } else {
00061                 LogDebug("CSCTFUnpacker|ctor") << "Generating default hw<->geometry mapping";
00062                 class M: public CSCTriggerSimpleMapping{ void fill(void){} };
00063                 mapping = new M();
00064                 for(int endcap=1; endcap<=2; endcap++)
00065                         for(int station=1; station<=4; station++)
00066                                 for(int sector=1; sector<=6; sector++)
00067                                         for(int csc=1; csc<=9; csc++){
00068                                                 if( station==1 ){
00069                                                         mapping->addRecord(endcap,station,sector,1,csc,endcap,station,sector,1,csc);
00070                                                         mapping->addRecord(endcap,station,sector,2,csc,endcap,station,sector,2,csc);
00071                                                 } else
00072                                                         mapping->addRecord(endcap,station,sector,0,csc,endcap,station,sector,0,csc);
00073                                         }
00074         }
00075 
00076         producer = pset.getUntrackedParameter<edm::InputTag>("producer",edm::InputTag("source"));
00077 
00078         produces<CSCCorrelatedLCTDigiCollection>();
00079         produces<L1CSCTrackCollection>();
00080         produces<L1CSCStatusDigiCollection>();
00081 
00082         LogDebug("CSCTFUnpacker|ctor") << "... and finished";
00083 }

CSCTFUnpacker::~CSCTFUnpacker ( void   ) 

Definition at line 85 of file CSCTFUnpacker.cc.

References mapping.

00085                              {
00086         if( mapping ) delete mapping;
00087 }


Member Function Documentation

void CSCTFUnpacker::produce ( edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDProducer.

Definition at line 89 of file CSCTFUnpacker.cc.

References L1CSCSPStatusDigi::af, CSCSPRecord::AFs(), L1CSCSPStatusDigi::bx, CSCSPHeader::BXN(), CSCSPRecord::BXs(), CSCSPEvent::counters(), FEDRawData::data(), CSCTriggerMapping::detId(), GeomDetEnumerators::endcap, CSCSPHeader::endcap(), first, L1CSCSPStatusDigi::fmm_status, edm::Event::getByLabel(), FEDNumbering::getCSCTFFEDIds(), CSCSPEvent::header(), edm::InputTag::instance(), int, iter, CSCSPHeader::L1A(), L1CSCSPStatusDigi::l1a_bxn, edm::InputTag::label(), CSCSPRecord::LCT(), link(), L1CSCSPStatusDigi::link_status, m_maxBX, m_minBX, mapping, L1CSCSPStatusDigi::mpc_link_id, CSCSPHeader::nTBINs(), L1CSCSPStatusDigi::orbit_cnt, CSCSPCounters::orbit_counter(), producer, CSCSPRecord::ptSpy(), CSCSPRecord::ptSpyTrack(), edm::Event::put(), CSCSPEvent::record(), L1CSCSPStatusDigi::se, CSCSPHeader::sector(), CSCSPRecord::SEs(), FEDRawData::size(), CSCSPHeader::slot(), slot2sector, L1CSCSPStatusDigi::sm, CSCSPRecord::SMs(), L1CSCSPStatusDigi::sp_slot, CSCTFEvent::SPs_fast(), StDecayID::status, CSCSPHeader::status(), strip(), swapME1strips, tfEvent, track, L1CSCSPStatusDigi::track_cnt, CSCSPCounters::track_counter(), CSCSPRecord::tracks(), tracks, CSCTFEvent::unpack(), L1CSCSPStatusDigi::vp, CSCSPRecord::VPs(), and cms::Exception::what().

00089                                                               {
00090         // Get a handle to the FED data collection
00091         edm::Handle<FEDRawDataCollection> rawdata;
00092         e.getByLabel(producer.label(),producer.instance(),rawdata);
00093 
00094         // create the collection of CSC wire and strip Digis
00095         std::auto_ptr<CSCCorrelatedLCTDigiCollection> LCTProduct(new CSCCorrelatedLCTDigiCollection);
00096         std::auto_ptr<L1CSCTrackCollection>           trackProduct(new L1CSCTrackCollection);
00097         std::auto_ptr<L1CSCStatusDigiCollection>      statusProduct(new L1CSCStatusDigiCollection);
00098 
00099         for(int fedid=FEDNumbering::getCSCTFFEDIds().first; fedid<=FEDNumbering::getCSCTFFEDIds().second; fedid++){
00100                 const FEDRawData& fedData = rawdata->FEDData(fedid);
00101                 if( fedData.size()==0 ) continue;
00102                 //LogDebug("CSCTFUnpacker|produce");
00103                 //if( monitor ) monitor->process((unsigned short*)fedData.data());
00104                 unsigned int unpacking_status = tfEvent.unpack((unsigned short*)fedData.data(),fedData.size()/2);
00105                 if( unpacking_status==0 ){
00106                         // There may be several SPs in event
00107                         std::vector<const CSCSPEvent*> SPs = tfEvent.SPs_fast();
00108                         // Cycle over all of them
00109                         for(std::vector<const CSCSPEvent *>::const_iterator spItr=SPs.begin(); spItr!=SPs.end(); spItr++){
00110                                 const CSCSPEvent *sp = *spItr;
00111 
00112                                 L1CSCSPStatusDigi status; 
00113                                 status.sp_slot    = sp->header().slot();
00114                                 status.l1a_bxn    = sp->header().BXN();
00115                                 status.fmm_status = sp->header().status();
00116                                 status.track_cnt  = sp->counters().track_counter();
00117                                 status.orbit_cnt  = sp->counters().orbit_counter();
00118 
00119                                 // Finds central LCT BX
00120                                 // assumes window is odd number of bins
00121                                 int central_lct_bx = (m_maxBX + m_minBX)/2;
00122 
00123                                 // Find central SP BX
00124                                 // assumes window is odd number of bins
00125                                 int central_sp_bx = int(sp->header().nTBINs()/2);
00126 
00127                                 for(unsigned int tbin=0; tbin<sp->header().nTBINs(); tbin++){
00128 
00129                                         status.se |= sp->record(tbin).SEs();
00130                                         status.sm |= sp->record(tbin).SMs();
00131                                         status.bx |= sp->record(tbin).BXs();
00132                                         status.af |= sp->record(tbin).AFs();
00133                                         status.vp |= sp->record(tbin).VPs();
00134 
00135                                         for(unsigned int FPGA=0; FPGA<5; FPGA++)
00136                                                 for(unsigned int MPClink=0; MPClink<3; ++MPClink){
00137                                                         std::vector<CSCSP_MEblock> lct = sp->record(tbin).LCT(FPGA,MPClink);
00138                                                         if( lct.size()==0 ) continue;
00139 
00140                                                         status.link_status[lct[0].spInput()] |=
00141                                                                 (1<<lct[0].receiver_status_frame1())|
00142                                                                 (1<<lct[0].receiver_status_frame2())|
00143                                                                 ((lct[0].aligment_fifo()?1:0)<<4);
00144                                                         status.mpc_link_id |= (lct[0].link()<<2)|lct[0].mpc();
00145 
00146                                                         int station = ( FPGA ? FPGA : 1 );
00147                                                         int endcap=0, sector=0;
00148                                                         if( slot2sector[sp->header().slot()] ){
00149                                                                 endcap = slot2sector[sp->header().slot()]/7 + 1;
00150                                                                 sector = slot2sector[sp->header().slot()];
00151                                                                 if( sector>6 ) sector -= 6;
00152                                                         } else {
00153                                                                 endcap = (sp->header().endcap()?1:2);
00154                                                                 sector =  sp->header().sector();
00155                                                         }
00156                                                         int subsector = ( FPGA>1 ? 0 : FPGA+1 );
00157                                                         int cscid   = lct[0].csc() ;
00158 
00159                                                         try{
00160                                                                 CSCDetId id = mapping->detId(endcap,station,sector,subsector,cscid,0);
00161                                                                 // corrlcts now have no layer associated with them
00162                                                                 LCTProduct->insertDigi(id,
00163                                                                         CSCCorrelatedLCTDigi(
00164                                                                                 0,lct[0].vp(),lct[0].quality(),lct[0].wireGroup(),
00165                                                                                 (swapME1strips && cscid<=3 && station==1 && endcap==2 && lct[0].strip()<65 ? 65 - lct[0].strip() : lct[0].strip() ),
00166                                                                                 lct[0].pattern(),lct[0].l_r(),
00167                                                                                 (lct[0].tbin()+(central_lct_bx-central_sp_bx)),
00168                                                                                 lct[0].link(), lct[0].BXN(), 0, cscid )
00169                                                                         );
00170 
00171 // LogDebug("CSCUnpacker|produce") << "Unpacked digi: "<< aFB.frontDigiData(FPGA,MPClink);
00172 
00173                                                         } catch(cms::Exception &e) {
00174                                                                 edm::LogInfo("CSCTFUnpacker|produce") << e.what() << "Not adding digi to collection in event "
00175                                                                       <<sp->header().L1A()<<" (endcap="<<endcap<<",station="<<station<<",sector="<<sector<<",subsector="<<subsector<<",cscid="<<cscid<<",spSlot="<<sp->header().slot()<<")";
00176                                                         }
00177 
00178                                                 }
00179 
00180                                         std::vector<CSCSP_SPblock> tracks = sp->record(tbin).tracks();
00181                                         unsigned int trkNumber=0;
00182                                         for(std::vector<CSCSP_SPblock>::const_iterator iter=tracks.begin(); iter!=tracks.end(); iter++,trkNumber++){
00183                                                 L1CSCTrack track;
00184                                                 if( slot2sector[sp->header().slot()] ){
00185                                                         track.first.m_endcap = slot2sector[sp->header().slot()]/7 + 1;
00186                                                         track.first.m_sector = slot2sector[sp->header().slot()];
00187                                                         if(  track.first.m_sector>6 ) track.first.m_sector -= 6;
00188                                                 } else {
00189                                                         track.first.m_endcap = (sp->header().endcap()?1:2);
00190                                                         track.first.m_sector =  sp->header().sector();
00191                                                 }
00192 
00193                                                 track.first.m_lphi      = iter->phi();
00194                                                 track.first.m_ptAddress = iter->ptLUTaddress();
00195                                                 track.first.m_ptAddress|=(iter->f_r() << 21);
00196                                                 track.first.setStationIds(iter->ME1_id(),iter->ME2_id(),iter->ME3_id(),iter->ME4_id(),iter->MB_id());
00197                                                 track.first.setBx(iter->tbin()-central_sp_bx);
00198 
00199                                                 track.first.setPhiPacked(iter->phi());
00200                                                 track.first.setEtaPacked(iter->eta());
00201                                                 track.first.setChargePacked((~iter->charge())&0x1);
00202 
00203                                                 track.first.m_output_link = sp->record(tbin).ptSpyTrack();
00204                                                 if( track.first.m_output_link ){
00205                                                         track.first.m_rank = (iter->f_r()?sp->record(tbin).ptSpy()&0x1F:(sp->record(tbin).ptSpy()&0x1F00)>>8);
00206                                                         track.first.setChargeValidPacked((iter->f_r()?(sp->record(tbin).ptSpy()&0x80)>>8:(sp->record(tbin).ptSpy()&0x8000)>>15));
00207                                                 } else {
00208                                                         track.first.m_rank = 0;
00209                                                         track.first.setChargeValidPacked(0);
00210                                                 }
00211                                                 track.first.setFineHaloPacked(iter->halo());
00212 
00213 //                                              track.first.m_winner = iter->MS_id()&(1<<trkNumber);
00214 
00215                                                 std::vector<CSCSP_MEblock> lcts = iter->LCTs();
00216 
00217                                                 for(std::vector<CSCSP_MEblock>::const_iterator lct=lcts.begin(); lct!=lcts.end(); lct++){
00218                                                         int station   = ( lct->spInput()>6 ? (lct->spInput()-1)/3 : 1 );
00219                                                         int subsector = ( lct->spInput()>6 ? 0 : (lct->spInput()-1)/3 + 1 );
00220                                                         try{
00221                                                                 CSCDetId id = mapping->detId(track.first.m_endcap,station,track.first.m_sector,subsector,lct->csc(),0);
00222                                                                 track.second.insertDigi(id,
00223                                                                         CSCCorrelatedLCTDigi(
00224                                                                                 0,lct->vp(),lct->quality(),lct->wireGroup(),
00225                                                                                 (swapME1strips && lct->csc()<=3 && station==1 && track.first.m_endcap==2 && lct[0].strip()<65 ? 65 - lct[0].strip() : lct[0].strip() ),
00226                                                                                 lct->pattern(),lct->l_r(),
00227                                                                                 (lct->tbin()+(central_lct_bx-central_sp_bx)),
00228                                                                                 lct->link(), lct->BXN(), 0, lct->csc() )
00229                                                                         );
00230                                                         } catch(cms::Exception &e) {
00231                                                                 edm::LogInfo("CSCTFUnpacker|produce") << e.what() << "Not adding track digi to collection in event"
00232                                                                       <<sp->header().L1A()<<" (endcap="<<track.first.m_endcap<<",station="<<station<<",sector="<<track.first.m_sector<<",subsector="<<subsector<<",cscid="<<lct->csc()<<",spSlot="<<sp->header().slot()<<")";
00233                                                         }
00234                                                 }
00235                                                 trackProduct->push_back( track );
00236                                         }
00237                                 }
00238                                 statusProduct->second.push_back( status );
00239                         }
00240                 } else {
00241                         edm::LogError("CSCTFUnpacker|produce")<<" problem of unpacking TF event: 0x"<<std::hex<<unpacking_status<<std::dec<<" code";
00242                 }
00243 
00244                 statusProduct->first  = unpacking_status;
00245 
00246         } //end of fed cycle
00247         e.put(LCTProduct); // put processed lcts into the event.
00248         e.put(trackProduct);
00249         e.put(statusProduct);
00250 }


Member Data Documentation

int CSCTFUnpacker::m_maxBX [private]

Definition at line 18 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

int CSCTFUnpacker::m_minBX [private]

Definition at line 18 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

CSCTriggerMapping* CSCTFUnpacker::mapping [private]

Definition at line 21 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), produce(), and ~CSCTFUnpacker().

edm::InputTag CSCTFUnpacker::producer [private]

Definition at line 30 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

std::vector<int> CSCTFUnpacker::slot2sector [private]

Definition at line 27 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

bool CSCTFUnpacker::swapME1strips [private]

Definition at line 19 of file CSCTFUnpacker.h.

Referenced by CSCTFUnpacker(), and produce().

CSCTFEvent CSCTFUnpacker::tfEvent [private]

Definition at line 23 of file CSCTFUnpacker.h.

Referenced by produce().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:17:30 2009 for CMSSW by  doxygen 1.5.4