Skip to content

Commit

Permalink
Merge pull request #23302 from usarica/HIPAlignmentAlgorithm940pre2
Browse files Browse the repository at this point in the history
HipPy alignment algorithm improvements
  • Loading branch information
cmsbuild committed Jul 17, 2018
2 parents 02e93c9 + 11cfd2a commit 1376cca
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 144 deletions.
22 changes: 17 additions & 5 deletions Alignment/CommonAlignment/python/tools/trackselectionRefitting.py
Expand Up @@ -351,11 +351,23 @@ def getSequence(process, collection,
strSrcConstr = module.srcConstr.getModuleLabel()
if strSrcConstr:
procsrcconstr = getattr(process,strSrcConstr)
if procsrcconstr.src != module.src:
module.srcConstr=''
module.constraint=''
else:
moduleSum += procsrcconstr
if hasattr(procsrcconstr,"src"): # Momentum or track parameter constraints
if procsrcconstr.src != module.src:
module.srcConstr=''
module.constraint=''
else:
moduleSum += procsrcconstr # Add constraint
elif hasattr(procsrcconstr,"srcTrk"): # Vertex constraint
if procsrcconstr.srcTrk != module.src:
module.srcConstr=''
module.constraint=''
else:
procsrcconstrsrcvtx = getattr(process,procsrcconstr.srcVtx.getModuleLabel())
if type(procsrcconstrsrcvtx) is cms.EDFilter: # If source of vertices is itself a filter (e.g. good PVs)
procsrcconstrsrcvtxprefilter = getattr(process,procsrcconstrsrcvtx.src.getModuleLabel())
moduleSum += procsrcconstrsrcvtxprefilter # Add vertex source to constraint before filter
moduleSum += procsrcconstrsrcvtx # Add vertex source to constraint
moduleSum += procsrcconstr # Add constraint

moduleSum += module # append the other modules

Expand Down
5 changes: 4 additions & 1 deletion Alignment/HIPAlignmentAlgorithm/BuildFile.xml
Expand Up @@ -2,13 +2,16 @@
<use name="FWCore/PluginManager"/>
<use name="FWCore/Utilities"/>
<use name="FWCore/ParameterSet"/>
<use name="CondFormats/Alignment"/>
<use name="TrackingTools/PatternTools"/>
<use name="TrackingTools/TrackFitters"/>
<use name="TrackingTools/TrajectoryState"/>
<use name="TrackingTools/TransientTrack"/>
<use name="RecoVertex/PrimaryVertexProducer"/>
<use name="DataFormats/Alignment"/>
<use name="rootcore"/>
<use name="Alignment/CommonAlignment"/>
<use name="Alignment/CommonAlignmentAlgorithm"/>
<use name="Alignment/TrackerAlignment"/>
<use name="Utilities/General"/>
<use name="rootcore"/>
<flags EDM_PLUGIN="1"/>
Expand Up @@ -150,17 +150,8 @@ class HIPAlignmentAlgorithm : public AlignmentAlgorithmBase{
TFile* theSurveyIORootFile;
TTree* theSurveyTree; // survey tree

// variables for event-wise tree
int m_Ntracks;
std::vector<int> m_Nhits, m_nhPXB, m_nhPXF, m_nhTIB, m_nhTOB, m_nhTID, m_nhTEC;
std::vector<float> m_Pt, m_Eta, m_Phi, m_Chi2n, m_P, m_d0, m_dz, m_wt;

// variables for hit-wise tree
bool m_hasHitProb;
float m_sinTheta, m_hitwt, m_angle, m_probXY, m_probQ;
unsigned int m_rawQualityWord;
// common variables for monitor trees
int m_datatype;
align::ID m_detId;

// variables for alignable-wise tree
align::ID m2_Id;
Expand Down
87 changes: 86 additions & 1 deletion Alignment/HIPAlignmentAlgorithm/interface/HIPMonitorConfig.h
Expand Up @@ -3,18 +3,103 @@

#include <vector>
#include <string>
#include "TTree.h"
#include <FWCore/ParameterSet/interface/ParameterSet.h>
#include <CondFormats/Alignment/interface/Definitions.h>


class HIPMonitorVariables{
protected:

TTree* tree;

public:

HIPMonitorVariables() : tree(nullptr){}
virtual ~HIPMonitorVariables(){}

void setTree(TTree* tree_){ tree=tree_; }
virtual void bookBranches()=0;
virtual void fill()=0;

};
class HIPTrackMonitorVariables : public HIPMonitorVariables{
public:

const int maxNEvents;
const int maxTracksRcd;
int nEvents;
int nTracks;
int m_Ntracks;
std::vector<float> m_Pt, m_Eta, m_Phi, m_Chi2n, m_P, m_d0, m_dz, m_wt;
std::vector<int> m_Nhits, m_nhPXB, m_nhPXF, m_nhTIB, m_nhTOB, m_nhTID, m_nhTEC;

HIPTrackMonitorVariables(int maxNEvents_=-1, int maxTracksRcd_=-1) : HIPMonitorVariables(), maxNEvents(maxNEvents_), maxTracksRcd(maxTracksRcd_), nEvents(0), nTracks(0), m_Ntracks(0){}

void bookBranches();
void fill();

protected:

void resetPerEvent(){
// Do not reset nTracks
m_Ntracks=0;
m_Pt.clear(); m_Eta.clear(); m_Phi.clear(); m_Chi2n.clear(); m_P.clear(); m_d0.clear(); m_dz.clear(); m_wt.clear();
m_Nhits.clear(); m_nhPXB.clear(); m_nhPXF.clear(); m_nhTIB.clear(); m_nhTOB.clear(); m_nhTID.clear(); m_nhTEC.clear();
}
void resizeVectors(int NewSize){
m_Pt.resize(NewSize); m_Eta.resize(NewSize); m_Phi.resize(NewSize); m_Chi2n.resize(NewSize); m_P.resize(NewSize); m_d0.resize(NewSize); m_dz.resize(NewSize); m_wt.resize(NewSize);
m_Nhits.resize(NewSize); m_nhPXB.resize(NewSize); m_nhPXF.resize(NewSize); m_nhTIB.resize(NewSize); m_nhTOB.resize(NewSize); m_nhTID.resize(NewSize); m_nhTEC.resize(NewSize);
}

};
class HIPHitMonitorVariables : public HIPMonitorVariables{
public:

const int maxHitsRcd;
int nHits;

bool m_hasHitProb;
float m_sinTheta, m_hitwt, m_angle, m_probXY, m_probQ;
unsigned int m_rawQualityWord;
align::ID m_detId;

protected:

void resetPerHit(){
m_hasHitProb=false;
m_sinTheta=0;
m_hitwt=1;
m_angle=0;
m_probXY=-1;
m_probQ=-1;
m_rawQualityWord=9999;
m_detId=0;
}

public:

HIPHitMonitorVariables(int maxHitsRcd_=-1) : HIPMonitorVariables(), maxHitsRcd(maxHitsRcd_), nHits(0){ resetPerHit(); }

void bookBranches();
void fill();

};

struct HIPMonitorConfig{
const edm::ParameterSet cfgMonitor;

const std::string outfilecore;

const bool fillTrackMonitoring;
const int maxEventsPerJob;

const bool fillTrackMonitoring;
const int maxTracks;
HIPTrackMonitorVariables trackmonitorvars;

const bool fillTrackHitMonitoring;
const int maxHits;
HIPHitMonitorVariables hitmonitorvars;

std::string outfile;

Expand Down
Expand Up @@ -86,8 +86,9 @@

monitorConfig = cms.PSet(
outfile = cms.string('HIPAlignmentEvents.root'),
maxEventsPerJob = cms.int32(-1),
fillTrackMonitoring = cms.bool(False),
maxEventsPerJob = cms.int32(100),
maxTracks = cms.int32(100),
fillTrackHitMonitoring = cms.bool(False),
maxHits = cms.int32(10000), # Not per track, just total
),
Expand Down
Expand Up @@ -147,6 +147,26 @@ def interpretOptions(self):
else:
raise RuntimeError("GT specification {} does not have size==2".format(namespec))
gttogetpsets.append(apset)
# Get hits to drop or keep
elif key=="hitfiltercommands":
vallist=val.split(';')
for iv in range(0,len(vallist)):
keepdrop_det_pair=vallist[iv].split('=')
if len(keepdrop_det_pair)==2:
if (keepdrop_det_pair[0]=="keep" or keepdrop_det_pair[0]=="drop"):
strcmd = keepdrop_det_pair[0]

keepdrop_det_pair[1]=keepdrop_det_pair[1].replace('/',' ') # e.g. 'PIX/2' instead of 'PIX 2'
keepdrop_det_pair[1]=keepdrop_det_pair[1].upper()

strcmd = strcmd + " " + keepdrop_det_pair[1]
if not hasattr(self,"hitfiltercommands"):
self.hitfiltercommands=[]
self.hitfiltercommands.append(strcmd)
else:
raise RuntimeError("Keep/drop command {} is not keep or drop.".format(keepdrop_det_pair[0]))
else:
raise RuntimeError("Keep/drop-det. pair {} does not have size==2 or has a command other than keep or drop.".format(vallist[iv]))
# Get data type
elif (key=="type" or key=="datatype" or key=="datagroup"):
try:
Expand Down Expand Up @@ -175,13 +195,24 @@ def interpretOptions(self):
elif key=="uniformetaformula":
self.uniformetaformula=val
## Options for mMin. bias
# Apply vertex constraint
elif (key=="primaryvertextpye" or key=="pvtype"):
val=val.lower()
if (val=="nobs" or val=="withbs"):
self.PVtype=val
else:
raise ValueError("PV type can only receive NoBS or WithBS.")
elif (key=="primaryvertexconstraint" or key=="pvconstraint"):
self.applyPVConstraint=parseBoolString(val)
if not hasattr(self,"PVtype"):
self.PVtype="nobs"
# Get custom track selection for TBD
elif (key=="twobodytrackselection" or key=="twobodydecayselection" or key=="tbdselection"):
val=val.lower()
if (val=="zsel" or val=="y1sel"):
if (val=="zsel" or val=="y1ssel"):
self.TBDsel=val
else:
raise ValueError("TBD selection can only be Zsel or Y1sel at this time.")
raise ValueError("TBD selection can only be Zsel or Y1Ssel at this time.")
## Get options common in min. bias, Zmumu and Ymumu
# Get TBD constraint type
elif (key=="twobodytrackconstraint" or key=="twobodydecayconstraint" or key=="tbdconstraint"):
Expand Down Expand Up @@ -217,6 +248,10 @@ def interpretOptions(self):


def doCheckOptions(self,optstocheck):
# First check option consistencies overall
if (hasattr(self,"TBDconstraint") and hasattr(self,"applyPVConstraint")):
raise RuntimeError("Options TBDconstraint and applyPVConstraint cannot coexist.")
# Force presence of the options passed
for oc in optstocheck:
if not hasattr(self,oc):
raise RuntimeError("Option {} needs to specified in {}.".format(oc, self.flag))
Expand Down
4 changes: 4 additions & 0 deletions Alignment/HIPAlignmentAlgorithm/python/align_tpl_py.txt
Expand Up @@ -56,6 +56,10 @@ process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(-1))
# "including" selection for this track sample
<SELECTION>

# Override track hit filter commands
if hasattr(optpy, "hitfiltercommands"):
process.TrackerTrackHitFilter.commands = cms.vstring(optpy.hitfiltercommands)

# parameters for HIP
process.AlignmentProducer.tjTkAssociationMapTag = 'FinalTrackRefitter'

Expand Down
@@ -1,6 +1,6 @@
import Alignment.CommonAlignment.tools.trackselectionRefitting as TrackRefitterSequencer

strTBDConstrainer=None
strTrackConstrainer=None
strtbdsel=""
if hasattr(optpy,"TBDsel"):
strtbdsel=optpy.TBDsel
Expand All @@ -17,7 +17,7 @@ if (hasattr(optpy, "TBDconstraint") and strtbdsel!=""):
process.TwoBodyDecayMomConstraint.primaryWidth = cms.double(1.4)
process.TwoBodyDecayMomConstraint.rescaleError = cms.double(1.0)
process.TwoBodyDecayMomConstraint.chi2Cut = cms.double(99999.)
strTBDConstrainer="TwoBodyDecayMomConstraint,momentum"
strTrackConstrainer="TwoBodyDecayMomConstraint,momentum"

elif "fullconstr" in strtbdconstr:
process.load("RecoTracker.TrackProducer.TwoBodyDecayConstraintProducer_cff")
Expand All @@ -30,7 +30,30 @@ if (hasattr(optpy, "TBDconstraint") and strtbdsel!=""):
process.TwoBodyDecayConstraint.primaryWidth = cms.double(1.4)
process.TwoBodyDecayConstraint.rescaleError = cms.double(1.0)
process.TwoBodyDecayConstraint.chi2Cut = cms.double(99999.)
strTBDConstrainer="TwoBodyDecayConstraint,trackParameters"
strTrackConstrainer="TwoBodyDecayConstraint,trackParameters"
elif hasattr(optpy, "applyPVConstraint"):
# Existence of PVtype is guaranteed in the option parser
strpvtype=optpy.PVtype
process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
process.load("RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi")
process.offlinePrimaryVertices.TrackLabel=cms.InputTag("AlignmentTrackSelector")
if strpvtype=="withbs":
process.goodOfflinePrimaryVertices=cms.EDFilter("VertexSelector",
src = cms.InputTag("offlinePrimaryVertices","WithBS"),
cut = cms.string("!isFake && ndof >= 4.0 && abs(z) <= 24.0 && abs(position.Rho) <= 2.0"),
filter = cms.bool(True)
)
else:
process.goodOfflinePrimaryVertices=cms.EDFilter("VertexSelector",
src = cms.InputTag("offlinePrimaryVertices"),
cut = cms.string("!isFake && ndof >= 4.0 && abs(z) <= 24.0 && abs(position.Rho) <= 2.0"),
filter = cms.bool(True)
)
process.load("RecoTracker.TrackProducer.VertexConstraintProducer_cfi")
process.vertexConstraint.srcTrk = "AlignmentTrackSelector"
process.vertexConstraint.srcVtx = "goodOfflinePrimaryVertices"
strTrackConstrainer="vertexConstraint,vertex"


process.TrackRefitterSequence = TrackRefitterSequencer.getSequence(
process,
Expand All @@ -40,12 +63,12 @@ process.TrackRefitterSequence = TrackRefitterSequencer.getSequence(
openMassWindow = False,
cosmicsDecoMode = False,
cosmicsZeroTesla = False,
momentumConstraint = strTBDConstrainer, # Should be a momentum constraint object
momentumConstraint = strTrackConstrainer, # Should be a momentum constraint object
cosmicTrackSplitting = False,
use_d0cut = True
)

if strTBDConstrainer is not None:
if (strTrackConstrainer is not None and strtbdsel!=""):
process.AlignmentTrackSelector.TwoBodyDecaySelector.daughterMass = 0.0 # Causes tiny bias in mass, but should not be very important
if "y1ssel" in strtbdsel:
process.AlignmentTrackSelector.ptMin = 3.0
Expand Down

0 comments on commit 1376cca

Please sign in to comment.