Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] start to integrate TPC pixel readout #316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ILD/compact/ILD_common_v02/tpc10_01.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<readouts>
<readout name="TPCCollection">
<!-- fixme: for now DD4hep cannot handle signed values - side should actually be "-2" -->
<id>system:5,side:2,layer:9,module:8,sensor:8</id>
<id>system:5,side:-2,layer:9,module:8,sensor:8</id>
</readout>
</readouts>

Expand Down
6 changes: 5 additions & 1 deletion ILD/compact/ILD_l1_v01/ILD_l1_v01.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

<define>

<!-- use constant to chose between "pixel" or "pad" readout -->
<constant name="TPC_readoutType" type="string" value="pad" /> <!-- option can be "pixel", anything else is pad readout-->
<constant name="TPC_simulationMode" type="string" value="regular" /> <!--option "fast" for pixel readout, anything else is default -->

<include ref="top_defs_ILD_l1_v01.xml"/>
<include ref="../ILD_common_v01/top_defs_common_v01.xml"/>
<include ref="../ILD_common_v01/basic_defs.xml"/>
Expand Down Expand Up @@ -148,7 +152,7 @@
</readout>
<readout name="TPCCollection">
<!-- fixme: for now DD4hep cannot handle signed values - side should actually be "-2" -->
<id>system:5,side:2,layer:9,module:8,sensor:8</id>
<id>system:5,side:2,layer:17,module:20,sensor:8</id> <!-- extended for pixelTPC -->
</readout>
<readout name="SETCollection">
<!-- fixme: for now DD4hep cannot handle signed values - side should actually be "-2" -->
Expand Down
4 changes: 4 additions & 0 deletions ILD/compact/ILD_l6_v02/ILD_l6_v02.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

<define>

<!-- use constant to chose between "pixel" or "pad" readout -->
<constant name="TPC_readoutType" type="string" value="pixel" /> <!-- option can be "pixel", anything else is pad readout-->
<constant name="TPC_simulationMode" type="string" value="regular" /> <!--option "fast" for pixel readout, anything else is default -->

<include ref="top_defs_ILD_l6_v02.xml"/>
<include ref="../ILD_common_v02/top_defs_common_v02.xml"/>
<include ref="../ILD_common_v02/basic_defs.xml"/>
Expand Down
17 changes: 12 additions & 5 deletions detector/tracker/TPC10_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
const double dzTotal = theDetector.constant<double>("TPC_Ecal_Hcal_barrel_halfZ") * 2. ;
const double rInner = theDetector.constant<double>("TPC_inner_radius") ;
const double rOuter = theDetector.constant<double>("TPC_outer_radius") ;

//chose between pixel and pad readout
const std::string TPCReadoutType= theDetector.constantAsString("TPC_readoutType");
const bool pixelTPC = (TPCReadoutType=="pixel") ;



