CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Calibration/HcalIsolatedTrackReco/src/ECALRegFEDSelector.cc

Go to the documentation of this file.
00001 
00002 #include "Calibration/HcalIsolatedTrackReco/interface/ECALRegFEDSelector.h"
00003 #include "EventFilter/EcalRawToDigi/interface/EcalRegionCabling.h"
00004 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00005 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
00006 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
00007 
00008 ECALRegFEDSelector::ECALRegFEDSelector(const edm::ParameterSet& iConfig)
00009 {
00010   seedLabel_=iConfig.getParameter<edm::InputTag>("regSeedLabel");
00011   delta_=iConfig.getParameter<double>("delta");
00012   
00013   rawInLabel_=iConfig.getParameter<edm::InputTag>("rawInputLabel");
00014 
00015   ec_mapping = new EcalElectronicsMapping();
00016 
00017   produces<FEDRawDataCollection>();
00018   produces<EcalListOfFEDS>();
00019 
00020   for (int p=0; p<1200; p++)
00021     {
00022       fedSaved[p]=false;
00023     }
00024 }
00025 
00026 
00027 ECALRegFEDSelector::~ECALRegFEDSelector()
00028 {
00029 }
00030 
00031 
00032 void ECALRegFEDSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00033 {
00034   for (int p=0; p<1200; p++)
00035     {
00036       fedSaved[p]=false;
00037     }
00038 
00039   std::auto_ptr<FEDRawDataCollection> producedData(new FEDRawDataCollection);
00040 
00041   std::auto_ptr<EcalListOfFEDS> fedList(new EcalListOfFEDS);  
00042 
00043   edm::Handle<trigger::TriggerFilterObjectWithRefs> trigSeedTrks;
00044   iEvent.getByLabel(seedLabel_,trigSeedTrks);
00045 
00046   std::vector< edm::Ref<reco::IsolatedPixelTrackCandidateCollection> > isoPixTrackRefs;
00047   trigSeedTrks->getObjects(trigger::TriggerTrack, isoPixTrackRefs);
00048 
00049   edm::Handle<FEDRawDataCollection> rawIn;
00050   iEvent.getByLabel(rawInLabel_,rawIn);
00051 
00052   //  std::vector<int> EC_FED_IDs;
00053   
00054   for (uint32_t p=0; p<isoPixTrackRefs.size(); p++)
00055     {
00056       double etaObj_=isoPixTrackRefs[p]->track()->eta();
00057       double phiObj_=isoPixTrackRefs[p]->track()->phi();
00058 
00059       EcalEtaPhiRegion ecEtaPhi(etaObj_-delta_,etaObj_+delta_,phiObj_-delta_,phiObj_+delta_);
00060       
00061       const std::vector<int> EC_FED_IDs=ec_mapping->GetListofFEDs(ecEtaPhi);
00062       
00063       const FEDRawDataCollection *rdc=rawIn.product();
00064       
00065       for ( int j=0; j< FEDNumbering::MAXFEDID; j++ ) 
00066         {
00067           bool rightFED=false;
00068           for (uint32_t k=0; k<EC_FED_IDs.size(); k++)
00069             {
00070               if (j==EcalRegionCabling::fedIndex(EC_FED_IDs[k])) 
00071                 {
00072                   if (!fedSaved[j]) 
00073                     {
00074                       fedList->AddFED(j);
00075                       rightFED=true;
00076                       fedSaved[j]=true;
00077                     }
00078                 }
00079             }
00080           if (j>=FEDNumbering::MINPreShowerFEDID&&j<=FEDNumbering::MAXPreShowerFEDID) 
00081             {
00082               fedSaved[j]=true;
00083               rightFED=true;
00084             }
00085           if (!rightFED) continue;
00086           const FEDRawData & fedData = rdc->FEDData(j);
00087           size_t size=fedData.size();
00088           
00089           if ( size > 0 ) 
00090             {
00091               // this fed has data -- lets copy it
00092               FEDRawData & fedDataProd = producedData->FEDData(j);
00093               if ( fedDataProd.size() != 0 ) 
00094                 {
00095 //                std::cout << " More than one FEDRawDataCollection with data in FED ";
00096 //                std::cout << j << " Skipping the 2nd\n";
00097                   continue;
00098                 }
00099               fedDataProd.resize(size);
00100               unsigned char *dataProd=fedDataProd.data();
00101               const unsigned char *data=fedData.data();
00102               for ( unsigned int k=0; k<size; ++k ) 
00103                 {
00104                   dataProd[k]=data[k];
00105                 }
00106             }
00107           
00108         }
00109     }
00110 
00111   iEvent.put(producedData);  
00112   iEvent.put(fedList);
00113   
00114 }
00115 
00116 
00117 void ECALRegFEDSelector::beginJob() {
00118 }
00119 
00120 
00121 void ECALRegFEDSelector::endJob() {
00122 }