CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OMTFPatternMaker.cc
Go to the documentation of this file.
1 #include <iostream>
2 
5 
8 
16 
18 
19 #include "Math/VectorUtil.h"
20 
22 
24  : theConfig(cfg), g4SimTrackSrc(cfg.getParameter<edm::InputTag>("g4SimTrackSrc")) {
25  inputTokenDTPh = consumes<L1MuDTChambPhContainer>(theConfig.getParameter<edm::InputTag>("srcDTPh"));
26  inputTokenDTTh = consumes<L1MuDTChambThContainer>(theConfig.getParameter<edm::InputTag>("srcDTTh"));
27  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(theConfig.getParameter<edm::InputTag>("srcCSC"));
28  inputTokenRPC = consumes<RPCDigiCollection>(theConfig.getParameter<edm::InputTag>("srcRPC"));
29  inputTokenSimHit = consumes<edm::SimTrackContainer>(theConfig.getParameter<edm::InputTag>("g4SimTrackSrc"));
30 
32  myInputMaker = new OMTFinputMaker(consumesColl);
33 
34  makeGoldenPatterns = theConfig.getParameter<bool>("makeGoldenPatterns");
35  makeConnectionsMaps = theConfig.getParameter<bool>("makeConnectionsMaps");
36  mergeXMLFiles = theConfig.getParameter<bool>("mergeXMLFiles");
37 
38  myOMTFConfig = nullptr;
39 }
43  delete myOMTFConfig;
44  delete myOMTFConfigMaker;
45  delete myOMTF;
46 }
50  const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get<L1TMuonOverlapParamsRcd>();
51 
52  edm::ESHandle<L1TMuonOverlapParams> omtfParamsHandle;
53  omtfParamsRcd.get(omtfParamsHandle);
54 
55  const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product();
56 
57  if (!omtfParams) {
58  edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
59  }
60 
63 
66  L1TMuonOverlapParams omtfParamsMutable = *omtfParams;
67  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
68  nPdfAddrBits = omtfParams->nPdfAddrBits();
69 
70  if (!mergeXMLFiles)
72  omtfParamsMutable.setGeneralParams(generalParams);
73 
74  myOMTFConfig->configure(&omtfParamsMutable);
75  myOMTF->configure(myOMTFConfig, omtfParams);
77 
79  if (!mergeXMLFiles) {
80  const std::map<Key, GoldenPattern*>& theGPs = myOMTF->getPatterns();
81  for (auto itGP : theGPs)
82  itGP.second->reset();
83  }
84 }
89  myOMTF = new OMTFProcessor();
90 }
96  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
97  for (auto itGP : myGPmap) {
98  if (!itGP.second->hasCounts())
99  continue;
100  itGP.second->normalise(nPdfAddrBits);
101  }
102 
103  GoldenPattern dummyGP(Key(0, 0, 0), myOMTFConfig);
104  dummyGP.reset();
105 
107  L1TMuonOverlapParams omtfParamsMutable = *myOMTFConfig->getRawParams();
108  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
110  omtfParamsMutable.setGeneralParams(generalParams);
111  myOMTFConfig->configure(&omtfParamsMutable);
112 
113  for (auto itGP : myGPmap) {
115  unsigned int iPt = theConfig.getParameter<int>("ptCode") + 1;
116  if (iPt > 31)
117  iPt = 200 * 2 + 1;
118  else
119  iPt = RPCConst::ptFromIpt(iPt) * 2.0 +
120  1; //MicroGMT has 0.5 GeV step size, with lower bin edge (uGMT_pt_code - 1)*step_size
122  if (itGP.first.thePtCode == iPt && 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";
129  }
130 
133  std::string fName = "Connections.xml";
134  unsigned int iProcessor = 0;
145  }
146 
147  if (mergeXMLFiles) {
148  GoldenPattern* dummy = new GoldenPattern(Key(0, 0, 0), myOMTFConfig);
149  dummy->reset();
150 
151  std::string fName = "OMTF";
153  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
154  for (auto itGP : myGPmap) {
155  myWriter->writeGPData(*itGP.second, *dummy, *dummy, *dummy);
156  }
157  fName = "GPs.xml";
162  fName = "OMTF";
164  myOMTF->averagePatterns(-1);
166  writeMergedGPs();
167  fName = "GPs_4x.xml";
169  }
170 }
174  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
175 
176  GoldenPattern* dummy = new GoldenPattern(Key(0, 0, 0), myOMTFConfig);
177  dummy->reset();
178 
179  unsigned int iPtMin = 9;
180  Key aKey = Key(0, iPtMin, 1);
181  while (myGPmap.find(aKey) != myGPmap.end()) {
182  GoldenPattern* aGP1 = myGPmap.find(aKey)->second;
183  GoldenPattern* aGP2 = dummy;
184  GoldenPattern* aGP3 = dummy;
185  GoldenPattern* aGP4 = dummy;
186 
187  ++aKey.thePtCode;
188  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
189  ++aKey.thePtCode;
190  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
191  aGP2 = myGPmap.find(aKey)->second;
192 
193  if (aKey.thePtCode > 71) {
194  ++aKey.thePtCode;
195  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
196  ++aKey.thePtCode;
197  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
198  aGP3 = myGPmap.find(aKey)->second;
199 
200  ++aKey.thePtCode;
201  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
202  ++aKey.thePtCode;
203  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
204  aGP4 = myGPmap.find(aKey)->second;
205  }
206  ++aKey.thePtCode;
207  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
208  ++aKey.thePtCode;
209  myWriter->writeGPData(*aGP1, *aGP2, *aGP3, *aGP4);
210 
212  Key aTmpKey = aGP1->key();
213  aTmpKey.theCharge = -1;
214  if (myGPmap.find(aTmpKey) != myGPmap.end())
215  aGP1 = myGPmap.find(aTmpKey)->second;
216  else
217  aGP1 = dummy;
218 
219  aTmpKey = aGP2->key();
220  aTmpKey.theCharge = -1;
221  if (myGPmap.find(aTmpKey) != myGPmap.end())
222  aGP2 = myGPmap.find(aTmpKey)->second;
223  else
224  aGP2 = dummy;
225 
226  aTmpKey = aGP3->key();
227  aTmpKey.theCharge = -1;
228  if (myGPmap.find(aTmpKey) != myGPmap.end())
229  aGP3 = myGPmap.find(aTmpKey)->second;
230  else
231  aGP3 = dummy;
232 
233  aTmpKey = aGP4->key();
234  aTmpKey.theCharge = -1;
235  if (myGPmap.find(aTmpKey) != myGPmap.end())
236  aGP4 = myGPmap.find(aTmpKey)->second;
237  else
238  aGP4 = dummy;
239 
240  myWriter->writeGPData(*aGP1, *aGP2, *aGP3, *aGP4);
241  }
242 }
246  if (mergeXMLFiles)
247  return;
248 
250  const SimTrack* aSimMuon = findSimMuon(iEvent, evSetup);
251  if (!aSimMuon) {
252  edm::LogError("OMTFPatternMaker") << "No SimMuon found in the event!";
253  return;
254  }
255 
257 
262 
264  if (!theConfig.getParameter<bool>("dropDTPrimitives")) {
265  iEvent.getByToken(inputTokenDTPh, dtPhDigis);
266  iEvent.getByToken(inputTokenDTTh, dtThDigis);
267  }
268  if (!theConfig.getParameter<bool>("dropRPCPrimitives"))
269  iEvent.getByToken(inputTokenRPC, rpcDigis);
270  if (!theConfig.getParameter<bool>("dropCSCPrimitives"))
271  iEvent.getByToken(inputTokenCSC, cscDigis);
272 
273  //l1t::tftype mtfType = l1t::tftype::bmtf;
275  //l1t::tftype mtfType = l1t::tftype::emtf_pos;
276 
278  for (unsigned int iProcessor = 0; iProcessor < 6; ++iProcessor) {
281  dtPhDigis.product(), dtThDigis.product(), cscDigis.product(), rpcDigis.product(), iProcessor, mtfType);
282 
286  myOMTFConfigMaker->makeConnetionsMap(iProcessor, myInput);
287 
288  if (makeGoldenPatterns)
289  myOMTF->fillCounts(iProcessor, myInput, aSimMuon);
290  }
291 }
295  const edm::EventSetup& es,
296  const SimTrack* previous) {
297  const SimTrack* result = nullptr;
299  ev.getByToken(inputTokenSimHit, simTks);
300 
301  for (std::vector<SimTrack>::const_iterator it = simTks->begin(); it < simTks->end(); it++) {
302  const SimTrack& aTrack = *it;
303  if (!(aTrack.type() == 13 || aTrack.type() == -13))
304  continue;
305  if (previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(), previous->momentum()) < 0.07)
306  continue;
307  if (!result || aTrack.momentum().pt() > result->momentum().pt())
308  result = &aTrack;
309  }
310  return result;
311 }
Key key() const
Definition: GoldenPattern.h:56
void fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon)
void writeConnectionsData(const std::vector< std::vector< OMTFConfiguration::vector2D > > &measurements4D)
edm::EDGetTokenT< edm::SimTrackContainer > inputTokenSimHit
tuple cfg
Definition: looper.py:296
edm::ConsumesCollector consumesColl(consumesCollector())
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
OMTFinput buildInputForProcessor(const L1MuDTChambPhContainer *dtPhDigis, const L1MuDTChambThContainer *dtThDigis, const CSCCorrelatedLCTDigiCollection *cscDigis, const RPCDigiCollection *rpcDigis, unsigned int iProcessor, l1t::tftype type=l1t::tftype::omtf_pos, int bx=0)
Method translating trigger digis into input matrix with global phi coordinates.
OMTFConfiguration * myOMTFConfig
OMTF objects.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
tuple omtfParams
OMTF ESProducer.
void initialiseXMLDocument(const std::string &docName)
int theCharge
Definition: GoldenPattern.h:36
void makeConnetionsMap(unsigned int iProcessor, const OMTFinput &aInput)
OMTFPatternMaker(const edm::ParameterSet &cfg)
const SimTrack * findSimMuon(const edm::Event &ev, const edm::EventSetup &es, const SimTrack *previous=nullptr)
bool ev
edm::EDGetTokenT< L1MuDTChambPhContainer > inputTokenDTPh
void averagePatterns(int charge)
void initialize(const edm::EventSetup &, const OMTFConfiguration *)
Log< level::Error, false > LogError
unsigned int thePtCode
Definition: GoldenPattern.h:35
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
tuple previous
Definition: callgraph.py:103
tuple result
Definition: mps_fire.py:311
OMTFConfigMaker * myOMTFConfigMaker
int iEvent
Definition: GenABIO.cc:224
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)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const L1TMuonOverlapParams * getRawParams() const
if(conf_.getParameter< bool >("UseStripCablingDB"))
void beginRun(edm::Run const &run, edm::EventSetup const &iSetup) override
XMLConfigWriter * myWriter
OMTFProcessor * myOMTF
static double ptFromIpt(const int ipt)
Definition: RPCConst.cc:29
void configure(const L1TMuonOverlapParams *omtfParams)
void reset()
Reset contents of all data vectors, keeping the vectors size.
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
int nPdfAddrBits() const
Access to specific general settings.
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void analyze(const edm::Event &, const edm::EventSetup &) override
void printPhiMap(std::ostream &out)
bool configure(const OMTFConfiguration *omtfParams, const L1TMuonOverlapParams *omtfPatterns)
Fill GP map with patterns from CondFormats object.
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
T get() const
Definition: EventSetup.h:88
void finaliseXMLDocument(const std::string &fName)
void endJob() override
tuple cout
Definition: gather_cfg.py:144
~OMTFPatternMaker() override
void beginJob() override
edm::EDGetTokenT< RPCDigiCollection > inputTokenRPC
unsigned int nPdfAddrBits
Original pdf width. read from configuration.
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:45
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
OMTFinputMaker * myInputMaker
edm::ParameterSet theConfig
vector4D & getMeasurements4D()