CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Calibration/HcalIsolatedTrackReco/src/SiStripRegFEDSelector.cc

Go to the documentation of this file.
00001 
00002 #include "Calibration/HcalIsolatedTrackReco/interface/SiStripRegFEDSelector.h"
00003 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
00004 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00005 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00006 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
00007 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
00008 
00009 SiStripRegFEDSelector::SiStripRegFEDSelector(const edm::ParameterSet& iConfig)
00010 {
00011   seedLabel_=iConfig.getParameter<edm::InputTag>("regSeedLabel");
00012   delta_=iConfig.getParameter<double>("delta");
00013   
00014   rawInLabel_=iConfig.getParameter<edm::InputTag>("rawInputLabel");
00015 
00016   produces<FEDRawDataCollection>();
00017 }
00018 
00019 
00020 SiStripRegFEDSelector::~SiStripRegFEDSelector()
00021 {
00022  
00023 }
00024 
00025 void
00026 SiStripRegFEDSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00027 {
00028   std::auto_ptr<FEDRawDataCollection> producedData(new FEDRawDataCollection);
00029 
00030   edm::Handle<trigger::TriggerFilterObjectWithRefs> trigSeedTrks;
00031   iEvent.getByLabel(seedLabel_,trigSeedTrks);
00032   
00033   std::vector< edm::Ref<reco::IsolatedPixelTrackCandidateCollection> > isoPixTrackRefs;
00034   trigSeedTrks->getObjects(trigger::TriggerTrack, isoPixTrackRefs);
00035  
00036   edm::Handle<FEDRawDataCollection> rawIn;
00037   iEvent.getByLabel(rawInLabel_,rawIn);
00038   
00039   iSetup.get<SiStripRegionCablingRcd>().get(strip_cabling);
00040   
00041   std::vector<int> stripFEDVec; 
00042   
00043   //get vector of regions
00044   const SiStripRegionCabling::Cabling ccab=strip_cabling->getRegionCabling();
00045   
00046   //size of region (eta,phi)
00047   const std::pair<double,double> regDim=strip_cabling->regionDimensions();
00048   
00049   const SiStripRegionCabling::ElementCabling elcabling;
00050   
00051   bool fedSaved[1000];
00052   for (int i=0; i<1000; i++) fedSaved[i]=false;
00053   
00054   //cycle on seeds
00055   for (uint32_t p=0; p<isoPixTrackRefs.size(); p++)
00056     {
00057       double etaObj_=isoPixTrackRefs[p]->track()->eta();
00058       double phiObj_=isoPixTrackRefs[p]->track()->phi();
00059       
00060       //cycle on regions
00061       for (uint32_t i=0; i<ccab.size(); i++)
00062         {
00063           SiStripRegionCabling::Position pos=strip_cabling->position(i);
00064           double dphi=fabs(pos.second-phiObj_);
00065           if (dphi>acos(-1)) dphi=2*acos(-1)-dphi;
00066           double R=sqrt(pow(pos.first-etaObj_,2)+dphi*dphi);
00067           if (R-sqrt(pow(regDim.first/2,2)+pow(regDim.second/2,2))>delta_) continue;
00068           //get vector of subdets within region
00069           const SiStripRegionCabling::RegionCabling regSubdets= ccab[i];
00070           //cycle on subdets
00071           for (uint32_t idet=0; idet<SiStripRegionCabling::ALLSUBDETS; idet++)
00072             {
00073               //get vector of layers within subdet of region
00074               const SiStripRegionCabling::WedgeCabling regSubdetLayers=regSubdets[idet];        
00075               for (uint32_t ilayer=0; ilayer<SiStripRegionCabling::ALLLAYERS; ilayer++)
00076                 {
00077                   //get map of vectors of feds withing the layer of subdet of region
00078                   const SiStripRegionCabling::ElementCabling fedVectorMap=regSubdetLayers[ilayer];
00079                   SiStripRegionCabling::ElementCabling::const_iterator it=fedVectorMap.begin();
00080                   for( ; it!=fedVectorMap.end(); it++)
00081                     {
00082                       for (uint32_t op=0; op<(it->second).size(); op++)
00083                         {
00084                           //get fed id 
00085                           int fediid=(it->second)[op].fedId(); 
00086                           if (!fedSaved[fediid]) 
00087                             {
00088                               stripFEDVec.push_back(fediid);
00089                             }
00090                           fedSaved[fediid]=true;
00091                           
00092                         }
00093                     }   
00094                   
00095                 }
00096               
00097             }
00098         }
00099     }
00100   
00101   
00103   
00104   const FEDRawDataCollection *rdc=rawIn.product();
00105   
00106   //   if ( ( rawData[i].provenance()->processName() != e.processHistory().rbegin()->processName() ) )
00107   //       continue ; // skip all raw collections not produced by the current process
00108   
00109   for ( int j=0; j< FEDNumbering::MAXFEDID; ++j ) 
00110     {
00111       bool rightFED=false;
00112       for (uint32_t k=0; k<stripFEDVec.size(); k++) 
00113         {
00114           if (j==stripFEDVec[k])
00115             {
00116               rightFED=true;
00117             }
00118         }
00119       if (!rightFED) continue;
00120       const FEDRawData & fedData = rdc->FEDData(j);
00121       size_t size=fedData.size();
00122       
00123       if ( size > 0 ) 
00124         {
00125           // this fed has data -- lets copy it
00126           FEDRawData & fedDataProd = producedData->FEDData(j);
00127           if ( fedDataProd.size() != 0 ) {
00128 //          std::cout << " More than one FEDRawDataCollection with data in FED ";
00129 //          std::cout << j << " Skipping the 2nd\n";
00130             continue;
00131           }
00132           fedDataProd.resize(size);
00133           unsigned char *dataProd=fedDataProd.data();
00134           const unsigned char *data=fedData.data();
00135           for ( unsigned int k=0; k<size; ++k ) {
00136             dataProd[k]=data[k];
00137           }
00138         }
00139     }
00140   
00141   iEvent.put(producedData);  
00142   
00143 }
00144 
00145 void 
00146 SiStripRegFEDSelector::beginJob() {
00147 }
00148 
00149 void 
00150 SiStripRegFEDSelector::endJob() {
00151 }