]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - THerwig/AliGenHerwig.cxx
Completely reengineered version of CMake build system (Johny)
[u/mrichter/AliRoot.git] / THerwig / AliGenHerwig.cxx
index 4a75ccd6ddbe0af13107c1e0e751e9836b545ff3..d6d2f76dcb1c3611a39eefd214861f006d3ed077 100644 (file)
 // The main Herwig options are accessable for the user through this interface.
 // Uses the THerwig implementation of TGenerator.
 
-#include "AliGenHerwig.h"
-#include "AliHerwigRndm.h"
-#include "AliRun.h"
 
+#include <Riostream.h>
+#include <TClonesArray.h>
 #include <TParticle.h>
-#include "THerwig6.h"
 
-#include "Riostream.h"
-#include "AliMC.h"
+#include <THerwig6.h>
 
+#include "AliGenHerwig.h"
+#include "AliGenHerwigEventHeader.h"
+#include "AliHerwigRndm.h"
+#include "AliMC.h"
+#include "AliRun.h"
 #include "driver.h"
 
 ClassImp(AliGenHerwig)
@@ -45,7 +47,6 @@ ClassImp(AliGenHerwig)
     fTrigger(0),
     fSelectAll(0),
     fFlavor(0),
-    fEnergyCMS(14000),
     fMomentum1(7000),
     fMomentum2(7000),
     fKineBias(1),
@@ -54,15 +55,26 @@ ClassImp(AliGenHerwig)
     fHerwig(0x0),
     fProcess(0),
     fPtHardMin(0.),
+    fPtHardMax(9999.),
     fPtRMS(0.),
     fMaxPr(10),
     fMaxErrors(1000),
     fEnSoft(1),
     fEv1Pr(0),
     fEv2Pr(0),
-    fFileName(0)
+    fFileName(0),
+    fEtaMinParton(-20.),     
+    fEtaMaxParton(20.),     
+    fPhiMinParton(0.),     
+    fPhiMaxParton(2.* TMath::Pi()),     
+    fEtaMinGamma(-20.),      
+    fEtaMaxGamma(20.),      
+    fPhiMinGamma(0.),      
+    fPhiMaxGamma(2. * TMath::Pi()),
+    fHeader(0)
 {
 // Constructor
+  fEnergyCMS = 14000;
 }
 
 AliGenHerwig::AliGenHerwig(Int_t npart)
@@ -75,7 +87,6 @@ AliGenHerwig::AliGenHerwig(Int_t npart)
     fTrigger(0),
     fSelectAll(0),
     fFlavor(0),
-    fEnergyCMS(14000),
     fMomentum1(7000),
     fMomentum2(7000),
     fKineBias(1),
@@ -84,14 +95,25 @@ AliGenHerwig::AliGenHerwig(Int_t npart)
     fHerwig(0x0),
     fProcess(0),
     fPtHardMin(0.),
+    fPtHardMax(9999.),
     fPtRMS(0.),
     fMaxPr(10),
     fMaxErrors(1000),
     fEnSoft(1),
     fEv1Pr(0),
     fEv2Pr(0),
