/////////////////////////////////////////////////////////////////////
//  PChannel Class implementation file
//
//  PChannel is one of the main classes of Pluto.
//  A Channel object represents one step of a reaction process,
//  namely of a parent particle decaying into n decay products.
//  A Channel consists of parent and decay particles and
//  the decay mode. For an overview of the Pluto package
//  see also PData, PParticle, PReaction, and PFilter.
//
//                                  Author:  M.A. Kagarlis
//                                  Written: 21.01.99
//                         p+d part revised: 13.10.00 by V. Hejny
//                                  Revised: 19.08.03 by R. Holzmann
//            angular distributions Revised: 08.11.03 by I. Froehlich
//           propagate parent index Revised: 22.03.05 by R. Holzmann
//                     set sourceId Revised: 13.04.05 by R. Holzmann
//                  helicity angles Revised: 28.11.05 by I. Froehlich
//          eta->3pi matrix element Revised: 05.12.05 by I. Froehlich
//             ds_dt(cos) bug fixed Revised: 11.07.06 by R. Holzmann
//            e_cm static bug fixed Revised: 29.08.06 by R. Holzmann
//
//
////////////////////////////////////////////////////////////////////

using namespace std;
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>

#include "PDefines.h"

const char *Message[14] = {
    "PChannel: operation successful",
    "PChannel: invalid pids",
    "PChannel: reconstruct failed, increase beam energy",
    "PChannel: decay failed, system invariant mass is zero",
    "PChannel: decay failed, insufficient energy",
    "PChannel: genbod failed, fewer than two decay products",
    "PChannel: genbod failed",
    "PChannel: baryon_cos algorithm failed",
    "PChannel: mflag must be 0 or 1",
    "PChannel: aflag must be 0 or 1",
    "PChannel: bflag must be 0 or 1",
    "PChannel: reconstruct failed for deuteron Fermi sampling",
    "PChannel: invalid decay-mode index in the constructor",
    "PChannel: inconsistent particle array with decay-mode index"};

#include "PChannel.h"
#include "PDynamicData.h"
#include "PUtils.h"
#include "PFileInput.h"
#include "PFireball.h"
#include "PDiLepton.h"
#include "PKinematics.h"



double PChannel::globalWeight = 1.;              // global channel weight

PChannel::PChannel(PParticle **particles, int nt, int, int, int) {
    // Channel constructor by pointer to array of pointers to particles
    // (parent, decay products), number of decay particles (default 2).
    // ____________________________________________________________________________
    // Flags: (obsolete)

    makeStdData()->fillDataBase();//init physics, if not yet done
    init_done = kFALSE;
    e_cm = 0;
    int i, k = -1;
    status = (!particles);         // true if argument pid array is invalid
    n = nt;                        // number of product particles
  
    if (!status) {
	ipid.Set(n+1);                 // pid array
	for (i=0; i<=n; ++i) {
	    k = particles[i]->ID();      // id of current particle
//      if ((i&&k>1000)||!k) {       // error in pid (Not longer true, IF)
	    if (!k) { 
		status = 1;
		ipid.~TArrayI();
		break;
	    }
	    ipid[i] = k;
	}
    }
    if (status) {                  // failed
	printf("%s:", Message[status]);
	for(i=0; i<=n; i++) printf(" %d", particles[i]->ID());
	printf("\n");
	return;
    }

    ptcls = particles;
    ptcls_extern = -1;

    IsReaction();     // if reaction channel, identify beam, target & decay mode

    particles[0]->SetDecayModeIndex(makeStaticData()->GetDecayIdxByKey(decay_key));

    w = particles[0]->W();           // weight on instantiation
    ecm = particles[0]->M();         // system invariant mass on instantiation
    DMIndex=makeStaticData()->GetDecayIdx(ipid.GetArray(),n); // match decay mode with PData
}

PChannel::PChannel(int idx, PParticle **particles, int, int, int) {
    // Channel constructor by decay-mode index
    
    makeStdData()->fillDataBase();//init physics, if not yet done
    init_done = kFALSE;
    e_cm = 0;
//    status=(idx<0||idx>PData::maxnummodes);
    //get key
    Int_t key = makeDataBase()->GetEntryInt("didx", idx);
    Int_t ia[11];
    ia[0] = 10;
    if (key < 0) {
	printf("%s\n", Message[12]);    // invalid decay mode
	return;
    } else 
	makeStaticData()->GetDecayMode(idx,ia); // retrieve decay-mode info

    DMIndex = idx;                   // decay-mode index
    n = ia[0];                       // number of products in current mode
    ipid.Set(n+1);                   // set up pid array
    
    if (!particles) {                // no particle-array passed as argument
	ptcls = new PParticle*[n+1];   // create channel particle array
	for(int i=0; i<=n; i++) ptcls[i] = 0;
	ptcls_extern = 0;
    } else {
	ptcls = particles;          // copy
	ptcls_extern = -1;
    }
    
    int i;
    for (i=0; i<=n; ++i) {             // fill particle and id arrays
	if (particles) 
	    ipid[i] = particles[i]->ID();
	else {                         // create from decay-mode info
	    if (!i)                      // parent id
		ipid[0] = makeStaticData()->GetDecayParent(idx);
	    else 
		ipid[i] = ia[i+1];        // product ids
	    ptcls[i] = new PParticle(ipid[i]);
	}
    }      
    
    if (particles) {                 // consistency checks
	ia[0] = ipid[0];               // reset first entry to parent pid
	PUtils::isort(ia, n+1);        // sort pids (parent & products) in ascending order
	TArrayI test(ipid);            // make a copy of channel pid array
	PUtils::isort(test.GetArray(), n+1);// sort as well
	int hit = 0;
	for (i=0; i<=n; ++i)             // ompare id arrays
	    hit += (test[i]==ia[i]);
	if (hit != n) {                  // input array inconsistent with decay-mode index
	    printf("%s\n", Message[13]);
	    ipid.~TArrayI();
	    return;
	}
    }
    
    IsReaction();                  // if reaction channel identify beam, target & decay mode

    ptcls[0]->SetDecayModeIndex(makeStaticData()->GetDecayIdxByKey(decay_key));

    w = ptcls[0]->W();               // weight on instantiation
    ecm = ptcls[0]->M();             // system invariant mass on instantiation
}     

PChannel::PChannel(int idx, PParticle &parent, int, int, int) {
    // Channel constructor by decay-mode index and parent reference
    
    makeStdData()->fillDataBase();//init physics, if not yet done
    init_done = kFALSE;
    e_cm = 0;

    //get key
    Int_t key = makeDataBase()->GetEntryInt("didx", idx);
    Int_t ia[11];
    ia[0] = 10;
    if (key < 0) {
	printf("%s\n", Message[12]);    // invalid decay mode
	return;
    } else 
	makeStaticData()->GetDecayMode(idx,ia); // retrieve decay-mode info

    DMIndex = idx;                   // decay-mode index
    n = ia[0];                       // number of products in current mode
    ipid.Set(n+1);                   // set up pid array
    
    ptcls = new PParticle*[n+1];     // create channel particle array
    ptcls[0] = &parent;
    ptcls_extern = 1;
    ipid[0] = parent.ID();           // parent id

    if (ipid[0] != makeStaticData()->GetDecayParent(idx)) {
	printf("%s\n", Message[13]);
	ipid.~TArrayI();
	delete [] ptcls;
	return;
    }

    int i;
    for (i=1; i<=n; ++i) {             // fill particle and id arrays
	ipid[i] = ia[i];               // product ids
	ptcls[i] = new PParticle(ipid[i]);
    }

    IsReaction();                    // if reaction channel identify beam, target & decay mode

    ptcls[0]->SetDecayModeIndex(makeStaticData()->GetDecayIdxByKey(decay_key));

    w = ptcls[0]->W();                 // weight on instantiation
    ecm = ptcls[0]->M();               // system invariant mass on instantiation
}     

void PChannel::IsReaction() {
    // Identify beam and target if the current channel is a beam + target reaction.
 
    event_impact_param = (makeStaticData()->GetBatchValue("_event_impact_param"));
    event_plane        = (makeStaticData()->GetBatchValue("_event_plane"));
    weight_version     = makeStaticData()->GetBatchValue("_system_weight_version");

    makeDynamicData()->PushPChannel((TObject *) this);

    parent      = ptcls[0];
    orig_parent = ptcls[0];
    int k = GetParentSize();                   // get parent size
    thSrc = 0;
    tcSrc = 0;
    dlSrc = 0;
    sourceid = 0;
    fEnablePattern = 0;
    thermal_disable_didx = 0;
    num_not_finalized = 0;

    distribution_position = 0;
    print_tentative = kTRUE;
    quasi_pchannel = NULL;
    weight_sum = 0;
    tid = bid = 0;
    bulkdecay_pos = 0;
    pro_bulkdecay_pos = 0;
    current_projector = NULL;

    events = makeStaticData()->GetBatchValue("_system_total_event_number");

    k = GetParentSize();
// The grandparent is not known yet at this stage, it is set in PReaction::setUp() only!

    parent->SetSourceId(parent->ID());
    parent->SetParentId(0);

    for (int i=1; i<=n; i++) {
	ptcls[i]->SetValue(CHANNEL_POS, (double)i);
    }

    emin = 0.;                       // channel energy threshold

    if (k == 1) {                              // decay of size=1 parent
	if (parent->IsFireball()) 
	    thSrc = 1;
	else if (parent->IsFileInput()) 
	    tcSrc = 1;
	else if (parent->IsDilepton()) 
	    dlSrc = 1;
	else {
	    IdChannel();
	    //get data base key:
	    decay_key = makeStaticData()->GetDecayKey(ipid.GetArray(), n);
	    CheckDecayKey();
	    return;	 
	}
    }

    //Continue with compound parents

    parent->SetParentIndex(-2);              // Set some indexes for the compound object
    parent->SetIndex(-1);

    tid = ipid[0]/1000;                    // target id
    bid = ipid[0]%1000;                    // beam id

    IdChannel();                             // identify reaction if known
 
    //get data base key:
    decay_key = makeStaticData()->GetDecayKey(ipid.GetArray(), n);
    if ((decay_key < 0) && (ipid[0]>999)) {
	//If not yet defined, add the decay of composites to the data base
	decay_key = makeStaticData()->AddDecay(ipid.GetArray(), n);
    }
    if (!thSrc && !tcSrc) CheckDecayKey();
    //check for emin in initial states
    for (int i=1; i<=n; ++i) { 
	emin += PData::LMass(ptcls[i]->ID());
    }

    //BUGBUG: check for an additional Decayemin
}

void PChannel::CheckDecayKey(void) const {

    if (decay_key < 0) {
	Error("Initialization", "No database entry for:");
	cout << "               ";
	PrintReaction(0);
	Error("Initialization", "Bye...");
	exit(1);
    }
}

