CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMuonOverlapTrackProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <strstream>
3 #include <vector>
4 
6 
9 
12 
20 
22 
24 
25  produces<l1t::RegionalMuonCandBxCollection >("OMTF");
26 
27  inputTokenDTPh = consumes<L1MuDTChambPhContainer>(theConfig.getParameter<edm::InputTag>("srcDTPh"));
28  inputTokenDTTh = consumes<L1MuDTChambThContainer>(theConfig.getParameter<edm::InputTag>("srcDTTh"));
29  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(theConfig.getParameter<edm::InputTag>("srcCSC"));
30  inputTokenRPC = consumes<RPCDigiCollection>(theConfig.getParameter<edm::InputTag>("srcRPC"));
31 
32  if(!theConfig.exists("omtf")){
33  edm::LogError("L1TMuonOverlapTrackProducer")<<"omtf configuration not found in cfg.py";
34  }
35 
37  mySorter = new OMTFSorter();
38  myOMTF = 0;
39  myWriter = 0;
40 
41  dumpResultToXML = theConfig.getParameter<bool>("dumpResultToXML");
42  dumpDetailedResultToXML = theConfig.getParameter<bool>("dumpDetailedResultToXML");
43  dumpGPToXML = theConfig.getParameter<bool>("dumpGPToXML");
44  theConfig.getParameter<std::string>("XMLDumpFileName");
45 
46  if(dumpResultToXML || dumpGPToXML){
47  myWriter = new XMLConfigWriter();
48  std::string fName = "OMTF";
50  }
51 
52  myOMTFConfig = 0;
53 }
57 
58  delete myOMTFConfig;
59  delete myOMTF;
60 
61  delete myInputMaker;
62  delete mySorter;
63 
64  if (myWriter) delete myWriter;
65 
66 }
70 
71  if(theConfig.exists("omtf")){
74  }
75 }
79 
81  std::string fName = theConfig.getParameter<std::string>("XMLDumpFileName");
83  }
84 
86 
87  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0));
88  dummy->reset();
89 
90  std::string fName = "OMTF";
92  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
93  for(auto itGP: myGPmap){
94  if(itGP.second->key().thePtCode==6) std::cout<<*itGP.second<<std::endl;
95  //myWriter->writeGPData(*itGP.second);
96  if(itGP.second->key().thePtCode>5) myWriter->writeGPData(*itGP.second,*dummy, *dummy, *dummy);
97  }
98  fName = "GPs.xml";
103  fName = "OMTF";
106  myOMTF->averagePatterns(-1);
107 
108  writeMergedGPs();
109 
110  fName = "GPs_4x.xml";
112  }
113 }
117 
118  const std::map<Key,GoldenPattern*> & myGPmap = myOMTF->getPatterns();
119 
120  GoldenPattern *dummy = new GoldenPattern(Key(0,0,0));
121  dummy->reset();
122 
123  unsigned int iPtMin = 6;
124  Key aKey = Key(1, iPtMin,-1);
125  while(myGPmap.find(aKey)!=myGPmap.end()){
126 
127  GoldenPattern *aGP1 = myGPmap.find(aKey)->second;
128  GoldenPattern *aGP2 = dummy;
129  GoldenPattern *aGP3 = dummy;
130  GoldenPattern *aGP4 = dummy;
131 
132  ++aKey.thePtCode;
133  if(aKey.thePtCode<=31 && myGPmap.find(aKey)!=myGPmap.end()) aGP2 = myGPmap.find(aKey)->second;
134 
135  if(aKey.thePtCode>19){
136  ++aKey.thePtCode;
137  if(aKey.thePtCode<=31 && myGPmap.find(aKey)!=myGPmap.end()) aGP3 = myGPmap.find(aKey)->second;
138 
139  ++aKey.thePtCode;
140  if(aKey.thePtCode<=31 && myGPmap.find(aKey)!=myGPmap.end()) aGP4 = myGPmap.find(aKey)->second;
141  }
142  ++aKey.thePtCode;
143  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
144 
146  Key aTmpKey = aGP1->key();
147  aTmpKey.theCharge = 1;
148  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP1 = myGPmap.find(aTmpKey)->second;
149  else aGP1 = dummy;
150 
151  aTmpKey = aGP2->key();
152  aTmpKey.theCharge = 1;
153  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP2 = myGPmap.find(aTmpKey)->second;
154  else aGP2 = dummy;
155 
156  aTmpKey = aGP3->key();
157  aTmpKey.theCharge = 1;
158  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP3 = myGPmap.find(aTmpKey)->second;
159  else aGP3 = dummy;
160 
161  aTmpKey = aGP4->key();
162  aTmpKey.theCharge = 1;
163  if(myGPmap.find(aTmpKey)!=myGPmap.end()) aGP4 = myGPmap.find(aTmpKey)->second;
164  else aGP4 = dummy;
165 
166  myWriter->writeGPData(*aGP1,*aGP2, *aGP3, *aGP4);
167  }
168 }
172 
174  if(theConfig.getParameter<edm::ParameterSet>("omtf").getParameter<bool>("configFromXML")) return;
175 
176  const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get<L1TMuonOverlapParamsRcd>();
177 
178  edm::ESHandle<L1TMuonOverlapParams> omtfParamsHandle;
179  omtfParamsRcd.get(omtfParamsHandle);
180 
181  omtfParams = std::unique_ptr<L1TMuonOverlapParams>(new L1TMuonOverlapParams(*omtfParamsHandle.product()));
182  if (!omtfParams) {
183  edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl;
184  }
185 
188 
189 }
193 
194  std::ostringstream myStr;
195 
196  myInputMaker->initialize(evSetup);
197 
202 
204  if(!theConfig.getParameter<bool>("dropDTPrimitives")){
205  iEvent.getByToken(inputTokenDTPh,dtPhDigis);
206  iEvent.getByToken(inputTokenDTTh,dtThDigis);
207  }
208  if(!theConfig.getParameter<bool>("dropRPCPrimitives")) iEvent.getByToken(inputTokenRPC,rpcDigis);
209  if(!theConfig.getParameter<bool>("dropCSCPrimitives")) iEvent.getByToken(inputTokenCSC,cscDigis);
210 
211  std::auto_ptr<l1t::RegionalMuonCandBxCollection > myCands(new l1t::RegionalMuonCandBxCollection);
212 
214 
215  // NOTE: assuming all is for bx 0
216  int bx = 0;
217 
219  for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){
220 
221  //myStr<<" iProcessor: "<<iProcessor;
222 
224  const OMTFinput *myInputPos = myInputMaker->buildInputForProcessor(dtPhDigis.product(),
225  dtThDigis.product(),
226  cscDigis.product(),
227  rpcDigis.product(),
228  iProcessor,
230 
231  OMTFinput myShiftedInputPos = myOMTF->shiftInput(iProcessor,*myInputPos);
232 
233  const OMTFinput *myInputNeg = myInputMaker->buildInputForProcessor(dtPhDigis.product(),
234  dtThDigis.product(),
235  cscDigis.product(),
236  rpcDigis.product(),
237  iProcessor,
239 
240 
241  OMTFinput myShiftedInputNeg = myOMTF->shiftInput(iProcessor,*myInputNeg);
242 
243  l1t::RegionalMuonCandBxCollection myOTFCandidatesPos, myOTFCandidatesNeg;
245  //Retreive all candidates returned by sorter: upto 3 non empty ones with different phi or charge
246  const std::vector<OMTFProcessor::resultsMap> & myResultsNeg = myOMTF->processInput(iProcessor,myShiftedInputNeg);
247  mySorter->sortProcessor(myResultsNeg, myOTFCandidatesNeg, bx);
248 
249  const std::vector<OMTFProcessor::resultsMap> & myResultsPos = myOMTF->processInput(iProcessor,myShiftedInputPos);
250  mySorter->sortProcessor(myResultsPos, myOTFCandidatesPos, bx);
251 
253  processCandidates(iProcessor, bx, myCands, myOTFCandidatesPos, l1t::tftype::omtf_pos);
254  processCandidates(iProcessor, bx, myCands, myOTFCandidatesNeg, l1t::tftype::omtf_neg);
255 
257  if(dumpResultToXML){
258  xercesc::DOMElement * aProcElement = myWriter->writeEventData(aTopElement,iProcessor,myShiftedInputPos);
259  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::nTestRefHits;++iRefHit){
261  InternalObj myCand = mySorter->sortRefHitResults(myResultsPos[iRefHit],0);//charge=0 means ignore charge
262  if(myCand.pt){
263  myWriter->writeCandidateData(aProcElement,iRefHit,myCand);
265  for(auto & itKey: myResultsNeg[iRefHit]) myWriter->writeResultsData(aProcElement,
266  iRefHit,
267  itKey.first,itKey.second);
268  }
269  }
270  }
271  }
272  }
273 
274  //dumpResultToXML = true;
275  myStr<<" Number of candidates: "<<myCands->size(bx);
276  edm::LogInfo("OMTFOMTFProducer")<<myStr.str();
277 
278  iEvent.put(myCands, "OMTF");
279 }
282 void L1TMuonOverlapTrackProducer::processCandidates(unsigned int iProcessor, int bx,
283  std::auto_ptr<l1t::RegionalMuonCandBxCollection > & myCands,
284  l1t::RegionalMuonCandBxCollection & myOTFCandidates,
285  l1t::tftype mtfType){
286 
288  int procOffset = OMTFConfiguration::globalPhiStart(iProcessor);
289  if(procOffset<0) procOffset+=(int)OMTFConfiguration::nPhiBins;
291  procOffset-=(15+iProcessor*60)/360.0*OMTFConfiguration::nPhiBins;
292  int lowScaleEnd = pow(2,OMTFConfiguration::nPhiBits-1);
293 
294  for(unsigned int iCand=0; iCand<myOTFCandidates.size(bx); ++iCand){
295  // shift phi from processor to global coordinates
296  l1t::RegionalMuonCand cand = myOTFCandidates.at(bx, iCand);
297  int phiValue = (cand.hwPhi()+procOffset+lowScaleEnd);
298  if(phiValue>=(int)OMTFConfiguration::nPhiBins) phiValue-=OMTFConfiguration::nPhiBins;
299  phiValue/=10; //MicroGMT has 10x coarser scale than OMTF
300 
301  cand.setHwPhi(phiValue);
302  cand.setTFIdentifiers(iProcessor,mtfType);
303  // store candidate
304  if(cand.hwPt()) myCands->push_back(bx, cand);
305  }
306 }
309 
Key key() const
Definition: GoldenPattern.h:59
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
void averagePatterns(int charge)
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
tuple cfg
Definition: looper.py:293
unsigned size(int bx) const
void writeCandidateData(xercesc::DOMElement *aTopElement, unsigned int iRefHit, const InternalObj &aCand)
virtual void produce(edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#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
xercesc::DOMElement * writeEventData(xercesc::DOMElement *aTopElement, unsigned int iProcessor, const OMTFinput &aInput)
static int globalPhiStart(unsigned int iProcessor)
edm::EDGetTokenT< L1MuDTChambPhContainer > inputTokenDTPh
bool configure(XMLConfigReader *aReader)
Fill GP map with patterns from XML file.
unsigned int thePtCode
Definition: GoldenPattern.h:36
void initialize(const edm::EventSetup &es)
void processCandidates(unsigned int iProcessor, int bx, std::auto_ptr< l1t::RegionalMuonCandBxCollection > &myCands, l1t::RegionalMuonCandBxCollection &myOTFCandidates, l1t::tftype mtfType)
std::shared_ptr< L1TMuonOverlapParams > omtfParams
int iEvent
Definition: GenABIO.cc:230
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
void writeResultsData(xercesc::DOMElement *aTopElement, unsigned int iRegion, const Key &aKey, const OMTFResult &aResult)
void configure(XMLConfigReader *aReader)
static unsigned int nTestRefHits
void get(HolderT &iHolder) const
static unsigned int nPhiBins
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
static unsigned int nPhiBits
OMTFConfiguration * myOMTFConfig
OMTF objects.
edm::EDGetTokenT< RPCDigiCollection > inputTokenRPC
void reset()
Reset contents of all data vectors, keeping the vectors size.
T const * product() const
Definition: Handle.h:81
InternalObj sortRefHitResults(const OMTFProcessor::resultsMap &aResultsMap, int charge=0)
Definition: OMTFSorter.cc:70
const T & get() const
Definition: EventSetup.h:56
float pt
Definition: InternalObj.h:8
void sortProcessor(const std::vector< OMTFProcessor::resultsMap > &procResults, l1t::RegionalMuonCandBxCollection &sortedCands, int bx, int charge=0)
Sort all processor results.
Definition: OMTFSorter.cc:207
virtual void beginRun(edm::Run const &run, edm::EventSetup const &iSetup)
edm::EDGetTokenT< L1MuDTChambThContainer > inputTokenDTTh
const 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.
edm::EventID id() const
Definition: EventBase.h:59
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > inputTokenCSC
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
const std::vector< OMTFProcessor::resultsMap > & processInput(unsigned int iProcessor, const OMTFinput &aInput)
void finaliseXMLDocument(const std::string &fName)
OMTFinput shiftInput(unsigned int iProcessor, const OMTFinput &aInput)
tuple cout
Definition: gather_cfg.py:145
xercesc::DOMElement * writeEventHeader(unsigned int eventId, unsigned int mixedEventId=0)
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void writeGPData(const GoldenPattern &aGP)
Definition: Run.h:43
L1TMuonOverlapTrackProducer(const edm::ParameterSet &)
const T & at(int bx, unsigned i) const