Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions RecoMTD/TimingIDTools/plugins/MVATrainingNtuple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ void MVATrainingNtuple::analyze(const edm::Event& iEvent, const edm::EventSetup&
});
// Check if TP has direct or other sim cluster for BTL
for (const auto& simClusterRef : simClustersRefs) {
if (simClusterRef->trackIdOffset() == 0) {
if (simClusterRef->hitProdType() == 0) {
isTPmtdDirectETL = true;
} else if (simClusterRef->trackIdOffset() != 0) {
} else if (simClusterRef->hitProdType() != 0) {
isTPmtdOtherETL = true;
}
}
Expand All @@ -724,9 +724,9 @@ void MVATrainingNtuple::analyze(const edm::Event& iEvent, const edm::EventSetup&
});
// Check if TP has direct or other sim cluster for BTL
for (const auto& simClusterRef : simClustersRefs) {
if (simClusterRef->trackIdOffset() == 0) {
if (simClusterRef->hitProdType() == 0) {
isTPmtdDirectBTL = true;
} else if (simClusterRef->trackIdOffset() != 0) {
} else if (simClusterRef->hitProdType() != 0) {
isTPmtdOtherBTL = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions SimDataFormats/CaloAnalysis/interface/MtdSimCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class MtdSimCluster : public SimCluster {
++nsimhits_;
}

void setTrackIdOffset(unsigned int offset) { idOffset_ = offset; }
void setHitProdType(unsigned int offset) { idOffset_ = offset; }

unsigned int trackIdOffset() const { return idOffset_; }
unsigned int hitProdType() const { return idOffset_; }

protected:
std::vector<uint64_t> mtdHits_;
Expand Down
2 changes: 1 addition & 1 deletion SimDataFormats/CaloAnalysis/src/MtdSimLayerCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MtdSimLayerCluster::~MtdSimLayerCluster() {}
std::ostream &operator<<(std::ostream &s, MtdSimLayerCluster const &tp) {
s << "CP momentum, q, ID, & Event #: " << tp.p4() << " " << tp.charge() << " " << tp.pdgId() << " "
<< tp.eventId().bunchCrossing() << "." << tp.eventId().event() << std::endl;
s << " Offset " << tp.trackIdOffset() << " "
s << " Offset " << tp.hitProdType() << " "
<< " LC time " << tp.simLCTime() << " LC energy " << tp.simLCEnergy() << std::endl;

for (MtdSimLayerCluster::genp_iterator hepT = tp.genParticle_begin(); hepT != tp.genParticle_end(); ++hepT) {
Expand Down
18 changes: 6 additions & 12 deletions SimDataFormats/TrackingHit/interface/PSimHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
#include "DataFormats/GeometryVector/interface/LocalVector.h"
#include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
#include "SimHitCategory.h"

class TrackingSlaveSD; // for friend declaration only

Expand All @@ -14,8 +15,6 @@ class TrackingSlaveSD; // for friend declaration only

class PSimHit {
public:
static constexpr unsigned int k_tidOffset = 200000000;

PSimHit() : theDetUnitId(0) {}

PSimHit(const Local3DPoint& entry,
Expand Down Expand Up @@ -107,15 +106,6 @@ class PSimHit {
*/
unsigned int trackId() const { return theTrackId; }

/** In case te SimTrack ID is incremented by the k_tidOffset for hit category definition, this
* methods returns the original theTrackId value directly.
*/
unsigned int originalTrackId() const { return theTrackId % k_tidOffset; }

unsigned int offsetTrackId() const { return theTrackId / k_tidOffset; }

static unsigned int addTrackIdOffset(unsigned int tId, unsigned int offset) { return offset * k_tidOffset + tId; }

EncodedEventId eventId() const { return theEventId; }

void setEventId(EncodedEventId e) { theEventId = e; }
Expand All @@ -128,7 +118,11 @@ class PSimHit {
* value with special significance is zero (for "undefined"), so zero should
* not be the ID of any process.
*/
unsigned short processType() const { return theProcessType; }
// use 9 bits (up to 511) for process id, reserve the rest for hit production mechanism id
unsigned short processType() const { return theProcessType & k_procidMask_; }

unsigned short hitProdType() const { return (theProcessType >> k_hitidShift_) & k_hitidMask_; }
void setHitProdType(unsigned int hitId) { theProcessType |= hitId << k_hitidShift_; }

void setTof(float tof) { theTof = tof; }

Expand Down
20 changes: 20 additions & 0 deletions SimDataFormats/TrackingHit/interface/SimHitCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef SimHitCategory_h
#define SimHitCategory_h

// 7 bits field availablen PSimHit processType, i.e. up 127
static constexpr unsigned int k_procidMask_ = 0x1FF;
static constexpr unsigned int k_hitidMask_ = 0x7F;
static constexpr unsigned int k_hitidShift_ = 9;

namespace SimHitCategory {

// Identification code of sim hit production mechanism, subdetector dependent

static constexpr unsigned int k_BTLsecondary = 1; // BTL hit from secondary particle not saved in history
static constexpr unsigned int k_BTLlooper = 2; // BTL hit from identified looper
static constexpr unsigned int k_BTLfromCalo = 3; // BTL hit from back-scattering from CALO volume
static constexpr unsigned int k_ETLfromBack = 4; // ETL hit entering from a rear face of disks

}; // namespace SimHitCategory

#endif
13 changes: 12 additions & 1 deletion SimDataFormats/TrackingHit/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<lcgdict>
<class name="PSimHit" ClassVersion="10">
<class name="PSimHit" ClassVersion="11">
<version ClassVersion="11" checksum="1181355938"/>
<version ClassVersion="10" checksum="1181355938"/>
<ioread sourceClass = "PSimHit" version="[-10]" targetClass="PSimHit" source="unsigned int theTrackId" target="theTrackId">
<![CDATA[
if ((newObj->detUnitId() >> 25) == 0x31) {theTrackId = onfile.theTrackId % 200000000;}
]]>
</ioread>
<ioread sourceClass = "PSimHit" version="[-10]" targetClass="PSimHit" source="unsigned int theTrackId; unsigned short theProcessType" target="theProcessType">
<![CDATA[
if ((newObj->detUnitId() >> 25) == 0x31) {theProcessType |= (onfile.theTrackId / 200000000) << 9 ;}
]]>
</ioread>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@makortel sorry, do you perhaps manage to see what is wrong with this syntax? I took inspiration from other examples found in CMSSW, but the conversion of older format does not work, just simply running the SimHitCaloHitDumper test analyzer in SimG4Core/Application when reading an old 16_1_0_pre1 input file without these updates... I did several tests and variants, but event the trivial theTrackId = onfile.theTrackId causes a core dump.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pcanal @vepadulano Any thoughts what could be going wrong here?

The rules seem to have an expectation of upper one to be run before the lower one, but on the surface the source and target seem to specify the dependencies correctly (I have a vague recollection ROOT would be able to deal with those, but I don't really know).

Copy link
Contributor

@pcanal pcanal Feb 2, 2026

Choose a reason for hiding this comment

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

@makortel Where does the order dependency comes into play?

(I have a vague recollection ROOT would be able to deal with those, but I don't really know).

There is no 'real' promise on the ordering of rules executions. They will be executed after their input have been read into the onfile place-holders but after that the order depends on implementation details (including but not limited to the order of the output fields)

Copy link
Contributor

Choose a reason for hiding this comment

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

I did several tests and variants, but event the trivial theTrackId = onfile.theTrackId causes a core dump.

Can you run the failing example under valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Where does the order dependency comes into play?

The upper rule updates theTrackId member, that the lower rule uses as a source. Although reading the rule code again, I assume the expectation would actually be to run the lower rule first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the issue with ordering, anyway I thought that the "onfile." prefix was ensuring to always look at the original input, not at its modified version. And in any case, even if the modified one is taken, that would result in missing the correct hit type, setting it to zero, but should not cause crashes. I also tried for the second rule the modified syntax:

<ioread sourceClass = "PSimHit" version="[10]" targetClass="PSimHit" source="unsigned int theTrackId; unsigned int theDetUnitId; unsigned short theProcessType" target="theProcessProdType">
     <![CDATA[
     if ((onfile.theDetUnitId >> 25) == 0x31) {unsigned short tmp = onfile.theProcessType; tmp |= (onfile.theTrackId / 200000000) << 9 ; theProcessProdType = tmp;}
    ]]>
   </ioread>

just to avoid mixing things, but it keeps crashing.

The valgrind output is quite long, I can provide it if useful, the piece just before crashing

valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp cmsRun runSimHitCaloHitDumper_cfg.py

looks like

==5276== 
==5276== Conditional jump or move depends on uninitialised value(s)
==5276==    at 0xFD3DC89: clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition(clang::Decl const*, llvm::Function*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFD6D728: clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFD69E40: clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFD72C57: clang::CodeGen::CodeGenModule::EmitDeferred() (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFD73EF5: clang::CodeGen::CodeGenModule::Release() (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFC27849: clang::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFA3BF19: cling::IncrementalParser::codeGenTransaction(cling::Transaction*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFA3C204: cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*>, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&, bool) (
in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFA3F20A: cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xF9A4682: cling::Interpreter::DeclareInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions const&, cling::Transaction**) const (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xF9A5B0D: cling::Interpreter::loadHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276==    by 0xFAA2A3F: cling::MetaSema::actOnLCommand(llvm::StringRef, cling::Transaction**) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCling.so)
==5276== 
==5276== Warning: invalid file descriptor -1 in syscall close()
==5276== Warning: invalid file descriptor -1 in syscall close()
==5276== Warning: invalid file descriptor -1 in syscall close()
==5276== Warning: invalid file descriptor -1 in syscall close()
03-Feb-2026 10:18:54 CET  Initiating request to open file file:step1.root
03-Feb-2026 10:19:06 CET  Successfully opened file file:step1.root
Begin processing the 1st record. Run 1, Event 1, LumiSection 1 on stream 0 at 03-Feb-2026 10:19:10.286 CET


A fatal system signal has occurred: segmentation violation
The following is the call stack containing the origin of the signal.

==5276== Unsupported clone() flags: 0x311
==5276== 
==5276== The only supported clone() uses are:
==5276==  - via a threads library (LinuxThreads or NPTL)
==5276==  - via the implementation of fork or vfork
==5276== 
==5276== Valgrind detected that your program requires
==5276== the following unimplemented functionality:
==5276==    Valgrind does not support general clone().
==5276== This may be because the functionality is hard to implement,
==5276== or because no reasonable program would behave this way,
==5276== or because nobody has yet needed it.  In any case, let us know at
==5276== www.valgrind.org and/or try to work around the problem, if you can.
==5276== 
==5276== Valgrind has to exit now.  Sorry.  Bye!
==5276== 

sched status:
  running_tid=2

Thread 1: status = VgTs_WaitSys syscall 7 (lwpid 5276)
==5276==    at 0x5768AE1: poll (in /usr/lib64/libc-2.28.so)
==5276==    by 0xCB12ACD: edm::service::InitRootHandlers::stacktraceFromThread() (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/cms/cmssw/CMSSW_16_1_0_pre1/lib/el8_amd64_gcc13/pluginFWCoreServicesPlugins.so)
==5276==    by 0xCB12CD2: sig_dostack_then_abort (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/cms/cmssw/CMSSW_16_1_0_pre1/lib/el8_amd64_gcc13/pluginFWCoreServicesPlugins.so)
==5276==    by 0x568462F: ??? (in /usr/lib64/libc-2.28.so)
==5276==    by 0x2DFAB61F: ROOT::new_Basic3DVectorlEfloatgR(void*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/cms/cmssw/CMSSW_16_1_0_pre1/lib/el8_amd64_gcc13/libDataFormatsGeometryVector.so)
==5276==    by 0x50DD21A: TClass::NewObject(void*, TClass::ENewType) const (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCore.so)
==5276==    by 0x50DD591: TClass::New(void*, TClass::ENewType) const (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCore.so)
==5276==    by 0xD3E4DBF: TStreamerInfo::New(void*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD3E41CD: TStreamerInfo::NewArray(long, void*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0x50DD0D4: TClass::NewObjectArray(long, TClass::ENewType) const (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libCore.so)
==5276==    by 0xD5791E5: TVirtualArray::TVirtualArray(TClass*, unsigned int) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD63F49A: int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD46AA3B: TStreamerInfoActions::VectorLooper::GenericRead(TBuffer&, void*, void const*, TStreamerInfoActions::TLoopConfiguration const*, TStreamerInfoActions::TConfiguration const*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD3225AB: TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*, void*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD52D4E8: int TStreamerInfoActions::ReadSTL<&TStreamerInfoActions::ReadSTLMemberWiseSameClass, &TStreamerInfoActions::ReadSTLObjectWiseFastArray>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD3234C4: TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libRIO.so)
==5276==    by 0xD12A904: TBranchElement::ReadLeavesMember(TBuffer&) (in /cvmfs/cms.cern.ch/el8_amd64_gcc13/lcg/root/6.36.07-bd71f88d9cd20e5042c0ac03a7e23595/lib/libTree.so)

As far as I can see, the target must be for a single item, cannot share two of them, at least I tried and got an error message at compilation stage. So I should try a way through a conversion function. Is there a syntax to start fir a copy of the whole PSimHit object onfile, and then modify only the members of interest?

BTW, I modified the name of one, not strictly needed in principle, as I was not getting otherwise a different checksum to be used in the class version history.

Copy link
Contributor

Choose a reason for hiding this comment

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

The failing stack trace is odd and indicates some probable internal error and seems to be related to the fact that some collection is involved. I will need a reproducer with a debug build of ROOT to look into this further.

the target must be for a single item

There can be (in principle) more than one target data member, although it usually makes more sense to only have one.

Is there a syntax to start fir a copy of the whole PSimHit object onfile, and then modify only the members of interest

Not really but it should also not be (in principle) any more helpful that the current syntax.

BTW, I modified the name of one, not strictly needed in principle, as I was not getting otherwise a different checksum to be used in the class version history.

I do not know about the CMS version checker but for ROOT proper, you can increase the version number explicitly without any change in the checksum.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I modified the name of one, not strictly needed in principle, as I was not getting otherwise a different checksum to be used in the class version history.

I do not know about the CMS version checker but for ROOT proper, you can increase the version number explicitly without any change in the checksum.

IIRC we have an earlier case where the version number was increased while keeping the checksum the same.

</class>
<class name="std::vector<PSimHit>"/>
<class name="edm::Wrapper<std::vector<PSimHit> >" splitLevel="0"/>
Expand Down
4 changes: 4 additions & 0 deletions SimDataFormats/TrackingHit/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<use name="SimDataFormats/TrackingHit"/>

<bin file="testPSimHit.cc">
</bin>
24 changes: 24 additions & 0 deletions SimDataFormats/TrackingHit/test/testPSimHit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include <iostream>
#include <iomanip>
#include <cassert>

int main() {
Local3DPoint dummy(0, 0, 0);

for (int procId = 1; procId < 404; procId++) {
for (unsigned short itype = 0; itype < 8; itype++) {
PSimHit testHit(dummy, dummy, 0., 0., 0., 11, 0, 0, 0., 0., procId);
testHit.setHitProdType(itype);
std::cout << " hit procId = " << std::fixed << std::setw(8) << procId << " sim procId = " << std::setw(8)
<< testHit.processType() << " hit type = " << std::setw(8) << itype << " sim type = " << std::setw(8)
<< testHit.hitProdType() << std::endl;

assert(procId == testHit.processType());
assert(itype == testHit.hitProdType());
}
}

return 0;
}
4 changes: 4 additions & 0 deletions SimG4CMS/Forward/interface/BscG4Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <cstdint>
#include <iostream>

#include "SimDataFormats/TrackingHit/interface/SimHitCategory.h"

class BscG4Hit : public G4VHit {
public:
BscG4Hit();
Expand Down Expand Up @@ -92,6 +94,8 @@ class BscG4Hit : public G4VHit {

int getParentId() const { return theParentId; };
int getProcessId() const { return theProcessId; };
int getProdType() const { return (theProcessId >> k_hitidShift_) & k_hitidMask_; }
void setHitProdType(unsigned int hitId) { theProcessId |= hitId << k_hitidShift_; }
float getVx() const { return theVx; };
float getVy() const { return theVy; };
float getVz() const { return theVz; };
Expand Down
15 changes: 0 additions & 15 deletions SimG4CMS/Forward/interface/MtdHitCategory.h

This file was deleted.

2 changes: 1 addition & 1 deletion SimG4CMS/Forward/interface/MtdSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SimG4CMSForward_MtdSD_h

#include "SimG4CMS/Forward/interface/TimingSD.h"
#include "SimG4CMS/Forward/interface/MtdHitCategory.h"
#include "SimDataFormats/TrackingHit/interface/SimHitCategory.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
Expand Down
4 changes: 2 additions & 2 deletions SimG4CMS/Forward/src/BSCG4Hit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ std::ostream& operator<<(std::ostream& os, const BscG4Hit& hit) {
<< " EnergyLoss = " << hit.getEnergyLoss() << std::endl
<< " ParticleType = " << hit.getParticleType() << std::endl
<< " Pabs = " << hit.getPabs() << std::endl
<< " Energy of primary particle (ID = " << hit.getTrackID() << ") = " << hit.getIncidentEnergy() << " (MeV)"
<< std::endl
<< " Energy of primary particle (ID = " << hit.getTrackID() << " hit type = " << hit.getProdType()
<< ") = " << hit.getIncidentEnergy() << " (MeV)" << std::endl
<< " Entry point in Bsc unit number " << hit.getUnitID() << " is: " << hit.getEntry() << " (mm)" << std::endl;
os << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
return os;
Expand Down
47 changes: 18 additions & 29 deletions SimG4CMS/Forward/src/MtdSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <iostream>

using namespace MtdHitCategory;

//-------------------------------------------------------------------
MtdSD::MtdSD(const std::string& name,
const SensitiveDetectorCatalog& clg,
Expand Down Expand Up @@ -111,32 +109,12 @@ int MtdSD::getTrackID(const G4Track* aTrack) {
if (!trkInfo->storeTrack()) {
theID = trkInfo->idLastStoredAncestor();
}
if (theID >= static_cast<int>(PSimHit::k_tidOffset)) {
edm::LogError("MtdSim") << " SimTrack ID " << theID << " exceeds maximum allowed by PSimHit identifier"
<< PSimHit::k_tidOffset << " unreliable MTD hit type";
}
if (rname == "FastTimerRegionSensBTL") {
if (trkInfo->isInTrkFromBackscattering()) {
theID = PSimHit::addTrackIdOffset(theID, k_idFromCaloOffset);
} else if (trkInfo->isExtSecondary() && !trkInfo->isInTrkFromBackscattering() && !trkInfo->storeTrack()) {
theID = PSimHit::addTrackIdOffset(theID, k_idsecOffset);
} else if (trkInfo->isBTLlooper()) {
theID = PSimHit::addTrackIdOffset(theID, k_idloopOffset);
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "MtdSD: Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->mcTruthID() << ":" << theID;
#endif
} else if (rname == "FastTimerRegionSensETL") {
if (hitClassID == k_idETLfromBack) {
theID = PSimHit::addTrackIdOffset(theID, k_idETLfromBack);
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "MtdSD: Track ID: " << aTrack->GetTrackID()
<< " ETL Track ID: " << trkInfo->mcTruthID() << ":" << theID;
edm::LogVerbatim("MtdSim") << "MtdSD: current Track ID: " << aTrack->GetTrackID()
<< " stored Track ID: " << trkInfo->mcTruthID() << ":" << theID;
#endif
// In the case of ECAL GFlash fast spot may be inside MTD and should be ignored
} else {
// In the case of ECAL GFlash fast spot may be inside MTD and should be ignored
if (rname != "FastTimerRegionSensBTL" && rname != "FastTimerRegionSensETL") {
throw cms::Exception("MtdSDError") << "MtdSD called in incorrect region " << rname;
}
} else {
Expand All @@ -148,20 +126,31 @@ int MtdSD::getTrackID(const G4Track* aTrack) {
}

void MtdSD::setHitClassID(const G4Step* aStep) {
hitClassID = 0;
TrackInformation* trkInfo = cmsTrackInformation(aStep->GetTrack());
if (nullptr == trkInfo) {
return;
}
const G4String& rname = aStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetRegion()->GetName();
if (rname == "FastTimerRegionSensETL") {
if (rname == "FastTimerRegionSensBTL") {
if (trkInfo->isInTrkFromBackscattering()) {
hitClassID = SimHitCategory::k_BTLfromCalo;
} else if (trkInfo->isExtSecondary() && !trkInfo->isInTrkFromBackscattering() && !trkInfo->storeTrack()) {
hitClassID = SimHitCategory::k_BTLsecondary;
} else if (trkInfo->isBTLlooper()) {
hitClassID = SimHitCategory::k_BTLlooper;
}
} else if (rname == "FastTimerRegionSensETL") {
double zin = std::abs(aStep->GetPreStepPoint()->GetPosition().z());
double zout = std::abs(aStep->GetPostStepPoint()->GetPosition().z());
if (zout - zin < 0.) {
hitClassID = k_idETLfromBack;
hitClassID = SimHitCategory::k_ETLfromBack;
trkInfo->setETLfromBack();
} else {
hitClassID = 0;
trkInfo->setETLfromFront();
}
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "MtdSD: process type = " << hitClassID;
#endif
}
2 changes: 2 additions & 0 deletions SimG4CMS/Forward/src/TimingSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ bool TimingSD::checkHit(const G4Step*, BscG4Hit* hit) {

hit->setParentId(theTrack->GetParentID());
hit->setProcessId(theEnumerator->processId(theTrack->GetCreatorProcess()));
hit->setHitProdType(hitClassID);

hit->setVertexPosition(theTrack->GetVertexPosition());
}
Expand Down Expand Up @@ -294,6 +295,7 @@ void TimingSD::createNewHit(const G4Step* aStep) {

currentHit->setParentId(theTrack->GetParentID());
currentHit->setProcessId(theEnumerator->processId(theTrack->GetCreatorProcess()));
currentHit->setHitProdType(hitClassID);

currentHit->setVertexPosition(theTrack->GetVertexPosition());

Expand Down
3 changes: 1 addition & 2 deletions SimG4Core/Application/test/SimHitCaloHitDumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ void SimHitCaloHitDumper::analyze(const edm::Event& iEvent, const edm::EventSetu
for (int ihit = 0; ihit < (*icoll).first; ++ihit) {
edm::LogPrint("SimHitCaloHitDumper")
<< theMTDHits[nhit] << " Energy = " << theMTDHits[nhit].energyLoss()
<< " tid orig/offset= " << theMTDHits[nhit].originalTrackId() << " " << theMTDHits[nhit].offsetTrackId()
<< " Track Id = " << theMTDHits[nhit].trackId();
<< " Track Id = " << theMTDHits[nhit].trackId() << " hit type = " << theMTDHits[nhit].hitProdType();
nhit++;
}
}
Expand Down
4 changes: 0 additions & 4 deletions SimG4Core/Notification/src/SimTrackManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ void SimTrackManager::reallyStoreTracks() {
}
}

if (id >= static_cast<int>(PSimHit::k_tidOffset)) {
edm::LogWarning("SimTrackManager::reallyStoreTracks")
<< " SimTrack ID " << id << " exceeds maximum allowed by PSimHit identifier" << PSimHit::k_tidOffset;
}
TmpSimTrack* g4simtrack =
new TmpSimTrack(id, trkH->particleID(), trkH->momentum(), trkH->totalEnergy(), ivertex, ig, pm, spos, smom);
g4simtrack->copyCrossedBoundaryVars(trkH);
Expand Down
Loading