void PChannel::IdChannel() {
    // Make quasi-channel for d+p reactions

    int i, nucleon_pid;

    spectator       = NULL;
    participant     = NULL;
    quasi_composite = NULL;
    quasi_pchannel  = NULL;

    //Workaround for backward-compatibility
    //check id beam or target is a d, and we have
    //no d in the exit channel. In this case, we
    //construct a helper PChannel in oder to get the
    //"real" scattering

    //First, we check if all particles have the spec flag=-1
    //this is the case when using the decay parser but not "(x)"

    int has_spec = 0;
    for (i=1; i<=n; ++i) {
	if (ptcls[n]->IsSpectator() != -1)
	    has_spec=1;
    }
    
    if (!has_spec) return;

    has_spec = ptcls[n]->IsSpectator();

    //if spectator model not forced, do it only for d
    if (has_spec == 0) {
	if ((bid != makeStaticData()->GetParticleID("d")) &&
	    (tid  != makeStaticData()->GetParticleID("d")))
	    return;
	//in this case the, spectator must be a nucleon
	if (!ptcls[n]->IsNucleon()) return;
    }
        
    for (i=1; i<=n; ++i) {
	if (!has_spec) {
	    if (ptcls[i]->ID() == makeStaticData()->GetParticleID("d")) 
		return; // coherent scattering
	}
	if (ptcls[i]->ID()>1000) return; //dummy PChannel
    }

    //get the nucleon pid
    if (bid == makeStaticData()->GetParticleID("d")) 
	nucleon_pid = tid;
    else 
	nucleon_pid = bid;

    //identify the spectator
    spectator = ptcls[n];

    //identify the participant
    if (spectator->ID() == makeStaticData()->GetParticleID("p"))
	participant = new PParticle("n");
    else if (spectator->ID() == makeStaticData()->GetParticleID("n"))
	participant = new PParticle("p");
    else {
	//loop over first part, misuse "spectator flag"
	for (i=1; i<=(n-1); ++i) {
	    if (ptcls[i]->IsSpectator() == 1)
		participant = new PParticle(ptcls[i]);
	}
	//special case when we have a quasi-reaction (a b) is more complicated
	//in this case b is the participant
	Int_t a_pos = -1;
	for (i=1; i<=(n-1); ++i) {
	    if (ptcls[i]->IsSpectator() == 3)
		participant = new PParticle(ptcls[i]);
	    if (ptcls[i]->IsSpectator() == 2)
		a_pos = i;
	}
	if (a_pos != 1)  {
	    Error("IdChannel","Quasi-reaction must come at first");
	} else if ((a_pos == 1) && (participant)) {//....  a and b have to be removed
	    for (i=1; i<=(n-3); ++i) {
		ptcls[i] = ptcls[i+2];
		ipid[i]  = ipid[i+2];
	    }
	    n -= 2;
	}

	if (!participant) {
	    Warning("IdChannel", "No valid spectator found");
	    return;
	}
    }

    PParticle dummy(nucleon_pid);
    if (nucleon_pid == tid) { //d beam
	quasi_composite = new PParticle(*participant + dummy);
    } else {
	quasi_composite = new PParticle(dummy + *participant);  
    }
    PParticle **cc1 = new PParticle*[3];   // create channel particle array
    cc1[0] = parent;
    cc1[1] = quasi_composite;
    cc1[2] = spectator;

    quasi_pchannel = new PChannel(cc1,2);

    //now we have to touch a little bit myself:
    //the spectator is removed from the list, and the parent id replaced by
    //the dummy composite
    
    Info("IdChannel", "(%s) Quasi-free production", PRINT_AUTO_ALLOC);

    n--;
  
    parent      = quasi_composite;
    orig_parent = quasi_composite;
    ptcls[0]    = quasi_composite;
    ipid[0]     = quasi_composite->ID();
}

void PChannel::ThermalSampling() {
    // parent is midrapidity thermal source

    double px, py, pz, Energy;
    float b = 0., phi = 0.;
    int i, nTherm = n;
    PFireball *pFire =          // pointer to thermal source
	(ptcls[0]->IsFireball()) ? (PFireball *)ptcls[0] : NULL;

    if (pFire->IsRandomB()) {             // sample impact parameter
	if (*event_impact_param == 0.) {
	    b = pFire->sampleB() + 0.001;     // sample new value
	    phi = 2.*TMath::Pi()*PUtils::sampleFlat(); // ev plane
	} else {
	    b   = *event_impact_param;    // use previous value
	    phi = *event_plane;
	}
	nTherm = pFire->sampleNProd(b);
	if (nTherm > n) nTherm = n;
    } else if (pFire->IsRandomN()) {        // sample multiplicity directly
	nTherm = pFire->sampleNProd();
	if (*event_plane == 0.) 
	    phi = 2.*TMath::Pi()*PUtils::sampleFlat(); // ev plane
	else 
	    phi = *event_plane;
	if (nTherm > n) 
	    nTherm = n;
    }

    *event_impact_param = b;
    *event_plane        = phi;
    for(i=1; i<=nTherm; i++) {
	int didx = ptcls[i]->GetDecayModeIndex(1);
    redo_thermal:
	if (nTherm == 1) {
	    pFire->samplePartCM(px, py, pz, Energy,didx);
	} else {
	    //when having more then one product with different didx
	    //it causes endless time because the 2dim ROOT sampling
	    //will regenerate the polynomials each time
	    if (thermal_disable_didx)
		pFire->samplePartCM(px, py, pz, Energy, -1);
	    else if ((i>1) && didx != ptcls[i-1]->GetDecayModeIndex(1)) {
		//inconsistent didx -> disable
		thermal_disable_didx = 1;
		Warning("ThermalSampling","Different decays, disable partial decay sampling");
	    } else {
		pFire->samplePartCM(px, py, pz, Energy, didx);
	    }
	}
	ptcls[i]->SetPxPyPzE(px, py, pz, Energy);
	if (ptcls[i]->M() < PData::LMass(ptcls[i]->ID()) || ptcls[i]->M() > PData::UMass(ptcls[i]->ID())) goto redo_thermal; //DONEv6
	ptcls[i]->SetW(w*(pFire->mtScale(ptcls[i]->M())));  // weight * mt-scaling
	if (sourceid) 
	    ptcls[i]->SetSourceId(sourceid);
	else 
	    ptcls[i]->SetSourceId(pFire->ID());
	
	ptcls[i]->SetParentId(pFire->ID());
	ptcls[i]->SetActive();
    }
    for(i=nTherm+1; i<=n; i++) {
	ptcls[i]->SetInActive();  // inactivate rest
    }

    TVector3 Beta = pFire->BoostVector();
    if (Beta.Mag() > 0.) {
	for(i=1; i<=nTherm; ++i) {
	    ptcls[i]->Boost(Beta);
	}
    }
}

void PChannel::MakeDilepton() {
    // parent is dilepton source

    double px, py, pz, Energy;
    PDiLepton * pDL =          // pointer to dilepton
	(ptcls[0]->IsDilepton()) ? (PDiLepton *)ptcls[0] : NULL;

    pDL->samplePartCM(px, py, pz, Energy);
    ptcls[1]->SetPxPyPzE(px, py, pz, Energy);
    ptcls[1]->SetW(w);
    ptcls[1]->SetSourceId(pDL->ID());
    ptcls[1]->SetParentId(pDL->ID());
    ptcls[1]->SetActive();

    TVector3 Beta=pDL->BoostVector();
    if (Beta.Mag()>0.) ptcls[1]->Boost(Beta);
}

Int_t PChannel:: ReadFileInput() {  // parent is file input

    Double_t px, py, pz, Energy, vx, vy, vz, vt;
    Float_t b = 0., phi = 0.;
    Int_t id, idSrc, idPar, indPar = -2, ret;
    Int_t i, nFile = 0, nMax;
    PFileInput *pFile =             // pointer to file input interface
	(ptcls[0]->IsFileInput()) ? (PFileInput*)ptcls[0] : NULL;

    nMax = nFile = pFile->readEventHeader(b);  // read event header
    if (nFile == -1) {
	printf("**** EOF reached on file input ****\n");
	for(i=1; i<=n; i++) 
	    ptcls[i]->SetInActive();  // inactivate all
	return 8;
    }

    if (nMax > n) nMax = n;
  
    if (*event_impact_param == 0.) {
	phi = 2.*TMath::Pi()*PUtils::sampleFlat(); // ev plane
    }
    else {
	b =   *event_impact_param;           // use previous value
	phi = *event_plane;
    }

    *event_impact_param = b;
    *event_plane = phi;
    
    for(i=1; i<=nFile; i++) {
	ret = pFile->readParticle(px,py,pz,Energy,vx,vy,vz,vt,id,idSrc,idPar,indPar,w);
	if (ret == -1) break;  // EOF
	if (i > n) continue;
	ptcls[i]->SetID(id);           // reset particle ID
	ptcls[i]->SetPxPyPzE(px, py, pz, Energy);
	ptcls[i]->ResetE();            // make Energy consistent with mass
	ptcls[i]->SetW(w);
	ptcls[i]->SetSourceId(idSrc);
	ptcls[i]->SetParentId(idPar);
	ptcls[i]->SetParentIndex(indPar);
	ptcls[i]->SetActive();
	ptcls[i]->SetVertex(vx,vy,vz,vt);
    }
    if (ret == -1) return 8;
    for(i=nMax+1; i<=n; i++) 
	ptcls[i]->SetInActive();  // inactivate rest

    TVector3 Beta = pFile->BoostVector();
    if (Beta.Mag() > 0.) 
	for(i=1; i<=nMax; ++i) 
	    ptcls[i]->Boost(Beta);
    return 0;
}

int PChannel::CheckSiblings(PParticle *p, PDistribution *dist, int flag) {
    if (p == NULL) {
	return -1;
    }

    if (p->GetParent()) //Fireball daughters: no check for siblings
	if ((p->GetParent()->ID() > 500) && (p->GetParent()->ID() <1000)) return -1;

    if (p->ID() >= 1000) return -1; //no sibling for compounds

   //  cout << "******************checkSiblings for " <<dist->GetName() <<   ", SEED: " << endl;
//      p->Print();
    
    PParticle *currentSibling = p->GetSibling();   
    Int_t counter = 0; //break condition
    Int_t ret     = -1;
    while (currentSibling != p) {
	if (currentSibling == NULL) return ret;
	if (ret == 0) { //found one more "additional" sibling -> reset 
	    ret = -1;
	}
  	//cout << "My sibling is:" << endl;
 	//currentSibling->Print();

	if (dist->SetParticle(currentSibling, currentSibling->ID(), flag | PARTICLE_LIST_SIBLING) == 0) { 
	    //I found the missing sibling
	    ret = 0;
	    //cout << "found the missing sibling" << endl;
	}  
	//jump to next sibling
	currentSibling = currentSibling->GetSibling();
	counter++;
	if (counter == 8) { //max 7 decay particles
	    Warning("CheckSiblings", "Sibling chain seems to be corrupted");
	    Print();
	    return -1;
	}
    }
//     cout << "RET: " << ret << endl;
//     dist->Print();
    if (ret == -1) dist->ResetRelatives(flag | PARTICLE_LIST_SIBLING); //RESET current flag
    return ret;
}

Bool_t PChannel::Reset() {
    for (int j=0; j<distribution_position; j++) {
	dist[j]->ResetRelatives();
	dist[j]->SetEnable(1); //can be done as disabled distr. are never attached
    }

    grandparent      = NULL;
    grandgrandparent = NULL;
    init_done        = kFALSE;

    return kTRUE;
}

Bool_t PChannel::SetDaughters() {
    if (thSrc || tcSrc)  return kTRUE; //makes no sense and print errors
    parent->ResetDaughters();
    
    if (parent->IsActive() == kTRUE) {
	for (Int_t k=1; k<=n; k++) {
	    parent->SetDaughter(ptcls[k]);
	}
    }
    return kTRUE;
}

