@@ -76,8 +76,11 @@ Detector::Detector(Bool_t active)
7676 if (!mClassifierScaler ) {
7777 mClassifierScaler = new fastsim::processors::StandardScaler;
7878 }
79- if (!mModelScaler ) {
80- mModelScaler = new fastsim::processors::StandardScaler;
79+ if (!mModelScalerNeutron ) {
80+ mModelScalerNeutron = new fastsim::processors::StandardScaler;
81+ }
82+ if (!mModelScalerProton ) {
83+ mModelScalerProton = new fastsim::processors::StandardScaler;
8184 }
8285 auto eonScales = o2::zdc::fastsim::loadScales (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimClassifierScales );
8386 if (!eonScales.has_value ()) {
@@ -88,17 +91,30 @@ Detector::Detector(Bool_t active)
8891 mClassifierScaler ->setScales (eonScales->first , eonScales->second );
8992 mFastSimClassifier = new o2::zdc::fastsim::ConditionalModelSimulation (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimClassifierPath , 1 );
9093
91- if (o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPath .empty () && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScales .empty ()) {
92- auto modelScales = o2::zdc::fastsim::loadScales (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScales );
94+ if (o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPathNeutron .empty () && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesNeutron .empty ()) {
95+ auto modelScalesNeutron = o2::zdc::fastsim::loadScales (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesNeutron );
96+
97+ if (!modelScalesNeutron.has_value ()) {
98+ LOG (error) << " Error while reading model scales from: "
99+ << " '" << o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesNeutron << " '" ;
100+ LOG (error) << " FastSim module disabled" ;
101+ } else {
102+ mModelScalerNeutron ->setScales (modelScalesNeutron->first , modelScalesNeutron->second );
103+ mFastSimModelNeutron = new o2::zdc::fastsim::ConditionalModelSimulation (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPathNeutron , 1 );
104+ LOG (info) << " FastSim neutron module enabled" ;
105+ }
106+ }
107+ if (o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPathProton .empty () && !o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesProton .empty ()) {
108+ auto modelScalesProton = o2::zdc::fastsim::loadScales (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesProton );
93109
94- if (!modelScales .has_value ()) {
110+ if (!modelScalesProton .has_value ()) {
95111 LOG (error) << " Error while reading model scales from: "
96- << " '" << o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScales << " '" ;
112+ << " '" << o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelScalesProton << " '" ;
97113 LOG (error) << " FastSim module disabled" ;
98114 } else {
99- mModelScaler ->setScales (modelScales ->first , modelScales ->second );
100- mFastSimModel = new o2::zdc::fastsim::ConditionalModelSimulation (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPath , 1 );
101- LOG (info) << " FastSim module enabled" ;
115+ mModelScalerProton ->setScales (modelScalesProton ->first , modelScalesProton ->second );
116+ mFastSimModelProton = new o2::zdc::fastsim::ConditionalModelSimulation (o2::zdc::ZDCSimParam::Instance ().ZDCFastSimModelPathProton , 1 );
117+ LOG (info) << " FastSim proton module enabled" ;
102118 }
103119 }
104120 }
@@ -118,9 +134,11 @@ Detector::Detector(const Detector& rhs)
118134Detector::~Detector ()
119135{
120136 delete (mFastSimClassifier );
121- delete (mFastSimModel );
137+ delete (mFastSimModelNeutron );
138+ delete (mFastSimModelProton );
122139 delete (mClassifierScaler );
123- delete (mModelScaler );
140+ delete (mModelScalerNeutron );
141+ delete (mModelScalerProton );
124142}
125143#endif
126144
@@ -2470,7 +2488,7 @@ void Detector::FinishPrimary()
24702488
24712489#ifdef ZDC_FASTSIM_ONNX
24722490 // dump to file only if debugZDCFastSim is set to true
2473- if (o2::zdc::ZDCSimParam::Instance ().debugZDCFastSim && o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && mFastSimModel != nullptr && mFastSimClassifier != nullptr ) {
2491+ if (o2::zdc::ZDCSimParam::Instance ().debugZDCFastSim && o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && mFastSimModelNeutron != nullptr && mFastSimModelProton != nullptr && mFastSimClassifier != nullptr ) {
24742492 std::fstream output (" o2sim-FastSimResult" , std::fstream::out | std::fstream::app);
24752493 if (!output.is_open ()) {
24762494 LOG (error) << " Could not open file." ;
@@ -2498,7 +2516,7 @@ void Detector::BeginPrimary()
24982516 mCurrentPrincipalParticle = *stack->GetCurrentTrack ();
24992517
25002518#ifdef ZDC_FASTSIM_ONNX
2501- if (o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && mFastSimModel != nullptr && mFastSimClassifier != nullptr ) {
2519+ if (o2::zdc::ZDCSimParam::Instance ().useZDCFastSim && mFastSimModelNeutron != nullptr && mFastSimModelProton != nullptr && mFastSimClassifier != nullptr ) {
25022520 const std::vector<float > rawInput = {static_cast <float >(mCurrentPrincipalParticle .Energy ()),
25032521 static_cast <float >(mCurrentPrincipalParticle .Vx ()),
25042522 static_cast <float >(mCurrentPrincipalParticle .Vy ()),
@@ -2517,22 +2535,27 @@ void Detector::BeginPrimary()
25172535 mFastSimClassifier ->setInput (classifierInput);
25182536 mFastSimClassifier ->run ();
25192537 if (fastsim::processors::readClassifier (mFastSimClassifier ->getResult ()[0 ], 1 )[0 ]) {
2520- auto scaledModelParticle = mModelScaler ->scale (rawInput);
2521- if (!scaledModelParticle.has_value ()) {
2538+ auto scaledModelParticleNeutron = mModelScalerNeutron ->scale (rawInput);
2539+ auto scaledModelParticleProton = mModelScalerProton ->scale (rawInput);
2540+ if (!scaledModelParticleNeutron.has_value () || !scaledModelParticleProton.has_value ()) {
25222541 LOG (error) << " FastSimModule: error occurred on scaling" ;
25232542 } else {
2524- std::vector<std::vector<float >> modelInput = {fastsim::normal_distribution (0.0 , 1.0 , 10 ), std::move (*scaledModelParticle)};
2525- mFastSimModel ->setInput (modelInput);
2526- mFastSimModel ->run ();
2543+ std::vector<std::vector<float >> modelInputNeutron = {fastsim::normal_distribution (0.0 , 1.0 , 10 ), std::move (*scaledModelParticleNeutron)};
2544+ mFastSimModelNeutron ->setInput (modelInputNeutron);
2545+ mFastSimModelNeutron ->run ();
2546+ std::vector<std::vector<float >> modelInputProton = {fastsim::normal_distribution (0.0 , 1.0 , 10 ), std::move (*scaledModelParticleProton)};
2547+ mFastSimModelProton ->setInput (modelInputProton);
2548+ mFastSimModelProton ->run ();
25272549
25282550 if (o2::zdc::ZDCSimParam::Instance ().debugZDCFastSim ) {
2529- mFastSimResults .push_back (fastsim::processors::calculateChannels (mFastSimModel ->getResult ()[0 ], 1 )[0 ]);
2551+ mFastSimResults .push_back (fastsim::processors::calculateChannels (mFastSimModelNeutron ->getResult ()[0 ], 1 )[0 ]);
2552+ // TODO: same for protons
25302553 }
25312554
25322555 // produce hits from fast sim result
25332556 bool forward = mCurrentPrincipalParticle .Pz () > 0 .;
2534- FastSimToHits (mFastSimModel ->getResult ()[0 ], mCurrentPrincipalParticle , forward ? ZNA : ZNC );
2535- // TODO: call models for all detectors ZNA + ZPA
2557+ FastSimToHits (mFastSimModelNeutron ->getResult ()[0 ], mCurrentPrincipalParticle , forward ? ZNA : ZNC );
2558+ FastSimToHits ( mFastSimModelProton -> getResult ()[ 0 ], mCurrentPrincipalParticle , forward ? ZPA : ZPC );
25362559 }
25372560 } else if (o2::zdc::ZDCSimParam::Instance ().debugZDCFastSim ) {
25382561 mFastSimResults .push_back ({0 , 0 , 0 , 0 , 0 });
0 commit comments