-    fFileName(0)
+    fFileName(0),
+    fEtaMinParton(-20.),     
+    fEtaMaxParton(20.),     
+    fPhiMinParton(0.),     
+    fPhiMaxParton(2.* TMath::Pi()),     
+    fEtaMinGamma(-20.),      
+    fEtaMaxGamma(20.),      
+    fPhiMinGamma(0.),
+    fPhiMaxGamma(2. * TMath::Pi()),
+    fHeader(0)
 {
+    fEnergyCMS = 14000;
     SetTarget();
     SetProjectile();
     // Set random number generator
@@ -105,8 +127,8 @@ AliGenHerwig::~AliGenHerwig()
 
 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
 {
-  fEv1Pr = ++eventFirst;
-  fEv2Pr = ++eventLast;
+  fEv1Pr = eventFirst;
+  fEv2Pr = eventLast;
   if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
 }
 
@@ -118,18 +140,15 @@ void AliGenHerwig::Init()
   SetMC(new THerwig6());
   fHerwig=(THerwig6*) fMCEvGen;
   // initialize common blocks
-  fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
+  fHerwig->Initialize(fProjectile.Data(), fTarget.Data(), fMomentum1, fMomentum2, fProcess); // 
   // reset parameters according to user needs
   InitPDF();
   fHerwig->SetPTMIN(fPtHardMin);
+  fHerwig->SetPTMAX(fPtHardMax);
   fHerwig->SetPTRMS(fPtRMS);
   fHerwig->SetMAXPR(fMaxPr);
   fHerwig->SetMAXER(fMaxErrors);
   fHerwig->SetENSOF(fEnSoft);
-
-  fHerwig->SetEV1PR(fEv1Pr);
-  fHerwig->SetEV2PR(fEv2Pr);
-
 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
 //       RMASS(1)=0.32
 //       RMASS(2)=0.32
@@ -144,7 +163,7 @@ void AliGenHerwig::Init()
 
   if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
 
-  fHerwig->Hwusta("PI0     ");
+  //fHerwig->Hwusta("PI0     ");
 
   // compute parameter dependent constants
   fHerwig->PrepareRun();
@@ -167,9 +186,6 @@ void AliGenHerwig::InitJimmy()
   fHerwig->SetMAXER(fMaxErrors);
   fHerwig->SetENSOF(fEnSoft);
 
-  fHerwig->SetEV1PR(fEv1Pr);
-  fHerwig->SetEV2PR(fEv2Pr);
-
 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
 //       RMASS(1)=0.32
 //       RMASS(2)=0.32
@@ -184,7 +200,7 @@ void AliGenHerwig::InitJimmy()
 
   if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
 
-  fHerwig->Hwusta("PI0     ");
+  //  fHerwig->Hwusta("PI0     ");
 
   // compute parameter dependent constants
   fHerwig->PrepareRunJimmy();
@@ -254,10 +270,9 @@ void AliGenHerwig::Generate()
 {
   // Generate one event
 
-  Float_t polar[3] =   {0,0,0};
-  Float_t origin[3]=   {0,0,0};
-  Float_t origin0[3]=  {0,0,0};
-  Float_t p[4], random[6];
+  Float_t polar[3]  =   {0,0,0};
+  Float_t origin[3] =   {0,0,0};
+  Float_t p[4];
 
   static TClonesArray *particles;
   //  converts from mm/c to s
@@ -265,20 +280,15 @@ void AliGenHerwig::Generate()
   //
   Int_t nt=0;
   Int_t jev=0;
-  Int_t j, kf, ks, imo;
+  Int_t kf, ks, imo;
   kf=0;
 
   if(!particles) particles=new TClonesArray("TParticle",10000);
 
   fTrials=0;
-  for (j=0;j<3;j++) origin0[j]=fOrigin[j];
-  if(fVertexSmear==kPerEvent) {
-    Rndm(random,6);
-    for (j=0;j<3;j++) {
-      origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
-       TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
-    }
-  }
+
+  //  Set collision vertex position 
+  if (fVertexSmear == kPerEvent) Vertex();
 
   while(1)
     {
@@ -288,8 +298,25 @@ void AliGenHerwig::Generate()
        Int_t np = particles->GetEntriesFast()-1;
        if (np == 0 ) continue;
 
-       Int_t nc=0;
+       //Check hard partons or direct gamma in kine range
+
+       if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
+           TParticle* parton1 = (TParticle *) particles->At(6);
+           TParticle* parton2 = (TParticle *) particles->At(7);
+           if (!CheckParton(parton1, parton2))  continue ;
+       } 
 
+       // 
+       if (gAlice) {
+           if (gAlice->GetEvNumber()>=fEv1Pr &&
+               gAlice->GetEvNumber()<=fEv2Pr) fHerwig->PrintEvt();
+
+       }
+
+       
+       Int_t nc = 0;
+       fNprimaries = 0;
+       
        Int_t * newPos = new Int_t[np];
        for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
 
@@ -306,9 +333,11 @@ void AliGenHerwig::Generate()
                p[1]=iparticle->Py();
                p[2]=iparticle->Pz();
                p[3]=iparticle->Energy();
-               origin[0]=origin0[0]+iparticle->Vx()/10;
-               origin[1]=origin0[1]+iparticle->Vy()/10;
-               origin[2]=origin0[2]+iparticle->Vz()/10;
+
+               origin[0] = fVertex[0] + iparticle->Vx()/10; // [cm]
+               origin[1] = fVertex[1] + iparticle->Vy()/10; // [cm]
+               origin[2] = fVertex[2] + iparticle->Vz()/10; // [cm]
+
                Float_t tof = kconv*iparticle->T();
                Int_t   iparent = (imo > -1) ? newPos[imo] : -1;
                Int_t   trackIt = (ks == 1) && fTrackIt;
@@ -320,10 +349,10 @@ void AliGenHerwig::Generate()
                          kPPrimary, nt, fHerwig->GetEVWGT(), ks);
                KeepTrack(nt);
                newPos[i]=nt;
+               fNprimaries++;
            } // end of if: selection of particle
        } // end of for: particle loop
        if (newPos) delete[] newPos;
