From $ROOTSYS/tutorials/tree/printSizes.C

#include "TTree.h"
#include "TBranch.h"
#include "Riostream.h"
#include "TMemFile.h"
#include "TKey.h"
#include "TBranchRef.h"

//
// This macro can be used to get aggregate information on the size
// take on disk or in memory by the various branches in a TTree.
// For example:
/*

root [] printTreeSummary(tree);
The TTree "T" takes 3764343 bytes on disk
  It's branch "event" takes 3760313 bytes on disk

root [] printBranchSummary(tree->GetBranch("event"));
The branch "event" takes 3760313 bytes on disk
  It's sub-branch "TObject" takes 581 bytes on disk
  It's sub-branch "fType[20]" takes 640 bytes on disk
  It's sub-branch "fEventName" takes 855 bytes on disk
  It's sub-branch "fNtrack" takes 506 bytes on disk
  It's sub-branch "fNseg" takes 554 bytes on disk
  It's sub-branch "fNvertex" takes 507 bytes on disk
  It's sub-branch "fFlag" takes 420 bytes on disk
  It's sub-branch "fTemperature" takes 738 bytes on disk
  It's sub-branch "fMeasures[10]" takes 1856 bytes on disk
  It's sub-branch "fMatrix[4][4]" takes 4563 bytes on disk
  It's sub-branch "fClosestDistance" takes 2881 bytes on disk
  It's sub-branch "fEvtHdr" takes 847 bytes on disk
  It's sub-branch "fTracks" takes 3673982 bytes on disk
  It's sub-branch "fHighPt" takes 59640 bytes on disk
  It's sub-branch "fMuons" takes 1656 bytes on disk
  It's sub-branch "fLastTrack" takes 785 bytes on disk
  It's sub-branch "fWebHistogram" takes 596 bytes on disk
  It's sub-branch "fH" takes 10076 bytes on disk
  It's sub-branch "fTriggerBits" takes 1699 bytes on disk
  It's sub-branch "fIsValid" takes 366 bytes on disk

 */

Long64_t GetTotalSize(TBranch * b, bool ondisk, bool inclusive);
Long64_t GetBasketSize(TBranch * b, bool ondisk, bool inclusive);

Long64_t GetBasketSize(TObjArray * branches, bool ondisk, bool inclusive) {
   Long64_t result = 0;
   size_t n = branches->GetEntries();
   for( size_t i = 0; i < n; ++ i ) {
      result += GetBasketSize( dynamic_cast<TBranch*>( branches->At( i ) ), ondisk, inclusive );
   }
   return result;
}

Long64_t GetBasketSize(TBranch * b, bool ondisk, bool inclusive) {
   Long64_t result = 0;
   if (b) {
      if (ondisk && b->GetZipBytes() > 0) {
         result = b->GetZipBytes();
      } else {
         result = b->GetTotBytes();
      }
      if (inclusive) {
         result += GetBasketSize(b->GetListOfBranches(), ondisk, true);
      }
      return result;
   }
   return result;
}

Long64_t GetTotalSize( TBranch * br, bool ondisk, bool inclusive ) {
   TMemFile f("buffer","CREATE");
   if (br->GetTree()->GetCurrentFile()) {
      f.SetCompressionSettings(br->GetTree()->GetCurrentFile()->GetCompressionSettings());
   }
   f.WriteObject(br,"thisbranch");
   TKey* key = f.GetKey("thisbranch");
   Long64_t size;
   if (ondisk)
      size = key->GetNbytes();
   else
      size = key->GetObjlen();
   return GetBasketSize(br, ondisk, inclusive) + size;
}

Long64_t GetTotalSize( TObjArray * branches, bool ondisk ) {
   Long64_t result = 0;
   size_t n = branches->GetEntries();
   for( size_t i = 0; i < n; ++ i ) {
      result += GetTotalSize( dynamic_cast<TBranch*>( branches->At( i ) ), ondisk, true );
      cerr << "After " << branches->At( i )->GetName() << " " << result << endl;
   }
   return result;
}

Long64_t GetTotalSize(TTree *t, bool ondisk) {
   TKey *key = 0;
   if (t->GetDirectory()) {
      key = t->GetDirectory()->GetKey(t->GetName());
   }
   Long64_t ondiskSize = 0;
   Long64_t totalSize = 0;
   if (key) {
      ondiskSize = key->GetNbytes();
      totalSize = key->GetObjlen();
   } else {
      TMemFile f("buffer","CREATE");
      if (t->GetCurrentFile()) {
         f.SetCompressionSettings(t->GetCurrentFile()->GetCompressionSettings());
      }
      f.WriteTObject(t);
      key = f.GetKey(t->GetName());
      ondiskSize = key->GetNbytes();
      totalSize = key->GetObjlen();
   }
   if (t->GetBranchRef() ) {
      if (ondisk) {
         ondiskSize += GetBasketSize(t->GetBranchRef(), true, true);
      } else {
         totalSize += GetBasketSize(t->GetBranchRef(), false, true);
      }
   }
   if (ondisk) {
      return ondiskSize + GetBasketSize(t->GetListOfBranches(), /* ondisk */ true, /* inclusive */ true);
   } else {
      return totalSize + GetBasketSize(t->GetListOfBranches(), /* ondisk */ false, /* inclusive */ true);
   }
}

Long64_t sizeOnDisk(TTree *t) {
   // Return the size on disk on this TTree.

   return GetTotalSize(t, true);
}

