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 
64  myOMTFConfig->configure(omtfParams);
65  myOMTF->configure(myOMTFConfig, omtfParams);
66 
68  std::string fName = "OMTF";
70 
73  //FIXME myOMTFConfig->rawParams().nPdfAddrBits = 14;
74 
76  const std::map<Key,GoldenPattern*> & theGPs = myOMTF->getPatterns();
77  for(auto itGP: theGPs) itGP.second->reset();
78 
79 }
83 
86  myOMTF = new OMTFProcessor();
87 }
91 
93  std::string fName = "OMTF";
95  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
96  for(auto itGP: myGPmap){
97  if(!itGP.second->hasCounts()) continue;
98  itGP.second->normalise();
99  }
100 
102  //FIXME myOMTFConfig->nPdfAddrBits = 7;
103  for(auto itGP: myGPmap){
105  unsigned int iPt = theConfig.getParameter<int>("ptCode")+1;
106  if(iPt>31) iPt = 200*2+1;
107  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
109  if(itGP.first.thePtCode==iPt &&
110  itGP.first.theCharge==theConfig.getParameter<int>("charge")){
111  std::cout<<*itGP.second<<std::endl;
112  myWriter->writeGPData(*itGP.second);
113  }
114  }
115  fName = "GPs.xml";
116  myWriter->finaliseXMLDocument(fName);
117  }
118 
120  std::string fName = "Connections.xml";
121  unsigned int iProcessor = 0;
132  }
133 
134  if(mergeXMLFiles){
135 
136  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0), myOMTFConfig);
137  dummy->reset();
138 
139  std::string fName = "OMTF";
141  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
142  for(auto itGP: myGPmap){
143  myWriter->writeGPData(*itGP.second,*dummy, *dummy, *dummy);
144  }
145  fName = "GPs.xml";
150  fName = "OMTF";
152  myOMTF->averagePatterns(-1);
154  writeMergedGPs();
155  fName = "GPs_4x.xml";
157  }
158 }
162 
163  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
164 
165  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0), myOMTFConfig);
166  dummy->reset();
167 
168  unsigned int iPtMin = 9;
169  Key aKey = Key(0, iPtMin,-1);
170  while(myGPmap.find(aKey)!=myGPmap.end()){
171 
172  GoldenPattern *aGP1 = myGPmap.find(aKey)->second;
173  GoldenPattern *aGP2 = dummy;
174  GoldenPattern *aGP3 = dummy;
175  GoldenPattern *aGP4 = dummy;
176 
177  ++aKey.thePtCode;
178  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
179  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP2 = myGPmap.find(aKey)->second;
180 
181  if(aKey.thePtCode>71){
182  ++aKey.thePtCode;
183  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
184  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP3 = myGPmap.find(aKey)->second;
185 
186  ++aKey.thePtCode;
187  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
188  if(aKey.thePtCode<=401 && myGPmap.find(aKey)!=myGPmap.end()) aGP4 = myGPmap.find(aKey)->second;
189  }
190  ++aKey.thePtCode;
191  while(myGPmap.find(aKey)==myGPmap.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
192  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
193 
195  Key aTmpKey = aGP1->key();
196  aTmpKey.theCharge = 1;
197  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP1 = myGPmap.find(aTmpKey)->second;
198  else aGP1 = dummy;
199 
200  aTmpKey = aGP2->key();
201  aTmpKey.theCharge = 1;
202  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP2 = myGPmap.find(aTmpKey)->second;
203  else aGP2 = dummy;
204 
205  aTmpKey = aGP3->key();
206  aTmpKey.theCharge = 1;
207  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP3 = myGPmap.find(aTmpKey)->second;
208  else aGP3 = dummy;
209 
210  aTmpKey = aGP4->key();
211  aTmpKey.theCharge = 1;
212  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP4 = myGPmap.find(aTmpKey)->second;
213  else aGP4 = dummy;
214 
215  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
216  }
217 }
221 
222  if(mergeXMLFiles) return;
223 
225  const SimTrack* aSimMuon = findSimMuon(iEvent,evSetup);
226  if(!aSimMuon){
227  edm::LogError("OMTFPatternMaker")<<"No SimMuon found in the event!";
228  return;
229  }
230 
232 
237 
239  if(!theConfig.getParameter<bool>("dropDTPrimitives")){
240  iEvent.getByToken(inputTokenDTPh,dtPhDigis);
241  iEvent.getByToken(inputTokenDTTh,dtThDigis);
242  }
243  if(!theConfig.getParameter<bool>("dropRPCPrimitives")) iEvent.getByToken(inputTokenRPC,rpcDigis);
244  if(!theConfig.getParameter<bool>("dropCSCPrimitives")) iEvent.getByToken(inputTokenCSC,cscDigis);
245 
246  //l1t::tftype mtfType = l1t::tftype::bmtf;
248  //l1t::tftype mtfType = l1t::tftype::emtf_pos;
249 
251  for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){
252 
254  OMTFinput myInput = myInputMaker->buildInputForProcessor(dtPhDigis.product(),
255  dtThDigis.product(),
256  cscDigis.product(),
257  rpcDigis.product(),
258  iProcessor,
259  mtfType);
260 
264 
265  if(makeGoldenPatterns) myOMTF->fillCounts(iProcessor,myInput, aSimMuon);
266 
267  }
268 }
271 const SimTrack * OMTFPatternMaker::findSimMuon(const edm::Event &ev, const edm::EventSetup &es, const SimTrack * previous){
272 
273  const SimTrack * result = 0;
275  ev.getByToken(inputTokenSimHit,simTks);
276 
277  for (std::vector<SimTrack>::const_iterator it=simTks->begin(); it< simTks->end(); it++) {
278  const SimTrack & aTrack = *it;
279  if ( !(aTrack.type() == 13 || aTrack.type() == -13) )continue;
280  if(previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(),previous->momentum())<0.07) continue;
281  if ( !result || aTrack.momentum().pt() > result->momentum().pt()) result = &aTrack;
282  }
283  return result;
284 }
Key key() const
Definition: GoldenPattern.h:60
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:38
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:37
virtual void beginJob()
tuple result
Definition: mps_fire.py:83
OMTFConfigMaker * myOMTFConfigMaker
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > inputTokenCSC
void printConnections(std::ostream &out, unsigned int iProcessor, unsigned int iCone)
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.
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.
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:43
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
OMTFinputMaker * myInputMaker
edm::ParameterSet theConfig
vector4D & getMeasurements4D()