CMS 3D CMS Logo

SimHitShifter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimHitShifter
4 // Class: SimHitShifter
5 //
13 //
14 // Original Author: Camilo Andres Carrillo Montoya,40 2-B15,+41227671625,
15 // Created: Mon Aug 30 18:35:05 CEST 2010
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
50 
58 
62 
67 
70 
72 
74 
80 
81 #include <cmath>
82 
83 //Root
84 #include "TFile.h"
85 #include "TF1.h"
86 #include "TH1F.h"
87 #include "TH1.h"
88 #include "TH2F.h"
89 #include "TROOT.h"
90 #include "TMath.h"
91 #include "TCanvas.h"
92 
93 //Track
99 
100 #include <fstream>
101 
102 //
103 // class declaration
104 //
105 
107 public:
108  explicit SimHitShifter(const edm::ParameterSet&);
109  ~SimHitShifter() override;
110  //edm::ESHandle <RPCGeometry> rpcGeo;
111  void beginRun(const edm::Run&, const edm::EventSetup&) override;
112  std::map<int, float> shiftinfo;
113 
114 private:
116  void beginJob() override;
117  void produce(edm::Event&, const edm::EventSetup&) override;
118  void endJob() override;
119 };
120 
122  std::cout << "in the constructor" << std::endl;
123 
124  ShiftFileName =
125  iConfig.getUntrackedParameter<std::string>("ShiftFileName",
126  "/afs/cern.ch/user/c/carrillo/simhits/CMSSW_3_5_8_patch2/src/"
127  "simhitshifter/SimHitShifter/Merged_Muon_RawId_Shift.txt");
128 
129  //iSetup.get<MuonGeometryRecord>().get(rpcGeo);
130 
131  std::ifstream ifin(ShiftFileName.c_str());
132 
133  int rawId;
134  float offset;
135 
136  std::cout << "In the constructor, The name of the file is " << ShiftFileName.c_str() << std::endl;
137 
138  if (!ifin)
139  std::cout << "Problem reading the map rawId shift " << ShiftFileName.c_str() << std::endl;
140  assert(ifin);
141 
142  while (ifin.good()) {
143  ifin >> rawId >> offset;
144  shiftinfo[rawId] = offset;
145  std::cout << "rawId =" << rawId << " offset=" << offset << std::endl;
146  }
147 
148  produces<edm::PSimHitContainer>("MuonCSCHits");
149  produces<edm::PSimHitContainer>("MuonDTHits");
150  produces<edm::PSimHitContainer>("MuonRPCHits");
151 }
152 
154 
156  using namespace edm;
157 
158  //std::cout << " Getting the SimHits " <<std::endl;
159  std::vector<edm::Handle<edm::PSimHitContainer> > theSimHitContainers;
160  iEvent.getManyByType(theSimHitContainers);
161  //std::cout << " The Number of sim Hits is " << theSimHitContainers.size() <<std::endl;
162 
163  std::unique_ptr<edm::PSimHitContainer> pcsc(new edm::PSimHitContainer);
164  std::unique_ptr<edm::PSimHitContainer> pdt(new edm::PSimHitContainer);
165  std::unique_ptr<edm::PSimHitContainer> prpc(new edm::PSimHitContainer);
166 
167  std::vector<PSimHit> theSimHits;
168 
169  using std::dec;
170  using std::oct;
171 
172  for (int i = 0; i < int(theSimHitContainers.size()); i++) {
173  theSimHits.insert(theSimHits.end(), theSimHitContainers.at(i)->begin(), theSimHitContainers.at(i)->end());
174  }
175 
176  for (std::vector<PSimHit>::const_iterator iHit = theSimHits.begin(); iHit != theSimHits.end(); iHit++) {
177  DetId theDetUnitId((*iHit).detUnitId());
178  DetId simdetid = DetId((*iHit).detUnitId());
179 
180  if (simdetid.det() != DetId::Muon)
181  continue;
182 
183  float newtof = 0;
184 
185  if (simdetid.det() == DetId::Muon && simdetid.subdetId() == MuonSubdetId::RPC) { //Only RPCs
186  //std::cout<<"\t\t We have an RPC Sim Hit! in t="<<(*iHit).timeOfFlight()<<" DetId="<<(*iHit).detUnitId()<<std::endl;
187  if (shiftinfo.find(simdetid.rawId()) == shiftinfo.end()) {
188  std::cout << "RPC Warning the RawId = " << simdetid.det() << " | " << simdetid.rawId() << "is not in the map"
189  << std::endl;
190  newtof = (*iHit).timeOfFlight();
191  } else {
192  newtof = (*iHit).timeOfFlight() + shiftinfo[simdetid.rawId()];
193  }
194 
195  PSimHit hit((*iHit).entryPoint(),
196  (*iHit).exitPoint(),
197  (*iHit).pabs(),
198  newtof,
199  (*iHit).energyLoss(),
200  (*iHit).particleType(),
201  simdetid,
202  (*iHit).trackId(),
203  (*iHit).thetaAtEntry(),
204  (*iHit).phiAtEntry(),
205  (*iHit).processType());
206  prpc->push_back(hit);
207  } else if (simdetid.det() == DetId::Muon && simdetid.subdetId() == MuonSubdetId::DT) { //Only DTs
208  int RawId = simdetid.rawId();
209  std::cout << "We found a DT simhit the RawId in Dec is";
210  std::cout << dec << RawId << std::endl;
211  std::cout << "and in oct" << std::endl;
212  std::cout << oct << RawId << std::endl;
213  std::cout << "once masked in oct " << std::endl;
214  int compressedRawId = RawId / 8 / 8 / 8 / 8 / 8;
215  std::cout << compressedRawId << std::endl;
216  std::cout << "extendedRawId" << std::endl;
217  int extendedRawId = compressedRawId * 8 * 8 * 8 * 8 * 8;
218  std::cout << extendedRawId << std::endl;
219  std::cout << "converted again in decimal" << std::endl;
220  std::cout << dec << extendedRawId << std::endl;
221 
222  if (shiftinfo.find(extendedRawId) == shiftinfo.end()) {
223  //std::cout<<"DT Warning the RawId = "<<extendedRawId<<"is not in the map"<<std::endl;
224  newtof = (*iHit).timeOfFlight();
225  } else {
226  newtof = (*iHit).timeOfFlight() + shiftinfo[extendedRawId];
227  std::cout << "RawId = " << extendedRawId << "is in the map " << (*iHit).timeOfFlight() << " " << newtof
228  << std::endl;
229  }
230 
231  std::cout << "\t\t We have an DT Sim Hit! in t=" << (*iHit).timeOfFlight() << " DetId=" << (*iHit).detUnitId()
232  << std::endl;
233  PSimHit hit((*iHit).entryPoint(),
234  (*iHit).exitPoint(),
235  (*iHit).pabs(),
236  newtof,
237  (*iHit).energyLoss(),
238  (*iHit).particleType(),
239  simdetid,
240  (*iHit).trackId(),
241  (*iHit).thetaAtEntry(),
242  (*iHit).phiAtEntry(),
243  (*iHit).processType());
244  pdt->push_back(hit);
245  } else if (simdetid.det() == DetId::Muon && simdetid.subdetId() == MuonSubdetId::CSC) { //Only CSCs
246  //std::cout<<"\t\t We have an CSC Sim Hit! in t="<<(*iHit).timeOfFlight()<<" DetId="<<(*iHit).detUnitId()<<std::endl;
247 
248  CSCDetId TheCSCDetId = CSCDetId(simdetid);
249  CSCDetId TheChamberDetId = TheCSCDetId.chamberId();
250 
251  if (shiftinfo.find(TheChamberDetId.rawId()) == shiftinfo.end()) {
252  std::cout << "The RawId is not in the map,perhaps it is on the CSCs station 1 ring 4" << std::endl;
253  if (TheChamberDetId.station() == 1 && TheChamberDetId.ring() == 4) {
254  CSCDetId TheChamberDetIdNoring4 = CSCDetId(TheChamberDetId.endcap(),
255  TheChamberDetId.station(),
256  1 //1 instead of 4
257  ,
258  TheChamberDetId.chamber(),
259  TheChamberDetId.layer());
260 
261  if (shiftinfo.find(TheChamberDetIdNoring4.rawId()) == shiftinfo.end()) {
262  std::cout << "CSC Warning the RawId = " << TheChamberDetIdNoring4 << " " << TheChamberDetIdNoring4.rawId()
263  << "is not in the map" << std::endl;
264  newtof = (*iHit).timeOfFlight();
265  } else {
266  newtof = (*iHit).timeOfFlight() + shiftinfo[TheChamberDetIdNoring4.rawId()];
267  }
268  }
269  } else {
270  newtof = (*iHit).timeOfFlight() + shiftinfo[TheChamberDetId.rawId()];
271  }
272 
273  PSimHit hit((*iHit).entryPoint(),
274  (*iHit).exitPoint(),
275  (*iHit).pabs(),
276  newtof,
277  (*iHit).energyLoss(),
278  (*iHit).particleType(),
279  simdetid,
280  (*iHit).trackId(),
281  (*iHit).thetaAtEntry(),
282  (*iHit).phiAtEntry(),
283  (*iHit).processType());
284 
285  std::cout << "CSC check newtof" << newtof << " " << (*iHit).timeOfFlight() << std::endl;
286  if (newtof == (*iHit).timeOfFlight())
287  std::cout << "Warning!!!" << std::endl;
288  pcsc->push_back(hit);
289  }
290  }
291 
292  std::cout << "Putting collections in the event" << std::endl;
293 
294  iEvent.put(std::move(pcsc), "MuonCSCHits");
295  iEvent.put(std::move(pdt), "MuonDTHits");
296  iEvent.put(std::move(prpc), "MuonRPCHits");
297 }
298 
299 void SimHitShifter::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {}
300 
301 // ------------ method called once each job just before starting event loop ------------
303 
304 // ------------ method called once each job just after ending the event loop ------------
306 
307 //define this as a plug-in
Propagator.h
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
MuonPatternRecoDumper.h
SteppingHelixPropagator.h
EDProducer.h
ESHandle.h
edm::Run
Definition: Run.h:45
SimHitShifter::beginJob
void beginJob() override
Definition: SimHitShifter.cc:302
edm
HLT enums.
Definition: AlignableModifier.h:19
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PSimHitContainer.h
cms::cuda::assert
assert(be >=bs)
SimHitShifter::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: SimHitShifter.cc:299
SimHitShifter
Definition: SimHitShifter.cc:106
RPCRoll.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
SimHitShifter::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SimHitShifter.cc:155
TransientTrack.h
CSCDetId.h
CandMatchMap.h
CandidateFwd.h
DetId
Definition: DetId.h:17
RPCGeomServ.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Surface.h
LocalError.h
SimVertex.h
CSCDetId::layer
int layer() const
Definition: CSCDetId.h:56
IdealMagneticFieldRecord.h
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
RPCDigi.h
TrajTrackAssociation.h
SimHitShifter::SimHitShifter
SimHitShifter(const edm::ParameterSet &)
Definition: SimHitShifter.cc:121
GlobalTrackingGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RPCDetId.h
RPCRecHitCollection.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ParticleDataTable.h
CSCDetId
Definition: CSCDetId.h:26
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
SimHitShifter::shiftinfo
std::map< int, float > shiftinfo
Definition: SimHitShifter.cc:112
CSCDetId::chamberId
CSCDetId chamberId() const
Definition: CSCDetId.h:47
CSCDetId::chamber
int chamber() const
Definition: CSCDetId.h:62
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
AnalyticalPropagator.h
TrajectorySeedCollection.h
MuonSubdetId.h
SimHitShifter::endJob
void endJob() override
Definition: SimHitShifter.cc:305
Trajectory.h
GeomDet.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DetId.h
Frameworkfwd.h
MuonSubdetId::RPC
static constexpr int RPC
Definition: MuonSubdetId.h:13
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
LocalPoint.h
TrackingComponentsRecord.h
RPCRecHit.h
SimHitShifter::~SimHitShifter
~SimHitShifter() override
Definition: SimHitShifter.cc:153
RPCDigiCollection.h
edm::EDProducer
Definition: EDProducer.h:36
Candidate.h
DetId::Muon
Definition: DetId.h:26
SimHitShifter::ShiftFileName
std::string ShiftFileName
Definition: SimHitShifter.cc:115
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
SimTrack.h
ParameterSet.h
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
TrackCandidate.h
PSimHit
Definition: PSimHit.h:15
MuonGeometryRecord.h
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
edm::Event
Definition: Event.h:73
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
RPCGeometry.h
SimTrackContainer.h
SimVertexContainer.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88