Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, 10/08/2022 (ivan 28 29 #include "G4THnToolsManager.hh" 30 31 #include "tools/histo/p2d" 32 33 using namespace G4Analysis; 34 35 #include <fstream> 36 37 // Specialization for P2 type 38 39 40 //____________________________________________ 41 template <> 42 tools::histo::p2d* G4THnToolsManager<kDim3, to 43 const G4String& title, 44 const std::array<G4HnDimension, kDim3>& bins 45 const std::array<G4HnDimensionInformation, k 46 { 47 // Apply hn information to bins 48 auto newXBins(bins[kX]); 49 Update(newXBins, hnInfo[kX]); 50 auto newYBins(bins[kY]); 51 Update(newYBins, hnInfo[kY]); 52 auto newZBins(bins[kZ]); 53 UpdateValues(newZBins, hnInfo[kZ]); 54 55 if ((hnInfo[kX].fBinScheme == G4BinScheme::k 56 (hnInfo[kY].fBinScheme == G4BinScheme::k 57 if ( newZBins.fMinValue == 0. && newZBins. 58 return new tools::histo::p2d( 59 title, newXBins.fNBins, newXBins.fMinV 60 newYBins.fNBins, newYBins.fMinValue, n 61 } 62 return new tools::histo::p2d( 63 title, newXBins.fNBins, newXBins.fMinVal 64 newYBins.fNBins, newYBins.fMinValue, new 65 newZBins.fMinValue, newZBins.fMaxValue); 66 } 67 68 if ( newZBins.fMinValue == 0. && newZBins.fM 69 return new tools::histo::p2d(title, newXBi 70 } 71 return new tools::histo::p2d(title, newXBins 72 newZBins.fMinValue, newZBins.fMaxValue); 73 } 74 75 //____________________________________________ 76 template <> 77 void G4THnToolsManager<kDim3, tools::histo::p2 78 tools::histo::p2d* ht, 79 const std::array<G4HnDimension, kDim3>& bins 80 const std::array<G4HnDimensionInformation, k 81 { 82 // Apply hn information to bins 83 auto newXBins(bins[kX]); 84 Update(newXBins, hnInfo[kX]); 85 auto newYBins(bins[kY]); 86 Update(newYBins, hnInfo[kY]); 87 auto newZBins(bins[kZ]); 88 UpdateValues(newZBins, hnInfo[kZ]); 89 90 if ((hnInfo[kX].fBinScheme == G4BinScheme::k 91 (hnInfo[kY].fBinScheme == G4BinScheme::k 92 if ( newZBins.fMinValue == 0. && newZBins. 93 ht->configure( 94 newXBins.fNBins, newXBins.fMinValu 95 newYBins.fNBins, newYBins.fMinValu 96 return; 97 } 98 ht->configure( 99 newXBins.fNBins, newXBins.fMinValue, 100 newYBins.fNBins, newYBins.fMinValue, 101 newZBins.fMinValue, newZBins.fMaxVal 102 return; 103 } 104 105 if ( newZBins.fMinValue == 0. && newZBins.fM 106 ht->configure(newXBins.fEdges, newYBins.fE 107 return; 108 } 109 110 ht->configure(newXBins.fEdges, newYBins.fEdg 111 newZBins.fMinValue, newZBins.fMaxValue 112 } 113 114 //____________________________________________ 115 template <> 116 G4bool G4THnToolsManager<kDim3, tools::histo:: 117 tools::histo::p2d* ht, const G4HnInformation 118 std::array<G4double, kDim3>& value, G4double 119 { 120 const auto& xInfo = hnInformation.GetHnDimen 121 const auto& yInfo = hnInformation.GetHnDimen 122 const auto& zInfo = hnInformation.GetHnDimen 123 124 // Apply hn information to value 125 Update(value[kX], xInfo); 126 Update(value[kY], yInfo); 127 Update(value[kZ], zInfo); 128 129 // Fill updated value 130 ht->fill(value[kX], value[kY], value[kZ], we 131 132 return true; 133 } 134 135 //____________________________________________ 136 template <> 137 G4bool G4THnToolsManager<kDim3, tools::histo:: 138 std::ofstream& output) 139 { 140 // Write selected objects on ASCII file 141 142 // Do nothing if no histograms are selected 143 if ( ! GetHnManager()->IsAscii() ) return tr 144 145 // Write p2 histograms 146 auto id = GetHnManager()->GetFirstId(); 147 for (const auto& [p2, info] : *GetTHnVector( 148 149 if ( (p2 == nullptr) || (! info->GetAscii( 150 // skip writing 151 // if p2 was deleted or writing ascii is 152 id++; 153 continue; 154 } 155 156 Message(kVL3, "write on ascii", "p2d", inf 157 158 output << "\n 2D profile " << id++ << ": 159 << "\n \n \t \t X \t\t Y \t 160 161 for (G4int j=0; j< G4int(p2->axis_x().bins 162 for (G4int k=0; k< G4int(p2->axis_y().bi 163 auto sw = p2->bin_Sw(j, k); 164 auto svw = p2->bin_Svw(j, k); 165 auto mean = ( sw != 0. ) ? (svw / sw) 166 output << " " << j << "\t" << k << "\ 167 << p2->axis_x().bin_center(j) < 168 << p2->axis_y().bin_center(k) < 169 << mean << G4endl; 170 } 171 } 172 } 173 174 return output.good(); 175 } 176