#include #include "TFile.h" #include "TTree.h" #include "TH1F.h" #include "TClonesArray.h" #include "TRandom3.h" void testTClonesArraty() { TFile *outFile = new TFile("out.root", "RECREATE", ""); TTree *fTree; TClonesArray* muoHits = new TClonesArray("TH1F", 100); TRandom3 *r3=new TRandom3(); unsigned int nMuo_; fTree = new TTree ("ana", "CMSSW anaFind tree"); fTree->Branch("nMuo", &nMuo_, "nMuo/I"); fTree->Branch("muoHits", "TClonesArray", &muoHits, 32000, 0); TH1F *tmpHisto; for( unsigned int iEvt=0;iEvt<10;iEvt++) { nMuo_ = int(r3->Uniform(0,10)); for( unsigned int n=0;nConstructedAt(n); tmpHisto->SetBins(10,0,10); //tmpHisto->SetName(Form("tmpHisto_%d",n)); for( unsigned int i=0;i<10;i++) { tmpHisto->Fill(i,iEvt*1000+n*100+i); cout << iEvt << " " << n << " " << i << " " << iEvt*1000+n*100+i << endl; } } fTree->Fill(); muoHits->Clear("C"); //tmpHisto->Reset(); } outFile->Write(); outFile->Close(); }