//-----------------------------------------------------------------
//ROOT
-#include <TObject.h>
#include <Riostream.h>
-#include <TSystem.h>
-#include <TChain.h>
#include <TFile.h>
#include <TString.h>
-#include <THashTable.h>
+#include <TTree.h>
+#include <TSystem.h>
+#include <TChain.h>
+#include <TLorentzVector.h>
//ROOT-AliEn
#include <TGrid.h>
-#include <TAlienCollection.h>
#include <TGridResult.h>
-#include <TFileMerger.h>
-#include <TMap.h>
-#include <TXMLParser.h>
-#include <TThread.h>
-#include <TTreePlayer.h>
-#include <TProof.h>
//AliRoot
#include "AliRunTag.h"
#include "AliEventTag.h"
#include "AliESD.h"
+#include "AliESDEvent.h"
#include "AliESDVertex.h"
-#include "AliPID.h"
-#include "AliESDpid.h"
#include "AliLog.h"
+#include "AliAODEvent.h"
+#include "AliAODVertex.h"
+#include "AliAODTrack.h"
#include "AliTagCreator.h"
//______________________________________________________________________________
-AliTagCreator::AliTagCreator() //local mode
+ AliTagCreator::AliTagCreator() :
+ TObject(),
+ fSE("ALICE::CERN::se"),
+ fgridpath(""),
+ fStorage(0)
{
//==============Default constructor for a AliTagCreator==================
- fUser = "";
- fPasswd = "";
- fSE = "";
- fCollectionFile = "";
- fHost = "";
- fPort = 0;
}
//______________________________________________________________________________
-AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username)
-{
- //==============Default constructor for a AliTagCreator==================
- fHost = host;
- fUser = username;
- fPort = port;
-
- TString grid = "alien://";
- grid += fHost;
- grid += ":";
- grid += port;
-
- //connect to the grid
- TGrid::Connect(grid.Data(),fUser.Data());
- if(!gGrid)
- {
- AliError("Connection failed!!!");
- return;
- }
+AliTagCreator::~AliTagCreator() {
+//================Default destructor for a AliTagCreator=======================
}
-
//______________________________________________________________________________
-AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
-{
- //==============Default constructor for a AliTagCreator==================
- fHost = host;
- fUser = username;
- fPasswd = passwd;
- fPort = port;
-
- TString grid = "alien://";
- grid += fHost;
- grid += ":";
- grid += port;
-
- //connect to the grid
- TGrid::Connect(grid.Data(),fUser.Data(),fPasswd.Data());
- if(!gGrid)
+void AliTagCreator::SetStorage(Int_t storage) {
+ // Sets correctly the storage: 0 for local, 1 for GRID
+ fStorage = storage;
+ if(fStorage == 0)
+ AliInfo(Form("Tags will be stored locally...."));
+ if(fStorage == 1)
+ AliInfo(Form("Tags will be stored in the grid...."));
+ if((fStorage != 0)&&(fStorage != 1))
{
- AliError("Connection failed!!!");
- return;
- }
+ AliInfo(Form("Storage was not properly set!!!"));
+ abort();
+ }
}
//______________________________________________________________________________
-AliTagCreator::~AliTagCreator()
-{
-//================Default destructor for a AliTagCreator=======================
-}
+Bool_t AliTagCreator::ReadGridCollection(TGridResult *fresult) {
+ // Reads the entry of the TGridResult and creates the tags
+ Int_t nEntries = fresult->GetEntries();
-//______________________________________________________________________________
-void AliTagCreator::SetSE(const char *se)
-{
- fSE = se;
+ TString alienUrl;
+ const char *guid;
+ const char *md5;
+ const char *turl;
+ Long64_t size = -1;
+
+ Int_t counter = 0;
+ for(Int_t i = 0; i < nEntries; i++) {
+ alienUrl = fresult->GetKey(i,"turl");
+ guid = fresult->GetKey(i,"guid");
+ if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
+ md5 = fresult->GetKey(i,"md5");
+ turl = fresult->GetKey(i,"turl");
+ if(md5 && !strlen(guid)) md5 = 0;
+ if(guid && !strlen(guid)) guid = 0;
+
+ TFile *f = TFile::Open(alienUrl,"READ");
+ CreateTag(f,guid,md5,turl,size,counter);
+ f->Close();
+ delete f;
+ counter += 1;
+ }//grid result loop
+
+ return kTRUE;
}
//______________________________________________________________________________
-Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
-{
- fHost = host;
- fUser = username;
- fPort = port;
-
- TString grid = "alien://";
- grid += fHost;
- grid += ":";
- grid += port;
+Bool_t AliTagCreator::ReadLocalCollection(const char *localpath) {
+ // Checks the different subdirs of the given local path and in the
+ // case where it finds an AliESDs.root file it creates the tags
- //connect to the grid
- TGrid::Connect(grid.Data(),fUser.Data());
- if(!gGrid)
- {
- AliError("Connection failed!!!");
- return kFALSE;
- } //connect to the grid
+ void *dira = gSystem->OpenDirectory(localpath);
+ Char_t fPath[256];
+ const char * dirname = 0x0;
+ const char * filename = 0x0;
+ const char * pattern = "AliESDs.root";
+
+ Int_t counter = 0;
+ while((dirname = gSystem->GetDirEntry(dira))) {
+ sprintf(fPath,"%s/%s",localpath,dirname);
+ void *dirb = gSystem->OpenDirectory(fPath);
+ while((filename = gSystem->GetDirEntry(dirb))) {
+ if(strstr(filename,pattern)) {
+ TString fESDFileName;
+ fESDFileName = fPath;
+ fESDFileName += "/";
+ fESDFileName += pattern;
+ TFile *f = TFile::Open(fESDFileName,"READ");
+ CreateTag(f,fESDFileName,counter);
+ f->Close();
+ delete f;
+
+ counter += 1;
+ }//pattern check
+ }//child directory's entry loop
+ }//parent directory's entry loop
return kTRUE;
}
//______________________________________________________________________________
-Bool_t AliTagCreator::ReadESDCollection(const char *CollectionFile)
-{
- fCollectionFile = CollectionFile;
-
- gSystem->Load("libXMLIO.so");
- gSystem->Load("libXMLParser.so");
- //define the tag collection
- TAlienCollection *collection = new TAlienCollection(fCollectionFile.Data());
- collection->Reset();
-
- TMap *map;
- TPair *pair;
-
- TString gridname = "alien://";
- Int_t gridnameSize = gridname.Sizeof();
- TString Esd = "AliEsds.root";
-
- TString EsdFilePath;
- TString AlienUrl;
- TString lfn;
- const char *guid;
- TString EsdPattern = "/alien";
-
+Bool_t AliTagCreator::ReadCAFCollection(const char *filename) {
+ // Temporary solution for CAF: Takes as an input the ascii file that
+ // lists the ESDs stored in the SE of the CAF and creates the tags.
+
+ // Open the input stream
+ ifstream in;
+ in.open(filename);
+
Int_t counter = 0;
- while((map = collection->Next()))
- {
- TIter next(map->GetTable());
- counter += 1;
- while ((pair = (TPair*) next()))
- {
- EsdFilePath = pair->Key()->GetName();
- AlienUrl = collection->GetTURL(EsdFilePath);
- EsdFilePath = pair->Value()->GetName();
-
- lfn = EsdFilePath.Replace(0,gridnameSize-1,EsdFilePath,0);
- //TAlienFile *f = new TAlienFile(AlienUrl,"READ");
- //TFile *f = new TFile(AlienUrl,"READ");
- TFile *f = TFile::Open(AlienUrl,"READ");
-
- TGridResult* result = gGrid->Ls(lfn,"-b");
- guid = result->GetKey(0,"guid");
-
- CreateTag(f,guid,counter);
- f->Close();
- delete f;
- }//key loop
- }//collection loop
+ TString esdfile;
+ // Read the input list of files and add them to the chain
+ while(in.good()) {
+ in >> esdfile;
+ if (!esdfile.Contains("root")) continue; // protection
+ TFile *f = TFile::Open(esdfile,"READ");
+ CreateTag(f,esdfile,counter);
+ f->Close();
+ delete f;
+
+ counter += 1;
+ }
+
+ return kTRUE;
+}
+
+
+//__________________________________________________________________________
+Bool_t AliTagCreator::MergeTags() {
+ //Merges the tags and stores the merged tag file
+ //locally if fStorage=0 or in the grid if fStorage=1
+ AliInfo(Form("Merging tags....."));
+ TChain *fgChain = new TChain("T");
+
+ if(fStorage == 0) {
+ const char * tagPattern = "tag";
+ // Open the working directory
+ void * dirp = gSystem->OpenDirectory(gSystem->pwd());
+ const char * name = 0x0;
+ // Add all files matching *pattern* to the chain
+ while((name = gSystem->GetDirEntry(dirp))) {
+ if (strstr(name,tagPattern)) fgChain->Add(name);
+ }//directory loop
+ AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
+ }//local mode
+
+ else if(fStorage == 1) {
+ TString alienLocation = gGrid->Pwd();
+ alienLocation += fgridpath.Data();
+ alienLocation += "/";
+
+ TGridResult *tagresult = gGrid->Query(alienLocation,"*tag.root","","");
+ Int_t nEntries = tagresult->GetEntries();
+ for(Int_t i = 0; i < nEntries; i++) {
+ TString alienUrl = tagresult->GetKey(i,"turl");
+ fgChain->Add(alienUrl);
+ }//grid result loop
+ AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
+ }//grid mode
+
+ AliRunTag *tag = new AliRunTag;
+ fgChain->SetBranchAddress("AliTAG",&tag);
+ fgChain->GetEntry(0);
+ TString localFileName = "Run"; localFileName += tag->GetRunId();
+ localFileName += ".Merged"; localFileName += ".ESD.tag.root";
+
+ TString filename = 0x0;
+
+ if(fStorage == 0) {
+ filename = localFileName.Data();
+ AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
+ }
+ else if(fStorage == 1) {
+ TString alienFileName = "/alien";
+ alienFileName += gGrid->Pwd();
+ alienFileName += fgridpath.Data();
+ alienFileName += "/";
+ alienFileName += localFileName;
+ alienFileName += "?se=";
+ alienFileName += fSE.Data();
+ filename = alienFileName.Data();
+ AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
+ }
+
+ fgChain->Merge(filename);
return kTRUE;
}
+//__________________________________________________________________________
+Bool_t AliTagCreator::MergeTags(TGridResult *result) {
+ //Merges the tags that are listed in the TGridResult
+ AliInfo(Form("Merging tags....."));
+ TChain *fgChain = new TChain("T");
+
+ Int_t nEntries = result->GetEntries();
+
+ TString alienUrl;
+ for(Int_t i = 0; i < nEntries; i++) {
+ alienUrl = result->GetKey(i,"turl");
+ fgChain->Add(alienUrl);
+ }
+ AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
+ AliRunTag *tag = new AliRunTag;
+ fgChain->SetBranchAddress("AliTAG",&tag);
+ fgChain->GetEntry(0);
+
+ TString localFileName = "Run"; localFileName += tag->GetRunId();
+ localFileName += ".Merged"; localFileName += ".ESD.tag.root";
+
+ TString filename = 0x0;
+
+ if(fStorage == 0) {
+ filename = localFileName.Data();
+ AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
+ }
+ else if(fStorage == 1) {
+ TString alienFileName = "/alien";
+ alienFileName += gGrid->Pwd();
+ alienFileName += fgridpath.Data();
+ alienFileName += "/";
+ alienFileName += localFileName;
+ alienFileName += "?se=";
+ alienFileName += fSE.Data();
+ filename = alienFileName.Data();
+ AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
+ }
+
+ fgChain->Merge(filename);
+
+ return kTRUE;
+}
//_____________________________________________________________________________
-void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
-{
+void AliTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
+ //private method that creates tag files
+ TString fguid = guid;
+ TString fmd5 = md5;
+ TString fturl = turl;
+ /////////////
+ //muon code//
+ ////////////
+ Double_t fMUONMASS = 0.105658369;
+ //Variables
+ Double_t fX,fY,fZ ;
+ Double_t fThetaX, fThetaY, fPyz, fChisquare;
+ Double_t fPxRec, fPyRec, fPzRec, fEnergy;
+ Int_t fCharge;
+ TLorentzVector fEPvector;
+
+ Float_t fZVertexCut = 10.0;
+ Float_t fRhoVertexCut = 2.0;
+
+ Float_t fLowPtCut = 1.0;
+ Float_t fHighPtCut = 3.0;
+ Float_t fVeryHighPtCut = 10.0;
+ ////////////
+
+ Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
+
+ // 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 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;
+ Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
+ 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;
+ Int_t fVertexflag;
+ Int_t iRunNumber = 0;
+ TString fVertexName;
AliRunTag *tag = new AliRunTag();
- AliDetectorTag *detTag = new AliDetectorTag();
AliEventTag *evTag = new AliEventTag();
TTree ttag("T","A Tree with event tags");
- TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
+ TBranch * btag = ttag.Branch("AliTAG", &tag);
btag->SetCompressionLevel(9);
AliInfo(Form("Creating the tags......."));
Int_t firstEvent = 0,lastEvent = 0;
TTree *t = (TTree*) file->Get("esdTree");
- TBranch * b = t->GetBranch("ESD");
- AliESD *esd = 0;
- b->SetAddress(&esd);
+ AliESDEvent *esd = new AliESDEvent();
+ esd->ReadFromTree(t);
- tag->SetRunId(esd->GetRunNumber());
-
- Int_t i_NumberOfEvents = b->GetEntries();
- for (Int_t i_EventNumber = 0; i_EventNumber < i_NumberOfEvents; i_EventNumber++)
- {
- 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;
- Nch1GeV = 0;
- Nch3GeV = 0;
- Nch10GeV = 0;
- Nmu1GeV = 0;
- Nmu3GeV = 0;
- Nmu10GeV = 0;
- Nel1GeV = 0;
- Nel3GeV = 0;
- Nel10GeV = 0;
- MaxPt = .0;
- MeanPt = .0;
- TotalP = .0;
+ t->GetEntry(0);
+ Int_t iInitRunNumber = esd->GetRunNumber();
+
+ Int_t iNumberOfEvents = (Int_t)t->GetEntries();
+ for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; 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;
+ 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;
+
+ t->GetEntry(iEventNumber);
+ iRunNumber = esd->GetRunNumber();
+ if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
+ const AliESDVertex * vertexIn = esd->GetVertex();
+ fVertexName = vertexIn->GetName();
+ if(fVertexName == "default") fVertexflag = 0;
+
+ for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
+ AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
+ if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
+ else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
+ UInt_t status = esdTrack->GetStatus();
- b->GetEntry(i_EventNumber);
- const AliESDVertex * VertexIn = esd->GetVertex();
+ //select only tracks with ITS refit
+ if ((status&AliESDtrack::kITSrefit)==0) continue;
+ //select only tracks with TPC refit
+ if ((status&AliESDtrack::kTPCrefit)==0) continue;
- for (Int_t i_TrackNumber = 0; i_TrackNumber < esd->GetNumberOfTracks(); i_TrackNumber++)
- {
- AliESDtrack * ESDTrack = esd->GetTrack(i_TrackNumber);
- UInt_t status = ESDTrack->GetStatus();
-
- //select only tracks with ITS refit
- if ((status&AliESDtrack::kITSrefit)==0) continue;
-
- //select only tracks with TPC refit-->remove extremely high Pt tracks
- if ((status&AliESDtrack::kTPCrefit)==0) continue;
-
- //select only tracks with the "combined PID"
- if ((status&AliESDtrack::kESDpid)==0) continue;
- Double_t p[3];
- ESDTrack->GetPxPyPz(p);
- Double_t P = 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));
- TotalP += P;
- MeanPt += fPt;
- if(fPt > MaxPt)
- MaxPt = fPt;
-
- if(ESDTrack->GetSign() > 0)
- {
- Npos++;
- if(fPt > 1.0)
- Nch1GeV++;
- if(fPt > 3.0)
- Nch3GeV++;
- if(fPt > 10.0)
- Nch10GeV++;
- }
- if(ESDTrack->GetSign() < 0)
- {
- Nneg++;
- if(fPt > 1.0)
- Nch1GeV++;
- if(fPt > 3.0)
- Nch3GeV++;
- if(fPt > 10.0)
- Nch10GeV++;
- }
- if(ESDTrack->GetSign() == 0)
- Nneutr++;
-
- //PID
- Double_t prob[10];
- ESDTrack->GetESDpid(prob);
-
- //K0s
- if ((prob[8]>prob[7])&&(prob[8]>prob[6])&&(prob[8]>prob[5])&&(prob[8]>prob[4])&&(prob[8]>prob[3])&&(prob[8]>prob[2])&&(prob[8]>prob[1])&&(prob[8]>prob[0]))
- NK0s++;
- //neutrons
- if ((prob[7]>prob[8])&&(prob[7]>prob[6])&&(prob[7]>prob[5])&&(prob[7]>prob[4])&&(prob[7]>prob[3])&&(prob[7]>prob[2])&&(prob[7]>prob[1])&&(prob[7]>prob[0]))
- Nneutrons++;
- //pi0s
- if ((prob[6]>prob[8])&&(prob[6]>prob[7])&&(prob[6]>prob[5])&&(prob[6]>prob[4])&&(prob[6]>prob[3])&&(prob[6]>prob[2])&&(prob[6]>prob[1])&&(prob[6]>prob[0]))
- Npi0s++;
- //gamas
- if ((prob[5]>prob[8])&&(prob[5]>prob[7])&&(prob[5]>prob[6])&&(prob[5]>prob[4])&&(prob[5]>prob[3])&&(prob[5]>prob[2])&&(prob[5]>prob[1])&&(prob[5]>prob[0]))
- Ngamas++;
- //protons
- if ((prob[4]>prob[8])&&(prob[4]>prob[7])&&(prob[4]>prob[6])&&(prob[4]>prob[5])&&(prob[4]>prob[3])&&(prob[4]>prob[2])&&(prob[4]>prob[1])&&(prob[4]>prob[0]))
- NProtons++;
- //kaons
- if ((prob[3]>prob[8])&&(prob[3]>prob[7])&&(prob[3]>prob[6])&&(prob[3]>prob[5])&&(prob[3]>prob[4])&&(prob[3]>prob[2])&&(prob[3]>prob[1])&&(prob[3]>prob[0]))
- NKaons++;
- //pions
- if ((prob[2]>prob[8])&&(prob[2]>prob[7])&&(prob[2]>prob[6])&&(prob[2]>prob[5])&&(prob[2]>prob[4])&&(prob[2]>prob[3])&&(prob[2]>prob[1])&&(prob[2]>prob[0]))
- NPions++;
- //muons
- if ((prob[1]>prob[8])&&(prob[1]>prob[7])&&(prob[1]>prob[6])&&(prob[1]>prob[5])&&(prob[1]>prob[4])&&(prob[1]>prob[3])&&(prob[1]>prob[2])&&(prob[1]>prob[0]))
- {
- NMuons++;
- if(fPt > 1.0)
- Nmu1GeV++;
- if(fPt > 3.0)
- Nmu3GeV++;
- if(fPt > 10.0)
- Nmu10GeV++;
- }
- //electrons
- if ((prob[0]>prob[8])&&(prob[0]>prob[7])&&(prob[0]>prob[6])&&(prob[0]>prob[5])&&(prob[0]>prob[4])&&(prob[0]>prob[3])&&(prob[0]>prob[2])&&(prob[0]>prob[1]))
- {
- NElectrons++;
- if(fPt > 1.0)
- Nel1GeV++;
- if(fPt > 3.0)
- Nel3GeV++;
- if(fPt > 10.0)
- Nel10GeV++;
+ //select only tracks with the "combined PID"
+ 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));
+ totalP += momentum;
+ meanPt += fPt;
+ if(fPt > maxPt) maxPt = fPt;
+
+ if(esdTrack->GetSign() > 0) {
+ nPos++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(esdTrack->GetSign() < 0) {
+ nNeg++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(esdTrack->GetSign() == 0) nNeutr++;
+
+ //PID
+ Double_t prob[5];
+ esdTrack->GetESDpid(prob);
+
+ Double_t rcc = 0.0;
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
+ if(rcc == 0.0) continue;
+ //Bayes' formula
+ Double_t w[5];
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
+
+ //protons
+ if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
+ //kaons
+ if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
+ //pions
+ if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
+ //electrons
+ if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
+ nElectrons++;
+ if(fPt > fLowPtCut) nEl1GeV++;
+ if(fPt > fHighPtCut) nEl3GeV++;
+ if(fPt > fVeryHighPtCut) nEl10GeV++;
+ }
+ ntrack++;
+ }//esd track loop
+
+ /////////////
+ //muon code//
+ ////////////
+ Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
+ // loop over all reconstructed tracks (also first track of combination)
+ for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
+ AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
+ if (muonTrack == 0x0) continue;
+
+ // Coordinates at vertex
+ fZ = muonTrack->GetZ();
+ fY = muonTrack->GetBendingCoor();
+ fX = muonTrack->GetNonBendingCoor();
+
+ fThetaX = muonTrack->GetThetaX();
+ fThetaY = muonTrack->GetThetaY();
+
+ fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
+ fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
+ fPxRec = fPzRec * TMath::Tan(fThetaX);
+ fPyRec = fPzRec * TMath::Tan(fThetaY);
+ fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
+
+ //ChiSquare of the track if needed
+ fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
+ 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++;
+ if(fEPvector.Pt() > fLowPtCut) {
+ nMu1GeV++;
+ if(fEPvector.Pt() > fHighPtCut) {
+ nMu3GeV++;
+ if (fEPvector.Pt() > fVeryHighPtCut) {
+ nMu10GeV++;
}
-
-
-
- ntrack++;
- }//track loop
- // Fill the event tags
- if(ntrack != 0)
- MeanPt = MeanPt/ntrack;
+ }
+ }
+ }
+ }//muon track loop
+
+ // Fill the event tags
+ if(ntrack != 0) meanPt = meanPt/ntrack;
+
+ evTag->SetEventId(iEventNumber+1);
+ evTag->SetGUID(fguid);
+ evTag->SetMD5(fmd5);
+ evTag->SetTURL(fturl);
+ evTag->SetSize(size);
+ evTag->SetVertexX(vertexIn->GetXv());
+ evTag->SetVertexY(vertexIn->GetYv());
+ evTag->SetVertexZ(vertexIn->GetZv());
+ evTag->SetVertexZError(vertexIn->GetZRes());
+ evTag->SetVertexFlag(fVertexflag);
+
+ evTag->SetT0VertexZ(esd->GetT0zVertex());
+
+ evTag->SetTriggerMask(esd->GetTriggerMask());
+ evTag->SetTriggerCluster(esd->GetTriggerCluster());
+
+ evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
+ evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
+ evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+ evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
+ evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
+ evTag->SetNumOfParticipants(esd->GetZDCParticipants());
+
+
+ evTag->SetNumOfTracks(esd->GetNumberOfTracks());
+ evTag->SetNumOfPosTracks(nPos);
+ evTag->SetNumOfNegTracks(nNeg);
+ evTag->SetNumOfNeutrTracks(nNeutr);
+
+ evTag->SetNumOfV0s(esd->GetNumberOfV0s());
+ evTag->SetNumOfCascades(esd->GetNumberOfCascades());
+ evTag->SetNumOfKinks(esd->GetNumberOfKinks());
+ evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
+
+ evTag->SetNumOfProtons(nProtons);
+ evTag->SetNumOfKaons(nKaons);
+ evTag->SetNumOfPions(nPions);
+ evTag->SetNumOfMuons(nMuons);
+ evTag->SetNumOfElectrons(nElectrons);
+ evTag->SetNumOfPhotons(nGamas);
+ evTag->SetNumOfPi0s(nPi0s);
+ evTag->SetNumOfNeutrons(nNeutrons);
+ evTag->SetNumOfKaon0s(nK0s);
+
+ evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
+ evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
+ evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
+ evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
+ evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
+ evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
+ evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
+ evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
+ evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
+
+ evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
+ evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
+
+ evTag->SetTotalMomentum(totalP);
+ evTag->SetMeanPt(meanPt);
+ evTag->SetMaxPt(maxPt);
+
+ tag->SetRunId(iInitRunNumber);
+ if(fIsSim) tag->SetDataType(0);
+ else tag->SetDataType(1);
+ tag->AddEventTag(*evTag);
+ }//event loop
+ lastEvent = iNumberOfEvents;
+
+ t->Delete("");
+
+ ttag.Fill();
+ tag->Clear();
+
+ 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.Write();
+ ftag->Close();
+
+ delete ftag;
+ delete esd;
+
+ delete tag;
+}
+
+//_____________________________________________________________________________
+void AliTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
+ //private method that creates tag files
+ /////////////
+ //muon code//
+ ////////////
+ Double_t fMUONMASS = 0.105658369;
+ //Variables
+ Double_t fX,fY,fZ ;
+ Double_t fThetaX, fThetaY, fPyz, fChisquare;
+ Double_t fPxRec, fPyRec, fPzRec, fEnergy;
+ Int_t fCharge;
+ TLorentzVector fEPvector;
+
+ Float_t fZVertexCut = 10.0;
+ Float_t fRhoVertexCut = 2.0;
+
+ Float_t fLowPtCut = 1.0;
+ Float_t fHighPtCut = 3.0;
+ Float_t fVeryHighPtCut = 10.0;
+ ////////////
+
+ Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
+
+ // 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 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;
+ Int_t fVertexflag;
+ 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);
+
+ AliInfo(Form("Creating the tags......."));
+
+ Int_t firstEvent = 0,lastEvent = 0;
+
+ TTree *t = (TTree*) file->Get("esdTree");
+ AliESDEvent *esd = new AliESDEvent();
+ esd->ReadFromTree(t);
+
+ t->GetEntry(0);
+ Int_t iInitRunNumber = esd->GetRunNumber();
+
+ Int_t iNumberOfEvents = (Int_t)t->GetEntries();
+ for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; 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;
+ 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;
+
+ t->GetEntry(iEventNumber);
+ iRunNumber = esd->GetRunNumber();
+ if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
+ const AliESDVertex * vertexIn = esd->GetVertex();
+ fVertexName = vertexIn->GetName();
+ if(fVertexName == "default") fVertexflag = 0;
+
+ for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
+ AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
+ if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
+ else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
+ UInt_t status = esdTrack->GetStatus();
- evTag->SetEventId(i_EventNumber+1);
- evTag->SetGUID(guid);
- evTag->SetVertexX(VertexIn->GetXv());
- evTag->SetVertexY(VertexIn->GetYv());
- evTag->SetVertexZ(VertexIn->GetZv());
+ //select only tracks with ITS refit
+ if ((status&AliESDtrack::kITSrefit)==0) continue;
+ //select only tracks with TPC refit
+ if ((status&AliESDtrack::kTPCrefit)==0) continue;
- evTag->SetT0VertexZ(esd->GetT0zVertex());
+ //select only tracks with the "combined PID"
+ 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));
+ totalP += momentum;
+ meanPt += fPt;
+ if(fPt > maxPt) maxPt = fPt;
- evTag->SetTrigger(esd->GetTrigger());
+ if(esdTrack->GetSign() > 0) {
+ nPos++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(esdTrack->GetSign() < 0) {
+ nNeg++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(esdTrack->GetSign() == 0) nNeutr++;
- evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
- evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
- evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
- evTag->SetNumOfParticipants(esd->GetZDCParticipants());
+ //PID
+ Double_t prob[5];
+ esdTrack->GetESDpid(prob);
+ Double_t rcc = 0.0;
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
+ if(rcc == 0.0) continue;
+ //Bayes' formula
+ Double_t w[5];
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
- evTag->SetNumOfTracks(esd->GetNumberOfTracks());
- evTag->SetNumOfPosTracks(Npos);
- evTag->SetNumOfNegTracks(Nneg);
- evTag->SetNumOfNeutrTracks(Nneutr);
+ //protons
+ if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
+ //kaons
+ if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
+ //pions
+ if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
+ //electrons
+ if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
+ nElectrons++;
+ if(fPt > fLowPtCut) nEl1GeV++;
+ if(fPt > fHighPtCut) nEl3GeV++;
+ if(fPt > fVeryHighPtCut) nEl10GeV++;
+ }
+ ntrack++;
+ }//esd track loop
+
+ /////////////
+ //muon code//
+ ////////////
+ Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
+ // loop over all reconstructed tracks (also first track of combination)
+ for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
+ AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
+ if (muonTrack == 0x0) continue;
- evTag->SetNumOfV0s(esd->GetNumberOfV0s());
- evTag->SetNumOfCascades(esd->GetNumberOfCascades());
- evTag->SetNumOfKinks(esd->GetNumberOfKinks());
- evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
+ // Coordinates at vertex
+ fZ = muonTrack->GetZ();
+ fY = muonTrack->GetBendingCoor();
+ fX = muonTrack->GetNonBendingCoor();
- evTag->SetNumOfProtons(NProtons);
- evTag->SetNumOfKaons(NKaons);
- evTag->SetNumOfPions(NPions);
- evTag->SetNumOfMuons(NMuons);
- evTag->SetNumOfElectrons(NElectrons);
- evTag->SetNumOfPhotons(Ngamas);
- evTag->SetNumOfPi0s(Npi0s);
- evTag->SetNumOfNeutrons(Nneutrons);
- evTag->SetNumOfKaon0s(NK0s);
+ fThetaX = muonTrack->GetThetaX();
+ fThetaY = muonTrack->GetThetaY();
- evTag->SetNumOfChargedAbove1GeV(Nch1GeV);
- evTag->SetNumOfChargedAbove3GeV(Nch3GeV);
- evTag->SetNumOfChargedAbove10GeV(Nch10GeV);
- evTag->SetNumOfMuonsAbove1GeV(Nmu1GeV);
- evTag->SetNumOfMuonsAbove3GeV(Nmu3GeV);
- evTag->SetNumOfMuonsAbove10GeV(Nmu10GeV);
- evTag->SetNumOfElectronsAbove1GeV(Nel1GeV);
- evTag->SetNumOfElectronsAbove3GeV(Nel3GeV);
- evTag->SetNumOfElectronsAbove10GeV(Nel10GeV);
+ fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
+ fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
+ fPxRec = fPzRec * TMath::Tan(fThetaX);
+ fPyRec = fPzRec * TMath::Tan(fThetaY);
+ fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
- evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
- evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
+ //ChiSquare of the track if needed
+ fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
+ fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
+ fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
- evTag->SetTotalMomentum(TotalP);
- evTag->SetMeanPt(MeanPt);
- evTag->SetMaxPt(MaxPt);
-
- tag->AddEventTag(evTag);
- }
- lastEvent = i_NumberOfEvents;
+ // total number of muons inside a vertex cut
+ if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
+ nMuons++;
+ if(fEPvector.Pt() > fLowPtCut) {
+ nMu1GeV++;
+ if(fEPvector.Pt() > fHighPtCut) {
+ nMu3GeV++;
+ if (fEPvector.Pt() > fVeryHighPtCut) {
+ nMu10GeV++;
+ }
+ }
+ }
+ }
+ }//muon track loop
+
+ // Fill the event tags
+ if(ntrack != 0) meanPt = meanPt/ntrack;
+
+ evTag->SetEventId(iEventNumber+1);
+ evTag->SetPath(filepath);
+
+ evTag->SetVertexX(vertexIn->GetXv());
+ evTag->SetVertexY(vertexIn->GetYv());
+ evTag->SetVertexZ(vertexIn->GetZv());
+ evTag->SetVertexZError(vertexIn->GetZRes());
+ evTag->SetVertexFlag(fVertexflag);
+
+ evTag->SetT0VertexZ(esd->GetT0zVertex());
+
+ evTag->SetTriggerMask(esd->GetTriggerMask());
+ evTag->SetTriggerCluster(esd->GetTriggerCluster());
+
+ evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
+ evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
+ evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
+ evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
+ evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
+ evTag->SetNumOfParticipants(esd->GetZDCParticipants());
+
+
+ evTag->SetNumOfTracks(esd->GetNumberOfTracks());
+ evTag->SetNumOfPosTracks(nPos);
+ evTag->SetNumOfNegTracks(nNeg);
+ evTag->SetNumOfNeutrTracks(nNeutr);
+
+ evTag->SetNumOfV0s(esd->GetNumberOfV0s());
+ evTag->SetNumOfCascades(esd->GetNumberOfCascades());
+ evTag->SetNumOfKinks(esd->GetNumberOfKinks());
+ evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
+
+ evTag->SetNumOfProtons(nProtons);
+ evTag->SetNumOfKaons(nKaons);
+ evTag->SetNumOfPions(nPions);
+ evTag->SetNumOfMuons(nMuons);
+ evTag->SetNumOfElectrons(nElectrons);
+ evTag->SetNumOfPhotons(nGamas);
+ evTag->SetNumOfPi0s(nPi0s);
+ evTag->SetNumOfNeutrons(nNeutrons);
+ evTag->SetNumOfKaon0s(nK0s);
+
+ evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
+ evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
+ evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
+ evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
+ evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
+ evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
+ evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
+ evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
+ evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
+
+ evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
+ evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
+
+ evTag->SetTotalMomentum(totalP);
+ evTag->SetMeanPt(meanPt);
+ evTag->SetMaxPt(maxPt);
+
+ tag->SetRunId(iInitRunNumber);
+ if(fIsSim) tag->SetDataType(0);
+ else tag->SetDataType(1);
+ tag->AddEventTag(*evTag);
+ }//event loop
+ lastEvent = iNumberOfEvents;
t->Delete("");
-
+
ttag.Fill();
tag->Clear();
- TString LocalfileName = "Run"; LocalfileName += tag->GetRunId();
- LocalfileName += ".Event"; LocalfileName += firstEvent; LocalfileName += "_"; LocalfileName += lastEvent; LocalfileName += "."; LocalfileName += Counter;
- LocalfileName += ".ESD.tag.root";
+ TString localFileName = "Run"; localFileName += tag->GetRunId();
+ localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
+ localFileName += ".ESD.tag.root";
- cout<<"Writing tags to local file: "<<LocalfileName<<endl;
+ 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(LocalfileName, "recreate");
+ TFile* ftag = TFile::Open(fileName, "recreate");
ftag->cd();
ttag.Write();
ftag->Close();
delete esd;
delete tag;
- delete detTag;
- delete evTag;
}
-//_____________________________________________________________________________
-Bool_t AliTagCreator::StoreGridTagFile(const char *localpath, const char *gridpath)
-{
- gSystem->Load("libThread.so");
- gSystem->Load("libTreePlayer.so");
- gSystem->Load("libProof.so");
- cout<<"Storing tag file to alien's file catalog..."<<endl;
- TFileMerger merger;
- const char * pattern = "tag.root";
+//__________________________________________________________________________
+void AliTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent) {
+ //creates tag files for AODs
+
+ Float_t fLowPtCut = 1.0;
+ Float_t fHighPtCut = 3.0;
+ Float_t fVeryHighPtCut = 10.0;
+ ////////////
+
+ Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
+
+ // Creates the tags for all the events in a given ESD file
+ Int_t ntrack;
+ Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
+ Int_t nPos, nNeg, nNeutr;
+ Int_t nKinks, nV0s, nCascades;
+ 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;
+
+ AliRunTag *tag = new AliRunTag();
+ TTree ttag("T","A Tree with event tags");
+ TBranch * btag = ttag.Branch("AliTAG", &tag);
+ btag->SetCompressionLevel(9);
+
+ //reading the esd tag file
+ TChain *oldTagTree = new TChain("T");
+ const char * tagPattern = "ESD.tag";
// Open the working directory
- void * dirp = gSystem->OpenDirectory(localpath);
+ void * dirp = gSystem->OpenDirectory(gSystem->pwd());
const char * name = 0x0;
- TString AlienLocation;
- Char_t LocalLocation[256];
-
// Add all files matching *pattern* to the chain
- while((name = gSystem->GetDirEntry(dirp)))
- {
- if (strstr(name,pattern))
- {
- sprintf(LocalLocation,"file:%s/%s",localpath,name);
- AlienLocation = "/alien";
- AlienLocation += gGrid->Pwd();
- AlienLocation += gridpath;
- AlienLocation += "/";
- AlienLocation += name;
- AlienLocation += "?se=";
- AlienLocation += fSE.Data();
- merger.Cp(LocalLocation,AlienLocation);
-
+ while((name = gSystem->GetDirEntry(dirp))) {
+ if (strstr(name,tagPattern)) oldTagTree->Add(name);
+ }//directory loop
+ AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
+
+ //reading the esd tag file
+ AliRunTag *oldtag = new AliRunTag();
+ TString tagFilename;
+ oldTagTree->SetBranchAddress("AliTAG",&oldtag);
+ oldTagTree->GetEntry(0);
+ tag->CopyStandardContent(oldtag);
+ const TClonesArray *evTagList = oldtag->GetEventTags();
+
+ cout<<"Creating the tags......."<<endl;
+
+ TFile *file = TFile::Open("AliAOD.root");
+ if (!file || !file->IsOpen()) {
+ AliError(Form("opening failed"));
+ delete file;
+ return ;
+ }
+ TTree *aodTree = (TTree*)file->Get("AOD");
+ AliAODEvent *aod = (AliAODEvent*)aodTree->GetUserInfo()->FindObject("AliAODEvent");
+ TIter next(aod->GetList());
+ TObject *el;
+
+ Int_t lastEvent = 0;
+ if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
+ else lastEvent = fLastEvent;
+
+ while((el=(TNamed*)next()))
+ aodTree->SetBranchAddress(el->GetName(),aod->GetList()->GetObjectRef(el));
+
+ // loop over events
+ Int_t nEvents = aodTree->GetEntries();
+ for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
+ AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
+ ntrack = 0;
+ nPos = 0; nNeg = 0; nNeutr =0;
+ nKinks = 0; nV0s = 0; nCascades = 0;
+ nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
+ nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 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;
+
+ // read events
+ aodTree->GetEvent(iEventNumber);
+
+ // set pointers
+ aod->GetStdContent();
+
+ Int_t nTracks = aod->GetNTracks();
+ cout << "Event: " << iEventNumber+1 << "/" << nEvents <<" - Tracks: "<<nTracks<< endl;
+ // loop over vertices
+ Int_t nVtxs = aod->GetNVertices();
+ for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
+ // print track info
+ AliAODVertex *vertex = aod->GetVertex(nVtx);
+ if(vertex->GetType() == 1) nKinks += 1;
+ if(vertex->GetType() == 2) nV0s += 1;
+ if(vertex->GetType() == 3) nCascades += 1;
+ }
+ for (Int_t nTr = 0; nTr < nTracks; nTr++) {
+ AliAODTrack *track = aod->GetTrack(nTr);
+
+ Double_t fPt = track->Pt();
+ if(fPt > maxPt) maxPt = fPt;
+ if(track->Charge() > 0) {
+ nPos++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(track->Charge() < 0) {
+ nNeg++;
+ if(fPt > fLowPtCut) nCh1GeV++;
+ if(fPt > fHighPtCut) nCh3GeV++;
+ if(fPt > fVeryHighPtCut) nCh10GeV++;
+ }
+ if(track->Charge() == 0) nNeutr++;
+
+ //PID
+ const Double32_t *prob = track->PID();
+ Double_t rcc = 0.0;
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
+ if(rcc == 0.0) continue;
+ //Bayes' formula
+ Double_t w[10];
+ for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
+
+ //protons
+ if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
+ //kaons
+ if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
+ //pions
+ if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
+ //muons
+ if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
+ nMuons++;
+ if(fPt > fLowPtCut) nMu1GeV++;
+ if(fPt > fHighPtCut) nMu3GeV++;
+ if(fPt > fVeryHighPtCut) nMu10GeV++;
}
- }
- gSystem->FreeDirectory(dirp);
-
- return kTRUE;
+ //electrons
+ if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
+ nElectrons++;
+ if(fPt > fLowPtCut) nEl1GeV++;
+ if(fPt > fHighPtCut) nEl3GeV++;
+ if(fPt > fVeryHighPtCut) nEl10GeV++;
+ }
+
+ totalP += track->P();
+ meanPt += fPt;
+ ntrack++;
+ }//track loop
+ // Fill the event tags
+ if(ntrack != 0)
+ meanPt = meanPt/ntrack;
+
+ evTag->SetEventId(iEventNumber+1);
+
+ evTag->SetNumOfTracks(nTracks);
+ evTag->SetNumOfPosTracks(nPos);
+ evTag->SetNumOfNegTracks(nNeg);
+ evTag->SetNumOfNeutrTracks(nNeutr);
+
+ evTag->SetNumOfV0s(nV0s);
+ evTag->SetNumOfCascades(nCascades);
+ evTag->SetNumOfKinks(nKinks);
+
+ evTag->SetNumOfProtons(nProtons);
+ evTag->SetNumOfKaons(nKaons);
+ evTag->SetNumOfPions(nPions);
+ evTag->SetNumOfMuons(nMuons);
+ evTag->SetNumOfElectrons(nElectrons);
+ evTag->SetNumOfPhotons(nGamas);
+ evTag->SetNumOfPi0s(nPi0s);
+ evTag->SetNumOfNeutrons(nNeutrons);
+ evTag->SetNumOfKaon0s(nK0s);
+
+ evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
+ evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
+ evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
+ evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
+ evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
+ evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
+ evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
+ evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
+ evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
+
+ evTag->SetTotalMomentum(totalP);
+ evTag->SetMeanPt(meanPt);
+ evTag->SetMaxPt(maxPt);
+ tag->AddEventTag(*evTag);
+ }//event loop
+ if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
+ else lastEvent = fLastEvent;
+
+ ttag.Fill();
+ tag->Clear();
+
+ char fileName[256];
+ sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root",
+ tag->GetRunId(),fFirstEvent,lastEvent );
+ cout<<"writing tags to file "<<fileName<<endl;
+ AliDebug(1, Form("writing tags to file %s", fileName));
+
+ TFile* ftag = TFile::Open(fileName, "recreate");
+ ftag->cd();
+ ttag.Write();
+ ftag->Close();
+ file->cd();
+ file->Close();
}