41 #include <TSelector.h>
48 # include <TLegendEntry.h>
53 # include <TClonesArray.h>
56 # include <TOutputListSelectorDataMap.h>
60 # include <TDirectory.h>
61 # include <TSystemDirectory.h>
64 # include <TFileCollection.h>
65 # include <THashList.h>
67 # include <TQConnection.h>
70 # include <TStopwatch.h>
84 class TSystemDirectory;
128 title, bins.GetSize()-1,
176 if (&o ==
this)
return *
this;
178 TObject::operator=(o);
227 for (
Int_t i = 0; i < 2; i++) {
228 if (!hists[i])
continue;
230 Int_t n = hists[i]->GetEntries();
231 if (n <= 0)
continue;
234 hists[i]->Scale(1. / n,
"width");
235 stack->Add(hists[i]);
237 if (i != 0)
continue;
240 leg->AddEntry(hists[i], hists[i]->GetTitle(),
"p");
243 TLegendEntry* e = leg->AddEntry(
"",
244 (i == 0 ?
"Primary" :
"Secondary"),
246 e->SetMarkerStyle(hists[i]->GetMarkerStyle());
247 e->SetFillStyle(hists[i]->GetFillStyle());
248 e->SetFillColor(kBlack);
264 while ((obj = nxt())) {
265 if (!obj->IsA()->InheritsFrom(this->IsA())) {
266 Warning(
"Merge",
"Will not merge a Spectra with a %s",
267 obj->IsA()->GetName());
279 Warning(
"Merge",
"Will not merge %s with %s",
304 gROOT->IncreaseDirLevel();
308 for (
Int_t i = 0; i < 2; i++)
if (hists[i]) hists[i]->ls();
309 gROOT->DecreaseDirLevel();
318 TDirectory* out = dir->mkdir(
fName);
320 fPrimary->Clone(
"primary")->Write();
351 fPrimary->SetXTitle(
"particle type");
359 fPrimary->GetXaxis()->SetBinLabel(1,
"e^{#pm}");
360 fPrimary->GetXaxis()->SetBinLabel(2,
"#pi^{#pm}");
361 fPrimary->GetXaxis()->SetBinLabel(3,
"K^{#pm}");
362 fPrimary->GetXaxis()->SetBinLabel(4,
"p/#bar{p}");
363 fPrimary->GetXaxis()->SetBinLabel(5,
"strange");
364 fPrimary->GetXaxis()->SetBinLabel(6,
"other");
367 static_cast<TH1*
>(
fPrimary->Clone(Form(
"secondary%s",name)));
417 fName(Form(
"FMD%d%c", d, r)),
458 if (&r ==
this)
return *
this;
480 if (i >
fSpectra->GetEntriesFast())
return 0;
494 if (i >
fSpectra->GetEntriesFast())
return 0;
533 return spe->
Hist(primary);
547 while ((obj = nxt())) {
548 if (!obj->IsA()->InheritsFrom(this->IsA())) {
549 Warning(
"Merge",
"Will not merge a Ring with a %s",
550 obj->IsA()->GetName());
553 Ring* oth =
static_cast<Ring*
>(obj);
554 if (oth->
fD !=
fD || oth->
fR !=
fR) {
555 Warning(
"Merge",
"Will not merge FMD%d%c with FMD%d%c",
567 while ((thsSpec = static_cast<Spectra*>(thsNext())) &&
568 (othSpec = static_cast<Spectra*>(othNext())))
569 thsSpec->
Add(othSpec);
579 Info(
"Draw",
"Should draw rings here");
590 gROOT->IncreaseDirLevel();
592 gROOT->DecreaseDirLevel();
601 TDirectory* out = dir->mkdir(
fName);
605 while ((spec = static_cast<Spectra*>(next())))
620 fName = gProof->GetSessionTag();
621 gDirectory->Add(
this);
623 Bool_t ret = gProof->Connect(
"Feedback(TList *objs)",
"Monitor",
this,
624 "Feedback(TList *objs)");
626 Warning(
"Monitor",
"Failed to connect to Proof");
631 gProof->Disconnect(
"Feedback(TList *objs)",
this,
632 "Feedback(TList* objs)");
638 Info(
"Feedback",
"Got a list of objects (%p)", objs);
684 Bool_t inner = (r ==
'i' || r ==
'I');
687 case 2:
return (inner ? 1 : 2);
688 case 3:
return (inner ? 4 : 3);
690 ::Warning(
"",
"Unknown ring FMD%d%c", d, r);
695 Info(
"Init",
"Got a tree: %p", tree);
698 Warning(
"Init",
"No tree passed");
703 fHits =
new TClonesArray(
"AliFMDMCTrackELoss::Hit");
708 Info(
"Begin",
"Called w/tree @ %p", tree);
719 Info(
"SlaveBegin",
"Got a tree: %p", tree);
745 Info(
"Notify",
"processing file: %p (%s)",
746 file, (file ? file->GetName() :
"nil"));
759 Warning(
"Process",
"No tree");
762 if (!
fTree->GetTree()) {
763 Warning(
"Process",
"No real tree");
767 fTree->GetTree()->GetEntry(entry);
777 while ((hit = static_cast<AliFMDMCTrackELoss::Hit*>(next())))
830 Printf(
"\nDone (rings=%p)",
fRings);
835 Error(
"Terminate",
"No rings in output array");
840 TFile* out = TFile::Open(
"tuple_summary.root",
"RECREATE");
859 static Int_t cnt = 1;
860 const char* name = Form(
"c%02d", cnt++);
862 TCanvas*
c =
new TCanvas(name, title, 1000, 1000);
865 c->SetTopMargin(0.01);
866 c->SetRightMargin(0.03);
868 TLegend* leg =
new TLegend(0.65, 0.65, 0.975, 0.975);
869 leg->SetFillStyle(0);
870 leg->SetBorderSize(0);
873 THStack*
stack =
new THStack(name, title);
874 for (
Int_t i = 0; i < 5; i++) {
878 Warning(
"PlotOne",
"No spectra for %d", which);
883 spec->
Stack(stack, leg);
886 if (xTitle.IsNull() && spec->
Hist(
true))
887 xTitle = spec->
Hist(
true)->GetXaxis()->GetTitle();
897 if (!stack->GetHists() ||
898 stack->GetHists()->GetEntries() < 0) {
899 Warning(
"PlotOne",
"No histograms added");
902 stack->Draw(Form(
"nostack %s", opt));
903 stack->GetHistogram()->SetXTitle(xTitle);
904 stack->GetHistogram()->GetListOfFunctions()->Add(leg);
913 TLatex* ltx =
new TLatex(0.02, 0.02,
fTitle);
915 ltx->SetTextColor(kRed+2);
916 ltx->SetTextAlign(11);
917 ltx->SetTextSize(0.02);
919 stack->GetHistogram()->GetListOfFunctions()->Add(ltx);
923 stack->Clone()->Write();
931 c->Print(Form(
"%s.pdf", name));
940 TDirectory* out = dir->mkdir(
fTitle);
944 while ((ring = static_cast<Ring*>(next())))
984 if (
gSystem->AccessPathName(file))
return 0;
986 TFile* in = TFile::Open(file,
"READ");
989 TObject* ret = in->Get(
"tree");
995 if (ret->IsA()->InheritsFrom(TChain::Class()))
996 static_cast<TChain*>(ret)->SetDirectory(0);
997 else if (ret->IsA()->InheritsFrom(TDSet::Class()))
998 static_cast<TDSet*>(ret)->SetDirectory(0);
1000 ::Warning(
"GetChainOrDataSet",
"Found object is a %s",
1001 ret->IsA()->GetName());
1021 TString dsFile(Form(
"%s/dataset.root", src.Data()));
1031 dataset =
new TDSet(*c,
false);
1032 dataset->SetName(
"tree");
1033 dataset->SetLookedUp();
1034 dataset->Validate();
1038 TFile* out = TFile::Open(dsFile,
"RECREATE");
1040 dataset->SetDirectory(0);
1061 TString chFile(Form(
"%s/chain.root", src.Data()));
1062 if (!
gSystem->AccessPathName(chFile)) {
1063 TFile* in = TFile::Open(chFile,
"READ");
1067 ret->SetDirectory(0);
1071 if (ret)
return ret;
1077 TFile* out = TFile::Open(chFile,
"RECREATE");
1079 chain->SetDirectory(0);
1101 TSystemDirectory d(
gSystem->BaseName(src.Data()), src.Data());
1102 if (!
ScanDirectory(&d, chain,
"forward_tree_*", recursive, verbose)) {
1106 else if (!chain->GetListOfFiles() ||
1107 chain->GetListOfFiles()->GetEntries() <= 0) {
1134 ::Error(
"ScanDirectory",
"No diretory passed");
1137 if (verbose) ::Info(
"ScanDirectory",
"Scanning %s", dir->GetName());
1140 TRegexp wild(pattern,
true);
1142 TList* files = dir->GetListOfFiles();
1144 if (!
gSystem->ChangeDirectory(oldDir)) {
1145 ::Error(
"ScanDirectory",
"Failed to go back to %s",
1150 ::Warning(
"ScanDirectory",
"No files");
1160 TSystemFile*
file = 0;
1161 while ((file = static_cast<TSystemFile*>(next()))) {
1162 TString name(file->GetName());
1164 TString full(
gSystem->ConcatFileName(file->GetTitle(), name.Data()));
1165 if (file->IsA()->InheritsFrom(TSystemDirectory::Class())) full =
title;
1168 if (name.EqualTo(
".")||name.EqualTo(
"..")) {
1170 if (verbose) ::Info(
"ScanDirectory",
"Ignoring special %s",
1175 if (verbose) ::Info(
"ScanDirectory",
"Looking at %s", full.Data());
1178 if (
gSystem->GetPathInfo(full.Data(), fs)) {
1179 ::Warning(
"ScanDirectory",
"Cannot stat %s (%s)",
1180 full.Data(),
gSystem->WorkingDirectory());
1184 if (file->IsDirectory(full)) {
1185 if (verbose) ::Info(
"ScanDirectory",
"Got a directory: %s",
1189 TSystemDirectory* d =
new TSystemDirectory(file->GetName(),
1199 if (!name.EndsWith(
".root") &&
1200 !name.EndsWith(
".zip",TString::kIgnoreCase)) {
1201 if (verbose) ::Info(
"ScanDirectory",
"Ignoring non-ROOT or ZIP %s",
1207 if (!name.Contains(wild)) {
1208 if (verbose) ::Info(
"ScanDirectory",
"%s does not match %s",
1209 name.Data(), pattern.Data());
1214 ::Info(
"::ScanDirectory",
"Candidate %s", full.Data());
1215 toAdd.Add(
new TObjString(full));
1217 TIter nextAdd(&toAdd);
1220 while ((s = static_cast<TObjString*>(nextAdd()))) {
1224 if (!
CheckFile(fn, chain,
true))
continue;
1228 if (added > 0) ret =
true;
1229 if (verbose) ::Info(
"ScanDirectory",
"Added %d files", added);
1231 gSystem->ChangeDirectory(oldDir);
1251 gSystem->RedirectOutput(
"/dev/null",
"w");
1252 TFile*
test = TFile::Open(fn,
"READ");
1255 ::Warning(
"CheckFile",
"Failed to open %s", fn.Data());
1260 TObject* o = test->Get(chain->GetName());
1262 TFileCollection*
c =
dynamic_cast<TFileCollection*
>(o);
1264 Int_t n = t->GetEntries();
1268 if (verbose) ::Info(
"CheckFile",
"Added file %s (%d)", fn.Data(), n);
1270 chain->AddFileInfoList(c->GetList());
1272 if (verbose) ::Info(
"CheckFile",
"Added file collection %s", fn.Data());
1275 TList* l = test->GetListOfKeys();
1278 while ((k = static_cast<TKey*>(next()))) {
1279 TString cl(k->GetClassName());
1280 if (!cl.EqualTo(
"TFileCollection"))
continue;
1281 c =
dynamic_cast<TFileCollection*
>(k->ReadObj());
1283 ::Warning(
"CheckFile",
"Returned collection invalid");
1287 chain->AddFileInfoList(c->GetList());
1289 if (verbose) ::Info(
"CheckFile",
"Added file collection %s", fn.Data());
1295 ::Warning(
"CheckFile",
1296 "The file %s does not contain the tree %s "
1297 "or a file collection",
1298 path.Data(), chain->GetName());
1311 const char*
title=
"")
1317 ::Error(
"Run",
"No chain!");
1322 Int_t status= chain->Process(s,
"", maxEvents);
1337 const char*
title=
"")
1341 TProof::Reset(
"lite:///?workers=8");
1342 TProof::Open(
"lite:///?workers=8");
1343 gProof->ClearCache();
1345 TString fwd = ali +
"/PWGLF/FORWARD/analysis2";
1346 gProof->AddIncludePath(Form(
"%s/include", ali.Data()));
1347 gProof->Load(Form(
"%s/scripts/LoadLibs.C",fwd.Data()),
true);
1348 gProof->Exec(
"LoadLibs()");
1350 gProof->Load(Form(
"%s/scripts/TupleSelector.C+%s", fwd.Data(), opt),
true);
1354 ::Error(
"Proof",
"No dataset");
1359 gProof->AddFeedback(
"rings");
1360 gProof->Process(dataset, s,
"", maxEvents);
Int_t color[]
print message on plot with ok/not ok
Spectra(const char *name, const char *title, Color_t color, const TArrayD &bins)
void Store(TDirectory *dir)
Double_t BetaGamma() const
const char * GetName() const
TH1 * Hist(Bool_t primary) const
Spectra(const Spectra &o)
TClonesArray * fHits
Must not be persistent.
Long64_t Merge(TCollection *list)
UShort_t Index(UShort_t d, Char_t r) const
void Fill(AliFMDMCTrackELoss::Hit *hit)
Ring * Get(UShort_t d, Char_t r)
TTree * fTree
Must not be persistent.
void ls(Option_t *option="") const
TList * list
TDirectory file where lists per trigger are stored in train ouput.
void Store(TDirectory *dir)
static TChain * MakeChain(const TString &src=".", Bool_t recursive=false, Bool_t verbose=false)
void SlaveBegin(TTree *tree)
static TDSet * MakeDataSet(const TString &src=".", Bool_t recursive=false, Bool_t verbose=false)
Bool_t IsElectron() const
const char * GetName() const
const Spectra * Get(UInt_t which) const
static Bool_t ScanDirectory(TSystemDirectory *dir, TChain *chain, const TString &pattern, Bool_t recursive, Bool_t verbose)
static Color_t RingColor(UShort_t d, Char_t r)
Long64_t Merge(TCollection *list)
TH1 * Hist(Bool_t primary, UShort_t which) const
const char * GetName() const
Bool_t Add(const Spectra *oth)
virtual void Stack(THStack *stack, TLegend *leg)
static TChain * DoMakeChain(const TString &src=".", Bool_t recursive=false, Bool_t verbose=false)
Spectra & operator=(const Spectra &o)
static TObject * GetChainOrDataSet(const char *file)
static Bool_t Run(Long64_t maxEvents=-1, const char *title="")
static Bool_t Proof(Long64_t maxEvents, const char *opt="", const char *title="")
void Fill(Bool_t primary, Double_t x)
TupleSelector(const char *name="")
Not persistent.
void Fill(AliFMDMCTrackELoss::Hit *hit)
Type(const char *name, const char *title, Color_t color)
const char * GetName() const
TupleSelector & operator=(const TupleSelector &)
TFile * file
TList with histograms for a given trigger.
void Draw(Option_t *opt="")
static void MakeLogScale(Int_t nBins, Int_t minOrder, Int_t maxOrder, TArrayD &bins)
TObjArray * fRings
Not persistent.
const Ring * Get(UShort_t d, Char_t r) const
Bool_t Process(Long64_t entry)
void test(int runnumber=195345)
Ring(UShort_t d, Char_t r)
Int_t fI
Must not be persistent.
void PlotOne(UShort_t which, const char *title, TDirectory *dir=0, Option_t *opt="")
void Feedback(TList *objs)
Ring & operator=(const Ring &r)
void Store(TDirectory *dir)
static Bool_t CheckFile(const TString &path, TChain *chain, Bool_t verbose)
Long64_t GetStatus() const
void ls(Option_t *option="") const
void SetName(const char *name)
Spectra * Get(UInt_t which)