diff --git a/SimG4CMS/Muon/interface/MuonMe0FrameRotation.h b/SimG4CMS/Muon/interface/MuonMe0FrameRotation.h new file mode 100644 index 0000000000000..1a6aa27d07fc6 --- /dev/null +++ b/SimG4CMS/Muon/interface/MuonMe0FrameRotation.h @@ -0,0 +1,34 @@ +#ifndef MuonMe0FrameRotation_H +#define MuonMe0FrameRotation_H + +/** \class MuonMe0FrameRotation + * + * implementation of FrameRotation for the muon ME0 + * + * \author Arno Straessner, CERN + * + * Modification: + * + */ + +#include "SimG4CMS/Muon/interface/MuonFrameRotation.h" +#include "SimG4CMS/Muon/interface/MuonG4Numbering.h" + +#include "G4Step.hh" + +class DDCompactView; + +class MuonMe0FrameRotation : public MuonFrameRotation { + +public: + MuonMe0FrameRotation( const DDCompactView& cpv ); + virtual ~MuonMe0FrameRotation(); + virtual Local3DPoint transformPoint(const Local3DPoint &, const G4Step *) const; + +private: + MuonG4Numbering* g4numbering; + int theSectorLevel; +}; + + +#endif diff --git a/SimG4CMS/Muon/interface/MuonSlaveSD.h b/SimG4CMS/Muon/interface/MuonSlaveSD.h index 387d5ac62d154..cae393fb8780b 100644 --- a/SimG4CMS/Muon/interface/MuonSlaveSD.h +++ b/SimG4CMS/Muon/interface/MuonSlaveSD.h @@ -65,4 +65,16 @@ class FormatRpcHits { int sortId (const PSimHit & a) const; }; +class FormatGemHits { + public: + bool operator() (const PSimHit & a, const PSimHit & b); + int sortId (const PSimHit & a) const; +}; + +class FormatMe0Hits { + public: + bool operator() (const PSimHit & a, const PSimHit & b); + int sortId (const PSimHit & a) const; +}; + #endif // MuonSlaveSD_h diff --git a/SimG4CMS/Muon/src/MuonGemFrameRotation.cc b/SimG4CMS/Muon/src/MuonGemFrameRotation.cc index fbe60a5c8b0f9..406417bda5945 100644 --- a/SimG4CMS/Muon/src/MuonGemFrameRotation.cc +++ b/SimG4CMS/Muon/src/MuonGemFrameRotation.cc @@ -36,7 +36,8 @@ Local3DPoint MuonGemFrameRotation::transformPoint(const Local3DPoint & point,con << " Rotation " << rotated << std::endl; #endif if (rotated) { - return Local3DPoint(-point.x(),point.z(),point.y()); + // return Local3DPoint(-point.x(),point.z(),point.y()); + return Local3DPoint(point.x(),point.z(),-point.y()); } else { return Local3DPoint(point.x(),point.z(),-point.y()); } diff --git a/SimG4CMS/Muon/src/MuonMe0FrameRotation.cc b/SimG4CMS/Muon/src/MuonMe0FrameRotation.cc new file mode 100644 index 0000000000000..d604a30417cf5 --- /dev/null +++ b/SimG4CMS/Muon/src/MuonMe0FrameRotation.cc @@ -0,0 +1,44 @@ +#include "SimG4CMS/Muon/interface/MuonMe0FrameRotation.h" +#include "Geometry/MuonNumbering/interface/MuonDDDConstants.h" +#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h" + +#include "G4StepPoint.hh" +#include "G4TouchableHistory.hh" + +//#define LOCAL_DEBUG + +MuonMe0FrameRotation::MuonMe0FrameRotation(const DDCompactView& cpv) : MuonFrameRotation::MuonFrameRotation(cpv) { + g4numbering = new MuonG4Numbering(cpv); + MuonDDDConstants muonConstants(cpv); + int theLevelPart= muonConstants.getValue("level"); + theSectorLevel = muonConstants.getValue("mg_sector")/theLevelPart; +#ifdef LOCAL_DEBUG + std::cout << "MuonMe0FrameRotation: theSectorLevel " << theSectorLevel + << std::endl; +#endif +} + +MuonMe0FrameRotation::~MuonMe0FrameRotation() { + delete g4numbering; +} + +Local3DPoint MuonMe0FrameRotation::transformPoint(const Local3DPoint & point,const G4Step * aStep=0) const { + if (!aStep) return Local3DPoint(0.,0.,0.); + + //check if it is rotated +#ifdef LOCAL_DEBUG + std::cout << "Position " << aStep->GetPreStepPoint()->GetPosition() << std::endl; +#endif + MuonBaseNumber num = g4numbering->PhysicalVolumeToBaseNumber(aStep); + bool rotated = (num.getBaseNo(theSectorLevel)>=50); +#ifdef LOCAL_DEBUG + std::cout << "MuonMe0FrameRotation num " << num.getBaseNo(theSectorLevel) + << " Rotation " << rotated << std::endl; +#endif + if (rotated) { + // return Local3DPoint(-point.x(),point.z(),point.y()); + return Local3DPoint(point.x(),point.z(),-point.y()); + } else { + return Local3DPoint(point.x(),point.z(),-point.y()); + } +} diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index 3da99ded5c2d5..b6e1369064411 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -1,8 +1,9 @@ #include "SimG4CMS/Muon/interface/MuonSensitiveDetector.h" #include "SimG4CMS/Muon/interface/MuonSlaveSD.h" #include "SimG4CMS/Muon//interface/MuonEndcapFrameRotation.h" -#include "SimG4CMS/Muon/interface/MuonGemFrameRotation.h" #include "SimG4CMS/Muon/interface/MuonRpcFrameRotation.h" +#include "SimG4CMS/Muon/interface/MuonGemFrameRotation.h" +#include "SimG4CMS/Muon/interface/MuonMe0FrameRotation.h" #include "Geometry/MuonNumbering/interface/MuonSubDetector.h" #include "DataFormats/GeometryVector/interface/LocalVector.h" @@ -59,6 +60,9 @@ MuonSensitiveDetector::MuonSensitiveDetector(std::string name, } else if (detector->isGem()) { // cout << "MuonFrameRotation create MuonGemFrameRotation"<isME0()) { + // cout << "MuonFrameRotation create MuonMe0FrameRotation"<isRpc()) { sort(hits_.begin(),hits_.end(), FormatRpcHits()); + } else if (detector->isGem()) { + sort(hits_.begin(),hits_.end(), FormatGemHits()); + } else if (detector->isME0()) { + sort(hits_.begin(),hits_.end(), FormatMe0Hits()); } - return true; } @@ -69,3 +72,23 @@ int FormatRpcHits::sortId(const PSimHit & a) const return a.detUnitId(); } +bool FormatGemHits::operator() (const PSimHit & a, const PSimHit & b) +{ + return (sortId(a)