11 #include <TSelector.h>
14 # include <TParticle.h>
21 # include <TClonesArray.h>
24 # include <TStopwatch.h>
27 # include <TLegendEntry.h>
28 # include <TMultiGraph.h>
32 # include <TParameter.h>
127 if (gROOT->IsBatch()) {
128 Warning(
"SetupMonitor",
"Batch processing, no monitoring");
134 Info(
"SetupMonitor",
"Monitoring frequency too low");
141 if (!objs || objs->GetEntries() < 1) {
142 Info(
"SetupMonitor",
"No monitored objects defined");
149 while ((obj = next())) monitor->
Register(obj);
185 Warning(
"SetupEstimator",
"Using fixed estimator");
186 Double_t bs[] = { 0, 1.57, 2.22, 2.71, 3.13,
187 3.50, 4.94, 6.05, 6.98, 7.81,
188 8.55, 9.23, 9.88, 10.47, 11.04,
189 11.58, 12.09, 12.58, 13.05, 13.52,
190 13.97, 14.43, 14.96, 15.67, 20.00 };
191 Double_t cs[] = { 0.5, 1.5, 2.5, 3.5, 4.5,
192 7.5, 12.5, 17.5, 22.5, 27.5,
193 32.5, 37.5, 42.5, 47.5, 52.5,
194 57.5, 62.5, 67.5, 72.5, 77.5,
195 82.5, 87.5, 92.5, 97.5 };
196 TH1* h =
new TH1D(
"rawB",
"B to Centrality", 28, bs);
198 h->SetXTitle(
"b\\hbox{ [fm]}");
199 h->SetYTitle(
"c\\hbox{ [\\%]}");
200 h->SetBinContent(0,1);
201 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
202 h->SetBinContent(i, cs[i-1]);
209 Warning(
"SetupEstimator",
"No tree defined!");
212 TFile* f =
fTree->GetCurrentFile();
214 Warning(
"SetupEstimator",
"Failed to get current file from tree");
228 Warning(
"SetupEstimator",
"Failed to get %s from estimator list:",
234 if (!o->IsA()->InheritsFrom(TH1::Class())) {
235 Warning(
"SetupEstimator",
"Estimator object %s is not a histogram "
236 "but a %s", o->GetName(), o->ClassName());
251 Info(
"Init",
"Initializing with tree %p (%s)",
252 tree, (tree ? tree->ClassName() :
""));
255 TFile*
file = tree->GetCurrentFile();
256 Info(
"Init",
"Current file: (%p) %s", file,
257 (file ? file->GetName() :
""));
261 Fatal(
"Init",
"Failed to set-up branches");
281 Info(
"Notify",
"processing file: (%p) %s", file,
282 (file ? file->GetName() :
""));
283 if (!file)
return true;
286 Warning(
"Notify",
"Failed to set-up branches");
290 Warning(
"Notify",
"Failed to set-up estimator");
305 Int_t read =
fTree->GetTree()->GetEntry(entry);
306 if (read <= 0)
return false;
309 printf(
"Process event %7lld (0x%x) ",
312 if (
fVerbose) Printf(
"No accepted");
328 Printf(
"A total of %ld events accepted",
fOK);
359 Info(
"GetCentrality",
"fCentHist=%p, fCentMethod=%s cent=%f",
366 Warning(
"",
"Look-up of %f failed (%d)",
fEventMult, bin);
373 Warning(
"",
"Look-up of %f failed (%d > %d)",
fEventMult, bin, nBin);
394 return fOK = p->GetVal();
406 TObject* o = fOutput->FindObject(name);
408 Warning(
"GetOutputObject",
"Object %s not found in output", name);
412 if (cls && !o->IsA()->InheritsFrom(cls)) {
413 Warning(
"GetOutputObject",
"Object %s from output is not a %s, but a %s",
414 o->GetName(), cls->GetName(), o->ClassName());
421 if (fOutput->FindObject(
"eg"))
return;
423 Info(
"CopyEgHistogram",
"Current file: (%p) %s", file,
424 (file ? file->GetName() :
""));
426 TH1* egTitle =
static_cast<TH1*
>(file->Get(
"eg"));
428 Warning(
"CopyEgHistogram",
"No EG histogram");
431 TH1* copy =
static_cast<TH1*
>(egTitle->Clone());
432 copy->SetDirectory(0);
482 for (
Int_t iPart = 0; iPart < nParticles; iPart++) {
484 if (!oPart)
continue;
485 if (!oPart->TestBit((1<<14)) || oPart->TestBit(1<<15)) {
490 if (!oPart->TestBit((1<<16))) {
503 Printf(
"ok:%7d sec:%7d neu=%7d out:%7d total:%7d",
504 nOK, nSec, nNeut, nOut, nParticles);
569 Bool_t hasCmd = (cmd && cmd[0] !=
'\0');
571 lne.Form(
"gProof%s%s", (hasCmd ?
"->" :
""), (hasCmd ? cmd :
""));
572 Printf(
"FastAnalysis::ProofExec: %s", lne.Data());
573 return gROOT->ProcessLine(lne);
577 const char* real =
gSystem->Which(gROOT->GetMacroPath(),
578 file, kReadPermission);
580 ::Warning(
"ProofLoad",
"%s not found in load path: %s",
581 file, gROOT->GetMacroPath());
585 TString cc(opt);
if (cc ==
"-") cc =
"" ;
else cc.Prepend(
"+");
586 Long_t ret =
ProofExec(Form(
"Load(\"%s%s\",true)",real, cc.Data()));
588 ::Warning(
"ProofLoad",
"Failed to load %s%s", real, cc.Data());
610 Int_t idx = in.Index(sep);
611 if (idx == kNPOS)
return false;
614 val = in(idx+1, in.Length()-idx-1);
626 gROOT->LoadClass(
"TProof",
"libProof");
627 ret = gROOT->ProcessLine(Form(
"TProof::Reset(\"%s\")",url.GetUrl()));
628 ret = gROOT->ProcessLine(Form(
"TProof::Open(\"%s\")",url.GetUrl()));
630 Printf(
"Error: FastAnalysis::SetupProof: Failed to connect");
637 TString fwd = phy +
"/PWGLF/FORWARD/analysis2";
639 mkLib.ReplaceAll(
"-std=c++14",
"-std=c++98");
640 gROOT->SetMacroPath(Form(
"%s:%s/sim",
641 gROOT->GetMacroPath(), fwd.Data()));
642 ProofExec(Form(
"Exec(\"gSystem->SetMakeSharedLib(\\\"%s\\\")\")",
645 if (!
ProofLoad(
"FastMonitor.C", opt))
return false;
646 if (!
ProofLoad(
"FastShortHeader.C", opt))
return false;
647 if (!
ProofLoad(
"FastAnalysis.C", opt))
return false;
648 if (!
ProofLoad(
"FastCentHelper.C", opt))
return false;
649 if (!extra || extra[0] ==
'\0')
return true;
650 if (!
ProofLoad(extra, opt))
return false;
683 virtual void List()
const = 0;
687 virtual const char*
Script()
const = 0;
690 Maker(
const char* type=
"");
706 if (!instance) instance =
new Factory;
728 Bool_t help = (type.EqualTo(
"help",TString::kIgnoreCase) ||
729 type.EqualTo(
"list",TString::kIgnoreCase));
732 while ((maker = static_cast<Maker*>(next()))) {
733 if (!help && !type.EqualTo(maker->GetName(), TString::kIgnoreCase))
735 if (help) Printf(
"%s", maker->GetName());
737 subtype.EqualTo(
"help", TString::kIgnoreCase) ||
738 subtype.EqualTo(
"list", TString::kIgnoreCase)) {
752 while ((maker = static_cast<Maker*>(next()))) {
753 if (!type.EqualTo(maker->GetName(), TString::kIgnoreCase))
812 Printf(
"Error: FastAnalysis::Run: No analyser given");
817 Printf(
"Error: FastAnalysis::Run: URL %s is invalid", u.GetUrl());
821 TString treeName = u.GetAnchor();
822 if (treeName.IsNull()) treeName =
"T";
823 TFile*
file = TFile::Open(u.GetFile(),
"READ");
825 Printf(
"Error: FastAnalysis::Run: Failed to open %s",
831 TObject* o = file->Get(treeName);
833 Printf(
"Error: FastAnalysis::Run: Couldn't get %s from %s",
834 treeName.Data(), u.GetFile());
839 if (o->IsA()->InheritsFrom(TChain::Class()))
840 cret = chain->Add(static_cast<TChain*>(o));
841 else if (o->IsA()->InheritsFrom(TTree::Class()))
842 cret = chain->AddFile(u.GetFile());
843 else if (o->IsA()->InheritsFrom(TCollection::Class()))
844 cret = chain->AddFileInfoList(static_cast<TCollection*>(o));
847 Printf(
"Error: FastAnalysis::Run: Failed to create chain");
851 TString proto = u.GetProtocol();
852 Bool_t isProof = (proto.EqualTo(
"proof") || proto.EqualTo(
"lite"));
858 Printf(
"===================================================\n"
860 " Processing chain %s with selector %s\n"
861 " Max events: %lld\n"
862 " Event offset: %lld\n"
865 "===================================================",
866 chain->GetName(), a->GetName(), nev, offset, u.GetUrl());
867 if (nev < 0) nev = TChain::kBigNumber;
868 Long64_t ret = chain->Process(a,
"", nev, offset);
870 if (output && output[0] !=
'\0') {
871 TFile* out = TFile::Open(output,
"RECREATE");
872 a->GetOutputList()->Write(
"out",TObject::kSingleKey);
874 Printf(
"Saved in %s", out->GetName());
902 TObjString* token = 0;
903 TIter nextToken(opts);
904 while ((token = static_cast<TObjString*>(nextToken()))) {
906 if (str.IsNull())
continue;
908 if (str.EqualTo(
"verbose")) {
914 if (!uout.IsNull()) uout.Append(
"&");
919 if (key.EqualTo(
"events")) nev = val.Atoll();
920 else if (key.EqualTo(
"offset")) off = val.Atoll();
921 else if (key.EqualTo(
"type")) type = val;
922 else if (key.EqualTo(
"subtype")) sub = val;
923 else if (key.EqualTo(
"monitor")) monitor = val.Atoi();
925 if (!uout.IsNull()) uout.Append(
"&");
932 if (type.EqualTo(
"help",TString::kIgnoreCase) ||
933 type.EqualTo(
"list",TString::kIgnoreCase) ||
934 sub .EqualTo(
"help",TString::kIgnoreCase) ||
935 sub .EqualTo(
"list",TString::kIgnoreCase))
return false;
938 return Run(u.GetUrl(), output, a, s, nev, off, monitor, verbose, opt);
TObject * GetOutputObject(const char *name, TClass *cls)
return jsonbuilder str().c_str()
static Factory & Instance()
virtual void List() const =0
static Bool_t ProofLoad(const char *file, const char *opt)
FastAnalysis * Make(const TString &type, const TString &subtype, Int_t monitor, Bool_t verbose, TString &uout)
FastShortHeader * fHeader
virtual Bool_t SetupEstimator()
ClassDef(FastAnalysis, 1)
virtual void Begin(TTree *)
static Bool_t SetupProof(TUrl &url, const char *opt, const char *extra)
virtual Bool_t Process(Long64_t entry)
void Connect(Int_t freq=-1)
void SetVerbose(Bool_t verb)
const char * Script(const TString &type) const
Double_t GetCentrality() const
TClonesArray * fParticles
static Bool_t Run(const char *url, const char *output, FastAnalysis *a, const char *script, Long64_t nev=-1, Long64_t offset=0, Int_t monitor=-1, Bool_t verbose=false, const char *opt="")
static Bool_t Run(const char *url, const char *output, const char *opt="g")
virtual void ProcessParticles()
static Bool_t Str2KeyVal(const TString &in, TString &key, TString &val, const char sep='=')
TList * GetListOfFiles(const char *input=".")
void Register(TObject *descr, Bool_t proof=true)
virtual FastAnalysis * Make(const TString &subtype, Int_t monitor, Bool_t verbose, TString &uout)=0
virtual const char * Script() const =0
virtual Bool_t ProcessParticle(const TParticle *p)=0
virtual TList * GetMonitorObjects()
virtual void SlaveTerminate()
virtual Bool_t AcceptNeutrals() const
FastAnalysis(Bool_t verb=false, Int_t monitor=0)
virtual Bool_t ProcessHeader()=0
Maker(const char *type="")
virtual Bool_t AcceptSecondaries() const
virtual void Clear(Option_t *option="")
static Long_t ProofExec(const char *cmd=0)