Changeset 4956 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
09/12/04 20:47:28 (20 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r4955 r4956  
    3333   * mbase/BaseLinkDef.h
    3434     - new class analogously to MArrayD
     35
     36   * mhbase/MH.[h,cc]
     37     - added functions ProjectArray(MArrayD,...)
     38       and ProjectArray(MArrayF,...)
    3539
    3640
  • trunk/MagicSoft/Mars/mhbase/MH.cc

    r4895 r4956  
    7373#include "MBinning.h"
    7474
     75#include "MArrayD.h"
     76#include "MArrayF.h"
     77
    7578ClassImp(MH);
    7679
     
    11421145// M.Gaug added this withouz Documentation
    11431146//
    1144 TH1I* MH::ProjectArray(const TArrayF &array, Int_t nbins, const char* name, const char* title)
     1147TH1I* MH::ProjectArray(const TArrayF &array, Int_t nbins,
     1148                       const char* name, const char* title)
    11451149{
    11461150    const Int_t size = array.GetSize();
     
    12291233}
    12301234
     1235// --------------------------------------------------------------------------
     1236//
     1237// M.Gaug added this withouz Documentation
     1238//
     1239TH1I* MH::ProjectArray(const MArrayF &array, Int_t nbins,
     1240                       const char* name, const char* title)
     1241{
     1242    const Int_t size = array.GetSize();
     1243
     1244    TH1I *h1=0;
     1245
     1246    //check if histogram with identical name exist
     1247    TObject *h1obj = gROOT->FindObject(name);
     1248    if (h1obj && h1obj->InheritsFrom("TH1I"))
     1249    {
     1250        h1 = (TH1I*)h1obj;
     1251        h1->Reset();
     1252    }
     1253
     1254    Double_t min = size>0 ? array[0] : 0;
     1255    Double_t max = size>0 ? array[0] : 1;
     1256
     1257    // first loop over array to find the min and max
     1258    for (Int_t i=1; i<size;i++)
     1259    {
     1260        max = TMath::Max((Double_t)array[i], max);
     1261        min = TMath::Min((Double_t)array[i], min);
     1262    }
     1263
     1264    Int_t newbins = 0;
     1265    FindGoodLimits(nbins, newbins, min, max, kFALSE);
     1266
     1267    if (!h1)
     1268    {
     1269        h1 = new TH1I(name, title, nbins, min, max);
     1270        h1->SetXTitle("");
     1271        h1->SetYTitle("Counts");
     1272        h1->SetDirectory(gROOT);
     1273    }
     1274
     1275    // Second loop to fill the histogram
     1276    for (Int_t i=0;i<size;i++)
     1277        h1->Fill(array[i]);
     1278
     1279    return h1;
     1280}
     1281
     1282// --------------------------------------------------------------------------
     1283//
     1284// M.Gaug added this withouz Documentation
     1285//
     1286TH1I* MH::ProjectArray(const MArrayD &array, Int_t nbins, const char* name, const char* title)
     1287{
     1288    const Int_t size = array.GetSize();
     1289    TH1I *h1=0;
     1290
     1291    //check if histogram with identical name exist
     1292    TObject *h1obj = gROOT->FindObject(name);
     1293    if (h1obj && h1obj->InheritsFrom("TH1I"))
     1294    {
     1295        h1 = (TH1I*)h1obj;
     1296        h1->Reset();
     1297    }
     1298
     1299    Double_t min = size>0 ? array[0] : 0;
     1300    Double_t max = size>0 ? array[0] : 1;
     1301
     1302    // first loop over array to find the min and max
     1303    for (Int_t i=1; i<size;i++)
     1304    {
     1305        max = TMath::Max(array[i], max);
     1306        min = TMath::Min(array[i], min);
     1307    }
     1308
     1309    Int_t newbins = 0;
     1310    FindGoodLimits(nbins, newbins, min, max, kFALSE);
     1311
     1312    if (!h1)
     1313    {
     1314        h1 = new TH1I(name, title, newbins, min, max);
     1315        h1->SetXTitle("");
     1316        h1->SetYTitle("Counts");
     1317        h1->SetDirectory(gROOT);
     1318    }
     1319
     1320    // Second loop to fill the histogram
     1321    for (Int_t i=0;i<size;i++)
     1322        h1->Fill(array[i]);
     1323
     1324    return h1;
     1325}
     1326
  • trunk/MagicSoft/Mars/mhbase/MH.h

    r3156 r4956  
    1414class TArrayF;
    1515class TArrayD;
     16class MArrayF;
     17class MArrayD;
    1618class TCanvas;
    1719
     
    9698    static TH1I* ProjectArray(const TArrayD &array, Int_t nbins=30,
    9799                              const char* name="ProjectArray", const char* title="Projected Array");
     100    static TH1I* ProjectArray(const MArrayF &array, Int_t nbins=30,
     101                              const char* name="ProjectArray", const char* title="Projected Array");
     102    static TH1I* ProjectArray(const MArrayD &array, Int_t nbins=30,
     103                              const char* name="ProjectArray", const char* title="Projected Array");
    98104   
    99105    static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
Note: See TracChangeset for help on using the changeset viewer.