Bool_t PChannel::Init() {
    //On the 1st call, set the grandparent, etc...
    //look for tentative distributions
    
    int has_printed = 0;
    //set parent, grandparent
    if (orig_parent != ptcls[0]) {
	//Workaround for PlutoBulkDecay
	parent = ptcls[0];
	*orig_parent = *(ptcls[0]);
    }

    grandparent = parent->GetParent();
    grandgrandparent = NULL;
    if (grandparent) 
	grandgrandparent = grandparent->GetParent();

    Double_t set_mode_index = 0;

    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if (dist[j]->GetVersionFlag() & VERSION_INVERT_WEIGHTING) {
	    set_mode_index++;
	} else if ((dist[j]->GetVersionFlag() & VERSION_WEIGHTING) 
		   && (dist[j]->GetVersionFlag() & VERSION_GENERATOR_MC) 
//		   && (dist[j]->GetExpectedWeightMean() < 0) 		
// This must be disabled, otherwise the Delta mass is not taken correctly
// Mass shape of the epja figure disagrees for sampling/weighting method		   
		   ) {
	    set_mode_index++;
	} else if (dist[j]->GetVersionFlag() & VERSION_FORCE_NO_PARTIAL_WIDTH) 
	    set_mode_index =  set_mode_index + 2;
    }

    if (set_mode_index < 2)  //
	ptcls[0]->SetDecayModeIndex(makeStaticData()->GetDecayIdxByKey(decay_key));
    else {
	ptcls[0]->SetDecayModeIndex(-1);
    }

    if (parent->IsActive() == kTRUE) {
	parent->SetDaughterIndex(ptcls[1]->GetIndex());
	Int_t parId, parInd;
	for (Int_t k=1; k<=n; k++) {
	    ptcls[k]->SetActive();          // activate children
	    if (sourceid) 
		ptcls[k]->SetSourceId(sourceid);
	    else 
		ptcls[k]->SetSourceId(parent->GetSourceId());

	    parId  = parent->ID();
	    parInd = parent->GetIndex();
	    if ((parId==50 || parId==51) && grandparent!=NULL) {
		parId += 1000*(grandparent->ID()); // if parent = dilepton,
		// add grandparent id
		parInd = grandparent->GetIndex();
	    }
	    ptcls[k]->SetParentId(parId);
	    ptcls[k]->SetParentIndex(parInd);
	    ptcls[k]->SetDaughterIndex(-1);
	    if (k != n) {
		ptcls[k]->SetSiblingIndex(ptcls[k+1]->GetIndex());
		ptcls[k]->SetSibling(ptcls[k+1]);
	    } else {
		ptcls[k]->SetSiblingIndex(ptcls[1]->GetIndex());
		ptcls[k]->SetSibling(ptcls[1]);
	    }	  
	}
    } //end parent active


    // check tentative distributions for additional particles

    for (int j=0; j<distribution_position; j++) {
	if ((dist[j]->GetStatus() == -1) && dist[j]->GetEnable()){ //not all particles set
	    if (has_printed == 0 && print_tentative) {
		has_printed = 1;
		cout << "checking tentative distributions for ";
		if (grandparent) {
		    if (grandparent->ID() < 1000)
			printf("%s --> ",makeStaticData()->GetParticleName(grandparent->ID()));
		}
		PrintReaction();
		cout << endl;
	    }
	    if (print_tentative) 
		printf("                             [checking] %s\n",
		       dist[j]->GetDescription());
	    //check grand(grand)parent itself

	    if (grandparent) {
		if (grandparent->ID() < 1000)
		    dist[j]->SetParticle(grandparent, grandparent->ID(), PARTICLE_LIST_GRANDPARENT);
		else
		    dist[j]->SetParticle(grandparent, DISTRIBUTION_QUASI_PID, PARTICLE_LIST_GRANDPARENT);
	    }
	    if (grandgrandparent) {
		if (grandgrandparent->ID() < 1000)
		    dist[j]->SetParticle(grandgrandparent, grandgrandparent->ID(), PARTICLE_LIST_GRANDGRANDPARENT);
		else
		    dist[j]->SetParticle(grandgrandparent, DISTRIBUTION_QUASI_PID, PARTICLE_LIST_GRANDGRANDPARENT);
	    }
#if 1
	    //sometimes we have to jump over a compound particle
	    if (parent->ID() >= 1000) {
		if (parent->GetScattering(0)) {
		    dist[j]->SetParticle(parent->GetScattering(0), parent->GetScattering(0)->ID(), PARTICLE_LIST_GRANDPARENT);
		    dist[j]->SetParticle(parent->GetScattering(1), parent->GetScattering(1)->ID(), PARTICLE_LIST_GRANDPARENT);
		}
	    } else if (grandparent) {
		if (grandparent->ID() >= 1000) {
		    if (grandparent->GetScattering(0)) {
			dist[j]->SetParticle(grandparent->GetScattering(0), grandparent->GetScattering(0)->ID(), PARTICLE_LIST_GRANDGRANDPARENT);
			dist[j]->SetParticle(grandparent->GetScattering(1), grandparent->GetScattering(1)->ID(), PARTICLE_LIST_GRANDGRANDPARENT);
		    }
		}
	    }

#endif

	    //check siblings for parent, grandparent, grandgrandparent	  
	    CheckSiblings(parent, dist[j], PARTICLE_LIST_PARENT);
	    if (grandparent) {
		CheckSiblings(grandparent, dist[j], PARTICLE_LIST_GRANDPARENT);
		if (grandgrandparent)
		    CheckSiblings(grandgrandparent, dist[j], PARTICLE_LIST_GRANDGRANDPARENT);
	    }

	    //check for granddaughters...
	    for (Int_t k=1; k<=n; k++) {
		//looping over daughters
		int kk = 0;
		
		while (ptcls[k]->GetDaughter(kk) != NULL) {  
		    
		    dist[j]->SetParticle(ptcls[k]->GetDaughter(kk), 
					 ptcls[k]->GetDaughter(kk)->ID(), 
					 PARTICLE_LIST_GRANDDAUGHTER);
		    kk++;
		}
	    }
	    
	    //final check
	    if (dist[j]->GetStatus() == -1) { //not all particles set
		if (print_tentative) printf("                             [removed] %s\n",dist[j]->GetDescription());
		dist[j]->SetEnable(0); 
	    }
	    else {
		if (dist[j]->Init() == kTRUE) {
		    if (print_tentative) printf("                             [enabled] %s\n",dist[j]->GetDescription()); }
		else {
		    printf("                             [error] %s:%s\n",dist[j]->GetDescription(),dist[j]->GetIdentifier());
		    dist[j]->SetEnable(0);
		  
		}
	    }
	}      
    }

    //after all, look for artificial models (primary)
    //this can happen when parent is composite

    Int_t num_mass_sampling = 0;
    if (parent->ID() > PLUTO_COMPOSITE) {
	for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	    if (dist[j]->GetVersionFlag() & VERSION_MASS_SAMPLING) {
		if (num_mass_sampling)
		    dist[j]->SetEnable(0);
		num_mass_sampling++;
	    }
	}
    }
    // end check tentative distributions
    init_done       = kTRUE;
    print_tentative = kFALSE;

    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    dist[j]->GetDepth();  //Init sub-models
	}
    }

    return kTRUE;
}

// Bool_t PChannel::InitEnv() {
//   //Init "envelope" afterburner for distributions spanning over a chain
//   cout << "**********init env" << endl; 
//   for (Int_t k=1;k<=n;k++) {
//     //looping over daughters
//     int kk=0;
//     ptcls[k]->Print();
//     while (ptcls[k]->GetDaughter(kk) != NULL) {  
//       cout << "found:" << endl;
//       ptcls[k]->GetDaughter(kk)->Print();
//       for (int j=0;j<distribution_position;j++) {
// 	dist[j]->Print();
// 	cout << dist[j]->GetStatus() << ":" << dist[j]->GetEnable() << endl;
// 	if ((dist[j]->GetStatus() == -1) && dist[j]->GetEnable()){ //not all particles set
// 	  dist[j]->SetParticle(ptcls[k]->GetDaughter(kk), 
// 			       ptcls[k]->GetDaughter(kk)->ID(), 
// 			       PARTICLE_LIST_GRANDDAUGHTER);
// 	}
//       }
//       kk++;
//     }
//   }
// }


int PChannel::Decay() {
    // The N-body phase-space decay function is based on the CERNLIB
    // routine GENBOD. 
    //
    // Return code:
    //
    // status = 0  all ok
    //        = 1  not used
    //        = 2  weighting negative
    //        = 3  not enough energy
    //        = 4  not enough energy to decay to final state
    //        = 5  genbod error (energy violation)
    //        = 6  genbod error (kinematics failed)
    //        = 7  genbod error (energy violation)
    //        = 8  EOF on input in PFileInput::readParticle()
    //        = 9  not used
    //        = 10 Abort distribution rejection after 10 times, do chain again
    //        = 11 Fermi sampling failed for deuteron wave function
    // > 80 is for PReaction
    //        = 80 Empty event
    //   STATUS_NOT_DECAYED 99

    TVector3 vCreation, vDecay;
    Double_t tCreation, tDecay;

    if (!init_done) Init();

    if (parent->IsActive() == kFALSE) {
	for (Int_t k=1; k<=n; k++) 
	    ptcls[k]->SetInActive();  // inactivate children
	return STATUS_OK;
    }
    else {
	for (Int_t k=1; k<=n; k++) {
	    if (ptcls[k]->ID() > 0)
		ptcls[k]->SetM(makeStaticData()->GetParticleMass(ptcls[k]->ID()));
	    ptcls[k]->SetActive();   
	}
	// re-activate children as they are de-activated in PReaction
      
	//Vertex calculations have to be done in each decay
	vCreation = parent->GetVertex();  // creation vertex of parent
	tCreation = parent->T();          // creation time of parent
	tDecay = tCreation + parent->Gamma() * parent->GetProperTime();
	vDecay = vCreation + parent->Gamma() * parent->GetProperTime()
	    * parent->BoostVector();  // decay vertex of parent
	for (Int_t k=1; k<=n; k++) {
	    ptcls[k]->SetProperTime();           // proper decay time (in mm/c)
	    ptcls[k]->SetVertex(vDecay,tDecay);  // set creation vertex of product
	    // ptcls[k]->clearDebugString();  BUGBUG
	}
    }

    int decay_done[n+1];
    int real_size = n+1;
    for (int i=0; i<=n; i++) {
	//ptcls[i]->Print();
	decay_done[i] = 0;
    }
    for (int bu=0; bu<pro_bulkdecay_pos; bu++) {
	pro_bulk[bu]->Modify(ptcls, decay_done, &real_size, n+1);
    }	

    w = parent->W();
    int i, nProd = n;

    status = 0;
    num_not_finalized = 0;

    if (thSrc) {                   // parent is a midrapidity thermal source
	ThermalSampling();
	decay_done[0] = 1;
	for (int bu=0; bu<bulkdecay_pos; bu++)
	    bulk[bu]->Modify(ptcls, decay_done, &real_size, n+1);

	return status;
    }    

    if (tcSrc) {                   // parent is transport code (file input)
	status = ReadFileInput();
	return status;
    }    

    if (dlSrc) {                   // parent is a Dilepton
	MakeDilepton();
	return status;
    }

    ecm = parent->M();

    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    dist[j]->Prepare();
	}
    } //Prepare can change the parent mass

    if (ecm < emin) {
	// cout << "ecm: " << ecm << " emin: " << emin <<  endl;
 	// parent->Print();
 	// Print();
	return status = 4; // not enough energy to do the channel
    }
    
    Int_t do_flag = 1, 
	distr_status = 0;
    while (do_flag) {  // do genbod loop until all distributions are convinced
	status = Genbod(nProd);  // induce first isotropic decay
	distr_status = 0;

	for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	    if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()) { //all particles set
		if (dist[j]->IsNotRejected() == kFALSE) { 
		    distr_status++;
		    if (dist[j]->CheckAbort()) {
			do_flag = 1000000;//set to big number, next step will abort
		    }
		}
	    } //end if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable())
	} // end for (int j=0;j<distribution_position;j++)

	if (distr_status) {// did not work out...
	    do_flag++;
	    if (do_flag > 10) { // abort after 10 times, do chain again
		status  = 10;
		do_flag = 0;
	    }
	} else {
	    do_flag = 0;
	} 
    } //end while (do_flag)

    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    if (!dist[j]->Finalize()) {
		//distribution is waiting for more....
		if (num_not_finalized < MAX_NUM_NOT_FINALIZED) {
		    distribution_not_finalized[num_not_finalized] = dist[j];
		    num_not_finalized++;
		} else {
		    Error("Decay","MAX_NUM_NOT_FINALIZED reached");
		}
	    }
	}
    }

    if (status) return status;                  // genbod failed

    //In a first step collect all weights from all distributions
    //This we have to do because in the increment we have to 
    //use the stat. scaling with 1/w
 
    Double_t new_weight              = ptcls[0]->W();
    Double_t hidden_generator_weight = ptcls[0]->GenW();
    Double_t inv_generator_weight    = ptcls[0]->InvGenW();
    Double_t dynamic_range = 1.;

    if (*weight_version) {	
#if 1
	Double_t generator_weight = hidden_generator_weight; 
	for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	    if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
		dist_weight[j] = dist[j]->GetWeight();
		if ((dist[j]->GetVersionFlag()) & VERSION_INVERT_WEIGHTING) { //Here I assume a "generator"
		    generator_weight *= dist_weight[j];
		    dynamic_range    *= dist[j]->GetDynamicRange();
		}
	    }
	}
	
	for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	    if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
		if (((dist[j]->GetVersionFlag()) & VERSION_INVERT_WEIGHTING) ||
		    ((dist[j]->GetVersionFlag()) & VERSION_WEIGHTING)) {
		    
		    Double_t local_weight = dist_weight[j];
		    //weighting is enabled
		
		    if ((dist[j]->GetVersionFlag()) & VERSION_GENERATOR_MC) { 
			//Pure function models
			//--> These are function for which we have
			//Int dx dsigma/dx = sigma
			//In this case, the boundaries have to be taken into account
			//This is the Delta_x in the MC integral
			local_weight *= dynamic_range;
			dynamic_range = 1.;
		    }	

		    if (dist[j]->GetExpectedWeightMean() > 0) { //re-scaling is allowed
			if ((dist[j]->GetVersionFlag()) & VERSION_INVERT_WEIGHTING) {
			    local_weight = (1./local_weight);
			    dist[j]->IncrementWeightSum(local_weight);
			} else {
			    //Weighting model
			    dist[j]->IncrementWeightSum(local_weight, 1./generator_weight);
			}
			local_weight *= (dist[j]->GetExpectedWeightMean()/dist[j]->CalcWeightMean());
		    } 

		    new_weight *= local_weight;  //fold with local weights
		    
		    dist_weight_sum[j] += local_weight;
		    dist_counter[j]++;
		} else { //for sampling models use just the mean
		    if (dist[j]->GetExpectedWeightMean() > 0) {
			new_weight *= dist[j]->GetExpectedWeightMean();
			dist_weight_sum[j] += dist[j]->GetExpectedWeightMean();
			dist_counter[j]++;
			
			//If we have broad resonances, like in the case
			//Delta->dilepton + gamma we have to keep the information
			//about the generator
			
			//this is only possible if we "push" the history of used generators
			//to the next PChannel(s)
			
			//check if weight is what we expect
			Double_t local_weight = dist_weight[j];
			//		hidden_generator_weight *=local_weight;
			
			Double_t inv_local_weight = 0.;
			if (local_weight > 0.) 
			    inv_local_weight = (1./local_weight);
			dist[j]->IncrementWeightSum(inv_local_weight);
			//		inv_generator_weight*=(inv_local_weight/dist[j]->CalcWeightMean());
		    } 
		    // else {
		    // 	new_weight*=dist_weight[j];
		    // }
		}
	    }
	}

	if (new_weight <= 0.) 
	    return status = 2; // something wrong

	weight_sum += new_weight;	
