Skip to content

Commit

Permalink
Merge pull request cms-sw#49 from dtp2-tpg-am/otherBranch
Browse files Browse the repository at this point in the history
Several evaluations done and it works fine, able to merge.
  • Loading branch information
jaimeleonh authored Jul 8, 2019
2 parents 99d90be + 204a35f commit a05f922
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 42 deletions.
3 changes: 2 additions & 1 deletion L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void endRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) override;
// RPC
bool useRPC;
GlobalPoint getRPCGlobalPosition(RPCDetId rpcId, const RPCRecHit& rpcIt) const;

void assignIndex(std::vector<metaPrimitive> &inMPaths);
int assignQualityOrder(metaPrimitive mP);
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MPQualityEnhancerFilter : public MPFilter {
private:
// Private methods
void filterCousins(std::vector<metaPrimitive> &inMPath, std::vector<metaPrimitive> &outMPath);
void refilteringCousins(std::vector<metaPrimitive> &inMPath, std::vector<metaPrimitive> &outMPath);
void filterTanPhi(std::vector<metaPrimitive> &inMPath, std::vector<metaPrimitive> &outMPath);
void filterUnique(std::vector<metaPrimitive> &inMPath, std::vector<metaPrimitive> &outMPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
chi2corTh = cms.untracked.double(0.1), #in cm^2
do_correlation = cms.untracked.bool(True),
dT0_correlate_TP = cms.untracked.double(25.),
minx_match_2digis = cms.untracked.double(2.1),
#minx_match_2digis = cms.untracked.double(2.1),
minx_match_2digis = cms.untracked.double(1.),
p2_df = cms.untracked.int32(2), #0 for phase-1, 1 for slice-test, 2 for phase-2 carlo-federica
filter_cousins = cms.untracked.bool(True),
apply_txt_ttrig_bc0 = cms.untracked.bool(False),
Expand Down
81 changes: 51 additions & 30 deletions L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,40 +346,13 @@ void DTTrigPhase2Prod::produce(Event & iEvent, const EventSetup& iEventSetup){

vector<L1Phase2MuDTPhDigi> outP2Ph;

// First we asociate a new index to the metaprimitive depending on quality or phiB;
uint32_t rawId = -1;
int numP = -1;
for (auto metaPrimitiveIt = correlatedMetaPrimitives.begin(); metaPrimitiveIt != correlatedMetaPrimitives.end(); ++metaPrimitiveIt){
numP++;
rawId = (*metaPrimitiveIt).rawId;

int inf = 0;
int numP2 = -1;
for (auto metaPrimitiveItN = correlatedMetaPrimitives.begin(); metaPrimitiveItN != correlatedMetaPrimitives.end(); ++metaPrimitiveItN){
numP2++;
if (rawId != (*metaPrimitiveItN).rawId) continue;
if (numP2 == numP) {
(*metaPrimitiveIt).index = inf;
break;
} else if ((*metaPrimitiveIt).quality < (*metaPrimitiveItN).quality) {
inf++;
} else if ((*metaPrimitiveIt).quality > (*metaPrimitiveItN).quality) {
(*metaPrimitiveItN).index++;
} else if ((*metaPrimitiveIt).quality == (*metaPrimitiveItN).quality) {
if (fabs((*metaPrimitiveIt).phiB) >= fabs((*metaPrimitiveItN).phiB) ){
inf++;
} else if (fabs((*metaPrimitiveIt).phiB) < fabs((*metaPrimitiveItN).phiB) ){
(*metaPrimitiveItN).index++;
}
}
}

}
// Assigning index value

assignIndex(correlatedMetaPrimitives);

for (auto metaPrimitiveIt = correlatedMetaPrimitives.begin(); metaPrimitiveIt != correlatedMetaPrimitives.end(); ++metaPrimitiveIt){
DTChamberId chId((*metaPrimitiveIt).rawId);
if(debug) std::cout<<"looping in final vector: SuperLayerId"<<chId<<" x="<<(*metaPrimitiveIt).x<<" quality="<<(*metaPrimitiveIt).quality << " chi2="<< (*metaPrimitiveIt).chi2 <<std::endl;
if(debug) std::cout<<"looping in final vector: SuperLayerId"<<chId<<" x="<<(*metaPrimitiveIt).x<<" quality="<<(*metaPrimitiveIt).quality << " chi2="<< (*metaPrimitiveIt).chi2 << " index=" << (*metaPrimitiveIt).index <<std::endl;

int sectorTP=chId.sector();
if(sectorTP==13) sectorTP=4;
Expand Down Expand Up @@ -566,3 +539,51 @@ GlobalPoint DTTrigPhase2Prod::getRPCGlobalPosition(RPCDetId rpcId, const RPCRecH

}

void DTTrigPhase2Prod::assignIndex(std::vector<metaPrimitive> &inMPaths)
{
// First we asociate a new index to the metaprimitive depending on quality or phiB;
uint32_t rawId = -1;
int numP = -1;
for (auto metaPrimitiveIt = inMPaths.begin(); metaPrimitiveIt != inMPaths.end(); ++metaPrimitiveIt){
numP++;
rawId = (*metaPrimitiveIt).rawId;
int iOrder = assignQualityOrder((*metaPrimitiveIt));
int inf = 0;
int numP2 = -1;
for (auto metaPrimitiveItN = inMPaths.begin(); metaPrimitiveItN != inMPaths.end(); ++metaPrimitiveItN){
int nOrder = assignQualityOrder((*metaPrimitiveItN));
numP2++;
if (rawId != (*metaPrimitiveItN).rawId) continue;
if (numP2 == numP) {
(*metaPrimitiveIt).index = inf;
break;
} else if (iOrder < nOrder) {
inf++;
} else if (iOrder > nOrder) {
(*metaPrimitiveItN).index++;
} else if (iOrder == nOrder) {
if (fabs((*metaPrimitiveIt).phiB) >= fabs((*metaPrimitiveItN).phiB) ){
inf++;
} else if (fabs((*metaPrimitiveIt).phiB) < fabs((*metaPrimitiveItN).phiB) ){
(*metaPrimitiveItN).index++;
}
}
} // ending second for
} // ending first for
}

int DTTrigPhase2Prod::assignQualityOrder(metaPrimitive mP)
{
if (mP.quality == 9) return 9;
if (mP.quality == 8) return 8;
if (mP.quality == 7) return 6;
if (mP.quality == 6) return 7;
if (mP.quality == 5) return 3;
if (mP.quality == 4) return 5;
if (mP.quality == 3) return 4;
if (mP.quality == 2) return 2;
if (mP.quality == 1) return 1;
return -1;
}


103 changes: 94 additions & 9 deletions L1Trigger/DTPhase2Trigger/src/MPQualityEnhancerFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,25 @@ void MPQualityEnhancerFilter::run(edm::Event& iEvent, const edm::EventSetup& iEv
if (debug) cout <<"MPQualityEnhancerFilter: run" << endl;

std::vector<metaPrimitive> buff;
std::vector<metaPrimitive> buff2;

filterCousins(inMPaths,buff);
if (debug){ cout <<"Ended Cousins Filter. The final primitives before UniqueFilter are: " << endl;
if (debug){ cout <<"Ended Cousins Filter. The final primitives before Refiltering are: " << endl;
//if (debug){ cout <<"Ended Cousins Filter. The final primitives before UniqueFilter are: " << endl;
for (unsigned int i=0; i<buff.size(); i++){
printmP(buff[i]);cout<<endl;
}
cout << "Total Primitives = " << buff.size()<< endl;
}
filterUnique(buff,outMPaths);
refilteringCousins(buff,buff2);
if (debug){ cout <<"Ended Cousins Refilter. The final primitives before UniqueFilter are: " << endl;
for (unsigned int i=0; i<buff2.size(); i++){
printmP(buff2[i]);cout<<endl;
}
cout << "Total Primitives = " << buff2.size()<< endl;
}
filterUnique(buff2,outMPaths);
// filterUnique(buff,outMPaths);

if (debug){ cout <<"Ended Unique Filter. The final primitives are: " << endl;
for (unsigned int i=0; i<outMPaths.size(); i++){
Expand All @@ -58,6 +68,8 @@ void MPQualityEnhancerFilter::run(edm::Event& iEvent, const edm::EventSetup& iEv

buff.clear();
buff.erase(buff.begin(),buff.end());
buff2.clear();
buff2.erase(buff2.begin(),buff2.end());

if (debug) cout <<"MPQualityEnhancerFilter: done" << endl;
}
Expand Down Expand Up @@ -173,13 +185,29 @@ void MPQualityEnhancerFilter::filterCousins(std::vector<metaPrimitive> &inMPaths
outMPaths.push_back(inMPaths[0]);
if(debug)std::cout<<"filtering: kept0 i="<<0<<std::endl;
}
else {
else if (inMPaths.size() > 1) {
for(int i=0; i<int(inMPaths.size()); i++){
if(debug){
std::cout<<"filtering:";
printmP(inMPaths[i]);
std::cout<<" \t is:"<<i<<" "<<primo_index<<" "<<" "<<oneof4<<std::endl;
}
if (areCousins(inMPaths[i],inMPaths[i-primo_index])==0) {
if (oneof4) {
outMPaths.push_back(inMPaths[bestI]);

if(debug)std::cout<<"filtering: kept4 i="<<bestI<<std::endl;
bestI = -1; bestChi2 = 9999; oneof4=false;
} else {
for (int j = i-primo_index; j<i; j++){
outMPaths.push_back(inMPaths[j]);
if(debug)std::cout<<"filtering: kept3 i="<<j<<std::endl;
}
}
i--;
primo_index = 0;
continue;
}
if(rango(inMPaths[i])==4){
oneof4=true;
if (bestChi2 > inMPaths[i].chi2){
Expand All @@ -189,25 +217,82 @@ void MPQualityEnhancerFilter::filterCousins(std::vector<metaPrimitive> &inMPaths
}
if (areCousins(inMPaths[i],inMPaths[i+1])!=0) {
primo_index++;
} else {
} else if (areCousins(inMPaths[i],inMPaths[i+1])==0){
if (oneof4) {
outMPaths.push_back(inMPaths[bestI]);
if(debug)std::cout<<"filtering: kept4 i="<<bestI<<std::endl;
bestI = -1; bestChi2 = 9999; oneof4=false;
outMPaths.push_back(inMPaths[bestI]);

if(debug)std::cout<<"filtering: kept4 i="<<bestI<<std::endl;
bestI = -1; bestChi2 = 9999; oneof4=false;
} else {
for (int j = i-primo_index; j<=i; j++){
outMPaths.push_back(inMPaths[j]);
if(debug)std::cout<<"filtering: kept3 i="<<j<<std::endl;
}
}
primo_index = 0;
}
primo_index = 0;
}
}
}


} //End filterCousins

void MPQualityEnhancerFilter::refilteringCousins(std::vector<metaPrimitive> &inMPaths,
std::vector<metaPrimitive> &outMPaths)
{
int bestI = -1;
double bestChi2 = 9999;
bool oneOf4 = false;
bool enter = true;
if (inMPaths.size()>1){
for (int i = 0; i<(int)inMPaths.size(); i++){
enter = true;
if (rango(inMPaths[i])==4) {
oneOf4 = true;
bestI = i;
bestChi2 = inMPaths[i].chi2;
}
//for (int j = 0; j<(int)inMPaths.size(); j++){
for (int j = i+1; j<(int)inMPaths.size(); j++){
if (areCousins(inMPaths[i],inMPaths[j])==0){ //they arent cousins
//cout << "mp"; printmP(inMPaths[i]); cout<< " is not cousin from mp"; printmP(inMPaths[j]); cout << endl;
enter = false; // We dont want to save them two times
if (oneOf4 == false){
//cout << "kept3 mp" << i << endl; ;
outMPaths.push_back(inMPaths[i]);
} else {
outMPaths.push_back(inMPaths[bestI]);
//cout << "kept4 mp" << bestI << endl;
bestI = -1;
bestChi2 = 9999;
oneOf4 = false;
i = j -1;
}
break;
} else { //they are cousins
if (rango(inMPaths[j])==4) {
if (oneOf4 == true) {
if (bestChi2 > inMPaths[j].chi2) {
bestI = j;
bestChi2 = inMPaths[j].chi2;
}
} else { // if rango of j is 4 and this MP has no rango 4, I will not accept this rango 3 mp
enter = false; break;
}
} // if range of j is not 4, I do not do anything until I get a rango 4 or a no-primo-mp
}
}
if (enter == true) outMPaths.push_back(inMPaths[i]);
}
} else if (inMPaths.size() == 1) {
outMPaths.push_back(inMPaths[0]);
}


}





void MPQualityEnhancerFilter::filterUnique(std::vector<metaPrimitive> &inMPaths,
Expand Down
2 changes: 1 addition & 1 deletion L1Trigger/DTPhase2Trigger/src/MuonPathAnalyzerPerSL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void MuonPathAnalyzerPerSL::buildLateralities(void) {
*/
bool MuonPathAnalyzerPerSL::isStraightPath(LATERAL_CASES sideComb[4]) {

//return true; //trying with all lateralities to be confirmed
return true; //trying with all lateralities to be confirmed

int i, ajustedLayout[4], pairDiff[3], desfase[3];

Expand Down

0 comments on commit a05f922

Please sign in to comment.