12 #define NUM_SECTORS 12
16 #include "L1Trigger/CSCTrackFinder/test/src/RefTrack.h"
37 using namespace L1TMuon;
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");
78 std::vector<TriggerPrimitive> tester;
79 std::vector<TriggerPrimitive> tester_rpc;
99 std::vector<TriggerPrimitive>
out;
100 std::vector<TriggerPrimitive> out_rpc;
103 auto chend = MDC->end();
105 auto digi = (*chamber).second.first;
106 auto dend = (*chamber).second.second;
107 for( ; digi != dend; ++digi ) {
116 OutputHits->push_back( thisHit );
117 if ( ((thisHit.
Ring() != 1 || thisHit.
Station() == 1) && (thisHit.
Chamber() % 6 == 2)) ||
121 OutputHits->push_back( neighborHit );
126 auto rchamber = RDC->begin();
127 auto rchend = RDC->end();
128 for( ; rchamber != rchend; ++rchamber) {
129 auto rdigi = (*rchamber).second.first;
130 auto rdend = (*rchamber).second.second;
131 for( ; rdigi != rdend; ++rdigi) {
132 out_rpc.push_back(
TriggerPrimitive( (*rchamber).first, rdigi->strip(), 0, rdigi->bx()));
146 auto tp = out_rpc.cbegin();
147 auto tpend = out_rpc.cend();
149 for( ; tp != tpend; ++tp ) {
150 if (tp->subsystem() == 2) tester_rpc.push_back(*tp);
154 for(
unsigned int i1=0;i1<out.size();i1++){
155 tester.push_back(out[i1]);
157 for(
unsigned int i2=i1+1;i2<out.size();i2++){
158 if ( out[i1].detId<CSCDetId>().station() == out[i2].detId<
CSCDetId>().
station() &&
163 out[i1].getBX() == out[i2].getBX() && out[i1].Id() == out[i2].Id() &&
164 out[i1].getStrip() != out[i2].getStrip() && out[i1].getWire() != out[i2].getWire() ) {
168 tester.push_back(NewWire1);
169 tester.push_back(NewWire2);
174 uint nHits = OutputHits->size();
175 for (uint iHit = 0; iHit < nHits; iHit++) {
176 for (uint jHit = iHit+1; jHit < nHits; jHit++) {
177 if ( OutputHits->at(iHit).Chamber() != OutputHits->at(jHit).Chamber() )
continue;
178 if ( (OutputHits->at(iHit).Ring() % 3) != (OutputHits->at(jHit).Ring() % 3) )
continue;
179 if ( OutputHits->at(iHit).Sector() != OutputHits->at(jHit).Sector() )
continue;
180 if ( OutputHits->at(iHit).Station() != OutputHits->at(jHit).Station() )
continue;
181 if ( OutputHits->at(iHit).Endcap() != OutputHits->at(jHit).Endcap() )
continue;
182 if ( OutputHits->at(iHit).BX() != OutputHits->at(jHit).BX() )
continue;
183 if ( OutputHits->at(iHit).Neighbor() != OutputHits->at(jHit).Neighbor() )
continue;
184 if ( OutputHits->at(iHit).Strip() == OutputHits->at(jHit).Strip() )
continue;
185 if ( OutputHits->at(iHit).Wire() == OutputHits->at(jHit).Wire() )
continue;
189 new_hit_1.
set_wire( OutputHits->at(jHit).Wire() );
190 new_hit_2.
set_wire( OutputHits->at(iHit).Wire() );
193 OutputHits->push_back( new_hit_1 );
194 OutputHits->push_back( new_hit_2 );
201 for(
int SectIndex=0;SectIndex<
NUM_SECTORS;SectIndex++){
207 std::vector<ConvertedHit> ConvHits = primConv_.convert(tester,SectIndex);
208 CHits[SectIndex] = ConvHits;
211 for (uint iHit = 0; iHit < tmp_hits_rpc.size(); iHit++)
212 OutputHitsRPC->push_back( tmp_hits_rpc.at(iHit) );
213 std::vector<ConvertedHit> ConvHitsRPC = primConvRPC_.fillConvHits(tmp_hits_rpc);
216 for (uint iCHit = 0; iCHit < ConvHits.size(); iCHit++) {
219 for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
220 if ( ConvHits.at(iCHit).Station() == OutputHits->at(iHit).Station() &&
221 ( ConvHits.at(iCHit).Id() == OutputHits->at(iHit).CSC_ID() ||
222 ConvHits.at(iCHit).Id() == ( (OutputHits->at(iHit).Ring() != 4)
223 ? OutputHits->at(iHit).CSC_ID()
224 : OutputHits->at(iHit).CSC_ID() + 9 ) ) &&
225 ConvHits.at(iCHit).Wire() == OutputHits->at(iHit).Wire() &&
226 ConvHits.at(iCHit).Strip() == OutputHits->at(iHit).Strip() &&
227 ConvHits.at(iCHit).BX() - 6 == OutputHits->at(iHit).BX() &&
228 ConvHits.at(iCHit).IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
230 OutputHits->at(iHit).set_neighbor ( ConvHits.at(iCHit).IsNeighbor());
231 OutputHits->at(iHit).set_sector_index( ConvHits.at(iCHit).SectorIndex() );
232 OutputHits->at(iHit).set_phi_zone ( ConvHits.at(iCHit).Zhit() );
233 OutputHits->at(iHit).set_phi_hit ( ConvHits.at(iCHit).Ph_hit() );
234 OutputHits->at(iHit).set_zone ( ConvHits.at(iCHit).Phzvl() );
235 OutputHits->at(iHit).set_phi_loc_int ( ConvHits.at(iCHit).Phi() );
236 OutputHits->at(iHit).set_theta_int ( ConvHits.at(iCHit).Theta() );
240 OutputHits->at(iHit).set_phi_loc_deg (
l1t::calc_phi_loc_deg( OutputHits->at(iHit).Phi_loc_int() ) );
241 OutputHits->at(iHit).set_phi_loc_rad (
l1t::calc_phi_loc_rad( OutputHits->at(iHit).Phi_loc_int() ) );
242 OutputHits->at(iHit).set_phi_glob_deg (
l1t::calc_phi_glob_deg_hit( OutputHits->at(iHit).Phi_loc_deg(), OutputHits->at(iHit).Sector_index() ) );
243 OutputHits->at(iHit).set_phi_glob_rad (
l1t::calc_phi_glob_rad_hit( OutputHits->at(iHit).Phi_loc_rad(), OutputHits->at(iHit).Sector_index() ) );
248 OutHits->push_back( OutputHits->at(iHit).CreateEMTFHit() );
293 std::vector<std::vector<ConvertedHit>> GroupedHits =
GroupBX(ConvHits);
300 std::vector<ZonesOutput> Zout =
Zones(GroupedHits);
308 std::vector<PatternOutput> Pout =
Patterns(Zout);
309 std::vector<PatternOutput> Pout_Hold = Pout;
322 std::vector<SortingOutput> Sout_Hold =
SortSect_Hold(Pout_Hold);
350 std::vector<std::vector<BTrack>> Bout_Hold =
BestTracks_Hold(Dout_Hold);
351 for(
int bx=0;bx<3;bx++)
352 PTracks_BX[SectIndex][bx] = Bout_Hold[bx];
363 std::vector<BTrack> AllTracks, AllTracks_PreCancel;
366 for(
int bx=0;bx<3;bx++){
367 for(
int j=0;
j<36;
j++){
372 if(PTracks_BX[
j/3][bx][
j%3].
phi) {
373 AllTracks_PreCancel.push_back(PTracks_BX[
j/3][bx][
j%3]);
374 if (PTracks_BX[j/3][bx][j%3].
theta == 0)
375 std::cout <<
"PTrack_BX theta = 0" << std::endl;
382 for (
unsigned int i1 = 0; i1 < AllTracks_PreCancel.size(); i1++) {
384 int rank1 = AllTracks_PreCancel[i1].winner.Rank();
388 for (
unsigned int i2 = 0; i2 < AllTracks_PreCancel.size(); i2++) {
389 if (i1 == i2)
continue;
390 for (std::vector<ConvertedHit>::iterator A1 = AllTracks_PreCancel[i1].AHits.begin(); A1 != AllTracks_PreCancel[i1].AHits.end(); A1++) {
393 for (std::vector<ConvertedHit>::iterator A2 = AllTracks_PreCancel[i2].AHits.begin(); A2 != AllTracks_PreCancel[i2].AHits.end(); A2++) {
398 C1.bx == C2.bx && C1.strip == C2.strip && C1.keywire == C2.keywire ) {
400 if (AllTracks_PreCancel[i2].winner.Rank() > rank2) {
402 rank2 = AllTracks_PreCancel[i2].winner.Rank();
410 if ( (!dup) || (rank1 > rank2) || (rank1 == rank2 && i1_dup < i2_dup) ) AllTracks.push_back(AllTracks_PreCancel[i1]);
419 std::vector<l1t::RegionalMuonCand> tester1;
420 std::vector<std::pair<int,l1t::RegionalMuonCand>> holder, holder2;
422 for(
unsigned int fbest=0;fbest<AllTracks.size();fbest++){
424 if(AllTracks[fbest].
phi){
428 tempTrack.
phi = AllTracks[fbest].phi;
429 tempTrack.
theta = AllTracks[fbest].theta;
430 tempTrack.
rank = AllTracks[fbest].winner.Rank();
431 tempTrack.
deltas = AllTracks[fbest].deltas;
432 std::vector<int> ps, ts;
434 if (tempTrack.
theta == 0)
std::cout <<
"Track has theta 0" << std::endl;
439 thisTrack.
set_rank ( AllTracks[fbest].winner.Rank() );
441 int tempStraightness = 0;
442 int tempRank = thisTrack.
Rank();
444 tempStraightness |= 4;
446 tempStraightness |= 2;
448 tempStraightness |= 1;
452 if(tempTrack.
rank & 32)
454 if(tempTrack.
rank & 8)
456 if(tempTrack.
rank & 2)
458 if(tempTrack.
rank & 1)
463 int me1address = 0, me2address = 0, CombAddress = 0, mode_uncorr = 0;
464 int ebx = 20, sebx = 20;
465 int phis[4] = {-99,-99,-99,-99};
467 int cHits_in_station[4] = {0,0,0,0};
468 int eHits_in_station[4] = {0,0,0,0};
469 for(std::vector<ConvertedHit>::iterator
A = AllTracks[fbest].AHits.begin();
A != AllTracks[fbest].AHits.end();
A++){
471 if(
A->Phi() != -999){
477 for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
478 if ( (
A->TP().detId<
CSCDetId>().
endcap() == 1) == (OutputHits->at(iHit).Endcap() == 1) &&
481 A->TP().getCSCData().cscID == OutputHits->at(iHit).CSC_ID() &&
482 A->Wire() == OutputHits->at(iHit).Wire() &&
483 A->Strip() == OutputHits->at(iHit).Strip() &&
484 A->TP().getCSCData().bx - 6 == OutputHits->at(iHit).BX() &&
485 A->IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
486 thisHit = OutputHits->at(iHit);
492 eHits_in_station[OutputHits->at(iHit).Station() - 1] += 1;
501 std::cout <<
"!@#$ Converted hit with station " <<
A->TP().detId<
CSCDetId>().
station() <<
", CSC_ID " <<
A->TP().getCSCData().cscID
502 <<
", sector index " <<
A->SectorIndex() <<
", subsector " <<
A->Sub()
503 <<
", wire " <<
A->Wire() <<
", strip " <<
A->Strip() <<
", BX " <<
A->TP().getCSCData().bx - 6
504 <<
", neighbor " <<
A->IsNeighbor() <<
" has no match" << std::endl;
505 for (uint iHit = 0; iHit < OutputHits->size(); iHit++)
506 std::cout <<
"!@#$ Option " << iHit+1 <<
" with endcap " << OutputHits->at(iHit).Endcap()
507 <<
", station " << OutputHits->at(iHit).Station() <<
", CSC_ID " << OutputHits->at(iHit).CSC_ID()
508 <<
", ring " << OutputHits->at(iHit).Ring() <<
", chamber " << OutputHits->at(iHit).Chamber()
509 <<
", wire " << OutputHits->at(iHit).Wire() <<
", strip " << OutputHits->at(iHit).Strip()
510 <<
", BX " << OutputHits->at(iHit).BX() <<
", neighbor " << OutputHits->at(iHit).Neighbor() << std::endl;
523 int id =
A->TP().getCSCData().cscID;
524 int trknm =
A->TP().getCSCData().trknmb;
526 phis[station-1] =
A->Phi();
529 if(
A->TP().getCSCData().bx < ebx){
531 ebx =
A->TP().getCSCData().bx;
533 else if(
A->TP().getCSCData().bx < sebx){
534 sebx =
A->TP().getCSCData().bx;
538 ps.push_back(
A->Phi());
539 ts.push_back(
A->Theta());
541 sector =
A->SectorIndex();
544 case 1: mode_uncorr |= 8;
break;
545 case 2: mode_uncorr |= 4;
break;
546 case 3: mode_uncorr |= 2;
break;
547 case 4: mode_uncorr |= 1;
break;
548 default: mode_uncorr |= 0;
555 if(station == 1 &&
id > 3 &&
id < 7){
563 me1address += 3*(sub - 1);
565 me1address |= trknm-1;
569 if(station == 2 &&
id > 3){
573 me2address = me2address<<1;
574 me2address |= trknm-1;
590 if ( ( mode == 15 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
591 ( mode == 14 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 0) ) ||
592 ( mode == 13 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 0 || eHits_in_station[3] != 1) ) ||
593 ( mode == 11 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 0 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
594 ( mode == 7 && (eHits_in_station[0] != 0 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) )
595 std::cout <<
"Mode " << mode <<
" track has " << eHits_in_station[0] <<
" / " << eHits_in_station[1] <<
" / "
596 << eHits_in_station[2] <<
" / " << eHits_in_station[3] <<
" EMTF hits in stations 1 / 2 / 3 / 4" << std::endl;
600 tempTrack.
deltas = AllTracks[fbest].deltas;
607 unsigned long xmlpt_address = ptAssignment_.calculateAddress(tempTrack, es, mode);
608 float xmlpt = ptAssignment_.calculatePt(xmlpt_address);
610 tempTrack.
pt = xmlpt*1.4;
613 CombAddress = (me2address<<4) | me1address;
618 charge,mode,CombAddress,sector);
634 thisTrack.
set_pt ( xmlpt*1.4 );
637 thisTrack.
set_charge ( (charge == 1) ? -1 : 1 );
652 std::pair<int,l1t::RegionalMuonCand> outPair(sebx,outCand);
665 holder.push_back(outPair);
668 OutputTracks->push_back( thisTrack );
673 OutputCands->setBXRange(-2,2);
675 for(
int sect=0;sect<12;sect++){
677 for(
unsigned int h=0;
h<holder.size();
h++){
679 int bx = holder[
h].first - 6;
680 int sector = holder[
h].second.processor();
681 if(holder[
h].
second.trackFinderType() == 3)
685 OutputCands->push_back(bx,holder[
h].
second);
692 ev.
put( OutputCands,
"EMTF");
693 ev.
put( OutHits,
"");
694 ev.
put( OutTracks,
"");
695 ev.
put( OutputHits,
"CSC");
696 ev.
put( OutputHitsRPC,
"RPC");
697 ev.
put( OutputTracks,
"");
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)
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.
const RPCChamber * chamber(RPCDetId id) const
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)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
float calc_eta_from_theta_rad(float _theta_rad)
std::vector< EMTFHit > EMTFHitCollection
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)
std::vector< EMTFTrack > EMTFTrackCollection
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)
std::vector< EMTFTrackExtra > EMTFTrackExtraCollection
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)