Skip to content

Commit

Permalink
simple test runs (up to 150cm)
Browse files Browse the repository at this point in the history
  • Loading branch information
VinInn committed Jul 27, 2022
1 parent 386cf0d commit 264a5ff
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TrackPropagation/Geant4e/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<use name="Geometry/RPCGeometry"/>
<use name="Geometry/CSCGeometry"/>
<use name="DataFormats/MuonDetId"/>
<library file="Geant4ePropagatorAnalyzer.cc" name="Geant4ePropagatorAnalyzer">
<library file="*.cc" name="Geant4ePropagatorTests">
<flags EDM_PLUGIN="1"/>
</library>

Expand Down
137 changes: 137 additions & 0 deletions TrackPropagation/Geant4e/test/SimpleGeant4ePropagatorTest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h" //For define_fwk_module

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

//- Timing
//#include "Utilities/Timing/interface/TimingReport.h"

#include "Geometry/Records/interface/IdealGeometryRecord.h"

//- Magnetic field
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "SimG4Core/MagneticField/interface/Field.h"
#include "SimG4Core/MagneticField/interface/FieldBuilder.h"

//- Propagator
#include "TrackPropagation/Geant4e/interface/ConvertFromToCLHEP.h"
#include "TrackPropagation/Geant4e/interface/Geant4ePropagator.h"
#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"

#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/GeometryVector/interface/GlobalVector.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
#include "MagneticField/VolumeGeometry/interface/MagVolumeOutsideValidity.h"
#include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"

//- Geant4
#include "G4TransportationManager.hh"

class SimpleGeant4ePropagatorTest final : public edm::one::EDAnalyzer<> {
public:
explicit SimpleGeant4ePropagatorTest(const edm::ParameterSet &);
~SimpleGeant4ePropagatorTest() override {}

void analyze(const edm::Event &, const edm::EventSetup &) override;

protected:
// tokens
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken;

Propagator *thePropagator;
};

SimpleGeant4ePropagatorTest::SimpleGeant4ePropagatorTest(const edm::ParameterSet &iConfig)
: magFieldToken(esConsumes()), thePropagator(nullptr) {}

namespace {
Surface::RotationType rotation(const GlobalVector &zDir) {
GlobalVector zAxis = zDir.unit();
GlobalVector yAxis(zAxis.y(), -zAxis.x(), 0);
GlobalVector xAxis = yAxis.cross(zAxis);
return Surface::RotationType(xAxis, yAxis, zAxis);
}
} // namespace

void SimpleGeant4ePropagatorTest::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
using namespace edm;

std::cout << "Starting G4e test..." << std::endl;

///////////////////////////////////////
// Construct Magnetic Field
const ESHandle<MagneticField> bField = iSetup.getHandle(magFieldToken);
if (bField.isValid())
std::cout << "G4e -- Magnetic field is valid. Value in (0,0,0): " << bField->inTesla(GlobalPoint(0, 0, 0)).mag()
<< " Tesla " << std::endl;
else
LogError("Geant4e") << "G4e -- NO valid Magnetic field" << std::endl;

// Initialise the propagator
if (!thePropagator)
thePropagator = new Geant4ePropagator(bField.product());

if (thePropagator)
std::cout << "Propagator built!" << std::endl;
else
LogError("Geant4e") << "Could not build propagator!" << std::endl;

GlobalVector p3T(10., 10., 2.);
std::cout << "*** Phi (rad): " << p3T.phi() << " - Phi(deg)" << p3T.phi().degrees();
std::cout << "Track P.: " << p3T << "\nTrack P.: PT=" << p3T.perp() << "\tEta=" << p3T.eta()
<< "\tPhi=" << p3T.phi().degrees() << "--> Rad: Phi=" << p3T.phi() << std::endl;

GlobalPoint r3T(0., 0., 0.);
std::cout << "Init point: " << r3T << "\nInit point Ro=" << r3T.perp() << "\tEta=" << r3T.eta()
<< "\tPhi=" << r3T.phi().degrees() << std::endl;

//- Charge
int charge = 1;
std::cout << "Track charge = " << charge << std::endl;

//- Initial covariance matrix is unity 10-6
ROOT::Math::SMatrixIdentity id;
AlgebraicSymMatrix55 C(id);
C *= 0.01;
CurvilinearTrajectoryError covT(C);

