Hi Jean-Eric,
My proposed solution to your simple problem is the following:
Create two TClonesArray for hits and digits and post them to a folder.
Assuming that you have created the folder "/Event/MC" pointer by
TFolder *MC
for example with:
TFolder *EvFolder, *MC;
EvFolder = gROOT->GetRootFolder()->AddFolder("Event","Event folder");
gROOT->GetListOfBrowsables()->Add(EvFolder, "Event Folder");
MC = EvFolder->AddFolder ("MC", "MC hits and Digits folder");
TClonesArray *fHits = new TClonesArray("MCHits");
TClonesArray *fDigits = new TClonesArray("MCDigits");
fHits->SetName("Hits");
fDigits->SetName("Digits");
MC->Add(fHits);
MC->add(fDigits);
- Now produce a TTree (eg, TreeH) with
TFile f("hits.root","recreate");
TClonesArray *myhits = MC->FindObject("Hits); //should be equal to fHits
void *adh = (void*)MC->GetListOfFolders()->GetObjectRef(myhits);
TTree *TreeH = new TTree("TreeH","TClonesArray",adh);
// fill your TClonesArray with MCHits objects
TreeH->Fill();
- In your step 2:
//if a separate job, create the folder structure as above
TFile f("hits.root","update");
TTree *TreeH = (TTree*)f.Get(TreeH"):
TClonesArray *mydigits = MC->FindObject("Digits); //equal to fDigits
void *add = (void*)MC->GetListOfFolders()->GetObjectRef(mydigits);
TTree *TreeD = new TTree("TreeD","TClonesArray",add);
//start the loop on events. for each event, do:
TreeH->GetEntry(evnumber);
//fill your fDigits from fHits
TreeD->Fill();
Note that instead of updating the file hits.root, it might be more
convenient to create a separated file digits.root in case you want to run
multiple digitisation algorithms.
If in a next job, you want to read TreeH and TreeD in parallel,
it may be convenient to declare TreeD a friend of TreeH.
I already implemented a TTree::Branch function accepting a folder name
in input (this saves a few lines above). Unfortunately, I have not yet
implemented the automatic creation of a TFolder structure when
connecting a Tree. This is on my todo list.
Rene Brun
Jean-Eric Campagne wrote:
>
> Hello dear ROOT developpers,
>
> I would like to present a use case and ask for guide lines to
> solve it.
>
> Use Case:
> --------
>
> A) Let say that I would like to setup a very simple Data Hierarchy as
> follows:
> 1) <my-experiment>/Event/MC/Hits
>
> to holds (T)List of MCHit
>
> with a very simple MCHit class
> class MCHit : public TObject {
> public:
> MCHit(): m_channelID(0) {}
> virtual ~MCHit() {}
> //set/get accessor method to the channelID data member
> <...>
> private:
> Int_t m_channelID;
> };
> and all the "magic" macros to do the serialisation
>
> 2) <my-experiment>/Event/MC/Digits
>
> to holds (T)List of MCDigits
>
> with a little more complicated MCDigit class
> class MCDigit : public TObject {
> public:
> MCDigit(): m_x(0.) {<initialisation of the MCHitRef>}
> virtual ~MCDigit() {}
> //set/get accessor method to the x data member
> //and to the MCHit
> <...>
> private:
> Float_t m_x;
> TRef MCHitRef;
> };
> and all the "magic" macros to do the serialisation
>
> B) I have a task that transform the list of MCHit into a list of
> MCDigit which simply transform the channelId into a x position and
> maintain also a reference to the MCHit used (here a one-to-one link is
> supposed)
>
> Wishes
> ------
> 1) I would like to produce a Tree from the <...>/Event/MC/Hits
> folder and fill it with a (T)List of MCHits
> 2) read back this Tree to retreive the (T)List of MCHit
> 3) create the (T)List of MCDigit
> 4) post this new (T)List in the folder <...>/Event/MC/Digits
> 5) increase the structure of the Tree used at step 2) with this
> new folder and fill it with the (T)List of MCDigit created at step 3)
>
>
> How I can manage that?
>
> Best regards
> J.E Campagne
>
>
> .............................................................................
> .LAL - IN2P3 - CNRS
> .LAL - B.P 34 - 91898 Orsay Cedex - France
> .Piece 108
> .Tel +33 (0)1 64 46 84 29
> .Fax +33 (0)1 64 46 83 97
> ...........................................................................
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET