]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDTagCreator.cxx
New base class.
[u/mrichter/AliRoot.git] / STEER / AliESDTagCreator.cxx
index 9d33e1f3365db2891c55a806b023c3ea96b3ba30..150e21f9b910335b6d1f619ba18cb8af0cd63a8b 100644 (file)
@@ -196,7 +196,7 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
   //private method that creates tag files
   TString fSession = type;
   TString fguid, fmd5, fturl;
-  TString fTempGuid = 0;
+  TString fTempGuid;
 
   /////////////
   //muon code//
@@ -209,11 +209,11 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
   Int_t fCharge;
   TLorentzVector fEPvector;
 
-  Float_t fZVertexCut = 10.0; 
-  Float_t fRhoVertexCut = 2.0; 
+  Float_t fZVertexCut    = 40.0; 
+  Float_t fRhoVertexCut  = 600.0; 
 
-  Float_t fLowPtCut = 1.0;
-  Float_t fHighPtCut = 3.0;
+  Float_t fLowPtCut      =  1.0;
+  Float_t fHighPtCut     =  3.0;
   Float_t fVeryHighPtCut = 10.0;
   ////////////
 
@@ -222,13 +222,13 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
   // Creates the tags for all the events in a given ESD file
   Bool_t fIsSim = kTRUE;
   Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
   Int_t nMu1GeV, nMu3GeV, nMu10GeV;
   Int_t nEl1GeV, nEl3GeV, nEl10GeV;
-  Float_t maxPt = .0, meanPt = .0, totalP = .0;
+  Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
   Int_t fVertexflag;
   Int_t iRunNumber = 0;
   TString fVertexName;
@@ -280,19 +280,23 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
 
   AliRunTag *tag = new AliRunTag();
   AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  TTree * ttag = new TTree("T","A Tree with event tags");
+  TBranch * btag = ttag->Branch("AliTAG", &tag);
   btag->SetCompressionLevel(9);
-
+  // Run related information
+  tag->SetMagneticField(esd->GetMagneticField());
+  tag->SetBeamEnergy(esd->GetBeamEnergy());
+  tag->SetBeamType(TString(esd->GetBeamType()));
+  
   for(Int_t iEventNumber = 0; iEventNumber < chain->GetEntries(); iEventNumber++) {
     ntrack = 0; nPos = 0; nNeg = 0; nNeutr =0;
     nK0s = 0; nNeutrons = 0; nPi0s = 0;
     nGamas = 0; nProtons = 0; nKaons = 0;
-    nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 0;        
+    nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 0; nFWMatchedMuons = 0;   
     nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
     nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
     nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
-    maxPt = .0; meanPt = .0; totalP = .0;
+    maxPt = .0; etamaxPt = -999.; phimaxPt = -999.; meanPt = .0; totalP = .0;
     fVertexflag = 1;
     
     chain->GetEntry(iEventNumber);    
@@ -336,7 +340,11 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
       Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
-      if(fPt > maxPt) maxPt = fPt;
+      if(fPt > maxPt) {
+         maxPt = fPt;
+         phimaxPt = esdTrack->Phi();
+         etamaxPt = esdTrack->Eta();
+      }
       
       if(esdTrack->GetSign() > 0) {
        nPos++;
@@ -407,19 +415,18 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
       fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
       fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
       
-      // total number of muons inside a vertex cut 
-      if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
-       nMuons++;
-       nFWMuons++;
-       if(fEPvector.Pt() > fLowPtCut) {
-         nMu1GeV++; 
-         if(fEPvector.Pt() > fHighPtCut) {
-           nMu3GeV++; 
-           if (fEPvector.Pt() > fVeryHighPtCut) {
-             nMu10GeV++;
-           }
-         }
-       }
+      if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
+      
+      nMuons++;
+      nFWMuons++;
+      if(fEPvector.Pt() > fLowPtCut) {
+        nMu1GeV++; 
+        if(fEPvector.Pt() > fHighPtCut) {
+          nMu3GeV++; 
+          if (fEPvector.Pt() > fVeryHighPtCut) {
+            nMu10GeV++;
+          }
+        }
       }
     }//muon track loop
     
@@ -448,7 +455,7 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
     evTag->SetBunchCrossNumber(esd->GetBunchCrossNumber());
     evTag->SetGUID(fguid);
     if(fSession == "grid") {
-      evTag->SetMD5(0);
+      evTag->SetMD5("");
       evTag->SetTURL(fturl);
       evTag->SetSize(0);
     }
@@ -465,14 +472,15 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
     evTag->SetTriggerMask(esd->GetTriggerMask());
     evTag->SetTriggerCluster(esd->GetTriggerCluster());
     
+    evTag->SetEventType(esd->GetEventType());
+    evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
+
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
     evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
     evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
     evTag->SetNumOfParticipants(esd->GetZDCParticipants());
-    evTag->SetNumOfParticipants(esd->GetZDCParticipants());
-    evTag->SetNumOfParticipants2(esd->GetZDCParticipants2());
     
     
     evTag->SetNumOfTracks(esd->GetNumberOfTracks());
@@ -490,6 +498,7 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
     evTag->SetNumOfFWMuons(nFWMuons);
+    evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -514,6 +523,8 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
     evTag->SetTotalMomentum(totalP);
     evTag->SetMeanPt(meanPt);
     evTag->SetMaxPt(maxPt);
+    evTag->SetEtaMaxPt(etamaxPt);
+    evTag->SetPhiMaxPt(phimaxPt);
     
     tag->SetRunId(iInitRunNumber);
     if(fIsSim) tag->SetDataType(0);
@@ -521,13 +532,13 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
 
     if(fguid != fTempGuid) {
       fTempGuid = fguid;
-      ttag.Fill();
+      ttag->Fill();
       tag->Clear("");
     }
     tag->AddEventTag(*evTag);
     if(iEventNumber+1 == chain->GetEntries()) {
       //AliInfo(Form("File: %s",fturl.Data()));
-      ttag.Fill();
+      ttag->Fill();
       tag->Clear("");
     }      
   }//event loop
