From f0f294806ae9130d01d8347c26d7bac06f5a92f1 Mon Sep 17 00:00:00 2001 From: morsch Date: Tue, 3 Nov 2009 10:00:14 +0000 Subject: [PATCH] These are the changes for the propagation of the tag cut selection bookkeeping. I have tested it in the following way: - Created XML list with cut summary in, read it via the AliTagAnalysis, put it as a UserInfo object into the chain and recovered the information in the task via the ESD Handler - Checked that the same code does not crash if the tag summary information is not available in the XML list. A. Kisiel --- ANALYSIS/AliTagAnalysis.cxx | 110 +++++++++++++++++++++++++-- ANALYSIS/AliXMLCollection.cxx | 139 +++++++++++++++++++++++++++++++++- ANALYSIS/AliXMLCollection.h | 12 +++ STEER/AliESDInputHandler.cxx | 82 +++++++++++++++++++- STEER/AliESDInputHandler.h | 7 +- 5 files changed, 339 insertions(+), 11 deletions(-) diff --git a/ANALYSIS/AliTagAnalysis.cxx b/ANALYSIS/AliTagAnalysis.cxx index c9c1aa0b920..d9301874b12 100644 --- a/ANALYSIS/AliTagAnalysis.cxx +++ b/ANALYSIS/AliTagAnalysis.cxx @@ -27,6 +27,7 @@ #include #include #include +#include //ROOT-AliEn #include @@ -371,6 +372,16 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, Int_t ientry = 0; Int_t cEntries = 0; + Int_t iRejectedRun = 0; + Int_t iRejectedLHC = 0; + Int_t iRejectedDet = 0; + Int_t iRejectedEvt = 0; + + Int_t iTotalEvents = 0; + + Int_t iAcceptedEvtInFile = 0; + Int_t iRejectedEvtInFile = 0; + //Defining tag objects AliRunTag *tag = new AliRunTag; AliEventTag *evTag = new AliEventTag; @@ -388,12 +399,15 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, ientry = 0; } //Event list + iTotalEvents += tag->GetNEvents(); if ((iev == 0) || !aod) localList->Reset(); if(runTagCuts->IsAccepted(tag)) { if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) { if(detTagCuts->IsAccepted(tag->GetDetectorTags())) { Int_t iEvents = tag->GetNEvents(); const TClonesArray *tagList = tag->GetEventTags(); + iRejectedEvtInFile = 0; + iAcceptedEvtInFile = 0; for(Int_t i = 0; i < iEvents; i++) { evTag = (AliEventTag *) tagList->At(i); guid = evTag->GetGUID(); @@ -402,19 +416,34 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, if(evTagCuts->IsAccepted(evTag)) { if(aod) localList->Enter(iev); else localList->Enter(i); + iAcceptedEvtInFile++; + } + else { + iRejectedEvt++; + iRejectedEvtInFile++; } iev++; }//event loop if ((ientry == cEntries-1) || !aod) { - collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList); - iAccepted += localList->GetN(); + iAccepted += localList->GetN(); + collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile,iRejectedEvtInFile); } }//detector tag cuts + else { + iRejectedDet += tag->GetNEvents(); + } }//lhc tag cuts + else { + iRejectedLHC += tag->GetNEvents(); + } }//run tag cuts + else { + iRejectedRun += tag->GetNEvents(); + } tag->Clear(); ientry++; }//tag file loop + collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); collection->Export(); delete tag; @@ -444,12 +473,21 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, TString lfn; TEntryList* localList = new TEntryList(); - Int_t iAccepted = 0; Int_t iev = 0; Int_t ientry = 0; Int_t cEntries = 0; + Int_t iRejectedRun = 0; + Int_t iRejectedLHC = 0; + Int_t iRejectedDet = 0; + Int_t iRejectedEvt = 0; + + Int_t iTotalEvents = 0; + + Int_t iAcceptedEvtInFile = 0; + Int_t iRejectedEvtInFile = 0; + //Defining tag objects AliRunTag *tag = new AliRunTag; AliEventTag *evTag = new AliEventTag; @@ -477,12 +515,15 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, current = fChain->GetTreeNumber(); } //Event list + iTotalEvents += tag->GetNEvents(); if ((iev == 0) || !aod) localList->Reset(); if(fRunFormula->EvalInstance(iTagFiles) == 1) { if(fLHCFormula->EvalInstance(iTagFiles) == 1) { if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { Int_t iEvents = fEventFormula->GetNdata(); const TClonesArray *tagList = tag->GetEventTags(); + iRejectedEvtInFile = 0; + iAcceptedEvtInFile = 0; for(Int_t i = 0; i < iEvents; i++) { evTag = (AliEventTag *) tagList->At(i); guid = evTag->GetGUID(); @@ -491,18 +532,33 @@ Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, if(fEventFormula->EvalInstance(i) == 1) { if(aod) localList->Enter(iev); else localList->Enter(i); + iAcceptedEvtInFile++; + } + else { + iRejectedEvt++; + iRejectedEvtInFile++; } iev++; }//event loop if ((ientry == cEntries-1) || !aod) { - collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList); - iAccepted += localList->GetN(); + collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile, iRejectedEvtInFile); + iAccepted += localList->GetN(); } }//detector tag cuts + else { + iRejectedDet += tag->GetNEvents(); + } }//lhc tag cuts + else { + iRejectedLHC += tag->GetNEvents(); + } }//run tag cuts + else { + iRejectedRun += tag->GetNEvents(); + } ientry++; }//tag file loop + collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); collection->Export(); delete tag; @@ -559,6 +615,10 @@ TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, fGlobalList = new TEntryList(); AliXMLCollection *collection = AliXMLCollection::Open(collectionname); + // Tag selection summary per file + TMap *tagCutSummary = new TMap(); + tagCutSummary->SetName("TagCutSumm"); + collection->Reset(); while (collection->Next()) { AliInfo(Form("Adding: %s",collection->GetTURL(""))); @@ -568,11 +628,51 @@ TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, list->SetFileName(collection->GetTURL("")); fGlobalList->Add(list); iAccepted += list->GetN(); + if (collection->GetCutSumm()) + tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm())); } fAnalysisChain->SetEntryList(fGlobalList,"ne"); AliInfo(Form("Number of selected events: %d",iAccepted)); + TList *aUserInfo = fAnalysisChain->GetUserInfo(); + aUserInfo->Add(tagCutSummary); + + Int_t iAccEv; + Int_t iTotalEvents; + Int_t iRejRun; + Int_t iRejLHC; + Int_t iRejDet; + Int_t iRejEvt; + + collection->GetCollectionSummary(&iTotalEvents, &iAccEv, &iRejRun, &iRejLHC, &iRejDet, &iRejEvt); + + char nstr[2000]; + + sprintf(nstr, "TotalEvents=%i", iTotalEvents); + TObjString *iTotStr = new TObjString(nstr); + aUserInfo->Add(iTotStr); + + sprintf(nstr, "AcceptedEvents=%i", iAccepted); + TObjString *iAccStr = new TObjString(nstr); + aUserInfo->Add(iAccStr); + + sprintf(nstr, "RejectedRun=%i", iRejRun); + TObjString *iRejRunStr = new TObjString(nstr); + aUserInfo->Add(iRejRunStr); + + sprintf(nstr, "RejectedLHC=%i", iRejLHC); + TObjString *iRejLHCStr = new TObjString(nstr); + aUserInfo->Add(iRejLHCStr); + + sprintf(nstr, "RejectedDet=%i", iRejDet); + TObjString *iRejDetStr = new TObjString(nstr); + aUserInfo->Add(iRejDetStr); + + sprintf(nstr, "RejectedEvt=%i", iRejEvt); + TObjString *iRejEvtStr = new TObjString(nstr); + aUserInfo->Add(iRejEvtStr); + return fAnalysisChain; } diff --git a/ANALYSIS/AliXMLCollection.cxx b/ANALYSIS/AliXMLCollection.cxx index 6552806e004..356bb08758a 100644 --- a/ANALYSIS/AliXMLCollection.cxx +++ b/ANALYSIS/AliXMLCollection.cxx @@ -43,7 +43,14 @@ ClassImp(AliXMLCollection) fEventListIter(0), fCurrent(0), fCollectionName(), - fout() { + fout(), + fTotalEvents(0), + fAcceptedEvents(0), + fRejectedRun(0), + fRejectedLHC(0), + fRejectedDet(0), + fRejectedEvt(0) +{ //Default constructor } @@ -55,7 +62,13 @@ AliXMLCollection::AliXMLCollection(const char *localcollectionfile) : fEventListIter(0), fCurrent(0), fCollectionName(), - fout() + fout(), + fTotalEvents(0), + fAcceptedEvents(0), + fRejectedRun(0), + fRejectedLHC(0), + fRejectedDet(0), + fRejectedEvt(0) { // Create Alien event collection, by reading collection for the specified // file. @@ -77,7 +90,13 @@ AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection): fEventListIter(0), fCurrent(0), fCollectionName(collection.fCollectionName), - fout() + fout(), + fTotalEvents(0), + fAcceptedEvents(0), + fRejectedRun(0), + fRejectedLHC(0), + fRejectedDet(0), + fRejectedEvt(0) { //copy constructor @@ -115,6 +134,32 @@ Bool_t AliXMLCollection::WriteHeader() { return kTRUE; } +//___________________________________________________________________________ +Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt) +{ + // Write selection summary + + TString collectionSummary = ""; + + // Open the output stream + fout<<" "<GetN(); i++) { + listline += list->GetEntry(i); + listline += ","; + } + listline = listline(0,listline.Length()-1); + TString line0 = ""; + + TString line1 = "\n"; + + return kTRUE; + +} //___________________________________________________________________________ Bool_t AliXMLCollection::Export() { //Closes the stream @@ -252,6 +338,22 @@ const char *AliXMLCollection::GetLFN(const char* ) { return 0; } +//__________________________________________________________________________ +const char *AliXMLCollection::GetCutSumm() { + // Get a file's tag cuts summary. Returns 0 in case of error. + + if (fCurrent) { + TMap *obj = (TMap *) fCurrent->GetValue(""); + if (obj) { + if (obj->GetValue("cutsumm")) { + return (((TObjString *) obj->GetValue("cutsumm"))->GetName()); + } + } + } + Error("GetTagSumm", "cannot get Tag Cut Summary"); + return 0; + +} //__________________________________________________________________________ Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) { // return kTRUE if comparator overlaps with this @@ -329,7 +431,7 @@ void AliXMLCollection::ParseXML() { // files XMLNodePointer_t xfile = xml.GetChild(xevent); if (!xfile) continue; - + Bool_t firstfile=kTRUE; do { // here we have an event file @@ -343,6 +445,11 @@ void AliXMLCollection::ParseXML() { TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn")); TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid")); TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist")); + TObjString *otagsumm; + if (xml.GetAttr(xfile, "cutsumm")) + otagsumm = new TObjString(xml.GetAttr(xfile, "cutsumm")); + else + otagsumm = 0; Info("ParseXML","Collection: %s - turl: %s eventlist: %s", fXmlFile.Data(),oturl->GetName(),oevlist->GetName()); if (strcmp(oevlist->GetName(),"") != 0) { @@ -357,6 +464,8 @@ void AliXMLCollection::ParseXML() { attributes->Add(new TObjString("turl"),oturl); attributes->Add(new TObjString("lfn"),olfn); attributes->Add(new TObjString("guid"),oguid); + if (otagsumm) + attributes->Add(new TObjString("cutsumm"),otagsumm); files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes); // we add the first file always as a file without name to the map @@ -367,6 +476,28 @@ void AliXMLCollection::ParseXML() { } while ((xfile = xml.GetNext(xfile))); fEventList->Add(files); } + else { + if (xml.GetAttr(xevent, "acceptedEvents")) { + // Read list summary + fAcceptedEvents = atoi(xml.GetAttr(xevent, "acceptedEvents")); + fTotalEvents = atoi(xml.GetAttr(xevent, "totalEvent")); + fRejectedRun = atoi(xml.GetAttr(xevent, "rejectedRun")); + fRejectedLHC = atoi(xml.GetAttr(xevent, "rejectedLHC")); + fRejectedDet = atoi(xml.GetAttr(xevent, "rejectedDet")); + fRejectedEvt = atoi(xml.GetAttr(xevent, "rejectedEvt")); + } + } } while ((xevent = xml.GetNext(xevent))); } +Bool_t AliXMLCollection::GetCollectionSummary(Int_t *aTot, Int_t *aAcc, Int_t *aRejRun, Int_t *aRejLHC, Int_t *aRejDet, Int_t *aRejEvt) +{ + // Return read list summary + *aTot = fTotalEvents; + *aAcc = fAcceptedEvents; + *aRejRun = fRejectedRun; + *aRejLHC = fRejectedLHC; + *aRejDet = fRejectedDet; + *aRejEvt = fRejectedEvt; + return kTRUE; +} diff --git a/ANALYSIS/AliXMLCollection.h b/ANALYSIS/AliXMLCollection.h index f9a49e19084..4525950180d 100644 --- a/ANALYSIS/AliXMLCollection.h +++ b/ANALYSIS/AliXMLCollection.h @@ -34,7 +34,9 @@ class AliXMLCollection : public TGridCollection { //____________________________________________________// Bool_t WriteHeader(); + Bool_t WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt); Bool_t WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList *fEntryList); + Bool_t WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList *fEntryListm, Int_t accSum, Int_t rejSum); Bool_t Export(); void SetCollectionName(const char* name) {fCollectionName = name;} @@ -49,9 +51,11 @@ class AliXMLCollection : public TGridCollection { const char *GetTURL(const char *name); const char *GetLFN(const char *name); const char *GetGUID(const char *name); + const char *GetCutSumm(); TEntryList *GetEventList(const char *filename) const; TEntryList *GetEntryList(const char *filename) { return GetEventList(filename); } Bool_t OverlapCollection(TGridCollection * comparator); + Bool_t GetCollectionSummary(Int_t *aTot, Int_t *aAcc, Int_t *aRejRun, Int_t *aRejLHC, Int_t *aRejDet, Int_t *aRejEvt); static AliXMLCollection *Open(const char *localcollectionfile); @@ -65,6 +69,14 @@ class AliXMLCollection : public TGridCollection { TMap *fCurrent; // current event file map TString fCollectionName; //the name of the xml file ofstream fout; // The output stream + + // List summary information + Int_t fTotalEvents; // Total no. of events in collection + Int_t fAcceptedEvents; // No. of accepted events in collection + Int_t fRejectedRun; // No. of events rejected by Run cuts + Int_t fRejectedLHC; // No. of events rejected by LHC cuts + Int_t fRejectedDet; // No. of events rejected by Detector cuts + Int_t fRejectedEvt; // No. of events rejected by Event cuts AliXMLCollection & operator=(const AliXMLCollection & ) {return *this;} diff --git a/STEER/AliESDInputHandler.cxx b/STEER/AliESDInputHandler.cxx index d2ab9338d02..f36a94a32b8 100644 --- a/STEER/AliESDInputHandler.cxx +++ b/STEER/AliESDInputHandler.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include "AliESDInputHandler.h" #include "AliESDEvent.h" @@ -50,6 +51,7 @@ AliESDInputHandler::AliESDInputHandler() : fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), + fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), @@ -68,7 +70,7 @@ AliESDInputHandler::~AliESDInputHandler() //______________________________________________________________________________ AliESDInputHandler::AliESDInputHandler(const char* name, const char* title): AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0), - fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0) + fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0) { // Constructor } @@ -231,3 +233,81 @@ Option_t *AliESDInputHandler::GetDataType() const // Returns handled data type. return gESDDataType; } + +Int_t AliESDInputHandler::GetNEventAcceptedInFile() +{ + // Get number of events in file accepted by the tag cuts + // return -1 if no info is available + if (!fTagCutSumm) { + TList *luo = fTree->GetUserInfo(); + if (!luo) { + AliInfo(Form("No user info in input tree - no tag cut summary\n")); + return -1; + } + for (int iluo=0; iluoGetEntries(); iluo++) { + fTagCutSumm = dynamic_cast(luo->At(iluo)); + if (fTagCutSumm) break; + } + if (!fTagCutSumm) { + AliInfo(Form("No tag summary map in input tree\n")); + return -1; + } + } + + TObjString *ostr = 0; + if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName())) + ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName()); + else { + AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName())); + return -1; + } + char *iTagInfo; + iTagInfo = strdup(ostr->GetString().Data()); + + Int_t iAcc = atoi(strtok(iTagInfo, ",")); + + AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName())); + + free(iTagInfo); + + return iAcc; +} +Int_t AliESDInputHandler::GetNEventRejectedInFile() +{ + // Get number of events in file rejected by the tag cuts + // return -1 if no info is available + if (!fTagCutSumm) { + TList *luo = fTree->GetUserInfo(); + if (!luo) { + AliInfo(Form("No user info in input tree - no tag cut summary\n")); + return -1; + } + for (int iluo=0; iluoGetEntries(); iluo++) { + fTagCutSumm = dynamic_cast(luo->At(iluo)); + if (fTagCutSumm) break; + } + if (!fTagCutSumm) { + AliInfo(Form("No tag summary map in input tree\n")); + return -1; + } + } + + TObjString *ostr = 0; + if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName())) + ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName()); + else { + AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName())); + return -1; + } + char *iTagInfo; + iTagInfo = strdup(ostr->GetString().Data()); + + strtok(iTagInfo, ","); + Int_t iRej = atoi(strtok(NULL, ",")); + + AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName())); + + free(iTagInfo); + + return iRej; +} diff --git a/STEER/AliESDInputHandler.h b/STEER/AliESDInputHandler.h index 1c09ff63807..07db470a138 100644 --- a/STEER/AliESDInputHandler.h +++ b/STEER/AliESDInputHandler.h @@ -15,7 +15,7 @@ class TChain; class TTree; class AliRunTag; - +class TMap; class AliESDInputHandler : public AliInputEventHandler { @@ -32,6 +32,9 @@ class AliESDInputHandler : public AliInputEventHandler { AliESDEvent *GetEvent() const {return fEvent;} Option_t *GetAnalysisType() const {return fAnalysisType;} Option_t *GetDataType() const; + // Tag cut summary analysis + Int_t GetNEventAcceptedInFile(); + Int_t GetNEventRejectedInFile(); // HLT analysis AliESDEvent *GetHLTEvent() const {return fHLTEvent;} TTree *GetHLTTree() const {return fHLTTree;} @@ -52,6 +55,8 @@ class AliESDInputHandler : public AliInputEventHandler { AliESDEvent *fHLTEvent; //! Pointer to the HLT Event (if present) TTree *fHLTTree; //! Pointer to the HLT Event (if present) Bool_t fUseHLT; // Flag to access HLT Events + // ESD Tag Cut Summary + TMap *fTagCutSumm; //! Tag cut summary map // ESD Tags (optional) Bool_t fUseTags; // Flag to use tags TChain *fChainT; //! File with event tags -- 2.43.0