Realisation of AliGenReader that reads the old cwn event format.
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Nov 2001 09:10:46 +0000 (09:10 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Nov 2001 09:10:46 +0000 (09:10 +0000)
EVGEN/AliGenReaderCwn.cxx [new file with mode: 0644]
EVGEN/AliGenReaderCwn.h [new file with mode: 0644]

diff --git a/EVGEN/AliGenReaderCwn.cxx b/EVGEN/AliGenReaderCwn.cxx
new file mode 100644 (file)
index 0000000..48223be
--- /dev/null
@@ -0,0 +1,136 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+/*
+$Log$
+*/
+
+// Read the old ALICE event format based on CW-ntuples
+// http://consult.cern.ch/alice/Internal_Notes/1995/32/abstract
+// .cwn file have to be converted to .root using h2root
+// Use SetFileName(file) to read from "file" 
+// Author: andreas.morsch@cern.ch
+
+#include <TFile.h>
+#include <TTree.h>
+#include <TParticle.h>
+
+#include "AliGenReaderCwn.h"
+#include "AliMC.h"
+ClassImp(AliGenReaderCwn);
+
+
+AliGenReaderCwn::AliGenReaderCwn() 
+{
+// Default constructor
+    fNcurrent   = 0;
+    fTreeNtuple = 0;
+}
+
+void AliGenReaderCwn::Init() 
+{
+//
+// reset the existing file environment and open a new root file if
+// the pointer to the Fluka tree is null
+    
+    TFile *pFile=0;
+    if (!pFile) {
+       pFile = new TFile(fFileName);
+       pFile->cd();
+       printf("\n I have opened %s file \n", fFileName);
+    }
+// get the tree address in the Fluka boundary source file
+    fTreeNtuple = (TTree*)gDirectory->Get("h888");
+
+    TTree *h2=fTreeNtuple;
+//Set branch addresses
+    h2->SetBranchAddress("Nihead",&fNihead);
+    h2->SetBranchAddress("Ihead",fIhead);
+    h2->SetBranchAddress("Nrhead",&fNrhead);
+    h2->SetBranchAddress("Rhead",fRhead);
+    h2->SetBranchAddress("Idpart",&fIdpart);
+    h2->SetBranchAddress("Theta",&fTheta);
+    h2->SetBranchAddress("Phi",&fPhi);
+    h2->SetBranchAddress("P",&fP);
+    h2->SetBranchAddress("E",&fE);
+}
+
+Int_t AliGenReaderCwn::NextEvent() 
+{
+// Read the next event  
+    Int_t nTracks;
+    fNparticle = 0;
+    TFile* pFile = fTreeNtuple->GetCurrentFile();
+    pFile->cd();
+
+    Int_t nentries = (Int_t) fTreeNtuple->GetEntries();
+    if (fNcurrent < nentries) {
+       Int_t nb = (Int_t)fTreeNtuple->GetEvent(fNcurrent);
+       fNcurrent++;
+       
+       Int_t i5=fIhead[4];
+       Int_t i6=fIhead[5];
+       if (i5==0) {
+           printf("\n This should never happen !\n");
+           nTracks = 0;
+       } else {
+           printf("\n Next event contains %d tracks! \n", i6);
+           nTracks = i6;
+       }    
+       fNparticleMax = nTracks;
+       return nTracks;
+    } else {
+       return 0;
+    }
+    return 0;
+}
+
+TParticle* AliGenReaderCwn::NextParticle() 
+{
+//
+//  
+    Float_t prwn;
+    Float_t p[4];
+// Read the next particle
+    if (fCode == kGEANT3) fIdpart=gMC->PDGFromId(fIdpart);
+    Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
+    if(fE<=amass) {
+       Warning("Generate","Particle %d  E = %f mass = %f %f %f \n",
+               fIdpart,fE,amass, fPhi, fTheta);
+       prwn=0;
+    } else {
+       prwn=sqrt((fE+amass)*(fE-amass));
+    }
+
+    fTheta *= TMath::Pi()/180.;
+    fPhi    = (fPhi-180)*TMath::Pi()/180.;      
+    p[0] = prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
+    p[1] = prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);      
+    p[2] = prwn*TMath::Cos(fTheta);
+    p[3] = fE;
+    TParticle* particle = new TParticle(fIdpart, 0, -1, -1, -1, -1, p[0], p[1], p[2], p[3], 
+                                       0., 0., 0., 0.);
+    Int_t nb = (Int_t)fTreeNtuple->GetEvent(fNcurrent);
+    fNcurrent++;
+    fNparticle++;
+    return particle;
+}
+
+
+
+
+
+
diff --git a/EVGEN/AliGenReaderCwn.h b/EVGEN/AliGenReaderCwn.h
new file mode 100644 (file)
index 0000000..a1b7759
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALIGENREADERCWN_H
+#define ALIGENREADERCWN_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include "AliGenReader.h"
+
+
+class AliGenReaderCwn : public AliGenReader
+{
+ public:
+    AliGenReaderCwn();
+    
+    AliGenReaderCwn(const AliGenReaderCwn &reader){;}
+    virtual ~AliGenReaderCwn(){;}
+    // Initialise 
+    virtual void Init();
+    // Read
+    virtual Int_t NextEvent();
+    virtual TParticle*  NextParticle();
+    AliGenReaderCwn & operator=(const AliGenReader & rhs);
+ protected:
+    Int_t             fNcurrent;      // points to the next entry
+    Int_t             fNparticle;     // particle number in event
+    Int_t             fNparticleMax;  // number of particles in event    
+    TTree            *fTreeNtuple;    // pointer to the TTree
+    //Declaration of leaves types
+    Int_t           fNihead;          // Number of entries in integer header  
+    Int_t           fIhead[12];       // Integer header
+    Int_t           fNrhead;          // Number of entries in float header
+    Float_t         fRhead[6];        // Float header
+    UInt_t          fIdpart;          // Particle type
+    Float_t         fTheta;           // Theta 
+    Float_t         fPhi;             // Phi
+    Float_t         fP;               // Total momentum
+    Float_t         fE;               // Total energy
+    ClassDef(AliGenReaderCwn,1) // Read particles from cwn-ntuple
+};
+#endif
+
+
+
+
+
+