Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // Author: Ivana Hrivnacova, 26/08/2022 (ivan 27 // Author: Ivana Hrivnacova, 26/08/2022 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4AnalysisUtilities.hh" 29 #include "G4AnalysisUtilities.hh" 30 30 31 #include "G4UIdirectory.hh" 31 #include "G4UIdirectory.hh" 32 #include "G4UIcommand.hh" 32 #include "G4UIcommand.hh" 33 #include "G4UIparameter.hh" 33 #include "G4UIparameter.hh" 34 #include "G4Tokenizer.hh" 34 #include "G4Tokenizer.hh" 35 35 36 #include <vector> 36 #include <vector> 37 37 38 using namespace G4Analysis; 38 using namespace G4Analysis; 39 39 40 //____________________________________________ 40 //_____________________________________________________________________________ 41 template <unsigned int DIM, typename HT> 41 template <unsigned int DIM, typename HT> 42 G4THnMessenger<DIM, HT>::G4THnMessenger(G4THnT 42 G4THnMessenger<DIM, HT>::G4THnMessenger(G4THnToolsManager<DIM, HT>* manager) 43 : fManager(manager) 43 : fManager(manager) 44 { 44 { 45 CreateDirectory(); 45 CreateDirectory(); 46 46 47 CreateCmd(); 47 CreateCmd(); 48 SetCmd(); 48 SetCmd(); 49 for (unsigned int idim = 0; idim < DIM; ++id 49 for (unsigned int idim = 0; idim < DIM; ++idim) { 50 fSetDimensionCmd[idim] = CreateSetBinsComm 50 fSetDimensionCmd[idim] = CreateSetBinsCommand(idim); 51 } 51 } 52 52 53 DeleteCmd(); << 54 << 55 CreateSetTitleCommand(); 53 CreateSetTitleCommand(); 56 54 57 auto maxDim = (DIM < kMaxDim) ? DIM + 1 : kM << 55 for (unsigned int idim = 0; idim < DIM + 1; ++idim) { 58 for (unsigned int idim = 0; idim < maxDim; + << 59 fSetAxisCmd[idim] = CreateSetAxisCommand(i 56 fSetAxisCmd[idim] = CreateSetAxisCommand(idim); >> 57 fSetAxisLogCmd[idim] = CreateSetAxisLogCommand(idim); 60 } 58 } 61 59 62 CreateListCommand(); 60 CreateListCommand(); 63 CreateGetCommand(); 61 CreateGetCommand(); 64 CreateGetVectorCommand(); 62 CreateGetVectorCommand(); 65 63 66 // Initialize data 64 // Initialize data 67 for (unsigned int idim = 0; idim < DIM; ++id 65 for (unsigned int idim = 0; idim < DIM; ++idim) { 68 fTmpId[idim] = G4Analysis::kInvalidId; 66 fTmpId[idim] = G4Analysis::kInvalidId; 69 fTmpBins[idim] = G4HnDimension(); 67 fTmpBins[idim] = G4HnDimension(); 70 fTmpInfo[idim] = G4HnDimensionInformation( 68 fTmpInfo[idim] = G4HnDimensionInformation(); 71 } 69 } 72 } 70 } 73 71 74 // 72 // 75 // private functions 73 // private functions 76 // 74 // 77 75 78 //____________________________________________ 76 //_____________________________________________________________________________ 79 template <unsigned int DIM, typename HT> 77 template <unsigned int DIM, typename HT> 80 G4String G4THnMessenger<DIM, HT>::GetObjectTyp 78 G4String G4THnMessenger<DIM, HT>::GetObjectType() const 81 { 79 { 82 return (G4Analysis::IsProfile<HT>()) ? 80 return (G4Analysis::IsProfile<HT>()) ? 83 std::to_string(DIM - 1) + "D profile " : 81 std::to_string(DIM - 1) + "D profile " : std::to_string(DIM) + "D histogram"; 84 } 82 } 85 83 86 //____________________________________________ 84 //_____________________________________________________________________________ 87 template <unsigned int DIM, typename HT> 85 template <unsigned int DIM, typename HT> 88 G4bool G4THnMessenger<DIM, HT>::IsProfileLastD 86 G4bool G4THnMessenger<DIM, HT>::IsProfileLastDimension(unsigned int idim) const 89 { 87 { 90 return (idim == DIM - 1) && (G4Analysis::IsP 88 return (idim == DIM - 1) && (G4Analysis::IsProfile<HT>()); 91 } 89 } 92 90 93 //____________________________________________ 91 //_____________________________________________________________________________ 94 template <unsigned int DIM, typename HT> 92 template <unsigned int DIM, typename HT> 95 std::unique_ptr<G4UIcommand> G4THnMessenger<DI 93 std::unique_ptr<G4UIcommand> G4THnMessenger<DIM, HT>::CreateCommand( 96 G4String name, G4String guidance) 94 G4String name, G4String guidance) 97 { 95 { 98 G4String fullName = "/analysis/" + G4Analysi 96 G4String fullName = "/analysis/" + G4Analysis::GetHnType<HT>() + "/" + name; 99 G4String fullGuidance = guidance + GetObject 97 G4String fullGuidance = guidance + GetObjectType(); 100 98 101 auto command = std::make_unique<G4UIcommand> 99 auto command = std::make_unique<G4UIcommand>(fullName, this); 102 command->SetGuidance(fullGuidance); 100 command->SetGuidance(fullGuidance); 103 101 104 return command; 102 return command; 105 } 103 } 106 104 107 //____________________________________________ 105 //_____________________________________________________________________________ 108 template <unsigned int DIM, typename HT> 106 template <unsigned int DIM, typename HT> 109 void G4THnMessenger<DIM, HT>::CreateDimensionP 107 void G4THnMessenger<DIM, HT>::CreateDimensionParameters( 110 unsigned int idim, std::vector<G4UIparameter 108 unsigned int idim, std::vector<G4UIparameter*>& parameters) const 111 { 109 { 112 // Create [nbins], valMin, valMax, valUnit, va 110 // Create [nbins], valMin, valMax, valUnit, valFcn, [valBinScheme] parameters. 113 // The parameters in [] are omitted for the la 111 // The parameters in [] are omitted for the last dimension for profiles 114 112 115 std::string xyz{"xyz"}; 113 std::string xyz{"xyz"}; 116 std::string axis = xyz.substr(idim, 1); 114 std::string axis = xyz.substr(idim, 1); 117 115 118 if (! IsProfileLastDimension(idim)) { 116 if (! IsProfileLastDimension(idim)) { 119 auto parName = axis + "nBins"; 117 auto parName = axis + "nBins"; 120 auto guidance = 118 auto guidance = 121 std::string("Number of ") + axis + "-bin 119 std::string("Number of ") + axis + "-bins (default = 100)\n" 122 "Can be reset with /analysis/hn/set comm 120 "Can be reset with /analysis/hn/set command"; 123 121 124 auto param = new G4UIparameter(parName.c_s 122 auto param = new G4UIparameter(parName.c_str(), 'i', false); 125 param->SetGuidance(guidance.c_str()); 123 param->SetGuidance(guidance.c_str()); 126 param->SetDefaultValue(100); 124 param->SetDefaultValue(100); 127 parameters.push_back(param); 125 parameters.push_back(param); 128 } 126 } 129 127 130 auto parName = axis + "valMin"; 128 auto parName = axis + "valMin"; 131 auto guidance = 129 auto guidance = 132 std::string("Minimum ") + axis + "-value, 130 std::string("Minimum ") + axis + "-value, expressed in unit (default = 0.)\n" 133 "Can be reset with /analysis/hn/set comman 131 "Can be reset with /analysis/hn/set command"; 134 auto param = new G4UIparameter(parName.c_str 132 auto param = new G4UIparameter(parName.c_str(), 'd', false); 135 param->SetGuidance(guidance.c_str()); 133 param->SetGuidance(guidance.c_str()); 136 param->SetDefaultValue(0.); 134 param->SetDefaultValue(0.); 137 parameters.push_back(param); 135 parameters.push_back(param); 138 136 139 parName = axis + "valMax"; 137 parName = axis + "valMax"; 140 guidance = 138 guidance = 141 std::string("Maximum ") + axis + "-value, 139 std::string("Maximum ") + axis + "-value, expressed in unit (default = 1.)\n" 142 "Can be reset with /analysis/hn/set comman 140 "Can be reset with /analysis/hn/set command"; 143 param = new G4UIparameter(parName.c_str(), ' 141 param = new G4UIparameter(parName.c_str(), 'd', false); 144 param->SetGuidance(guidance.c_str()); 142 param->SetGuidance(guidance.c_str()); 145 param->SetDefaultValue(1.); 143 param->SetDefaultValue(1.); 146 parameters.push_back(param); 144 parameters.push_back(param); 147 145 148 parName = axis + "valUnit"; 146 parName = axis + "valUnit"; 149 guidance = 147 guidance = 150 std::string("The unit applied to filled ") 148 std::string("The unit applied to filled ") + axis + "-values and \n" 151 "Can be reset with /analysis/hn/set comman 149 "Can be reset with /analysis/hn/set command"; 152 param = new G4UIparameter(parName.c_str(), ' 150 param = new G4UIparameter(parName.c_str(), 's', true); 153 param->SetGuidance(guidance.c_str()); 151 param->SetGuidance(guidance.c_str()); 154 param->SetDefaultValue("none"); 152 param->SetDefaultValue("none"); 155 parameters.push_back(param); 153 parameters.push_back(param); 156 154 157 parName = axis + "valFcn"; 155 parName = axis + "valFcn"; 158 guidance = 156 guidance = 159 std::string("The function applied to fille 157 std::string("The function applied to filled ") + axis + "-values (log, log10, exp, none).\n" 160 "Note that the unit parameter cannot be om 158 "Note that the unit parameter cannot be omitted in this case,\n" 161 "but none value should be used instead."; 159 "but none value should be used instead."; 162 param = new G4UIparameter(parName.c_str(), ' 160 param = new G4UIparameter(parName.c_str(), 's', true); 163 param->SetGuidance(guidance.c_str()); 161 param->SetGuidance(guidance.c_str()); 164 param->SetParameterCandidates("log log10 exp 162 param->SetParameterCandidates("log log10 exp none"); 165 param->SetDefaultValue("none"); 163 param->SetDefaultValue("none"); 166 parameters.push_back(param); 164 parameters.push_back(param); 167 165 168 if (! IsProfileLastDimension(idim)) { 166 if (! IsProfileLastDimension(idim)) { 169 parName = axis + "valBinScheme"; 167 parName = axis + "valBinScheme"; 170 guidance = 168 guidance = 171 std::string("The binning scheme (linear 169 std::string("The binning scheme (linear, log).\n" 172 "Note that the unit and fcn parameters 170 "Note that the unit and fcn parameters cannot be omitted in this case,\n" 173 "but none value should be used instead. 171 "but none value should be used instead."); 174 param = new G4UIparameter(parName.c_str(), 172 param = new G4UIparameter(parName.c_str(), 's', true); 175 param->SetGuidance(guidance.c_str()); 173 param->SetGuidance(guidance.c_str()); 176 param->SetParameterCandidates("linear log" 174 param->SetParameterCandidates("linear log"); 177 param->SetDefaultValue("linear"); 175 param->SetDefaultValue("linear"); 178 parameters.push_back(param); 176 parameters.push_back(param); 179 } 177 } 180 } 178 } 181 179 182 //____________________________________________ 180 //_____________________________________________________________________________ 183 template <unsigned int DIM, typename HT> 181 template <unsigned int DIM, typename HT> 184 void G4THnMessenger<DIM, HT>::AddIdParameter(G 182 void G4THnMessenger<DIM, HT>::AddIdParameter(G4UIcommand& command) 185 { 183 { >> 184 // update guidance >> 185 // // TO DO: this will add a new guidance as a new line !! >> 186 // auto guidance = command.GetGuidanceLine(0); >> 187 // guidance += " of given id"; >> 188 // command.SetGuidance(guidance); >> 189 186 // add parameter 190 // add parameter 187 auto htId = new G4UIparameter("id", 'i', fal 191 auto htId = new G4UIparameter("id", 'i', false); 188 htId->SetGuidance("Histogram id"); 192 htId->SetGuidance("Histogram id"); 189 htId->SetParameterRange("id>=0"); 193 htId->SetParameterRange("id>=0"); 190 command.SetParameter(htId); 194 command.SetParameter(htId); 191 } 195 } 192 196 193 //____________________________________________ 197 //_____________________________________________________________________________ 194 template <unsigned int DIM, typename HT> 198 template <unsigned int DIM, typename HT> 195 G4String G4THnMessenger<DIM, HT>::GetTAddress( 199 G4String G4THnMessenger<DIM, HT>::GetTAddress(G4int id) const 196 { 200 { 197 auto ht = fManager->GetT(id); 201 auto ht = fManager->GetT(id); 198 if ( ht != nullptr ) { 202 if ( ht != nullptr ) { 199 std::ostringstream os; 203 std::ostringstream os; 200 os << static_cast<void*>(ht); 204 os << static_cast<void*>(ht); 201 return os.str(); 205 return os.str(); 202 } 206 } 203 return {}; 207 return {}; 204 } 208 } 205 209 206 //____________________________________________ 210 //_____________________________________________________________________________ 207 template <unsigned int DIM, typename HT> 211 template <unsigned int DIM, typename HT> 208 G4String G4THnMessenger<DIM, HT>::GetTVectorAd 212 G4String G4THnMessenger<DIM, HT>::GetTVectorAddress() const 209 { 213 { 210 auto htVector = fManager->GetTVector(); 214 auto htVector = fManager->GetTVector(); 211 if ( htVector != nullptr ) { 215 if ( htVector != nullptr ) { 212 std::ostringstream os; 216 std::ostringstream os; 213 os << static_cast<void*>(htVector); 217 os << static_cast<void*>(htVector); 214 return os.str(); 218 return os.str(); 215 } 219 } 216 return {}; 220 return {}; 217 } 221 } 218 222 219 //____________________________________________ 223 //_____________________________________________________________________________ 220 template <unsigned int DIM, typename HT> 224 template <unsigned int DIM, typename HT> 221 void G4THnMessenger<DIM, HT>::CreateDirectory( 225 void G4THnMessenger<DIM, HT>::CreateDirectory() const 222 { 226 { 223 G4String dirName = "/analysis/" + G4Analysis 227 G4String dirName = "/analysis/" + G4Analysis::GetHnType<HT>() + "/"; 224 G4String guidance = GetObjectType() + " cont 228 G4String guidance = GetObjectType() + " control"; 225 229 226 auto directory = std::make_unique<G4UIdirect 230 auto directory = std::make_unique<G4UIdirectory>(dirName); 227 directory->SetGuidance(guidance.c_str()); 231 directory->SetGuidance(guidance.c_str()); 228 } 232 } 229 233 230 //____________________________________________ 234 //_____________________________________________________________________________ 231 template <unsigned int DIM, typename HT> 235 template <unsigned int DIM, typename HT> 232 void G4THnMessenger<DIM, HT>::CreateCmd() 236 void G4THnMessenger<DIM, HT>::CreateCmd() 233 { 237 { 234 fCreateCmd = CreateCommand("create", "Create 238 fCreateCmd = CreateCommand("create", "Create "); 235 fCreateCmd->AvailableForStates(G4State_PreIn 239 fCreateCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 236 240 237 auto htName = new G4UIparameter("name", 's', 241 auto htName = new G4UIparameter("name", 's', false); 238 htName->SetGuidance("Histogram name (label)" 242 htName->SetGuidance("Histogram name (label)"); 239 fCreateCmd->SetParameter(htName); 243 fCreateCmd->SetParameter(htName); 240 244 241 auto htTitle = new G4UIparameter("title", 's 245 auto htTitle = new G4UIparameter("title", 's', false); 242 htTitle->SetGuidance("Histogram title"); 246 htTitle->SetGuidance("Histogram title"); 243 fCreateCmd->SetParameter(htTitle); 247 fCreateCmd->SetParameter(htTitle); 244 248 245 std::vector<G4UIparameter*> parameters; 249 std::vector<G4UIparameter*> parameters; 246 for (unsigned int idim = 0; idim < DIM; ++id 250 for (unsigned int idim = 0; idim < DIM; ++idim) { 247 CreateDimensionParameters(idim, parameters 251 CreateDimensionParameters(idim, parameters); 248 for (size_t ipar = 0; ipar < parameters.si 252 for (size_t ipar = 0; ipar < parameters.size(); ++ipar) { 249 // the first three parameters can be omi 253 // the first three parameters can be omittes in create command 250 if (ipar < 3) parameters[ipar]->SetOmitt 254 if (ipar < 3) parameters[ipar]->SetOmittable(true); 251 fCreateCmd->SetParameter(parameters[ipar 255 fCreateCmd->SetParameter(parameters[ipar]); 252 } 256 } 253 parameters.clear(); 257 parameters.clear(); 254 } 258 } 255 } 259 } 256 260 257 //____________________________________________ 261 //_____________________________________________________________________________ 258 template <unsigned int DIM, typename HT> 262 template <unsigned int DIM, typename HT> 259 void G4THnMessenger<DIM, HT>::SetCmd() 263 void G4THnMessenger<DIM, HT>::SetCmd() 260 { 264 { 261 fSetCmd = CreateCommand("set", "Set "); 265 fSetCmd = CreateCommand("set", "Set "); 262 fSetCmd->AvailableForStates(G4State_PreInit, 266 fSetCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 263 267 264 // Add Id parameter 268 // Add Id parameter 265 AddIdParameter(*fSetCmd); 269 AddIdParameter(*fSetCmd); 266 270 267 // Update guidance 271 // Update guidance 268 fSetCmd->SetGuidance("\n nbins; valMin; val 272 fSetCmd->SetGuidance("\n nbins; valMin; valMax; unit; function; binScheme"); 269 273 270 std::vector<G4UIparameter*> parameters; 274 std::vector<G4UIparameter*> parameters; 271 for (unsigned int idim = 0; idim < DIM; ++id 275 for (unsigned int idim = 0; idim < DIM; ++idim) { 272 CreateDimensionParameters(idim, parameters 276 CreateDimensionParameters(idim, parameters); 273 for (auto parameter: parameters) { 277 for (auto parameter: parameters) { 274 fSetCmd->SetParameter(parameter); 278 fSetCmd->SetParameter(parameter); 275 } 279 } 276 parameters.clear(); 280 parameters.clear(); 277 } 281 } 278 } 282 } 279 283 280 //____________________________________________ 284 //_____________________________________________________________________________ 281 template <unsigned int DIM, typename HT> 285 template <unsigned int DIM, typename HT> 282 void G4THnMessenger<DIM, HT>::DeleteCmd() << 283 { << 284 fDeleteCmd = CreateCommand("delete", "Delete << 285 fDeleteCmd->AvailableForStates(G4State_PreIn << 286 << 287 // Add Id parameter << 288 AddIdParameter(*fDeleteCmd); << 289 << 290 auto parKeepSetting = new G4UIparameter("kee << 291 G4String guidance = << 292 "If set true, activation, plotting, etc. o << 293 "and applied when a new object with the sa << 294 parKeepSetting->SetGuidance(guidance.c_str() << 295 parKeepSetting->SetDefaultValue("false"); << 296 fDeleteCmd->SetParameter(parKeepSetting); << 297 } << 298 << 299 //____________________________________________ << 300 template <unsigned int DIM, typename HT> << 301 std::unique_ptr<G4UIcommand> 286 std::unique_ptr<G4UIcommand> 302 G4THnMessenger<DIM, HT>::CreateSetBinsCommand( 287 G4THnMessenger<DIM, HT>::CreateSetBinsCommand(unsigned int idim) 303 { 288 { 304 G4String xyz{"XYZ"}; 289 G4String xyz{"XYZ"}; 305 auto axis = xyz.substr(idim, 1); 290 auto axis = xyz.substr(idim, 1); 306 291 307 auto command = CreateCommand("set" + axis, " 292 auto command = CreateCommand("set" + axis, "Set " + axis + " parameters for the "); 308 command->AvailableForStates(G4State_PreInit, 293 command->AvailableForStates(G4State_PreInit, G4State_Idle); 309 294 310 // Add Id parameter 295 // Add Id parameter 311 AddIdParameter(*command); 296 AddIdParameter(*command); 312 297 313 // Update guidance 298 // Update guidance 314 G4String guidance = 299 G4String guidance = 315 "\n nAXISbins; AXISvalMin; AXISvalMax; AX 300 "\n nAXISbins; AXISvalMin; AXISvalMax; AXISunit; AXISfunction; AXISbinScheme"; 316 // update AXIS with xyz 301 // update AXIS with xyz 317 std::string::size_type n = 0; 302 std::string::size_type n = 0; 318 std::string ts{"AXIS"}; 303 std::string ts{"AXIS"}; 319 while ( ( n = guidance.find(ts, n)) != std:: 304 while ( ( n = guidance.find(ts, n)) != std::string::npos ) { 320 guidance.replace(n, ts.size(), axis); 305 guidance.replace(n, ts.size(), axis); 321 n += ts.size(); 306 n += ts.size(); 322 } 307 } 323 command->SetGuidance(guidance); 308 command->SetGuidance(guidance); 324 309 325 std::vector<G4UIparameter*> parameters; 310 std::vector<G4UIparameter*> parameters; 326 CreateDimensionParameters(idim, parameters); 311 CreateDimensionParameters(idim, parameters); 327 for (auto parameter: parameters) { 312 for (auto parameter: parameters) { 328 command->SetParameter(parameter); 313 command->SetParameter(parameter); 329 } 314 } 330 315 331 return command; 316 return command; 332 } 317 } 333 318 334 //____________________________________________ 319 //_____________________________________________________________________________ 335 template <unsigned int DIM, typename HT> 320 template <unsigned int DIM, typename HT> 336 void G4THnMessenger<DIM, HT>::CreateSetTitleCo 321 void G4THnMessenger<DIM, HT>::CreateSetTitleCommand() 337 { 322 { 338 fSetTitleCmd = CreateCommand("setTitle", "Se 323 fSetTitleCmd = CreateCommand("setTitle", "Set title for the "); 339 fSetTitleCmd->AvailableForStates(G4State_Pre 324 fSetTitleCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 340 325 341 // Add Id parameter 326 // Add Id parameter 342 AddIdParameter(*fSetTitleCmd); 327 AddIdParameter(*fSetTitleCmd); 343 328 344 auto parTitle = new G4UIparameter("title", ' 329 auto parTitle = new G4UIparameter("title", 's', true); 345 auto guidance = GetObjectType() + " title"; 330 auto guidance = GetObjectType() + " title"; 346 parTitle->SetGuidance(guidance.c_str()); 331 parTitle->SetGuidance(guidance.c_str()); 347 parTitle->SetDefaultValue("none"); 332 parTitle->SetDefaultValue("none"); 348 fSetTitleCmd->SetParameter(parTitle); 333 fSetTitleCmd->SetParameter(parTitle); 349 } 334 } 350 335 351 //____________________________________________ 336 //_____________________________________________________________________________ 352 template <unsigned int DIM, typename HT> 337 template <unsigned int DIM, typename HT> 353 std::unique_ptr<G4UIcommand> 338 std::unique_ptr<G4UIcommand> 354 G4THnMessenger<DIM, HT>::CreateSetAxisCommand( 339 G4THnMessenger<DIM, HT>::CreateSetAxisCommand(unsigned int idim) 355 { 340 { 356 G4String xyz{"XYZ"}; 341 G4String xyz{"XYZ"}; 357 auto axis = xyz.substr(idim, 1); 342 auto axis = xyz.substr(idim, 1); 358 343 359 G4String commandName = "set" + axis + "axis" 344 G4String commandName = "set" + axis + "axis"; 360 G4String guidance = "Set " + axis + "-axis t 345 G4String guidance = "Set " + axis + "-axis title for the ";; 361 346 362 auto command = CreateCommand(std::move(comma << 347 auto command = CreateCommand(commandName, guidance); 363 command->AvailableForStates(G4State_PreInit, 348 command->AvailableForStates(G4State_PreInit, G4State_Idle); 364 349 365 // Add Id parameter 350 // Add Id parameter 366 AddIdParameter(*command); 351 AddIdParameter(*command); 367 352 368 auto parAxis = new G4UIparameter("axis", 's' 353 auto parAxis = new G4UIparameter("axis", 's', false); 369 guidance = GetObjectType() + " " + std::move << 354 guidance = GetObjectType() + " " + axis + "-axis title"; 370 parAxis->SetGuidance(guidance.c_str()); 355 parAxis->SetGuidance(guidance.c_str()); 371 command->SetParameter(parAxis); 356 command->SetParameter(parAxis); 372 357 373 return command; 358 return command; 374 } 359 } 375 360 376 //____________________________________________ 361 //_____________________________________________________________________________ 377 template <unsigned int DIM, typename HT> 362 template <unsigned int DIM, typename HT> >> 363 std::unique_ptr<G4UIcommand> >> 364 G4THnMessenger<DIM, HT>::CreateSetAxisLogCommand(unsigned int idim) >> 365 { >> 366 G4String xyz{"XYZ"}; >> 367 auto axis = xyz.substr(idim, 1); >> 368 >> 369 G4String commandName = "set" + axis + "axisLog"; >> 370 G4String guidance = "Activate " + axis + "-axis log scale for plotting of the "; >> 371 >> 372 auto command = CreateCommand(commandName, guidance); >> 373 command->AvailableForStates(G4State_PreInit, G4State_Idle); >> 374 >> 375 // Add Id parameter >> 376 AddIdParameter(*command); >> 377 >> 378 auto parAxisLog = new G4UIparameter("axis", 'b', false); >> 379 guidance = GetObjectType() + " " + axis + "-axis log scale"; >> 380 parAxisLog->SetGuidance(guidance.c_str()); >> 381 command->SetParameter(parAxisLog); >> 382 >> 383 return command; >> 384 } >> 385 >> 386 //_____________________________________________________________________________ >> 387 template <unsigned int DIM, typename HT> 378 void G4THnMessenger<DIM, HT>::CreateListComman 388 void G4THnMessenger<DIM, HT>::CreateListCommand() 379 { 389 { 380 fListCmd = CreateCommand("list", "List all/a 390 fListCmd = CreateCommand("list", "List all/activate "); 381 fListCmd->AvailableForStates(G4State_Idle, G 391 fListCmd->AvailableForStates(G4State_Idle, G4State_GeomClosed, G4State_EventProc); 382 392 383 auto parOnlyIfActive = new G4UIparameter("on 393 auto parOnlyIfActive = new G4UIparameter("onlyIfActive", 'b', true); 384 parOnlyIfActive->SetGuidance("Option whether 394 parOnlyIfActive->SetGuidance("Option whether to list only active objects"); 385 parOnlyIfActive->SetDefaultValue("true"); 395 parOnlyIfActive->SetDefaultValue("true"); 386 fListCmd->SetParameter(parOnlyIfActive); 396 fListCmd->SetParameter(parOnlyIfActive); 387 } 397 } 388 398 389 //____________________________________________ 399 //_____________________________________________________________________________ 390 template <unsigned int DIM, typename HT> 400 template <unsigned int DIM, typename HT> 391 void G4THnMessenger<DIM, HT>::CreateGetCommand 401 void G4THnMessenger<DIM, HT>::CreateGetCommand() 392 { 402 { 393 fGetTCmd = CreateCommand("get", "Get the add 403 fGetTCmd = CreateCommand("get", "Get the address of the "); 394 fGetTCmd->SetGuidance( "This command is only 404 fGetTCmd->SetGuidance( "This command is only for Geant4 internal use."); 395 fGetTCmd->AvailableForStates(G4State_Idle, G 405 fGetTCmd->AvailableForStates(G4State_Idle, G4State_GeomClosed, G4State_EventProc); 396 406 397 // Add Id parameter 407 // Add Id parameter 398 AddIdParameter(*fGetTCmd); 408 AddIdParameter(*fGetTCmd); 399 } 409 } 400 410 401 //____________________________________________ 411 //_____________________________________________________________________________ 402 template <unsigned int DIM, typename HT> 412 template <unsigned int DIM, typename HT> 403 void G4THnMessenger<DIM, HT>::CreateGetVectorC 413 void G4THnMessenger<DIM, HT>::CreateGetVectorCommand() 404 { 414 { 405 fGetTVectorCmd = CreateCommand("getVector", 415 fGetTVectorCmd = CreateCommand("getVector", "Get the address of the vector of the "); 406 fGetTVectorCmd->SetGuidance( "This command i 416 fGetTVectorCmd->SetGuidance( "This command is only for Geant4 internal use."); 407 fGetTVectorCmd->AvailableForStates(G4State_I 417 fGetTVectorCmd->AvailableForStates(G4State_Idle, G4State_GeomClosed, G4State_EventProc); 408 } 418 } 409 419 410 //____________________________________________ 420 //_____________________________________________________________________________ 411 template <unsigned int DIM, typename HT> 421 template <unsigned int DIM, typename HT> 412 void G4THnMessenger<DIM, HT>::GetBinData( 422 void G4THnMessenger<DIM, HT>::GetBinData( 413 unsigned int idim, G4int& counter, const std 423 unsigned int idim, G4int& counter, const std::vector<G4String>& parameters, 414 G4HnDimension& bins) const 424 G4HnDimension& bins) const 415 { 425 { 416 G4int nbins = (! IsProfileLastDimension(id 426 G4int nbins = (! IsProfileLastDimension(idim)) ? 417 G4UIcommand::ConvertToInt(parameters[cou 427 G4UIcommand::ConvertToInt(parameters[counter++]) : 0; 418 428 419 bins = {nbins, 429 bins = {nbins, 420 G4UIcommand::ConvertToDouble(param 430 G4UIcommand::ConvertToDouble(parameters[counter]), 421 G4UIcommand::ConvertToDouble(param 431 G4UIcommand::ConvertToDouble(parameters[counter + 1])}; 422 counter += 2; 432 counter += 2; 423 } 433 } 424 434 425 //____________________________________________ 435 //_____________________________________________________________________________ 426 template <unsigned int DIM, typename HT> 436 template <unsigned int DIM, typename HT> 427 void G4THnMessenger<DIM, HT>::GetBinInfoData( 437 void G4THnMessenger<DIM, HT>::GetBinInfoData( 428 unsigned int idim, G4int& counter, const std 438 unsigned int idim, G4int& counter, const std::vector<G4String>& parameters, 429 G4HnDimension& bins, G4HnDimensionInformatio 439 G4HnDimension& bins, G4HnDimensionInformation& info) const 430 { 440 { 431 // get bin data (this will shift the counter 441 // get bin data (this will shift the counter for hnInfo data) 432 GetBinData(idim, counter, parameters, bins); 442 GetBinData(idim, counter, parameters, bins); 433 443 434 // get dimension information data 444 // get dimension information data 435 if (! IsProfileLastDimension(idim)) { 445 if (! IsProfileLastDimension(idim)) { 436 info = {parameters[counter], parameters[co 446 info = {parameters[counter], parameters[counter + 1], parameters[counter + 2]}; 437 counter += 3; 447 counter += 3; 438 } 448 } 439 else { 449 else { 440 info = {parameters[counter], parameters[co 450 info = {parameters[counter], parameters[counter + 1]}; 441 counter += 2; 451 counter += 2; 442 } 452 } 443 453 444 // apply unit to minValue and maxValue 454 // apply unit to minValue and maxValue 445 bins.fMinValue *= info.fUnit; 455 bins.fMinValue *= info.fUnit; 446 bins.fMaxValue *= info.fUnit; 456 bins.fMaxValue *= info.fUnit; 447 } 457 } 448 458 449 //____________________________________________ 459 //_____________________________________________________________________________ 450 template <unsigned int DIM, typename HT> 460 template <unsigned int DIM, typename HT> 451 void G4THnMessenger<DIM, HT>::GetData( 461 void G4THnMessenger<DIM, HT>::GetData( 452 G4int& counter, const std::vector<G4String>& 462 G4int& counter, const std::vector<G4String>& parameters, 453 std::array<G4HnDimension, DIM>& bins, 463 std::array<G4HnDimension, DIM>& bins, 454 std::array<G4HnDimensionInformation, DIM>& i 464 std::array<G4HnDimensionInformation, DIM>& info) const 455 { 465 { 456 for (unsigned int idim = 0; idim < DIM; ++id 466 for (unsigned int idim = 0; idim < DIM; ++idim) { 457 // get bin data (this will shift the count 467 // get bin data (this will shift the counter for hnInfo data) 458 GetBinInfoData(idim, counter, parameters, 468 GetBinInfoData(idim, counter, parameters, bins[idim], info[idim]); 459 } 469 } 460 } 470 } 461 471 462 // 472 // 463 // public functions 473 // public functions 464 // 474 // 465 475 466 //____________________________________________ 476 //_____________________________________________________________________________ 467 template <unsigned int DIM, typename HT> 477 template <unsigned int DIM, typename HT> 468 G4String G4THnMessenger<DIM, HT>::GetCurrentVa 478 G4String G4THnMessenger<DIM, HT>::GetCurrentValue (G4UIcommand* command) 469 { 479 { 470 if ( command == fGetTCmd.get() ) return fTVa 480 if ( command == fGetTCmd.get() ) return fTValue; 471 481 472 if ( command == fGetTVectorCmd.get() ) retur 482 if ( command == fGetTVectorCmd.get() ) return fTVectorValue; 473 483 474 return ""; 484 return ""; 475 } 485 } 476 486 477 //____________________________________________ 487 //_____________________________________________________________________________ 478 template <unsigned int DIM, typename HT> 488 template <unsigned int DIM, typename HT> 479 void G4THnMessenger<DIM, HT>::SetNewValue(G4UI 489 void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValues) 480 { 490 { 481 // tokenize parameters in a vector 491 // tokenize parameters in a vector 482 std::vector<G4String> parameters; 492 std::vector<G4String> parameters; 483 G4Analysis::Tokenize(newValues, parameters); 493 G4Analysis::Tokenize(newValues, parameters); 484 // check consistency 494 // check consistency 485 if ( parameters.size() != command->GetParame 495 if ( parameters.size() != command->GetParameterEntries() ) { 486 // Should never happen but let's check any 496 // Should never happen but let's check anyway for consistency 487 G4Analysis::Warn( 497 G4Analysis::Warn( 488 "Got wrong number of \"" + command->GetC 498 "Got wrong number of \"" + command->GetCommandName() + 489 "\" parameters: " + to_string(parameters 499 "\" parameters: " + to_string(parameters.size()) + 490 " instead of " + to_string(command->GetP 500 " instead of " + to_string(command->GetParameterEntries()) + " expected", 491 fkClass, "WarnAboutParameters"); 501 fkClass, "WarnAboutParameters"); 492 return; 502 return; 493 } 503 } 494 504 495 std::array<G4HnDimension, DIM> bins; 505 std::array<G4HnDimension, DIM> bins; 496 std::array<G4HnDimensionInformation, DIM> in 506 std::array<G4HnDimensionInformation, DIM> info; 497 507 498 if ( command == fCreateCmd.get() ) { 508 if ( command == fCreateCmd.get() ) { 499 auto counter = 0; 509 auto counter = 0; 500 const auto& name = parameters[counter++]; << 510 auto name = parameters[counter++]; 501 const auto& title = parameters[counter++]; << 511 auto title = parameters[counter++]; 502 GetData(counter, parameters, bins, info); 512 GetData(counter, parameters, bins, info); 503 fManager->Create(name, title, bins, info); 513 fManager->Create(name, title, bins, info); 504 return; 514 return; 505 } 515 } 506 516 507 if ( command == fSetCmd.get() ) { 517 if ( command == fSetCmd.get() ) { 508 auto counter = 0; 518 auto counter = 0; 509 const auto& id = G4UIcommand::ConvertToInt << 519 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 510 GetData(counter, parameters, bins, info); 520 GetData(counter, parameters, bins, info); 511 fManager->Set(id, bins, info); 521 fManager->Set(id, bins, info); 512 return; 522 return; 513 } 523 } 514 524 515 if ( command == fDeleteCmd.get() ) { << 516 auto counter = 0; << 517 const auto& id = G4UIcommand::ConvertToInt << 518 const auto& keepSetting = G4UIcommand::Con << 519 fManager->Delete(id, keepSetting); << 520 return; << 521 } << 522 << 523 if ( command == fSetTitleCmd.get() ) { 525 if ( command == fSetTitleCmd.get() ) { 524 auto counter = 0; 526 auto counter = 0; 525 const auto& id = G4UIcommand::ConvertToInt << 527 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 526 const auto& title = parameters[counter++]; << 528 auto title = parameters[counter++]; 527 fManager->SetTitle(id, title); 529 fManager->SetTitle(id, title); 528 return; 530 return; 529 } 531 } 530 532 531 for (unsigned int idim = 0; idim < DIM; ++id 533 for (unsigned int idim = 0; idim < DIM; ++idim) { 532 if ( command == fSetDimensionCmd[idim].get 534 if ( command == fSetDimensionCmd[idim].get() ) { 533 auto counter = 0; 535 auto counter = 0; 534 fTmpId[idim] = G4UIcommand::ConvertToInt 536 fTmpId[idim] = G4UIcommand::ConvertToInt(parameters[counter++]); 535 GetBinInfoData(idim, counter, parameters 537 GetBinInfoData(idim, counter, parameters, fTmpBins[idim], fTmpInfo[idim]); 536 538 537 if ( DIM > 1 && idim > 0) { 539 if ( DIM > 1 && idim > 0) { 538 // the setX, setY, setZ must be apply 540 // the setX, setY, setZ must be apply consequently 539 if (fTmpId[idim - 1] != fTmpId[idim]) 541 if (fTmpId[idim - 1] != fTmpId[idim]) { 540 G4Analysis::Warn( 542 G4Analysis::Warn( 541 "Command setX, setY, setZ must be 543 "Command setX, setY, setZ must be called successively in this order.\n" 542 "Command was ignored.", fkClass, " 544 "Command was ignored.", fkClass, "SetNewValue"); 543 return; 545 return; 544 } 546 } 545 } 547 } 546 if ( idim == DIM - 1) { 548 if ( idim == DIM - 1) { 547 // Apply parameters when all dimension 549 // Apply parameters when all dimensions are set 548 fManager->Set(fTmpId[idim], fTmpBins, << 550 fManager->Set(fTmpId[idim], bins, info); 549 return; 551 return; 550 } 552 } 551 } 553 } 552 } 554 } 553 555 554 if ( command == fSetTitleCmd.get() ) { 556 if ( command == fSetTitleCmd.get() ) { 555 auto counter = 0; 557 auto counter = 0; 556 const auto& id = G4UIcommand::ConvertToInt << 558 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 557 const auto& title = parameters[counter++]; << 559 auto title = parameters[counter++]; 558 fManager->SetTitle(id, title); 560 fManager->SetTitle(id, title); 559 return; 561 return; 560 } 562 } 561 563 562 auto maxDim = (DIM < kMaxDim) ? DIM + 1 : kM 564 auto maxDim = (DIM < kMaxDim) ? DIM + 1 : kMaxDim; 563 for (unsigned int idim = 0; idim < maxDim; + 565 for (unsigned int idim = 0; idim < maxDim; ++idim) { 564 if ( command == fSetAxisCmd[idim].get() ) 566 if ( command == fSetAxisCmd[idim].get() ) { 565 auto counter = 0; 567 auto counter = 0; 566 const auto& id = G4UIcommand::ConvertToI << 568 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); 567 const auto& axisTitle = parameters[count << 569 auto axisTitle = parameters[counter++]; 568 fManager->SetAxisTitle(idim, id, axisTit 570 fManager->SetAxisTitle(idim, id, axisTitle); 569 return; 571 return; 570 } 572 } >> 573 if ( command == fSetAxisLogCmd[idim].get() ) { >> 574 // TO DO: this should go in HnMessenger >> 575 auto counter = 0; >> 576 auto id = G4UIcommand::ConvertToInt(parameters[counter++]); >> 577 auto axisLog = G4UIcommand::ConvertToBool(parameters[counter++]); >> 578 fManager->GetHnManager()->SetAxisIsLog(idim, id, axisLog); >> 579 return; >> 580 } 571 } 581 } 572 582 573 if ( command == fListCmd.get() ) { 583 if ( command == fListCmd.get() ) { 574 auto onlyIfActive = G4UIcommand::ConvertTo 584 auto onlyIfActive = G4UIcommand::ConvertToBool(parameters[0]); 575 fManager->List(G4cout, onlyIfActive); 585 fManager->List(G4cout, onlyIfActive); 576 return; 586 return; 577 } 587 } 578 588 579 if ( command == fGetTCmd.get() ) { 589 if ( command == fGetTCmd.get() ) { 580 const auto& id = G4UIcommand::ConvertToInt << 590 auto id = G4UIcommand::ConvertToInt(newValues); 581 fTValue = GetTAddress(id); 591 fTValue = GetTAddress(id); 582 return; 592 return; 583 } 593 } 584 594 585 if ( command == fGetTVectorCmd.get() ) { 595 if ( command == fGetTVectorCmd.get() ) { 586 fTVectorValue = GetTVectorAddress(); 596 fTVectorValue = GetTVectorAddress(); 587 return; 597 return; 588 } 598 } 589 } 599 } 590 600