@@ -545,7 +556,7 @@ void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
 
   ftag->cd();
   tag->Clear();
-  ttag.Write();
+  ttag->Write();
   ftag->Close();
 
   //gSystem->GetMemInfo(meminfo);
@@ -576,8 +587,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
   Int_t fCharge;
   TLorentzVector fEPvector;
 
-  Float_t fZVertexCut = 10.0; 
-  Float_t fRhoVertexCut = 2.0; 
+  Float_t fZVertexCut = 40.0; 
+  Float_t fRhoVertexCut = 600.0; 
 
   Float_t fLowPtCut = 1.0;
   Float_t fHighPtCut = 3.0;
@@ -589,13 +600,13 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
   // Creates the tags for all the events in a given ESD file
   Bool_t fIsSim = kTRUE;
   Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
   Int_t nMu1GeV, nMu3GeV, nMu10GeV;
   Int_t nEl1GeV, nEl3GeV, nEl10GeV;
-  Float_t maxPt = .0, meanPt = .0, totalP = .0;
+  Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
   Int_t fVertexflag;
   Int_t iRunNumber = 0;
   TString fVertexName;
@@ -603,8 +614,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
 
   AliRunTag *tag = new AliRunTag();
   AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  TTree * ttag = new TTree("T","A Tree with event tags");
+  TBranch * btag = ttag->Branch("AliTAG", &tag);
   btag->SetCompressionLevel(9);
   gSystem->GetMemInfo(meminfo);
   AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed));
@@ -639,6 +650,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     nPions = 0;
     nMuons = 0;
     nFWMuons = 0;
+    nFWMatchedMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -650,6 +662,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     nEl3GeV = 0;
     nEl10GeV = 0;
     maxPt = .0;
+    etamaxPt = -999.;
+    phimaxPt = -999.;
     meanPt = .0;
     totalP = .0;
     fVertexflag = 1;
@@ -681,8 +695,13 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
       Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
-      if(fPt > maxPt) maxPt = fPt;
+      if(fPt > maxPt) {
+         maxPt = fPt;
+         etamaxPt = esdTrack->Eta();
+         phimaxPt = esdTrack->Phi();
+      }
       
+             
       if(esdTrack->GetSign() > 0) {
        nPos++;
        if(fPt > fLowPtCut) nCh1GeV++;
@@ -752,19 +771,18 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
       fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
       fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
       
-      // total number of muons inside a vertex cut 
-      if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
-       nMuons++;
-       nFWMuons++;
-       if(fEPvector.Pt() > fLowPtCut) {
-         nMu1GeV++; 
-         if(fEPvector.Pt() > fHighPtCut) {
-           nMu3GeV++; 
-           if (fEPvector.Pt() > fVeryHighPtCut) {
-             nMu10GeV++;
-           }
-         }
-       }
+      if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
+      
+      nMuons++;
+      nFWMuons++;
+      if(fEPvector.Pt() > fLowPtCut) {
+        nMu1GeV++; 
+        if(fEPvector.Pt() > fHighPtCut) {
+          nMu3GeV++; 
+          if (fEPvector.Pt() > fVeryHighPtCut) {
+            nMu10GeV++;
+          }
+        }
       }
     }//muon track loop
     
@@ -803,6 +821,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     evTag->SetTriggerMask(esd->GetTriggerMask());
     evTag->SetTriggerCluster(esd->GetTriggerCluster());
     
+    evTag->SetEventType(esd->GetEventType());
+    evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
+
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
     evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
@@ -826,6 +847,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
     evTag->SetNumOfFWMuons(nFWMuons);
