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