Skip to content

Commit

Permalink
Merge pull request cms-sw#110 from kmcdermo/cmd-opts-cleanup
Browse files Browse the repository at this point in the history
Assorted cleanups: command line options, CCS, endcap tests, etc.
  • Loading branch information
osschar authored Oct 25, 2017
2 parents ee8a6e7 + 58032f2 commit 942886a
Show file tree
Hide file tree
Showing 77 changed files with 394 additions and 112,543 deletions.
11 changes: 5 additions & 6 deletions Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ namespace Config

float chi2Cut = 15.;

bool useCMSGeom = false;
bool readCmsswSeeds = false;
bool cleanCmsswSeeds = false;
bool readExtRecTracks = false;
seedOpts seedInput = simSeeds;
cleanOpts seedCleaning = noCleaning;

bool findSeeds = false;
bool endcapTest = false;
bool useCMSGeom = false;
bool readCmsswTracks = false;

bool silent = false;

Expand All @@ -61,6 +59,7 @@ namespace Config
bool root_val = false;
bool cmssw_val = false;
bool fit_val = false;
bool readSimTrackStates = false;
bool inclusiveShorts = false;
bool applyCMSSWHitMatch = false;

Expand Down
27 changes: 15 additions & 12 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ class TrackerInfo;
#include <algorithm>
#include <cmath>
#include <string> // won't compile on clang gcc for mac OS w/o this!
#include <map>

//#define PRINTOUTS_FOR_PLOTS
#define CCSCOORD

#if defined(__CUDACC__)
#define CUDA_CALLABLE __host__ __device__
#else
#define CUDA_CALLABLE
#endif

// Enum for input seed options
enum seedOpts {simSeeds, cmsswSeeds, findSeeds};
typedef std::map<std::string,seedOpts> seedOptsMap;

// Enum for seed cleaning options
enum cleanOpts {noCleaning, cleanSeedsN2, cleanSeedsPure, cleanSeedsBadLabel};
typedef std::map<std::string,cleanOpts> cleanOptsMap;

