Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turning on ClusterRepair for edge hits only #26263

Merged
merged 10 commits into from Apr 11, 2019
6 changes: 3 additions & 3 deletions Configuration/AlCa/python/autoCond.py
Expand Up @@ -24,11 +24,11 @@
# GlobalTag for MC production (p-Pb collisions) with realistic alignment and calibrations for Run2
'run2_mc_pa' : '105X_mcRun2_pA_v2',
# GlobalTag for Run1 data reprocessing
'run1_data' : '106X_dataRun2_v1',
'run1_data' : '106X_dataRun2_v4',
# GlobalTag for Run2 data reprocessing
'run2_data' : '106X_dataRun2_v1',
'run2_data' : '106X_dataRun2_v4',
# GlobalTag for Run2 data relvals: allows customization to run with fixed L1 menu
'run2_data_relval' : '106X_dataRun2_relval_v1',
'run2_data_relval' : '106X_dataRun2_relval_v2',
# GlobalTag for Run2 data 2018B relvals only: HEM-15-16 fail
'run2_data_promptlike_HEfail' : '106X_dataRun2_PromptLike_HEfail_v1',
# GlobalTag for Run2 data 2016H relvals only: Prompt Conditions + fixed L1 menu (to be removed)
Expand Down
1 change: 1 addition & 0 deletions RecoLocalTracker/SiPixelRecHits/interface/PixelCPEBase.h
Expand Up @@ -76,6 +76,7 @@ class PixelCPEBase : public PixelClusterParameterEstimator
float lorentzShiftInCmX; // a FULL shift, in cm
float lorentzShiftInCmY; // a FULL shift, in cm
int detTemplateId; // det if for templates & generic errors
int detTemplateId2D; // det if for 2D templates
};

struct ClusterParam
Expand Down
Expand Up @@ -87,6 +87,8 @@ class PixelCPEClusterRepair : public PixelCPEBase
SiPixelTemplateReco::ClusMatrix & clusterPayload,
int ID) const;

//Fill IDs for 2D template
void fill2DTemplIDs();



Expand All @@ -104,13 +106,40 @@ class PixelCPEClusterRepair : public PixelCPEBase
int forwardTemplateID_ ;
std::string templateDir_ ;

const SiPixel2DTemplateDBObject * templateDBobject2D_;

// Configure 2D reco.
float minChargeRatio_;
float maxSizeMismatchInY_ ;

//bool DoCosmics_;
//bool LoadTemplatesFromDB_;


// read sub-detectors to recommend 2D
class Rule {
public:
// parse a rule from a string
Rule(const std::string &str) ;
// check this DetId to recommend 2D or not (default false)
bool recommend(DetId detid, const TrackerTopology &tTopo) const {
// check detector
if (detid.subdetId() == subdet_) {
// check layer
if ( (layer_ == 0) || (layer_ == int(tTopo.layer(detid))) ) {
return true;
}
else return false;
}
else return false;
}
private:
int subdet_;
int layer_;
};
std::vector<Rule> recommend2D_;

// run on damaged hits or not
bool runDamagedClusters_;
};

#endif
Expand Down
Expand Up @@ -3,6 +3,8 @@

