void HFDHE2PolymerEstimator::accumulate(WalkerIterator first, WalkerIterator last, RealType wgt)
  {
    for(int i=0; i<NumCopies; i++) 
    {
      RealType uw(Reptile->UmbrellaWeight[i]);
      //Adding all parts from the Hamiltonian
      RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
      RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
      RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
      scalars[0](eloc,uw);
      for(int obsi=0;obsi<SizeOfHamiltonians ;obsi++){
        scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
      };
      //Center Pressure
      RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
      scalars[SizeOfHamiltonians+3]( (2.0*eloc-2.0*CenProp[LOCALPOTENTIAL])*pNorm + CenProp[Pindex+1+FirstHamiltonian] ,uw);
      
      int Rage(Reptile->Age);
      int Bage=Rage;

      RealType tmpV=0.0;
      RealType tmpP=0.0;
      KEconst = (*(Reptile->begin()))->Drift.size()  * 1.5 * OneOverTau;
      for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
        tmpP+= (*Bit)->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
        tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
        Bage=min((*Bit)->stepmade,Bage);
      };

      tmpP-=0.5*Reptile->back()->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
      tmpP-=0.5*Reptile->front()->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
      tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpV *= -2.0*pNorm*Tau;
      tmpP *= Tau;

      scalars[SizeOfHamiltonians+1](tmpV+tmpP,uw);
      scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpP),uw);
      scalars[SizeOfHamiltonians+4](Rage-Bage,1.0);

    }
  }
