12 #define NUM_SECTORS 12 16 #include "L1Trigger/CSCTrackFinder/test/src/RefTrack.h" 50 produces<l1t::RegionalMuonCandBxCollection >(
"EMTF");
51 produces< l1t::EMTFTrackCollection >(
"");
52 produces< l1t::EMTFHitCollection >(
"");
53 produces< l1t::EMTFTrackExtraCollection >(
"");
54 produces< l1t::EMTFHitExtraCollection >(
"CSC");
55 produces< l1t::EMTFHitExtraCollection >(
"RPC");
68 auto FoundTracks = std::make_unique<L1TMuon::InternalTrackCollection>();
69 auto OutputCands = std::make_unique<l1t::RegionalMuonCandBxCollection>();
70 auto OutTracks = std::make_unique<l1t::EMTFTrackCollection>();
71 auto OutHits = std::make_unique<l1t::EMTFHitCollection>();
72 auto OutputTracks = std::make_unique<l1t::EMTFTrackExtraCollection>();
73 auto OutputHits = std::make_unique<l1t::EMTFHitExtraCollection>();
74 auto OutputHitsRPC = std::make_unique<l1t::EMTFHitExtraCollection>();
79 std::vector<TriggerPrimitive> tester;
80 std::vector<TriggerPrimitive> tester_rpc;
100 std::vector<TriggerPrimitive>
out;
101 std::vector<TriggerPrimitive> out_rpc;
104 auto chend = MDC->end();
106 auto digi = (*chamber).second.first;
107 auto dend = (*chamber).second.second;
108 for( ; digi != dend; ++digi ) {
117 OutputHits->push_back( thisHit );
118 if ( ((thisHit.
Ring() != 1 || thisHit.
Station() == 1) && (thisHit.
Chamber() % 6 == 2)) ||
122 OutputHits->push_back( neighborHit );
127 auto rchamber = RDC->begin();
128 auto rchend = RDC->end();
129 for( ; rchamber != rchend; ++rchamber) {
130 auto rdigi = (*rchamber).second.first;
131 auto rdend = (*rchamber).second.second;
132 for( ; rdigi != rdend; ++rdigi) {
133 out_rpc.push_back(
TriggerPrimitive( (*rchamber).first, rdigi->strip(), 0, rdigi->bx()));
147 auto tp = out_rpc.cbegin();
148 auto tpend = out_rpc.cend();
150 for( ; tp != tpend; ++tp ) {
151 if (tp->subsystem() == 2) tester_rpc.push_back(*tp);
155 for(
unsigned int i1=0;i1<out.size();i1++){
156 tester.push_back(out[i1]);
158 for(
unsigned int i2=i1+1;i2<out.size();i2++){
159 if ( out[i1].detId<CSCDetId>().station() == out[i2].detId<
CSCDetId>().
station() &&
164 out[i1].getBX() == out[i2].getBX() && out[i1].Id() == out[i2].Id() &&
165 out[i1].getStrip() != out[i2].getStrip() && out[i1].getWire() != out[i2].getWire() ) {
169 tester.push_back(NewWire1);
170 tester.push_back(NewWire2);
175 uint nHits = OutputHits->size();
176 for (uint iHit = 0; iHit < nHits; iHit++) {
177 for (uint jHit = iHit+1; jHit < nHits; jHit++) {
178 if ( OutputHits->at(iHit).Chamber() != OutputHits->at(jHit).Chamber() )
continue;
179 if ( (OutputHits->at(iHit).Ring() % 3) != (OutputHits->at(jHit).Ring() % 3) )
continue;
180 if ( OutputHits->at(iHit).Sector() != OutputHits->at(jHit).Sector() )
continue;
181 if ( OutputHits->at(iHit).Station() != OutputHits->at(jHit).Station() )
continue;
182 if ( OutputHits->at(iHit).Endcap() != OutputHits->at(jHit).Endcap() )
continue;
183 if ( OutputHits->at(iHit).BX() != OutputHits->at(jHit).BX() )
continue;
184 if ( OutputHits->at(iHit).Neighbor() != OutputHits->at(jHit).Neighbor() )
continue;
185 if ( OutputHits->at(iHit).Strip() == OutputHits->at(jHit).Strip() )
continue;
186 if ( OutputHits->at(iHit).Wire() == OutputHits->at(jHit).Wire() )
continue;
190 new_hit_1.
set_wire( OutputHits->at(jHit).Wire() );
191 new_hit_2.
set_wire( OutputHits->at(iHit).Wire() );
194 OutputHits->push_back( new_hit_1 );
195 OutputHits->push_back( new_hit_2 );
202 for(
int SectIndex=0;SectIndex<
NUM_SECTORS;SectIndex++){
208 std::vector<ConvertedHit> ConvHits = primConv_.convert(tester,SectIndex);
209 CHits[SectIndex] = ConvHits;
212 for (uint iHit = 0; iHit < tmp_hits_rpc.size(); iHit++)
213 OutputHitsRPC->push_back( tmp_hits_rpc.at(iHit) );
214 std::vector<ConvertedHit> ConvHitsRPC = primConvRPC_.fillConvHits(tmp_hits_rpc);
217 for (uint iCHit = 0; iCHit < ConvHits.size(); iCHit++) {
220 for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
221 if ( ConvHits.at(iCHit).Station() == OutputHits->at(iHit).Station() &&
222 ( ConvHits.at(iCHit).Id() == OutputHits->at(iHit).CSC_ID() ||
223 ConvHits.at(iCHit).Id() == ( (OutputHits->at(iHit).Ring() != 4)
224 ? OutputHits->at(iHit).CSC_ID()
225 : OutputHits->at(iHit).CSC_ID() + 9 ) ) &&
226 ConvHits.at(iCHit).Wire() == OutputHits->at(iHit).Wire() &&
227 ConvHits.at(iCHit).Strip() == OutputHits->at(iHit).Strip() &&
228 ConvHits.at(iCHit).BX() - 6 == OutputHits->at(iHit).BX() &&
229 ConvHits.at(iCHit).IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
231 OutputHits->at(iHit).set_neighbor ( ConvHits.at(iCHit).IsNeighbor());
232 OutputHits->at(iHit).set_sector_index( ConvHits.at(iCHit).SectorIndex() );
233 OutputHits->at(iHit).set_phi_zone ( ConvHits.at(iCHit).Zhit() );
234 OutputHits->at(iHit).set_phi_hit ( ConvHits.at(iCHit).Ph_hit() );
235 OutputHits->at(iHit).set_zone ( ConvHits.at(iCHit).Phzvl() );
236 OutputHits->at(iHit).set_phi_loc_int ( ConvHits.at(iCHit).Phi() );
237 OutputHits->at(iHit).set_theta_int ( ConvHits.at(iCHit).Theta() );
241 OutputHits->at(iHit).set_phi_loc_deg (
l1t::calc_phi_loc_deg( OutputHits->at(iHit).Phi_loc_int() ) );
242 OutputHits->at(iHit).set_phi_loc_rad (
l1t::calc_phi_loc_rad( OutputHits->at(iHit).Phi_loc_int() ) );
243 OutputHits->at(iHit).set_phi_glob_deg (
l1t::calc_phi_glob_deg_hit( OutputHits->at(iHit).Phi_loc_deg(), OutputHits->at(iHit).Sector_index() ) );
244 OutputHits->at(iHit).set_phi_glob_rad (
l1t::calc_phi_glob_rad_hit( OutputHits->at(iHit).Phi_loc_rad(), OutputHits->at(iHit).Sector_index() ) );
249 OutHits->push_back( OutputHits->at(iHit).CreateEMTFHit() );
294 std::vector<std::vector<ConvertedHit>> GroupedHits =
GroupBX(ConvHits);
301 std::vector<ZonesOutput> Zout =
Zones(GroupedHits);
309 std::vector<PatternOutput> Pout =
Patterns(Zout);
310 std::vector<PatternOutput> Pout_Hold = Pout;
323 std::vector<SortingOutput> Sout_Hold =
SortSect_Hold(Pout_Hold);
351 std::vector<std::vector<BTrack>> Bout_Hold =
BestTracks_Hold(Dout_Hold);
352 for(
int bx=0;bx<3;bx++)
353 PTracks_BX[SectIndex][bx] = Bout_Hold[bx];
364 std::vector<BTrack> AllTracks, AllTracks_PreCancel;
367 for(
int bx=0;bx<3;bx++){
368 for(
int j=0;j<36;j++){
373 if(PTracks_BX[j/3][bx][j%3].
phi) {
374 AllTracks_PreCancel.push_back(PTracks_BX[j/3][bx][j%3]);
375 if (PTracks_BX[j/3][bx][j%3].
theta == 0)
376 LogTrace(
"L1TMuonEndCapTrackProducer") <<
"PTrack_BX theta = 0" << std::endl;
383 for (
unsigned int i1 = 0; i1 < AllTracks_PreCancel.size(); i1++) {
385 int rank1 = AllTracks_PreCancel[i1].winner.Rank();
389 for (
unsigned int i2 = 0; i2 < AllTracks_PreCancel.size(); i2++) {
390 if (i1 == i2)
continue;
391 for (std::vector<ConvertedHit>::iterator A1 = AllTracks_PreCancel[i1].AHits.begin(); A1 != AllTracks_PreCancel[i1].AHits.end(); A1++) {
394 for (std::vector<ConvertedHit>::iterator A2 = AllTracks_PreCancel[i2].AHits.begin(); A2 != AllTracks_PreCancel[i2].AHits.end(); A2++) {
399 C1.bx == C2.bx && C1.strip == C2.strip && C1.keywire == C2.keywire ) {
401 if (AllTracks_PreCancel[i2].winner.Rank() > rank2) {
403 rank2 = AllTracks_PreCancel[i2].winner.Rank();
411 if ( (!dup) || (rank1 > rank2) || (rank1 == rank2 && i1_dup < i2_dup) ) AllTracks.push_back(AllTracks_PreCancel[i1]);
420 std::vector<l1t::RegionalMuonCand> tester1;
421 std::vector<std::pair<int,l1t::RegionalMuonCand>> holder, holder2;
423 for(
unsigned int fbest=0;fbest<AllTracks.size();fbest++){
425 if(AllTracks[fbest].
phi){
429 tempTrack.
phi = AllTracks[fbest].phi;
430 tempTrack.
theta = AllTracks[fbest].theta;
431 tempTrack.
rank = AllTracks[fbest].winner.Rank();
432 tempTrack.
deltas = AllTracks[fbest].deltas;
433 std::vector<int> ps, ts;
435 if (tempTrack.
theta == 0)
LogTrace(
"L1TMuonEndCapTrackProducer") <<
"Track has theta 0" << std::endl;
440 thisTrack.
set_rank ( AllTracks[fbest].winner.Rank() );
442 int tempStraightness = 0;
443 int tempRank = thisTrack.
Rank();
445 tempStraightness |= 4;
447 tempStraightness |= 2;
449 tempStraightness |= 1;
453 if(tempTrack.
rank & 32)
455 if(tempTrack.
rank & 8)
457 if(tempTrack.
rank & 2)
459 if(tempTrack.
rank & 1)
464 int me1address = 0, me2address = 0, CombAddress = 0, mode_uncorr = 0;
465 int ebx = 20, sebx = 20;
466 int phis[4] = {-99,-99,-99,-99};
468 int cHits_in_station[4] = {0,0,0,0};
469 int eHits_in_station[4] = {0,0,0,0};
470 for(std::vector<ConvertedHit>::iterator
A = AllTracks[fbest].AHits.begin();
A != AllTracks[fbest].AHits.end();
A++){
472 if(
A->Phi() != -999){
478 for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
479 if ( (
A->TP().detId<
CSCDetId>().
endcap() == 1) == (OutputHits->at(iHit).Endcap() == 1) &&
482 A->TP().getCSCData().cscID == OutputHits->at(iHit).CSC_ID() &&
483 A->Wire() == OutputHits->at(iHit).Wire() &&
484 A->Strip() == OutputHits->at(iHit).Strip() &&
485 A->TP().getCSCData().bx - 6 == OutputHits->at(iHit).BX() &&
486 A->IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
487 thisHit = OutputHits->at(iHit);
493 eHits_in_station[OutputHits->at(iHit).Station() - 1] += 1;
502 LogTrace(
"L1TMuonEndCapTrackProducer") <<
"!@#$ Converted hit with station " <<
A->TP().detId<
CSCDetId>().
station() <<
", CSC_ID " <<
A->TP().getCSCData().cscID
503 <<
", sector index " <<
A->SectorIndex() <<
", subsector " <<
A->Sub()
504 <<
", wire " <<
A->Wire() <<
", strip " <<
A->Strip() <<
", BX " <<
A->TP().getCSCData().bx - 6
505 <<
", neighbor " <<
A->IsNeighbor() <<
" has no match" << std::endl;
506 for (uint iHit = 0; iHit < OutputHits->size(); iHit++)
507 LogTrace(
"L1TMuonEndCapTrackProducer") <<
"!@#$ Option " << iHit+1 <<
" with endcap " << OutputHits->at(iHit).Endcap()
508 <<
", station " << OutputHits->at(iHit).Station() <<
", CSC_ID " << OutputHits->at(iHit).CSC_ID()
509 <<
", ring " << OutputHits->at(iHit).Ring() <<
", chamber " << OutputHits->at(iHit).Chamber()
510 <<
", wire " << OutputHits->at(iHit).Wire() <<
", strip " << OutputHits->at(iHit).Strip()
511 <<
", BX " << OutputHits->at(iHit).BX() <<
", neighbor " << OutputHits->at(iHit).Neighbor() << std::endl;
524 int id =
A->TP().getCSCData().cscID;
525 int trknm =
A->TP().getCSCData().trknmb;
527 phis[station-1] =
A->Phi();
530 if(
A->TP().getCSCData().bx < ebx){
532 ebx =
A->TP().getCSCData().bx;
534 else if(
A->TP().getCSCData().bx < sebx){
535 sebx =
A->TP().getCSCData().bx;
539 ps.push_back(
A->Phi());
540 ts.push_back(
A->Theta());
542 sector =
A->SectorIndex();
545 case 1: mode_uncorr |= 8;
break;
546 case 2: mode_uncorr |= 4;
break;
547 case 3: mode_uncorr |= 2;
break;
548 case 4: mode_uncorr |= 1;
break;
549 default: mode_uncorr |= 0;
556 if(station == 1 &&
id > 3 &&
id < 7){
564 me1address += 3*(sub - 1);
566 me1address |= trknm-1;
570 if(station == 2 &&
id > 3){
574 me2address = me2address<<1;
575 me2address |= trknm-1;
591 if ( ( mode == 15 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
592 ( mode == 14 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 0) ) ||
593 ( mode == 13 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 0 || eHits_in_station[3] != 1) ) ||
594 ( mode == 11 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 0 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
595 ( mode == 7 && (eHits_in_station[0] != 0 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) )
596 LogTrace(
"L1TMuonEndCapTrackProducer") <<
"Mode " << mode <<
" track has " << eHits_in_station[0] <<
" / " << eHits_in_station[1] <<
" / " 597 << eHits_in_station[2] <<
" / " << eHits_in_station[3] <<
" EMTF hits in stations 1 / 2 / 3 / 4" << std::endl;
601 tempTrack.
deltas = AllTracks[fbest].deltas;
608 unsigned long xmlpt_address = ptAssignment_.calculateAddress(tempTrack, es, mode);
609 float xmlpt = ptAssignment_.calculatePt(xmlpt_address);
611 tempTrack.
pt = xmlpt*1.4;
614 CombAddress = (me2address<<4) | me1address;
619 charge,mode,CombAddress,sector);
635 thisTrack.
set_pt ( xmlpt*1.4 );
638 thisTrack.
set_charge ( (charge == 1) ? -1 : 1 );
653 std::pair<int,l1t::RegionalMuonCand> outPair(sebx,outCand);
666 holder.push_back(outPair);
669 OutputTracks->push_back( thisTrack );
674 OutputCands->setBXRange(-2,2);
676 for(
int sect=0;sect<12;sect++){
678 for(
unsigned int h=0;
h<holder.size();
h++){
680 int bx = holder[
h].first - 6;
681 int sector = holder[
h].second.processor();
682 if(holder[
h].
second.trackFinderType() == 3)
686 OutputCands->push_back(bx,holder[
h].
second);
std::vector< EMTFHitExtra > EMTFHitExtraCollection
void set_pt_GMT(int bits)
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
void set_neighbor(int bits)
T getUntrackedParameter(std::string const &, T const &) const
void set_phi_GMT(int bits)
float Phi_loc_rad() const
void SetCSCLCTDigi(CSCCorrelatedLCTDigi digi)
void set_quality(int bits)
void set_phi_loc_int(int bits)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void set_sector(int bits)
L1TMuonEndCapTrackProducer(const PSet &)
edm::ESHandle< RPCGeometry > _geom_rpc
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
float calc_phi_glob_rad_hit(float loc, int sect_ind)
float Phi_loc_deg() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
float calc_phi_loc_rad(int bits)
float calc_theta_deg_from_int(int _theta_int)
#define DEFINE_FWK_MODULE(type)
void set_charge_GMT(int bits)
void set_charge(int bits)
DeltaOutArr3 CalcDeltas_Hold(const std::vector< MatchingOutput > &Mout)
Geom::Theta< T > theta() const
void setType(unsigned type)
std::vector< int > thetas
void set_pt_LUT_addr(unsigned long bits)
int calc_sector_GMT(int _sector)
std::vector< PatternOutput > Patterns(std::vector< ZonesOutput > Zones)
U second(std::pair< T, U > const &p)
const int hwQual() const
Get quality code.
int calc_sector_from_index(int index)
unsigned long long _geom_cache_id
void addStub(const TriggerPrimitive &stub)
std::vector< SortingOutput > SortSect_Hold(std::vector< PatternOutput > Pout)
void ImportPtLUT(int _mode, unsigned long _address)
CSCCorrelatedLCTDigi CreateCSCCorrelatedLCTDigi()
float calc_phi_loc_deg(int bits)
float calc_eta_from_theta_rad(float _theta_rad)
void get(HolderT &iHolder) const
void set_sector_index(int bits)
void set_all_neighbor(int bits)
void produce(edm::Event &, const edm::EventSetup &)
l1t::RegionalMuonCand MakeRegionalCand(float pt, int phi, int theta, int sign, int mode, int trackaddress, int sector)
std::vector< std::vector< int > > deltas
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
int getCharge(int phi1, int phi2, int phi3, int phi4, int mode)
float calc_theta_rad_from_int(int _theta_int)
std::vector< MatchingOutput > PhiMatching_Hold(std::vector< SortingOutput > Sout)
void set_phi_glob_rad(float val)
void set_eta_GMT(int bits)
void ImportCSCDetId(const CSCDetId &_detId)
void set_has_neighbor(int bits)
unsigned long Pt_LUT_addr() const
float calc_phi_glob_rad(float loc, int sect)
int triggerSector() const
void set_endcap(int bits)
float calc_phi_glob_deg_hit(float loc, int sect_ind)
void set_phi_loc_rad(float val)
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
std::vector< std::vector< BTrack > > BestTracks_Hold(DeltaOutArr3 Dout)
void set_sector_GMT(int bits)
int phi
TEMPORARY ADDITION by G. Brown ///.
std::vector< std::vector< ConvertedHit > > GroupBX(std::vector< ConvertedHit > ConvHits)
float calc_phi_glob_deg(float loc, int sect)
void set_phi_loc_deg(float val)
std::vector< ZonesOutput > Zones(std::vector< std::vector< ConvertedHit >> Hits)
Int_t triggerSector(Int_t station, Int_t ring, Int_t chamber) const
void set_phi_glob_deg(float val)