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  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(theConfig.getParameter<edm::InputTag>("srcCSC"));
29  inputTokenRPC = consumes<RPCDigiCollection>(theConfig.getParameter<edm::InputTag>("srcRPC"));
30  inputTokenSimHit = consumes<edm::SimTrackContainer>(theConfig.getParameter<edm::InputTag>("g4SimTrackSrc"));
31 
33 
34  makeGoldenPatterns = theConfig.getParameter<bool>("makeGoldenPatterns");
35  makeConnectionsMaps = theConfig.getParameter<bool>("makeConnectionsMaps");
36  mergeXMLFiles = theConfig.getParameter<bool>("mergeXMLFiles");
37 
38  myOMTFConfig = 0;
39 }
43 
44  delete myOMTFConfig;
45  delete myOMTFConfigMaker;
46  delete myOMTF;
47 
48 }
52 
53  const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get<L1TMuonOverlapParamsRcd>();
54 
55  edm::ESHandle<L1TMuonOverlapParams> omtfParamsHandle;
56  omtfParamsRcd.get(omtfParamsHandle);
57 
58  const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product();
59 
60  if (!omtfParams) {
61  edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
62  }
63 
66 
69  L1TMuonOverlapParams omtfParamsMutable = *omtfParams;
70  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
71  nPdfAddrBits = omtfParams->nPdfAddrBits();
72 
74  omtfParamsMutable.setGeneralParams(generalParams);
75 
76  myOMTFConfig->configure(&omtfParamsMutable);
77  myOMTF->configure(myOMTFConfig, omtfParams);
79 
81  if(!mergeXMLFiles){
82  const std::map<Key,GoldenPattern*> & theGPs = myOMTF->getPatterns();
83  for(auto itGP: theGPs) itGP.second->reset();
84  }
85 }
89 
91  myOMTF = new OMTFProcessor();
92 }
96 
99  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
100  for(auto itGP: myGPmap){
101  if(!itGP.second->hasCounts()) continue;
102  itGP.second->normalise(nPdfAddrBits);
103  }
104 
105  GoldenPattern dummyGP(Key(0,0,0), myOMTFConfig);
106  dummyGP.reset();
107 
109  L1TMuonOverlapParams omtfParamsMutable = *myOMTFConfig->getRawParams();
110  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
112  omtfParamsMutable.setGeneralParams(generalParams);
113  myOMTFConfig->configure(&omtfParamsMutable);
114 
115  for(auto itGP: myGPmap){
117  unsigned int iPt = theConfig.getParameter<int>("ptCode")+1;
118  if(iPt>31) iPt = 200*2+1;
119  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
121  if(itGP.first.thePtCode==iPt &&
122  itGP.first.theCharge==theConfig.getParameter<int>("charge")){
123  std::cout<<*itGP.second<<std::endl;
124  myWriter->writeGPData(*itGP.second, dummyGP, dummyGP, dummyGP);
125  }
126  }
127  std::string fName = "GPs.xml";
128  myWriter->finaliseXMLDocument(fName);
129  }
130 
133  std::string fName = "Connections.xml";
134  unsigned int iProcessor = 0;
145  }
146 
147  if(mergeXMLFiles){
148 
149  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0), myOMTFConfig);
150  dummy->reset();
151 
152  std::string fName = "OMTF";
154  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
155  for(auto itGP: myGPmap){
156  myWriter->writeGPData(*itGP.second,*dummy, *dummy, *dummy);
157  }
158  fName = "GPs.xml";
163  fName = "OMTF";
165  myOMTF->averagePatterns(-1);
167  writeMergedGPs();
168  fName = "GPs_4x.xml";
170  }
171 }
175 
176  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
177 
178  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0), myOMTFConfig);
179  dummy->reset();
180 
181  unsigned int iPtMin = 9;
182  Key aKey = Key(0, iPtMin, 1);
183  while(myGPmap.find(aKey)!=myGPmap.end()){
184 
185  GoldenPattern *aGP1 = myGPmap.find(aKey)->second;
186  GoldenPattern *aGP2 = dummy;
187  GoldenPattern *aGP3 = dummy;
188  GoldenPattern *aGP4 = dummy;
189 
190  ++aKey.thePtCode;
191  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
192  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP2 = myGPmap.find(aKey)->second;
193 
194  if(aKey.thePtCode>71){
195  ++aKey.thePtCode;
196  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
197  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP3 = myGPmap.find(aKey)->second;
198 
199  ++aKey.thePtCode;
200  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
201  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP4 = myGPmap.find(aKey)->second;
202  }
203  ++aKey.thePtCode;
204  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
205  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
206 
208  Key aTmpKey = aGP1->key();
209  aTmpKey.theCharge = -1;
210  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP1 = myGPmap.find(aTmpKey)->second;
211  else aGP1 = dummy;
212 
213  aTmpKey = aGP2->key();
214  aTmpKey.theCharge = -1;
215  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP2 = myGPmap.find(aTmpKey)->second;
216  else aGP2 = dummy;
217 
218  aTmpKey = aGP3->key();
219  aTmpKey.theCharge = -1;
220  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP3 = myGPmap.find(aTmpKey)->second;
221  else aGP3 = dummy;
222 
223  aTmpKey = aGP4->key();
224  aTmpKey.theCharge = -1;
225  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP4 = myGPmap.find(aTmpKey)->second;
226  else aGP4 = dummy;
227 
228  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
229  }
230 }
234 
235  if(mergeXMLFiles) return;
236 
238  const SimTrack* aSimMuon = findSimMuon(iEvent,evSetup);
239  if(!aSimMuon){
240  edm::LogError("OMTFPatternMaker")<<"No SimMuon found in the event!";
241  return;
242  }
243 
245 
250 
252  if(!theConfig.getParameter<bool>("dropDTPrimitives")){
253  iEvent.getByToken(inputTokenDTPh,dtPhDigis);
254  iEvent.getByToken(inputTokenDTTh,dtThDigis);
255  }
256  if(!theConfig.getParameter<bool>("dropRPCPrimitives")) iEvent.getByToken(inputTokenRPC,rpcDigis);
257  if(!theConfig.getParameter<bool>("dropCSCPrimitives")) iEvent.getByToken(inputTokenCSC,cscDigis);
258 
259  //l1t::tftype mtfType = l1t::tftype::bmtf;
261  //l1t::tftype mtfType = l1t::tftype::emtf_pos;
262 
264  for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){
265 
267  OMTFinput myInput = myInputMaker->buildInputForProcessor(dtPhDigis.product(),
268  dtThDigis.product(),
269  cscDigis.product(),
270  rpcDigis.product(),
271  iProcessor,
272  mtfType);
273 
277 
278  if(makeGoldenPatterns) myOMTF->fillCounts(iProcessor,myInput, aSimMuon);
279 
280  }
281 }
284 const SimTrack * OMTFPatternMaker::findSimMuon(const edm::Event &ev, const edm::EventSetup &es, const SimTrack * previous){
285 
286  const SimTrack * result = 0;
288  ev.getByToken(inputTokenSimHit,simTks);
289 
290  for (std::vector<SimTrack>::const_iterator it=simTks->begin(); it< simTks->end(); it++) {
291  const SimTrack & aTrack = *it;
292  if ( !(aTrack.type() == 13 || aTrack.type() == -13) )continue;
293  if(previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(),previous->momentum())<0.07) continue;
294  if ( !result || aTrack.momentum().pt() > result->momentum().pt()) result = &aTrack;
295  }
296  return result;
297 }
Key key() const
Definition: GoldenPattern.h:58
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 configure(const OMTFConfiguration *omtfParams, const L1TMuonOverlapParams *omtfPatterns)
Fill GP map with patterns from CondFormats object.
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)
void initialize(const edm::EventSetup &es, const OMTFConfiguration *)
int theCharge
Definition: GoldenPattern.h:35
void makeConnetionsMap(unsigned int iProcessor, const OMTFinput &aInput)
OMTFPatternMaker(const edm::ParameterSet &cfg)
bool ev
edm::EDGetTokenT< L1MuDTChambPhContainer > inputTokenDTPh
unsigned int thePtCode
Definition: GoldenPattern.h:34
virtual void beginJob()
tuple result
Definition: mps_fire.py:84
OMTFConfigMaker * myOMTFConfigMaker
int iEvent
Definition: GenABIO.cc:230
const std::vector< int > * generalParams() const
General definitions.
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > inputTokenCSC
void printConnections(std::ostream &out, unsigned int iProcessor, unsigned int iCone)
void setGeneralParams(const std::vector< int > &paramsVec)
const L1TMuonOverlapParams * getRawParams() const
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 configure(const L1TMuonOverlapParams *omtfParams)
void reset()
Reset contents of all data vectors, keeping the vectors size.
int nPdfAddrBits() const
Access to specific general settings.
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
unsigned int nPdfAddrBits
Original pdf width. read from configuration.
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:43
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
OMTFinputMaker * myInputMaker
edm::ParameterSet theConfig
vector4D & getMeasurements4D()