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 // $Id: G4HnManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $ 26 27 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivan 28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 29 29 #include "G4HnManager.hh" 30 #include "G4HnManager.hh" 30 #include "G4HnMessenger.hh" << 31 << 32 #include "G4AnalysisUtilities.hh" << 33 #include "G4VFileManager.hh" << 34 << 35 #include <utility> << 36 << 37 using namespace G4Analysis; << 38 using std::to_string; << 39 << 40 //____________________________________________ << 41 G4HnManager::G4HnManager(G4String hnType, cons << 42 : G4BaseAnalysisManager(state), fHnType(std: << 43 {} << 44 31 45 //____________________________________________ 32 //_____________________________________________________________________________ 46 G4HnManager::~G4HnManager() << 33 G4HnManager::G4HnManager(const G4String& hnType, >> 34 const G4AnalysisManagerState& state) >> 35 : G4BaseAnalysisManager(state), >> 36 fHnType(hnType), >> 37 fNofActiveObjects(0), >> 38 fNofAsciiObjects(0), >> 39 fHnVector() 47 { 40 { 48 for ( auto info : fHnVector ) { << 49 delete info; << 50 } << 51 } 41 } 52 42 53 // << 54 // private methods << 55 // << 56 << 57 //____________________________________________ 43 //_____________________________________________________________________________ 58 void G4HnManager::SetActivation(G4HnInformati << 44 G4HnManager::~G4HnManager() 59 { << 60 // Set activation to a given object << 61 << 62 // Do nothing if activation does not change << 63 if ( info->GetActivation() == activation ) r << 64 << 65 // Change activation and account it in fNofA << 66 info->SetActivation(activation); << 67 if (activation) { << 68 fNofActiveObjects++; << 69 } << 70 else { << 71 fNofActiveObjects--; << 72 } << 73 } << 74 << 75 //____________________________________________ << 76 void G4HnManager::SetPlotting(G4HnInformation << 77 { << 78 // Do nothing if ascii does not change << 79 if ( info->GetPlotting() == plotting ) retur << 80 << 81 // Change Plotting and account it in fNofPlo << 82 info->SetPlotting(plotting); << 83 if (plotting) { << 84 fNofPlottingObjects++; << 85 } << 86 else { << 87 fNofPlottingObjects--; << 88 } << 89 } << 90 << 91 //____________________________________________ << 92 void G4HnManager::SetFileName(G4HnInformation << 93 { 45 { 94 // Do nothing if file name does not change << 46 std::vector<G4HnInformation*>::iterator it; 95 if ( info->GetFileName() == fileName ) retur << 47 for (it = fHnVector.begin(); it != fHnVector.end(); it++ ) { 96 << 48 delete (*it); 97 auto hnFileName = fileName; << 49 } 98 auto extension = GetExtension(fileName); << 99 if (extension.size() != 0u) { << 100 // Check if valid extension (if present) << 101 auto output = G4Analysis::GetOutput(extens << 102 if ( output == G4AnalysisOutput::kNone ) { << 103 Warn("The file extension " + extension + << 104 fkClass, "SetFileName"); << 105 return; << 106 } << 107 } << 108 else { << 109 if (fDefaultFileType.size() != 0u) { << 110 //add extension if missing and file type << 111 hnFileName = fileName + "." + fDefaultFi << 112 } << 113 } << 114 << 115 // Save the info and account a new file name << 116 info->SetFileName(hnFileName); << 117 if (fFileManager) { << 118 fFileManager->AddFileName(hnFileName); << 119 } else { << 120 Warn("Failed to set fileName " + fileName << 121 " for object " + info->GetName() + ". << 122 fkClass, "SetFileName"); << 123 return; << 124 } << 125 << 126 if ( hnFileName != "" ) { << 127 fNofFileNameObjects++; << 128 } else { << 129 fNofFileNameObjects--; << 130 } << 131 } 50 } 132 51 133 // << 52 // 134 // public methods 53 // public methods 135 // 54 // 136 55 137 //____________________________________________ 56 //_____________________________________________________________________________ 138 void G4HnManager::CreateMessenger() << 57 void G4HnManager::AddH1Information(const G4String& name, 139 { << 58 const G4String& unitName, 140 fMessenger = std::make_unique<G4HnMessenger> << 59 const G4String& fcnName, 141 } << 60 G4double unit, G4Fcn fcn, 142 << 61 G4BinScheme binScheme) 143 //____________________________________________ << 62 { 144 void G4HnManager::AddHnInformation(G4HnInforma << 63 G4HnInformation* hnInformation = new G4HnInformation(name, 1); 145 { << 64 hnInformation 146 // Add new information << 65 ->AddHnDimensionInformation( >> 66 G4HnDimensionInformation(unitName, fcnName, unit, fcn, binScheme)); 147 67 148 fHnVector.push_back(info); << 68 fHnVector.push_back(hnInformation); 149 ++fNofActiveObjects; 69 ++fNofActiveObjects; 150 } << 70 } 151 71 152 //____________________________________________ 72 //_____________________________________________________________________________ 153 void G4HnManager::AddHnInformation(G4HnInforma << 73 void G4HnManager::AddH2Information(const G4String& name, 154 { << 74 const G4String& xunitName, 155 // Replace the information at 'index' positi << 75 const G4String& yunitName, 156 // Update new information with the previous << 76 const G4String& xfcnName, 157 // previous histogram was deleted with 'keep << 77 const G4String& yfcnName, 158 << 78 G4double xunit, G4double yunit, 159 auto previousInfo = fHnVector[index]; << 79 G4Fcn xfcn, G4Fcn yfcn, 160 if (previousInfo->GetDeletedPair().second) { << 80 G4BinScheme xbinScheme, G4BinScheme ybinScheme) 161 info->Update(*previousInfo); << 81 { 162 } << 82 G4HnInformation* hnInformation = new G4HnInformation(name, 2); 163 delete previousInfo; << 83 hnInformation >> 84 ->AddHnDimensionInformation( >> 85 G4HnDimensionInformation(xunitName, xfcnName, xunit, xfcn, xbinScheme)); >> 86 hnInformation >> 87 ->AddHnDimensionInformation( >> 88 G4HnDimensionInformation(yunitName, yfcnName, yunit, yfcn, ybinScheme)); 164 89 165 fHnVector[index] = info; << 90 fHnVector.push_back(hnInformation); 166 << 91 ++fNofActiveObjects; 167 if (info->GetActivation()) { ++fNofActiveObj << 92 } 168 if (info->GetAscii()) { ++fNofAsciiObje << 169 if (info->GetPlotting()) { ++fNofPlottingO << 170 if (! info->GetFileName().empty()) { ++fNofF << 171 } << 172 93 173 //____________________________________________ 94 //_____________________________________________________________________________ 174 void G4HnManager::SetHnDeleted(G4HnInformation << 95 void G4HnManager::AddH3Information(const G4String& name, 175 { << 96 const G4String& xunitName, 176 info->SetDeleted(true, keepSetting); << 97 const G4String& yunitName, >> 98 const G4String& zunitName, >> 99 const G4String& xfcnName, >> 100 const G4String& yfcnName, >> 101 const G4String& zfcnName, >> 102 G4double xunit, G4double yunit, G4double zunit, >> 103 G4Fcn xfcn, G4Fcn yfcn, G4Fcn zfcn, >> 104 G4BinScheme xbinScheme, G4BinScheme ybinScheme, >> 105 G4BinScheme zbinScheme) >> 106 { >> 107 G4HnInformation* hnInformation = new G4HnInformation(name, 3); >> 108 hnInformation >> 109 ->AddHnDimensionInformation( >> 110 G4HnDimensionInformation(xunitName, xfcnName, xunit, xfcn, xbinScheme)); >> 111 hnInformation >> 112 ->AddHnDimensionInformation( >> 113 G4HnDimensionInformation(yunitName, yfcnName, yunit, yfcn, ybinScheme)); >> 114 hnInformation >> 115 ->AddHnDimensionInformation( >> 116 G4HnDimensionInformation(zunitName, zfcnName, zunit, zfcn, zbinScheme)); 177 117 178 if (info->GetActivation()) { --fNofActiveObj << 118 fHnVector.push_back(hnInformation); 179 if (info->GetAscii()) { --fNofAsciiObje << 119 ++fNofActiveObjects; 180 if (info->GetPlotting()) { --fNofPlottingO << 120 } 181 if (! info->GetFileName().empty()) { --fNofF << 182 } << 183 << 184 //____________________________________________ << 185 void G4HnManager::ClearData() << 186 { << 187 for ( auto info : fHnVector ) { << 188 delete info; << 189 } << 190 fHnVector.clear(); << 191 SetLockFirstId(false); << 192 } << 193 121 194 //____________________________________________ 122 //_____________________________________________________________________________ 195 G4HnInformation* G4HnManager::GetHnInformation << 123 G4HnInformation* G4HnManager::GetHnInformation(G4int id, 196 std::string_v << 124 G4String functionName, G4bool warn) const 197 { 125 { 198 G4int index = id - fFirstId; 126 G4int index = id - fFirstId; 199 if ( index < 0 || index >= G4int(fHnVector.s 127 if ( index < 0 || index >= G4int(fHnVector.size()) ) { 200 if ( warn ) { 128 if ( warn ) { 201 Warn(fHnType + " histogram " + to_string << 129 G4String inFunction = "G4HnManager::"; 202 fkClass, functionName); << 130 if ( functionName.size() ) 203 } << 131 inFunction += functionName; 204 return nullptr; << 132 else >> 133 inFunction += "GetHnInformation"; >> 134 G4ExceptionDescription description; >> 135 description << " " << fHnType << " histogram " << id >> 136 << " does not exist."; >> 137 G4Exception(inFunction, "Analysis_W011", JustWarning, description); >> 138 } >> 139 return 0; 205 } 140 } 206 return fHnVector[index]; 141 return fHnVector[index]; 207 } << 142 } 208 143 209 //____________________________________________ 144 //_____________________________________________________________________________ 210 G4HnDimensionInformation* G4HnManager::GetHnDi << 145 G4HnDimensionInformation* G4HnManager::GetHnDimensionInformation(G4int id, 211 G4int dimensio 146 G4int dimension, 212 std::string_vi << 147 G4String functionName, G4bool warn) const 213 { 148 { 214 auto info = GetHnInformation(id, functionNam << 149 G4HnInformation* hnInformation = GetHnInformation(id, functionName, warn); 215 if (info == nullptr) return nullptr; << 150 if ( ! hnInformation ) return 0; 216 151 217 return info->GetHnDimensionInformation(dimen << 152 return hnInformation->GetHnDimensionInformation(dimension); 218 } << 153 } 219 154 220 //____________________________________________ 155 //_____________________________________________________________________________ 221 G4bool G4HnManager::IsActive() const 156 G4bool G4HnManager::IsActive() const 222 { 157 { 223 return ( fNofActiveObjects > 0 ); 158 return ( fNofActiveObjects > 0 ); 224 } << 159 } 225 160 226 //____________________________________________ 161 //_____________________________________________________________________________ 227 G4bool G4HnManager::IsAscii() const 162 G4bool G4HnManager::IsAscii() const 228 { 163 { 229 return ( fNofAsciiObjects > 0 ); 164 return ( fNofAsciiObjects > 0 ); 230 } << 165 } 231 << 232 //____________________________________________ << 233 G4bool G4HnManager::IsPlotting() const << 234 { << 235 return ( fNofPlottingObjects > 0 ); << 236 } << 237 << 238 //____________________________________________ << 239 G4bool G4HnManager::IsFileName() const << 240 { << 241 return ( fNofFileNameObjects > 0 ); << 242 } << 243 166 244 //____________________________________________ 167 //_____________________________________________________________________________ 245 void G4HnManager::SetActivation(G4int id, G4b 168 void G4HnManager::SetActivation(G4int id, G4bool activation) 246 { 169 { 247 // Set activation to a given object 170 // Set activation to a given object 248 171 249 auto info = GetHnInformation(id, "SetActivat << 172 G4HnInformation* info = GetHnInformation(id, "SetActivation"); 250 173 251 if (info == nullptr) return; << 174 if ( ! info ) return; 252 175 253 SetActivation(info, activation); << 176 // Do nothing if activation does not change 254 } << 177 if ( info->GetActivation() == activation ) return; >> 178 >> 179 // Change activation and account it in fNofActiveObjects >> 180 info->SetActivation(activation); >> 181 if ( activation ) >> 182 fNofActiveObjects++; >> 183 else >> 184 fNofActiveObjects--; >> 185 } 255 186 256 //____________________________________________ 187 //_____________________________________________________________________________ 257 void G4HnManager::SetActivation(G4bool activa 188 void G4HnManager::SetActivation(G4bool activation) 258 { 189 { 259 // Set activation to all objects of the given 190 // Set activation to all objects of the given type 260 191 261 //std::vector<G4HnInformation*>::iterator it << 192 std::vector<G4HnInformation*>::iterator it; 262 //for ( it = fHnVector.begin(); it != fHnVec << 193 for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) { 263 // G4HnInformation* info = *it; << 194 G4HnInformation* info = *it; 264 << 195 265 for ( auto info : fHnVector ) { << 196 // Do nothing if activation does not change 266 SetActivation(info, activation); << 197 if ( info->GetActivation() == activation ) continue; 267 } << 198 268 } << 199 // Change activation and account it in fNofActiveObjects >> 200 info->SetActivation(activation); >> 201 if ( activation ) >> 202 fNofActiveObjects++; >> 203 else >> 204 fNofActiveObjects--; >> 205 } >> 206 } 269 207 270 //____________________________________________ 208 //_____________________________________________________________________________ 271 void G4HnManager::SetAscii(G4int id, G4bool a 209 void G4HnManager::SetAscii(G4int id, G4bool ascii) 272 { 210 { 273 auto info = GetHnInformation(id, "SetAscii") << 211 G4HnInformation* info = GetHnInformation(id, "SetAscii"); 274 212 275 if (info == nullptr) return; << 213 if ( ! info ) return; 276 214 277 // Do nothing if ascii does not change 215 // Do nothing if ascii does not change 278 if ( info->GetAscii() == ascii ) return; 216 if ( info->GetAscii() == ascii ) return; 279 << 217 280 // Change ascii and account it in fNofAsciiO 218 // Change ascii and account it in fNofAsciiObjects 281 info->SetAscii(ascii); 219 info->SetAscii(ascii); 282 if (ascii) { << 220 if ( ascii ) 283 fNofAsciiObjects++; 221 fNofAsciiObjects++; 284 } << 222 else 285 else { << 223 fNofAsciiObjects--; 286 fNofAsciiObjects--; << 224 } 287 } << 288 } << 289 225 290 //____________________________________________ 226 //_____________________________________________________________________________ 291 void G4HnManager::SetPlotting(G4int id, G4boo << 227 G4String G4HnManager::GetName(G4int id) const 292 { << 293 auto info = GetHnInformation(id, "SetPlottin << 294 << 295 if (info == nullptr) return; << 296 << 297 SetPlotting(info, plotting); << 298 } << 299 << 300 //____________________________________________ << 301 void G4HnManager::SetPlotting(G4bool plotting << 302 { << 303 // Set plotting to all objects of the given ty << 304 << 305 for ( auto info : fHnVector ) { << 306 SetPlotting(info, plotting); << 307 } << 308 } << 309 << 310 //____________________________________________ << 311 void G4HnManager::SetFileName(G4int id, const << 312 { << 313 auto info = GetHnInformation(id, "SetFileNam << 314 << 315 if (info == nullptr) return; << 316 << 317 SetFileName(info, fileName); << 318 } << 319 << 320 //____________________________________________ << 321 void G4HnManager::SetFileName(const G4String& << 322 { << 323 // Set plotting to all objects of the given ty << 324 << 325 for ( auto info : fHnVector ) { << 326 SetFileName(info, fileName); << 327 } << 328 } << 329 << 330 //____________________________________________ << 331 G4bool G4HnManager::SetAxisIsLog(unsigned int << 332 { 228 { 333 auto info = GetHnInformation(id, "SetAxisIsL << 229 G4HnInformation* info = GetHnInformation(id, "GetName"); 334 230 335 if (info == nullptr) return false; << 231 if ( ! info ) return ""; 336 << 232 337 info->SetIsLogAxis(idim, isLog); << 233 return info->GetName(); 338 return true; << 234 } 339 } << 340 235 341 //____________________________________________ 236 //_____________________________________________________________________________ 342 G4String G4HnManager::GetName(G4int id) const << 237 G4double G4HnManager::GetXUnit(G4int id) const 343 { 238 { 344 auto info = GetHnInformation(id, "GetName"); << 239 G4HnDimensionInformation* info >> 240 = GetHnDimensionInformation(id, G4HnInformation::kX, "GetXUnit"); 345 241 346 if (info == nullptr) return ""; << 242 if ( ! info ) return 1.0; 347 << 243 348 return info->GetName(); << 244 return info->fUnit; 349 } << 245 } 350 246 351 //____________________________________________ 247 //_____________________________________________________________________________ 352 G4double G4HnManager::GetUnit(unsigned int idi << 248 G4double G4HnManager::GetYUnit(G4int id) const 353 { 249 { 354 auto info = GetHnDimensionInformation(id, id << 250 G4HnDimensionInformation* info 355 << 251 = GetHnDimensionInformation(id, G4HnInformation::kY, "GetYUnit"); 356 if (info == nullptr) return 1.0; << 357 252 >> 253 if ( ! info ) return 1.0; >> 254 358 return info->fUnit; 255 return info->fUnit; 359 } << 256 } 360 257 361 //____________________________________________ 258 //_____________________________________________________________________________ 362 G4bool G4HnManager::GetAxisIsLog(unsigned int << 259 G4double G4HnManager::GetZUnit(G4int id) const 363 { 260 { 364 auto info = GetHnInformation(id, "GetXAxisIs << 261 G4HnDimensionInformation* info >> 262 = GetHnDimensionInformation(id, G4HnInformation::kZ, "GetZUnit"); 365 263 366 if (info == nullptr) return false; << 264 if ( ! info ) return 1.0; 367 << 265 368 return info->GetIsLogAxis(idim); << 266 return info->fUnit; 369 } << 267 } 370 268 371 //____________________________________________ 269 //_____________________________________________________________________________ 372 G4bool G4HnManager::GetActivation(G4int id) co 270 G4bool G4HnManager::GetActivation(G4int id) const 373 { 271 { 374 auto info = GetHnInformation(id, "GetActivat << 272 G4HnInformation* info = GetHnInformation(id, "GetActivation"); 375 << 376 if (info == nullptr) return true; << 377 273 >> 274 if ( ! info ) return true; >> 275 378 return info->GetActivation(); 276 return info->GetActivation(); 379 } << 277 } 380 278 381 //____________________________________________ 279 //_____________________________________________________________________________ 382 G4bool G4HnManager::GetAscii(G4int id) const 280 G4bool G4HnManager::GetAscii(G4int id) const 383 { 281 { 384 auto info = GetHnInformation(id, "GetAscii") << 282 G4HnInformation* info = GetHnInformation(id, "GetAscii"); 385 << 386 if (info == nullptr) return false; << 387 283 >> 284 if ( ! info ) return false; >> 285 388 return info->GetAscii(); 286 return info->GetAscii(); 389 } << 287 } 390 << 391 //____________________________________________ << 392 G4bool G4HnManager::GetPlotting(G4int id) cons << 393 { << 394 auto info = GetHnInformation(id, "GetPlottin << 395 << 396 if (info == nullptr) return false; << 397 << 398 return info->GetPlotting(); << 399 } << 400 << 401 //____________________________________________ << 402 G4String G4HnManager::GetFileName(G4int id) co << 403 { << 404 auto info = GetHnInformation(id, "GetFileNam << 405 << 406 if (info == nullptr) return ""; << 407 << 408 return info->GetFileName(); << 409 } << 410 288