#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "RecoLocalTracker/Records/interface/TkPixelCPERecord.h"
#include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
#include <memory>
Expand All @@ -11,6 +13,7 @@ class PixelCPEClusterRepairESProducer: public edm::ESProducer{
public:
PixelCPEClusterRepairESProducer(const edm::ParameterSet & p);
~PixelCPEClusterRepairESProducer() override;
static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
std::unique_ptr<PixelClusterParameterEstimator> produce(const TkPixelCPERecord &);
private:
edm::ParameterSet pset_;
Expand Down
Expand Up @@ -37,6 +37,28 @@ PixelCPEClusterRepairESProducer::PixelCPEClusterRepairESProducer(const edm::Para

PixelCPEClusterRepairESProducer::~PixelCPEClusterRepairESProducer() {}

void PixelCPEClusterRepairESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
// templates2
edm::ParameterSetDescription desc;
desc.add<bool>("DoLorentz", true);
desc.add<bool>("DoCosmics", false);
desc.add<bool>("LoadTemplatesFromDB", true);
desc.add<bool>("RunDamagedClusters", false);
desc.add<std::string>("ComponentName", "PixelCPEClusterRepair");
desc.add<double>("MinChargeRatio", 0.8);
desc.add<double>("MaxSizeMismatchInY", 0.3);
desc.add<bool>("Alpha2Order", true);
desc.add<std::vector<std::string>>("Recommend2D", {
"PXB 2",
"PXB 3",
"PXB 4",
});
desc.add<int>("ClusterProbComputationFlag", 0);
desc.add<int>("speed", -2);
desc.add<bool>("UseClusterSplitter", false);
descriptions.add("templates2", desc);
}

std::unique_ptr<PixelClusterParameterEstimator>
PixelCPEClusterRepairESProducer::produce(const TkPixelCPERecord & iRecord){

Expand Down
Expand Up @@ -12,6 +12,11 @@
MaxSizeMismatchInY = cms.double(0.3),
MinChargeRatio = cms.double(0.8),

# layers to run on: (only PXB 2,PXB 3,PXB 4 for now)
Recommend2D = cms.vstring("PXB 2","PXB 3","PXB 4"),

# to run on damaged clusterss or not (default=no)
RunDamagedClusters = cms.bool(False),

# petar, for clusterProbability() from TTRHs
ClusterProbComputationFlag = cms.int32(0),
Expand Down
117 changes: 98 additions & 19 deletions RecoLocalTracker/SiPixelRecHits/src/PixelCPEClusterRepair.cc
Expand Up @@ -15,10 +15,11 @@
// Commented for now (3/10/17) until we figure out how to resuscitate 2D template splitter
/// #include "RecoLocalTracker/SiPixelRecHits/interface/SiPixelTemplateSplit.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <vector>
#include "boost/multi_array.hpp"
#include <boost/regex.hpp>
#include <map>

#include <iostream>

Expand Down Expand Up @@ -59,8 +60,8 @@ PixelCPEClusterRepair::PixelCPEClusterRepair(edm::ParameterSet const & conf,
// Initialize template store to the selected ID [Morris, 6/25/08]
if ( !SiPixelTemplate2D::pushfile( *templateDBobject2D , thePixelTemp2D_) )
throw cms::Exception("PixelCPEClusterRepair")
<< "\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
<< (*templateDBobject_).version() << "\n\n";
<< "\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject2D version "
<< (*templateDBobject2D).version() << "\n\n";
}
else
{
Expand All @@ -80,6 +81,8 @@ PixelCPEClusterRepair::PixelCPEClusterRepair(edm::ParameterSet const & conf,
<< "\nERROR: Template ID " << forwardTemplateID_ << " not loaded correctly from text file. Reconstruction will fail.\n\n";
}

templateDBobject2D_ = templateDBobject2D;
fill2DTemplIDs();
speed_ = conf.getParameter<int>( "speed");
LogDebug("PixelCPEClusterRepair::PixelCPEClusterRepair:") <<
"Template speed = " << speed_ << "\n";
Expand All @@ -91,6 +94,55 @@ PixelCPEClusterRepair::PixelCPEClusterRepair(edm::ParameterSet const & conf,
maxSizeMismatchInY_ = conf.getParameter<double>("MaxSizeMismatchInY");
minChargeRatio_ = conf.getParameter<double>("MinChargeRatio");

// read sub-detectors and apply rule to recommend 2D
// can be:
// XYX (XYZ = PXB, PXE)
// XYZ n (XYZ as above, n = layer, wheel or disk = 1 .. 6 ;)
std::vector<std::string> str_recommend2D = conf.getParameter<std::vector<std::string> >("Recommend2D");
recommend2D_.reserve(str_recommend2D.size());
for (unsigned int i=0; i<str_recommend2D.size();++i){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I had in mind was something as

   for (auto & str: str_recommend2D){
     recommend2D_.push_back(str);
   }

recommend2D_.push_back(Rule(str_recommend2D.at(i)));
}

// run CR on damaged clusters (and not only on edge hits)
runDamagedClusters_ = conf.getParameter<bool>("RunDamagedClusters");
}

//-----------------------------------------------------------------------------
// Fill all 2D template IDs
//-----------------------------------------------------------------------------
void PixelCPEClusterRepair::fill2DTemplIDs()
{
auto const & dus = geom_.detUnits();
unsigned m_detectors = dus.size();
for(unsigned int i=1;i<7;++i) {
LogDebug("PixelCPEClusterRepair:: LookingForFirstStrip") << "Subdetector " << i
<< " GeomDetEnumerator " << GeomDetEnumerators::tkDetEnum[i]
<< " offset " << geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])
<< " is it strip? " << (geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) != dus.size() ?
dus[geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])]->type().isTrackerStrip() : false);
if(geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) != dus.size() &&
dus[geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])]->type().isTrackerStrip()) {
if(geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) < m_detectors) m_detectors = geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]);
}
}
LogDebug("LookingForFirstStrip") << " Chosen offset: " << m_detectors;