Long64_t sizeOnDisk(TBranch *branch, bool inclusive)
{
   // Return the size on disk on this branch.
   // If 'inclusive' is true, include also the size
   // of all its sub-branches.

   return GetTotalSize(branch, true, inclusive);
}

void printBranchSummary(TBranch *br)
{
   cout << "The branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n";
   size_t n = br->GetListOfBranches()->GetEntries();
   for( size_t i = 0; i < n; ++ i ) {
      TBranch *subbr = dynamic_cast<TBranch*>(br->GetListOfBranches()->At(i));
      cout << "  It's sub-branch \"" << subbr->GetName() << "\" takes " << sizeOnDisk(subbr,true) << " bytes on disk\n";
   }
}

void printTreeSummary(TTree *t)
{
   cout << "The TTree \"" << t->GetName() << "\" takes " << sizeOnDisk(t) << " bytes on disk\n";
   size_t n = t->GetListOfBranches()->GetEntries();
   for( size_t i = 0; i < n; ++ i ) {
      TBranch *br =dynamic_cast<TBranch*>(t->GetListOfBranches()->At(i));
      cout << "  It's branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n";
   }
}

void printSizes() {}
 printSizes.C:1
 printSizes.C:2
 printSizes.C:3
 printSizes.C:4
 printSizes.C:5
 printSizes.C:6
 printSizes.C:7
 printSizes.C:8
 printSizes.C:9
 printSizes.C:10
 printSizes.C:11
 printSizes.C:12
 printSizes.C:13
 printSizes.C:14
 printSizes.C:15
 printSizes.C:16
 printSizes.C:17
 printSizes.C:18
 printSizes.C:19
 printSizes.C:20
 printSizes.C:21
 printSizes.C:22
 printSizes.C:23
 printSizes.C:24
 printSizes.C:25
 printSizes.C:26
 printSizes.C:27
 printSizes.C:28
 printSizes.C:29
 printSizes.C:30
 printSizes.C:31
 printSizes.C:32
 printSizes.C:33
 printSizes.C:34
 printSizes.C:35
 printSizes.C:36
 printSizes.C:37
 printSizes.C:38
 printSizes.C:39
 printSizes.C:40
 printSizes.C:41
 printSizes.C:42
 printSizes.C:43
 printSizes.C:44
 printSizes.C:45
 printSizes.C:46
 printSizes.C:47
 printSizes.C:48
 printSizes.C:49
 printSizes.C:50
 printSizes.C:51
 printSizes.C:52
 printSizes.C:53
 printSizes.C:54
 printSizes.C:55
 printSizes.C:56
 printSizes.C:57
 printSizes.C:58
 printSizes.C:59
 printSizes.C:60
 printSizes.C:61
 printSizes.C:62
 printSizes.C:63
 printSizes.C:64
 printSizes.C:65
 printSizes.C:66
 printSizes.C:67
 printSizes.C:68
 printSizes.C:69
 printSizes.C:70
 printSizes.C:71
 printSizes.C:72
 printSizes.C:73
 printSizes.C:74
 printSizes.C:75
 printSizes.C:76
 printSizes.C:77
 printSizes.C:78
 printSizes.C:79
 printSizes.C:80
 printSizes.C:81
 printSizes.C:82
 printSizes.C:83
 printSizes.C:84
 printSizes.C:85
 printSizes.C:86
 printSizes.C:87
 printSizes.C:88
 printSizes.C:89
 printSizes.C:90
 printSizes.C:91
 printSizes.C:92
 printSizes.C:93
 printSizes.C:94
 printSizes.C:95
 printSizes.C:96
 printSizes.C:97
 printSizes.C:98
 printSizes.C:99
 printSizes.C:100
 printSizes.C:101
 printSizes.C:102
 printSizes.C:103
 printSizes.C:104
 printSizes.C:105
 printSizes.C:106
 printSizes.C:107
 printSizes.C:108
 printSizes.C:109
 printSizes.C:110
 printSizes.C:111
 printSizes.C:112
 printSizes.C:113
 printSizes.C:114
 printSizes.C:115
 printSizes.C:116
 printSizes.C:117
 printSizes.C:118
 printSizes.C:119
 printSizes.C:120
 printSizes.C:121
 printSizes.C:122
 printSizes.C:123
 printSizes.C:124
 printSizes.C:125
 printSizes.C:126
 printSizes.C:127
 printSizes.C:128
 printSizes.C:129
 printSizes.C:130
 printSizes.C:131
 printSizes.C:132
 printSizes.C:133
 printSizes.C:134
 printSizes.C:135
 printSizes.C:136
 printSizes.C:137
 printSizes.C:138
 printSizes.C:139
 printSizes.C:140
 printSizes.C:141
 printSizes.C:142
 printSizes.C:143
 printSizes.C:144
 printSizes.C:145
 printSizes.C:146
 printSizes.C:147
 printSizes.C:148
 printSizes.C:149
 printSizes.C:150
 printSizes.C:151
 printSizes.C:152
 printSizes.C:153
 printSizes.C:154
 printSizes.C:155
 printSizes.C:156
 printSizes.C:157
 printSizes.C:158
 printSizes.C:159
 printSizes.C:160
 printSizes.C:161
 printSizes.C:162
 printSizes.C:163
 printSizes.C:164
 printSizes.C:165
 printSizes.C:166