Problem on change vectors to doubles

Dear Rooters,

I am interesting to fit some of my ntuple branches using rooFit, but all my branches are type vectors and I try to transfer them from vectors to double to use the roofit functions, to do that i am using a macro but it doesn’t works well:

#include ;

void tree5() {

//Get old file, old tree and set top branch address
TFile *f = new TFile("/tmp/gouighri/MergentupleCDF_E2.root",“READ”);
TTree inputtree = (TTree)f->Get(“BmesonntupleCDF”);

vector *pvec1(0);
vector *pvec2(0);
vector *pvec3(0);
vector *pvec4(0);

inputtree->SetBranchAddress(“MassBd”,&pvec1);
inputtree->SetBranchAddress(“TauBd”,&pvec2);
inputtree->SetBranchAddress(“LxyBd”,&pvec3);
inputtree->SetBranchAddress(“LxyJFit”,&pvec4);

TFile *outputfile = new TFile("/tmp/gouighri/test1.root",“recreate”);
TTree *outputtree = new TTree(“tree”,“tree with doubles”);

double MassBd1;
double TauBd1;
double LxyBd1;
double LxyJFit1;

outputtree->Branch(“MassBd1”,&MassBd1);
outputtree->Branch(“TauBd1”,&TauBd1);
outputtree->Branch(“LxyBd1”,&LxyBd1);
outputtree->Branch(“LxyJFit1”,&LxyJFit1);

for(Long64_t entry = 0; entry < inputtree->GetEntries(); ++entry) {
inputtree->GetEntry(entry);
std::vector::iterator iter1 = pvec1->begin();
std::vector::iterator iter2 = pvec2->begin();
std::vector::iterator iter3 = pvec3->begin();
std::vector::iterator iter4 = pvec4->begin();

 assert( pvec1->size() == pvec2->size() && pvec2->size() == pvec3->size() && pvec2->size() == pvec4->size() );

 for( ; iter1 != pvec1->end(); ++iter1, ++iter2, ++iter3, ++iter4) {
  
   MassBd1 = (*iter1);
   TauBd1 = (*iter2);
   LxyBd1 = (*iter3);
   LxyJFit1 = (*iter4);
   outputtree->Fill();
 }

}

outputfile->Write();
outputfile->Close();
}

Please do you have an idea what i am doing wrong? How can I manage it?

Thank you very much for your help

Cheers
Mohamed

Hi,

[quote]Please do you have an idea what i am doing wrong? How can I manage it?[/quote]A casual read of you code does not show any issue. How does it fail for you?

Philippe.

PS. One thing is that your new TTree has many more entries than the original, you mean need to use arrays of double rather than simple double.

Hi Philippe,
Thank you very much for your reply.

A casual read of you code does not show any issue. How does it fail for you?

The code doesn’t fail, but the new ntuple created contains branches with the same entries as for the old one, it’s likely i am still in vectors instead of doubles

Many thanks
Mohamed

[quote]with the same entries as for the old one[/quote]I do not understand. Do you mean that it has the same total number of entries? Do you mean that the branches are the same? Do you mean that the data is the same (it should be … just a different format)?

Philippe.

Hi Philippe,

Do you mean that it has the same total number of entries? Do you mean that the branches are the same? Do
you mean that the data is the same (it should be … just a different format)?

Yes, actually the new ntuple that was created contains the same number of entries as in the old one, normally it should be less if the vectors are nicely transfered to doubles, that’s why I said that the macro doesn’t transfer my ntuple branches type vectors to simple doubles … and yes the data in the new ntuple branches are exactly the same as in the old one, I don’t see any change.

Many thanks
Cheers
Mohamed

[quote]Yes, actually the new ntuple that was created contains the same number of entries as in the old one, normally it should be less if the vectors are nicely transfered to doubles,[/quote]Well it would be less only if in average the size of the vector is less than 1 element (i.e. I guess 0 and 1). If the size of the vector in average is greater than one, you would get more entries … wouldn’t you?

[quote]and yes the data in the new ntuple branches are exactly the same as in the old one, I don’t see any change. [/quote]This means either you actually succeeded or you are looking at the old tree (or a perfect ‘clone’) …

Cheers,
Philippe

Dear Philippe,

This means either you actually succeeded or you are looking at the old tree (or a perfect ‘clone’) …

My goal is not to clone the data, but i am interesting to transfer my branches from vectors to doubles.

The new ntuple (as in the macro) still contains the same size, entries, … as they were in the old ntuple where the branches are vectors, so the macro didn’t do what I need, I do not know were the problem is …

Many thanks for your help
Mohamed

[quote]The new ntuple (as in the macro) still contains the same size, entries,[/quote]Given the macro you gave this is not possible … or I do not understand what you mean. I think the best way to proceed would be for you to upload (and/or send me) a complete running example including the way you assert that you did not get what you wanted.

Cheers,
Philippe.

Many thanks Philippe for your answer and helps,

upload (and/or send me) a complete running example including the way you assert that you did not get what you wanted

I sent as attachment the macro i run to change the branches in my original ntuple “MergentupleCDFD6E1.root” where they are vectors to a new ntuple “test111.root” where i “dream” to have them doubles.

I sent also two plots, the MassBd present a branch in the original ntuple (vector) and MassBd1 a branch in the new ntuple (double), they look similar.

