CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/L1Trigger/TextToDigi/plugins/RctDigiToSourceCardText.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    RctDigiToSourceCardText
00004 // Class:      RctDigiToSourceCardText
00005 // 
00011 //
00012 // Original Author:  Alex Tapper
00013 //         Created:  Fri Feb 16 14:52:19 CET 2007
00014 // $Id: RctDigiToSourceCardText.cc,v 1.4 2010/08/06 20:24:40 wmtan Exp $
00015 //
00016 //
00017 
00018 #include "RctDigiToSourceCardText.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h" // Logger
00021 
00022 using namespace edm;
00023 using namespace std;
00024 
00025 // Set constant
00026 const static int NUM_RCT_CRATES = 18;
00027 
00028 RctDigiToSourceCardText::RctDigiToSourceCardText(const edm::ParameterSet& iConfig):
00029   m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
00030   m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
00031   m_nevt(0)
00032 {
00033   // Open the output file
00034   m_file.open(m_textFileName.c_str(),std::ios::out);
00035 
00036   if(!m_file.good())
00037     {
00038       throw cms::Exception("RctDigiToSourceCardTextFileOpenError")
00039         << "RctDigiToSourceCardText::RctDigiToSourceCardText : "
00040         << " couldn't open the file " << m_textFileName << " for writing" << std::endl;
00041     }
00042 
00043   // Make a SC routing object
00044   SourceCardRouting m_scRouting; 
00045 }
00046 
00047 
00048 RctDigiToSourceCardText::~RctDigiToSourceCardText()
00049 {
00050   // Close the output file
00051   m_file.close();
00052 }
00053 
00054 // ------------ method called to for each event  ------------
00055 void RctDigiToSourceCardText::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00056 {
00057 
00058   // get the RCT data
00059   Handle<L1CaloEmCollection> em;
00060   Handle<L1CaloRegionCollection> rgn;
00061   iEvent.getByLabel(m_rctInputLabel, em);
00062   iEvent.getByLabel(m_rctInputLabel, rgn);
00063 
00064   // General variables
00065   int RoutingMode;
00066   unsigned short logicalCardID;
00067   std::string dataString;
00068 
00069   // Arrays to hold electron variables
00070   unsigned short eIsoRank[18][4]={{0}};
00071   unsigned short eIsoCardId[18][4]={{0}};
00072   unsigned short eIsoRegionId[18][4]={{0}};
00073   unsigned short eNonIsoRank[18][4]={{0}};
00074   unsigned short eNonIsoCardId[18][4]={{0}};
00075   unsigned short eNonIsoRegionId[18][4]={{0}};
00076 
00077   // Fill electrons
00078   unsigned numIsoEM[18]={0};
00079   unsigned numNonIsoEM[18]={0};
00080 
00081   for (L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); iem++){
00082     if (iem->isolated()){
00083       eIsoRank[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rank();
00084       eIsoCardId[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rctCard();
00085       eIsoRegionId[iem->rctCrate()][numIsoEM[iem->rctCrate()]]=iem->rctRegion();
00086       numIsoEM[iem->rctCrate()]++;
00087     } else {
00088       eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rank();
00089       eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctCard();
00090       eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]]=iem->rctRegion();
00091       numNonIsoEM[iem->rctCrate()]++;
00092     }
00093     // Debug info
00094     LogDebug("Electrons") << "Rank=" << iem->rank()
00095                           << " Card=" << iem->rctCard()
00096                           << " Region=" << iem->rctRegion()
00097                           << " Crate=" << iem->rctCrate()
00098                           << " Isolated=" << iem->isolated();
00099   }
00100 
00101   // Arrays to hold region variables
00102   unsigned short RC[18][7][2]={{{0}}};
00103   unsigned short RCof[18][7][2]={{{0}}};
00104   unsigned short RCtau[18][7][2]={{{0}}};
00105   unsigned short HF[18][4][2]={{{0}}};
00106   unsigned short HFQ[18][4][2]={{{0}}};
00107   unsigned short MIPbits[18][7][2]={{{0}}};
00108   unsigned short Qbits[18][7][2]={{{0}}};  
00109 
00110   // Fill regions
00111   for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
00112     if (irgn->id().isHf()){
00113       HF[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->et();
00114       HFQ[irgn->rctCrate()][irgn->id().rctEta()-7][irgn->id().rctPhi()]=irgn->fineGrain();      
00115       // Debug info
00116       LogDebug("HFRegions") << "Et=" << irgn->et()
00117                             << " FineGrain=" << irgn->fineGrain()
00118                             << " Eta=" << irgn->id().rctEta()
00119                             << " Phi=" << irgn->id().rctPhi()
00120                             << " Crate=" << irgn->rctCrate();
00121     } else {
00122       RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->et();         
00123       RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->overFlow();                 
00124       RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->tauVeto();
00125       MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->mip();
00126       Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()]=irgn->quiet();
00127       // Debug info
00128       LogDebug("Regions") << "Et=" << irgn->et()
00129                           << " OverFlow=" << irgn->overFlow()
00130                           << " tauVeto=" << irgn->tauVeto()
00131                           << " mip=" << irgn->mip()
00132                           << " quiet=" << irgn->quiet()
00133                           << " Card=" << irgn->rctCard()
00134                           << " Region=" << irgn->rctRegionIndex()
00135                           << " Crate=" << irgn->rctCrate();
00136     }
00137   }
00138 
00139   for (int crate=0; crate<NUM_RCT_CRATES; crate++){
00140 
00141     // Logical Card ID = Source Card number
00142     RoutingMode=0;
00143     m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
00144 
00145     // Convert electrons to SC format
00146     m_scRouting.EMUtoSTRING(logicalCardID,
00147                             m_nevt,
00148                             eIsoRank[crate],
00149                             eIsoCardId[crate],
00150                             eIsoRegionId[crate],
00151                             eNonIsoRank[crate],
00152                             eNonIsoCardId[crate],
00153                             eNonIsoRegionId[crate],
00154                             MIPbits[crate],
00155                             Qbits[crate],
00156                             dataString);
00157 
00158     // Write electrons
00159     m_file << dataString;
00160 
00161     // Logical Card ID = Source Card number
00162     RoutingMode=1;
00163     m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
00164  
00165     // Convert regions to SC format
00166     m_scRouting.RC56HFtoSTRING(logicalCardID,
00167                                m_nevt,
00168                                RC[crate],
00169                                RCof[crate],
00170                                RCtau[crate],
00171                                HF[crate],
00172                                HFQ[crate],
00173                                dataString);
00174   
00175     // Write regions
00176     m_file << dataString;
00177 
00178     // Logical Card ID = Source Card number             
00179     RoutingMode=2;
00180     m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
00181 
00182     // Convert regions to SC format  
00183     m_scRouting.RC012toSTRING(logicalCardID,
00184                               m_nevt,
00185                               RC[crate],
00186                               RCof[crate],
00187                               RCtau[crate],
00188                               dataString);
00189 
00190     // Write regions
00191     m_file << dataString;
00192 
00193     // This is to 9 only as this is the shared source card
00194     if (crate<9){ 
00195       // Logical Card ID = Source Card number
00196       RoutingMode=3;                                    
00197       m_scRouting.RoutingModetoLogicalCardID(logicalCardID,RoutingMode,crate);
00198   
00199       // Convert regions to SC format    
00200       m_scRouting.RC234toSTRING(logicalCardID,
00201                                 m_nevt,
00202                                 RC[crate],
00203                                 RCof[crate],
00204                                 RCtau[crate],
00205                                 RC[crate+9],
00206                                 RCof[crate+9],
00207                                 RCtau[crate+9],
00208                                 dataString);
00209     
00210       // Write regions
00211       m_file << dataString;
00212     }
00213     
00214   }
00215   
00216   // Force write to file 
00217   m_file << flush;
00218 
00219   m_nevt++;
00220 }
00221