Skip to content

Commit

Permalink
Merge pull request #911 from bechenard/TimePhiClusterFinder
Browse files Browse the repository at this point in the history
Time phi cluster finder
  • Loading branch information
brownd1978 authored Dec 16, 2022
2 parents 9656246 + 2eea351 commit 2469285
Show file tree
Hide file tree
Showing 7 changed files with 754 additions and 639 deletions.
131 changes: 131 additions & 0 deletions TrkPatRec/data/TimePhiCluster.weights.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0"?>
<MethodSetup Method="MLP::MLP">
<GeneralInfo>
<Info name="TMVA Release" value="4.2.1 [262657]"/>
<Info name="ROOT Release" value="6.16/00 [397312]"/>
<Info name="Creator" value="echenard"/>
<Info name="Date" value="Sat Dec 10 16:19:59 2022"/>
<Info name="Host" value="Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux"/>
<Info name="Dir" value="/home/echenard/TCF"/>
<Info name="Training events" value="16428"/>
<Info name="TrainingTime" value="2.81479330e+01"/>
<Info name="AnalysisType" value="Classification"/>
</GeneralInfo>
<Options>
<Option name="NCycles" modified="Yes">300</Option>
<Option name="HiddenLayers" modified="Yes">N</Option>
<Option name="NeuronType" modified="Yes">ReLU</Option>
<Option name="RandomSeed" modified="No">1</Option>
<Option name="EstimatorType" modified="No">CE</Option>
<Option name="NeuronInputType" modified="No">sum</Option>
<Option name="V" modified="Yes">False</Option>
<Option name="VerbosityLevel" modified="No">Default</Option>
<Option name="VarTransform" modified="Yes">Norm</Option>
<Option name="H" modified="Yes">True</Option>
<Option name="CreateMVAPdfs" modified="No">False</Option>
<Option name="IgnoreNegWeightsInTraining" modified="No">False</Option>
<Option name="TrainingMethod" modified="No">BP</Option>
<Option name="LearningRate" modified="No">2.000000e-02</Option>
<Option name="DecayRate" modified="No">1.000000e-02</Option>
<Option name="TestRate" modified="No">10</Option>
<Option name="EpochMonitoring" modified="No">False</Option>
<Option name="Sampling" modified="No">1.000000e+00</Option>
<Option name="SamplingEpoch" modified="No">1.000000e+00</Option>
<Option name="SamplingImportance" modified="No">1.000000e+00</Option>
<Option name="SamplingTraining" modified="No">True</Option>
<Option name="SamplingTesting" modified="No">False</Option>
<Option name="ResetStep" modified="No">50</Option>
<Option name="Tau" modified="No">3.000000e+00</Option>
<Option name="BPMode" modified="No">sequential</Option>
<Option name="BatchSize" modified="No">-1</Option>
<Option name="ConvergenceImprove" modified="No">1.000000e-30</Option>
<Option name="ConvergenceTests" modified="No">-1</Option>
<Option name="UseRegulator" modified="No">False</Option>
<Option name="UpdateLimit" modified="No">10000</Option>
<Option name="CalculateErrors" modified="No">False</Option>
<Option name="WeightRange" modified="No">1.000000e+00</Option>
</Options>
<Variables NVar="3">
<Variable VarIndex="0" Expression="var2" Label="var2" Title="R" Unit="mm" Internal="var2" Type="F" Min="-1.73173706e+02" Max="1.98663849e+02"/>
<Variable VarIndex="1" Expression="var3" Label="var3" Title="P" Unit="mm" Internal="var3" Type="F" Min="-3.13736010e+00" Max="3.14120722e+00"/>
<Variable VarIndex="2" Expression="var4" Label="var4" Title="T" Unit="mm" Internal="var4" Type="F" Min="-3.20384521e+01" Max="3.31112061e+01"/>
</Variables>
<Spectators NSpec="0"/>
<Classes NClass="2">
<Class Name="Signal" Index="0"/>
<Class Name="Background" Index="1"/>
</Classes>
<Transformations NTransformations="1">
<Transform Name="Normalize">
<Selection>
<Input NInputs="3">
<Input Type="Variable" Label="var2" Expression="var2"/>
<Input Type="Variable" Label="var3" Expression="var3"/>
<Input Type="Variable" Label="var4" Expression="var4"/>
</Input>
<Output NOutputs="3">
<Output Type="Variable" Label="var2" Expression="var2"/>
<Output Type="Variable" Label="var3" Expression="var3"/>
<Output Type="Variable" Label="var4" Expression="var4"/>
</Output>
</Selection>
<Class ClassIndex="0">
<Ranges>
<Range Index="0" Min="-1.7317370605468750e+02" Max="1.7058389282226562e+02"/>
<Range Index="1" Min="-1.8792338371276855e+00" Max="1.6014366149902344e+00"/>
<Range Index="2" Min="-2.5261230468750000e+01" Max="2.4981018066406250e+01"/>
</Ranges>
</Class>
<Class ClassIndex="1">
<Ranges>
<Range Index="0" Min="-1.6320797729492188e+02" Max="1.9866384887695312e+02"/>
<Range Index="1" Min="-3.1373600959777832e+00" Max="3.1412072181701660e+00"/>
<Range Index="2" Min="-3.2038452148437500e+01" Max="3.3111206054687500e+01"/>
</Ranges>
</Class>
<Class ClassIndex="2">
<Ranges>
<Range Index="0" Min="-1.7317370605468750e+02" Max="1.9866384887695312e+02"/>
<Range Index="1" Min="-3.1373600959777832e+00" Max="3.1412072181701660e+00"/>
<Range Index="2" Min="-3.2038452148437500e+01" Max="3.3111206054687500e+01"/>
</Ranges>
</Class>
</Transform>
</Transformations>
<MVAPdfs/>
<Weights>
<Layout NLayers="3">
<Layer Index="0" NNeurons="4">
<Neuron NSynapses="3">
2.8525778513986091e+00 -9.5229598879773236e-01 2.9330274142048509e+00
</Neuron>
<Neuron NSynapses="3">
1.1522500332927178e+01 -3.6221560790540130e-01 -1.1954539868310139e+01
</Neuron>
<Neuron NSynapses="3">
-2.2112106934820939e+00 9.2978819404300292e+00 -2.5935313650381846e+00
</Neuron>
<Neuron NSynapses="3">
-1.7692998546080208e+00 -1.0885405658857725e+00 -1.7668012990661688e+00
</Neuron>
</Layer>
<Layer Index="1" NNeurons="4">
<Neuron NSynapses="1">
-1.6284519977108367e+00
</Neuron>
<Neuron NSynapses="1">
-1.0894476182376776e+00
</Neuron>
<Neuron NSynapses="1">
-1.6243987907436743e+00
</Neuron>
<Neuron NSynapses="1">
1.5591149684011134e+00
</Neuron>
</Layer>
<Layer Index="2" NNeurons="1">
<Neuron NSynapses="0"/>
</Layer>
</Layout>
</Weights>
</MethodSetup>
28 changes: 13 additions & 15 deletions TrkPatRec/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,24 @@ TimeAndPhiClusterFinder : {
module_type : TimeAndPhiClusterFinder
ComboHitCollection : "makePH"
StrawHitFlagCollection : "FlagBkgHits:ComboHits"
CaloClusterCollection : "CaloClusterFromProtoCluster"
TimeClusterMVA : { MVAWeights : "Offline/TrkPatRec/data/TimeCluster3.weights.xml" }
CaloClusterCollection : "CaloClusterMaker"
HitSelectionBits : ["EnergySelection","TimeSelection","RadiusSelection"]
HitBackgroundBits : @local::PatRecBackground
MVATime : { MVAWeights : "Offline/TrkPatRec/data/TimePhiCluster.weights.xml" }
TestFlag : true
Tbin : 15.0
Pbin : 0.2
MinNSHits : 7
UseCaloCluster : false
CaloClusterMinE : 50.0
CaloClusterWeight : 10.0
T0Calculator : { }
AveragePitch : 0.6
WindowTime : 1
MinTimeYbin : 5
MaxTimeDT : 30.0
MaxTimeDTCal : 30.0
MinHitSplit : 30
MVAScoreCut : 0.75
Recover : true
DphiMaxReco : 1.2
AlgoAssignHits : 1
MinNSHits : 10
Tbin : 15.0
MinTimeYbin : 6
MaxTimeDT : 35.0
FilterMVA : true
MinCutMVA : 0.1
SplitPhi : true
MaxDeltaPhi : 0.3
MaxNdiff : 1
Diag : 0

DiagPlugin : {
Expand All @@ -98,6 +95,7 @@ TimeAndPhiClusterFinder : {

# specific time cluster finders for different particle hypotheses. The redundant Calo time offset should come from conditions FIXME!
# note these are helicity-independent
# NOt needed anymore for TimeAndPhiClusterFinder
TimeClusterFinderDe : {
@table::TimeClusterFinder
AveragePitch : 0.63 # signed
Expand Down
38 changes: 14 additions & 24 deletions TrkPatRec/inc/TimeAndPhiClusterFinder_types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,35 @@
#include "fhiclcpp/types/Sequence.h"
#include "TTree.h"

namespace art {
class Event;
};

namespace art {class Event;};

namespace mu2e {

class ComboHitCollection;

namespace TimeAndPhiClusterFinderTypes {

struct Config
{
fhicl::Atom<std::string> tool_type{ fhicl::Name("tool_type"), fhicl::Comment("Needed fot backward compatibility"), "" };
fhicl::Atom<bool> mcDiag{ fhicl::Name("MCDiag"), fhicl::Comment("Switch to perform MC diag"), true };
fhicl::Atom<art::InputTag> strawDigiMCCollection{ fhicl::Name("StrawDigiMCCollection"), fhicl::Comment("StrawDigiMC collection name"), "makeSD" };
struct Config{
fhicl::Atom<std::string> tool_type{ fhicl::Name("tool_type"), fhicl::Comment("Needed fot backward compatibility"), "" };
fhicl::Atom<bool> mcDiag{ fhicl::Name("MCDiag"), fhicl::Comment("Switch to perform MC diag"), true };
fhicl::Atom<art::InputTag> strawDigiMCCollection{ fhicl::Name("StrawDigiMCCollection"), fhicl::Comment("StrawDigiMC collection name"), "makeSD" };
};


struct Data_t {

enum {kMaxHits = 8192};
enum {kMaxHits = 8192};

const art::Event* event_;
const ComboHitCollection* chcol_;
const art::Event* event_;
const ComboHitCollection* chcol_;

Int_t iev_;
Int_t Nch_,chSel_[kMaxHits];
Int_t Ncal_;
Int_t nhit1_,nclu1_[kMaxHits],hitIdx1_[kMaxHits];
Int_t nhit2_,nclu2_[kMaxHits],hitIdx2_[kMaxHits];
Int_t nhit3_,nclu3_[kMaxHits],hitIdx3_[kMaxHits];
Float_t calTime_[kMaxHits], chTime_[kMaxHits], clu2Time_[kMaxHits],clu2Phi_[kMaxHits],clu2Rad_[kMaxHits];
Int_t nhitMVA_,icluMVA_, ncluMVA_[kMaxHits],hitIdxMVA_[kMaxHits],MVAsig_[kMaxHits],MVAsel_[kMaxHits];
Float_t MVAvar1_[kMaxHits],MVAvar2_[kMaxHits],MVAvar3_[kMaxHits],MVAvar4_[kMaxHits],MVAvar5_[kMaxHits];
Int_t iev_;
Int_t Nch_,chSel_[kMaxHits],chNhit_[kMaxHits],chPdg_[kMaxHits],chCrCode_[kMaxHits],chSimId_[kMaxHits];
Float_t chTime_[kMaxHits], chPhi_[kMaxHits],chRad_[kMaxHits],chX_[kMaxHits],chY_[kMaxHits],chZ_[kMaxHits];
Int_t nhit1_,nclu1_[kMaxHits],hitIdx1_[kMaxHits];
Int_t nhit2_,nclu2_[kMaxHits],hitIdx2_[kMaxHits];

void reset() {Nch_=nhit1_=nhit2_=nhit3_=nhitMVA_=icluMVA_=Ncal_=0;}
void reset() {Nch_=nhit1_=nhit2_=0;}
};

}
}

Expand Down
75 changes: 28 additions & 47 deletions TrkPatRec/src/TimeAndPhiClusterFinderDiag_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,69 +78,50 @@ namespace mu2e {
trkdiag_->Branch("iev", &data_->iev_, "iev/I");
trkdiag_->Branch("Nch", &data_->Nch_, "Nch/I");
trkdiag_->Branch("chSel", &data_->chSel_, "chSel[Nch]/I");
trkdiag_->Branch("chNhit", &data_->chNhit_, "chNhit[Nch]/I");
trkdiag_->Branch("chPdg", &data_->chPdg_, "chPdg[Nch]/I");
trkdiag_->Branch("chCrCode", &data_->chCrCode_, "chCrCode[Nch]/I");
trkdiag_->Branch("chSimId", &data_->chSimId_, "chSimId[Nch]/I");
trkdiag_->Branch("chTime", &data_->chTime_, "chTime[Nch]/F");
trkdiag_->Branch("Ncal", &data_->Ncal_, "Ncal/I");
trkdiag_->Branch("calTime", &data_->calTime_, "calTime[Ncal]/F");
trkdiag_->Branch("chPhi", &data_->chPhi_, "chPhi[Nch]/F");
trkdiag_->Branch("chRad", &data_->chRad_, "chRad[Nch]/F");
trkdiag_->Branch("chX", &data_->chX_, "chX[Nch]/F");
trkdiag_->Branch("chY", &data_->chY_, "chY[Nch]/F");
trkdiag_->Branch("chZ", &data_->chZ_, "chZ[Nch]/F");
trkdiag_->Branch("nhit1", &data_->nhit1_, "nhit1/I");
trkdiag_->Branch("hitIdx1", &data_->hitIdx1_, "hitIdx1[nhit1]/I");
trkdiag_->Branch("nclu1", &data_->nclu1_, "nclu1[nhit1]/I");
trkdiag_->Branch("nhit2", &data_->nhit2_, "nhit2/I");
trkdiag_->Branch("hitIdx2", &data_->hitIdx2_, "hitIdx2[nhit2]/I");
trkdiag_->Branch("nclu2", &data_->nclu2_, "nclu2[nhit2]/I");
trkdiag_->Branch("clu2Time", &data_->clu2Time_, "clu2Time[nhit2]/F");
trkdiag_->Branch("clu2Phi", &data_->clu2Phi_, "clu2Phi[nhit2]/F");
trkdiag_->Branch("clu2Rad", &data_->clu2Rad_, "clu2Rad[nhit2]/F");
trkdiag_->Branch("nhit3", &data_->nhit3_, "nhit3/I");
trkdiag_->Branch("hitIdx3", &data_->hitIdx3_, "hitIdx3[nhit3]/I");
trkdiag_->Branch("nclu3", &data_->nclu3_, "nclu3[nhit3]/I");
trkdiag_->Branch("nhitMVA", &data_->nhitMVA_, "nhitMVA/I");
trkdiag_->Branch("ncluMVA", &data_->ncluMVA_, "ncluMVA[nhitMVA]/I");
trkdiag_->Branch("hitIdxMVA", &data_->hitIdxMVA_, "hitIdxMVA[nhitMVA]/I");
trkdiag_->Branch("MVAsel", &data_->MVAsel_, "MVAsel[nhitMVA]/I");
trkdiag_->Branch("MVAsig", &data_->MVAsig_, "MVAsig[nhitMVA]/I");
trkdiag_->Branch("MVAvar1", &data_->MVAvar1_, "MVAvar1[nhitMVA]/F");
trkdiag_->Branch("MVAvar2", &data_->MVAvar2_, "MVAvar2[nhitMVA]/F");
trkdiag_->Branch("MVAvar3", &data_->MVAvar3_, "MVAvar3[nhitMVA]/F");
trkdiag_->Branch("MVAvar4", &data_->MVAvar4_, "MVAvar4[nhitMVA]/F");
trkdiag_->Branch("MVAvar5", &data_->MVAvar5_, "MVAvar5[nhitMVA]/F");

treeInit_ = true;
}


int TimeAndPhiClusterFinderDiag::fillHistograms(void* Data, int Mode)
{
data_ = static_cast<Data_t*>(Data);

// we need to set up the branches once the data_ structure has been allocated
if (!treeInit_) setupBranches();

// fix the MC truth for the MVA, and set MVAsel for conversion clusters
if (mcdiag_)
{
auto& mcdigis = *data_->event_->getValidHandle<StrawDigiMCCollection>(mcdigisTag_);

std::set<int> signalCluster;
for (int i=0;i<data_->nhitMVA_;++i)
{
std::vector<StrawDigiIndex> dids;
data_->chcol_->fillStrawDigiIndices(*data_->event_,data_->hitIdxMVA_[i],dids);
const StrawDigiMC& mcdigi = mcdigis.at(dids[0]);// taking 1st digi: is there a better idea??
const art::Ptr<SimParticle>& spp = mcdigi.earlyStrawGasStep()->simParticle();
int genId(-1);
if (spp->genParticle().isNonnull()) genId = spp->genParticle()->generatorId().id();
data_->MVAsig_[i] = genId;

data_->MVAsel_[i]=0;
if (genId==2) signalCluster.insert(data_->ncluMVA_[i]);
data_ = static_cast<Data_t*>(Data);

// we need to set up the branches once the data_ structure has been allocated
if (!treeInit_) setupBranches();

if (mcdiag_){
auto& mcdigis = *data_->event_->getValidHandle<StrawDigiMCCollection>(mcdigisTag_);

for (int ich=0; ich <data_->Nch_ ; ++ich){
std::vector<StrawDigiIndex> dids;
data_->chcol_->fillStrawDigiIndices(*data_->event_,ich,dids);
const StrawDigiMC& mcdigi = mcdigis.at(dids[0]);// taking 1st digi: is there a better idea??
const art::Ptr<SimParticle>& spp = mcdigi.earlyStrawGasStep()->simParticle();
data_->chPdg_[ich] = spp->pdgId();
data_->chCrCode_[ich] = spp->creationCode();
data_->chSimId_[ich] = spp->id().asInt();
}
}

for (int i=0;i<data_->nhitMVA_;++i)
if (signalCluster.find(data_->ncluMVA_[i]) != signalCluster.end()) data_->MVAsel_[i]=1;
}

trkdiag_->Fill();
return 0;
trkdiag_->Fill();
return 0;
}

}
Expand Down
Loading

0 comments on commit 2469285

Please sign in to comment.