#endif
    }

//     for (i=1;i<=nProd;++i) {
// 	ptcls[i]->Print();
//     }

    TVector3 beta = parent->BoostVector();        // inv. mass velocity vector
    if (beta.Mag() > 0.) 
	for (i=1; i<=nProd; ++i) 
	    ptcls[i]->Boost(beta);

    for (i=1; i<=nProd; ++i) {
	ptcls[i]->SetParent(parent); // set pointer to parent
	//ptcls[i]->Print();
	ptcls[i]->SetW(new_weight);
	ptcls[i]->SetGenW(hidden_generator_weight);
	ptcls[i]->SetInvGenW(inv_generator_weight);
    }
    
#if 0
    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    //dist[j]->WriteDebugInfo(parent);
	}
    }
#endif
    decay_done[0] = 1;
    for (int bu=0; bu<bulkdecay_pos; bu++)
	bulk[bu]->Modify(ptcls, decay_done, &real_size, n+1);

    return status;
}

int PChannel::Genbod(int nProd) {
    // N-body phase-space decay of a particle in its rest frame,
    // wrapper function to all the distribution methods

    int i; 
    double conserve_e = 0., 
	em[nProd];
    Bool_t PDistribution_sampleMass  = kFALSE;
    int PDistribution_sampleMomentum = 0, 
	PDistribution_sampleModels   = 0;

    //MASS SAMPLING
    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()) { //all particles set
	    if ((dist[j]->GetVersionFlag()) & VERSION_SAMPLING)
		if (dist[j]->SampleMass()) {
		    PDistribution_sampleMass = kTRUE;
		    for (i=0; i<nProd; ++i) {
			em[i] = ptcls[i+1]->M(); //copy particle mass to array
		    }
		}
	}
    }

    conserve_e = ptcls[0]->M(); //take into account possible reconstruct

    if (PDistribution_sampleMass == kFALSE) { //No user-defined distribution    
	Warning("Genbod","No mass sampling model(s) found in %s",
		makeStaticData()->GetDecayNameByKey(decay_key));
	return status = 6;
    } else { //Recalculate total energy (for user-defined mass sampling)
	for (i=0; i<nProd; ++i) 
	    conserve_e -= em[i];
    }
  
    if ((conserve_e < -1.e-8) && (nProd>1) ) {
      // cout << "***********" << endl;
      // for (i=0;i<=nProd;++i) ptcls[i]->Print();
      // cout << conserve_e << endl;
	return status = 5;
    }
    conserve_e = ptcls[0]->M();

//     cout << ecm << endl;
//     ptcls[0]->Print();

    Int_t last_sampling_model = 0;

    //MOMENTUM SAMPLING
    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    if ((dist[j]->GetVersionFlag()) & VERSION_SAMPLING) {
		PDistribution_sampleModels++;
		if (dist[j]->SampleMomentum()) {
		    if (!PDistribution_sampleMomentum) last_sampling_model = j;
		    PDistribution_sampleMomentum++;
		} 
	    }
	    if (PDistribution_sampleMomentum > 1) {
		Warning("Genbod", "More than one momentum sampling model found in %s",
			makeStaticData()->GetDecayNameByKey(decay_key));
		Warning("Genbod","Model 1: [%s]", dist[last_sampling_model]->GetIdentifier());
		Warning("Genbod","Model 2: [%s]", dist[j]->GetIdentifier());
		
		return status=6;
	    }
	}
    }

    if (PDistribution_sampleModels == 0) {
	Warning("Genbod","No momentum sampling model found in %s",
		makeStaticData()->GetDecayNameByKey(decay_key));
	return status = 6;
    }

    //ANGLE SAMPLING
    for (int j=0; j<distribution_position; j++) { //loop over all valid distributions
	if ((dist[j]->GetStatus() == 0) && dist[j]->GetEnable()){ //all particles set
	    if ((dist[j]->GetVersionFlag()) & VERSION_SAMPLING)
		dist[j]->SampleAngle();
	}
    }

    //check conservation of energy again
    for (i=0; i<nProd; ++i) 
	conserve_e -= ptcls[i+1]->E();

    if (fabs(conserve_e) > 1.e-8) {
 	 // cout << "*************conserve_e" << conserve_e  << endl;
 	 // ptcls[0]->Print();
 	 // for (i=0;i<nProd;++i) ptcls[i+1]->Print();
 	 // cout << "*************" << endl;
	return status = 7; // conservation of energy violated
    }

    else return status=STATUS_OK;
}

int PChannel::SetDistribution(PDistribution *distribution) {
    //return -1 if distribution does not match the channel

    if (distribution->GetEnable() == 0) return -1;

    if (distribution_position == MAX_DISTRIBUTIONS) {
	Warning("SetDistribution","MAX_DISTRIBUTIONS reached");
	return -1;
    }

    Int_t check = 0;

    PParticle *p0 = ptcls[0];
    
    //The grand(grand)parent and sisters not known yet at this stage, 
    //will be done "online"
    //The only thing what I can do here is to have a 1st rough look

    distribution->Reset();

//    if (p0->ID() < 1000) //skip quasi-particles
//	check = distribution->SetParticle(p0, p0->ID(), PARTICLE_LIST_PARENT); 
//    else
//	check = distribution->SetParticle(p0, DISTRIBUTION_QUASI_PID, PARTICLE_LIST_PARENT); 

//either one of these methods has to work:
    check = distribution->SetParticle(p0, p0->ID(), PARTICLE_LIST_PARENT); 
    if (check<0 && (p0->ID() > 1000))
	check = distribution->SetParticle(p0, DISTRIBUTION_QUASI_PID, PARTICLE_LIST_PARENT); 

    for (int i=0;i<n;i++) {
	check += distribution->SetParticle(ptcls[i+1], ptcls[i+1]->ID(), PARTICLE_LIST_DAUGHTER); 
    }
   
    check += distribution->CheckDaughters(); //Are we still a daughter missing?

    if (!strcmp(distribution->GetName(), "_testmodel"))
	cout << "Check number in PChannel::SetDistribution: " << check << endl;
 
    //now check if this worked out....
    if (check < 0) {
	//forget it!
	if (distribution->debug_flag)
	     distribution->Print();

	distribution->Reset();
	return -1;
    }
    //success

    //Clone the distribution (done before in PDistributionManagerUtil)
    distribution = (PDistribution*) distribution->Clone();
    
    if (distribution->GetStatus() == 0) { //we are complete
	//cout << distribution->GetName() << " attached at" <<  distribution_position   << endl;
	if (distribution->Init() == kFALSE) {
	    printf("                             [error] %s:%s\n",distribution->GetDescription(),distribution->GetIdentifier());
	    distribution->SetEnable(0);
	} else {
	    distribution->GetDepth();  //Init sub-models
	    dist[distribution_position] = distribution;
	    distribution_position++;
	}
    } else { //if we are not yet complete, relatives are used
	if (init_done) { //relatives are already available
	    Reset();
	    Init();
	    if (distribution->GetStatus() == 0) { //we are complete
		if (distribution->Init() == kFALSE) {
		    printf("                             [error] %s:%s\n",distribution->GetDescription(),distribution->GetIdentifier());
		    distribution->SetEnable(0);
		} else {
		    distribution->GetDepth();  //Init sub-models
		    dist[distribution_position] = distribution;
		    distribution_position++;
		}		
		//printf("                             [incomplete] %s\n",distribution->GetDescription());
	    }
	} else { //END init_done
	    dist[distribution_position] = distribution;
	    distribution_position++;
	}
    } //...end not yet complete

    return 0;
}

void PChannel::GetMessage() { printf(" %s\n",Message[status]); }

char const *PChannel::GetName(void) const {
    //returns the name from the data base
    if (!thSrc && !tcSrc && !dlSrc) {
	//Here, the string from PData should be used!!!
	if (decay_key < 0 ) {
	    Warning("GetName", "No decay key found");
	    exit(1);
	}
	return makeStaticData()->GetDecayNameByKey(decay_key);
    }
    if (thSrc) 
	return " Fireball";
    else if (tcSrc) 
	return " File Input";
    else if (dlSrc) 
	return " Dilepton source";
    return "<unknown>";
}

