CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoLocalMuon/RPCRecHit/src/RPCRecHitProducer.cc

Go to the documentation of this file.
00001 
00008 #include "RPCRecHitProducer.h"
00009 
00010 
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 
00015 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00016 
00017 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00018 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00021 #include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
00022 
00023 #include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitBaseAlgo.h"
00024 #include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitAlgoFactory.h"
00025 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00026 
00027 #include "CondFormats/RPCObjects/interface/RPCMaskedStrips.h"
00028 #include "CondFormats/DataRecord/interface/RPCMaskedStripsRcd.h"
00029 #include "CondFormats/RPCObjects/interface/RPCDeadStrips.h"
00030 #include "CondFormats/DataRecord/interface/RPCDeadStripsRcd.h"
00031 
00032 #include <string>
00033 
00034 
00035 using namespace edm;
00036 using namespace std;
00037 
00038 
00039 RPCRecHitProducer::RPCRecHitProducer(const ParameterSet& config){
00040 
00041   // Set verbose output
00042 
00043   produces<RPCRecHitCollection>();
00044 
00045   theRPCDigiLabel = config.getParameter<InputTag>("rpcDigiLabel");
00046   
00047   // Get the concrete reconstruction algo from the factory
00048 
00049   string theAlgoName = config.getParameter<string>("recAlgo");
00050   theAlgo = RPCRecHitAlgoFactory::get()->create(theAlgoName,
00051                                                 config.getParameter<ParameterSet>("recAlgoConfig"));
00052 
00053   // Get masked- and dead-strip information
00054 
00055   RPCMaskedStripsObj = new RPCMaskedStrips();
00056 
00057   RPCDeadStripsObj = new RPCDeadStrips();
00058 
00059   maskSource = config.getParameter<std::string>("maskSource");
00060 
00061   if (maskSource == "File") {
00062     edm::FileInPath fp = config.getParameter<edm::FileInPath>("maskvecfile");
00063     std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
00064     if ( !inputFile ) {
00065       std::cerr << "Masked Strips File cannot not be opened" << std::endl;
00066       exit(1);
00067     }
00068     while ( inputFile.good() ) {
00069       RPCMaskedStrips::MaskItem Item;
00070       inputFile >> Item.rawId >> Item.strip;
00071       if ( inputFile.good() ) MaskVec.push_back(Item);
00072     }
00073     inputFile.close();
00074   }
00075 
00076   deadSource = config.getParameter<std::string>("deadSource");
00077 
00078   if (deadSource == "File") {
00079     edm::FileInPath fp = config.getParameter<edm::FileInPath>("deadvecfile");
00080     std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
00081     if ( !inputFile ) {
00082       std::cerr << "Dead Strips File cannot not be opened" << std::endl;
00083       exit(1);
00084     }
00085     while ( inputFile.good() ) {
00086       RPCDeadStrips::DeadItem Item;
00087       inputFile >> Item.rawId >> Item.strip;
00088       if ( inputFile.good() ) DeadVec.push_back(Item);
00089     }
00090     inputFile.close();
00091   }
00092 
00093 }
00094 
00095 
00096 RPCRecHitProducer::~RPCRecHitProducer(){
00097 
00098   delete theAlgo;
00099   delete RPCMaskedStripsObj;
00100   delete RPCDeadStripsObj;
00101 
00102 }
00103 
00104 
00105 
00106 void RPCRecHitProducer::beginRun( edm::Run& r, const edm::EventSetup& setup){
00107 
00108   // Getting the masked-strip information
00109 
00110   if ( maskSource == "EventSetup" ) {
00111     edm::ESHandle<RPCMaskedStrips> readoutMaskedStrips;
00112     setup.get<RPCMaskedStripsRcd>().get(readoutMaskedStrips);
00113     const RPCMaskedStrips* tmp_obj = readoutMaskedStrips.product();
00114     RPCMaskedStripsObj->MaskVec = tmp_obj->MaskVec;
00115     delete tmp_obj;
00116   }
00117   else if ( maskSource == "File" ) {
00118     std::vector<RPCMaskedStrips::MaskItem>::iterator posVec;
00119     for ( posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec ) {
00120       RPCMaskedStrips::MaskItem Item; 
00121       Item.rawId = (*posVec).rawId;
00122       Item.strip = (*posVec).strip;
00123       RPCMaskedStripsObj->MaskVec.push_back(Item);
00124     }
00125   }
00126 
00127   // Getting the dead-strip information
00128 
00129   if ( deadSource == "EventSetup" ) {
00130     edm::ESHandle<RPCDeadStrips> readoutDeadStrips;
00131     setup.get<RPCDeadStripsRcd>().get(readoutDeadStrips);
00132     const RPCDeadStrips* tmp_obj = readoutDeadStrips.product();
00133     RPCDeadStripsObj->DeadVec = tmp_obj->DeadVec;
00134     delete tmp_obj;
00135   }
00136   else if ( deadSource == "File" ) {
00137     std::vector<RPCDeadStrips::DeadItem>::iterator posVec;
00138     for ( posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec ) {
00139       RPCDeadStrips::DeadItem Item;
00140       Item.rawId = (*posVec).rawId;
00141       Item.strip = (*posVec).strip;
00142       RPCDeadStripsObj->DeadVec.push_back(Item);
00143     }
00144   }
00145 
00146 }
00147 
00148 
00149 
00150 void RPCRecHitProducer::produce(Event& event, const EventSetup& setup) {
00151 
00152   // Get the RPC Geometry
00153 
00154   ESHandle<RPCGeometry> rpcGeom;
00155   setup.get<MuonGeometryRecord>().get(rpcGeom);
00156 
00157   // Get the digis from the event
00158 
00159   Handle<RPCDigiCollection> digis; 
00160   event.getByLabel(theRPCDigiLabel,digis);
00161 
00162   // Pass the EventSetup to the algo
00163 
00164   theAlgo->setES(setup);
00165 
00166   // Create the pointer to the collection which will store the rechits
00167 
00168   auto_ptr<RPCRecHitCollection> recHitCollection(new RPCRecHitCollection());
00169 
00170   // Iterate through all digi collections ordered by LayerId   
00171 
00172   RPCDigiCollection::DigiRangeIterator rpcdgIt;
00173   for (rpcdgIt = digis->begin(); rpcdgIt != digis->end();
00174        ++rpcdgIt){
00175        
00176     // The layerId
00177     const RPCDetId& rpcId = (*rpcdgIt).first;
00178 
00179     // Get the GeomDet from the setup
00180     const RPCRoll* roll = rpcGeom->roll(rpcId);
00181 
00182     // Get the iterators over the digis associated with this LayerId
00183     const RPCDigiCollection::Range& range = (*rpcdgIt).second;
00184 
00185 
00186     // Getting the roll mask, that includes dead strips, for the given RPCDet
00187 
00188     RollMask mask;
00189     int rawId = rpcId.rawId();
00190     int Size = RPCMaskedStripsObj->MaskVec.size();
00191     for (int i = 0; i < Size; i++ ) {
00192       if ( RPCMaskedStripsObj->MaskVec[i].rawId == rawId ) {
00193         int bit = RPCMaskedStripsObj->MaskVec[i].strip;
00194         mask.set(bit-1);
00195       }
00196     }
00197 
00198     Size = RPCDeadStripsObj->DeadVec.size();
00199     for (int i = 0; i < Size; i++ ) {
00200       if ( RPCDeadStripsObj->DeadVec[i].rawId == rawId ) {
00201         int bit = RPCDeadStripsObj->DeadVec[i].strip;
00202         mask.set(bit-1);
00203       }
00204     }
00205 
00206     // Call the reconstruction algorithm    
00207 
00208     OwnVector<RPCRecHit> recHits =
00209       theAlgo->reconstruct(*roll, rpcId, range, mask);
00210     
00211     if(recHits.size() > 0) //FIXME: is it really needed?
00212       recHitCollection->put(rpcId, recHits.begin(), recHits.end());
00213   }
00214 
00215   event.put(recHitCollection);
00216 
00217 }
00218