// Geometry parameters from the geometry environment and from the database
Expand All @@ -108,8 +113,10 @@ static Ref_t create_element(Detector& theDetector, xml_h e, SensitiveDetector se
// _gear_gas_material = material_TPC_Gas;
// #endif

//unused: const double sensitive_threshold_eV = db->fetchDouble("sensitive_threshold_eV") ;

if(pixelTPC) {
const double sensitive_threshold_eV = db->fetchDouble("sensitive_threshold_eV") ;
sens.setEnergyCutoff(sensitive_threshold_eV);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should come through filters in ddsim, and not here in the geometry.

}

// db->exec("SELECT * FROM `cathode`;");
// db->getTuple();
Expand Down Expand Up @@ -435,7 +442,7 @@ Material endplate_MaterialMix = theDetector.material( "TPC_endplate_mix" ) ;

for (int layer = 0; layer < numberPadRows; layer++) {

#if 1
if(!pixelTPC) {//padTPC
// create twice the number of rings as there are pads, producing an lower and upper part of the pad with the boundry between them the pad-ring centre

const double inner_lowerlayer_radius = rMin_Sensitive + (layer * (padHeight));
Expand Down Expand Up @@ -477,7 +484,7 @@ Material endplate_MaterialMix = theDetector.material( "TPC_endplate_mix" ) ;
lowerlayerLog.setSensitiveDetector(sens);
upperlayerLog.setSensitiveDetector(sens);

#else
} else if (pixelTPC) {
// create just one volume per pad ring

const double inner_radius = rMin_Sensitive + (layer * (padHeight) );
Expand Down Expand Up @@ -507,7 +514,7 @@ Material endplate_MaterialMix = theDetector.material( "TPC_endplate_mix" ) ;

layerLog.setSensitiveDetector(sens);

#endif
}
}

// Assembly of the TPC Readout
Expand Down
197 changes: 197 additions & 0 deletions plugins/InterpolatedHitGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* InterpolatedHitGenerator.h
*
* Created on: Oct 12, 2016
* Author: cligtenb
*/

#ifndef INTERPOLATEDHITGENERATOR_H_
#define INTERPOLATEDHITGENERATOR_H_

#include <functional>
#include <vector>
#include <cmath>
#include <algorithm>

//geant4
#include "G4ThreeVector.hh" //is actually a typedef of CLHEP::ThreeVector
#include "Randomize.hh"//also CLHEP

//root
#include "TRandom.h"
#include "TMath.h"


struct LinearVectorInterpolation {
LinearVectorInterpolation( G4ThreeVector x1, G4ThreeVector x2) :
_x1(x1),
_x2(x2)
{}
G4ThreeVector _x1, _x2;
G4ThreeVector operator()(double t) { //t is parameter between 0 and 1
return _x1+t*(_x2-_x1);//interpolate linearly
}
};

struct QuadraticVectorInterpolation {
//interpolate using momentum at second point
QuadraticVectorInterpolation( G4ThreeVector x1, G4ThreeVector x2, G4ThreeVector momentum) :
_x1(x1),
_x2(x2),
_mom(momentum)
{}
G4ThreeVector _x1, _x2, _mom;
G4ThreeVector operator()(double t) { //t is parameter between 0 and 1
G4ThreeVector vT=(_x2-_x1).mag()*_mom.unit();
return _x1+t*(2*(_x2-_x1)-vT)+t*t*(_x1-_x2+vT);//interpolate quadratically
}

};

struct AngleInterpolation {
//interpolate using momentum at angle between momenta
AngleInterpolation( G4ThreeVector x1, G4ThreeVector x2, G4ThreeVector p1, G4ThreeVector p2) :
_x1(x1),
_x2(x2),
_u1(p1.unit()),
_u2(p2.unit())
{}
G4ThreeVector _x1, _x2, _u1, _u2;
int sign(int x) {return x < 0 ? -1 : 1; }
G4ThreeVector operator()(double t) { //t is parameter between 0 and 1
G4ThreeVector pos {_x1};
G4ThreeVector difference {_x2-_x1};
//start with linear base
G4ThreeVector relativePos=t*difference;
//add dS factor in XY plane:
double dphi=_u1.deltaPhi(_u2); //phi difference between vectors
double L=difference.perp(); //point to point distance in XY plane
double dS=L/2*sin(dphi/2)/2;
//G4cout<<"ds="<<dS<<" L="<<L<<G4endl;
G4ThreeVector dSPos;
dSPos.setRhoPhiZ(
4*abs(dS)*t*(1-t), //quadratic function in t
difference.phi()-sign(dS)*M_PI/2, //orthogonal to difference
0);
return pos+relativePos+dSPos;
}

};

//Produce a new hit at each location with a given chance;
struct FlatMultipleHitFunction {
std::vector<double> recurrenceChance={0.1};
double previous=CLHEP::HepRandom::getTheEngine()->flat();
int multiplicity=0;
FlatMultipleHitFunction(double p) : recurrenceChance(1,p) {}
FlatMultipleHitFunction(std::vector<double> p) : recurrenceChance(p) {}
double operator() (int) {
if(CLHEP::HepRandom::getTheEngine()->flat()<recurrenceChance.at(multiplicity)) {
if(unsigned(multiplicity)<recurrenceChance.size()-1) ++multiplicity;
return previous;
} else {
multiplicity=0;
return previous=CLHEP::HepRandom::getTheEngine()->flat();
}
}
};

struct FlatHitFunction : FlatMultipleHitFunction {
FlatHitFunction() : FlatMultipleHitFunction(0) {};
};

struct LandauBasedHitFunction {
double mu, sigma;
int nhit=0;
double t;
LandauBasedHitFunction(double mu, double sigma) : mu(mu), sigma(sigma) {};
double operator() (int) {
if(nhit<=0) {
while ( !(nhit=int(gRandom->Landau(mu, sigma))) ) {};//draw number until different from zero
t=CLHEP::HepRandom::getTheEngine()->flat();
}
--nhit;
return t;
}
};

//generate a y=x like distribution for the number of hits
struct TriangularHitFunction {
double triangleFraction;
int nHitAtSame=0;
double t=0;
TriangularHitFunction(double triangleFraction=0.1) : triangleFraction(triangleFraction) {}
double operator() (int nHitRemaining) {
if(nHitAtSame<=0) {
double y=0;//under treshold is poisson=always one hit
// if(nHitRemaining<treshold) {
// if(nHitRemaining>10) {
// nHitAtSame=1;
// }
// const int startTrans=10; //treshold = slope length
// if(gRandom->Rndm() < double(nHitRemaining-startTrans)/treshold ) {
if(gRandom->Rndm() < triangleFraction) { // chance on generating a triangular dist
// if(nHitRemaining>treshold){
// y=1;
y=TMath::Sqrt( gRandom->Rndm() );//y is a triangle between 0 and 1
// y= gRandom->Rndm() ;//flat instead!
}
const int minHits=0; //fix to 1?
nHitAtSame=int(minHits+(nHitRemaining-minHits)*y);
t=gRandom->Rndm();
}
--nHitAtSame;
return t;
}
};

class InterpolatedHitGenerator {
public:
InterpolatedHitGenerator(
std::function<double(int)> hitDistributionFunction, //e.g. [](int) { return CLHEP::HepRandom::getTheEngine()->flat(); }
std::function<G4ThreeVector(double)> hitLocationFunction); //e.g. LinearVectorInterpolation(x1,x2);
std::vector<G4ThreeVector> generateHits(int nHits);
std::vector<G4ThreeVector> interpolateHits(std::function<G4ThreeVector>);
std::vector<G4ThreeVector> generateFromFunction(
const std::function<G4ThreeVector(double)>& vectorFunction);

protected:
std::function<double(int)> _getHitDistribution; //return parameter between 0.-1, for location on track, takes number of remaining hits as parameter
std::function<G4ThreeVector(double)> _getHitLocation;
std::vector<double> _param; //param saves parameter used to generate hits such that the corresponding momentum can later be found.

};


InterpolatedHitGenerator::InterpolatedHitGenerator(
std::function<double(int)> hitDistributionFunction,
std::function<G4ThreeVector(double)> hitLocationFunction) :
_getHitDistribution(hitDistributionFunction),
_getHitLocation(hitLocationFunction)
{}

std::vector<G4ThreeVector> InterpolatedHitGenerator::generateFromFunction(
const std::function<G4ThreeVector(double)>& vectorFunction) {
//generate hits
std::vector<G4ThreeVector> hits;
hits.reserve(_param.size());
for (double t : _param) {
hits.push_back(vectorFunction(t));
}
return hits;
}

std::vector<G4ThreeVector> InterpolatedHitGenerator::generateHits(int nHits) {
//first generate the parameter, such that hits can be easily placed in order
_param.reserve(nHits);
for(int i=0; i<nHits; i++) {
_param.push_back( _getHitDistribution(nHits-i) );
}
//sort
std::sort(_param.begin(), _param.end());
//generate hits
std::vector<G4ThreeVector> hits = generateFromFunction(_getHitLocation);
return hits;
}

#endif /* INTERPOLATEDHITGENERATOR_H_ */
Loading