void PChannel::PrintReport() const {
    PrintReaction();
    cout << "Weighting report" << endl;
    for (int j=0;j<distribution_position;j++) { //loop over all valid distributions
	printf("        [%s] %s\n",dist[j]->GetIdentifier(),dist[j]->GetDescription());

// 	if (((dist[j]->GetVersionFlag()) & VERSION_INVERT_WEIGHTING) ||
// 	    ((dist[j]->GetVersionFlag()) & VERSION_WEIGHTING)) {

	    if (dist[j]->GetExpectedWeightMean() > 0) { //re-scaling is allowed
		cout << "Expected mean: " << dist[j]->GetExpectedWeightMean() << " Reached: " 
		     << dist_weight_sum[j]/dist_counter[j] << endl;
		cout << "Calc mean: " << dist[j]->CalcWeightMean() << endl;
	    } else {
		cout << "Mean: " << dist_weight_sum[j]/dist_counter[j] << endl;
	    }	    
//	}
    }
}

void PChannel::PrintReaction(Int_t check_key) const {

    if (check_key) {
	if (!thSrc && !tcSrc && !dlSrc) {
	    if (decay_key < 0 ) {
		Warning("PrintReaction", "No decay key found");
		exit(1);
	    }
	    cout << makeStaticData()->GetDecayNameByKey(decay_key) << endl;
	    return;
	}
    }

    int j;

    if (thSrc) 
	printf("Fireball");
    else if (tcSrc) 
	printf("File Input");
    else if (dlSrc) 
	printf("Dilepton source");
    else 
	printf("%s", makeStaticData()->GetParticleName(ipid[0]));
    printf(" --> %s", makeStaticData()->GetParticleName(ipid[1]));
    for (j=2; j<=n; ++j) 
	printf(" + %s",makeStaticData()->GetParticleName(ipid[j]));
    cout << endl;
}

void PChannel::PrintNew() {
    
    Long_t nPattern = 0;
    for (int j=0; j<distribution_position; j++)
	if (dist[j]->GetEnable() != 0) {
	    nPattern += ((j<64) ?  1<<(j+1) : 0);
	}
    if (nPattern & (~fEnablePattern)) { 
	fEnablePattern |= nPattern;
	Print();
    }
}

void PChannel::Print(const Option_t *delme) const {
    int j;

    if (quasi_pchannel)
 	quasi_pchannel->Print();

    PrintReaction();
    printf("        Interaction model(s):\n");
    //Distributions
    for (j=0;j<distribution_position;j++) {
	
	if (dist[j]->GetEnable() != 0) {
	    if (dist[j]->GetStatus() == 0) { //all particles set 
		dist[j]->GetDepth();  //Init sub-models
		if (dist[j]->Path())
		    printf("        [%s] %s {/%s}",dist[j]->GetIdentifier(),dist[j]->GetDescription(),dist[j]->Path());
		else
		    printf("        [%s] %s",dist[j]->GetIdentifier(),dist[j]->GetDescription());
		dist[j]->SubPrint(0);
		cout << endl;
	    } else
		printf("        [%s,tentative] %s\n",dist[j]->GetIdentifier(),dist[j]->GetDescription());
	    if (delme != NULL && strcmp(delme,"debug") == 0) {
		dist[j]->Print();
	    }	    
	}
    }

    if (thSrc) ((PFireball * )parent)->Print("      ");

    if (bulkdecay_pos || pro_bulkdecay_pos) {
	printf("        Bulk Classes:\n");
	if (pro_bulkdecay_pos) {
	    printf("          Prologue: ");
	    for (j=0;j<pro_bulkdecay_pos;j++) 
		cout << "<" << pro_bulk[j]->ClassName() << "> ";
	    cout << endl;
	}
	if (bulkdecay_pos) {
	    printf("          Epilogue: ");
	    for (j=0;j<bulkdecay_pos;j++) 
		cout << "<" << bulk[j]->ClassName() << "> ";
	    cout << endl;
	}
    }

}

Bool_t PChannel::AddBulk(PBulkInterface *mybulk) {
    //Add a bulk interface to the list
    //Each bulk object will be executed during the event loop
    //after the normal decay
  
    if (bulkdecay_pos == MAX_BULKDECAY ) {
	Error("AddBulk","MAX_BULKDECAY reached");
	return kFALSE;
    }
    if (bulkdecay_pos && (bulk[bulkdecay_pos-1]->GetPriority() > mybulk->GetPriority())) {
	bulk[bulkdecay_pos]   = bulk[bulkdecay_pos-1];
	bulk[bulkdecay_pos-1] = mybulk;
	bulkdecay_pos++;
    } else
	bulk[bulkdecay_pos++]=mybulk;

    return kTRUE;
}

Bool_t PChannel::AddPrologueBulk(PBulkInterface * mybulk) {
    //Add a bulk interface to the list
    //Each bulk object will be executed during the event loop
    //before the normal decay

    if (pro_bulkdecay_pos == MAX_BULKDECAY ) {
	Error("AddPrologueBulk","MAX_BULKDECAY reached");
	return kFALSE;
    }
    
    if (pro_bulkdecay_pos && (pro_bulk[pro_bulkdecay_pos-1]->GetPriority() > mybulk->GetPriority())) {
	pro_bulk[pro_bulkdecay_pos]   = pro_bulk[pro_bulkdecay_pos-1];
	pro_bulk[pro_bulkdecay_pos-1] = mybulk;
	pro_bulkdecay_pos++;
    } else
	pro_bulk[pro_bulkdecay_pos++]=mybulk;

    return kTRUE;
}