void MJPolymerEstimator::accumulate(const MCWalkerConfiguration& W
                                    , WalkerIterator first, WalkerIterator last, RealType wgt)
{
    for(int i=0; i<NumCopies; i++)
    {
        RealType uw(Reptile->UmbrellaWeight[i]);
        //Adding all parts from the Hamiltonian
        RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
        RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
        RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
        scalars[0](eloc,uw);
        for(int obsi=0; obsi<SizeOfHamiltonians ; obsi++) {
            scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
        };
        //Center Pressure
        RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
        scalars[SizeOfHamiltonians+6]( (2.0*eloc-CenProp[LOCALPOTENTIAL])*pNorm ,uw);
        scalars[SizeOfHamiltonians+9]( CenProp[LOCALPOTENTIAL] ,uw);
        scalars[SizeOfHamiltonians+10]( HeadProp[LOCALENERGY] * TailProp[LOCALENERGY] ,uw);
        RealType energy_head = HeadProp[LOCALENERGY];
        RealType energy_tail = TailProp[LOCALENERGY];
        scalars[SizeOfHamiltonians+11]( HeadProp[LOCALENERGY] ,uw);
        scalars[SizeOfHamiltonians+12]( TailProp[LOCALENERGY] ,uw);

//       int Rage(Reptile->Age);
//       int Bage=Rage;
//
// //       RealType tmpE=0.0;
//       RealType tmpV=0.0;
// //       RealType tmpF=0.0;
// //       RealType localE=0.0;
// //       KEconst = (*(Reptile->begin()))->Drift.size()  * 1.5 * OneOverTau;
//       for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
// //         localE += 0.5*( (*Bit)->deltaRSquared[0] + (*Bit)->deltaRSquared[1]);
// //         tmpF+= 0.5*(*Bit)->deltaRSquared[2];
// //         tmpE+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
//         tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//         Bage=min((*Bit)->stepmade,Bage);
//       };
//
// //       tmpF-=0.25*Reptile->back()->deltaRSquared[2];
// //       tmpF-=0.25*Reptile->front()->deltaRSquared[2];
// //       tmpE-=0.5*Reptile->back()->getPropertyBase(i)[LOCALENERGY];
// //       tmpE-=0.5*Reptile->front()->getPropertyBase(i)[LOCALENERGY];
//       tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV *= -pNorm*Tau;
//
// //       localE *= -0.5*OneOverTau*OneOverTau;
// //       localE += KEconst* (Reptile->Last) + tmpF ;
// //       localE += tmpE;
//
//       scalars[SizeOfHamiltonians+1](tmpV,uw);
//       scalars[SizeOfHamiltonians+2](eloc*tmpV,uw);
//
//       scalars[SizeOfHamiltonians+4](Rage-Bage,1.0);

        ///This is the center bead energy using PIMC stuff.
//       localE *= 1.0/(Reptile->Last);
//       scalars[SizeOfHamiltonians+5]( localE ,uw);

        int Rage(Reptile->Age);
        int Bage=Rage;

        RealType tmpV_head=0.0;
        RealType tmpV_tail=0.0;
        RealType tmpF=0.0;
        int maxtouch=0;
        MultiChain::iterator Bit = Reptile->begin();
        MultiChain::iterator Lit = Reptile->end();
        MultiChain::iterator Endit = Reptile->end();
        Endit--;

        //truncated version of estimator
        Lit--;
        for(int j=0 ; ( (j<truncLength[0]) && (Bit != Endit) ); Bit++,Lit--,j++) {
            tmpV_head+= (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
            tmpV_tail+= (*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
            if ((*Bit)->timesTouched>maxtouch) maxtouch = (*Bit)->timesTouched;
            if ((*Bit)->stepmade < Bage) Bage = (*Bit)->stepmade;
        };
        RealType Ppref = (-pNorm*Tau);





        RealType tmpVsum = (energy_tail*tmpV_head + energy_head*tmpV_tail)*Ppref;
        scalars[SizeOfHamiltonians+3]((tmpV_head+tmpV_tail)*Ppref,uw);
        scalars[SizeOfHamiltonians+4](0.0,uw);
        scalars[SizeOfHamiltonians+5]( tmpVsum,uw);

        //continue sum for comparison to truncated version
        for( ; Bit != Endit; Bit++ ) {
            tmpV_head+= (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//         tmpV_tail+= (*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
            if ((*Bit)->timesTouched>maxtouch) maxtouch = (*Bit)->timesTouched;
            if ((*Bit)->stepmade < Bage) Bage = (*Bit)->stepmade;
        };

        RealType tmpV = tmpV_head*Ppref;
        RealType tmpEVsum = 0.5*(energy_head  + energy_tail)*tmpV;
        scalars[SizeOfHamiltonians+1](tmpV,uw);
        scalars[SizeOfHamiltonians+2](tmpEVsum,uw);


        scalars[SizeOfHamiltonians+7](Rage-Bage,1.0);
        scalars[SizeOfHamiltonians+8](maxtouch,1.0);

        //calculate correlation between head energy and energy at some point in chain to truncate correctly
        Bit= Reptile->begin();

        ObsEvals+=1.0;
        RealType Opf=1.0/ObsEvals;
        for(int j=0; Bit != (Reptile->end()); Bit++,j++) {
            ObsCont[j]+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
            ObsContAvg[j]=ObsCont[j]*Opf;
            ObsCont2[j]+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
            ObsContAvg2[j]=ObsCont[j]*Opf;
        };
        int AC(-1);
        RealType tmpE=1.0;
        RealType Hac=HeadProp[LOCALENERGY]-ObsContAvg[0];

        Bit = Reptile->begin();
        Bit++;
        for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++) {
            tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALENERGY]-ObsContAvg[j] );
            AC+=1;
        };
        scalars[SizeOfHamiltonians+13](AC,uw);

        int AC2(-1);
        tmpE= -1.0;
        Bit = Reptile->begin();
        if (Hac*((*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[0]) >0) tmpE=1.0;
        Bit++;
        for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
        {
            tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[j] );
            AC2+=1;
        }

        scalars[SizeOfHamiltonians+14](AC2,uw);
        scalars[SizeOfHamiltonians+15](CenProp[Findex+FirstHamiltonian],uw);
        scalars[SizeOfHamiltonians+16](CenProp[Findex+1+FirstHamiltonian],uw);
    }
}
void HFDHE2PolymerEstimator::accumulate(const MCWalkerConfiguration& W
                                        , WalkerIterator first, WalkerIterator last, RealType wgt)
{
  for(int i=0; i<NumCopies; i++)
  {
    RealType uw(Reptile->UmbrellaWeight[i]);
    //Adding all parts from the Hamiltonian
    RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
    RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
    RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
    scalars[0](eloc,uw);
    for(int obsi=0; obsi<SizeOfHamiltonians ; obsi++)
    {
      scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
    };
    //Center Pressure
    RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
    scalars[SizeOfHamiltonians+5]( (2.0*eloc-2.0*CenProp[LOCALPOTENTIAL])*pNorm + CenProp[Pindex+1+FirstHamiltonian] ,uw);
    int Rage(Reptile->Age);
    int Bage=Rage;
    RealType tmpV=0.0;
    RealType tmpF=0.0;
//       if (truncLength<0){
//         for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
//           tmpF+= (*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//           tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//           Bage=min((*Bit)->stepmade,Bage);
//         };
//
//       tmpF-=0.5*Reptile->back()->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//       tmpF-=0.5*Reptile->front()->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//       tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV *= -2.0*pNorm*Tau;
//       tmpF *= Tau;
//
//       scalars[SizeOfHamiltonians+1](tmpV+tmpF,uw);
//       scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpF),uw);
//       scalars[SizeOfHamiltonians+3](tmpV+tmpF,uw);
//       scalars[SizeOfHamiltonians+4](eloc*(tmpV+tmpF),uw);
//       } else {
    int maxtouch=0;
    MultiChain::iterator Bit = Reptile->begin();
    MultiChain::iterator Lit = Reptile->end();
    MultiChain::iterator Endit = Reptile->end();
    Endit--;
    //truncated version of estimator
    Lit--;
    for(int j=0 ; ( (j<truncLength) && (Bit != Endit) ); Bit++,Lit--,j++)
    {
      tmpF+= 0.5*(*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpF+= 0.5*(*Lit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
      if ((*Bit)->timesTouched>maxtouch)
        maxtouch = (*Bit)->timesTouched;
      if ((*Bit)->stepmade < Bage)
        Bage = (*Bit)->stepmade;
    };
    RealType tmpval = (tmpV*(-2.0*pNorm) + tmpF)*Tau;
    scalars[SizeOfHamiltonians+3](tmpval,uw);
    scalars[SizeOfHamiltonians+4](eloc*tmpval,uw);
    //continue sum for comparison to truncated version
    for( ; Bit != Endit; Bit++,Lit--)
    {
      tmpF+= 0.5*(*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpF+= 0.5*(*Lit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
      if ((*Bit)->timesTouched>maxtouch)
        maxtouch = (*Bit)->timesTouched;
      if ((*Bit)->stepmade < Bage)
        Bage = (*Bit)->stepmade;
    };
    tmpV *= -2.0*pNorm*Tau;
    tmpF *= Tau;
    scalars[SizeOfHamiltonians+1](tmpV+tmpF,uw);
    scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpF),uw);
    scalars[SizeOfHamiltonians+6](Rage-Bage,1.0);
    scalars[SizeOfHamiltonians+7](maxtouch,1.0);
    scalars[SizeOfHamiltonians+8](CenProp[LOCALPOTENTIAL] ,uw);
    //calculate correlation between head energy and energy at some point in chain to truncate correctly
    Bit= Reptile->begin();
    ObsEvals+=1.0;
    RealType Opf=1.0/ObsEvals;
    for(int j=0; Bit != (Reptile->end()); Bit++,j++)
    {
      ObsCont[j]+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
      ObsContAvg[j]=ObsCont[j]*Opf;
      ObsCont2[j]+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      ObsContAvg2[j]=ObsCont[j]*Opf;
    };
    int AC(-1);
    RealType tmpE=1.0;
    RealType Hac=HeadProp[LOCALENERGY]-ObsContAvg[0];
    Bit = Reptile->begin();
    Bit++;
    for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
    {
      tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALENERGY]-ObsContAvg[j] );
      AC+=1;
    };
    scalars[SizeOfHamiltonians+9](AC,uw);
    int AC2(-1);
    tmpE= -1.0;
    Bit = Reptile->begin();
    if (Hac*((*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[0]) >0)
      tmpE=1.0;
    Bit++;
    for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
    {
      tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[j] );
      AC2+=1;
    };
    scalars[SizeOfHamiltonians+10](AC2,uw);
  }
}