-void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) {
- //private method that creates tag files
- TString fSession = type;
- TString fguid, fmd5, fturl;
- TString fTempGuid = 0;
-
- //private method that creates tag files
- 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 AOD 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;
-
- //reading the esd tag file
- TChain *oldTagTree = new TChain("T");
- const char * tagPattern = "ESD.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)) oldTagTree->Add(name);
- }//directory loop
- AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
-
- /*if (!file || !file->IsOpen()) {
- AliError(Form("opening failed"));
- delete file;
- return ;
- }
- TTree *aodTree = (TTree*)file->Get("aodTree");*/
- AliAODEvent *aod = new AliAODEvent();
- aod->ReadFromTree(fChain);
- fChain->GetEntry(0);
- TFile *f = fChain->GetFile();
- fTempGuid = f->GetUUID().AsString();
- Int_t firstEvent = 0, lastEvent = 0;
- //lastEvent = (Int_t)aodTree->GetEntries();
-
- TString localFileName = "Run"; localFileName += aod->GetRunNumber();
- localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += fChain->GetEntries(); //localFileName += "."; localFileName += Counter;
- localFileName += ".AOD.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();
- TTree ttag("T","A Tree with event tags");
- TBranch * btag = ttag.Branch("AliTAG", &tag);
- btag->SetCompressionLevel(9);
-
- //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();
-
- AliInfo(Form("Creating the AOD tags......."));
-
- // loop over events
- Int_t nEvents = fChain->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
- fChain->GetEntry(iEventNumber);
- TFile *f = fChain->GetFile();
- const TUrl *url = f->GetEndpointUrl();
- fguid = f->GetUUID().AsString();
- if(fSession == "grid") {
- TString fturltemp = "alien://"; fturltemp += url->GetFile();
- fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
- }
- else fturl = url->GetFile();
-
- // set pointers
- aod->GetStdContent();
-
- Int_t nTracks = aod->GetNTracks();
- // loop over vertices
- Int_t nVtxs = aod->GetNVertices();
- for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
- 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++;
- }
- //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++;
- }