Int_t dieleAna(TString inputlist, TString outfile, Int_t nev=-1, Int_t whichweight = 0)
{

    TH1::SetDefaultSumw2();
    TH3F *p3DEffEle[6][NWEIGHTS+1]; // mult bins, MLP weights + HC
    TH3F *p3DEffPos[6][NWEIGHTS+1];
    TH3F *p3DAccEle[6][NWEIGHTS+1];
    TH3F *p3DAccPos[6][NWEIGHTS+1];
    readAccEffMatrices(p3DAccEle, p3DAccPos, p3DEffEle, p3DEffPos);
    TH2F *smear_ele, *smear_pos;
    TFile *file_smear = new TFile("smearing_matrix.root","read");
    smear_ele = (TH2F*)file_smear->Get("smear_ele");
    smear_pos = (TH2F*)file_smear->Get("smear_pos");

    TRandom random;

/*
    TFile *pEffFile;

    pEffFile = new TFile("Input/EffMatrixMVA2RefAccNewCP_100Mio.root");
    if (pEffFile)
    {
	pEffFile->cd();
	for(Int_t i = 0 ; i < 5 ; i++){
            p3DEffEle[i][6] = (TH3F*) pEffFile->Get(Form("hHistEff3DMult%iNeg",i));
            p3DEffPos[i][6] = (TH3F*) pEffFile->Get(Form("hHistEff3DMult%iPos",i));
     //       p3DEffEle[i] = (TH3F*) pEffFile->Get("hHistEff3DNeg");
      //      p3DEffPos[i] = (TH3F*) pEffFile->Get("hHistEff3DPos");
        }
    }
    else
    {
	Error("DrawFromNtuple constructor","pointer to eff matrix file is NULL");
	for(Int_t i = 0 ; i < 5 ; i++){
	    p3DEffEle[i][6] = NULL;
	    p3DEffPos[i][6] = NULL;
        }
    }
*/

    TH1F *pEventClass;
    TH1F *pEventClass_recur;
    TFile *pEventClassFile;
//    pEventClassFile = new TFile("eventClass_mult_nonempty_4secmult_200fpj_wait.root");
//    pEventClassFile = new TFile("eventClass_target_mult_rplane_nonempty_4secmult.root");
    pEventClassFile = new TFile("eventClass_target_mult_rplane_minmom_nmix_w6.root");
    if (pEventClassFile) {
        pEventClass = (TH1F*)pEventClassFile->Get("eventClass");
        pEventClass_recur = (TH1F*)pEventClassFile->Get("eventClass_recur");
        if (pEventClass == NULL || pEventClass_recur == NULL) {
            Error("DrawFromNtuple constructor","Histogram not found in the event class file");
            exit (-1);
        }
    }    
    else {
        Error("DrawFromNtuple constructor","Event class file not found");
        exit (-1);
    }
    HLoop* loop = new HLoop(kTRUE);  // kTRUE : create Hades  (needed to work with standard eventstructure)
    TString readCategories = "";
    if (inputlist.EndsWith(".list")) {
        loop->addFilesList(inputlist);
    }
    else {
        loop->addMultFiles(inputlist);
    }
    if(!loop->setInput(readCategories)) { exit(1); }
    loop->printCategories();
    loop->readSectorFileList("FileListLepton.list");
    int sectors[6];

    HGeantKine *kine1;
    HGeantKine *kine2;

    HCategory* kineCat = (HCategory*)HCategoryManager::getCategory(catGeantKine);

    HHistMap hM(outfile.Data());
    hM.setSilentFail(kTRUE);

    //------------------------------------------------------------------
    //--------------- begin histo booking -----------------------------------------------------
    //------------------------------------------------------------------------------------------

    const Int_t nbins = 26;
    Double_t xAxis1[nbins+1] = {0, 0.010, 0.020, 0.030, 0.040, 0.050, 0.060, 0.070, 0.080, 0.090, 0.110, 0.130, 0.150, 0.170, 0.200, 0.250, 0.300, 0.350, 0.400, 0.450, 0.500, 0.550, 0.600, 0.700, 0.800, 0.900, 1.};

    hM.addHist(new TH1F(TString("hmassNP"),TString("hmassNP"),nbins,xAxis1));
    hM.addHist(new TH1F(TString("hmassPP"),TString("hmassPP"),nbins,xAxis1));
    hM.addHist(new TH1F(TString("hmassNN"),TString("hmassNN"),nbins,xAxis1));
    hM.addHist(new TH1F(TString("hoAngleNP"),TString("hoAngleNP"),2000,0,200));
    hM.addHist(new TH1F(TString("hoAnglePP"),TString("hoAnglePP"),2000,0,200));
    hM.addHist(new TH1F(TString("hoAngleNN"),TString("hoAngleNN"),2000,0,200));
    hM.addHist(new TH1F(TString("hyNP"),TString("hyNP"),100,0,2));
    hM.addHist(new TH1F(TString("hyPP"),TString("hyPP"),100,0,2));
    hM.addHist(new TH1F(TString("hyNN"),TString("hyNN"),100,0,2));
    hM.addHist(new TH1F(TString("hptNP"),TString("hptNP"),100,0,1000));
    hM.addHist(new TH1F(TString("hptPP"),TString("hptPP"),100,0,1000));
    hM.addHist(new TH1F(TString("hptNN"),TString("hptNN"),100,0,1000));
    hM.addHist(new TH2F(TString("hoAnglemassNP"),TString("hoAnglemassNP"),90,0,180,nbins,xAxis1));
    hM.addHist(new TH2F(TString("hoAnglemassPP"),TString("hoAnglemassPP"),90,0,180,nbins,xAxis1));
    hM.addHist(new TH2F(TString("hoAnglemassNN"),TString("hoAnglemassNN"),90,0,180,nbins,xAxis1));
    hM.addHist(new TH2F(TString("hoAngleptNP"),TString("hoAngleptNP"),90,0,180,120,0,1200));
    hM.addHist(new TH2F(TString("hoAngleptPP"),TString("hoAngleptPP"),90,0,180,120,0,1200));
    hM.addHist(new TH2F(TString("hoAngleptNN"),TString("hoAngleptNN"),90,0,180,120,0,1200));
    hM.addHist(new TH2F(TString("hmassptNP"),TString("hmassptNP"),nbins,xAxis1,120,0,1200));
    hM.addHist(new TH2F(TString("hmassptPP"),TString("hmassptPP"),nbins,xAxis1,120,0,1200));
    hM.addHist(new TH2F(TString("hmassptNN"),TString("hmassptNN"),nbins,xAxis1,120,0,1200));
    hM.addHist(new TH2F(TString("hoAngleyNP"),TString("hoAngleyNP"),90,0,180,100,0,2));
    hM.addHist(new TH2F(TString("hoAngleyPP"),TString("hoAngleyPP"),90,0,180,100,0,2));
    hM.addHist(new TH2F(TString("hoAngleyNN"),TString("hoAngleyNN"),90,0,180,100,0,2));
    hM.addHist(new TH2F(TString("hmassyNP"),TString("hmassyNP"),nbins,xAxis1,100,0,2));
    hM.addHist(new TH2F(TString("hmassyPP"),TString("hmassyPP"),nbins,xAxis1,100,0,2));
    hM.addHist(new TH2F(TString("hmassyNN"),TString("hmassyNN"),nbins,xAxis1,100,0,2));
    hM.addHist(new TH2F(TString("hptyNP"),TString("hptyNP"),120,0,1200,100,0,2));
    hM.addHist(new TH2F(TString("hptyPP"),TString("hptyPP"),120,0,1200,100,0,2));
    hM.addHist(new TH2F(TString("hptyNN"),TString("hptyNN"),120,0,1200,100,0,2));
    hM.addHist(new TH2F(TString("hth1th2NP"),TString("hth1th2NP"),90,0,90,90,0,90));
    hM.addHist(new TH2F(TString("hth1th2PP"),TString("hth1th2PP"),90,0,90,90,0,90));
    hM.addHist(new TH2F(TString("hth1th2NN"),TString("hth1th2NN"),90,0,90,90,0,90));
    hM.addHist(new TH2F(TString("hp1p2NP"),TString("hp1p2NP"),100,0,1100,100,0,1100));
    hM.addHist(new TH2F(TString("hp1p2PP"),TString("hp1p2PP"),100,0,1100,100,0,1100));
    hM.addHist(new TH2F(TString("hp1p2NN"),TString("hp1p2NN"),100,0,1100,100,0,1100));

    for (int i = 0; i < 5; ++i) {
        hM.addHist(new TH1F(TString("hmassNP_eff_multbin")+TString::Itoa(i,10),TString("hmassNP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1));
        hM.addHist(new TH1F(TString("hmassPP_eff_multbin")+TString::Itoa(i,10),TString("hmassPP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1));
        hM.addHist(new TH1F(TString("hmassNN_eff_multbin")+TString::Itoa(i,10),TString("hmassNN_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1));
        hM.addHist(new TH1F(TString("hoAngleNP_eff_multbin")+TString::Itoa(i,10),TString("hoAngleNP_eff_multbin")+TString::Itoa(i,10),2000,0,200));
        hM.addHist(new TH1F(TString("hoAnglePP_eff_multbin")+TString::Itoa(i,10),TString("hoAnglePP_eff_multbin")+TString::Itoa(i,10),2000,0,200));
        hM.addHist(new TH1F(TString("hoAngleNN_eff_multbin")+TString::Itoa(i,10),TString("hoAngleNN_eff_multbin")+TString::Itoa(i,10),2000,0,200));
        hM.addHist(new TH1F(TString("hyNP_eff_multbin")+TString::Itoa(i,10),TString("hyNP_eff_multbin")+TString::Itoa(i,10),100,0,2));
        hM.addHist(new TH1F(TString("hyPP_eff_multbin")+TString::Itoa(i,10),TString("hyPP_eff_multbin")+TString::Itoa(i,10),100,0,2));
        hM.addHist(new TH1F(TString("hyNN_eff_multbin")+TString::Itoa(i,10),TString("hyNN_eff_multbin")+TString::Itoa(i,10),100,0,2));
        hM.addHist(new TH1F(TString("hptNP_eff_multbin")+TString::Itoa(i,10),TString("hptNP_eff_multbin")+TString::Itoa(i,10),100,0,1000));
        hM.addHist(new TH1F(TString("hptPP_eff_multbin")+TString::Itoa(i,10),TString("hptPP_eff_multbin")+TString::Itoa(i,10),100,0,1000));
        hM.addHist(new TH1F(TString("hptNN_eff_multbin")+TString::Itoa(i,10),TString("hptNN_eff_multbin")+TString::Itoa(i,10),100,0,1000));
        hM.addHist(new TH2F(TString("hoAnglemassNP_eff_multbin")+TString::Itoa(i,10),TString("hoAnglemassNP_eff_multbin")+TString::Itoa(i,10),90,0,180,nbins,xAxis1));
        hM.addHist(new TH2F(TString("hoAnglemassPP_eff_multbin")+TString::Itoa(i,10),TString("hoAnglemassPP_eff_multbin")+TString::Itoa(i,10),90,0,180,nbins,xAxis1));
        hM.addHist(new TH2F(TString("hoAnglemassNN_eff_multbin")+TString::Itoa(i,10),TString("hoAnglemassNN_eff_multbin")+TString::Itoa(i,10),90,0,180,nbins,xAxis1));
        hM.addHist(new TH2F(TString("hoAngleptNP_eff_multbin")+TString::Itoa(i,10),TString("hoAngleptNP_eff_multbin")+TString::Itoa(i,10),90,0,180,120,0,1200));
        hM.addHist(new TH2F(TString("hoAngleptPP_eff_multbin")+TString::Itoa(i,10),TString("hoAngleptPP_eff_multbin")+TString::Itoa(i,10),90,0,180,120,0,1200));
        hM.addHist(new TH2F(TString("hoAngleptNN_eff_multbin")+TString::Itoa(i,10),TString("hoAngleptNN_eff_multbin")+TString::Itoa(i,10),90,0,180,120,0,1200));
        hM.addHist(new TH2F(TString("hmassptNP_eff_multbin")+TString::Itoa(i,10),TString("hmassptNP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,120,0,1200));
        hM.addHist(new TH2F(TString("hmassptPP_eff_multbin")+TString::Itoa(i,10),TString("hmassptPP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,120,0,1200));
        hM.addHist(new TH2F(TString("hmassptNN_eff_multbin")+TString::Itoa(i,10),TString("hmassptNN_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,120,0,1200));
        hM.addHist(new TH2F(TString("hoAngleyNP_eff_multbin")+TString::Itoa(i,10),TString("hoAngleyNP_eff_multbin")+TString::Itoa(i,10),90,0,180,100,0,2));
        hM.addHist(new TH2F(TString("hoAngleyPP_eff_multbin")+TString::Itoa(i,10),TString("hoAngleyPP_eff_multbin")+TString::Itoa(i,10),90,0,180,100,0,2));
        hM.addHist(new TH2F(TString("hoAngleyNN_eff_multbin")+TString::Itoa(i,10),TString("hoAngleyNN_eff_multbin")+TString::Itoa(i,10),90,0,180,100,0,2));
        hM.addHist(new TH2F(TString("hmassyNP_eff_multbin")+TString::Itoa(i,10),TString("hmassyNP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,100,0,2));
        hM.addHist(new TH2F(TString("hmassyPP_eff_multbin")+TString::Itoa(i,10),TString("hmassyPP_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,100,0,2));
        hM.addHist(new TH2F(TString("hmassyNN_eff_multbin")+TString::Itoa(i,10),TString("hmassyNN_eff_multbin")+TString::Itoa(i,10),nbins,xAxis1,100,0,2));
        hM.addHist(new TH2F(TString("hptyNP_eff_multbin")+TString::Itoa(i,10),TString("hptyNP_eff_multbin")+TString::Itoa(i,10),120,0,1200,100,0,2));
        hM.addHist(new TH2F(TString("hptyPP_eff_multbin")+TString::Itoa(i,10),TString("hptyPP_eff_multbin")+TString::Itoa(i,10),120,0,1200,100,0,2));
        hM.addHist(new TH2F(TString("hptyNN_eff_multbin")+TString::Itoa(i,10),TString("hptyNN_eff_multbin")+TString::Itoa(i,10),120,0,1200,100,0,2));
        hM.addHist(new TH2F(TString("hth1th2NP_eff_multbin")+TString::Itoa(i,10),TString("hth1th2NP_eff_multbin")+TString::Itoa(i,10),90,0,90,90,0,90));
        hM.addHist(new TH2F(TString("hth1th2PP_eff_multbin")+TString::Itoa(i,10),TString("hth1th2PP_eff_multbin")+TString::Itoa(i,10),90,0,90,90,0,90));
        hM.addHist(new TH2F(TString("hth1th2NN_eff_multbin")+TString::Itoa(i,10),TString("hth1th2NN_eff_multbin")+TString::Itoa(i,10),90,0,90,90,0,90));
        hM.addHist(new TH2F(TString("hp1p2NP_eff_multbin")+TString::Itoa(i,10),TString("hp1p2NP_eff_multbin")+TString::Itoa(i,10),100,0,1100,100,0,1100));
        hM.addHist(new TH2F(TString("hp1p2PP_eff_multbin")+TString::Itoa(i,10),TString("hp1p2PP_eff_multbin")+TString::Itoa(i,10),100,0,1100,100,0,1100));
        hM.addHist(new TH2F(TString("hp1p2NN_eff_multbin")+TString::Itoa(i,10),TString("hp1p2NN_eff_multbin")+TString::Itoa(i,10),100,0,1100,100,0,1100));
    }

    //--------------- end histo booking -----------------------------------------------------

    HGenericEventMixer<HGeantKine> eventmixer;
    eventmixer.setPIDs(2,3,1);
    eventmixer.setBuffSize(80);
    //eventmixer.setBuffSize(2);
    HGenericEventMixer<HGeantKine> eventmixer_eff[5];
    for (int mb = 0; mb < 5; ++mb) {
        eventmixer_eff[mb].setPIDs(2,3,1);
        eventmixer_eff[mb].setBuffSize(80);
        //eventmixer_eff[mb].setBuffSize(2);
    }

    TStopwatch timer;
    timer.Reset();
    timer.Start();

    Float_t impB = -1.;
    Float_t impB_bins[]  = {9.3, 8.1, 6.6, 4.7, 0.};

    Int_t evtsInFile = loop->getEntries();
    if(nev < 0 || nev > evtsInFile ) nev = evtsInFile;

    for(Int_t i = 1; i < nev; i++)
    {
        //----------break if last event is reached-------------
        //if(!gHades->eventLoop(1)) break;
        if(loop->nextEvent(i) <= 0) { cout<<" end recieved "<<endl; break; } // last event reached
        HTool::printProgress(i,nev,1,"Analyze :");
        loop->getSectors(sectors);

	HPartialEvent *fSimul        = ((HRecEvent*)gHades->getCurrentEvent())->getPartialEvent(catSimul);
	HGeantHeader *fSubHeader = (HGeantHeader*)(fSimul->getSubHeader());
	impB = fSubHeader->getImpactParameter();

	Int_t multbin = 0;
        if (impB >= impB_bins[4] && impB <= impB_bins[3]) {multbin=1;} // most central
	if (impB >  impB_bins[3] && impB <= impB_bins[2]) {multbin=2;}
	if (impB >  impB_bins[2] && impB <= impB_bins[1]) {multbin=3;}
	if (impB >  impB_bins[1] && impB <= impB_bins[0]) {multbin=4;} // most peripheral
	if (impB >  impB_bins[0]) {multbin=5;}
/*
	HParticleEvtInfo* evtinfo;
	evtinfo = HCategoryManager::getObject(evtinfo,catParticleEvtInfo,0);

	Int_t multbin = 0;
	Int_t mult_meta = evtinfo->getSumTofMultCut() + evtinfo->getSumRpcMultHitCut();
        if (mult_meta >  60 && mult_meta <=  88) multbin = 4; // most peripheral
        if (mult_meta >  88 && mult_meta <= 121) multbin = 3;
        if (mult_meta > 121 && mult_meta <= 160) multbin = 2;
        if (mult_meta > 160 && mult_meta <= 250) multbin = 1; // most central
        if (mult_meta > 250) multbin = 5;
*/

        if (multbin == 0 || multbin == 5) continue;

        Int_t size = kineCat->getEntries();

        // Additional loop to fill vector
        vector<HGeantKine *> vep;
        vector<HGeantKine *> vem;
        vector<HGeantKine *> vep_eff;
        vector<HGeantKine *> vem_eff;
        vector<HGeantKine *> vep_eff_multbin;
        vector<HGeantKine *> vem_eff_multbin;
	for(Int_t j = 0; j < size; j ++){
	    kine1 = HCategoryManager::getObject(kine1,kineCat,j);
            Float_t vx,vy,vz;
            kine1->getVertex(vx,vy,vz);
	    Float_t vr = TMath::Sqrt(vx*vx+vy*vy);
            if (vz < -60 || vz > 0) continue;
            if (vr > 2) continue;
            Int_t mamaNum = kine1->getParentTrack();

            if (kine1->isInAcceptance()) {
                if (kine1->getTotalMomentum() > 100 && kine1->getTotalMomentum() < 1000) {
                    Float_t px,py,pz;
                    kine1->getMomentum(px,py,pz);
                    TH2F *smear_matr;
                    if (kine1->getID() == 2) {
                        smear_matr = smear_pos;
                    } else {
                        smear_matr = smear_ele;
                    }
                    Float_t mom_ideal = kine1->getTotalMomentum();
                    Float_t mom_reco = smear(mom_ideal,smear_matr,random);
                    Float_t reco_over_ideal = mom_reco / mom_ideal;
                    kine1->setMomentum(px*reco_over_ideal,py*reco_over_ideal,pz*reco_over_ideal);
                    TLorentzVector vec;
                    HParticleTool::getTLorentzVector(kine1,vec,kine1->getID());

                    Float_t mom = vec.Vect().Mag();
                    Float_t the = vec.Theta()*TMath::RadToDeg();
                    Float_t phi = (vec.Phi()+TMath::Pi())*TMath::RadToDeg();
                    Float_t chg = (kine1->getID() == 2) ? 1 : -1;

                    if (kine1->getID() == 3) {
                        vem.push_back(new HGeantKine(*kine1));
                    }
                    if (kine1->getID() == 2) {
                        vep.push_back(new HGeantKine(*kine1));
                    }
                    Float_t eff = 1./getEfficiencyFactor(p3DEffEle[0][6],p3DEffPos[0][6],mom_ideal,the,phi,chg,false,false); // don't debug, don't check min value
                    if (isinf(eff) || isnan(eff)) eff = 0.;
                    if (random.Uniform(1) > eff) {
                        if (kine1->getID() == 3) {
                            vem_eff.push_back(new HGeantKine(*kine1));
                        }
                        if (kine1->getID() == 2) {
                            vep_eff.push_back(new HGeantKine(*kine1));
                        }
                    }
                    Float_t eff_multbin = 1./getEfficiencyFactor(p3DEffEle[multbin][6],p3DEffPos[multbin][6],mom,the,phi,chg,false,false);
                    if (isinf(eff_multbin) || isnan(eff_multbin)) eff_multbin = 0.;
                    if (random.Uniform(1) > eff_multbin) {
                        if (kine1->getID() == 3) {
                            vem_eff_multbin.push_back(new HGeantKine(*kine1));
                        }
                        if (kine1->getID() == 2) {
                            vep_eff_multbin.push_back(new HGeantKine(*kine1));
                        }
                    }
                }
            }
        }

        eventmixer.nextEvent();
        eventmixer.addVector(vep,2);
        eventmixer.addVector(vem,3);
        vector<pair<HGeantKine *, HGeantKine* > >& pairsVec_acc = eventmixer.getMixedVector();

        eventmixer_eff[0].nextEvent();
        eventmixer_eff[0].addVector(vep_eff,2);
        eventmixer_eff[0].addVector(vem_eff,3);
        vector<pair<HGeantKine *, HGeantKine* > >& pairsVec_eff = eventmixer_eff[0].getMixedVector();

        eventmixer_eff[multbin].nextEvent();
        eventmixer_eff[multbin].addVector(vep_eff,2);
        eventmixer_eff[multbin].addVector(vem_eff,3);
        vector<pair<HGeantKine *, HGeantKine* > >& pairsVec_eff_multbin = eventmixer_eff[multbin].getMixedVector();

        for (int imix = 0; imix < 3; ++imix) {
            vector<pair<HGeantKine *, HGeantKine* > > pairsVec;
            TString suffix;
            switch (imix) {
                case 0: 
                    pairsVec = pairsVec_acc;
                    suffix = TString(""); 
                    break;
                case 1: 
                    pairsVec = pairsVec_eff;
                    suffix = TString("_eff_multbin0");
                    break;
                case 2: 
                    pairsVec = pairsVec_eff_multbin;
                    suffix = TString("_eff_multbin")+TString::Itoa(multbin,10);
                    break;
            }
            size = pairsVec.size();

            for (Int_t j = 0; j < size; j ++) {
                pair<HGeantKine*,HGeantKine*>& pair = pairsVec[j];

                kine1 = pair.first;
                kine2 = pair.second;
                TLorentzVector vec1, vec2;
                HParticleTool::getTLorentzVector(kine1,vec1,kine1->getID());
                HParticleTool::getTLorentzVector(kine2,vec2,kine2->getID());

                Float_t mom1 = vec1.Vect().Mag();
                Float_t the1 = vec1.Theta()*TMath::RadToDeg();
                Float_t mom2 = vec2.Vect().Mag();
                Float_t the2 = vec2.Theta()*TMath::RadToDeg();

                TLorentzVector dilep = vec1 + vec2;
                Float_t oAngle = vec1.Angle(vec2.Vect())*TMath::RadToDeg();
                Float_t mass   = dilep.M()/1000;
                Float_t pt     = dilep.Perp();
                Float_t y      = dilep.Rapidity();
                Float_t mbinw  = hM.get("hmassNP")->GetBinWidth(hM.get("hmassNP")->FindBin(mass));

                if (oAngle < 9) continue;

                TString chg = "NP";
                if (kine1->getID() == kine2->getID()) {
                    if (kine1->getID() == 2) chg = "PP";
                    if (kine1->getID() == 3) chg = "NN";
                }

                hM.get( TString("hmass")      +chg+suffix)->Fill(mass,       1./mbinw);
                hM.get( TString("hoAngle")    +chg+suffix)->Fill(oAngle      );
                hM.get( TString("hy")         +chg+suffix)->Fill(y           );
                hM.get( TString("hpt")        +chg+suffix)->Fill(pt          );
                hM.get2(TString("hoAnglemass")+chg+suffix)->Fill(oAngle,mass,1./mbinw);
                hM.get2(TString("hoAnglept")  +chg+suffix)->Fill(oAngle,pt   );
                hM.get2(TString("hmasspt")    +chg+suffix)->Fill(mass,pt,    1./mbinw);
                hM.get2(TString("hoAngley")   +chg+suffix)->Fill(oAngle,y    );
                hM.get2(TString("hmassy")     +chg+suffix)->Fill(mass,y,     1./mbinw);
                hM.get2(TString("hpty")       +chg+suffix)->Fill(pt,y        );
                hM.get2(TString("hth1th2")    +chg+suffix)->Fill(the1,the2   );
                hM.get2(TString("hp1p2")      +chg+suffix)->Fill(mom1,mom2   );
            }
        }
//#define DELETE_MIX
#ifdef DELETE_MIX
        vector <HGeantKine *>* toDel = eventmixer.getObjectsToDelete();
        for (unsigned int ii = 0; ii < toDel->size(); ++ii) {
            delete toDel->at(ii);
        }
        toDel->clear();
        delete toDel;
        vector <HGeantKine *>* toDel_eff = eventmixer_eff[0].getObjectsToDelete();
        for (unsigned int ii = 0; ii < toDel_eff->size(); ++ii) {
            delete toDel_eff->at(ii);
        }
        toDel_eff->clear();
        delete toDel_eff;
        vector <HGeantKine *>* toDel_eff_multbin = eventmixer_eff[multbin].getObjectsToDelete();
        for (unsigned int ii = 0; ii < toDel_eff_multbin->size(); ++ii) {
            delete toDel_eff_multbin->at(ii);
        }
        toDel_eff_multbin->clear();
        delete toDel_eff_multbin;
#endif

    } // end event loop

    timer.Stop();

    hM.getFile()->cd();
    TMacro m1(__DIELEANA_FILE__);
    m1.Write();
    hM.writeHists("nomap");

    cout<<"####################################################"<<endl;
    return 0;
}
Esempio n. 2
0
Int_t flowCount(TString inputlist, TString outfile, Int_t nev=-1)
{
    HLoop* loop = new HLoop   (kTRUE    );    // kTRUE : create Hades  (needed to work with standard eventstructure)
           loop ->addMultFiles(inputlist);
    //-----Inicialize-classes-we-need-to-use-----------------
    HMultCorr   cCorr;
    PidParticle p;
    //--------------------------------------------------------------------------------------------------------
    #include "/u/parfenov/anaflow/flowVar.C"     //include all constants and variables we need          
    TH2F*  hProtPtVsY_Eff;
    TFile* foutfile       = new TFile(outfile.Data(), "recreate"); 
    TFile* FileProtEff    = new TFile("EffCorrForProtPtVsY_WithWideBetaPcuts_ShieldGosia.root", "read");
           hProtPtVsY_Eff = (TH2F*) FileProtEff->Get("hProtPtVsY_EffSm");
           foutfile->cd();
    #include "/u/parfenov/anaflow/flowHisto.C"   //include all histograms we need                       
    //if(par!=0){
        FFlow pfy0pt[NC-4][NRAPI][NPTRN-5]; //--flow--9-bins-Yo--12-bins-in-Pt-in-3-centrality-sets--
        FFlow pfR0pt[NC-4][NRAPI][NPTRN-5];
        FFlow pfF0pt[NC-4][NRAPI][NPTRN-5];
        FHist phist[ NC-4][NRAPI][NPTRN-5];
        for (Int_t i=0; i<NC-4;i++){
            for(Int_t j=0; j<NRAPI; j++){
                for(Int_t k=0; k<NPTRN-5; k++){
                    //-proton------------------------------------------
                    pfy0pt[i][j][k].THDeclare("pCent",i,"Yo",j,"Pt",k);
                    pfR0pt[i][j][k].THDeclare("RCent",i,"Yo",j,"Pt",k);
                    pfF0pt[i][j][k].THDeclare("FCent",i,"Yo",j,"Pt",k);
                    phist[ i][j][k].THDeclare("pHist",i,"Yo",j,"Pt",k);
                }
            }
        }
    //}

    fBetaMeanP->SetParameter(0,HPhysicsConstants::mass(14));
    //--------------------------------------------------------------------------------------------------------
    if(!loop->setInput("-*,+HParticleCand,+HParticleEvtInfo,+HStart2Hit,+HStart2Cal,+HWallHit,+HRpcCluster,+HTofHit,+HWallEventPlane")) { exit(1); }
    loop->printCategories();
  
    HParticleEvtInfo* evtinfo;
  
    HParticleCand*   pParticleCand;   HCategory* candCat   = (HCategory*)HCategoryManager::getCategory(catParticleCand);   if(!candCat)  {exit(1);}
    HWallHit*        pWallHit;        HCategory* wallCat   = (HCategory*)HCategoryManager::getCategory(catWallHit);        if(!wallCat)  {exit(1);}
    HWallEventPlane* pWallEventPlane; HCategory* wallEPCat = (HCategory*)HCategoryManager::getCategory(catWallEventPlane); if(!wallEPCat){exit(1);}
    
    //--------------------------CONFIGURATION---------------------------------------------------
    //At begin of the program (outside the event loop)
    HParticleTrackSorter sorter;
    //sorter.setDebug();                          // for debug
    //sorter.setPrintLevel(3);                    // max prints
    //sorter.setIgnoreInnerMDC();                 // do not reject Double_t inner MDC hits
    //sorter.setIgnoreOuterMDC();                 // do not reject Double_t outer MDC hits
    //sorter.setIgnoreMETA();                     // do not reject Double_t META hits
    //sorter.setIgnorePreviousIndex();            // do not reject indices from previous selctions
    sorter.init();                                // get catgegory pointers etc...
    //--------------------------------------------------------------------------------------------

    HEnergyLossCorrPar *momCorPar = new HEnergyLossCorrPar();
    momCorPar->setDefaultPar("apr12");
      
    /////////////////////////////////////////////////////////
    //-----Loop-over-events----------------------------------
    /////////////////////////////////////////////////////////
  
    loop->addMultFiles(inputlist);
    Int_t events = loop->getEntries();
    if(nev < events && nev >= 0 ) events = nev;
  
    for (Int_t i=1; i<events;i++){
    
        if (loop->nextEvent(i)<=0){
            cout << "End recieved with IF exit" << endl;
            break;
        }
        if(par==0) hcuts->Fill(1.);
        if (i%1000 == 0){
            cout << "    event " << i << endl;
        }
    
        if( loop->isNewFile(currFName) ){ 
            printf("--New-file-started--> %s", currFName.Data() ); 
            currFName = currFName( currFName.Last('/')+1,currFName.Length()-currFName.Last('/')-1 );
            currBeName = currFName(0, 13); //-simply-the-file-name-w/o-EBchunk--
            currFDay = currFName( 4, 3 ); //-we-cut-out-day-number-position-starting-from-4th-digit-with-length-of-3digits--
            DAY_NUM = currFDay.Atoi();
            currTime = currFName( 7, 2 ); //-we-cut-out-day-hour--position-starting-from-4th-digit-with-length-of-3digits--
            HR=currTime.Atoi();
            currTime = currFName( 9, 2 ); //-we-cut-out-day-minute-position-starting-from-4th-digit-with-length-of-3digits--
            MN=currTime.Atoi();
            currTime = currFName(11, 2 ); //-we-cut-out-day-second-position-starting-from-4th-digit-with-length-of-3digits--
            SC=currTime.Atoi();
            AbsMinute = MN + HR*60 + DAY_NUM*24*60;
            #include "/u/parfenov/anaflow/FlatSinCos.cc"
            //#include "/u/parfenov/anaflow/FOPICorPar.cc"
            #include "/u/parfenov/anaflow/Recenter.cc"
            #include "/u/parfenov/anaflow/RecenterMETA.cc"
            #include "/u/parfenov/anaflow/RecenterFW.cc" //Q vect recenter FW;
            //#include "/u/parfenov/anaflow/FlatFourier.cc"//for flattening Psi_EP via fit;
            //--Now-we-read-multiplicity-parameters-for-this-beXXXXXXXXXX-file--------------------//
            mulVal = cCorr.getLineValuesAsVectFromCalibFile( currBeName );
            cout<<"mulVal "<< mulVal[0] <<" "<< mulVal[1] <<" "<< mulVal[2] <<" "<< mulVal[3] <<endl;
            fAverageMTS[0]=mulVal[4];  //multiplicity in tracking sector 1
            fAverageMTS[1]=mulVal[5];  //multiplicity in tracking sector 2
            fAverageMTS[2]=mulVal[6];  //...
            fAverageMTS[3]=mulVal[7];
            fAverageMTS[4]=mulVal[8];
            fAverageMTS[5]=mulVal[9];  //multiplicity in tracking sector 6
            printf("fAverageMTS[0,1,2,3,4,5]=[%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,]\n", fAverageMTS[0], fAverageMTS[1], fAverageMTS[2], fAverageMTS[3], fAverageMTS[4], fAverageMTS[5]);
        
            //fTrkMultDay108
            if(mulVal[2]>0.0){
                //-if-correction-is-found-or-if-it-was-not-zero-defined-(in-case-of-not-working-MDCs)---
                fTrkMultScaler = fTrkMultDay108/mulVal[2];
                printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f\n", fTrkMultDay108, mulVal[2], fTrkMultScaler );
            }else{
                //--if-correction-entry-is-not-found-(may-be-not-created-once)------------------
                //--or-if-say-MDCs-were-not-working-and-tracking-multiplicity-was-exectly-zero--
                //-we-keep-correction-as-it-was-in-previous-file-or-if-not-defined-hence-it-would-be-exactly-one=1-or-
                printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f (default or old correction is used)\n", fTrkMultDay108, mulVal[2], fTrkMultScaler);
            }
        }
        HTool::printProgress(i,events,1,"Analyze pairs :");
        evtinfo = HCategoryManager::getObject(evtinfo,catParticleEvtInfo,0);

        if( evtinfo->getSumParticleCandMult()<2 ){if(par==0){ hcuts->Fill(2.); } continue; } //getSumParticleCandMult()>1
        if(!evtinfo->isGoodEvent(
                               Particle::kGoodVertexClust|
                               Particle::kGoodVertexCand|
                               Particle::kNoPileUpSTART|
                               Particle::kGoodSTART|      
                               Particle::kGoodTRIGGER|    
                               Particle::kNoVETO|         
                               Particle::kGoodSTARTVETO|  
                               Particle::kGoodSTARTMETA
                              )){ if(par==0){ hcuts->Fill(3.); } continue ; }// bitwise add flags as suggested by Manuel 

        //------------------------------------------------------------------------
        // clean vectors and index arrays
        sorter.cleanUp();
        //------------------------------------------------------------------------

        sorter.resetFlags(kTRUE,kTRUE,kTRUE,kTRUE);
        Int_t nCandHad        = sorter.fill(selectHadronsQa);
        Int_t nCandHadBest    = sorter.selectBest(HParticleTrackSorter::kIsBestRK,HParticleTrackSorter::kIsHadron);

        Int_t nCandNoLept     = sorter.fill(rejectLeptons);
        Int_t nCandNoLeptBest = sorter.selectBest(HParticleTrackSorter::kIsBestRK,HParticleTrackSorter::kIsLepton);

        //-------Get-vertex-from-combined-fit-of-fitted-inner-segments------------
        HVertex   fPrimVertReco = gHades->getCurrentEvent()->getHeader()->getVertexReco();
        vertexX = fPrimVertReco.getX();
        vertexY = fPrimVertReco.getY();
        vertexZ = fPrimVertReco.getZ();

        if(par==0){
            hvertexXZ->Fill(vertexZ,vertexX);
            hvertexXY->Fill(vertexY,vertexX);
            hvertexX ->Fill(vertexX);
            hvertexY ->Fill(vertexY);
            hvertexZ ->Fill(vertexZ);
        }

        //------Alexandr's-vertex-cuts---------
        tgtChi2 = (Float_t) fPrimVertReco.getChi2();
        if( tgtChi2<2.0 || tgtChi2>40.){ if(par==0){ hcuts->Fill(4.); } continue; }//-skip-events-with-badly-reconstructed-target-------
        if( vertexZ<-59.|| vertexZ>0. ){ if(par==0){ hcuts->Fill(5.); } continue; }//-skip-events-with-primary-vertex-outside-of-target-
        if( (vertexX-tgtXc)*(vertexX-tgtXc)+(vertexY-tgtYc)*(vertexY-tgtYc)>R2 ){ if(par==0){ hcuts->Fill(6.); } continue; }//-skip-events-with-primary-vertex-far-from-target---
        //----end-of-Alexandr's-vertex-cuts----
        if(par==0){ 
            hvtxCutXZ->Fill(vertexZ,vertexX);
            hvtxCutXY->Fill(vertexY,vertexX);
            hvtxCutX ->Fill(vertexX);
            hvtxCutY ->Fill(vertexY);
            hvtxCutZ ->Fill(vertexZ);
        }
                              
        Mtof = evtinfo->getSumTofMult();
        Mrpc = evtinfo->getSumRpcMult();
        Mult = Mtof+Mrpc;
        //---------centrality-classes--------------------------------------------------------------------(begin)--------//
        //-Centrality-selection-for-further-if-selection-statements------------------------//
        nTrkMult = getParticleTrkMult();
        Mtr   = nTrkMult; if(par==0) hTrkMult->Fill(nTrkMult);
        nTrkMultCorr = nTrkMult*fTrkMultScaler; if(par==0) hTrkMultCorr->Fill(nTrkMultCorr);
        if(par==0) hMETAvsTRK    ->Fill(Mtof+Mrpc,nTrkMult    );
        if(par==0) hMETAvsTRKcorr->Fill(Mtof+Mrpc,nTrkMultCorr);

        //--------------------------------------------//
        //--Event plane reconstruction loop-----------//
        //--------------------------------------------// 
        multWall=0;
        cellNum=0;
        cellTime=0.0;
        cellCharge=0.0;
        wallX=0.0,wallY=0.0,wallZ=0.0;
        wallXc=0.0, wallYc=0.0; //corrected-reCentered-
        XfwSmear=0.0, YfwSmear=0.0;
        for (Int_t a=0;a<QvRING;a++){//Ring: 0-full,1-small,2-medium,3-large;
            FWRing[a] = kFALSE;
            for (Int_t b=0;b<QvWGHT;b++){//Weight: 0-wght=1, 1-wght=2;
                for (Int_t c=0;c<QvTYPE;c++){//Type: 0-source from FW, 1-recentered;
                    Qvect[a][b][c].Set(0.,0.);
                    Qvsum[a][b][c].Set(0.,0.);
                }
            }
        }
        vect.Set(    0.,0.);
        vsum.Set(    0.,0.);
        vsumMETA.Set(0.,0.);
        vsumFW.Set(  0.,0.);
        vsumCorr.Set(0.,0.);
        vsumCorrA.Set(0.,0.);
        vsumCorrB.Set(0.,0.);
        eX  .Set(1.,0.);
        dEdxCut=0.0;
        xyRadius=0.0;
        phiA   = -1000;
        phiB   = -1000;
        phiAB  = -1000;
        phiCorA= -1000;
        phiCorB= -1000;
        PsiA   = -1000;
        PsiB   = -1000;
        cellsVect.Reset();
      
        //-weight-for-scalar-product-method-------------------
        wgh = 1.0;  //PCpt; //1.0; //-or-could-be-also-equal-to-Pt---
        nFWhits   = 0;
        nFWspect  = 0;
        nFWunderflow = 0;
        FWdEdxA=0.0;
        FWdEdxB=0.0;
  
        FWdEdxL=0.0;
        FWdEdxM=0.0;
        FWdEdxN=0.0;
        choiceA = 1; //
        choiceB = 1; // Preparing for A/B subevent method
        wmod    = 0.;
        wmodA   = 0.;
        wmodB   = 0.;
        //-------------------------------------------iteration-WallHits----(begin)--------------------------------------------------//
        for(Int_t j=0; j<(wallCat->getEntries()); j++){
            pWallHit = HCategoryManager::getObject(pWallHit,wallCat,j);
            cellNum    = pWallHit->getCell();
            cellTime   = pWallHit->getTime();
            cellCharge = pWallHit->getCharge();
            cellChargeCtime = cellTime;
            hFW_TimeCell_0->Fill(cellTime  , cellNum);
            hFW_dEdxCell_0->Fill(cellCharge, cellNum);
            if(cellNum>=0   && cellNum<304 ){                   FWRing[0] = kTRUE; }
            if(cellNum< 144                ){ dEdxCut=Z1_cut_s; FWRing[1] = kTRUE; }
            if(cellNum>=144 && cellNum<=207){ dEdxCut=Z1_cut_m; FWRing[2] = kTRUE; }
            if(cellNum> 207                ){ dEdxCut=Z1_cut_l; FWRing[3] = kTRUE; }
            if(cellTime>T1_cut && cellTime<T2_cut && cellCharge>dEdxCut){
           
                nFWspect++;
                hFW_TimeCell_1->Fill(cellTime  , cellNum);
                hFW_dEdxCell_1->Fill(cellCharge, cellNum);
                pWallHit->getXYZLab(wallX,wallY,wallZ);
                hFWxyCC->Fill(wallX,wallY); //cell centers
                
                //-recentering--FW-----------------------------------------------------
                for (Int_t im=1;im<12;im++){
                    if( (Mtof+Mrpc)>=Mrang[im-1] && (Mtof+Mrpc)<Mrang[im]){ wallXc = wallX - X_shM[im]; wallYc = wallY - Y_shM[im]; }
                }
                //-here-we-fill-d2N/(dxdy)-inX-band--and--y-band--for-auto-recentering-
                //-this-makes-realistic-distribution-on-FW-face------------------------
                if (cellNum>=0   && cellNum<=143) { cellSize = 40;  }
                if (cellNum>=144 && cellNum<=207) { cellSize = 80;  }
                if (cellNum>=210 && cellNum<=301) { cellSize = 160; }
                XfwSmear = wallX + ( Random.Rndm(1) - 0.5 )*cellSize;
                YfwSmear = wallY + ( Random.Rndm(1) - 0.5 )*cellSize;
           
                for (Int_t im=0;im<11;im++){                    
                    if( (Mtof+Mrpc)>=  Mrang[im] && (Mtof+Mrpc)< Mrang[im+1] ){
                        hFW_TimeCell_0->Fill(cellTime  , cellNum);
                        hFW_dEdxCell_0->Fill(cellCharge, cellNum);
                    }
                }
                //-this-cut-was-forgotten-for-Feb2014-HADES-CM-report--//
                //-I-reintroduce-it-14.03.2014----(c)-Sadovsky---------//
                if(  wallXc*wallXc + wallYc*wallYc >= R0_cut*R0_cut  /*50.*50.*/ ){
                    hFW_TimeCell_2->Fill(cellTime  , cellNum);
                    hFW_dEdxCell_2->Fill(cellCharge, cellNum);
                    //-spectators-selected--
                    multWall++;
                    /*for (Int_t a=0;a<QvRING;a++){
                       for (Int_t b=0;b<QvWGHT;b++){
                            if (FWRing[a]){
                                Qvect[a][b][0].Set(wallX, wallY);
                                Qvect[a][b][0] = Qvect[a][b][0].Unit();
                                if(b == 1) Qvect[a][b][0] *= cellCharge;
                                Qvsum[a][b][0] = Qvsum[a][b][0] + Qvect[a][b][0];
                            }
                        }
                    }*/
                    vect.Set(wallX, wallY);
                    vect = vect.Unit();
                    vect *= cellCharge;
                    wmod += cellCharge;
                    vsum += vect;
                    cellsVect.SetCellVect(vect, cellCharge); //-note-[vect]-is-a-unit-vector-this-is-for-further-subevent-(A/B)-split--
                    hFWxyCCsmear->Fill(XfwSmear        ,YfwSmear        ); //cells smeared but not shifted
                    hFWxySHsmear->Fill(XfwSmear-X_shift,YfwSmear-Y_shift); //cells smeared and shifted as a whole
                    //-center-of-gravity-study-as-a-course-of-centrality-----------------------------
                    for (Int_t im=0;im<11;im++){
                        if( (Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){ 
                            hFWxyCCsmearM[im]->Fill(XfwSmear,YfwSmear); 
                            hFWxyCCsmearXscanM[im]->Fill(XfwSmear - X_shM[im],YfwSmear - Y_shM[im]); 
                        }
                    }
                }//-endif-R0_cut--//
            }//end-if-cells-cut---
        }//end-for-HitWall-loop---
        vsum      /= wmod;
        //mQx = mQxFW[nFWspect];
        //mQy = mQyFW[nFWspect];
        //if (mQx = mQxFW[nFWspect]) cout  << " ev = " << i << " * " << nFWspect << "| Qx = " << mQx << "; Qy = " << mQy <<"; vX = " << vsum.X() << "; vY = " << vsum.Y() << endl;
        //if(  nFWspect>=0    &&  nFWspect< 100   ) vsumFW.Set(vsum.X() - mQxFW[nFWspect],vsum.Y() - mQyFW[nFWspect]);
        mQx = vsum.X() - mQx;
        mQy = vsum.Y() - mQy;
        for (Int_t im=0;im<11;im++){
            if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                //vsumCorr = cellsVect.Recenter(vsum,sumXmean[0][im][DAY_NUM-96],sumYmean[0][im][DAY_NUM-96],sumXsigma[0][im][DAY_NUM-96],sumYsigma[0][im][DAY_NUM-96]);
                //vsumRec  = cellsVect.Recenter(vsum,sumXmean[0][im][DAY_NUM-96],sumYmean[0][im][DAY_NUM-96]);
                vsumCorr   = cellsVect.Recenter(vsum,mQxFW[nFWspect][0]       ,mQyFW[nFWspect][0]         );
                //if( (Mtof+Mrpc)>=20 && (Mtof+Mrpc)< 215 ) vsumMETA = cellsVect.Recenter(vsum,Qxmean[Mtof+Mrpc][0],Qymean[Mtof+Mrpc][0]);
                //cout << "ev = " << i << " | QxR = " << vsumFW.X() << "; QyR = " << vsumFW.Y() << ";" << endl; 
            }
        }
        VectphiEP   = vsum.DeltaPhi(eX)      *rad2deg;
        VectphiEPr  = vsum.DeltaPhi(eX);     //radians
        VectphiCorr = vsumCorr.DeltaPhi(eX)  *rad2deg;
        VectphiCorrR= vsumCorr.DeltaPhi(eX); //radians
        hPhiEPvect->Fill(VectphiEP);
        //-now-we-go-over-spectators-and-make-calculations-for-A/B-subevents
        NA=0;
        NB=0;
        multFWcells = cellsVect.GetNumbOfCells();
        Float_t choice;
        vectA.Set(0.,0.);
        vectB.Set(0.,0.);
        vsumA.Set(0.,0.);
        vsumB.Set(0.,0.);
        for(Int_t ic=0; ic<multFWcells; ic++){
            choice = Random.Rndm(1);
            //-this-is-(A/B)-subevents-split--(begin)-(c)-Sadovsky-----------------------------
            //-I-can-be-proud-that-my-algorithm-has-more-flat-distribution--:)-(c)-Sadovsky----
            levelA = (multFWcells/2.-choiceA+1.)/Float_t(multFWcells);
            levelB = (multFWcells/2.-choiceB+1.)/Float_t(multFWcells);
            if(choice < levelA/(levelA+levelB)){
                vectA = cellsVect.GetCellVector(ic);
                vsumA += vectA;
                choiceA++;
                NA++;
                vsumA += vectA;
                choiceA++;
                NA++;
                FWdEdxA=FWdEdxA + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
                wmodA += cellsVect.GetCellCharge(ic);
            }else{
                vectB = cellsVect.GetCellVector(ic);
                vsumB += vectB;
                choiceB++;
                NB++;
                vectB = cellsVect.GetCellVector(ic);
                vsumB += vectB;
                choiceB++;
                NB++;
                VectPhi_i = vectB.DeltaPhi(eX); //-Phi-of-i_th-spectator-particle-from-subevent-B--
                FWdEdxB=FWdEdxB + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
                wmodB += cellsVect.GetCellCharge(ic);
            }//-HWallHit-second-loop-for-reaction-plane-resolution--( end )---//
            //-this-is-(A/B)-subevents-split--( end )------------------------------------------
        }//-endfor-multFWcells-loop--for-A/B-method--
        //-calculating-eventplane-angles---------------
        vsumA /= wmodA;
        vsumB /= wmodB;
        for (Int_t im=0;im<11;im++){
            if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                vsumCorrA = cellsVect.Recenter(vsumA,mQxFW[nFWspect][1],mQyFW[nFWspect][1]);
                vsumCorrB = cellsVect.Recenter(vsumB,mQxFW[nFWspect][2],mQyFW[nFWspect][2]);
                //vsumRecA.Set(vsumCorrA.X()*sumXsigma[1][im][DAY_NUM-96],vsumCorrA.Y()*sumYsigma[1][im][DAY_NUM-96]);
                //vsumRecA.Set(vsumCorrA.X()*sumXsigma[2][im][DAY_NUM-96],vsumCorrA.Y()*sumYsigma[2][im][DAY_NUM-96]);
            }
        }
        phiA    = vsumA.DeltaPhi(eX)            *rad2deg;
        phiB    = vsumB.DeltaPhi(eX)            *rad2deg;
        phiAB   = vsumA.DeltaPhi(vsumB)         *rad2deg;
        phiCorAB= vsumCorrA.DeltaPhi(vsumCorrB) *rad2deg;
        phiCorA = vsumCorrA.DeltaPhi(eX)        *rad2deg;
        phiCorB = vsumCorrB.DeltaPhi(eX)        *rad2deg;
        Mfw     = NA+NB;
        if (Mfw > 3 && NA>1 && NB>1){
            for (Int_t im=0;im<11;im++){
                if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                    hQvectX[0][im]->Fill(vsum.X());            hQvectY[0][im]->Fill(vsum.Y());
                    hQvXrec[0][im]->Fill(vsumCorr.X());        hQvYrec[0][im]->Fill(vsumCorr.Y());
                    hQvectX[1][im]->Fill(vsumA.X());           hQvectY[1][im]->Fill(vsumA.Y());
                    hQvXrec[1][im]->Fill(vsumCorrA.X());       hQvYrec[1][im]->Fill(vsumCorrA.Y());
                    hQvectX[2][im]->Fill(vsumB.X());           hQvectY[2][im]->Fill(vsumB.Y());
                    hQvXrec[2][im]->Fill(vsumCorrB.X());       hQvYrec[2][im]->Fill(vsumCorrB.Y());
                    hQvRaw[0][ im]->Fill(vsum.X(),vsum.Y());   hQvRec[0][ im]->Fill(vsumCorr.X(),vsumCorr.Y());
                    hQvRaw[1][ im]->Fill(vsumA.X(),vsumA.Y()); hQvRec[1][ im]->Fill(vsumCorrA.X(),vsumCorrA.Y());
                    hQvRaw[2][ im]->Fill(vsumB.X(),vsumB.Y()); hQvRec[2][ im]->Fill(vsumCorrB.X(),vsumCorrB.Y());
                }
            }
            for (Int_t n=1;n<=6;n++){
                for (Int_t im=0;im<11;im++){
                    if ((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                        hSinPsi[0][n-1][im]->Fill(DAY_NUM,sin(n*VectphiCorrR),1);
                        hCosPsi[0][n-1][im]->Fill(DAY_NUM,cos(n*VectphiCorrR),1);
                        hSinPsi[1][n-1][im]->Fill(DAY_NUM,sin(n*phiCorA*hpi/90.),1);
                        hCosPsi[1][n-1][im]->Fill(DAY_NUM,cos(n*phiCorA*hpi/90.),1);
                        hSinPsi[2][n-1][im]->Fill(DAY_NUM,sin(n*phiCorB*hpi/90.),1);
                        hCosPsi[2][n-1][im]->Fill(DAY_NUM,cos(n*phiCorB*hpi/90.),1);
                    }
                }
            }
            for (Int_t im=0;im<11;im++){
                if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                    dPsi = 0.;
                    for (Int_t n=0;n<6;n++){
                        cellsVect.SetFlatt(n,FlatSin[0][n][im][DAY_NUM-96],FlatCos[0][n][im][DAY_NUM-96]);
                    }
                    PsiCorr = cellsVect.Flattening(VectphiCorr);
                    //hdPsi[im]->Fill(dPsi*rad2deg);
                    //PsiCorr = atan2(sin(VectphiCorrR+dPsi),cos(VectphiCorrR+dPsi))*rad2deg;
                    //PsiCorr2 = VectphiCorr + dPsi;
                    //hFlatDiff[im]->Fill(PsiCorr/PsiCorr2);
                    if (PsiCorr > 180. ) PsiCorr-=180.;
                    if (PsiCorr < -180.) PsiCorr+=180.;
                    hPsiEP[0][im]->Fill(VectphiEP); hPsiRcnt[0][im]->Fill(VectphiCorr); hPsiCorr[0][im]->Fill(PsiCorr);

                    hsumXmean[0][im]->Fill(DAY_NUM,vsum.X(),1); 
                    hsumYmean[0][im]->Fill(DAY_NUM,vsum.Y(),1); 

                    hQvsM_X[0][0]->Fill(Mtof+Mrpc,vsum.X()); 
                    hQvsM_Y[0][0]->Fill(Mtof+Mrpc,vsum.Y()); 
                    hQvFW_X[0][0]->Fill(nFWspect ,vsum.X()); 
                    hQvFW_Y[0][0]->Fill(nFWspect ,vsum.Y()); 
                    hQvsM_X[0][1]->Fill(Mtof+Mrpc,vsumA.X()); 
                    hQvsM_Y[0][1]->Fill(Mtof+Mrpc,vsumA.Y()); 
                    hQvFW_X[0][1]->Fill(nFWspect ,vsumA.X()); 
                    hQvFW_Y[0][1]->Fill(nFWspect ,vsumA.Y());
                    hQvsM_X[0][2]->Fill(Mtof+Mrpc,vsumB.X()); 
                    hQvsM_Y[0][2]->Fill(Mtof+Mrpc,vsumB.Y()); 
                    hQvFW_X[0][2]->Fill(nFWspect ,vsumB.X()); 
                    hQvFW_Y[0][2]->Fill(nFWspect ,vsumB.Y());
                    hQvsM_X[1][0]->Fill(Mtof+Mrpc,vsumCorr.X()); 
                    hQvsM_Y[1][0]->Fill(Mtof+Mrpc,vsumCorr.Y()); 
                    hQvFW_X[1][0]->Fill(nFWspect ,vsumCorr.X()); 
                    hQvFW_Y[1][0]->Fill(nFWspect ,vsumCorr.Y());
                    hQvsM_X[1][1]->Fill(Mtof+Mrpc,vsumCorrA.X()); 
                    hQvsM_Y[1][1]->Fill(Mtof+Mrpc,vsumCorrA.Y()); 
                    hQvFW_X[1][1]->Fill(nFWspect ,vsumCorrA.X()); 
                    hQvFW_Y[1][1]->Fill(nFWspect ,vsumCorrA.Y());
                    hQvsM_X[1][2]->Fill(Mtof+Mrpc,vsumCorrB.X()); 
                    hQvsM_Y[1][2]->Fill(Mtof+Mrpc,vsumCorrB.Y()); 
                    hQvFW_X[1][2]->Fill(nFWspect ,vsumCorrB.X()); 
                    hQvFW_Y[1][2]->Fill(nFWspect ,vsumCorrB.Y());   
                }
            }
            for (Int_t im=0;im<11;im++){
                if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                    for (Int_t n=0;n<6;n++){
                        cellsVect.SetFlatt(n,FlatSin[1][n][im][DAY_NUM-96],FlatCos[1][n][im][DAY_NUM-96]);
                    }
                    PsiA = cellsVect.Flattening(phiCorA);
                    if (PsiA > 180. ) PsiA-=180.;
                    if (PsiA < -180.) PsiA+=180.;
                    hPsiEP[1][im]->Fill(phiA); hPsiRcnt[1][im]->Fill(phiCorA); hPsiCorr[1][im]->Fill(PsiA);

                    hsumXmean[1][im]->Fill(DAY_NUM,vsumA.X(),1); 
                    hsumYmean[1][im]->Fill(DAY_NUM,vsumA.Y(),1); 
                }
            }
            for (Int_t im=0;im<11;im++){
                if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                    for (Int_t n=0;n<6;n++){
                        cellsVect.SetFlatt(n,FlatSin[2][n][im][DAY_NUM-96],FlatCos[2][n][im][DAY_NUM-96]);
                    }
                    cellsVect.SetNharm(6);
                    PsiB = cellsVect.Flattening(phiCorB);
                    if (PsiB > 180. ) PsiB-=180.;
                    if (PsiB < -180.) PsiB+=180.;
                    hPsiEP[2][im]->Fill(phiA); hPsiRcnt[2][im]->Fill(phiCorA); hPsiCorr[2][im]->Fill(PsiB);

                    hsumXmean[2][im]->Fill(DAY_NUM,vsumB.X(),1); 
                    hsumYmean[2][im]->Fill(DAY_NUM,vsumB.Y(),1); 
                }
            }

            PsiAB   = PsiA-PsiB;
            if (PsiAB> 180.){ PsiAB-=360; }
            if (PsiAB<-180.){ PsiAB+=360; }

            for(Int_t im=0;im<11;im++){
                if((Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){
                    for(Int_t n=0;n<2;n++){
                        CosPsiAB_META[0][n]->Fill(Mtof+Mrpc,cos((n+1)*phiAB   ),1);
                        CosPsiAB_META[1][n]->Fill(Mtof+Mrpc,cos((n+1)*phiCorAB),1);
                        CosPsiAB_META[2][n]->Fill(Mtof+Mrpc,cos((n+1)*PsiAB   ),1);
                        SinPsiAB_META[0][n]->Fill(Mtof+Mrpc,sin((n+1)*phiAB   ),1);
                        SinPsiAB_META[1][n]->Fill(Mtof+Mrpc,sin((n+1)*phiCorAB),1);
                        SinPsiAB_META[2][n]->Fill(Mtof+Mrpc,sin((n+1)*PsiAB   ),1);

                        CosPsiAB_FW[  0][n]->Fill(nFWspect ,cos((n+1)*phiAB   ),1);
                        CosPsiAB_FW[  1][n]->Fill(nFWspect ,cos((n+1)*phiCorAB),1);
                        CosPsiAB_FW[  2][n]->Fill(nFWspect ,cos((n+1)*PsiAB   ),1);
                        SinPsiAB_FW[  0][n]->Fill(nFWspect ,sin((n+1)*phiAB   ),1);
                        SinPsiAB_FW[  1][n]->Fill(nFWspect ,sin((n+1)*phiCorAB),1);
                        SinPsiAB_FW[  2][n]->Fill(nFWspect ,sin((n+1)*PsiAB   ),1);

                        CosPsi_META[0][n][0]->Fill(Mtof+Mrpc,cos((n+1)*phiA   ),1);
                        CosPsi_META[1][n][0]->Fill(Mtof+Mrpc,cos((n+1)*phiCorA),1);
                        CosPsi_META[2][n][0]->Fill(Mtof+Mrpc,cos((n+1)*PsiA   ),1);
                        SinPsi_META[0][n][0]->Fill(Mtof+Mrpc,sin((n+1)*phiA   ),1);
                        SinPsi_META[1][n][0]->Fill(Mtof+Mrpc,sin((n+1)*phiCorA),1);
                        SinPsi_META[2][n][0]->Fill(Mtof+Mrpc,sin((n+1)*PsiA   ),1);

                        CosPsi_FW[  0][n][0]->Fill(nFWspect ,cos((n+1)*phiA   ),1);
                        CosPsi_FW[  1][n][0]->Fill(nFWspect ,cos((n+1)*phiCorA),1);
                        CosPsi_FW[  2][n][0]->Fill(nFWspect ,cos((n+1)*PsiA   ),1);
                        SinPsi_FW[  0][n][0]->Fill(nFWspect ,sin((n+1)*phiA   ),1);
                        SinPsi_FW[  1][n][0]->Fill(nFWspect ,sin((n+1)*phiCorA),1);
                        SinPsi_FW[  2][n][0]->Fill(nFWspect ,sin((n+1)*PsiA   ),1);

                        CosPsi_META[0][n][1]->Fill(Mtof+Mrpc,cos((n+1)*phiB   ),1);
                        CosPsi_META[1][n][1]->Fill(Mtof+Mrpc,cos((n+1)*phiCorB),1);
                        CosPsi_META[2][n][1]->Fill(Mtof+Mrpc,cos((n+1)*PsiB   ),1);
                        SinPsi_META[0][n][1]->Fill(Mtof+Mrpc,sin((n+1)*phiB   ),1);
                        SinPsi_META[1][n][1]->Fill(Mtof+Mrpc,sin((n+1)*phiCorB),1);
                        SinPsi_META[2][n][1]->Fill(Mtof+Mrpc,sin((n+1)*PsiB   ),1);

                        CosPsi_FW[  0][n][1]->Fill(nFWspect ,cos((n+1)*phiB   ),1);
                        CosPsi_FW[  1][n][1]->Fill(nFWspect ,cos((n+1)*phiCorB),1);
                        CosPsi_FW[  2][n][1]->Fill(nFWspect ,cos((n+1)*PsiB   ),1);
                        SinPsi_FW[  0][n][1]->Fill(nFWspect ,sin((n+1)*phiB   ),1);
                        SinPsi_FW[  1][n][1]->Fill(nFWspect ,sin((n+1)*phiCorB),1);
                        SinPsi_FW[  2][n][1]->Fill(nFWspect ,sin((n+1)*PsiB   ),1);
                    }
                    hMETAvsCent->Fill(im+1,Mtof+Mrpc    );
                    hFWvsCent  ->Fill(im+1,nFWspect     );
                    hMETAvsFW  ->Fill(nFWspect,Mtof+Mrpc);
                }
            }

            h0PhiEPvect->Fill(VectphiEP);
            h0PhiEP->Fill(VectphiEP);
            hPhiCor->Fill(VectphiCorr);
            h0PhiA ->Fill(phiA);
            h0PhiB ->Fill(phiB);
            h0PhiAB->Fill(phiAB);
        }
        wPhiRPA = 1.;
        //-extended-version-introduced-at-09.07.15--which-corresponds-to-META-mult-equivalent-to-numTracking-Glauber--//
        if(NA>1 && NB>1 && Mfw>3){
            hRPA->Fill(VectphiEP);
            for(Int_t im=0;im<11;im++){
                if( (Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1]){ hPhiAB[im]->Fill(fabs(phiAB),wPhiRPA); }
            }
            hRPA6Ywc->Fill(VectphiCorr);
        }
        //-here-we-make-a-control-plot-for-pileup-events--//
        hMfwMmeta->Fill(Mtof+Mrpc, Mfw );
        hMfw     ->Fill(           Mfw );
        hMmeta   ->Fill(Mtof+Mrpc      );
        hMtof    ->Fill(           Mtof);
        hMrpc    ->Fill(           Mrpc);
        //-------------------------------------------iteration-WallHits----( end )--------------------------------------------------//
        
        ////////////////////////////////////////////
        //----getting-ready-to-loop-over-tracks---//
        ////////////////////////////////////////////
        size = candCat->getEntries();
        //note-new-event----------------------------
        //if(par!=0){
            for (Int_t icent=0;icent<NC-4;icent++){
                for (Int_t irpi=0;irpi<NRAPI;irpi++){
                    for (Int_t ipt=0;ipt<NPTRN-5;ipt++){
                        pfy0pt[icent][irpi][ipt].NewEvt();
                        pfR0pt[icent][irpi][ipt].NewEvt();
                        pfF0pt[icent][irpi][ipt].NewEvt();
                        phist[ icent][irpi][ipt].NewEvt();
                    }
                }
            }
        //}
        Ntrack = 0;
        /////////////////////////////////////////////////////
        //--------Now-lets-try-to-get-tracks-----------------
        /////////////////////////////////////////////////////
        for(Int_t j=0;j<size;j++){
            hPartCuts->Fill(1.);
            pParticleCand = HCategoryManager::getObject(pParticleCand,candCat,j);
            if(!pParticleCand->isFlagBit(Particle::kIsUsed)){ continue; }
            hPartCuts->Fill(2.);
            //pidFlag==kFALSE;
            
            sys      = pParticleCand->getSystem();           // sys == 0 - Rpc, sys == 1 - Tof
            mom      = pParticleCand->getMomentum();         //-later-shall-use: getMomentumPID()---(c)-Alexandr
            charge   = pParticleCand->getCharge();
            metaQa   = pParticleCand->getMetaMatchQuality(); 
            beta     = pParticleCand->getBeta();
            theta    = pParticleCand->getTheta();
            phi      = pParticleCand->getPhi();
            chi2     = pParticleCand->getChi2();
            sec      = pParticleCand->getSector();           // sector is the sixth part of the detector
            chi2In   = pParticleCand->getInnerSegmentChi2(); // chi2 of inner segment (mdc 1,2)
            chi2Out  = pParticleCand->getOuterSegmentChi2(); // chi2 of outer segment (mdc 3,4)
            mass2    = pParticleCand->getMass2();            // mass2 = mom*mom*(1-beta*beta)/(beta*beta);
            mass     = pParticleCand->getMass();             // mass  = sqrt(mass2);
            mdcdEdx  = pParticleCand->getMdcdEdx();
            tofdEdx  = pParticleCand->getTofdEdx();
            metaDx   = pParticleCand->getRkMetaDx();         
            metaDy   = pParticleCand->getRkMetaDy();         
            PCr      = pParticleCand->getR();
            PCz      = pParticleCand->getZ();
            hphi    -> Fill(phi);
            dphi     = phi - VectphiEP;
            if (dphi> 180.){dphi = dphi - 360.; }
            if (dphi<-180.){dphi = dphi + 360.; }
            dphiRec  = phi - VectphiCorr;
            if (dphiRec> 180.){dphiRec = dphiRec - 360.; }
            if (dphiRec<-180.){dphiRec = dphiRec + 360.; }
            dphiFlt  = phi - PsiCorr;
            if (dphiFlt> 180.){dphiFlt = dphiFlt - 360.; }
            if (dphiFlt<-180.){dphiFlt = dphiFlt + 360.; }
            // apply track QA cuts
            if (metaQa>2){ continue; }
            hPartCuts->Fill(3.);
            if (mass2 <0){ continue; }
            hPartCuts->Fill(4.);
            //Proton selection
            betaMeanP = fBetaMeanP->Eval(mom);
            hbetaMomAll ->Fill(mom*charge,beta);
            if(charge>0) hBetaMeanP  ->Fill(mom*charge,betaMeanP);
            if(charge>0) hBetaDownP  ->Fill(mom*charge,betaMeanP-0.05);
            if(charge>0) hBetaUpPro  ->Fill(mom*charge,betaMeanP+0.05);
            hdEdxMAll   ->Fill(charge*mass/1000 ,mdcdEdx);
            hdEdxMom    ->Fill(mom*charge,mdcdEdx);
            hfdEdxMomLow->Fill(mom*charge,fdEdxVsMomLowLimit(mom));
            hChi2In     ->Fill(chi2In);
            hChi2Out    ->Fill(chi2Out);
            hChi2       ->Fill(chi2);
            pt0       = mom*sin(theta*hpi/90.); //uncorrected pt
            y0        = (0.5*log((1+beta*cos(theta*hpi/90.))/(1-beta*cos(theta*hpi/90.)))-Ycm)/Ycm; //uncorrected Yo
            rapidity  = y0*Ycm;
            hAccept  -> Fill(rapidity,pt0/1e3);
            for(Int_t i=0;i<11-4;i++){
                for(Int_t j=0;j<9;j++){
                    for(Int_t k=0;k<18-5;k++){
                        if( (Mtof+Mrpc)>=Mrang[i+4] && (Mtof+Mrpc)<Mrang[i+5] && y0>Yrang[j] && y0<Yrang[j+1] && pt0>Prang[k] && pt0<Prang[k+1]){
                            phist[i][j][k].FillMass(mass2/1e6);
                        }
                    }
                }
            }
            if (p.fPID(14, mom,beta,charge)){ hbetaMomPro->Fill(mom*charge,beta); /*pidFlag == kTRUE;*/ }
            if ( mass>600 && mass<1250 && NA>0 && NB>0 && charge>0 && metaQa<5 && chi2<200. && chi2In>0.1 && chi2In<12. && chi2Out>0.1 && chi2Out<12. && sec>=0 && sec<=5 && mdcdEdx>fdEdxVsMomLowLimit(mom)){
                hphiPro     ->Fill(phi);
                hMom        ->Fill(mom*charge);
                hMomCorr    ->Fill(charge*momCorPar->getCorrMom(14,mom,theta));
                PCp         = pParticleCand->getCorrectedMomentumPID(14);
                hMomCorrPID ->Fill(charge*PCp);
                PCpz        = PCp*cos(theta*hpi/90.);
                PCE         = sqrt(mass2Pro + PCp*PCp        );
                PCY         = 0.5*(log((PCE+PCpz)/(PCE-PCpz))); //corrected rapidity for protons
                PCYn        = PCY/(2.*Ycm); //normalized to projectile rapidity Y/Yproj
                PCYo        = (PCY-Ycm)/Ycm; //normalized to projectile rapidity (Y(cm)/Yproj(cm))
                PCpt        = PCp*sin(theta*hpi/90.); //corrected pt
                hAcceptP    ->Fill((PCY-Ycm),PCpt/1e3);
                hPCpt       ->Fill(PCpt);
                hpt0        ->Fill( pt0);
                //---get-track-efficiency-------//
                binX      =   hProtPtVsY_Eff->GetXaxis()->FindBin((Double_t) PCY );  //-Pt:Y-correction--
                binY      =   hProtPtVsY_Eff->GetYaxis()->FindBin((Double_t) PCpt);  //-Pt:Y-correction--
                TrackEff  =   hProtPtVsY_Eff->GetBinContent(binX,binY);
                //------------------------------//

                CENT=-1;
                if( (Mtof+Mrpc)>=163 && (Mtof+Mrpc)<215 ){ CENT = 10; }
                if( (Mtof+Mrpc)>=144 && (Mtof+Mrpc)<163 ){ CENT =  9; }
                if( (Mtof+Mrpc)>=123 && (Mtof+Mrpc)<144 ){ CENT =  8; }
                if( (Mtof+Mrpc)>=103 && (Mtof+Mrpc)<123 ){ CENT =  7; }
                if( (Mtof+Mrpc)>= 85 && (Mtof+Mrpc)<103 ){ CENT =  6; }
                if( (Mtof+Mrpc)>= 72 && (Mtof+Mrpc)< 85 ){ CENT =  5; }
                if( (Mtof+Mrpc)>= 59 && (Mtof+Mrpc)< 72 ){ CENT =  4; }
                if( (Mtof+Mrpc)>= 50 && (Mtof+Mrpc)< 59 ){ CENT =  3; }
                if( (Mtof+Mrpc)>= 39 && (Mtof+Mrpc)< 50 ){ CENT =  2; }
                if( (Mtof+Mrpc)>= 30 && (Mtof+Mrpc)< 39 ){ CENT =  1; }
                if( (Mtof+Mrpc)>= 20 && (Mtof+Mrpc)< 30 ){ CENT =  0; }
                RAPI=-1;
                if( PCYo>-0.9 && PCYo<-0.7 ){ RAPI=0; }
                if( PCYo>-0.7 && PCYo<-0.5 ){ RAPI=1; }
                if( PCYo>-0.5 && PCYo<-0.3 ){ RAPI=2; }
                if( PCYo>-0.3 && PCYo<-0.1 ){ RAPI=3; }
                if( PCYo>-0.1 && PCYo< 0.1 ){ RAPI=4; }
                if( PCYo> 0.1 && PCYo< 0.3 ){ RAPI=5; }
                if( PCYo> 0.3 && PCYo< 0.5 ){ RAPI=6; }
                if( PCYo> 0.5 && PCYo< 0.7 ){ RAPI=7; }
                if( PCYo> 0.7 && PCYo< 0.9 ){ RAPI=8; }
                PTRN=-1;
                if( PCpt> 200 && PCpt< 300 ){ PTRN= 0; }
                if( PCpt> 300 && PCpt< 400 ){ PTRN= 1; }
                if( PCpt> 400 && PCpt< 500 ){ PTRN= 2; }
                if( PCpt> 500 && PCpt< 600 ){ PTRN= 3; }
                if( PCpt> 600 && PCpt< 700 ){ PTRN= 4; }
                if( PCpt> 700 && PCpt< 800 ){ PTRN= 5; }
                if( PCpt> 800 && PCpt< 900 ){ PTRN= 6; }
                if( PCpt> 900 && PCpt<1000 ){ PTRN= 7; }
                if( PCpt>1000 && PCpt<1100 ){ PTRN= 8; }
                if( PCpt>1100 && PCpt<1200 ){ PTRN= 9; }
                if( PCpt>1200 && PCpt<1300 ){ PTRN=10; }
                if( PCpt>1300 && PCpt<1400 ){ PTRN=11; }
                if( PCpt>1400 && PCpt<1500 ){ PTRN=12; }
                if( PCpt>1500 && PCpt<1600 ){ PTRN=13; }
                if( PCpt>1600 && PCpt<1700 ){ PTRN=14; }
                if( PCpt>1700 && PCpt<1800 ){ PTRN=15; }
                if( PCpt>1800 && PCpt<1900 ){ PTRN=16; }
                if( PCpt>1900 && PCpt<2000 ){ PTRN=17; }
                if( CENT>=4 && RAPI>=0 && PTRN>=0 && PTRN<=12 ){
                    pfy0pt[ CENT-4][RAPI][PTRN].Fill(dphi   , fabs(phiAB), VectphiEP  , 1.*TrackEff);
                    pfR0pt[ CENT-4][RAPI][PTRN].Fill(dphiRec, fabs(phiAB), VectphiCorr, 1.*TrackEff);
                    pfF0pt[ CENT-4][RAPI][PTRN].Fill(dphiFlt, fabs(phiAB), PsiCorr    , 1.*TrackEff); 
                    phist[  CENT-4][RAPI][PTRN].Fill(mass2/1e6,phi); 
                    hptvsphi->Fill(PCpt,phi);
                    hptvstheta->Fill(PCpt,theta);
                    hphivstheta->Fill(theta,phi);
                }
            }//end-proton-selection
            //------Now-make-PID----------end----------
            Ntrack++;
        }//j-----Loop-over-entries-----
        hNtrMult->Fill(Ntrack,Mtof+Mrpc);
    }//i-----Loop-over-events----------

    sorter.finalize();

    foutfile->Write();
    foutfile->Close();
  
    return 0;  
}
Esempio n. 3
0
Int_t EventCount(TString inputlist, TString outfile, Int_t nev=-1)
{  

  HLoop* loop = new HLoop   (kTRUE    );  // kTRUE : create Hades  (needed to work with standard eventstructure)
         loop ->addMultFiles(inputlist);

//-----Inicialize-classes-we-need-to-use-----------------
  PidParticle p;
  dEdx        d;
  HMultCorr   cCorr;
//-------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
#include "/u/parfenov/anaflow/EventCountVar.h"     //include all constants and variables we need          
#include "/u/parfenov/anaflow/outsigma.C"          //Declaration of the 3-sigma cuts for our pt & rapidity
TH2F*  hProtPtVsY_Eff;
TFile* foutfile       = new TFile(outfile.Data(), "recreate"); 
TFile* FileProtEff    = new TFile("EffCorrForProtPtVsY_WithWideBetaPcuts_ShieldGosia.root", "read");
       hProtPtVsY_Eff = (TH2F*) FileProtEff->Get("hProtPtVsY_EffSm");
       foutfile->cd();

#include "/u/parfenov/anaflow/EventCountHisto.h"   //include all histograms we need                       

FFlow pfy0pt[NC][NRAPI][NPTRN]; //--flow--9-bins-Yo--12-bins-in-Pt-in-3-centrality-sets--
  for (Int_t i=0; i<NC;i++){
   for(Int_t j=0; j<NRAPI; j++){
     for(Int_t k=0; k<NPTRN; k++){
       //-proton------------------------------------------
       pfy0pt[i][j][k].THDeclare("pCent",i,"Yo",j,"Pt",k);
     }
   }
  }
//--------------------------------------------------------------------------------------------------------

  if(!loop->setInput("-*,+HParticleCand,+HParticleEvtInfo,+HStart2Hit,+HStart2Cal,+HWallHit,+HRpcCluster,+HTofHit,+HWallEventPlane")) { exit(1); }
  loop->printCategories();
  
  TIterator* iterWallHit = 0;
  if (loop->getCategory("HWallHit")  ) iterWallHit   = loop->getCategory("HWallHit")->MakeIterator();
  
  HParticleEvtInfo* evtinfo;
  
  HParticleCand* pParticleCand; HCategory* candCat = (HCategory*)HCategoryManager::getCategory(catParticleCand); if(!candCat){exit(1);}
  HWallHit*      pWallHit;      HCategory* wallCat = (HCategory*)HCategoryManager::getCategory(catWallHit);      if(!wallCat){exit(1);}

  HEnergyLossCorrPar *momCorPar = new HEnergyLossCorrPar();
  momCorPar->setDefaultPar("apr12");
      
  /////////////////////////////////////////////////////////
  //-----Loop-over-events----------------------------------
  /////////////////////////////////////////////////////////
  
  loop->addMultFiles(inputlist);

  Int_t events = loop->getEntries();
  if(nev < events && nev >= 0 ) events = nev;
  
  for (Int_t i=1; i<events;i++){
    
    if (loop->nextEvent(i)<=0){
      cout << "End recieved with IF exit" << endl;
      break;
    }
    if (i%1000 == 0){
      cout << "    event " << i << endl;
    }
    
    if( loop->isNewFile(currFName) ){ 
        currFName = currFName( currFName.Last('/')+1,currFName.Length()-currFName.Last('/')-1 );
        currBeName = currFName(0, 13); //-simply-the-file-name-w/o-EBchunk--
        currFDay = currFName( 4, 3 ); //-we-cut-out-day-number-position-starting-from-4th-digit-with-length-of-3digits--
        DAY_NUM = currFDay.Atoi();
        currTime = currFName( 7, 2 ); //-we-cut-out-day-hour--position-starting-from-4th-digit-with-length-of-3digits--
        HR=currTime.Atoi();
        currTime = currFName( 9, 2 ); //-we-cut-out-day-minute-position-starting-from-4th-digit-with-length-of-3digits--
        MN=currTime.Atoi();
        currTime = currFName(11, 2 ); //-we-cut-out-day-second-position-starting-from-4th-digit-with-length-of-3digits--
        SC=currTime.Atoi();
        AbsMinute = MN + HR*60 + DAY_NUM*24*60;

        #include "/u/parfenov/anaflow/anaKaons_params_gen7_Auto_RC_RW_updated_gen108RminEqZero_11MultRecent.cc" //-for recentering---

        //--Now-we-read-multiplicity-parameters-for-this-beXXXXXXXXXX-file--------------------//
        mulVal = cCorr.getLineValuesAsVectFromCalibFile( currBeName );
        cout<<"mulVal "<< mulVal[0] <<" "<< mulVal[1] <<" "<< mulVal[2] <<" "<< mulVal[3] <<endl;
        fAverageMTS[0]=mulVal[4];  //multiplicity in tracking sector 1
        fAverageMTS[1]=mulVal[5];  //multiplicity in tracking sector 2
        fAverageMTS[2]=mulVal[6];  //...
        fAverageMTS[3]=mulVal[7];
        fAverageMTS[4]=mulVal[8];
        fAverageMTS[5]=mulVal[9];  //multiplicity in tracking sector 6
        printf("fAverageMTS[0,1,2,3,4,5]=[%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,]\n", fAverageMTS[0], fAverageMTS[1], fAverageMTS[2], fAverageMTS[3], fAverageMTS[4], fAverageMTS[5]);
        
        //fTrkMultDay108
        if(mulVal[2]>0.0){
          //-if-correction-is-found-or-if-it-was-not-zero-defined-(in-case-of-not-working-MDCs)---
          fTrkMultScaler = fTrkMultDay108/mulVal[2];
          printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f\n", fTrkMultDay108, mulVal[2], fTrkMultScaler );
        }else{
          //--if-correction-entry-is-not-found-(may-be-not-created-once)------------------
          //--or-if-say-MDCs-were-not-working-and-tracking-multiplicity-was-exectly-zero--
          //-we-keep-correction-as-it-was-in-previous-file-or-if-not-defined-hence-it-would-be-exactly-one=1-or-
          printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f (default or old correction is used)\n", fTrkMultDay108, mulVal[2], fTrkMultScaler);
        }
    }

    HTool::printProgress(i,events,1,"Analyze pairs :");

    evtinfo = HCategoryManager::getObject(evtinfo,catParticleEvtInfo,0);
    
      //-------Get-vertex-from-combined-fit-of-fitted-inner-segments------------
      HVertex            fPrimVertReco = gHades->getCurrentEvent()->getHeader()->getVertexReco();
      vertexX = fPrimVertReco.getX();
      vertexY = fPrimVertReco.getY();
      vertexZ = fPrimVertReco.getZ();
      
      hvertexXZ->Fill(vertexZ,vertexX);
      hvertexXY->Fill(vertexY,vertexX);
      hvertexX ->Fill(vertexX);
      hvertexY ->Fill(vertexY);
      hvertexZ ->Fill(vertexZ);
      
      //------Alexandr's-vertex-cuts---------
      
      tgtChi2 = (Float_t) fPrimVertReco.getChi2();

      hTargChi2->Fill(tgtChi2);


      if( tgtChi2<2.0 || tgtChi2>40.) continue; //-skip-events-with-badly-reconstructed-target-------
      if( vertexZ<-59.|| vertexZ>0. ) continue; //-skip-events-with-primary-vertex-outside-of-target-

      hTargX_EVT->Fill(vertexX);
      hTargY_EVT->Fill(vertexY);
      hTargZ_EVT->Fill(vertexZ);

      if( (vertexX-tgtXc)*(vertexX-tgtXc)+(vertexY-tgtYc)*(vertexY-tgtYc)>R2 ) continue; //-skip-events-with-primary-vertex-far-from-target---
      hCutSteps->Fill(5.5);

      hTargXYsel->Fill(vertexX,vertexY);
      hTargXZsel->Fill(vertexZ,vertexX);
      //---------end-of-Alexandr's-vertex-cut--------------
      
      //------HWall-iteration------------------------------
      if (iterWallHit){
    iterWallHit->Reset();
    HWallHit* pWallHit;
        
    while ( (pWallHit = (HWallHit*)iterWallHit->Next()) != 0 ){
         
         cellNum    = pWallHit->getCell();
             cellTime   = pWallHit->getTime();
             cellCharge = pWallHit->getCharge();
             cellPhi    = pWallHit->getPhi();
         
         hWallHitTIME->Fill(cellNum-0.1, cellTime  );
         hWallHitCHRG->Fill(cellNum-0.1, cellCharge);
         
         if (cellCharge > d.dEdxCut(cellNum)/10. && cellTime > 16. && cellTime < 44.){
           hWallHitTIMEcut->Fill(cellNum-0.1, cellTime  );
           hWallHitCHRGcut->Fill(cellNum-0.1, cellCharge);
         }//end-cut
         
    }//------end-HWall-iteration-----------------------
      }//endif

    if( evtinfo->getSumParticleCandMult()<2 ) continue;  //getSumParticleCandMult()>1
      if(!evtinfo->isGoodEvent(
                               Particle::kGoodVertexClust|
                               Particle::kGoodVertexCand|
                               Particle::kNoPileUpSTART|
                               Particle::kGoodSTART|      
                               Particle::kGoodTRIGGER|    
                               Particle::kNoVETO|         
                               Particle::kGoodSTARTVETO|  
                               Particle::kGoodSTARTMETA
                              )) continue ; // bitwise add flags as suggested by Manuel 
                              
      Mtof = evtinfo->getSumTofMult();
      Mrpc = evtinfo->getSumRpcMult();
      Mult = Mtof+Mrpc;
      
      hmultTofRpc->Fill(Mult);                                   // Fill( name , weight )
      
      
      //---------centrality-classes--------------------------------------------------------------------(begin)--------//
      //-Centrality-selection-for-further-if-selection-statements------------------------//
      Int_t   nTrkMult = getParticleTrkMult();
      Mtr   = nTrkMult;
      Float_t nTrkMultCorr = nTrkMult*fTrkMultScaler;
      MtrC  = nTrkMultCorr; //-after-correction-to-average-day108--

      if( nTrkMultCorr>33 && nTrkMultCorr<=49 ){ FOPI_blue=kTRUE; }else{ FOPI_blue=kFALSE; }        // Berusz's estimate
      if( nTrkMultCorr>49 && nTrkMultCorr<=82 ){ FOPI_gren=kTRUE; }else{ FOPI_gren=kFALSE; }        // based on Glauber model
      if( nTrkMultCorr>82                     ){ FOPI_redd=kTRUE; }else{ FOPI_redd=kFALSE; }        // (lucky me, seems very similar to my naive guess!)--Alexandr-(c)--

      if( FOPI_blue ){ hPhiAB_blue->Fill(fabs(phiAB), wPhiRPA); }
      if( FOPI_gren ){ hPhiAB_gren->Fill(fabs(phiAB), wPhiRPA); }
      if( FOPI_redd ){ hPhiAB_redd->Fill(fabs(phiAB), wPhiRPA); }

      multCand = evtinfo->getSumSelectedParticleCandMult();

      hmultSumSPCand->Fill(multCand);
     
     //--------------------------------------------//
     //--Event plane reconstruction loop-----------//
     //--------------------------------------------// 
      multWall=0;
      cellNum=0;
      cellTime=0.0;
      cellCharge=0.0;
      wallX=0.0,wallY=0.0,wallZ=0.0;
      wallXc=0.0, wallYc=0.0; //corrected-reCentered-
      XfwSmear=0.0, YfwSmear=0.0;
      vect.Set(0.,0.);
      vsum.Set(0.,0.);
      eX  .Set(1.,0.);
      dEdxCut=0.0;
      xyRadius=0.0;
      
      QLx=0.0, QLy=0.0, NL=0; 
      QMx=0.0, QMy=0.0, NM=0;
      QNx=0.0, QNy=0.0, NN=0;

      for(Int_t n=0; n<6; n++){
         Qx[ n]    =0.0; Qy[ n]   =0.0;
         QxRec[n]  =0.0; QyRec[n] =0.0;
         Qax[n]    =0.0; Qay[n]   =0.0;
         Qbx[n]    =0.0; Qby[n]   =0.0;
         phiEP[ n] = -1000.;
         phiEPr[n] = 0.;
      }

      phiA   = -1000;
      phiB   = -1000;
      cellsVect.Reset();
      
      //-weight-for-scalar-product-method-------------------
      wgh = 1.0;  //PCpt; //1.0; //-or-could-be-also-equal-to-Pt---

      nFWhits   = 0;
      nFWspect  = 0;
      nFWunderflow = 0;
      FWdEdxA=0.0;
      FWdEdxB=0.0;

      FWdEdxL=0.0;
      FWdEdxM=0.0;
      FWdEdxN=0.0;

      choiceA = 1; //
      choiceB = 1; // Preparing for A/B subevent method

      //-------------------------------------------iteration-WallHits----(begin)--------------------------------------------------//
      for(Int_t j=0; j<(wallCat->getEntries()); j++){
        pWallHit = HCategoryManager::getObject(pWallHit,wallCat,j);

         cellNum    = pWallHit->getCell();
         cellTime   = pWallHit->getTime();
         cellCharge = pWallHit->getCharge();

         cellChargeCtime = cellTime;
         hFW_TimeCell_0->Fill(cellTime  , cellNum);
         hFW_dEdxCell_0->Fill(cellCharge, cellNum);

         if(cellNum< 144                ){ dEdxCut=Z1_cut_s; }
         if(cellNum>=144 && cellNum<=207){ dEdxCut=Z1_cut_m; }
         if(cellNum> 207                ){ dEdxCut=Z1_cut_l; }

         if(cellTime>T1_cut && cellTime<T2_cut && cellCharge>dEdxCut){
           
           nFWspect++;

           hFW_TimeCell_1->Fill(cellTime  , cellNum);
           hFW_dEdxCell_1->Fill(cellCharge, cellNum);

           pWallHit->getXYZLab(wallX,wallY,wallZ);
           hFWxyCC->Fill(wallX,wallY); //cell centers
           
           for (Int_t im=1;im<12;im++){
            if( (Mtof+Mrpc)>=Mrang[im-1] && (Mtof+Mrpc)<Mrang[im]){ wallXc = wallX - X_shM[12-im]; wallYc = wallY - Y_shM[12-im]; }
           }

           //-here-we-fill-d2N/(dxdy)-inX-band--and--y-band--for-auto-recentering-
           //-this-makes-realistic-distribution-on-FW-face------------------------
           if (cellNum<=143)                 { cellSize = 40;  }
           if (cellNum>=144 && cellNum<=207) { cellSize = 80;  }
           if (cellNum>=210 && cellNum<=301) { cellSize = 160; }
           XfwSmear = wallXc + ( Random.Rndm(1) - 0.5 )*cellSize;
           YfwSmear = wallYc + ( Random.Rndm(1) - 0.5 )*cellSize;

           
           for (Int_t im=0;im<8;im++){
            //-X-beam-center-scan---
            if( (Mtof+Mrpc)>=  Mcent[im] && (Mtof+Mrpc)< Mcent[im+1] ){ hFWxyCCsmearXscanM[im]->Fill(XfwSmear,YfwSmear); }
            //-Y-beam-center-scan---
            if( (Mtof+Mrpc)>=  Mcent[im] && (Mtof+Mrpc)< Mcent[im+1] ){ hFWxyCCsmearYscanM[im]->Fill(XfwSmear,YfwSmear); }
           }


           //-this-cut-was-forgotten-for-Feb2014-HADES-CM-report--//
           //-I-reintroduce-it-14.03.2014----(c)-Sadovsky---------//
           if(  wallXc*wallXc + wallYc*wallYc >= R0_cut*R0_cut  /*50.*50.*/ ){
             hFW_TimeCell_2->Fill(cellTime  , cellNum);
             hFW_dEdxCell_2->Fill(cellCharge, cellNum);


             //-spectators-selected--
             multWall++;

             vect.Set(wallXc, wallYc);
             vect =  vect.Unit();
             vsum += vect;

             //-Qnx-method--for-n=1,2,3,4,5------
             VectPhi_i = TMath::ATan2(YfwSmear,XfwSmear); //-Phi-of-i_th-spectator-particle---
             for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
               Qx[n] = Qx[n] + wgh*cos(double(n)*VectPhi_i);
               Qy[n] = Qy[n] + wgh*sin(double(n)*VectPhi_i);
             }

             cellsVect.SetCellVect(vect, cellCharge); //-note-[vect]-is-a-unit-vector-this-is-for-further-subevent-(A/B)-split--


             hFWxyCCsmear->Fill(XfwSmear+X_shift,YfwSmear+Y_shift); //cells smeared but not shifted
             hFWxySHsmear->Fill(XfwSmear        ,YfwSmear        ); //cells smeared and shifted as a whole

             //-center-of-gravity-study-as-a-course-of-centrality-----------------------------
             for (Int_t im=0;im<8;im++){
              if( (Mtof+Mrpc)>=Mcent[im] && (Mtof+Mrpc)<Mcent[im+1]){ hFWxyCCsmearM[im]->Fill(XfwSmear,YfwSmear); }
             }
             
           }//-endif-R0_cut--//
           
        }//end-if-cells-cut---
     }//end-for-HitWall-loop---

     VectphiEP =  vsum.DeltaPhi(eX)   *rad2deg;
     VectphiEPr=  vsum.DeltaPhi(eX); //radians
     hPhiEPvect->Fill(VectphiEP);

     //-now-we-go-over-spectators-and-make-calculations-for-A/B-subevents
      NA=0;
      NB=0;
      multFWcells = cellsVect.GetNumbOfCells();

      Float_t choice;
      vectA.Set(0.,0.);
      vectB.Set(0.,0.);
      vsumA.Set(0.,0.);
      vsumB.Set(0.,0.);

      for(Int_t ic=0; ic<multFWcells; ic++){
        choice = Random.Rndm(1);
        //-this-is-(A/B)-subevents-split--(begin)-(c)-Sadovsky-----------------------------
        //-I-can-be-proud-that-my-algorithm-has-more-flat-distribution--:)-(c)-Sadovsky----
        levelA = (multFWcells/2.-choiceA+1.)/Float_t(multFWcells);
        levelB = (multFWcells/2.-choiceB+1.)/Float_t(multFWcells);
        if(choice < levelA/(levelA+levelB)){
           vectA = cellsVect.GetCellVector(ic);
           vsumA += vectA;
           choiceA++;
           NA++;
           vsumA += vectA;
           choiceA++;
           NA++;
           VectPhi_i = vectA.DeltaPhi(eX); //-Phi-of-i_th-spectator-particle-from-subevent-A--
           
           for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
              Qax[n] = Qax[n] + wgh*cos(double(n)*VectPhi_i);
              Qay[n] = Qay[n] + wgh*sin(double(n)*VectPhi_i);
           }

           FWdEdxA=FWdEdxA + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
           
        }else{

           vectB = cellsVect.GetCellVector(ic);
           vsumB += vectB;
           choiceB++;
           NB++;
           vectB = cellsVect.GetCellVector(ic);
           vsumB += vectB;
           choiceB++;
           NB++;
           VectPhi_i = vectB.DeltaPhi(eX); //-Phi-of-i_th-spectator-particle-from-subevent-B--
           
           for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
              Qbx[n] = Qbx[n] + wgh*cos(double(n)*VectPhi_i);
              Qby[n] = Qby[n] + wgh*sin(double(n)*VectPhi_i);
           }

           FWdEdxB=FWdEdxB + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
        }//-HWallHit-second-loop-for-reaction-plane-resolution--( end )---//
        //-this-is-(A/B)-subevents-split--( end )------------------------------------------
      }//-endfor-multFWcells-loop--for-A/B-method--

      //-calculating-eventplane-angles---------------
      phiA   = vsumA.DeltaPhi(eX)       *rad2deg;
      phiB   = vsumB.DeltaPhi(eX)       *rad2deg;
      phiAB  = vsumA.DeltaPhi(vsumB)    *rad2deg;
      Mfw = NA+NB;

      if (Mfw > 1){
        for (Int_t n=1;n<6;n++){
            QxRec[n]     = Qx[n] - MeanQx[n];
            QyRec[n]     = Qy[n] - MeanQy[n];
            phiEP[n ]    =  TMath::ATan2(Qy[n],Qx[n])/n       *rad2deg;
            phiEPr[n]    =  TMath::ATan2(Qy[n],Qx[n])/n               ;//radians
            phiEPrec[n]  =  TMath::ATan2(QyRec[n],QxRec[n])/n *rad2deg;
            hPhiEP[n-1]  -> Fill(phiEP[n]);
            hPhiEPrec[n-1]->Fill(phiEPrec[n]);
            hQvX  [n-1]  -> Fill(Qx[n]);
            hQvY  [n-1]  -> Fill(Qy[n]);
            hQvXrec[n-1] -> Fill(QxRec[n]);
            hQvYrec[n-1] -> Fill(QyRec[n]);
        }
        h0PhiEPvect->Fill(VectphiEP);
      }

      if(Mfw>=0){
        h0PhiEP->Fill(VectphiEP);
        h0PhiA ->Fill(phiA);
        h0PhiB ->Fill(phiB);
        h0PhiAB->Fill(phiAB);
      }
      //-extended-version-introduced-at-09.07.15--which-corresponds-to-META-mult-equivalent-to-numTracking-Glauber--//
      if(NA>0 && NB>0){
        hRPA->Fill(VectphiEP);
        for(Int_t im=0;im<11;im++){
            if( (Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1] ){ hRPAy[im] ->Fill(VectphiEP); wPhiRPA = 1./fRPAy[im] ->Eval(VectphiEP); hRPAyc[im] ->Fill(VectphiEP,wPhiRPA); }
        }
        hRPA6Ywc->Fill(VectphiEP,wPhiRPA);
      }

      //-here-we-make-a-control-plot-for-pileup-events--//
      hMfwMmeta->Fill(Mtof+Mrpc, Mfw );
      hMfw     ->Fill(           Mfw );
      hMmeta   ->Fill(Mtof+Mrpc      );
      hMtof    ->Fill(           Mtof);
      hMrpc    ->Fill(           Mrpc);
      
      //-------------------------------------------iteration-WallHits----( end )--------------------------------------------------//


      ////////////////////////////////////////////
      //----getting-ready-to-loop-over-tracks---//
      ////////////////////////////////////////////
                     size = candCat->getEntries();
      Bool_t pimFlag[size];    // pi-
      Bool_t pipFlag[size];    // pi+
      Bool_t proFlag[size];    // proton
      Bool_t kapFlag[size];    // K+ meson        
      
      //note-new-event----------------------------
      for (Int_t icent=0;icent<NC;icent++){
        for (Int_t irpi=0;irpi<NRAPI;irpi++){
            for (Int_t ipt=0;ipt<NPTRN;ipt++){
                pfy0pt[icent][irpi][ipt].NewEvt();
            }
        }
      }   
      
      /////////////////////////////////////////////////////
      //--------Now-lets-try-to-get-tracks-----------------
      /////////////////////////////////////////////////////
      for(Int_t j=0;j<size;j++){
    
    pimFlag[j] = kFALSE;
    pipFlag[j] = kFALSE;
    proFlag[j] = kFALSE;
    kapFlag[j] = kFALSE;
        
    hEntries->Fill(size);
    
    pParticleCand = HCategoryManager::getObject(pParticleCand,candCat,j);
    if(!pParticleCand->isFlagBit(Particle::kIsUsed)) continue;
    
    
    sys      = pParticleCand->getSystem();           // sys == 0 - Rpc, sys == 1 - Tof
    mom      = pParticleCand->getMomentum();         //-later-shall-use: getMomentumPID()---(c)-Alexandr
    charge   = pParticleCand->getCharge();
    metaQa   = pParticleCand->getMetaMatchQuality(); 
    beta     = pParticleCand->getBeta();
    theta    = pParticleCand->getTheta();
    phi      = pParticleCand->getPhi();
    chi2     = pParticleCand->getChi2();
    sec      = pParticleCand->getSector();           // sector is the sixth part of the detector
    chi2In   = pParticleCand->getInnerSegmentChi2(); // chi2 of inner segment
    chi2Out  = pParticleCand->getOuterSegmentChi2(); // chi2 of outer segment
    mass2    = pParticleCand->getMass2();            // mass2 = mom*mom*(1-beta*beta)/(beta*beta);
    mass     = pParticleCand->getMass();             // mass  = sqrt(mass2);
    mdcdEdx  = pParticleCand->getMdcdEdx();
    tofdEdx  = pParticleCand->getTofdEdx();
    metaDx   = pParticleCand->getRkMetaDx();         
    metaDy   = pParticleCand->getRkMetaDy();         
    
    PCr              = pParticleCand->getR();
        PCz              = pParticleCand->getZ();
    
    pz       = mom*cos(theta*hpi/90.)/1000;
    pt0      = mom*sin(theta*hpi/90.)/1000;
    px       = pt0*cos(phi*hpi/90.);
    py       = pt0*sin(phi*hpi/90.);
    
    rapid    = 0.5*TMath::Log((1+beta)/(1-beta));
    eta      =    -TMath::Log(tan(theta/2));
    
    betaL    = beta*cos(theta*hpi/90.);
    rapidity = 0.5*TMath::Log((1+betaL)/(1-betaL));
    Y0       = (rapidity - Ycm)/Ycm;
    dphi     = phi - VectphiEP;
    if (dphi>180.){dphi = dphi - 360.; }
    if (dphi<-180.){dphi = dphi + 360.; }

    hPhi->Fill(phi);
    
        // apply track QA cuts
        if (metaQa>2) continue;
    if (mass2 <0) continue;
    
    hRapidity->Fill(rapidity);
    
    hM2fromM->Fill(mass);
    
    hCharge->Fill(charge);
    
     //-Tetiana's-plots-----------
           hChi2       ->Fill(chi2);
           hChi2In     ->Fill(chi2In);
           hChi2Out    ->Fill(chi2Out);
           //Fill Theta vs Phi Plots
           hthetaPhiAll->Fill(phi,theta);
           //Fill Beta vs Momentum
           hbetaMomAll ->Fill(mom*charge,beta);
           hmommassAll ->Fill(charge*mass,mom);
       
       hsys    ->Fill(sys);
       hmom    ->Fill(mom);
       hmetaQa ->Fill(metaQa);
       hsec    ->Fill(sec);
       hmdcdEdx->Fill(mdcdEdx);
       htofdEdx->Fill(tofdEdx);
       hmetaDx ->Fill(metaDx);
       hmetaDy ->Fill(metaDy);
       hPCr    ->Fill(PCr);
       hPCz    ->Fill(PCz);
       
       hpx     ->Fill(px);
       hpy     ->Fill(py);
       hpz     ->Fill(pz);
       hpt     ->Fill(pt);
       
       hdEdxMAll->Fill(mass/1000,mdcdEdx);
       
       
       //------Now-make-PID-------begin-----------
       
       pimFlag[j] = p.fPID(9, mom,beta,charge);
       pipFlag[j] = p.fPID(8, mom,beta,charge);
       kapFlag[j] = p.fPID(11,mom,beta,charge);
       proFlag[j] = p.fPID(14,mom,beta,charge);
       
       //fill-particle-numeration-integral-----------------------------------------------------
                                      hmassAll->Fill(charge*mass2/1000000);
       if (pipFlag[j] == kTRUE && mdcdEdx < 5) {
         hPIDPip ->Fill(charge*mass2/1000000); 
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass( 8));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPip->Fill(y);
         hRPIDPip->Fill(rapidity);
         npip++;
      } // pi+    selection (Pip);
       if (pimFlag[j] == kTRUE && mdcdEdx < 5) {
         hPIDPim ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass( 9));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPim->Fill(y);
         hRPIDPim->Fill(rapidity);
         npim++;
      } // pi-    selection (Pim);
       if (kapFlag[j] == kTRUE && mdcdEdx < 5) { 
         hPIDKap ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass(11));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDKap->Fill(y);
         hRPIDKap->Fill(rapidity);
         nkap++;
      } // K+     selection (Kap);
       if (proFlag[j] == kTRUE && mdcdEdx < 5) { 
         hPIDPro ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass(14));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPro->Fill(y);
         hRPIDPro->Fill(rapidity);
         npro++;
      } // proton selection (Pro);
       //--------------------------------------------------------------------------------------
           
       for (Int_t ipt=0; ipt<npt-1;ipt++){
        
         if (pt0>binpt[ipt] && pt0<binpt[ipt+1]){
                                    hM2Y   [ipt]->Fill(charge*mass2/1000000,rapidity);
         if (pipFlag[j] == kTRUE) { hM2YPip[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (pimFlag[j] == kTRUE) { hM2YPim[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (kapFlag[j] == kTRUE) { hM2YKap[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (proFlag[j] == kTRUE) { hM2YPro[ipt]->Fill(charge*mass2/1000000,rapidity); }
         }
         
         for (Int_t irpdt=0; irpdt<nrpdt-1;irpdt++){
           if (pt0>binpt[ipt] && pt0<binpt[ipt+1] && rapidity>binrpdt[irpdt] && rapidity<binrpdt[irpdt+1]){
         if (                                                                                                       mdcdEdx < 5) { hM2   [ipt][irpdt]->Fill( charge*mass2/1000000);}
             
         if (pipFlag[j] == kTRUE && mass2/1e6<=mass2Pip+sPip[ipt][irpdt] && mass2/1e6>=mass2Pip-sPip[ipt][irpdt] && mdcdEdx < 5) { hM2Pip[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (pimFlag[j] == kTRUE && mass2/1e6<=mass2Pim+sPim[ipt][irpdt] && mass2/1e6>=mass2Pim-sPim[ipt][irpdt] && mdcdEdx < 5) { hM2Pim[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (kapFlag[j] == kTRUE && mass2/1e6<=mass2Kap+sKap[ipt][irpdt] && mass2/1e6>=mass2Kap-sKap[ipt][irpdt] && mdcdEdx < 5) { hM2Kap[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (proFlag[j] == kTRUE && mass2/1e6<=mass2Pro+sPro[ipt][irpdt] && mass2/1e6>=mass2Pro-sPro[ipt][irpdt] && mdcdEdx < 5) { hM2P  [ipt][irpdt]->Fill( charge*mass2/1000000);} 
         
         hdEdxMass[ipt][irpdt]->Fill(charge*mass/1000,mdcdEdx);
         
           }//endif
         }//irpdt
       }//ipt

        for (Int_t ipt=0; ipt<npt-1;ipt++){
        
         if (pt0>binpt[ipt] && pt0<binpt[ipt+1] && (rapidity-Ycm)>=-Ycm && (rapidity-Ycm)<=Ycm){
          v2            = cos(2*((phi-180-VectphiEP)*hpi/90.));
          v2sum [ipt]  += v2;
          ncount[ipt]++;
          hv2phi[ipt]->Fill((phi-180-VectphiEP),v2,wgh);

          hNphi [ipt]->Fill((phi-180-VectphiEP),wgh);
         }
        }
        
        if (mass>600 && mass<1250 && NA>0 && NB>0 && charge>0 && metaQa<5 && chi2<200. && chi2In>0.1 && chi2In<12. && chi2Out>0.1 && chi2Out<12. && sec>=0 && sec<=5 && mdcdEdx>fdEdxVsMomLowLimit(mom)){

            PCp     = pParticleCand->getCorrectedMomentumPID(14);
            PCpz      = PCp*cos(theta*hpi/90.);

            PCE     = sqrt(938.272*938.272 + PCp*PCp );
            PCY     = 0.5*(log((PCE+PCpz)/(PCE-PCpz))); //corrected rapidity for protons
            PCYn    = PCY/(2.*Ycm); //normalized to projectile rapidity Y/Yproj
            PCYo    = (PCY-Ycm)/Ycm; //normalized to projectile rapidity (Y(cm)/Yproj(cm))
            PCpt    = PCp*sin(theta*hpi/90.); //corrected pt

            //---get-track-efficiency-------//
            binX     =   hProtPtVsY_Eff->GetXaxis()->FindBin((Double_t) rapidity );  //-Pt:Y-correction--
            binY     =   hProtPtVsY_Eff->GetYaxis()->FindBin((Double_t) PCpt );  //-Pt:Y-correction--
            TrackEff =   hProtPtVsY_Eff->GetBinContent(binX,binY);
            //------------------------------//
            for (Int_t n=1; n<6; n++){
                hPhiEPc[n-1]->Fill(phiEP[n],wgh*TrackEff);
            }

            CENT=-1;
            if( FOPI_redd ){ CENT=0; }
            if( FOPI_gren ){ CENT=1; }
            if( FOPI_blue ){ CENT=2; }
            RAPI=-1;
            if( PCYo>-0.9 && PCYo<-0.7 ){ RAPI=0; }
            if( PCYo>-0.7 && PCYo<-0.5 ){ RAPI=1; }
            if( PCYo>-0.5 && PCYo<-0.3 ){ RAPI=2; }
            if( PCYo>-0.3 && PCYo<-0.1 ){ RAPI=3; }
            if( PCYo>-0.1 && PCYo< 0.1 ){ RAPI=4; }
            if( PCYo> 0.1 && PCYo< 0.3 ){ RAPI=5; }
            if( PCYo> 0.3 && PCYo< 0.5 ){ RAPI=6; }
            if( PCYo> 0.5 && PCYo< 0.7 ){ RAPI=7; }
            if( PCYo> 0.7 && PCYo< 0.9 ){ RAPI=8; }
            PTRN=-1;
            if( PCpt> 200 && PCpt< 300 ){ PTRN= 0; }
            if( PCpt> 300 && PCpt< 400 ){ PTRN= 1; }
            if( PCpt> 400 && PCpt< 500 ){ PTRN= 2; }
            if( PCpt> 500 && PCpt< 600 ){ PTRN= 3; }
            if( PCpt> 600 && PCpt< 700 ){ PTRN= 4; }
            if( PCpt> 700 && PCpt< 800 ){ PTRN= 5; }
            if( PCpt> 800 && PCpt< 900 ){ PTRN= 6; }
            if( PCpt> 900 && PCpt<1000 ){ PTRN= 7; }
            if( PCpt>1000 && PCpt<1100 ){ PTRN= 8; }
            if( PCpt>1100 && PCpt<1200 ){ PTRN= 9; }
            if( PCpt>1200 && PCpt<1300 ){ PTRN=10; }
            if( PCpt>1300 && PCpt<1400 ){ PTRN=11; }
            if( PCpt>1400 && PCpt<1500 ){ PTRN=12; }
            if( PCpt>1500 && PCpt<1600 ){ PTRN=13; }
            if( PCpt>1600 && PCpt<1700 ){ PTRN=14; }
            if( PCpt>1700 && PCpt<1800 ){ PTRN=15; }
            if( PCpt>1800 && PCpt<1900 ){ PTRN=16; }
            if( PCpt>1900 && PCpt<2000 ){ PTRN=17; }
            if( CENT>=0 && RAPI>=0 && PTRN>=0 ){
                   pfy0pt[CENT][RAPI][PTRN].Fill(dphi, fabs(phiAB), VectphiEP, wgh*TrackEff);
                 }
        }
        
       
       //------Now-make-PID----------end----------
       
      }//j-----Loop-over-entries-----

  }//i-----Loop-over-events----------

  for (Int_t i=0;i<npt-1;i++){
        v2x[i] = binpt[i] + 0.5*(binpt[i+1]-binpt[i]);
        v2w[i] = hv2phi[i]->GetMean(2);
        hv2   -> Fill(v2x[i],v2w[i]);
  }

  Float_t yPID [4] = {hyPIDPim->GetMean(), hyPIDPip->GetMean(), hyPIDKap->GetMean(), hyPIDPro->GetMean()};
  Float_t ybet [4] = {hRPIDPim->GetMean(), hRPIDPip->GetMean(), hRPIDKap->GetMean(), hRPIDPro->GetMean()};
  Float_t dyPID[4] = {hyPIDPim->GetRMS() , hyPIDPip->GetRMS() , hyPIDKap->GetRMS() , hyPIDPro->GetRMS() };
  Float_t dybet[4] = {hRPIDPim->GetRMS() , hRPIDPip->GetRMS() , hRPIDKap->GetRMS() , hRPIDPro->GetRMS() };
  Float_t dy   [4];
  Float_t MeanY = 0.0;
  for (Int_t i=0;i<4;i++){
    dy[i] = 0.5*sqrt(ybet[i]*ybet[i]*dyPID[i]*dyPID[i]+yPID[i]*yPID[i]*dybet[i]*dybet[i])/(ybet[i]*ybet[i]);
    MeanY+=yPID[i]/ybet[i];
  }
  MeanY = MeanY/4;
  
  for (Int_t i=0;i<4;i++){
    hyvsPID ->Fill(i+0.5,yPID[i]/ybet[i]);
    hnormPID->Fill(i+0.5,MeanY);
  }
  
  foutfile->Write();
  foutfile->Close();
  
  return 0;
  
}