00001 00008 #include "GEMRecHitProducer.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/GEMDigi/interface/GEMDigiCollection.h" 00016 00017 #include "Geometry/GEMGeometry/interface/GEMEtaPartition.h" 00018 #include "Geometry/GEMGeometry/interface/GEMGeometry.h" 00019 #include "Geometry/Records/interface/MuonGeometryRecord.h" 00020 #include "DataFormats/MuonDetId/interface/GEMDetId.h" 00021 #include "DataFormats/GEMRecHit/interface/GEMRecHit.h" 00022 00023 #include "RecoLocalMuon/GEMRecHit/interface/GEMRecHitBaseAlgo.h" 00024 #include "RecoLocalMuon/GEMRecHit/interface/GEMRecHitAlgoFactory.h" 00025 #include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h" 00026 00027 // #include "CondFormats/GEMObjects/interface/GEMMaskedStrips.h" 00028 // #include "CondFormats/DataRecord/interface/GEMMaskedStripsRcd.h" 00029 // #include "CondFormats/GEMObjects/interface/GEMDeadStrips.h" 00030 // #include "CondFormats/DataRecord/interface/GEMDeadStripsRcd.h" 00031 00032 #include <string> 00033 00034 00035 using namespace edm; 00036 using namespace std; 00037 00038 00039 GEMRecHitProducer::GEMRecHitProducer(const ParameterSet& config){ 00040 00041 // Set verbose output 00042 00043 produces<GEMRecHitCollection>(); 00044 00045 theGEMDigiLabel = config.getParameter<InputTag>("gemDigiLabel"); 00046 00047 // Get the concrete reconstruction algo from the factory 00048 00049 string theAlgoName = config.getParameter<string>("recAlgo"); 00050 theAlgo = GEMRecHitAlgoFactory::get()->create(theAlgoName, 00051 config.getParameter<ParameterSet>("recAlgoConfig")); 00052 00053 // Get masked- and dead-strip information 00054 00055 /* GEMMaskedStripsObj = new GEMMaskedStrips(); 00056 00057 GEMDeadStripsObj = new GEMDeadStrips(); 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 GEMMaskedStrips::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 GEMDeadStrips::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 GEMRecHitProducer::~GEMRecHitProducer(){ 00097 00098 delete theAlgo; 00099 // delete GEMMaskedStripsObj; 00100 // delete GEMDeadStripsObj; 00101 00102 } 00103 00104 00105 00106 void GEMRecHitProducer::beginRun(const edm::Run& r, const edm::EventSetup& setup){ 00107 00108 // Getting the masked-strip information 00109 /* 00110 if ( maskSource == "EventSetup" ) { 00111 edm::ESHandle<GEMMaskedStrips> readoutMaskedStrips; 00112 setup.get<GEMMaskedStripsRcd>().get(readoutMaskedStrips); 00113 const GEMMaskedStrips* tmp_obj = readoutMaskedStrips.product(); 00114 GEMMaskedStripsObj->MaskVec = tmp_obj->MaskVec; 00115 delete tmp_obj; 00116 } 00117 else if ( maskSource == "File" ) { 00118 std::vector<GEMMaskedStrips::MaskItem>::iterator posVec; 00119 for ( posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec ) { 00120 GEMMaskedStrips::MaskItem Item; 00121 Item.rawId = (*posVec).rawId; 00122 Item.strip = (*posVec).strip; 00123 GEMMaskedStripsObj->MaskVec.push_back(Item); 00124 } 00125 } 00126 */ 00127 // Getting the dead-strip information 00128 /* 00129 if ( deadSource == "EventSetup" ) { 00130 edm::ESHandle<GEMDeadStrips> readoutDeadStrips; 00131 setup.get<GEMDeadStripsRcd>().get(readoutDeadStrips); 00132 const GEMDeadStrips* tmp_obj = readoutDeadStrips.product(); 00133 GEMDeadStripsObj->DeadVec = tmp_obj->DeadVec; 00134 delete tmp_obj; 00135 } 00136 else if ( deadSource == "File" ) { 00137 std::vector<GEMDeadStrips::DeadItem>::iterator posVec; 00138 for ( posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec ) { 00139 GEMDeadStrips::DeadItem Item; 00140 Item.rawId = (*posVec).rawId; 00141 Item.strip = (*posVec).strip; 00142 GEMDeadStripsObj->DeadVec.push_back(Item); 00143 } 00144 } 00145 */ 00146 } 00147 00148 00149 00150 void GEMRecHitProducer::produce(Event& event, const EventSetup& setup) { 00151 00152 // Get the GEM Geometry 00153 00154 ESHandle<GEMGeometry> gemGeom; 00155 setup.get<MuonGeometryRecord>().get(gemGeom); 00156 00157 // Get the digis from the event 00158 00159 Handle<GEMDigiCollection> digis; 00160 event.getByLabel(theGEMDigiLabel,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<GEMRecHitCollection> recHitCollection(new GEMRecHitCollection()); 00169 00170 // Iterate through all digi collections ordered by LayerId 00171 00172 GEMDigiCollection::DigiRangeIterator gemdgIt; 00173 for (gemdgIt = digis->begin(); gemdgIt != digis->end(); 00174 ++gemdgIt){ 00175 00176 // The layerId 00177 const GEMDetId& gemId = (*gemdgIt).first; 00178 00179 // Get the GeomDet from the setup 00180 const GEMEtaPartition* roll = gemGeom->etaPartition(gemId); 00181 00182 // Get the iterators over the digis associated with this LayerId 00183 const GEMDigiCollection::Range& range = (*gemdgIt).second; 00184 00185 00186 // Getting the roll mask, that includes dead strips, for the given GEMDet 00187 EtaPartitionMask mask; 00188 /* 00189 int rawId = gemId.rawId(); 00190 int Size = GEMMaskedStripsObj->MaskVec.size(); 00191 for (int i = 0; i < Size; i++ ) { 00192 if ( GEMMaskedStripsObj->MaskVec[i].rawId == rawId ) { 00193 int bit = GEMMaskedStripsObj->MaskVec[i].strip; 00194 mask.set(bit-1); 00195 } 00196 } 00197 00198 Size = GEMDeadStripsObj->DeadVec.size(); 00199 for (int i = 0; i < Size; i++ ) { 00200 if ( GEMDeadStripsObj->DeadVec[i].rawId == rawId ) { 00201 int bit = GEMDeadStripsObj->DeadVec[i].strip; 00202 mask.set(bit-1); 00203 } 00204 } 00205 */ 00206 // Call the reconstruction algorithm 00207 00208 OwnVector<GEMRecHit> recHits = 00209 theAlgo->reconstruct(*roll, gemId, range, mask); 00210 00211 if(recHits.size() > 0) //FIXME: is it really needed? 00212 recHitCollection->put(gemId, recHits.begin(), recHits.end()); 00213 } 00214 00215 event.put(recHitCollection); 00216 00217 } 00218