]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDTagCreator.cxx
Removing coding violations (Marian)
[u/mrichter/AliRoot.git] / STEER / AliESDTagCreator.cxx
index 92182be3ed086c5e31ee929b7c5f2d81d3ef6f6f..892ea15a442d4960ec918f62e3eaf6abe60cc886 100644 (file)
@@ -29,6 +29,8 @@
 #include <TList.h>
 #include <TObjString.h>
 #include <TLorentzVector.h>
+#include <TMap.h>
+#include <TTimeStamp.h>
 
 //ROOT-AliEn
 #include <TGrid.h>
@@ -41,6 +43,7 @@
 #include "AliESDEvent.h"
 #include "AliESDVertex.h"
 #include "AliLog.h"
+#include "AliGRPObject.h"
 
 #include "AliESDTagCreator.h"
 
@@ -52,7 +55,7 @@ ClassImp(AliESDTagCreator)
   AliESDTagCreator::AliESDTagCreator() :
     AliTagCreator(),
     fChain(new TChain("esdTree")), fGUIDList(new TList()), 
-    fMD5List(new TList()), fTURLList(new TList()), 
+    fMD5List(new TList()), fTURLList(new TList()), fBranches(""), 
     meminfo(new MemInfo_t) {
   //==============Default constructor for a AliESDTagCreator================
 }
