Skip to content
Snippets Groups Projects
Unverified Commit f5124078 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn Committed by GitHub
Browse files

Merge pull request #235 from fucd/field

WIP: non-uniform magnetic field
parents bab1f566 4fd43b85
No related branches found
No related tags found
No related merge requests found
,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8
0,0,0.00072238,0.00141836,0.00207148,0.00267135,0.00321527,0.00370693,0.00415367,0.00456403,0.00494571,0.00530457,0.00564426,0.00596631,0.0062705,0.00655513,0.00681818,0.00705771,0.00732861,0.00810929
0.1,0,0.00146197,0.00286741,0.00418194,0.00538432,0.00647049,0.00744939,0.00833756,0.00915321,0.00991255,0.01062748,0.01130531,0.01194895,0.01255775,0.01312817,0.01365485,0.0141346,0.01459255,0.01554511
0.2,0,0.00299748,0.00586624,0.00852836,0.01094282,0.01310558,0.01504385,0.01679673,0.01840687,0.0199088,0.02132748,0.02267685,0.02396242,0.02518188,0.02632737,0.02738665,0.02834344,0.02917975,0.0297083
0.3,0,0.00470406,0.00916282,0.01324734,0.01687741,0.02009235,0.02293873,0.02550271,0.02785864,0.03007062,0.03216839,0.03417707,0.03610186,0.03793614,0.03966636,0.04127328,0.0427277,0.0439612,0.04473902
0.4,-0.00000647,0.00664673,0.01294727,0.01853694,0.02342833,0.02766724,0.03135658,0.0346236,0.03762847,0.04046865,0.04320808,0.0458611,0.04842299,0.05087912,0.05320893,0.05538617,0.05738196,0.05915243,0.06079397
0.5,-0.00000753,0.0093127,0.01763368,0.02493902,0.03105909,0.03608541,0.04029972,0.04410349,0.04768399,0.05113054,0.05449101,0.05777605,0.06097232,0.0640623,0.06701241,0.06978611,0.07235239,0.07473295,0.0768376
0.6,-0.00000589,0.01285906,0.02432863,0.03345808,0.04053062,0.04591404,0.05036601,0.05437551,0.05823045,0.06212425,0.06603374,0.06993371,0.07378217,0.07753199,0.0811289,0.08452695,0.08768658,0.09055379,0.09345266
0.7,-0.00001818,0.01897127,0.03418009,0.04560011,0.05281641,0.05740905,0.06123209,0.06509765,0.06921145,0.07346395,0.07789282,0.08238071,0.0868928,0.09132841,0.09560674,0.0996668,0.10344551,0.10688772,0.1094982
0.8,0.00017943,0.02721068,0.05488351,0.06640383,0.06919675,0.07087947,0.07329664,0.07650002,0.08044778,0.08499199,0.0898992,0.09508866,0.10031511,0.1054739,0.11049698,0.11526844,0.1197168,0.12378965,0.12742038
0.9,0.01131628,0.09964188,0.10956434,0.09523256,0.08783426,0.08543011,0.08570056,0.08801099,0.09185151,0.09665147,0.10215635,0.1080128,0.11402253,0.12001919,0.12585215,0.13140119,0.13657321,0.14130417,0.14599683
1,0.0123671,0.30322555,0.21825395,0.13134489,0.11117667,0.10138317,0.09856821,0.09950552,0.10304793,0.1082858,0.11448423,0.12115218,0.12806483,0.13499432,0.14172577,0.14814184,0.15410985,0.15952363,0.16392705
1.1,-0.0130006,0.81867829,0.31323294,0.17470945,0.14281412,0.1172797,0.11038319,0.11012807,0.11366068,0.11965809,0.12674095,0.13453239,0.1424621,0.15041161,0.15816834,0.16556992,0.17246392,0.17863443,0.18396849
1.2,-0.0229895,0.93538797,0.46957454,0.23912773,0.16118861,0.12885932,0.11926629,0.11930251,0.12397495,0.13088178,0.13917771,0.14794117,0.15714058,0.1663046,0.17522892,0.18375358,0.19173635,0.19902265,0.20514923
1.3,-0.01855092,0.48878047,0.39570774,0.21783572,0.14628804,0.12719277,0.1244525,0.12673939,0.13266682,0.14132752,0.1509941,0.16155572,0.17221989,0.18271251,0.19296685,0.20274364,0.21194262,0.22056561,0.22852649
1.4,0.0001534,0.61056539,0.22481189,0.15686994,0.12208722,0.12103158,0.12341572,0.1312666,0.14044614,0.15121053,0.16330192,0.17541998,0.18760352,0.19975484,0.211436,0.22260322,0.23308339,0.24285057,0.25312152
1.5,0.00007495,0.22857647,0.11926743,0.12824678,0.10299139,0.1138839,0.12406379,0.13519351,0.14790416,0.16150443,0.17522457,0.1894441,0.20354108,0.21735608,0.23071957,0.24344031,0.25529341,0.26606367,0.27585775
1.6,-0.00010149,-0.02566563,0.13180144,0.09216303,0.09393796,0.10978737,0.12344628,0.13875879,0.15454946,0.17083052,0.18742221,0.20381937,0.2201136,0.23576992,0.25099247,0.26534345,0.27884519,0.2909712,0.30117348
1.7,-0.00023463,0.03542866,0.00826892,0.0293468,0.07075312,0.10064326,0.12197606,0.14230222,0.16183629,0.18109952,0.20002048,0.21870015,0.23677882,0.25481145,0.27194845,0.28851309,0.3038795,0.3181035,0.33064435
1.8,0.00266113,-0.1083805,-0.04846637,-0.00185282,0.05428142,0.09184384,0.12142219,0.14631224,0.16958781,0.1915702,0.21306046,0.23400751,0.25476344,0.27460806,0.29417531,0.31269297,0.33038118,0.34699276,0.36319102
1.9,0.00866707,-0.75826116,-0.16385417,-0.02638878,0.03737719,0.08554504,0.12285399,0.15138835,0.17764276,0.20246647,0.22648528,0.24987969,0.27268593,0.29528103,0.31704459,0.33821854,0.35836124,0.37715912,0.39453256
2,-0.01028629,-0.84166325,-0.27516465,-0.04932607,0.03169354,0.09161905,0.12744717,0.15835233,0.18706874,0.21441486,0.24039237,0.26605301,0.29141355,0.31634381,0.34090269,0.36472764,0.38763394,0.40901008,0.42806931
2.1,-0.02345212,-0.71040417,-0.12480799,-0.01011505,0.04757865,0.10347055,0.13577915,0.16723645,0.19733806,0.22620832,0.25454209,0.28241604,0.31023706,0.33793591,0.36537642,0.39210751,0.41815286,0.44323329,0.46554539
2.2,0.04080456,0.04226858,-0.00078258,0.01048593,0.05762617,0.11188833,0.14459982,0.17659737,0.20787331,0.23848516,0.26902316,0.29876896,0.32841727,0.36007475,0.39038007,0.42062969,0.44952508,0.47982482,0.51122804
2.3,-0.00060695,0.00780579,0.03477412,0.03449414,0.04893474,0.10802297,0.14912835,0.18036347,0.21372361,0.24592588,0.27777672,0.31122163,0.34693402,0.37919576,0.41359103,0.44954674,0.48620949,0.516638,0.55516713
,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8
0,2.98254375,2.98318937,2.98547167,2.98899442,2.99374132,2.99961886,3.00652732,3.01437409,3.02307982,3.03257973,3.0428217,3.05376278,3.06536515,3.07759241,3.09040663,3.10376663,3.11764635,3.1322132,3.14750674
0.1,2.98109899,2.98175883,2.9840892,2.98767855,2.99250257,2.99845884,3.00544098,3.01335272,3.02211376,3.0316603,3.04194227,3.05291904,3.06455505,3.07681584,3.08966473,3.10306094,3.11695014,3.13125837,3.14695687
0.2,2.97669588,2.97740238,2.97988968,2.98369431,2.98876474,2.99496905,3.00217997,3.01029042,3.0192184,3.02890417,3.03930467,3.05038681,3.06212207,3.07448198,3.08743474,3.10094015,3.11494236,3.12912079,3.14515215
0.3,2.96910905,2.96990752,2.97270436,2.97692716,2.98246308,2.98912314,2.99674135,3.00519553,3.01440385,3.02431862,3.03491123,3.0461631,3.05805801,3.07057825,3.08370024,3.09739453,3.11161525,3.12652478,3.14114769
0.4,2.95790006,2.95886479,2.96221313,2.96717546,2.97349577,2.98087865,2.98913349,2.99809283,3.00769228,3.01791665,3.02876844,3.04024247,3.05234864,3.06508339,3.07843296,3.09237751,3.1069152,3.12198926,3.1366115
0.5,2.94243158,2.94347691,2.94786359,2.95411488,2.96176669,2.97015463,2.97940277,2.98902944,2.99913374,3.00971108,3.02088486,3.03261413,3.04497303,3.05796775,3.07159454,3.08583906,3.10067846,3.1161207,3.13094287
0.6,2.92094761,2.92246038,2.92872698,2.9372441,2.94699778,2.95714022,2.96764351,2.97814264,2.98880074,2.99976326,3.01127211,3.02326221,3.0359063,3.04919134,3.06313922,3.07773566,3.09292699,3.10868421,3.1244398
0.7,2.89064164,2.89309777,2.9030216,2.91587173,2.92916445,2.94201055,2.95415218,2.96563002,2.9767351,2.98808544,2.9999004,3.01215538,3.02512561,3.03869621,3.05301365,3.06801461,3.083694,3.09974359,3.11559875
0.8,2.84359314,2.84976659,2.86839028,2.88886517,2.90865565,2.92572711,2.93949461,2.95160087,2.96318284,2.97471894,2.98673052,2.99929833,3.0125135,3.02643358,3.04114725,3.05661202,3.0727791,3.09005281,3.10558271
0.9,2.79377195,2.79484734,2.81169347,2.8555578,2.88918856,2.90960141,2.9241453,2.93657548,2.94802672,2.95977126,2.97171818,2.98454606,2.99799764,3.01233191,3.02743736,3.04343022,3.06021239,3.07737665,3.09574487
1,2.0535586,2.54472074,2.74173407,2.84947422,2.876516,2.89449246,2.90861048,2.92050954,2.9315521,2.94296308,2.95492102,2.96770859,2.98154662,2.99619258,3.01179073,3.02837584,3.04580913,3.06404436,3.08274544
1.1,-0.03347429,2.28387737,2.78580819,2.85570683,2.87165377,2.8817725,2.89303944,2.90344406,2.91357043,2.92442137,2.93585694,2.94880619,2.96290759,2.97791834,2.99404928,3.01129936,3.029572,3.04881589,3.06767787
1.2,-2.83937519,2.87734798,3.02485748,2.86942174,2.86874145,2.87052332,2.87716174,2.88513562,2.89372698,2.90345868,2.91473407,2.9275138,2.94197698,2.95729219,2.97404537,2.99201004,3.01119216,3.03151131,3.05153552
1.3,-3.69765888,2.58057627,3.02821863,2.88738109,2.86932003,2.86205042,2.86000272,2.86499069,2.87163865,2.87983486,2.89089361,2.90376024,2.91837852,2.93421113,2.95157652,2.97029736,2.99034153,3.01198579,3.03418575
1.4,-3.79899166,-0.47892673,3.13566838,2.91113876,2.88664502,2.84969876,2.84019214,2.83916989,2.84528126,2.85343453,2.86393496,2.87724142,2.89200306,2.90843409,2.92645823,2.94600774,2.966883,2.98897154,3.01568605
1.5,-3.81052656,-0.60812881,2.98139683,2.91195237,2.87195812,2.82828197,2.8136639,2.81063727,2.81562642,2.82350832,2.83437979,2.84756355,2.86266308,2.87963631,2.89854369,2.91897372,2.94096453,2.96348955,2.99259771
1.6,-3.96050739,-0.7731603,3.12235101,2.8808503,2.84101603,2.80294502,2.78022688,2.77826142,2.78243026,2.79018237,2.80103121,2.81463616,2.83007497,2.84771231,2.86750718,2.88898777,2.91235399,2.93780291,2.96061481
1.7,-4.02599445,-0.93592331,2.89647078,2.82089094,2.76282035,2.75353776,2.74261542,2.74084514,2.74476447,2.75288815,2.76418066,2.77796882,2.79422958,2.81248555,2.83298022,2.8557321,2.88049262,2.90786297,2.93134384
1.8,-3.87968428,-0.83325284,2.86203808,2.75420373,2.70226483,2.70221165,2.69862684,2.6982541,2.70294435,2.71170193,2.72341528,2.73781958,2.75460121,2.77361869,2.79494731,2.8186598,2.84476997,2.87308853,2.9021298
1.9,-3.14971335,-0.35968446,2.82790469,2.67604145,2.64888583,2.6528447,2.64851541,2.6516181,2.65730121,2.66681706,2.67899248,2.69393163,2.71110006,2.73084567,2.75300787,2.7776393,2.80500933,2.83419274,2.86793361
2,-2.3023104,-0.22353596,2.61967494,2.5937405,2.59182482,2.59859145,2.59510427,2.60018043,2.60797762,2.61842573,2.63083054,2.64615837,2.66375681,2.68386971,2.70678236,2.73242961,2.76091048,2.79267313,2.82456839
2.1,0.32933266,0.44186465,2.46969787,2.50079108,2.52435322,2.54190753,2.53942484,2.54601671,2.55516344,2.56649507,2.57916145,2.59453011,2.61225552,2.63264638,2.65596904,2.68241859,2.71217202,2.74579311,2.77807088
2.2,0.19143149,0.203763,2.4800973,2.4492233,2.46665427,2.48551649,2.4810036,2.48932808,2.49926241,2.51088011,2.52425068,2.53911646,2.55651669,2.5767344,2.60032566,2.62728555,2.65755481,2.69306386,2.73026936
2.3,0.02797829,0.28282052,2.44391037,2.41509089,2.41246836,2.41538895,2.42029371,2.42996001,2.44075216,2.45197615,2.46501328,2.48036927,2.49567035,2.51567342,2.53957983,2.56657511,2.59683019,2.6306168,2.67158842
<?xml version="1.0" encoding="UTF-8"?>
<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
<info name="CRD_o1_v01"
title="CepC reference detctor with coil inside Hcal, pixel SIT/SET"
author="C.D.Fu, "
url="http://cepc.ihep.ac.cn"
status="developing"
version="v01">
<comment>CepC reference detector simulation models used for detector study </comment>
</info>
<includes>
<gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/>
<gdmlFile ref="../CRD_common_v01/materials.xml"/>
</includes>
<define>
<constant name="world_size" value="25*m"/>
<constant name="world_x" value="world_size"/>
<constant name="world_y" value="world_size"/>
<constant name="world_z" value="world_size"/>
<include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/>
</define>
<include ref="./CRD_Dimensions_v01_01.xml"/>
<include ref="../CRD_common_v01/Beampipe_v01_01.xml"/>
<include ref="../CRD_common_v01/VXD_v01_01.xml"/>
<include ref="../CRD_common_v01/FTD_SkewRing_v01_01.xml"/>
<include ref="../CRD_common_v01/SIT_SimplePixel_v01_01.xml"/>
<include ref="../CRD_common_v01/DC_Simple_v01_02.xml"/>
<include ref="../CRD_common_v01/SET_SimplePixel_v01_01.xml"/>
<fields>
<field name="Non-uniformFieldMap" type="GenericBFieldMapBrBz" lunit="m" bunit="tesla"
provider="file">
<!--source url="Br=/tmp/lint/CEPCSW/Br.csv;Bz=/tmp/lint/CEPCSW/fieldmap.csv"/-->
<!--must include absolute path or relative to path to run job-->
<source url="Br=Detector/DetCRD/compact/CRD_o1_v01/Br1.csv;Bz=Detector/DetCRD/compact/CRD_o1_v01/Bz.csv"/>
</field>
</fields>
</lccdd>
...@@ -209,6 +209,13 @@ bool FieldMapFileProvider::loadCSV(const std::string& fn, ...@@ -209,6 +209,13 @@ bool FieldMapFileProvider::loadCSV(const std::string& fn,
std::ifstream input(fn); std::ifstream input(fn);
std::string tmpline; std::string tmpline;
if (!input) {
std::cout << "Open file failure: please check file name and path! " << std::endl;
std::cout << "Notice: need absolute path or relative to path to run job!" << std::endl;
std::string error_msg = "[ERROR] FieldMapFileProvider: Cannot open " + fn;
throw std::runtime_error(error_msg);
}
ncol = 0; ncol = 0;
nrow = 0; nrow = 0;
......
...@@ -19,10 +19,14 @@ void GenericBFieldMapBrBz::fieldComponents(const double* pos, double* field) { ...@@ -19,10 +19,14 @@ void GenericBFieldMapBrBz::fieldComponents(const double* pos, double* field) {
throw std::runtime_error(error_msg); throw std::runtime_error(error_msg);
} }
if (m_length_unit<=0||m_bfield_unit<=0) {
std::string error_msg = "[ERROR] GenericBFieldMapBrBz: Not set units or error (<0)! ";
throw std::runtime_error(error_msg);
}
// convert pos to r/z // convert pos to r/z
double x = pos[0] / dd4hep::m; // convert to meter double x = pos[0] / m_length_unit; // convert to length unit from input
double y = pos[1] / dd4hep::m; double y = pos[1] / m_length_unit;
double z = pos[2] / dd4hep::m; double z = pos[2] / m_length_unit;
double r = sqrt(x*x+y*y); double r = sqrt(x*x+y*y);
double phi = atan2(y, x); double phi = atan2(y, x);
...@@ -98,9 +102,9 @@ void GenericBFieldMapBrBz::fieldComponents(const double* pos, double* field) { ...@@ -98,9 +102,9 @@ void GenericBFieldMapBrBz::fieldComponents(const double* pos, double* field) {
+ rn * zn * Bz_r1z1; + rn * zn * Bz_r1z1;
// update the global field // update the global field
field[0] += Br*cos(phi); field[0] += Br*cos(phi)*m_bfield_unit; // convert to input unit
field[1] += Br*sin(phi); field[1] += Br*sin(phi)*m_bfield_unit;
field[2] += Bz; field[2] += Bz*m_bfield_unit;
return; return;
} }
...@@ -116,3 +120,9 @@ void GenericBFieldMapBrBz::init_provider(const std::string& provider, const std: ...@@ -116,3 +120,9 @@ void GenericBFieldMapBrBz::init_provider(const std::string& provider, const std:
throw std::runtime_error(error_msg); throw std::runtime_error(error_msg);
} }
} }
void GenericBFieldMapBrBz::init_unit(double l, double b) {
m_length_unit = l;
m_bfield_unit = b;
std::cout << "Initialize units to l = " << m_length_unit/dd4hep::m << " m" << ", b = " << m_bfield_unit/dd4hep::tesla << " tesla" << std::endl;
}
...@@ -26,9 +26,15 @@ public: ...@@ -26,9 +26,15 @@ public:
// following are interfaces to configure this field map // following are interfaces to configure this field map
void init_provider(const std::string& provider, const std::string& url); void init_provider(const std::string& provider, const std::string& url);
// set unit
void init_unit(double l, double b);
private: private:
IFieldMapProvider* m_provider; IFieldMapProvider* m_provider;
double m_length_unit = 0;
double m_bfield_unit = 0;
}; };
#endif #endif
......
...@@ -70,6 +70,19 @@ static dd4hep::Ref_t create_GenericBFieldMapBrBz(dd4hep::Detector& , ...@@ -70,6 +70,19 @@ static dd4hep::Ref_t create_GenericBFieldMapBrBz(dd4hep::Detector& ,
ptr->init_provider(provider, url); ptr->init_provider(provider, url);
// set unit, default values will be m and tesla
double lunit = dd4hep::m;
double bunit = dd4hep::tesla;
bool hasLunit = xmlParameter.hasAttr(_Unicode(lunit));
if (hasLunit) {
lunit = xmlParameter.attr<double>(_Unicode(lunit));
}
bool hasBunit = xmlParameter.hasAttr(_Unicode(bunit));
if (hasBunit) {
bunit = xmlParameter.attr<double>(_Unicode(bunit));
}
ptr->init_unit(lunit, bunit);
obj.assign(ptr, xmlParameter.nameStr(), xmlParameter.typeStr()); obj.assign(ptr, xmlParameter.nameStr(), xmlParameter.typeStr());
return obj; return obj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment