CMS 3D CMS Logo

OMTFPatternMaker.cc
Go to the documentation of this file.
1 #include <iostream>
2 
6 
14 
16 
17 #include "Math/VectorUtil.h"
18 
20 
22  : theConfig(cfg),
23  g4SimTrackSrc(cfg.getParameter<edm::InputTag>("g4SimTrackSrc")),
24  esTokenParams_(esConsumes<edm::Transition::BeginRun>()) {
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 }
51 
52  if (!omtfParams) {
53  edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
54  }
55 
58 
61  L1TMuonOverlapParams omtfParamsMutable = *omtfParams;
62  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
63  nPdfAddrBits = omtfParams->nPdfAddrBits();
64 
65  if (!mergeXMLFiles)
67  omtfParamsMutable.setGeneralParams(generalParams);
68 
69  myOMTFConfig->configure(&omtfParamsMutable);
72 
74  if (!mergeXMLFiles) {
75  const std::map<Key, GoldenPattern*>& theGPs = myOMTF->getPatterns();
76  for (auto itGP : theGPs)
77  itGP.second->reset();
78  }
79 }
87  myOMTF = new OMTFProcessor();
88 }
94  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
95  for (auto itGP : myGPmap) {
96  if (!itGP.second->hasCounts())
97  continue;
98  itGP.second->normalise(nPdfAddrBits);
99  }
100 
101  GoldenPattern dummyGP(Key(0, 0, 0), myOMTFConfig);
102  dummyGP.reset();
103 
105  L1TMuonOverlapParams omtfParamsMutable = *myOMTFConfig->getRawParams();
106  std::vector<int> generalParams = *omtfParamsMutable.generalParams();
108  omtfParamsMutable.setGeneralParams(generalParams);
109  myOMTFConfig->configure(&omtfParamsMutable);
110 
111  for (auto itGP : myGPmap) {
113  unsigned int iPt = theConfig.getParameter<int>("ptCode") + 1;
114  if (iPt > 31)
115  iPt = 200 * 2 + 1;
116  else
117  iPt = RPCConst::ptFromIpt(iPt) * 2.0 +
118  1; //MicroGMT has 0.5 GeV step size, with lower bin edge (uGMT_pt_code - 1)*step_size
120  if (itGP.first.thePtCode == iPt && itGP.first.theCharge == theConfig.getParameter<int>("charge")) {
121  std::cout << *itGP.second << std::endl;
122  myWriter->writeGPData(*itGP.second, dummyGP, dummyGP, dummyGP);
123  }
124  }
125  std::string fName = "GPs.xml";
127  }
128 
131  std::string fName = "Connections.xml";
132  unsigned int iProcessor = 0;
143  }
144 
145  if (mergeXMLFiles) {
147  dummy->reset();
148 
149  std::string fName = "OMTF";
151  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
152  for (auto itGP : myGPmap) {
153  myWriter->writeGPData(*itGP.second, *dummy, *dummy, *dummy);
154  }
155  fName = "GPs.xml";
160  fName = "OMTF";
162  myOMTF->averagePatterns(-1);
164  writeMergedGPs();
165  fName = "GPs_4x.xml";
167  }
168 }
172  const std::map<Key, GoldenPattern*>& myGPmap = myOMTF->getPatterns();
173 
175  dummy->reset();
176 
177  unsigned int iPtMin = 9;
178  Key aKey = Key(0, iPtMin, 1);
179  while (myGPmap.find(aKey) != myGPmap.end()) {
180  GoldenPattern* aGP1 = myGPmap.find(aKey)->second;
181  GoldenPattern* aGP2 = dummy;
182  GoldenPattern* aGP3 = dummy;
183  GoldenPattern* aGP4 = dummy;
184 
185  ++aKey.thePtCode;
186  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
187  ++aKey.thePtCode;
188  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
189  aGP2 = myGPmap.find(aKey)->second;
190 
191  if (aKey.thePtCode > 71) {
192  ++aKey.thePtCode;
193  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
194  ++aKey.thePtCode;
195  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
196  aGP3 = myGPmap.find(aKey)->second;
197 
198  ++aKey.thePtCode;
199  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
200  ++aKey.thePtCode;
201  if (aKey.thePtCode <= 401 && myGPmap.find(aKey) != myGPmap.end())
202  aGP4 = myGPmap.find(aKey)->second;
203  }
204  ++aKey.thePtCode;
205  while (myGPmap.find(aKey) == myGPmap.end() && aKey.thePtCode <= 401)
206  ++aKey.thePtCode;
207  myWriter->writeGPData(*aGP1, *aGP2, *aGP3, *aGP4);
208 
210  Key aTmpKey = aGP1->key();
211  aTmpKey.theCharge = -1;
212  if (myGPmap.find(aTmpKey) != myGPmap.end())
213  aGP1 = myGPmap.find(aTmpKey)->second;
214  else
215  aGP1 = dummy;
216 
217  aTmpKey = aGP2->key();
218  aTmpKey.theCharge = -1;
219  if (myGPmap.find(aTmpKey) != myGPmap.end())
220  aGP2 = myGPmap.find(aTmpKey)->second;
221  else
222  aGP2 = dummy;
223 
224  aTmpKey = aGP3->key();
225  aTmpKey.theCharge = -1;
226  if (myGPmap.find(aTmpKey) != myGPmap.end())
227  aGP3 = myGPmap.find(aTmpKey)->second;
228  else
229  aGP3 = dummy;
230 
231  aTmpKey = aGP4->key();
232  aTmpKey.theCharge = -1;
233  if (myGPmap.find(aTmpKey) != myGPmap.end())
234  aGP4 = myGPmap.find(aTmpKey)->second;
235  else
236  aGP4 = dummy;
237 
238  myWriter->writeGPData(*aGP1, *aGP2, *aGP3, *aGP4);
239  }
240 }
244  if (mergeXMLFiles)
245  return;
246 
248  const SimTrack* aSimMuon = findSimMuon(iEvent);
249  if (!aSimMuon) {
250  edm::LogError("OMTFPatternMaker") << "No SimMuon found in the event!";
251  return;
252  }
253 
255 
260 
262  if (!theConfig.getParameter<bool>("dropDTPrimitives")) {
263  iEvent.getByToken(inputTokenDTPh, dtPhDigis);
264  iEvent.getByToken(inputTokenDTTh, dtThDigis);
265  }
266  if (!theConfig.getParameter<bool>("dropRPCPrimitives"))
267  iEvent.getByToken(inputTokenRPC, rpcDigis);
268  if (!theConfig.getParameter<bool>("dropCSCPrimitives"))
269  iEvent.getByToken(inputTokenCSC, cscDigis);
270 
271  //l1t::tftype mtfType = l1t::tftype::bmtf;
273  //l1t::tftype mtfType = l1t::tftype::emtf_pos;
274 
276  for (unsigned int iProcessor = 0; iProcessor < 6; ++iProcessor) {
279  dtPhDigis.product(), dtThDigis.product(), cscDigis.product(), rpcDigis.product(), iProcessor, mtfType);
280 
284  myOMTFConfigMaker->makeConnetionsMap(iProcessor, myInput);
285 
286  if (makeGoldenPatterns)
287  myOMTF->fillCounts(iProcessor, myInput, aSimMuon);
288  }
289 }
293  const SimTrack* result = nullptr;
295  ev.getByToken(inputTokenSimHit, simTks);
296 
297  for (std::vector<SimTrack>::const_iterator it = simTks->begin(); it < simTks->end(); it++) {
298  const SimTrack& aTrack = *it;
299  if (!(aTrack.type() == 13 || aTrack.type() == -13))
300  continue;
301  if (previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(), previous->momentum()) < 0.07)
302  continue;
303  if (!result || aTrack.momentum().pt() > result->momentum().pt())
304  result = &aTrack;
305  }
306  return result;
307 }
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
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const std::vector< int > * generalParams() const
General definitions.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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.
void initialiseXMLDocument(const std::string &docName)
int theCharge
Definition: GoldenPattern.h:36
T const * product() const
Definition: Handle.h:70
void endRun(edm::Run const &, edm::EventSetup const &) override
void makeConnetionsMap(unsigned int iProcessor, const OMTFinput &aInput)
OMTFPatternMaker(const edm::ParameterSet &cfg)
edm::EDGetTokenT< L1MuDTChambPhContainer > inputTokenDTPh
void averagePatterns(int charge)
void initialize(const edm::EventSetup &, const OMTFConfiguration *)
Log< level::Error, false > LogError
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
unsigned int thePtCode
Definition: GoldenPattern.h:35
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
OMTFConfigMaker * myOMTFConfigMaker
int iEvent
Definition: GenABIO.cc:224
omtfParams
OMTF ESProducer.
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > inputTokenCSC
void printConnections(std::ostream &out, unsigned int iProcessor, unsigned int iCone)
Key key() const
Definition: GoldenPattern.h:56
void setGeneralParams(const std::vector< int > &paramsVec)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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.
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.
HLT enums.
void finaliseXMLDocument(const std::string &fName)
void endJob() override
~OMTFPatternMaker() override
void beginJob() override
edm::ESGetToken< L1TMuonOverlapParams, L1TMuonOverlapParamsRcd > esTokenParams_
edm::EDGetTokenT< RPCDigiCollection > inputTokenRPC
unsigned int nPdfAddrBits
Original pdf width. read from configuration.
const SimTrack * findSimMuon(const edm::Event &ev, const SimTrack *previous=nullptr)
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:45
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
OMTFinputMaker * myInputMaker
edm::ParameterSet theConfig
vector4D & getMeasurements4D()
const L1TMuonOverlapParams * getRawParams() const