+    evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -850,6 +872,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     evTag->SetTotalMomentum(totalP);
     evTag->SetMeanPt(meanPt);
     evTag->SetMaxPt(maxPt);
+    evTag->SetEtaMaxPt(etamaxPt);
+    evTag->SetPhiMaxPt(phimaxPt);
     
     tag->SetRunId(iInitRunNumber);
     if(fIsSim) tag->SetDataType(0);
@@ -891,9 +915,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
 
   TFile* ftag = TFile::Open(fileName, "recreate");
   ftag->cd();
-  ttag.Fill();
+  ttag->Fill();
   tag->Clear();
-  ttag.Write();
+  ttag->Write();
   ftag->Close();
 
   gSystem->GetMemInfo(meminfo);
@@ -922,8 +946,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
   Int_t fCharge;
   TLorentzVector fEPvector;
 
-  Float_t fZVertexCut = 10.0; 
-  Float_t fRhoVertexCut = 2.0; 
+  Float_t fZVertexCut = 40.0; 
+  Float_t fRhoVertexCut = 600.0; 
 
   Float_t fLowPtCut = 1.0;
   Float_t fHighPtCut = 3.0;
@@ -935,13 +959,13 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
   // Creates the tags for all the events in a given ESD file
   Bool_t fIsSim = kTRUE;
   Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
   Int_t nMu1GeV, nMu3GeV, nMu10GeV;
   Int_t nEl1GeV, nEl3GeV, nEl10GeV;
-  Float_t maxPt = .0, meanPt = .0, totalP = .0;
+  Float_t maxPt = .0, etamaxPt = -999, phimaxPt = -999., meanPt = .0, totalP = .0;
   Int_t fVertexflag;
   Int_t iRunNumber = 0;
   TString fVertexName;
@@ -949,8 +973,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
 
   AliRunTag *tag = new AliRunTag();
   AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  TTree * ttag = new TTree("T","A Tree with event tags");
+  TBranch * btag = ttag->Branch("AliTAG", &tag);
   btag->SetCompressionLevel(9);
   
   AliInfo(Form("Creating the ESD tags......."));       
@@ -979,6 +1003,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     nPions = 0;
     nMuons = 0;
     nFWMuons = 0;
+    nFWMatchedMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -990,6 +1015,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     nEl3GeV = 0;
     nEl10GeV = 0;
     maxPt = .0;
+    etamaxPt = -999.;
+    phimaxPt = -999.;
     meanPt = .0;
     totalP = .0;
     fVertexflag = 1;
@@ -1021,7 +1048,12 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
       Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
-      if(fPt > maxPt) maxPt = fPt;
+      if(fPt > maxPt) {
+         maxPt = fPt;
+         etamaxPt = esdTrack->Eta();
+         phimaxPt = esdTrack->Phi();
+      }
+      
       
       if(esdTrack->GetSign() > 0) {
        nPos++;
@@ -1092,19 +1124,18 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
       fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
       fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
       
-      // total number of muons inside a vertex cut 
-      if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
-       nMuons++;
-       nFWMuons++;
-       if(fEPvector.Pt() > fLowPtCut) {
-         nMu1GeV++; 
-         if(fEPvector.Pt() > fHighPtCut) {
-           nMu3GeV++; 
-           if (fEPvector.Pt() > fVeryHighPtCut) {
-             nMu10GeV++;
-           }
-         }
-       }
+      if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
+
+      nMuons++;
+      nFWMuons++;
+      if(fEPvector.Pt() > fLowPtCut) {
+        nMu1GeV++; 
+        if(fEPvector.Pt() > fHighPtCut) {
+          nMu3GeV++; 
+          if (fEPvector.Pt() > fVeryHighPtCut) {
+            nMu10GeV++;
+          }
+        }
       }
     }//muon track loop
     
@@ -1140,6 +1171,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     evTag->SetTriggerMask(esd->GetTriggerMask());
     evTag->SetTriggerCluster(esd->GetTriggerCluster());
     
+    evTag->SetEventType(esd->GetEventType());
+    evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
+
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
     evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
@@ -1163,6 +1197,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
     evTag->SetNumOfFWMuons(nFWMuons);
+    evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -1187,6 +1222,8 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     evTag->SetTotalMomentum(totalP);
     evTag->SetMeanPt(meanPt);
     evTag->SetMaxPt(maxPt);
+    evTag->SetEtaMaxPt(etamaxPt);
+    evTag->SetPhiMaxPt(phimaxPt);
     
     tag->SetRunId(iInitRunNumber);
     if(fIsSim) tag->SetDataType(0);
@@ -1221,9 +1258,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
 
   TFile* ftag = TFile::Open(fileName, "recreate");
   ftag->cd();
-  ttag.Fill();
+  ttag->Fill();
   tag->Clear();