namespace Config
{
extern TrackerInfo TrkInfo;
Expand Down Expand Up @@ -171,7 +179,6 @@ namespace Config
constexpr float seed_z1cut = hitposerrZ * 3.6f; // 3.6 mm --> to match efficiency from chi2cut
constexpr float seed_d0cut = 0.5f; // 5mm
extern bool cf_seeding;
extern bool findSeeds;

// Config for propagation
constexpr int Niter = 5;
Expand Down Expand Up @@ -243,6 +250,7 @@ namespace Config
extern bool root_val;
extern bool cmssw_val;
extern bool fit_val;
extern bool readSimTrackStates; // need this to fill pulls
extern bool inclusiveShorts;
extern bool applyCMSSWHitMatch;

Expand All @@ -265,21 +273,16 @@ namespace Config

// number of layer1 hits for finding seeds per task
extern int numHitsPerTask;

// seed options
extern seedOpts seedInput;
extern cleanOpts seedCleaning;

extern bool useCMSGeom;
extern bool readCmsswSeeds;
extern bool cleanCmsswSeeds;
extern bool readExtRecTracks;

extern bool endcapTest;
extern bool readCmsswTracks;

extern bool silent;

const std::string inputFile = "cmssw.simtracks.SingleMu1GeV.10k.new.txt";
//const std::string inputFile = "cmssw.simtracks.SingleMu10GeV.10k.new.txt";
//const std::string inputFile = "cmssw.rectracks.SingleMu1GeV.10k.new.txt";
//const std::string inputFile = "cmssw.rectracks.SingleMu10GeV.10k.new.txt";

void RecalculateDependentConstants();

CUDA_CALLABLE
Expand Down
26 changes: 0 additions & 26 deletions ConformalUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void conformalFit(const Hit& hit0, const Hit& hit1, const Hit& hit2, TrackState&
float py = std::copysign( k*vrx , (y[2]-y[0]) );
float pz = (pt * (z[2]-z[0])) / std::sqrt(getRad2((x[2]-x[0]) , (y[2]-y[0])));

#ifdef CCSCOORD
fitStateHit0.parameters[3] = 1.0f/pt;
fitStateHit0.parameters[4] = getPhi(px,py);
fitStateHit0.parameters[5] = getTheta(pt,pz);
Expand All @@ -96,29 +95,4 @@ void conformalFit(const Hit& hit0, const Hit& hit1, const Hit& hit2, TrackState&
fitStateHit0.errors[3][3] = (fiterrs ? Config::ptinverr049 * Config::ptinverr049 : Config::ptinverr012 * Config::ptinverr012);
fitStateHit0.errors[4][4] = (fiterrs ? Config::phierr049 * Config::phierr049 : Config::phierr012 * Config::phierr012);
fitStateHit0.errors[5][5] = (fiterrs ? Config::thetaerr049 * Config::thetaerr049 : Config::thetaerr012 * Config::thetaerr012);
#else
#ifdef INWARDFIT
if (fiterrs) { // need conformal fit on seeds to be forward!
px*=-1.;
py*=-1.;
pz*=-1.;
}
#endif
//return px,py,pz
fitStateHit0.parameters[3] = px;
fitStateHit0.parameters[4] = py;
fitStateHit0.parameters[5] = pz;

//get them a posteriori from width of residue plots (i.e. unitary pulls) + global maxima scan of nHits / track in super debug mode
const float pt2 = pt*pt;
const float pz2 = pz*pz;

const float varPt = (fiterrs ? Config::ptinverr049 * Config::ptinverr049 : Config::ptinverr012 * Config::ptinverr012) * pt2;
const float varPhi = (fiterrs ? Config::phierr049 * Config::phierr049 : Config::phierr012 * Config::phierr012);
const float varTheta = (fiterrs ? Config::thetaerr049 * Config::thetaerr049 : Config::thetaerr012 * Config::thetaerr012);

fitStateHit0.errors[3][3] = px*px*varPt + py*py*varPhi;
fitStateHit0.errors[4][4] = py*py*varPt + px*px*varPhi;
fitStateHit0.errors[5][5] = pz2 *varPt + ((pz2+pt2)*(pz2+pz2)/pt2)*varTheta;
#endif // cartesian coords
}
59 changes: 24 additions & 35 deletions Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void Event::Reset(int evtID)
candidateTracksExtra_.clear();
fitTracks_.clear();
fitTracksExtra_.clear();
extRecTracks_.clear();
extRecTracksExtra_.clear();
cmsswTracks_.clear();
cmsswTracksExtra_.clear();

validation_.resetValidationMaps(); // need to reset maps for every event.
}
Expand Down Expand Up @@ -142,26 +142,15 @@ void Event::Simulate()

int q=0;//set it in setup function
// do the simulation
if (Config::useCMSGeom) setupTrackFromTextFile(pos,mom,covtrk,hits,*this,itrack,q,tmpgeom,initialTSs);
else if (Config::endcapTest) setupTrackByToyMCEndcap(pos,mom,covtrk,hits,*this,itrack,q,tmpgeom,initialTSs);
else setupTrackByToyMC(pos,mom,covtrk,hits,hitinfos,*this,itrack,q,tmpgeom,initialTSs);

// XXMT4K What genius set up separate setupTrackByToyMC / setupTrackByToyMCEndcap?
// setupTrackByToyMCEndcap does not have scattering and who knows what else.
// In the original commit Giuseppe he only did fittest ... strangle ... etc ...
// I'll just review/fix setupTrackByToyMC() for now (so Config::endcapTest = false).
// See also ifdef just below:

#ifdef CCSCOORD
// setupTrackByToyMCEndcap is already in CCS coord, no need to convert
if (Config::endcapTest==false) {
float pt = sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
mom=SVector3(1./pt,atan2(mom[1],mom[0]),atan2(pt,mom[2]));
for (int its = 0; its < initialTSs.size(); its++){
initialTSs[its].convertFromCartesianToCCS();
}
setupTrackByToyMC(pos,mom,covtrk,hits,hitinfos,*this,itrack,q,tmpgeom,initialTSs);

// convert from global cartesian to CCS
float pt = sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
mom=SVector3(1./pt,atan2(mom[1],mom[0]),atan2(pt,mom[2]));
for (int its = 0; its < initialTSs.size(); its++){
initialTSs[its].convertFromCartesianToCCS();
}
#endif

// MT: I'm putting in a mutex for now ...
std::lock_guard<std::mutex> lock(mcGatherMutex_);

Expand Down Expand Up @@ -207,7 +196,7 @@ void Event::Simulate()
{
tmpTSVec[its] = simTrackStates_[mcHitIDMap[its]];
}
simTrackStates_ = tmpTSVec;
simTrackStates_.swap(tmpTSVec);
}

void Event::Segment(BinInfoMap & segmentMap)
Expand Down Expand Up @@ -424,10 +413,10 @@ void Event::write_out(DataFile &data_file)
evsize += sizeof(int) + ns*sizeof(Track);
}

