CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OMTFPatternMaker.cc
Go to the documentation of this file.
1 #include <iostream>
2 
4 
7 
15 
17 
18 #include "Math/VectorUtil.h"
19 
21 
23  theConfig(cfg),
24  g4SimTrackSrc(cfg.getParameter<edm::InputTag>("g4SimTrackSrc")){
25 
26  inputTokenDTPh = consumes<L1MuDTChambPhContainer>(theConfig.getParameter<edm::InputTag>("srcDTPh"));
27  inputTokenDTTh = consumes<L1MuDTChambThContainer>(theConfig.getParameter<edm::InputTag>("srcDTTh"));
28  if(!theConfig.getParameter<bool>("dropCSCPrimitives"))
29  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(theConfig.getParameter<edm::InputTag>("srcCSC"));
30  if(!theConfig.getParameter<bool>("dropRPCPrimitives"))
31  inputTokenRPC = consumes<RPCDigiCollection>(theConfig.getParameter<edm::InputTag>("srcRPC"));
32  inputTokenSimHit = consumes<edm::SimTrackContainer>(theConfig.getParameter<edm::InputTag>("g4SimTrackSrc"));
33 
34 
35  if(!theConfig.exists("omtf")){
36  edm::LogError("OMTFPatternMaker")<<"omtf configuration not found in cfg.py";
37  }
38 
40 
41  myWriter = new XMLConfigWriter();
42  std::string fName = "OMTF";
44 
45  makeGoldenPatterns = theConfig.getParameter<bool>("makeGoldenPatterns");
46  makeConnectionsMaps = theConfig.getParameter<bool>("makeConnectionsMaps");
47  mergeXMLFiles = theConfig.getParameter<bool>("mergeXMLFiles");
48 
49  myOMTFConfig = 0;
50 }
54 
55  delete myOMTFConfig;
56  delete myOMTFConfigMaker;
57  delete myOMTF;
58 
59 }
63 
65  if(theConfig.getParameter<edm::ParameterSet>("omtf").getParameter<bool>("configFromXML")) return;
66 
67  const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get<L1TMuonOverlapParamsRcd>();
68 
69  edm::ESHandle<L1TMuonOverlapParams> omtfParamsHandle;
70  omtfParamsRcd.get(omtfParamsHandle);
71 
72  const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product();
73  if (!omtfParams) {
74  edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
75  }
76 
77  myOMTFConfig->configure(omtfParams);
78  myOMTF->configure(omtfParams);
79 
83 
85  const std::map<Key,GoldenPattern*> & theGPs = myOMTF->getPatterns();
86  for(auto itGP: theGPs) itGP.second->reset();
87 
88 }
92 
93  if(theConfig.exists("omtf")){
97  }
98 }
102 
104  std::string fName = "OMTF";
106  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
107  for(auto itGP: myGPmap){
108  if(!itGP.second->hasCounts()) continue;
109  itGP.second->normalise();
110  }
111 
114  for(auto itGP: myGPmap){
116  unsigned int iPt = theConfig.getParameter<int>("ptCode")+1;
117  if(iPt>31) iPt = 200*2+1;
118  else iPt = RPCConst::ptFromIpt(iPt)*2.0+1;//MicroGMT has 0.5 GeV step size, with lower bin edge (uGMT_pt_code - 1)*step_size
120  if(itGP.first.thePtCode==iPt &&
121  itGP.first.theCharge==theConfig.getParameter<int>("charge")){
122  std::cout<<*itGP.second<<std::endl;
123  myWriter->writeGPData(*itGP.second);
124  }
125  }
126  fName = "GPs.xml";
127  myWriter->finaliseXMLDocument(fName);
128  }
129 
131  std::string fName = "Connections.xml";
132  unsigned int iProcessor = 0;
143  }
144 
145  if(mergeXMLFiles){
146 
147  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0));
148  dummy->reset();
149 
150  std::string fName = "OMTF";
152  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
153  for(auto itGP: myGPmap){
154  myWriter->writeGPData(*itGP.second,*dummy, *dummy, *dummy);
155  }
156  fName = "GPs.xml";
161  fName = "OMTF";
163  myOMTF->averagePatterns(-1);
165  writeMergedGPs();
166  fName = "GPs_4x.xml";
168  }
169 }
173 
174  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
175 
176  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0));
177  dummy->reset();
178 
179  unsigned int iPtMin = 9;
180  Key aKey = Key(0, iPtMin,-1);
181  while(myGPmap.find(aKey)!=myGPmap.end()){
182 
183  GoldenPattern *aGP1 = myGPmap.find(aKey)->second;
184  GoldenPattern *aGP2 = dummy;
185  GoldenPattern *aGP3 = dummy;
186  GoldenPattern *aGP4 = dummy;
187 
188  ++aKey.thePtCode;
189  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
190  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP2 = myGPmap.find(aKey)->second;
191 
192  if(aKey.thePtCode>71){
193  ++aKey.thePtCode;
194  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
195  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP3 = myGPmap.find(aKey)->second;
196 
197  ++aKey.thePtCode;
198  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
199  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP4 = myGPmap.find(aKey)->second;
200  }
201  ++aKey.thePtCode;
202  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
203  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
204 
206  Key aTmpKey = aGP1->key();
207  aTmpKey.theCharge = 1;
208  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP1 = myGPmap.find(aTmpKey)->second;
209  else aGP1 = dummy;
210 
211  aTmpKey = aGP2->key();
212  aTmpKey.theCharge = 1;
213  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP2 = myGPmap.find(aTmpKey)->second;
214  else aGP2 = dummy;
215 
216  aTmpKey = aGP3->key();
217  aTmpKey.theCharge = 1;
218  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP3 = myGPmap.find(aTmpKey)->second;
219  else aGP3 = dummy;
220 
221  aTmpKey = aGP4->key();
222  aTmpKey.theCharge = 1;
223  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP4 = myGPmap.find(aTmpKey)->second;
224  else aGP4 = dummy;
225 
226  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
227  }
228 }
232 
233  if(mergeXMLFiles) return;
234 
236  const SimTrack* aSimMuon = findSimMuon(iEvent,evSetup);
237  if(!aSimMuon){
238  edm::LogError("OMTFPatternMaker")<<"No SimMuon found in the event!";
239  return;
240  }
241 
242  myInputMaker->initialize(evSetup);
243 
248 
250  if(!theConfig.getParameter<bool>("dropDTPrimitives")){
251  iEvent.getByToken(inputTokenDTPh,dtPhDigis);
252  iEvent.getByToken(inputTokenDTTh,dtThDigis);
253  }
254  if(!theConfig.getParameter<bool>("dropRPCPrimitives")) iEvent.getByToken(inputTokenRPC,rpcDigis);
255  if(!theConfig.getParameter<bool>("dropCSCPrimitives")) iEvent.getByToken(inputTokenCSC,cscDigis);
256 
257  //l1t::tftype mtfType = l1t::tftype::bmtf;
259  //l1t::tftype mtfType = l1t::tftype::emtf_pos;
260 
262  for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){
263 
265  OMTFinput myInput = myInputMaker->buildInputForProcessor(dtPhDigis.product(),
266  dtThDigis.product(),
267  cscDigis.product(),
268  rpcDigis.product(),
269  iProcessor,
270  mtfType);
271 
275 
276  if(makeGoldenPatterns) myOMTF->fillCounts(iProcessor,myInput, aSimMuon);
277 
278  }
279 }
282 const SimTrack * OMTFPatternMaker::findSimMuon(const edm::Event &ev, const edm::EventSetup &es, const SimTrack * previous){
283 
284  const SimTrack * result = 0;
286  ev.getByToken(inputTokenSimHit,simTks);
287 
288  for (std::vector<SimTrack>::const_iterator it=simTks->begin(); it< simTks->end(); it++) {
289  const SimTrack & aTrack = *it;
290  if ( !(aTrack.type() == 13 || aTrack.type() == -13) )continue;
291  if(previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(),previous->momentum())<0.07) continue;
292  if ( !result || aTrack.momentum().pt() > result->momentum().pt()) result = &aTrack;
293  }
294  return result;
295 }
Key key() const
Definition: GoldenPattern.h:59
void writeConnectionsData(const std::vector< std::vector< OMTFConfiguration::vector2D > > &measurements4D)
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::SimTrackContainer > inputTokenSimHit
void fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon)
void averagePatterns(int charge)
tuple cfg
Definition: looper.py:293
virtual void endJob()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
OMTFConfiguration * myOMTFConfig
OMTF objects.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void initialiseXMLDocument(const std::string &docName)
int theCharge
Definition: GoldenPattern.h:37
bool exists(std::string const &parameterName) const
checks if a parameter exists
void makeConnetionsMap(unsigned int iProcessor, const OMTFinput &aInput)
OMTFPatternMaker(const edm::ParameterSet &cfg)
bool ev
edm::EDGetTokenT< L1MuDTChambPhContainer > inputTokenDTPh
bool configure(XMLConfigReader *aReader)
Fill GP map with patterns from XML file.
unsigned int thePtCode
Definition: GoldenPattern.h:36
virtual void beginJob()
tuple result
Definition: mps_fire.py:95
void initialize(const edm::EventSetup &es)
unsigned int nPdfAddrBits
OMTFConfigMaker * myOMTFConfigMaker
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > inputTokenCSC
void printConnections(std::ostream &out, unsigned int iProcessor, unsigned int iCone)
void configure(XMLConfigReader *aReader)
tuple omtfParams
OMTF ESProducer.
void get(HolderT &iHolder) const
const SimTrack * findSimMuon(const edm::Event &ev, const edm::EventSetup &es, const SimTrack *previous=0)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
XMLConfigWriter * myWriter
OMTFProcessor * myOMTF
static double ptFromIpt(const int ipt)
Definition: RPCConst.cc:28
void reset()
Reset contents of all data vectors, keeping the vectors size.
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
void printPhiMap(std::ostream &out)
virtual ~OMTFPatternMaker()
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
void finaliseXMLDocument(const std::string &fName)
OMTFinput buildInputForProcessor(const L1MuDTChambPhContainer *dtPhDigis, const L1MuDTChambThContainer *dtThDigis, const CSCCorrelatedLCTDigiCollection *cscDigis, const RPCDigiCollection *rpcDigis, unsigned int iProcessor, l1t::tftype type=l1t::tftype::omtf_pos)
Method translating trigger digis into input matrix with global phi coordinates.
tuple cout
Definition: gather_cfg.py:145
virtual void beginRun(edm::Run const &run, edm::EventSetup const &iSetup)
edm::EDGetTokenT< RPCDigiCollection > inputTokenRPC
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
static const OMTFConfiguration * instance()
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:43
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
OMTFinputMaker * myInputMaker
edm::ParameterSet theConfig