-       //      MakeHeader();
        if (nc > 0) {
            jev+=nc;
            if (jev >= fNpart || fNpart == -1) {
@@ -332,11 +361,61 @@ void AliGenHerwig::Generate()
            }
        }
     }
+//
+  MakeHeader();
+//  
   SetHighWaterMark(nt);
 //  adjust weight due to kinematic selection
   AdjustWeights();
 //  get cross-section
   fXsection=fHerwig->GetAVWGT();
+  //printf(">> trials << %d\n",fTrials);
+}
+
+Bool_t AliGenHerwig::CheckParton(TParticle* parton1, TParticle* parton2)
+{
+// Check the kinematic trigger condition
+//
+//Select events with parton max energy
+    if(fPtHardMax < parton1->Pt()) return kFALSE;
+
+// Select events within angular window
+    Double_t eta[2];
+    eta[0] = parton1->Eta();
+    eta[1] = parton2->Eta();
+    Double_t phi[2];
+    phi[0] = parton1->Phi();
+    phi[1] = parton2->Phi();
+    Int_t    pdg[2]; 
+    pdg[0] = parton1->GetPdgCode();
+    pdg[1] = parton2->GetPdgCode();   
+    printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
+    printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
+    printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
+    
+    if (fProcess == kHeJets) {
+      //Check if one of the 2 outgoing partons are in the eta-phi window
+      for(Int_t i = 0; i < 2; i++)
+       if ((eta[i] < fEtaMaxParton  && eta[i] > fEtaMinParton) &&
+           (phi[i] < fPhiMaxParton  && phi[i] > fPhiMinParton)) return  kTRUE ;
+    }
+    
+    else {
+      //Check if the gamma and the jet  are in the eta-phi window
+      Int_t igj = 0;
+      Int_t ijj = 0;
+      if(pdg[0] == 22) ijj=1;
+      else igj=1;
+      if ((eta[ijj] < fEtaMaxParton   && eta[ijj] > fEtaMinParton) &&
+         (phi[ijj] < fPhiMaxParton   && phi[ijj] > fPhiMinParton)) {
+       
+       if ((eta[igj] < fEtaMaxGamma   && eta[igj] > fEtaMinGamma) &&
+           (phi[igj] < fPhiMaxGamma   && phi[igj] > fPhiMinGamma)) return  kTRUE;
+       
+      }
+    }
+
+    return kFALSE ;
 }
 
 void AliGenHerwig::AdjustWeights()
@@ -426,3 +505,29 @@ void AliGenHerwig::FinishRunJimmy()
 
 }
 
+
+void AliGenHerwig::MakeHeader()
+{
+//
+// Make header for the simulated event
+// 
+  if (fHeader) delete fHeader;
+  fHeader = new AliGenHerwigEventHeader("Herwig");
+//
+// Event type  
+    ((AliGenHerwigEventHeader*) fHeader)->SetProcessType(fHerwig->GetIHPRO());
+//
+// Number of trials
+    ((AliGenHerwigEventHeader*) fHeader)->SetTrials(fTrials);
+//
+// Event Vertex 
+    fHeader->SetPrimaryVertex(fVertex);
+    
+//
+// Number of primaries
+    fHeader->SetNProduced(fNprimaries);
+//  Pass header
+//
+    AddHeader(fHeader);
+    fHeader = 0x0;  
+}