Added file check.
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReaderKine.cxx
index 218336edab2b02d8aadedc2364178e6daf107f83..1fb6b9533d74637743b8e935fcf250fdfb0ca44d 100644 (file)
 /////////////////////////////////////////////////////////////////////////
 
 #include <Riostream.h>
+#include <TFile.h>
 #include <TString.h>
 #include <TParticle.h>
+#include <TLorentzVector.h>
 #include <AliRunLoader.h>
 #include <AliStack.h>
-
+#include <AliHeader.h>
+#include <AliGenEventHeader.h>
+#include <AliGenPythiaEventHeader.h>
+#include <AliGenHijingEventHeader.h>
 #include "AliJetParticle.h"
 #include "AliJetEventParticles.h"
 #include "AliJetParticlesReaderKine.h"
-#include "AliHeader.h"
-#include "AliGenPythiaEventHeader.h"
 
 ClassImp(AliJetParticlesReaderKine)
 
@@ -114,46 +117,91 @@ Int_t AliJetParticlesReaderKine::ReadNext()
       fEventParticles->Reset(npart);
 
       TString headdesc="";
+      Int_t gentype=-1;
       AliHeader *header=fRunLoader->GetHeader();
       if(!header) {
        Warning("ReadNext","Header not found in event %d",fCurrentEvent);
       } else {
-       headdesc+="Run ";
-       headdesc+=header->GetRun();
-       headdesc+=": Ev ";
-       headdesc+=header->GetEventNrInRun();
-       AliGenPythiaEventHeader *pheader=(AliGenPythiaEventHeader*)header->GenEventHeader();
-       if(!pheader) {
-         Warning("ReadNext","Pythia-Header not found in event %d",fCurrentEvent);
-       } else {
-         Int_t ntruq=pheader->NUQTriggerJets();
-         if(ntruq){
-           Double_t x0=pheader->GetXJet();
-           Double_t y0=pheader->GetYJet();
-           Double_t zquench[4];
-           pheader->GetZQuench(zquench);
-           fEventParticles->SetXYJet(x0,y0);
-           fEventParticles->SetZQuench(zquench);
-           for(Int_t j=0;j<ntruq;j++){
-             Float_t pjet[4];
-             pheader->UQJet(j,pjet);
-             fEventParticles->AddUQJet(pjet);
-           }
+       AliGenEventHeader *genheader=header->GenEventHeader();
+       TString hname=genheader->GetName();
+       if(hname.CompareTo("HIJINGparam")==0) {
+         gentype=1;      ;
+         headdesc+="HIJINGparam";
+       } else if(hname.CompareTo("Hijing")==0) {
+         gentype=2;
+         AliGenHijingEventHeader *hheader=(AliGenHijingEventHeader*)header->GenEventHeader();
+         headdesc+="Hijing";
+         if(!hheader) {
+           Warning("ReadNext","Hijing-Header not found in event %d",fCurrentEvent);
+         } else {
+           Int_t ntrials=hheader->Trials();
+           fEventParticles->SetTrials(ntrials);
+           fEventParticles->SetImpact(hheader->ImpactParameter());
+           fEventParticles->SetNhard(hheader->HardScatters());
+           fEventParticles->SetNpart(hheader->NwNw());
+
+           TLorentzVector  jet1; 
+           TLorentzVector  jet2; 
+           TLorentzVector  jetFsr1;
+           TLorentzVector  jetFsr2;
+           hheader->GetJets(jet1,jet2,jetFsr1,jetFsr2);
+           fEventParticles->AddHard(0,jet1.X(),jet1.Y(),jet1.Z(),jet1.T(),0);
+           fEventParticles->AddHard(1,jet2.X(),jet2.Y(),jet2.Z(),jet2.T(),0);
          }
-         //Int_t ptyp=pheader->ProcessType();
-         Int_t ntrials=pheader->Trials();
-         headdesc+=": Tr ";
-         headdesc+=ntrials;
-         Int_t ntr=pheader->NTriggerJets();
-         if(ntr){
-           for(Int_t j=0;j<ntr;j++){
-             Float_t pjet[4];
-             pheader->TriggerJet(j,pjet);
-             fEventParticles->AddJet(pjet);
-             if(!ntruq) fEventParticles->AddUQJet(pjet);
+       } else if(hname.CompareTo("Pythia")==0){
+         gentype=3;
+         headdesc+="Pythia";
+         AliGenPythiaEventHeader *pheader=(AliGenPythiaEventHeader*)header->GenEventHeader();
+         if(!pheader) {
+           Warning("ReadNext","Pythia-Header not found in event %d",fCurrentEvent);
+         } else {
+           Int_t ntruq=0;
+#ifndef NOUQHEADERINFO
+           ntruq=pheader->NUQTriggerJets();
+           if(ntruq){
+             Double_t x0=pheader->GetXJet();
+             Double_t y0=pheader->GetYJet();
+             if(x0==y0==-1){
+               x0=y0=0.;
+             }
+             Double_t zquench[4];
+             pheader->GetZQuench(zquench);
+             fEventParticles->SetXYJet(x0,y0);
+             fEventParticles->SetZQuench(zquench);
+             for(Int_t j=0;j<ntruq;j++){
+               Float_t pjet[4];
+               pheader->UQJet(j,pjet);
+               fEventParticles->AddUQJet(pjet);
+             }
+           }
+#endif
+           //Int_t ptyp=pheader->ProcessType();
+           Int_t ntrials=pheader->Trials();
+           fEventParticles->SetTrials(ntrials);
+
+           Int_t ntr=pheader->NTriggerJets();
+           if(ntr){
+             for(Int_t j=0;j<ntr;j++){
+               Float_t pjet[4];
+               pheader->TriggerJet(j,pjet);
+               fEventParticles->AddJet(pjet);
+               if(!ntruq) fEventParticles->AddUQJet(pjet);
+             }
+           }
+           for(Int_t i=6;i<=7;i++){
+             TParticle *MP = stack->Particle(i);
+             if(!MP) break;
+             Int_t type=0;
+             if(MP->GetPdgCode()==21) type=2;
+             else type=1;
+             fEventParticles->AddHard(i-6,MP->Px(),MP->Py(),MP->Pz(),MP->Energy(),type);
            }
          }
        }
+       headdesc+=" Run ";
+       headdesc+=header->GetRun();
+       headdesc+=": Ev ";
+       headdesc+=header->GetEventNrInRun();
       }
       fEventParticles->SetHeader(headdesc);
 
@@ -173,12 +221,24 @@ Int_t AliJetParticlesReaderKine::ReadNext()
          //Int_t mother = p->GetFirstMother();    
          //cout << child1 << " " << child2 << " " << mother << endl;
          if((child1>=0) && (child1<nprim)) continue; 
-         if(p->GetStatusCode()!=1){
-           //p->Print();
-           continue;
+
+         //check status code depending on gentype
+         if(gentype==1){ // Hijing Param
+           if(p->GetStatusCode()!=0) continue;
+         } else if(gentype==2){ //Hijing
+           //if( p->GetStatusCode()!=0){
+           //  cout <<p->GetStatusCode() << " ";p->Print(); 
+           //}
+         } else if(gentype==3){ //Pythia
+           if(p->GetStatusCode()!=1) continue;
+           p->SetWeight(-123); //mark particle
          }
-         if(IsAcceptedParticle(p)) //put particle in event
+
+         //kinematic cuts
+         if(IsAcceptedParticle(p)){ //put particle in event
+           //if(p->Pt()>20){cout <<p->GetStatusCode() << " ";p->Print(); }
            fEventParticles->AddParticle(p,i); 
+         }
        }
       fCurrentEvent++;
       fNEventsRead++;
@@ -206,13 +266,14 @@ Int_t AliJetParticlesReaderKine::OpenFile(Int_t n)
     }
 
   TString filename = dirname +"/"+ fFileName;
-  fRunLoader = AliRunLoader::Open(filename.Data()); 
-
-  if (fRunLoader == 0)
+  TFile file(filename);
+  if ( file.IsOpen() == 0)
     {
       Error("OpenNextFile","Can't open session from file %s",filename.Data());
       return kFALSE;
     }
+  file.Close();
+  fRunLoader = AliRunLoader::Open(filename.Data()); 
   
   if (fRunLoader->GetNumberOfEvents() <= 0)
     {