if (data_file.HasExtRecTracks()) {
int nert = extRecTracks_.size();
if (data_file.HasCmsswTracks()) {
int nert = cmsswTracks_.size();
fwrite(&nert, sizeof(int), 1, fp);
fwrite(&extRecTracks_[0], sizeof(Track), nert, fp);
fwrite(&cmsswTracks_[0], sizeof(Track), nert, fp);
evsize += sizeof(int) + nert*sizeof(Track);
}

Expand Down Expand Up @@ -502,7 +491,7 @@ void Event::read_in(DataFile &data_file, FILE *in_fp)
if (data_file.HasSeeds()) {
int ns;
fread(&ns, sizeof(int), 1, fp);
if (Config::readCmsswSeeds)
if (Config::seedInput == cmsswSeeds)
{
seedTracks_.resize(ns);
for (int i = 0; i < ns; ++i)
Expand Down Expand Up @@ -542,16 +531,16 @@ void Event::read_in(DataFile &data_file, FILE *in_fp)
#endif
}

if (data_file.HasExtRecTracks())
if (data_file.HasCmsswTracks())
{
int nert;
fread(&nert, sizeof(int), 1, fp);
if (Config::readExtRecTracks)
if (Config::readCmsswTracks)
{
extRecTracks_.resize(nert);
cmsswTracks_.resize(nert);
for (int i = 0; i < nert; ++i)
{
fread(&extRecTracks_[i], data_file.f_header.f_sizeof_track, 1, fp);
fread(&cmsswTracks_[i], data_file.f_header.f_sizeof_track, 1, fp);
}
}
else
Expand Down Expand Up @@ -806,7 +795,7 @@ int Event::use_seeds_from_cmsswtracks()
cleanSeedTracks.reserve(ns);

int i = 0;
for (auto&& cmsswtrack : extRecTracks_)
for (auto&& cmsswtrack : cmsswTracks_)
{
cleanSeedTracks.emplace_back(seedTracks_[cmsswtrack.label()]);
}
Expand Down Expand Up @@ -874,17 +863,17 @@ int DataFile::OpenRead(const std::string& fname, bool set_n_layers)
printf(" Extra sections:");
if (f_header.f_extra_sections & ES_SimTrackStates) printf(" SimTrackStates");
if (f_header.f_extra_sections & ES_Seeds) printf(" Seeds");
if (f_header.f_extra_sections & ES_ExtRecTracks) printf(" ExtRecTracks");
if (f_header.f_extra_sections & ES_CmsswTracks) printf(" CmsswTracks");
printf("\n");
}

if (Config::readCmsswSeeds && ! HasSeeds()) {
if (Config::seedInput == cmsswSeeds && ! HasSeeds()) {
fprintf(stderr, "Reading of CmsswSeeds requested but data not available on file.\n");
exit(1);
}

if (Config::readExtRecTracks && ! HasExtRecTracks()) {
fprintf(stderr, "Reading of ExtRecTracks requested but data not available on file.\n");
if (Config::readCmsswTracks && ! HasCmsswTracks()) {
fprintf(stderr, "Reading of CmsswTracks requested but data not available on file.\n");
exit(1);
}

Expand Down
8 changes: 4 additions & 4 deletions Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class Event
MCHitInfoVec simHitsInfo_;

TrackVec simTracks_, seedTracks_, candidateTracks_, fitTracks_;
TrackVec extRecTracks_;
TrackVec cmsswTracks_;
// validation sets these, so needs to be mutable
mutable TrackExtraVec simTracksExtra_, seedTracksExtra_, candidateTracksExtra_, fitTracksExtra_;
mutable TrackExtraVec extRecTracksExtra_;
mutable TrackExtraVec cmsswTracksExtra_;

// XXXXMT: Preliminary. Separators into seed/candidate arrays.
// This will have to be extended for multi-pass tracking.
Expand Down Expand Up @@ -97,7 +97,7 @@ struct DataFile
{
ES_SimTrackStates = 0x1,
ES_Seeds = 0x2,
ES_ExtRecTracks = 0x4
ES_CmsswTracks = 0x4
};

FILE *f_fp = 0;
Expand All @@ -111,7 +111,7 @@ struct DataFile

bool HasSimTrackStates() const { return f_header.f_extra_sections & ES_SimTrackStates; }
bool HasSeeds() const { return f_header.f_extra_sections & ES_Seeds; }
bool HasExtRecTracks() const { return f_header.f_extra_sections & ES_ExtRecTracks; }
bool HasCmsswTracks() const { return f_header.f_extra_sections & ES_CmsswTracks; }

int OpenRead (const std::string& fname, bool set_n_layers = false);
void OpenWrite(const std::string& fname, int nev, int extra_sections=0);
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ clean-local:
-rm -f ${TGTS} *.d *.o *.om *.so
-rm -rf main.dSYM
-rm -rf USolids-{host,mic}
-rm -rf plotting/*.so plotting/*.d

clean: clean-local
cd mkFit && ${MAKE} clean
Expand Down
Loading

0 comments on commit 942886a

Please sign in to comment.