Thank you so very much
Mohamed

NB: I just see that i have a bug in my rooFit macro, maybe that’s why it doesn’t work, I will let you know





copytree5.C (1.55 KB)

[quote]NB: I just see that i have a bug in my rooFit macro, maybe that’s why it doesn’t work, I will let you know[/quote]Also in order to reproduce the problem I would need the data file.

Cheers,
Philippe.

Hi Philippe,

Also in order to reproduce the problem I would need the data file.

The smallest root file is 148 Mb, I will try to make a small one and send it?

Many thanks
Cheers
Mohamed

[quote]The smallest root file is 148 Mb, I will try to make a small one and send it?[/quote]Let me know (however if you put this file somewhere I can access it (i.e. web server or afs) I can easily download it).

Cheers,
Philippe.

Dear Philippe,

Let me know (however if you put this file somewhere I can access it (i.e. web server or afs) I can easily download it).

OK, I put a file “MergentupleCDFD6E1.root” in /tmp of the machine lxplus237 at CERN, please let me know if you have access to it or not.

Thank you so very much
Mohamed

Hi Mohamed,

Your copytree5.C script does exactly what you wanted:[code][pcanal@rootsrv1 tmp]$ root.exe -b -l MergentupleCDFD6E1.root
root [0]
Attaching file MergentupleCDFD6E1.root as _file0…
root [1] BmesonntupleCDF->GetEntries()
(const Long64_t)293644
root [2] BmesonntupleCDF->Scan(“MassBd”)


  • Row * Instance * MassBd *

  •    0 *        0 *           *
    
  •    1 *        0 *           *
    
  •    2 *        0 *           *
    
  •    3 *        0 *           *
    
  •    4 *        0 *           *
    
  •    5 *        0 *           *
    
  •    6 *        0 *           *
    
  •    7 *        0 *           *
    
  •    8 *        0 *           *
    
  •    9 *        0 *           *
    
  •   10 *        0 *           *
    
  •   11 *        0 *           *
    
  •   12 *        0 *           *
    
  •   13 *        0 * 4057.7324 *
    
  •   13 *        1 * 4076.5749 *
    
  •   14 *        0 *           *
    
  •   15 *        0 *           *
    
  •   16 *        0 * 5498.5689 *
    
  •   16 *        1 * 4302.3977 *
    
  •   17 *        0 *           *
    
  •   18 *        0 *           *
    
  •   19 *        0 *           *
    
  •   20 *        0 *           *
    
  •   21 *        0 *           *
    
  •   22 *        0 *           *
    

Type to continue or q to quit ==> q


(Long64_t)25
root [3] TFile *_file0 = TFile::Open(“test111.root”)
root [4] tree->GetEntries()
(const Long64_t)111782
root [5] tree->Scan(“MassBd1”)


  • Row * MassBd1 *

  •    0 * 4057.7324 *
    
  •    1 * 4076.5749 *
    
  •    2 * 5498.5689 *
    
  •    3 * 4302.3977 *
    
  •    4 * 7880.4432 *
    
  •    5 * 6097.2484 *
    
  •    6 * 7008.2476 *
    
  •    7 * 4044.7054 *
    
  •    8 * 4482.4548 *
    
  •    9 * 4836.4262 *
    
  •   10 * 7071.2728 *
    
  •   11 * 6220.8620 *
    
  •   12 * 4413.2842 *
    
  •   13 * 7459.3196 *
    
  •   14 * 3879.0670 *
    
  •   15 * 5078.7200 *
    
  •   16 * 4344.9779 *
    
  •   17 * 4421.5673 *
    
  •   18 * 4321.0536 *
    
  •   19 * 4138.8401 *
    
  •   20 * 4060.5676 *
    
  •   21 * 4018.7991 *
    
  •   22 * 6168.4457 *
    
  •   23 * 6255.7099 *
    
  •   24 * 7151.4497 *
    

root [9] tree->Print()


*Tree :tree : tree with doubles *
*Entries : 111782 : Total = 2692166 bytes File Size = 2581370 *

  •    :          : Tree compression factor =   1.04                       *
    

*Br 0 :MassBd1 : MassBd1/D *
*Entries : 111782 : Total Size= 897292 bytes File Size = 843626 *
*Baskets : 29 : Basket Size= 32000 bytes Compression= 1.06 *

*Br 1 :TauBd1 : TauBd1/D *
*Entries : 111782 : Total Size= 897259 bytes File Size = 871489 *
*Baskets : 29 : Basket Size= 32000 bytes Compression= 1.03 *

*Br 2 :LxyBd1 : LxyBd1/D *
*Entries : 111782 : Total Size= 897259 bytes File Size = 865076 *
*Baskets : 29 : Basket Size= 32000 bytes Compression= 1.04 *

[/code]where the first Scan shows that indeed you have vectors/collections in the original files while the 2nd scan shows that indeed you have one double per entries. (Now whether or now this is what you need is a different question).

Cheers,
Philippe.

Dear Philippe,

Thank you so very much, that’s exactly what i need. Looking at the branches that seems in view looks like as in the original ntuple and the segmentation violation i got from the rooFit macro (now i fix the bug) allow me to think that the transfer was wrong … now everything works well.

Thank you so very much for your time and your help

Best regards
Mohamed