PlaneBuilder pb;
Surface::RotationType rot = rotation(p3T);
// Define end planes
for (float d = 50.; d < 700.; d += 50.) {
float propDistance = d; // 100 cm
std::cout << "G4e -- Extrapolatation distance " << d << " cm" << std::endl;
GlobalPoint targetPos = r3T + propDistance * p3T.unit();
auto endPlane = pb.plane(targetPos, rot);

//- Build FreeTrajectoryState
GlobalTrajectoryParameters trackPars(r3T, p3T, charge, &*bField);
FreeTrajectoryState ftsTrack(trackPars, covT);

// Propagate: Need to explicetely
TrajectoryStateOnSurface tSOSDest = thePropagator->propagate(ftsTrack, *endPlane);
if (!tSOSDest.isValid()) {
std::cout << "TSOS not valid? Propagation failed...." << std::endl;
continue;
}

auto posExtrap = tSOSDest.freeState()->position();
auto momExtrap = tSOSDest.freeState()->momentum();
std::cout << "G4e -- Extrapolated position:" << posExtrap << " cm\n"
<< "G4e -- (Rho, eta, phi): (" << posExtrap.perp() << " cm, " << posExtrap.eta() << ", "
<< posExtrap.phi() << ')' << std::endl;
std::cout << "G4e -- Extrapolated momentum:" << momExtrap << " GeV\n"
<< "G4e -- (pt, eta, phi): (" << momExtrap.perp() << " cm, " << momExtrap.eta() << ", "
<< momExtrap.phi() << ')' << std::endl;
}
}

// define this as a plug-in
DEFINE_FWK_MODULE(SimpleGeant4ePropagatorTest);
107 changes: 107 additions & 0 deletions TrackPropagation/Geant4e/test/simpleTestPropagator_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import FWCore.ParameterSet.Config as cms

from Configuration.Eras.Era_Run3_cff import Run3

#process = cms.Process("PROPAGATORTEST")
process = cms.Process("PROPAGATORTEST",Run3)



#####################################################################
# Message Logger ####################################################
#
process.load("FWCore.MessageService.MessageLogger_cfi")
process.load('Configuration.StandardSequences.Services_cff')
process.load('Configuration.StandardSequences.GeometryDB_cff')
process.load("Configuration.EventContent.EventContent_cff")
process.load("Configuration.StandardSequences.Reconstruction_cff")
process.load('Configuration.StandardSequences.MagneticField_38T_cff')
process.load('Configuration.StandardSequences.EndOfProcess_cff')
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")

from Configuration.AlCa.GlobalTag import GlobalTag
#process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run1_mc', '')
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2022_realistic', '')

process.load("FWCore.MessageService.MessageLogger_cfi")

# MessageLogger customizations
process.MessageLogger.cerr.enable = False
process.MessageLogger.cout.enable = True
labels = ["propTest", "geopro"] # Python module's label
messageLogger = dict()
for category in labels:
main_key = '%sMessageLogger'%(category)
category_key = 'Geant4e' # C++ EDProducer type
messageLogger[main_key] = dict(
filename = '%s_%s.log' % ("debugG4e", category),
threshold = 'DEBUG',
default = dict(limit=0)
)
messageLogger[main_key][category_key] = dict(limit=-1)
# First create defaults
setattr(process.MessageLogger.files, category, dict())
# Then modify them
setattr(process.MessageLogger.files, category, messageLogger[main_key])

process.source = cms.Source("EmptySource")
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

## Set up geometry
process.geopro = cms.EDProducer("GeometryProducer",
GeoFromDD4hep= cms.bool(True),
# GeoFromDD4hep= cms.bool(False),
UseMagneticField = cms.bool(True),
UseSensitiveDetectors = cms.bool(False),
MagneticField = cms.PSet(
UseLocalMagFieldManager = cms.bool(False),
Verbosity = cms.bool(False),
ConfGlobalMFM = cms.PSet(
Volume = cms.string('OCMS'),
OCMS = cms.PSet(
Stepper = cms.string('G4TDormandPrince45'),
Type = cms.string('CMSIMField'),
StepperParam = cms.PSet(
VacRegions = cms.vstring(),
# VacRegions = cms.vstring('DefaultRegionForTheWorld','BeamPipeVacuum','BeamPipeOutside'),
EnergyThTracker = cms.double(0.2), ## in GeV
RmaxTracker = cms.double(8000), ## in mm
ZmaxTracker = cms.double(11000), ## in mm
MaximumEpsilonStep = cms.untracked.double(0.01),
DeltaOneStep = cms.double(0.001), ## in mm
DeltaOneStepTracker = cms.double(1e-4),## in mm
MaximumLoopCounts = cms.untracked.double(1000.0),
DeltaChord = cms.double(0.002), ## in mm
DeltaChordTracker = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaIntersectionAndOneStep = cms.untracked.double(-1.0),
DeltaIntersection = cms.double(0.0001), ## in mm
DeltaIntersectionTracker = cms.double(1e-6),## in mm
MaxStep = cms.double(150.), ## in cm
MinimumEpsilonStep = cms.untracked.double(1e-05),
EnergyThSimple = cms.double(0.015), ## in GeV
DeltaChordSimple = cms.double(0.1), ## in mm
DeltaOneStepSimple = cms.double(0.1), ## in mm
DeltaIntersectionSimple = cms.double(0.01), ## in mm
MaxStepSimple = cms.double(50.), ## in cm
)
)
),
delta = cms.double(1.0)
),
)




#####################################################################
# Extrapolator ######################################################
#
process.propTest = cms.EDAnalyzer("SimpleGeant4ePropagatorTest",
)


process.g4TestPath = cms.Path( process.geopro*process.propTest )
process.schedule = cms.Schedule( process.g4TestPath )

0 comments on commit 264a5ff

Please sign in to comment.