-  ttag.Write();
+  ttag->Write();
   ftag->Close();
 
   delete ftag;
@@ -1260,8 +1297,8 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
   Int_t fCharge;
   TLorentzVector fEPvector;
 
-  Float_t fZVertexCut = 10.0; 
-  Float_t fRhoVertexCut = 2.0; 
+  Float_t fZVertexCut = 40.0; 
+  Float_t fRhoVertexCut = 600.0; 
 
   Float_t fLowPtCut = 1.0;
   Float_t fHighPtCut = 3.0;
@@ -1272,13 +1309,13 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
 
   // Creates the tags for all the events in a given ESD file
   Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
   Int_t nMu1GeV, nMu3GeV, nMu10GeV;
   Int_t nEl1GeV, nEl3GeV, nEl10GeV;
-  Float_t maxPt = .0, meanPt = .0, totalP = .0;
+  Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
   Int_t fVertexflag;
   Int_t iRunNumber = 0;
   TString fVertexName("default");
@@ -1301,7 +1338,8 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
   Int_t iInitRunNumber = esd->GetRunNumber();
   
   Int_t iNumberOfEvents = (Int_t)b->GetEntries();
-  if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
+  if ((fLastEvent == -1) || ((Int_t) b->GetEntries() < fLastEvent))
+    lastEvent = (Int_t)b->GetEntries();
   else lastEvent = fLastEvent;
 
   char fileName[256];
@@ -1314,11 +1352,12 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
  
   AliRunTag *tag = new AliRunTag();
   AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  TTree * ttag = new TTree("T","A Tree with event tags");
+  TBranch * btag = ttag->Branch("AliTAG", &tag);
   btag->SetCompressionLevel(9);
 
-  if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
+  if ((fLastEvent != -1) && ((Int_t) b->GetEntries() > fLastEvent)) 
+    iNumberOfEvents = fLastEvent + 1;
   for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
     ntrack = 0;
     nPos = 0;
@@ -1333,6 +1372,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
     nPions = 0;
     nMuons = 0;
     nFWMuons = 0;
+    nFWMatchedMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -1344,6 +1384,8 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
     nEl3GeV = 0;
     nEl10GeV = 0;
     maxPt = .0;
+    etamaxPt = -999.;
+    phimaxPt = -999.;
     meanPt = .0;
     totalP = .0;
     fVertexflag = 0;
@@ -1373,7 +1415,11 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
       Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
-      if(fPt > maxPt) maxPt = fPt;
+      if(fPt > maxPt) {
+         maxPt = fPt;
+         phimaxPt = esdTrack->Eta();
+         etamaxPt = esdTrack->Phi();
+      }
       
       if(esdTrack->GetSign() > 0) {
        nPos++;
@@ -1444,19 +1490,18 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
       fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
       fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
       
-      // total number of muons inside a vertex cut 
-      if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
-       nMuons++;
-       nFWMuons++;
-       if(fEPvector.Pt() > fLowPtCut) {
-         nMu1GeV++; 
-         if(fEPvector.Pt() > fHighPtCut) {
-           nMu3GeV++; 
-           if (fEPvector.Pt() > fVeryHighPtCut) {
-             nMu10GeV++;
-           }
-         }
-       }
+      if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
+
+      nMuons++;
+      nFWMuons++;
+      if(fEPvector.Pt() > fLowPtCut) {
+        nMu1GeV++; 
+        if(fEPvector.Pt() > fHighPtCut) {
+          nMu3GeV++; 
+          if (fEPvector.Pt() > fVeryHighPtCut) {
+            nMu10GeV++;
+          }
+        }
       }
     }//muon track loop
 
@@ -1494,6 +1539,9 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
     evTag->SetTriggerMask(esd->GetTriggerMask());
     evTag->SetTriggerCluster(esd->GetTriggerCluster());
     
+    evTag->SetEventType(esd->GetEventType());
+    evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
+
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
     evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
@@ -1517,6 +1565,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
     evTag->SetNumOfFWMuons(nFWMuons);
+    evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -1541,6 +1590,8 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
     evTag->SetTotalMomentum(totalP);
     evTag->SetMeanPt(meanPt);
     evTag->SetMaxPt(maxPt);
+    evTag->SetEtaMaxPt(etamaxPt);
+    evTag->SetPhiMaxPt(phimaxPt);
     
     tag->SetLHCTag(lhcLuminosity,lhcState);
     tag->SetDetectorTag(detectorMask);
@@ -1559,11 +1610,13 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRP
   }
        
   ftag->cd();
-  ttag.Fill();
+  ttag->Fill();
   tag->Clear();
-  ttag.Write();
+  ttag->Write();
   ftag->Close();
   file->cd();
+  delete file;
+  delete esd;
   delete tag;
   delete evTag;
 }