m_DetParams.resize(m_detectors);
LogDebug("PixelCPEClusterRepair::fillDetParams():") <<"caching "<<m_detectors<<" pixel detectors"<<endl;
//Loop through detectors and store 2D template ID
bool printed_info = false;
for (unsigned i=0; i!=m_detectors;++i) {
auto & p=m_DetParams[i];

p.detTemplateId2D = templateDBobject2D_->getTemplateID(p.theDet->geographicalId());
if(p.detTemplateId != p.detTemplateId2D && !printed_info){
edm::LogWarning("PixelCPEClusterRepair") << "different template ID between 1D and 2D " << p.detTemplateId << " " << p.detTemplateId2D << endl;
printed_info = true;
}
}

}


Expand Down Expand Up @@ -130,18 +182,17 @@ PixelCPEClusterRepair::localPosition(DetParam const & theDetParam, ClusterParam
<< "A non-pixel detector type in here?";


int ID = -9999;
int ID1 = -9999;
int ID2 = -9999;
if ( LoadTemplatesFromDB_ ) {
int ID0 = templateDBobject_->getTemplateID(theDetParam.theDet->geographicalId()); // just to comapre
ID = theDetParam.detTemplateId;
if(ID0!=ID) edm::LogError("PixelCPEClusterRepair") <<" different id"<< ID<<" "<<ID0<<endl;
ID1 = theDetParam.detTemplateId;
ID2 = theDetParam.detTemplateId2D;
} else { // from asci file
if ( ! GeomDetEnumerators::isEndcap(theDetParam.thePart) )
ID = barrelTemplateID_ ; // barrel
ID1 = ID2 = barrelTemplateID_ ; // barrel
else
ID = forwardTemplateID_ ; // forward
ID1 = ID2 = forwardTemplateID_ ; // forward
}
//cout << "PixelCPEClusterRepair : ID = " << ID << endl;

// &&& PM, note for later: PixelCPEBase calculates minInX,Y, and maxInX,Y
// Why can't we simply use that and save time with row_offset, col_offset
Expand Down Expand Up @@ -232,15 +283,15 @@ PixelCPEClusterRepair::localPosition(DetParam const & theDetParam, ClusterParam


//--- Should we run the 2D reco?
checkRecommend2D(theDetParam, theClusterParam, clusterPayload, ID);
checkRecommend2D(theDetParam, theClusterParam, clusterPayload, ID1);
if ( theClusterParam.recommended2D_ ) {
//--- Call the Template Reco 2d with cluster repair
filled_from_2d = true;
callTempReco2D( theDetParam, theClusterParam, clusterPayload2d, ID, lp );
callTempReco2D( theDetParam, theClusterParam, clusterPayload2d, ID2, lp );
}
else {
//--- Call the vanilla Template Reco
callTempReco1D( theDetParam, theClusterParam, clusterPayload, ID, lp );
callTempReco1D( theDetParam, theClusterParam, clusterPayload, ID1, lp );
filled_from_2d = false;
}

Expand Down Expand Up @@ -492,10 +543,15 @@ void PixelCPEClusterRepair::checkRecommend2D( DetParam const & theDetParam, Clus
{

DetId id = (theDetParam.theDet->geographicalId());
bool isBarrel = GeomDetEnumerators::isBarrel(theDetParam.thePart);
int layer=ttopo_.layer(id);
if(!isBarrel){
//only run on barrel

bool recommend = false;
for (unsigned int i=0; i<recommend2D_.size(); i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I had in mind was something as

   for (auto & rec: recommend2D_){
        recommend = rec.recommend(id, ttopo_);
	if(recommend) break;
    }

recommend = recommend2D_.at(i).recommend(id, ttopo_);
if(recommend) break;
}

// only run on those layers recommended by configuration
if(!recommend) {
theClusterParam.recommended2D_ = false;
return;
}
Expand Down Expand Up @@ -534,8 +590,10 @@ void PixelCPEClusterRepair::checkRecommend2D( DetParam const & theDetParam, Clus
theClusterParam.recommended2D_ = true;
theClusterParam.hasBadPixels_ = true;

//for now, don't try to fix any clusters in layer 1
if( layer == 1 ) theClusterParam.recommended2D_ = false;
// if not RunDamagedClusters flag, don't try to fix any clusters
if(!runDamagedClusters_) {
theClusterParam.recommended2D_ = false;
}

// Figure out what edge flags to set for truncated cluster
// Truncated clusters usually come from dead double columns
Expand Down Expand Up @@ -644,3 +702,24 @@ PixelCPEClusterRepair::localError(DetParam const & theDetParam, ClusterParam &
return LocalError(xerr*xerr, 0, yerr*yerr);
}

PixelCPEClusterRepair::Rule::Rule(const std::string &str) {
static const boost::regex rule("([A-Z]+)(\\s+(\\d+))?");
boost::cmatch match;
// match and check it works
if (!regex_match(str.c_str(), match, rule))
throw cms::Exception("Configuration") << "Rule '" << str << "' not understood.\n";

// subdet
subdet_ = -1;
if (strncmp(match[1].first, "PXB", 3) == 0) subdet_ = PixelSubdetector::PixelBarrel;
else if (strncmp(match[1].first, "PXE", 3) == 0) subdet_ = PixelSubdetector::PixelEndcap;
if (subdet_ == -1) {
throw cms::Exception("PixelCPEClusterRepair::Configuration") << "Detector '" << match[1].first << "' not understood. Should be PXB, PXE.\n";
}
// layer (if present)
if (match[3].first != match[3].second) {
layer_ = atoi(match[3].first);
} else {
layer_ = 0;
}
}//end Rule::Rule
Expand Up @@ -12,6 +12,6 @@
trackingPhase2PU140.toModify(TTRHBuilderAngleAndTemplate, Phase2StripCPE = cms.string('Phase2StripCPE'))

# uncomment these two lines to turn on Cluster Repair CPE
# from Configuration.Eras.Modifier_phase1Pixel_cff import phase1Pixel
# phase1Pixel.toModify(TTRHBuilderAngleAndTemplate, PixelCPE = cms.string('PixelCPEClusterRepair'))
from Configuration.Eras.Modifier_phase1Pixel_cff import phase1Pixel
phase1Pixel.toModify(TTRHBuilderAngleAndTemplate, PixelCPE = cms.string('PixelCPEClusterRepair'))