+ // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
+ if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
+
+ Bool_t okd = kFALSE;
+
+ Int_t pdg = 22;
+ Int_t iphcand = -1;
+ for (i=0; i< np; i++) {
+ TParticle* iparticle = (TParticle *) fParticles.At(i);
+ Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
+ Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
+
+ if(iparticle->GetStatusCode() == 1
+ && iparticle->GetPdgCode() == pdg
+ && iparticle->Pt() > fPhotonMinPt
+ && eta < fPHOSEta){
+
+ // first check if the photon is in PHOS phi
+ if(IsInPHOS(phi,eta)){
+ okd = kTRUE;
+ break;
+ }
+ if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
+
+ }
+ }
+
+ if(!okd && iphcand != -1) // execute rotation in phi
+ RotatePhi(iphcand,okd);
+
+ if(!okd)
+ return 0;
+ }
+
+ if (fTriggerParticle) {
+ Bool_t triggered = kFALSE;
+ for (i = 0; i < np; i++) {
+ TParticle * iparticle = (TParticle *) fParticles.At(i);
+ kf = CheckPDGCode(iparticle->GetPdgCode());
+ if (kf != fTriggerParticle) continue;
+ if (iparticle->Pt() == 0.) continue;
+ if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
+ triggered = kTRUE;
+ break;
+ }
+ if (!triggered) {
+ delete [] pParent;
+ return 0;
+ }
+ }
+
+
+ // Check if there is a ccbar or bbbar pair with at least one of the two
+ // in fYMin < y < fYMax
+
+ if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi || fProcess == kPyBeautyJets) {
+ TParticle *partCheck;
+ TParticle *mother;
+ Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
+ Bool_t theChild=kFALSE;
+ Float_t y;
+ Int_t pdg,mpdg,mpdgUpperFamily;
+ for(i=0; i<np; i++) {
+ partCheck = (TParticle*)fParticles.At(i);
+ pdg = partCheck->GetPdgCode();
+ if(TMath::Abs(pdg) == fFlavorSelect) { // quark
+ if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
+ y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
+ (partCheck->Energy()-partCheck->Pz()+1.e-13));
+ if(y>fYMin && y<fYMax) inYcut=kTRUE;
+ }
+ if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
+ Int_t mi = partCheck->GetFirstMother() - 1;
+ if(mi<0) continue;
+ mother = (TParticle*)fParticles.At(mi);
+ mpdg=TMath::Abs(mother->GetPdgCode());
+ mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
+ if ( ParentSelected(mpdg) ||
+ (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
+ if (KinematicSelection(partCheck,1)) {
+ theChild=kTRUE;
+ }
+ }
+ }
+ }
+ if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
+ delete[] pParent;
+ return 0;
+ }
+ if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
+ delete[] pParent;
+ return 0;
+ }
+
+ }
+
+ //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
+ if ( (fProcess == kPyW ||
+ fProcess == kPyZ ||
+ fProcess == kPyMbDefault ||
+ fProcess == kPyMb ||
+ fProcess == kPyMbAtlasTuneMC09 ||
+ fProcess == kPyMbWithDirectPhoton ||
+ fProcess == kPyMbNonDiffr)
+ && (fCutOnChild == 1) ) {
+ if ( !CheckKinematicsOnChild() ) {
+ delete[] pParent;
+ return 0;
+ }
+ }
+
+
+ for (i = 0; i < np; i++) {