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
#include <TEventList.h>
#include <TEntryList.h>
#include <TTreeFormula.h>
+#include <TMap.h>
//ROOT-AliEn
#include <TGridResult.h>
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;
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();
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;
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;
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();
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;
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("")));
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;
}
fEventListIter(0),
fCurrent(0),
fCollectionName(),
- fout() {
+ fout(),
+ fTotalEvents(0),
+ fAcceptedEvents(0),
+ fRejectedRun(0),
+ fRejectedLHC(0),
+ fRejectedDet(0),
+ fRejectedEvt(0)
+{
//Default constructor
}
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.
fEventListIter(0),
fCurrent(0),
fCollectionName(collection.fCollectionName),
- fout()
+ fout(),
+ fTotalEvents(0),
+ fAcceptedEvents(0),
+ fRejectedRun(0),
+ fRejectedLHC(0),
+ fRejectedDet(0),
+ fRejectedEvt(0)
{
//copy constructor
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 = "<summary";
+ collectionSummary += " acceptedEvents=\"";
+ collectionSummary += aAccepted;
+ collectionSummary += "\" totalEvent=\"";
+ collectionSummary += aTotal;
+ collectionSummary += "\" rejectedRun=\"";
+ collectionSummary += aRejRun;
+ collectionSummary += "\" rejectedLHC=\"";
+ collectionSummary += aRejLHC;
+ collectionSummary += "\" rejectedDet=\"";
+ collectionSummary += aRejDet;
+ collectionSummary += "\" rejectedEvt=\"";
+ collectionSummary += aRejEvt;
+ collectionSummary += "\" />";
+
+ // Open the output stream
+ fout<<" "<<collectionSummary<<"\n";
+
+ return kTRUE;
+}
+
//___________________________________________________________________________
Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
//Writes the body of the xml collection
return kTRUE;
}
+//___________________________________________________________________________
+Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList *list, Int_t accSum, Int_t rejSum)
+{
+ //Writes the body of the xml collection with tag cuts summary
+ TString listline;
+ for(Int_t i = 0; i < list->GetN(); i++) {
+ listline += list->GetEntry(i);
+ listline += ",";
+ }
+ listline = listline(0,listline.Length()-1);
+ TString line0 = "<event name=\"";
+ line0 += counter;
+ line0 += "\">";
+
+ TString line1 = "<file name=\"AliESDs.root\" ";
+ line1 += "guid=\"";
+ line1 += guid;
+ line1 += "\" ";
+ line1 += "lfn=\"";
+ line1 += lfn;
+ line1 += "\" ";
+ line1 += "turl=\"";
+ line1 += turl;
+ line1 += "\" ";
+ line1 += "evlist=\"";
+ line1 += listline;
+ line1 += "\" ";
+ line1 += "cutsumm=\"";
+ line1 += accSum;
+ line1 += ",";
+ line1 += rejSum;
+ line1 += "\"";
+ line1 += " />";
+
+ fout<<" "<<line0<<"\n";
+ fout<<" "<<line1<<"\n";
+ fout<<" </event>\n";
+
+ return kTRUE;
+
+}
//___________________________________________________________________________
Bool_t AliXMLCollection::Export() {
//Closes the stream
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
// files
XMLNodePointer_t xfile = xml.GetChild(xevent);
if (!xfile) continue;
-
+
Bool_t firstfile=kTRUE;
do {
// here we have an event file
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) {
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
} 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;
+}
//____________________________________________________//
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;}
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);
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;}
#include <TString.h>
#include <TObjString.h>
#include <TProcessID.h>
+#include <TMap.h>
#include "AliESDInputHandler.h"
#include "AliESDEvent.h"
fHLTEvent(0x0),
fHLTTree(0x0),
fUseHLT(kFALSE),
+ fTagCutSumm(0x0),
fUseTags(kFALSE),
fChainT(0),
fTreeT(0),
//______________________________________________________________________________
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
}
// 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; iluo<luo->GetEntries(); iluo++) {
+ fTagCutSumm = dynamic_cast<TMap *>(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; iluo<luo->GetEntries(); iluo++) {
+ fTagCutSumm = dynamic_cast<TMap *>(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;
+}
class TChain;
class TTree;
class AliRunTag;
-
+class TMap;
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;}
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