ClassImp(PChannel)
 PChannel.cc:1
 PChannel.cc:2
 PChannel.cc:3
 PChannel.cc:4
 PChannel.cc:5
 PChannel.cc:6
 PChannel.cc:7
 PChannel.cc:8
 PChannel.cc:9
 PChannel.cc:10
 PChannel.cc:11
 PChannel.cc:12
 PChannel.cc:13
 PChannel.cc:14
 PChannel.cc:15
 PChannel.cc:16
 PChannel.cc:17
 PChannel.cc:18
 PChannel.cc:19
 PChannel.cc:20
 PChannel.cc:21
 PChannel.cc:22
 PChannel.cc:23
 PChannel.cc:24
 PChannel.cc:25
 PChannel.cc:26
 PChannel.cc:27
 PChannel.cc:28
 PChannel.cc:29
 PChannel.cc:30
 PChannel.cc:31
 PChannel.cc:32
 PChannel.cc:33
 PChannel.cc:34
 PChannel.cc:35
 PChannel.cc:36
 PChannel.cc:37
 PChannel.cc:38
 PChannel.cc:39
 PChannel.cc:40
 PChannel.cc:41
 PChannel.cc:42
 PChannel.cc:43
 PChannel.cc:44
 PChannel.cc:45
 PChannel.cc:46
 PChannel.cc:47
 PChannel.cc:48
 PChannel.cc:49
 PChannel.cc:50
 PChannel.cc:51
 PChannel.cc:52
 PChannel.cc:53
 PChannel.cc:54
 PChannel.cc:55
 PChannel.cc:56
 PChannel.cc:57
 PChannel.cc:58
 PChannel.cc:59
 PChannel.cc:60
 PChannel.cc:61
 PChannel.cc:62
 PChannel.cc:63
 PChannel.cc:64
 PChannel.cc:65
 PChannel.cc:66
 PChannel.cc:67
 PChannel.cc:68
 PChannel.cc:69
 PChannel.cc:70
 PChannel.cc:71
 PChannel.cc:72
 PChannel.cc:73
 PChannel.cc:74
 PChannel.cc:75
 PChannel.cc:76
 PChannel.cc:77
 PChannel.cc:78
 PChannel.cc:79
 PChannel.cc:80
 PChannel.cc:81
 PChannel.cc:82
 PChannel.cc:83
 PChannel.cc:84
 PChannel.cc:85
 PChannel.cc:86
 PChannel.cc:87
 PChannel.cc:88
 PChannel.cc:89
 PChannel.cc:90
 PChannel.cc:91
 PChannel.cc:92
 PChannel.cc:93
 PChannel.cc:94
 PChannel.cc:95
 PChannel.cc:96
 PChannel.cc:97
 PChannel.cc:98
 PChannel.cc:99
 PChannel.cc:100
 PChannel.cc:101
 PChannel.cc:102
 PChannel.cc:103
 PChannel.cc:104
 PChannel.cc:105
 PChannel.cc:106
 PChannel.cc:107
 PChannel.cc:108
 PChannel.cc:109
 PChannel.cc:110
 PChannel.cc:111
 PChannel.cc:112
 PChannel.cc:113
 PChannel.cc:114
 PChannel.cc:115
 PChannel.cc:116
 PChannel.cc:117
 PChannel.cc:118
 PChannel.cc:119
 PChannel.cc:120
 PChannel.cc:121
 PChannel.cc:122
 PChannel.cc:123
 PChannel.cc:124
 PChannel.cc:125
 PChannel.cc:126
 PChannel.cc:127
 PChannel.cc:128
 PChannel.cc:129
 PChannel.cc:130
 PChannel.cc:131
 PChannel.cc:132
 PChannel.cc:133
 PChannel.cc:134
 PChannel.cc:135
 PChannel.cc:136
 PChannel.cc:137
 PChannel.cc:138
 PChannel.cc:139
 PChannel.cc:140
 PChannel.cc:141
 PChannel.cc:142
 PChannel.cc:143
 PChannel.cc:144
 PChannel.cc:145
 PChannel.cc:146
 PChannel.cc:147
 PChannel.cc:148
 PChannel.cc:149
 PChannel.cc:150
 PChannel.cc:151
 PChannel.cc:152
 PChannel.cc:153
 PChannel.cc:154
 PChannel.cc:155
 PChannel.cc:156
 PChannel.cc:157
 PChannel.cc:158
 PChannel.cc:159
 PChannel.cc:160
 PChannel.cc:161
 PChannel.cc:162
 PChannel.cc:163
 PChannel.cc:164
 PChannel.cc:165
 PChannel.cc:166
 PChannel.cc:167
 PChannel.cc:168
 PChannel.cc:169
 PChannel.cc:170
 PChannel.cc:171
 PChannel.cc:172
 PChannel.cc:173
 PChannel.cc:174
 PChannel.cc:175
 PChannel.cc:176
 PChannel.cc:177
 PChannel.cc:178
 PChannel.cc:179
 PChannel.cc:180
 PChannel.cc:181
 PChannel.cc:182
 PChannel.cc:183
 PChannel.cc:184
 PChannel.cc:185
 PChannel.cc:186
 PChannel.cc:187
 PChannel.cc:188
 PChannel.cc:189
 PChannel.cc:190
 PChannel.cc:191
 PChannel.cc:192
 PChannel.cc:193
 PChannel.cc:194
 PChannel.cc:195
 PChannel.cc:196
 PChannel.cc:197
 PChannel.cc:198
 PChannel.cc:199
 PChannel.cc:200
 PChannel.cc:201
 PChannel.cc:202
 PChannel.cc:203
 PChannel.cc:204
 PChannel.cc:205
 PChannel.cc:206
 PChannel.cc:207
 PChannel.cc:208
 PChannel.cc:209
 PChannel.cc:210
 PChannel.cc:211
 PChannel.cc:212
 PChannel.cc:213
 PChannel.cc:214
 PChannel.cc:215
 PChannel.cc:216
 PChannel.cc:217
 PChannel.cc:218
 PChannel.cc:219
 PChannel.cc:220
 PChannel.cc:221
 PChannel.cc:222
 PChannel.cc:223
 PChannel.cc:224
 PChannel.cc:225
 PChannel.cc:226
 PChannel.cc:227
 PChannel.cc:228
 PChannel.cc:229
 PChannel.cc:230
 PChannel.cc:231
 PChannel.cc:232
 PChannel.cc:233
 PChannel.cc:234
 PChannel.cc:235
 PChannel.cc:236
 PChannel.cc:237
 PChannel.cc:238
 PChannel.cc:239
 PChannel.cc:240
 PChannel.cc:241
 PChannel.cc:242
 PChannel.cc:243
 PChannel.cc:244
 PChannel.cc:245
 PChannel.cc:246
 PChannel.cc:247
 PChannel.cc:248
 PChannel.cc:249
 PChannel.cc:250
 PChannel.cc:251
 PChannel.cc:252
 PChannel.cc:253
 PChannel.cc:254
 PChannel.cc:255
 PChannel.cc:256
 PChannel.cc:257
 PChannel.cc:258
 PChannel.cc:259
 PChannel.cc:260
 PChannel.cc:261
 PChannel.cc:262
 PChannel.cc:263
 PChannel.cc:264
 PChannel.cc:265
 PChannel.cc:266
 PChannel.cc:267
 PChannel.cc:268
 PChannel.cc:269
 PChannel.cc:270
 PChannel.cc:271
 PChannel.cc:272
 PChannel.cc:273
 PChannel.cc:274
 PChannel.cc:275
 PChannel.cc:276
 PChannel.cc:277
 PChannel.cc:278
 PChannel.cc:279
 PChannel.cc:280
 PChannel.cc:281
 PChannel.cc:282
 PChannel.cc:283
 PChannel.cc:284
 PChannel.cc:285
 PChannel.cc:286
 PChannel.cc:287
 PChannel.cc:288
 PChannel.cc:289
 PChannel.cc:290
 PChannel.cc:291
 PChannel.cc:292
 PChannel.cc:293
 PChannel.cc:294
 PChannel.cc:295
 PChannel.cc:296
 PChannel.cc:297
 PChannel.cc:298
 PChannel.cc:299
 PChannel.cc:300
 PChannel.cc:301
 PChannel.cc:302
 PChannel.cc:303
 PChannel.cc:304
 PChannel.cc:305
 PChannel.cc:306
 PChannel.cc:307
 PChannel.cc:308
 PChannel.cc:309
 PChannel.cc:310
 PChannel.cc:311
 PChannel.cc:312
 PChannel.cc:313
 PChannel.cc:314
 PChannel.cc:315
 PChannel.cc:316
 PChannel.cc:317
 PChannel.cc:318
 PChannel.cc:319
 PChannel.cc:320
 PChannel.cc:321
 PChannel.cc:322
 PChannel.cc:323
 PChannel.cc:324
 PChannel.cc:325
 PChannel.cc:326
 PChannel.cc:327
 PChannel.cc:328
 PChannel.cc:329
 PChannel.cc:330
 PChannel.cc:331
 PChannel.cc:332
 PChannel.cc:333
 PChannel.cc:334
 PChannel.cc:335
 PChannel.cc:336
 PChannel.cc:337
 PChannel.cc:338
 PChannel.cc:339
 PChannel.cc:340
 PChannel.cc:341
 PChannel.cc:342
 PChannel.cc:343
 PChannel.cc:344
 PChannel.cc:345
 PChannel.cc:346
 PChannel.cc:347
 PChannel.cc:348
 PChannel.cc:349
 PChannel.cc:350
 PChannel.cc:351
 PChannel.cc:352
 PChannel.cc:353
 PChannel.cc:354
 PChannel.cc:355
 PChannel.cc:356
 PChannel.cc:357
 PChannel.cc:358
 PChannel.cc:359
 PChannel.cc:360
 PChannel.cc:361
 PChannel.cc:362
 PChannel.cc:363
 PChannel.cc:364
 PChannel.cc:365
 PChannel.cc:366
 PChannel.cc:367
 PChannel.cc:368
 PChannel.cc:369
 PChannel.cc:370
 PChannel.cc:371
 PChannel.cc:372
 PChannel.cc:373
 PChannel.cc:374
 PChannel.cc:375
 PChannel.cc:376
 PChannel.cc:377
 PChannel.cc:378
 PChannel.cc:379
 PChannel.cc:380
 PChannel.cc:381
 PChannel.cc:382
 PChannel.cc:383
 PChannel.cc:384
 PChannel.cc:385
 PChannel.cc:386
 PChannel.cc:387
 PChannel.cc:388
 PChannel.cc:389
 PChannel.cc:390
 PChannel.cc:391
 PChannel.cc:392
 PChannel.cc:393
 PChannel.cc:394
 PChannel.cc:395
 PChannel.cc:396
 PChannel.cc:397
 PChannel.cc:398
 PChannel.cc:399
 PChannel.cc:400
 PChannel.cc:401
 PChannel.cc:402
 PChannel.cc:403
 PChannel.cc:404
 PChannel.cc:405
 PChannel.cc:406
 PChannel.cc:407
 PChannel.cc:408
 PChannel.cc:409
 PChannel.cc:410
 PChannel.cc:411
 PChannel.cc:412
 PChannel.cc:413
 PChannel.cc:414
 PChannel.cc:415
 PChannel.cc:416
 PChannel.cc:417
 PChannel.cc:418
 PChannel.cc:419
 PChannel.cc:420
 PChannel.cc:421
 PChannel.cc:422
 PChannel.cc:423
 PChannel.cc:424
 PChannel.cc:425
 PChannel.cc:426
 PChannel.cc:427
 PChannel.cc:428
 PChannel.cc:429
 PChannel.cc:430
 PChannel.cc:431
 PChannel.cc:432
 PChannel.cc:433
 PChannel.cc:434
 PChannel.cc:435
 PChannel.cc:436
 PChannel.cc:437
 PChannel.cc:438
 PChannel.cc:439
 PChannel.cc:440
 PChannel.cc:441
 PChannel.cc:442
 PChannel.cc:443
 PChannel.cc:444
 PChannel.cc:445
 PChannel.cc:446
 PChannel.cc:447
 PChannel.cc:448
 PChannel.cc:449
 PChannel.cc:450
 PChannel.cc:451
 PChannel.cc:452
 PChannel.cc:453
 PChannel.cc:454
 PChannel.cc:455
 PChannel.cc:456
 PChannel.cc:457
 PChannel.cc:458
 PChannel.cc:459
 PChannel.cc:460
 PChannel.cc:461
 PChannel.cc:462
 PChannel.cc:463
 PChannel.cc:464
 PChannel.cc:465
 PChannel.cc:466
 PChannel.cc:467
 PChannel.cc:468
 PChannel.cc:469
 PChannel.cc:470
 PChannel.cc:471
 PChannel.cc:472
 PChannel.cc:473
 PChannel.cc:474
 PChannel.cc:475
 PChannel.cc:476
 PChannel.cc:477
 PChannel.cc:478
 PChannel.cc:479
 PChannel.cc:480
 PChannel.cc:481
 PChannel.cc:482
 PChannel.cc:483
 PChannel.cc:484
 PChannel.cc:485
 PChannel.cc:486
 PChannel.cc:487
 PChannel.cc:488
 PChannel.cc:489
 PChannel.cc:490
 PChannel.cc:491
 PChannel.cc:492
 PChannel.cc:493
 PChannel.cc:494
 PChannel.cc:495
 PChannel.cc:496
 PChannel.cc:497
 PChannel.cc:498
 PChannel.cc:499
 PChannel.cc:500
 PChannel.cc:501
 PChannel.cc:502
 PChannel.cc:503
 PChannel.cc:504
 PChannel.cc:505
 PChannel.cc:506
 PChannel.cc:507
 PChannel.cc:508
 PChannel.cc:509
 PChannel.cc:510
 PChannel.cc:511
 PChannel.cc:512
 PChannel.cc:513
 PChannel.cc:514
 PChannel.cc:515
 PChannel.cc:516
 PChannel.cc:517
 PChannel.cc:518
 PChannel.cc:519
 PChannel.cc:520
 PChannel.cc:521
 PChannel.cc:522
 PChannel.cc:523
 PChannel.cc:524
 PChannel.cc:525
 PChannel.cc:526
 PChannel.cc:527
 PChannel.cc:528
 PChannel.cc:529
 PChannel.cc:530
 PChannel.cc:531
 PChannel.cc:532
 PChannel.cc:533
 PChannel.cc:534
 PChannel.cc:535
 PChannel.cc:536
 PChannel.cc:537
 PChannel.cc:538
 PChannel.cc:539
 PChannel.cc:540
 PChannel.cc:541
 PChannel.cc:542
 PChannel.cc:543
 PChannel.cc:544
 PChannel.cc:545
 PChannel.cc:546
 PChannel.cc:547
 PChannel.cc:548
 PChannel.cc:549
 PChannel.cc:550
 PChannel.cc:551
 PChannel.cc:552
 PChannel.cc:553
 PChannel.cc:554
 PChannel.cc:555
 PChannel.cc:556
 PChannel.cc:557
 PChannel.cc:558
 PChannel.cc:559
 PChannel.cc:560
 PChannel.cc:561
 PChannel.cc:562
 PChannel.cc:563
 PChannel.cc:564
 PChannel.cc:565
 PChannel.cc:566
 PChannel.cc:567
 PChannel.cc:568
 PChannel.cc:569
 PChannel.cc:570
 PChannel.cc:571
 PChannel.cc:572
 PChannel.cc:573
 PChannel.cc:574
 PChannel.cc:575
 PChannel.cc:576
 PChannel.cc:577
 PChannel.cc:578
 PChannel.cc:579
 PChannel.cc:580
 PChannel.cc:581
 PChannel.cc:582
 PChannel.cc:583
 PChannel.cc:584
 PChannel.cc:585
 PChannel.cc:586
 PChannel.cc:587
 PChannel.cc:588
 PChannel.cc:589
 PChannel.cc:590
 PChannel.cc:591
 PChannel.cc:592
 PChannel.cc:593
 PChannel.cc:594
 PChannel.cc:595
 PChannel.cc:596
 PChannel.cc:597
 PChannel.cc:598
 PChannel.cc:599
 PChannel.cc:600
 PChannel.cc:601
 PChannel.cc:602
 PChannel.cc:603
 PChannel.cc:604
 PChannel.cc:605
 PChannel.cc:606
 PChannel.cc:607
 PChannel.cc:608
 PChannel.cc:609
 PChannel.cc:610
 PChannel.cc:611
 PChannel.cc:612
 PChannel.cc:613
 PChannel.cc:614
 PChannel.cc:615
 PChannel.cc:616
 PChannel.cc:617
 PChannel.cc:618
 PChannel.cc:619
 PChannel.cc:620
 PChannel.cc:621
 PChannel.cc:622
 PChannel.cc:623
 PChannel.cc:624
 PChannel.cc:625
 PChannel.cc:626
 PChannel.cc:627
 PChannel.cc:628
 PChannel.cc:629
 PChannel.cc:630
 PChannel.cc:631
 PChannel.cc:632
 PChannel.cc:633
 PChannel.cc:634
 PChannel.cc:635
 PChannel.cc:636
 PChannel.cc:637
 PChannel.cc:638
 PChannel.cc:639
 PChannel.cc:640
 PChannel.cc:641
 PChannel.cc:642
 PChannel.cc:643
 PChannel.cc:644
 PChannel.cc:645
 PChannel.cc:646
 PChannel.cc:647
 PChannel.cc:648
 PChannel.cc:649
 PChannel.cc:650
 PChannel.cc:651
 PChannel.cc:652
 PChannel.cc:653
 PChannel.cc:654
 PChannel.cc:655
 PChannel.cc:656
 PChannel.cc:657
 PChannel.cc:658
 PChannel.cc:659
 PChannel.cc:660
 PChannel.cc:661
 PChannel.cc:662
 PChannel.cc:663
 PChannel.cc:664
 PChannel.cc:665
 PChannel.cc:666
 PChannel.cc:667
 PChannel.cc:668
 PChannel.cc:669
 PChannel.cc:670
 PChannel.cc:671
 PChannel.cc:672
 PChannel.cc:673
 PChannel.cc:674
 PChannel.cc:675
 PChannel.cc:676
 PChannel.cc:677
 PChannel.cc:678
 PChannel.cc:679
 PChannel.cc:680
 PChannel.cc:681
 PChannel.cc:682
 PChannel.cc:683
 PChannel.cc:684
 PChannel.cc:685
 PChannel.cc:686
 PChannel.cc:687
 PChannel.cc:688
 PChannel.cc:689
 PChannel.cc:690
 PChannel.cc:691
 PChannel.cc:692
 PChannel.cc:693
 PChannel.cc:694
 PChannel.cc:695
 PChannel.cc:696
 PChannel.cc:697
 PChannel.cc:698
 PChannel.cc:699
 PChannel.cc:700
 PChannel.cc:701
 PChannel.cc:702
 PChannel.cc:703
 PChannel.cc:704
 PChannel.cc:705
 PChannel.cc:706
 PChannel.cc:707
 PChannel.cc:708
 PChannel.cc:709
 PChannel.cc:710
 PChannel.cc:711
 PChannel.cc:712
 PChannel.cc:713
 PChannel.cc:714
 PChannel.cc:715
 PChannel.cc:716
 PChannel.cc:717
 PChannel.cc:718
 PChannel.cc:719
 PChannel.cc:720
 PChannel.cc:721
 PChannel.cc:722
 PChannel.cc:723
 PChannel.cc:724
 PChannel.cc:725
 PChannel.cc:726
 PChannel.cc:727
 PChannel.cc:728
 PChannel.cc:729
 PChannel.cc:730
 PChannel.cc:731
 PChannel.cc:732
 PChannel.cc:733
 PChannel.cc:734
 PChannel.cc:735
 PChannel.cc:736
 PChannel.cc:737
 PChannel.cc:738
 PChannel.cc:739
 PChannel.cc:740
 PChannel.cc:741
 PChannel.cc:742
 PChannel.cc:743
 PChannel.cc:744
 PChannel.cc:745
 PChannel.cc:746
 PChannel.cc:747
 PChannel.cc:748
 PChannel.cc:749
 PChannel.cc:750
 PChannel.cc:751
 PChannel.cc:752
 PChannel.cc:753
 PChannel.cc:754
 PChannel.cc:755
 PChannel.cc:756
 PChannel.cc:757
 PChannel.cc:758
 PChannel.cc:759
 PChannel.cc:760
 PChannel.cc:761
 PChannel.cc:762
 PChannel.cc:763
 PChannel.cc:764
 PChannel.cc:765
 PChannel.cc:766
 PChannel.cc:767
 PChannel.cc:768
 PChannel.cc:769
 PChannel.cc:770
 PChannel.cc:771
 PChannel.cc:772
 PChannel.cc:773
 PChannel.cc:774
 PChannel.cc:775
 PChannel.cc:776
 PChannel.cc:777
 PChannel.cc:778
 PChannel.cc:779
 PChannel.cc:780
 PChannel.cc:781
 PChannel.cc:782
 PChannel.cc:783
 PChannel.cc:784
 PChannel.cc:785
 PChannel.cc:786
 PChannel.cc:787
 PChannel.cc:788
 PChannel.cc:789
 PChannel.cc:790
 PChannel.cc:791
 PChannel.cc:792
 PChannel.cc:793
 PChannel.cc:794
 PChannel.cc:795
 PChannel.cc:796
 PChannel.cc:797
 PChannel.cc:798
 PChannel.cc:799
 PChannel.cc:800
 PChannel.cc:801
 PChannel.cc:802
 PChannel.cc:803
 PChannel.cc:804
 PChannel.cc:805
 PChannel.cc:806
 PChannel.cc:807
 PChannel.cc:808
 PChannel.cc:809
 PChannel.cc:810
 PChannel.cc:811
 PChannel.cc:812
 PChannel.cc:813
 PChannel.cc:814
 PChannel.cc:815
 PChannel.cc:816
 PChannel.cc:817
 PChannel.cc:818
 PChannel.cc:819
 PChannel.cc:820
 PChannel.cc:821
 PChannel.cc:822
 PChannel.cc:823
 PChannel.cc:824
 PChannel.cc:825
 PChannel.cc:826
 PChannel.cc:827
 PChannel.cc:828
 PChannel.cc:829
 PChannel.cc:830
 PChannel.cc:831
 PChannel.cc:832
 PChannel.cc:833
 PChannel.cc:834
 PChannel.cc:835
 PChannel.cc:836
 PChannel.cc:837
 PChannel.cc:838
 PChannel.cc:839
 PChannel.cc:840
 PChannel.cc:841
 PChannel.cc:842
 PChannel.cc:843
 PChannel.cc:844
 PChannel.cc:845
 PChannel.cc:846
 PChannel.cc:847
 PChannel.cc:848
 PChannel.cc:849
 PChannel.cc:850
 PChannel.cc:851
 PChannel.cc:852
 PChannel.cc:853
 PChannel.cc:854
 PChannel.cc:855
 PChannel.cc:856
 PChannel.cc:857
 PChannel.cc:858
 PChannel.cc:859
 PChannel.cc:860
 PChannel.cc:861
 PChannel.cc:862
 PChannel.cc:863
 PChannel.cc:864
 PChannel.cc:865
 PChannel.cc:866
 PChannel.cc:867
 PChannel.cc:868
 PChannel.cc:869
 PChannel.cc:870
 PChannel.cc:871
 PChannel.cc:872
 PChannel.cc:873
 PChannel.cc:874
 PChannel.cc:875
 PChannel.cc:876
 PChannel.cc:877
 PChannel.cc:878
 PChannel.cc:879
 PChannel.cc:880
 PChannel.cc:881
 PChannel.cc:882
 PChannel.cc:883
 PChannel.cc:884
 PChannel.cc:885
 PChannel.cc:886
 PChannel.cc:887
 PChannel.cc:888
 PChannel.cc:889
 PChannel.cc:890
 PChannel.cc:891
 PChannel.cc:892
 PChannel.cc:893
 PChannel.cc:894
 PChannel.cc:895
 PChannel.cc:896
 PChannel.cc:897
 PChannel.cc:898
 PChannel.cc:899
 PChannel.cc:900
 PChannel.cc:901
 PChannel.cc:902
 PChannel.cc:903
 PChannel.cc:904
 PChannel.cc:905
 PChannel.cc:906
 PChannel.cc:907
 PChannel.cc:908
 PChannel.cc:909
 PChannel.cc:910
 PChannel.cc:911
 PChannel.cc:912
 PChannel.cc:913
 PChannel.cc:914
 PChannel.cc:915
 PChannel.cc:916
 PChannel.cc:917
 PChannel.cc:918
 PChannel.cc:919
 PChannel.cc:920
 PChannel.cc:921
 PChannel.cc:922
 PChannel.cc:923
 PChannel.cc:924
 PChannel.cc:925
 PChannel.cc:926
 PChannel.cc:927
 PChannel.cc:928
 PChannel.cc:929
 PChannel.cc:930
 PChannel.cc:931
 PChannel.cc:932
 PChannel.cc:933
 PChannel.cc:934
 PChannel.cc:935
 PChannel.cc:936
 PChannel.cc:937
 PChannel.cc:938
 PChannel.cc:939
 PChannel.cc:940
 PChannel.cc:941
 PChannel.cc:942
 PChannel.cc:943
 PChannel.cc:944
 PChannel.cc:945
 PChannel.cc:946
 PChannel.cc:947
 PChannel.cc:948
 PChannel.cc:949
 PChannel.cc:950
 PChannel.cc:951
 PChannel.cc:952
 PChannel.cc:953
 PChannel.cc:954
 PChannel.cc:955
 PChannel.cc:956
 PChannel.cc:957
 PChannel.cc:958
 PChannel.cc:959
 PChannel.cc:960
 PChannel.cc:961
 PChannel.cc:962
 PChannel.cc:963
 PChannel.cc:964
 PChannel.cc:965
 PChannel.cc:966
 PChannel.cc:967
 PChannel.cc:968
 PChannel.cc:969
 PChannel.cc:970
 PChannel.cc:971
 PChannel.cc:972
 PChannel.cc:973
 PChannel.cc:974
 PChannel.cc:975
 PChannel.cc:976
 PChannel.cc:977
 PChannel.cc:978
 PChannel.cc:979
 PChannel.cc:980
 PChannel.cc:981
 PChannel.cc:982
 PChannel.cc:983
 PChannel.cc:984
 PChannel.cc:985
 PChannel.cc:986
 PChannel.cc:987
 PChannel.cc:988
 PChannel.cc:989
 PChannel.cc:990
 PChannel.cc:991
 PChannel.cc:992
 PChannel.cc:993
 PChannel.cc:994
 PChannel.cc:995
 PChannel.cc:996
 PChannel.cc:997
 PChannel.cc:998
 PChannel.cc:999
 PChannel.cc:1000
 PChannel.cc:1001
 PChannel.cc:1002
 PChannel.cc:1003
 PChannel.cc:1004
 PChannel.cc:1005
 PChannel.cc:1006
 PChannel.cc:1007
 PChannel.cc:1008
 PChannel.cc:1009
 PChannel.cc:1010
 PChannel.cc:1011
 PChannel.cc:1012
 PChannel.cc:1013
 PChannel.cc:1014
 PChannel.cc:1015
 PChannel.cc:1016
 PChannel.cc:1017
 PChannel.cc:1018
 PChannel.cc:1019
 PChannel.cc:1020
 PChannel.cc:1021
 PChannel.cc:1022
 PChannel.cc:1023
 PChannel.cc:1024
 PChannel.cc:1025
 PChannel.cc:1026
 PChannel.cc:1027
 PChannel.cc:1028
 PChannel.cc:1029
 PChannel.cc:1030
 PChannel.cc:1031
 PChannel.cc:1032
 PChannel.cc:1033
 PChannel.cc:1034
 PChannel.cc:1035
 PChannel.cc:1036
 PChannel.cc:1037
 PChannel.cc:1038
 PChannel.cc:1039
 PChannel.cc:1040
 PChannel.cc:1041
 PChannel.cc:1042
 PChannel.cc:1043
 PChannel.cc:1044
 PChannel.cc:1045
 PChannel.cc:1046
 PChannel.cc:1047
 PChannel.cc:1048
 PChannel.cc:1049
 PChannel.cc:1050
 PChannel.cc:1051
 PChannel.cc:1052
 PChannel.cc:1053
 PChannel.cc:1054
 PChannel.cc:1055
 PChannel.cc:1056
 PChannel.cc:1057
 PChannel.cc:1058
 PChannel.cc:1059
 PChannel.cc:1060
 PChannel.cc:1061
 PChannel.cc:1062
 PChannel.cc:1063
 PChannel.cc:1064
 PChannel.cc:1065
 PChannel.cc:1066
 PChannel.cc:1067
 PChannel.cc:1068
 PChannel.cc:1069
 PChannel.cc:1070
 PChannel.cc:1071
 PChannel.cc:1072
 PChannel.cc:1073
 PChannel.cc:1074
 PChannel.cc:1075
 PChannel.cc:1076
 PChannel.cc:1077
 PChannel.cc:1078
 PChannel.cc:1079
 PChannel.cc:1080
 PChannel.cc:1081
 PChannel.cc:1082
 PChannel.cc:1083
 PChannel.cc:1084
 PChannel.cc:1085
 PChannel.cc:1086
 PChannel.cc:1087
 PChannel.cc:1088
 PChannel.cc:1089
 PChannel.cc:1090
 PChannel.cc:1091
 PChannel.cc:1092
 PChannel.cc:1093
 PChannel.cc:1094
 PChannel.cc:1095
 PChannel.cc:1096
 PChannel.cc:1097
 PChannel.cc:1098
 PChannel.cc:1099
 PChannel.cc:1100
 PChannel.cc:1101
 PChannel.cc:1102
 PChannel.cc:1103
 PChannel.cc:1104
 PChannel.cc:1105
 PChannel.cc:1106
 PChannel.cc:1107
 PChannel.cc:1108
 PChannel.cc:1109
 PChannel.cc:1110
 PChannel.cc:1111
 PChannel.cc:1112
 PChannel.cc:1113
 PChannel.cc:1114
 PChannel.cc:1115
 PChannel.cc:1116
 PChannel.cc:1117
 PChannel.cc:1118
 PChannel.cc:1119
 PChannel.cc:1120
 PChannel.cc:1121
 PChannel.cc:1122
 PChannel.cc:1123
 PChannel.cc:1124
 PChannel.cc:1125
 PChannel.cc:1126
 PChannel.cc:1127
 PChannel.cc:1128
 PChannel.cc:1129
 PChannel.cc:1130
 PChannel.cc:1131
 PChannel.cc:1132
 PChannel.cc:1133
 PChannel.cc:1134
 PChannel.cc:1135
 PChannel.cc:1136
 PChannel.cc:1137
 PChannel.cc:1138
 PChannel.cc:1139
 PChannel.cc:1140
 PChannel.cc:1141
 PChannel.cc:1142
 PChannel.cc:1143
 PChannel.cc:1144
 PChannel.cc:1145
 PChannel.cc:1146
 PChannel.cc:1147
 PChannel.cc:1148
 PChannel.cc:1149
 PChannel.cc:1150
 PChannel.cc:1151
 PChannel.cc:1152
 PChannel.cc:1153
 PChannel.cc:1154
 PChannel.cc:1155
 PChannel.cc:1156
 PChannel.cc:1157
 PChannel.cc:1158
 PChannel.cc:1159
 PChannel.cc:1160
 PChannel.cc:1161
 PChannel.cc:1162
 PChannel.cc:1163
 PChannel.cc:1164
 PChannel.cc:1165
 PChannel.cc:1166
 PChannel.cc:1167
 PChannel.cc:1168
 PChannel.cc:1169
 PChannel.cc:1170
 PChannel.cc:1171
 PChannel.cc:1172
 PChannel.cc:1173
 PChannel.cc:1174
 PChannel.cc:1175
 PChannel.cc:1176
 PChannel.cc:1177
 PChannel.cc:1178
 PChannel.cc:1179
 PChannel.cc:1180
 PChannel.cc:1181
 PChannel.cc:1182
 PChannel.cc:1183
 PChannel.cc:1184
 PChannel.cc:1185
 PChannel.cc:1186
 PChannel.cc:1187
 PChannel.cc:1188
 PChannel.cc:1189
 PChannel.cc:1190
 PChannel.cc:1191
 PChannel.cc:1192
 PChannel.cc:1193
 PChannel.cc:1194
 PChannel.cc:1195
 PChannel.cc:1196
 PChannel.cc:1197
 PChannel.cc:1198
 PChannel.cc:1199
 PChannel.cc:1200
 PChannel.cc:1201
 PChannel.cc:1202
 PChannel.cc:1203
 PChannel.cc:1204
 PChannel.cc:1205
 PChannel.cc:1206
 PChannel.cc:1207
 PChannel.cc:1208
 PChannel.cc:1209
 PChannel.cc:1210
 PChannel.cc:1211
 PChannel.cc:1212
 PChannel.cc:1213
 PChannel.cc:1214
 PChannel.cc:1215
 PChannel.cc:1216
 PChannel.cc:1217
 PChannel.cc:1218
 PChannel.cc:1219
 PChannel.cc:1220
 PChannel.cc:1221
 PChannel.cc:1222
 PChannel.cc:1223
 PChannel.cc:1224
 PChannel.cc:1225
 PChannel.cc:1226
 PChannel.cc:1227
 PChannel.cc:1228
 PChannel.cc:1229
 PChannel.cc:1230
 PChannel.cc:1231
 PChannel.cc:1232
 PChannel.cc:1233
 PChannel.cc:1234
 PChannel.cc:1235
 PChannel.cc:1236
 PChannel.cc:1237
 PChannel.cc:1238
 PChannel.cc:1239
 PChannel.cc:1240
 PChannel.cc:1241
 PChannel.cc:1242
 PChannel.cc:1243
 PChannel.cc:1244
 PChannel.cc:1245
 PChannel.cc:1246
 PChannel.cc:1247
 PChannel.cc:1248
 PChannel.cc:1249
 PChannel.cc:1250
 PChannel.cc:1251
 PChannel.cc:1252
 PChannel.cc:1253
 PChannel.cc:1254
 PChannel.cc:1255
 PChannel.cc:1256
 PChannel.cc:1257
 PChannel.cc:1258
 PChannel.cc:1259
 PChannel.cc:1260
 PChannel.cc:1261
 PChannel.cc:1262
 PChannel.cc:1263
 PChannel.cc:1264
 PChannel.cc:1265
 PChannel.cc:1266
 PChannel.cc:1267
 PChannel.cc:1268
 PChannel.cc:1269
 PChannel.cc:1270
 PChannel.cc:1271
 PChannel.cc:1272
 PChannel.cc:1273
 PChannel.cc:1274
 PChannel.cc:1275
 PChannel.cc:1276
 PChannel.cc:1277
 PChannel.cc:1278
 PChannel.cc:1279
 PChannel.cc:1280
 PChannel.cc:1281
 PChannel.cc:1282
 PChannel.cc:1283
 PChannel.cc:1284
 PChannel.cc:1285
 PChannel.cc:1286
 PChannel.cc:1287
 PChannel.cc:1288
 PChannel.cc:1289
 PChannel.cc:1290
 PChannel.cc:1291
 PChannel.cc:1292
 PChannel.cc:1293
 PChannel.cc:1294
 PChannel.cc:1295
 PChannel.cc:1296
 PChannel.cc:1297
 PChannel.cc:1298
 PChannel.cc:1299
 PChannel.cc:1300
 PChannel.cc:1301
 PChannel.cc:1302
 PChannel.cc:1303
 PChannel.cc:1304
 PChannel.cc:1305
 PChannel.cc:1306
 PChannel.cc:1307
 PChannel.cc:1308
 PChannel.cc:1309
 PChannel.cc:1310
 PChannel.cc:1311
 PChannel.cc:1312
 PChannel.cc:1313
 PChannel.cc:1314
 PChannel.cc:1315
 PChannel.cc:1316
 PChannel.cc:1317
 PChannel.cc:1318
 PChannel.cc:1319
 PChannel.cc:1320
 PChannel.cc:1321
 PChannel.cc:1322
 PChannel.cc:1323
 PChannel.cc:1324
 PChannel.cc:1325
 PChannel.cc:1326
 PChannel.cc:1327
 PChannel.cc:1328
 PChannel.cc:1329
 PChannel.cc:1330
 PChannel.cc:1331
 PChannel.cc:1332
 PChannel.cc:1333
 PChannel.cc:1334
 PChannel.cc:1335
 PChannel.cc:1336
 PChannel.cc:1337
 PChannel.cc:1338
 PChannel.cc:1339
 PChannel.cc:1340
 PChannel.cc:1341
 PChannel.cc:1342
 PChannel.cc:1343
 PChannel.cc:1344
 PChannel.cc:1345
 PChannel.cc:1346
 PChannel.cc:1347
 PChannel.cc:1348
 PChannel.cc:1349
 PChannel.cc:1350
 PChannel.cc:1351
 PChannel.cc:1352
 PChannel.cc:1353
 PChannel.cc:1354
 PChannel.cc:1355
 PChannel.cc:1356
 PChannel.cc:1357
 PChannel.cc:1358
 PChannel.cc:1359
 PChannel.cc:1360
 PChannel.cc:1361
 PChannel.cc:1362
 PChannel.cc:1363
 PChannel.cc:1364
 PChannel.cc:1365
 PChannel.cc:1366
 PChannel.cc:1367
 PChannel.cc:1368
 PChannel.cc:1369
 PChannel.cc:1370
 PChannel.cc:1371
 PChannel.cc:1372
 PChannel.cc:1373
 PChannel.cc:1374
 PChannel.cc:1375
 PChannel.cc:1376
 PChannel.cc:1377
 PChannel.cc:1378
 PChannel.cc:1379
 PChannel.cc:1380
 PChannel.cc:1381
 PChannel.cc:1382
 PChannel.cc:1383
 PChannel.cc:1384
 PChannel.cc:1385
 PChannel.cc:1386
 PChannel.cc:1387
 PChannel.cc:1388
 PChannel.cc:1389
 PChannel.cc:1390
 PChannel.cc:1391
 PChannel.cc:1392
 PChannel.cc:1393
 PChannel.cc:1394
 PChannel.cc:1395
 PChannel.cc:1396
 PChannel.cc:1397
 PChannel.cc:1398
 PChannel.cc:1399
 PChannel.cc:1400
 PChannel.cc:1401
 PChannel.cc:1402
 PChannel.cc:1403
 PChannel.cc:1404
 PChannel.cc:1405
 PChannel.cc:1406
 PChannel.cc:1407
 PChannel.cc:1408
 PChannel.cc:1409
 PChannel.cc:1410
 PChannel.cc:1411
 PChannel.cc:1412
 PChannel.cc:1413
 PChannel.cc:1414
 PChannel.cc:1415
 PChannel.cc:1416
 PChannel.cc:1417
 PChannel.cc:1418
 PChannel.cc:1419
 PChannel.cc:1420
 PChannel.cc:1421
 PChannel.cc:1422
 PChannel.cc:1423
 PChannel.cc:1424
 PChannel.cc:1425
 PChannel.cc:1426
 PChannel.cc:1427
 PChannel.cc:1428
 PChannel.cc:1429
 PChannel.cc:1430
 PChannel.cc:1431
 PChannel.cc:1432
 PChannel.cc:1433
 PChannel.cc:1434
 PChannel.cc:1435
 PChannel.cc:1436
 PChannel.cc:1437
 PChannel.cc:1438
 PChannel.cc:1439
 PChannel.cc:1440
 PChannel.cc:1441
 PChannel.cc:1442
 PChannel.cc:1443
 PChannel.cc:1444
 PChannel.cc:1445
 PChannel.cc:1446
 PChannel.cc:1447
 PChannel.cc:1448
 PChannel.cc:1449
 PChannel.cc:1450
 PChannel.cc:1451
 PChannel.cc:1452
 PChannel.cc:1453
 PChannel.cc:1454
 PChannel.cc:1455
 PChannel.cc:1456
 PChannel.cc:1457
 PChannel.cc:1458
 PChannel.cc:1459
 PChannel.cc:1460
 PChannel.cc:1461
 PChannel.cc:1462
 PChannel.cc:1463
 PChannel.cc:1464
 PChannel.cc:1465
 PChannel.cc:1466
 PChannel.cc:1467
 PChannel.cc:1468
 PChannel.cc:1469
 PChannel.cc:1470
 PChannel.cc:1471
 PChannel.cc:1472
 PChannel.cc:1473
 PChannel.cc:1474
 PChannel.cc:1475
 PChannel.cc:1476
 PChannel.cc:1477
 PChannel.cc:1478
 PChannel.cc:1479
 PChannel.cc:1480
 PChannel.cc:1481
 PChannel.cc:1482
 PChannel.cc:1483