@@ -102,6 +105,8 @@ Bool_t AliESDTagCreator::ReadGridCollection(TGridResult *fresult) {
   
   AliInfo(Form("ESD chain created......."));   
   AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  // Switch of branches on user request
+  SwitchOffBranches();
   CreateTag(fChain,"grid");
   
   return kTRUE;
@@ -143,6 +148,8 @@ Bool_t AliESDTagCreator::ReadLocalCollection(const char *localpath) {
 
   AliInfo(Form("ESD chain created......."));   
   AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  // Switch of branches on user request
+  SwitchOffBranches();
   CreateTag(fChain,"local");
 
   return kTRUE;
@@ -176,16 +183,17 @@ Bool_t AliESDTagCreator::ReadCAFCollection(const char *filename) {
 
   AliInfo(Form("ESD chain created......."));   
   AliInfo(Form("Chain entries: %d",fChain->GetEntries()));     
+  // Switch of branches on user request
+  SwitchOffBranches();
   CreateTag(fChain,"proof");
 
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
+void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
   //private method that creates tag files
   TString fSession = type;
-  //Int_t iCounter = 0;
   TString fguid, fmd5, fturl;
   TString fTempGuid = 0;
 
@@ -213,7 +221,7 @@ void AliESDTagCreator::CreateTag(TChain* fChain, 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;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
@@ -224,11 +232,6 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
   Int_t iRunNumber = 0;
   TString fVertexName;
 
-  AliRunTag *tag = new AliRunTag();
-  AliEventTag *evTag = new AliEventTag();
-  TTree ttag("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));
   //Int_t tempmem = meminfo->fMemUsed;
@@ -237,28 +240,66 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
   
   Int_t firstEvent = 0,lastEvent = 0;
   AliESDEvent *esd = new AliESDEvent();
-  esd->ReadFromTree(fChain);
+  esd->ReadFromTree(chain);
+  AliESD *esdold = 0x0;
   
   //gSystem->GetMemInfo(meminfo);
   //AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
   //tempmem = meminfo->fMemUsed;
   
   Int_t iInitRunNumber = -1;
-  for(Int_t iEventNumber = 0; iEventNumber < fChain->GetEntries(); iEventNumber++) {
+  chain->GetEntry(0);
+  TFile *f = chain->GetFile();
+  fTempGuid = f->GetUUID().AsString();
+
+  TString localFileName = "Run"; localFileName += esd->GetRunNumber(); 
+  localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += chain->GetEntries(); //localFileName += "."; localFileName += Counter;
+  localFileName += ".ESD.tag.root";
+
+  TString fileName;
+  
+  if(fStorage == 0) {
+    fileName = localFileName.Data();      
+    AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
+  }
+  else if(fStorage == 1) {
+    TString alienLocation = "/alien";
+    alienLocation += gGrid->Pwd();
+    alienLocation += fgridpath.Data();
+    alienLocation += "/";
+    alienLocation +=  localFileName;
+    alienLocation += "?se=";
+    alienLocation += fSE.Data();
+    fileName = alienLocation.Data();
+    AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
+  }
+
+  TFile* ftag = TFile::Open(fileName, "recreate");
+
+  AliRunTag *tag = new AliRunTag();
+  AliEventTag *evTag = new AliEventTag();
+  TTree ttag("T","A Tree with event tags");
+  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  btag->SetCompressionLevel(9);
+
+  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;      
+    nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 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;
     fVertexflag = 1;
     
-    fChain->GetEntry(iEventNumber);
-    TFile *f = fChain->GetFile();
-    const TUrl *url = f->GetEndpointUrl();
-    fguid = f->GetUUID().AsString();
+    chain->GetEntry(iEventNumber);    
+    esdold = esd->GetAliESDOld();
+    if(esdold) esd->CopyFromOldESD();
+
+    TFile *file = chain->GetFile();
+    const TUrl *url = file->GetEndpointUrl();
+    fguid = file->GetUUID().AsString();
     if(fSession == "grid") {
       TString fturltemp = "alien://"; fturltemp += url->GetFile();
       fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
@@ -288,8 +329,9 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
       if ((status&AliESDtrack::kESDpid)==0) continue;
       Double_t p[3];
       esdTrack->GetPxPyPz(p);
-      Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
-      Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
+      Double_t pt2 = p[0]*p[0]+p[1]*p[1];
+      Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
+      Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
       if(fPt > maxPt) maxPt = fPt;
@@ -366,6 +408,7 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
       // 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) {
@@ -381,9 +424,9 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
     // Fill the event tags 
     if(ntrack != 0) meanPt = meanPt/ntrack;
     
-    AliInfo(Form("====================================="));
-    AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data()));
-    AliInfo(Form("====================================="));
+    //AliInfo(Form("====================================="));
+    //AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data()));
+    //AliInfo(Form("====================================="));
 
     evTag->SetEventId(iEventNumber+1);
     evTag->SetGUID(fguid);
@@ -407,10 +450,12 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
     
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
-    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+    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());
@@ -427,6 +472,7 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
     evTag->SetNumOfKaons(nKaons);
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
+    evTag->SetNumOfFWMuons(nFWMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -453,51 +499,32 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
     tag->SetRunId(iInitRunNumber);
     if(fIsSim) tag->SetDataType(0);
     else tag->SetDataType(1);
-    tag->AddEventTag(*evTag);
 
     if(fguid != fTempGuid) {
       fTempGuid = fguid;
       ttag.Fill();
       tag->Clear("");
     }
+    tag->AddEventTag(*evTag);
+    if(iEventNumber+1 == chain->GetEntries()) {
+      //AliInfo(Form("File: %s",fturl.Data()));
+      ttag.Fill();
+      tag->Clear("");
+    }      
   }//event loop
-  lastEvent = fChain->GetEntries();
+  lastEvent = chain->GetEntries();
   
   //gSystem->GetMemInfo(meminfo);
   //AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
   //tempmem = meminfo->fMemUsed;
 
-  //fChain->Delete("");
+  //chain->Delete("");
   
   //gSystem->GetMemInfo(meminfo);
   //AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
   //tempmem = meminfo->fMemUsed;
 
-  TString localFileName = "Run"; localFileName += tag->GetRunId(); 
-  localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; //localFileName += "."; localFileName += Counter;
-  localFileName += ".ESD.tag.root";
-
-  TString fileName;
-  
-  if(fStorage == 0) {
-    fileName = localFileName.Data();      
-    AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
-  }
-  else if(fStorage == 1) {
-    TString alienLocation = "/alien";
-    alienLocation += gGrid->Pwd();
-    alienLocation += fgridpath.Data();
-    alienLocation += "/";
-    alienLocation +=  localFileName;
-    alienLocation += "?se=";
-    alienLocation += fSE.Data();
-    fileName = alienLocation.Data();
-    AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
-  }
-
-  TFile* ftag = TFile::Open(fileName, "recreate");
   ftag->cd();
-  //ttag.Fill();
   tag->Clear();
   ttag.Write();
   ftag->Close();
@@ -506,10 +533,9 @@ void AliESDTagCreator::CreateTag(TChain* fChain, const char *type) {
   //AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
   //tempmem = meminfo->fMemUsed;
 
-  delete ftag;
   delete esd;
-
   delete tag;
+
   //gSystem->GetMemInfo(meminfo);
   //AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
 }
@@ -544,7 +570,7 @@ 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;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
@@ -592,6 +618,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     nKaons = 0;
     nPions = 0;
     nMuons = 0;
+    nFWMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -629,8 +656,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
       if ((status&AliESDtrack::kESDpid)==0) continue;
       Double_t p[3];
       esdTrack->GetPxPyPz(p);
-      Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
-      Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
+      Double_t pt2 = p[0]*p[0]+p[1]*p[1];
+      Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
+      Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
       if(fPt > maxPt) maxPt = fPt;
@@ -707,6 +735,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
       // 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) {
@@ -740,7 +769,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
-    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
     evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
     evTag->SetNumOfParticipants(esd->GetZDCParticipants());
@@ -760,6 +789,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5,
     evTag->SetNumOfKaons(nKaons);
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
+    evTag->SetNumOfFWMuons(nFWMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -867,7 +897,7 @@ 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;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
@@ -909,6 +939,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     nKaons = 0;
     nPions = 0;
     nMuons = 0;
+    nFWMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -946,8 +977,9 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
       if ((status&AliESDtrack::kESDpid)==0) continue;
       Double_t p[3];
       esdTrack->GetPxPyPz(p);
-      Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
-      Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
+      Double_t pt2 = p[0]*p[0]+p[1]*p[1];
+      Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
+      Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
       if(fPt > maxPt) maxPt = fPt;
@@ -1024,6 +1056,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
       // 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) {
@@ -1055,7 +1088,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     
     evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
-    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
     evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
     evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
     evTag->SetNumOfParticipants(esd->GetZDCParticipants());
@@ -1075,6 +1108,7 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
     evTag->SetNumOfKaons(nKaons);
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
+    evTag->SetNumOfFWMuons(nFWMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -1143,11 +1177,21 @@ void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counte
 }
 
 //_____________________________________________________________________________
-void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
+void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength) {
   //GRP
   Float_t lhcLuminosity = 0.0;
   TString lhcState = "test";
-  UInt_t detectorMask = 0;
+  //UInt_t detectorMask = 0;
+  Int_t detectorMask = 0;
+
+  detectorMask = grpData->GetDetectorMask();
+  time_t startTime = grpData->GetTimeStart();
+  TTimeStamp *t1 = new TTimeStamp(startTime);
+  time_t endTime = grpData->GetTimeEnd();
+  TTimeStamp *t2 = new TTimeStamp(endTime);
+  const char* beamtype = grpData->GetBeamType();
+  Float_t beamenergy = grpData->GetBeamEnergy();
+
 
   /////////////
   //muon code//
@@ -1172,7 +1216,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
 
   // Creates the tags for all the events in a given ESD file
   Int_t ntrack;
-  Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
+  Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons;
   Int_t nPos, nNeg, nNeutr;
   Int_t nK0s, nNeutrons, nPi0s, nGamas;
   Int_t nCh1GeV, nCh3GeV, nCh10GeV;
@@ -1182,12 +1226,6 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
   Int_t fVertexflag;
   Int_t iRunNumber = 0;
   TString fVertexName("default");
-
-  AliRunTag *tag = new AliRunTag();
-  AliEventTag *evTag = new AliEventTag();
-  TTree ttag("T","A Tree with event tags");
-  TBranch * btag = ttag.Branch("AliTAG", &tag);
-  btag->SetCompressionLevel(9);
   
   AliInfo(Form("Creating the ESD tags......."));       
 
@@ -1206,6 +1244,23 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
   Int_t iInitRunNumber = esd->GetRunNumber();
   
   Int_t iNumberOfEvents = (Int_t)b->GetEntries();
+  if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
+  else lastEvent = fLastEvent;
+
+  char fileName[256];
+  sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", 
+         iInitRunNumber,fFirstEvent,lastEvent);
+  AliInfo(Form("writing tags to file %s", fileName));
+  AliDebug(1, Form("writing tags to file %s", fileName));
+  TFile* ftag = TFile::Open(fileName, "recreate");
+  AliRunTag *tag = new AliRunTag();
+  AliEventTag *evTag = new AliEventTag();
+  TTree ttag("T","A Tree with event tags");
+  TBranch * btag = ttag.Branch("AliTAG", &tag);
+  btag->SetCompressionLevel(9);
+
   if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
   for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
     ntrack = 0;
@@ -1220,6 +1275,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
     nKaons = 0;
     nPions = 0;
     nMuons = 0;
+    nFWMuons = 0;
     nElectrons = 0;      
     nCh1GeV = 0;
     nCh3GeV = 0;
@@ -1255,8 +1311,9 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
       if ((status&AliESDtrack::kESDpid)==0) continue;
       Double_t p[3];
       esdTrack->GetPxPyPz(p);
-      Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
-      Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
+      Double_t pt2 = p[0]*p[0]+p[1]*p[1];
+      Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
+      Double_t fPt = TMath::Sqrt(pt2);
       totalP += momentum;
       meanPt += fPt;
       if(fPt > maxPt) maxPt = fPt;
@@ -1333,6 +1390,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
       // 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) {
@@ -1367,7 +1425,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
     evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
     evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
     evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
-    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+    evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
     evTag->SetNumOfParticipants(esd->GetZDCParticipants());
     
     
@@ -1385,6 +1443,7 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
     evTag->SetNumOfKaons(nKaons);
     evTag->SetNumOfPions(nPions);
     evTag->SetNumOfMuons(nMuons);
+    evTag->SetNumOfFWMuons(nFWMuons);
     evTag->SetNumOfElectrons(nElectrons);
     evTag->SetNumOfPhotons(nGamas);
     evTag->SetNumOfPi0s(nPi0s);
@@ -1412,18 +1471,18 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
     tag->SetDetectorTag(detectorMask);
 
     tag->SetRunId(iInitRunNumber);
+    tag->SetRunStartTime(t1->GetDate());
+    tag->SetRunStopTime(t2->GetDate());
+    tag->SetBeamEnergy(beamenergy);
+    tag->SetBeamType(beamtype);
+    
+    //QA setting 
+    tag->SetQA(qa, qalength) ; 
+    tag->SetEventSpecies(es, eslength) ;
+
     tag->AddEventTag(*evTag);
   }
-  if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
-  else lastEvent = fLastEvent;
        
-  char fileName[256];
-  sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root", 
-         tag->GetRunId(),fFirstEvent,lastEvent );
-  AliInfo(Form("writing tags to file %s", fileName));
-  AliDebug(1, Form("writing tags to file %s", fileName));
-  TFile* ftag = TFile::Open(fileName, "recreate");
   ftag->cd();
   ttag.Fill();
   tag->Clear();
@@ -1434,3 +1493,15 @@ void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent) {
   delete evTag;
 }
 
+//_____________________________________________________________________________
+void AliESDTagCreator::SwitchOffBranches() const {
+  //
+  // Switch of branches on user request
+  TObjArray * tokens = fBranches.Tokenize(" ");
+  Int_t ntok = tokens->GetEntries();
+  for (Int_t i = 0; i < ntok; i++)  {
+    TString str = ((TObjString*) tokens->At(i))->GetString();
+    fChain->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
+    AliInfo(Form("Branch %s switched off \n", str.Data()));
+  }
+}