CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: SimHitShifter.cc,v 1.1 2011/11/18 03:52:58 jiechen Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
52 
60 
64 
69 #include "FastSimulation/Tracking/test/FastTrackAnalyzer.h"
70 
73 
75 
77 
83 
84 #include <cmath>
85 
86 //Root
87 #include "TFile.h"
88 #include "TF1.h"
89 #include "TH1F.h"
90 #include "TH1.h"
91 #include "TH2F.h"
92 #include "TROOT.h"
93 #include "TMath.h"
94 #include "TCanvas.h"
95 
96 //Track
102 
103 #include<fstream>
104 
105 
106 //
107 // class declaration
108 //
109 
111  public:
112  explicit SimHitShifter(const edm::ParameterSet&);
113  ~SimHitShifter();
114  //edm::ESHandle <RPCGeometry> rpcGeo;
115  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
116  std::map<int,float> shiftinfo;
117 
118 
119  private:
120  std::string ShiftFileName;
121  virtual void beginJob(const edm::Run&, const edm::EventSetup&) ;
122  virtual void produce(edm::Event&, const edm::EventSetup&);
123  virtual void endJob() ;
124 
125 };
126 
128 {
129  std::cout<<"in the constructor"<<std::endl;
130 
131  ShiftFileName = iConfig.getUntrackedParameter<std::string>("ShiftFileName","/afs/cern.ch/user/c/carrillo/simhits/CMSSW_3_5_8_patch2/src/simhitshifter/SimHitShifter/Merged_Muon_RawId_Shift.txt");
132 
133  //iSetup.get<MuonGeometryRecord>().get(rpcGeo);
134 
135  std::ifstream ifin(ShiftFileName.c_str());
136 
137  int rawId;
138  float offset;
139 
140  std::cout<<"In the constructor, The name of the file is "<<ShiftFileName.c_str()<<std::endl;
141 
142  if(!ifin) std::cout<<"Problem reading the map rawId shift "<<ShiftFileName.c_str()<<std::endl;
143  assert(ifin);
144 
145  while (ifin.good()){
146  ifin >>rawId >>offset;
147  shiftinfo[rawId]=offset;
148  std::cout<<"rawId ="<<rawId<<" offset="<<offset<<std::endl;
149  }
150 
151  produces<edm::PSimHitContainer>("MuonCSCHits");
152  produces<edm::PSimHitContainer>("MuonDTHits");
153  produces<edm::PSimHitContainer>("MuonRPCHits");
154 }
155 
156 
158 {
159 }
160 
162  using namespace edm;
163 
164  //std::cout << " Getting the SimHits " <<std::endl;
165  std::vector<edm::Handle<edm::PSimHitContainer> > theSimHitContainers;
166  iEvent.getManyByType(theSimHitContainers);
167  //std::cout << " The Number of sim Hits is " << theSimHitContainers.size() <<std::endl;
168 
169  std::auto_ptr<edm::PSimHitContainer> pcsc(new edm::PSimHitContainer);
170  std::auto_ptr<edm::PSimHitContainer> pdt(new edm::PSimHitContainer);
171  std::auto_ptr<edm::PSimHitContainer> prpc(new edm::PSimHitContainer);
172 
173  std::vector<PSimHit> theSimHits;
174 
175  using std::oct;
176  using std::dec;
177 
178  for (int i = 0; i < int(theSimHitContainers.size()); i++){
179  theSimHits.insert(theSimHits.end(),theSimHitContainers.at(i)->begin(),theSimHitContainers.at(i)->end());
180  }
181 
182  for (std::vector<PSimHit>::const_iterator iHit = theSimHits.begin(); iHit != theSimHits.end(); iHit++){
183  DetId theDetUnitId((*iHit).detUnitId());
184  DetId simdetid= DetId((*iHit).detUnitId());
185 
186  if(simdetid.det()!=DetId::Muon) continue;
187 
188  float newtof = 0;
189 
190  if(simdetid.det()==DetId::Muon && simdetid.subdetId()== MuonSubdetId::RPC){//Only RPCs
191  //std::cout<<"\t\t We have an RPC Sim Hit! in t="<<(*iHit).timeOfFlight()<<" DetId="<<(*iHit).detUnitId()<<std::endl;
192  if(shiftinfo.find(simdetid.rawId())==shiftinfo.end()){
193  std::cout<<"RPC Warning the RawId = "<<simdetid.det()<<" | "<<simdetid.rawId()<<"is not in the map"<<std::endl;
194  newtof = (*iHit).timeOfFlight();
195  }else{
196  newtof = (*iHit).timeOfFlight()+shiftinfo[simdetid.rawId()];
197  }
198 
199  PSimHit hit((*iHit).entryPoint(),(*iHit).exitPoint(),(*iHit).pabs(),
200  newtof,
201  (*iHit).energyLoss(),(*iHit).particleType(),simdetid,(*iHit). trackId(),(*iHit).thetaAtEntry(),(*iHit).phiAtEntry(),(*iHit).processType());
202  prpc->push_back(hit);
203  }
204  else if(simdetid.det()==DetId::Muon && simdetid.subdetId()== MuonSubdetId::DT){//Only DTs
205  int RawId = simdetid.rawId();
206  std::cout<<"We found a DT simhit the RawId in Dec is";
207  std::cout<<dec<<RawId<<std::endl;
208  std::cout<<"and in oct"<<std::endl;
209  std::cout<<oct<<RawId<< std::endl;
210  std::cout<<"once masked in oct "<<std::endl;
211  int compressedRawId = RawId/8/8/8/8/8;
212  std::cout<<compressedRawId<<std::endl;
213  std::cout<<"extendedRawId"<<std::endl;
214  int extendedRawId = compressedRawId*8*8*8*8*8;
215  std::cout<<extendedRawId<<std::endl;
216  std::cout<<"converted again in decimal"<<std::endl;
217  std::cout<<dec<<extendedRawId<<std::endl;
218 
219  if(shiftinfo.find(extendedRawId)==shiftinfo.end()){
220  //std::cout<<"DT Warning the RawId = "<<extendedRawId<<"is not in the map"<<std::endl;
221  newtof = (*iHit).timeOfFlight();
222  }else{
223  newtof = (*iHit).timeOfFlight()+shiftinfo[extendedRawId];
224  std::cout<<"RawId = "<<extendedRawId<<"is in the map "<<(*iHit).timeOfFlight()<<" "<<newtof<<std::endl;
225  }
226 
227  std::cout<<"\t\t We have an DT Sim Hit! in t="<<(*iHit).timeOfFlight()<<" DetId="<<(*iHit).detUnitId()<<std::endl;
228  PSimHit hit((*iHit).entryPoint(),(*iHit).exitPoint(),(*iHit).pabs(),
229  newtof,
230  (*iHit).energyLoss(),(*iHit).particleType(),simdetid,(*iHit). trackId(),(*iHit).thetaAtEntry(),(*iHit).phiAtEntry(),(*iHit).processType());
231  pdt->push_back(hit);
232  }
233  else if(simdetid.det()==DetId::Muon && simdetid.subdetId()== MuonSubdetId::CSC){//Only CSCs
234  //std::cout<<"\t\t We have an CSC Sim Hit! in t="<<(*iHit).timeOfFlight()<<" DetId="<<(*iHit).detUnitId()<<std::endl;
235 
236  CSCDetId TheCSCDetId = CSCDetId(simdetid);
237  CSCDetId TheChamberDetId = TheCSCDetId.chamberId();
238 
239  if(shiftinfo.find(TheChamberDetId.rawId())==shiftinfo.end()){
240  std::cout<<"The RawId is not in the map,perhaps it is on the CSCs station 1 ring 4"<<std::endl;
241  if(TheChamberDetId.station()==1 && TheChamberDetId.ring()==4){
242  CSCDetId TheChamberDetIdNoring4= CSCDetId(TheChamberDetId.endcap(),TheChamberDetId.station(),1 //1 instead of 4
243  ,TheChamberDetId.chamber(),TheChamberDetId.layer());
244 
245  if(shiftinfo.find(TheChamberDetIdNoring4.rawId())==shiftinfo.end()){
246  std::cout<<"CSC Warning the RawId = "<<TheChamberDetIdNoring4<<" "<<TheChamberDetIdNoring4.rawId()<<"is not in the map"<<std::endl;
247  newtof = (*iHit).timeOfFlight();
248  }else{
249  newtof = (*iHit).timeOfFlight()+shiftinfo[TheChamberDetIdNoring4.rawId()];
250  }
251  }
252  }else{
253  newtof = (*iHit).timeOfFlight()+shiftinfo[TheChamberDetId.rawId()];
254  }
255 
256  PSimHit hit((*iHit).entryPoint(),(*iHit).exitPoint(),(*iHit).pabs(),
257  newtof,
258  (*iHit).energyLoss(),(*iHit).particleType(),simdetid,(*iHit). trackId(),(*iHit).thetaAtEntry(),(*iHit).phiAtEntry(),(*iHit).processType());
259 
260  std::cout<<"CSC check newtof"<<newtof<<" "<<(*iHit).timeOfFlight()<<std::endl;
261  if(newtof==(*iHit).timeOfFlight())std::cout<<"Warning!!!"<<std::endl;
262  pcsc->push_back(hit);
263  }
264  }
265 
266  std::cout<<"Putting collections in the event"<<std::endl;
267 
268  iEvent.put(pcsc,"MuonCSCHits");
269  iEvent.put(pdt,"MuonDTHits");
270  iEvent.put(prpc,"MuonRPCHits");
271 
272 }
273 
274 void
276 {
277 
278 }
279 
280 // ------------ method called once each job just before starting event loop ------------
281 void
283 {
284 
285 }
286 
287 // ------------ method called once each job just after ending the event loop ------------
288 void
290 }
291 
292 //define this as a plug-in
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:408
int chamber() const
Definition: CSCDetId.h:70
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginJob()
Definition: EDProducer.h:65
int layer() const
Definition: CSCDetId.h:63
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
int endcap() const
Definition: CSCDetId.h:95
int iEvent
Definition: GenABIO.cc:243
static const int CSC
Definition: MuonSubdetId.h:15
SimHitShifter(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
std::map< int, float > shiftinfo
CSCDetId chamberId() const
Definition: CSCDetId.h:55
unsigned int offset(bool)
virtual void produce(edm::Event &, const edm::EventSetup &)
int ring() const
Definition: CSCDetId.h:77
Definition: DetId.h:20
static const int RPC
Definition: MuonSubdetId.h:16
int station() const
Definition: CSCDetId.h:88
tuple cout
Definition: gather_cfg.py:121
static const int DT
Definition: MuonSubdetId.h:14
std::vector< PSimHit > PSimHitContainer
virtual void endJob()
Definition: Run.h:33
std::string ShiftFileName