Projecting a branch to a histogram with a cut


I’m new to ROOT and don’t have much experience programming, so maybe my problem is trivial, but I need help. Here is the code I try running.

  int crystals=8000;
  TFile *f=new TFile("MyFile.root");
  TTree* t=(TTree*)f->Get("MyTree");
  TCut cut; vector<double> edep;

  for (int i=1; i<=crystals ; i++) {
   t->Project("hist","MyBranch1", Form("MyBranch2==%f", i));

The first iteration runs smooth, but in the next one has a problem. I’m not sure what happens when I try projecting a branch to a hist that is already filled, it seems that that is what creates the problem.