10 #ifndef FASTANALYSIS_C 11 #define FASTANALYSIS_C 12 #include <TSelector.h> 15 # include <TParticle.h> 22 # include <TClonesArray.h> 25 # include <TStopwatch.h> 28 # include <TLegendEntry.h> 29 # include <TMultiGraph.h> 33 # include <TParameter.h> 135 fTrigMask = ((mask & 0xFFFF) << 16) | 0xFFFF;
137 fTrigMask = ((mask & 0xFFFF) << 0) | 0xFFFF0000;
152 if (w.EqualTo(
"INEL") || w.EqualTo(
"MBOR"))
156 else if (w.EqualTo(
"INEL>0") || w.EqualTo(
"INELGT0")) {
161 else if (w.EqualTo(
"V0AND") || w.EqualTo(
"MBAND")) {
166 Warning(
"SetTrigger",
"Unknown trigger: %s", what);
176 UInt_t orMask = (fTrigMask >> 0) & 0xFFFF;
177 UInt_t andMask = (fTrigMask >> 16) & 0xFFFF;
178 if (orMask != 0 && (orMask & bits) == 0)
return false;
179 if (andMask != 0 && (andMask & bits) != andMask)
return false;
194 if (gROOT->IsBatch()) {
195 Warning(
"SetupMonitor",
"Batch processing, no monitoring");
201 Info(
"SetupMonitor",
"Monitoring frequency too low");
208 if (!objs || objs->GetEntries() < 1) {
209 Info(
"SetupMonitor",
"No monitored objects defined");
212 Printf(
"Monitor objects are:");
218 while ((obj = next())) monitor->
Register(obj);
233 fParticles =
new TClonesArray(
"TParticle");
234 fTree->SetBranchAddress(
"header", &(fHeader->
fRunNo));
235 fTree->SetBranchAddress(
"particles", &fParticles);
236 if (!fCentMethod.IsNull()) {
237 if (fCentMethod.EqualTo(
"B") && !fTree->GetBranch(
"B"))
240 fTree->SetBranchAddress(fCentMethod, &fEventMult);
252 if (fCentMethod.IsNull())
return true;
254 Warning(
"SetupEstimator",
"Using fixed estimator");
255 Double_t bs[] = { 0, 1.57, 2.22, 2.71, 3.13,
256 3.50, 4.94, 6.05, 6.98, 7.81,
257 8.55, 9.23, 9.88, 10.47, 11.04,
258 11.58, 12.09, 12.58, 13.05, 13.52,
259 13.97, 14.43, 14.96, 15.67, 20.00 };
260 Double_t cs[] = { 0.5, 1.5, 2.5, 3.5, 4.5,
261 7.5, 12.5, 17.5, 22.5, 27.5,
262 32.5, 37.5, 42.5, 47.5, 52.5,
263 57.5, 62.5, 67.5, 72.5, 77.5,
264 82.5, 87.5, 92.5, 97.5 };
265 TH1* h =
new TH1D(
"rawB",
"B to Centrality", 28, bs);
267 h->SetXTitle(
"b\\hbox{ [fm]}");
268 h->SetYTitle(
"c\\hbox{ [\\%]}");
269 h->SetBinContent(0,1);
270 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
271 h->SetBinContent(i, cs[i-1]);
278 Warning(
"SetupEstimator",
"No tree defined!");
281 TFile* f = fTree->GetCurrentFile();
283 Warning(
"SetupEstimator",
"Failed to get current file from tree");
295 TObject* o = f->Get(Form(
"estimators/%s",fCentMethod.Data()));
297 Warning(
"SetupEstimator",
"Failed to get %s from estimator list:",
303 if (!o->IsA()->InheritsFrom(TH1::Class())) {
304 Warning(
"SetupEstimator",
"Estimator object %s is not a histogram " 305 "but a %s", o->GetName(), o->ClassName());
308 fCentHist =
static_cast<TH1*
>(o);
309 fCentHist->SetDirectory(0);
310 fTree->SetBranchAddress(fCentMethod, &fEventMult);
320 Info(
"Init",
"Initializing with tree %p (%s)",
321 tree, (tree ? tree->ClassName() :
""));
324 TFile*
file = tree->GetCurrentFile();
325 Info(
"Init",
"Current file: (%p) %s", file,
326 (file ? file->GetName() :
""));
330 Fatal(
"Init",
"Failed to set-up branches");
349 TFile*
file = fTree->GetCurrentFile();
350 Info(
"Notify",
"processing file: (%p) %s", file,
351 (file ? file->GetName() :
""));
352 if (!file)
return true;
355 Warning(
"Notify",
"Failed to set-up branches");
359 Warning(
"Notify",
"Failed to set-up estimator");
374 Int_t read = fTree->GetTree()->GetEntry(entry);
375 if (read <= 0)
return false;
378 printf(
"Process event %7lld (0x%x) ",
379 entry, fHeader->
fType);
381 if (fVerbose) Printf(
"No accepted");
397 Printf(
"A total of %ld events accepted", fOK);
405 Printf(
"Analysis object %s (%s)", GetName(), ClassName());
406 Printf(
" Tree: %p", fTree);
407 Printf(
" Header: %p", fHeader);
408 Printf(
" Particles: %p", fParticles);
409 Printf(
" Verbose: %s", fVerbose ?
"yes" :
"no");
410 Printf(
" Timer: %s", fTimer.GetName());
411 Printf(
" Event multiplicity: %d", fEventMult);
412 Printf(
" Centrality method: %s", fCentMethod.Data());
413 Printf(
" Centrality histogram: %p", fCentHist);
414 Printf(
" # accepted events: %d", fOK);
415 Printf(
" Monitor frequency: %d s", fMonitor);
416 Printf(
" Compatibility impact: %s", fCompatB ?
"yes" :
"no");
417 Printf(
" Trigger mask: And: 0x%04x Or: 0x%04x",
418 ((fTrigMask >> 16) & 0xFFFF), (fTrigMask & 0xFFFF));
445 Info(
"GetCentrality",
"fCentHist=%p, fCentMethod=%s cent=%f",
446 fCentHist, fCentMethod.Data(), fHeader->
fC);
448 if (!fCentHist)
return fHeader->
fC;
449 Int_t nBin = fCentHist->GetNbinsX();
450 Int_t bin = fCentHist->GetXaxis()->FindBin(fEventMult);
452 Warning(
"",
"Look-up of %f failed (%d)", fEventMult, bin);
455 if (bin-1 == nBin && fEventMult == fCentHist->GetXaxis()->GetXmax()) {
459 Warning(
"",
"Look-up of %f failed (%d > %d)", fEventMult, bin, nBin);
462 Double_t cent = fCentHist->GetBinContent(bin);
474 if (fOK > 0)
return fOK;
480 return fOK = p->GetVal();
492 TObject* o = fOutput->FindObject(name);
494 Warning(
"GetOutputObject",
"Object %s not found in output", name);
498 if (cls && !o->IsA()->InheritsFrom(cls)) {
499 Warning(
"GetOutputObject",
"Object %s from output is not a %s, but a %s",
500 o->GetName(), cls->GetName(), o->ClassName());
507 if (fOutput->FindObject(
"eg"))
return;
508 TFile*
file = (fTree ? fTree->GetCurrentFile() : 0);
509 Info(
"CopyEgHistogram",
"Current file: (%p) %s", file,
510 (file ? file->GetName() :
""));
512 TH1* egTitle =
static_cast<TH1*
>(file->Get(
"eg"));
514 Warning(
"CopyEgHistogram",
"No EG histogram");
517 TH1* copy =
static_cast<TH1*
>(egTitle->Clone());
518 copy->SetDirectory(0);
548 fHeader->
Clear(option);
563 Int_t nParticles = fParticles->GetEntriesFast();
568 for (
Int_t iPart = 0; iPart < nParticles; iPart++) {
569 TObject* oPart = fParticles->At(iPart);
570 if (!oPart)
continue;
571 if (!oPart->TestBit((1<<14)) || oPart->TestBit(1<<15)) {
576 if (!oPart->TestBit((1<<16))) {
589 Printf(
"ok:%7d sec:%7d neu=%7d out:%7d total:%7d",
590 nOK, nSec, nNeut, nOut, nParticles);
655 Bool_t hasCmd = (cmd && cmd[0] !=
'\0');
657 lne.Form(
"gProof%s%s", (hasCmd ?
"->" :
""), (hasCmd ? cmd :
""));
658 Printf(
"FastAnalysis::ProofExec: %s", lne.Data());
659 return gROOT->ProcessLine(lne);
663 const char* real =
gSystem->Which(gROOT->GetMacroPath(),
664 file, kReadPermission);
666 ::Warning(
"ProofLoad",
"%s not found in load path: %s",
667 file, gROOT->GetMacroPath());
671 TString cc(opt);
if (cc ==
"-") cc =
"" ;
else cc.Prepend(
"+");
672 Long_t ret =
ProofExec(Form(
"Load(\"%s%s\",true)",real, cc.Data()));
674 ::Warning(
"ProofLoad",
"Failed to load %s%s", real, cc.Data());
696 Int_t idx = in.Index(sep);
697 if (idx == kNPOS)
return false;
700 val = in(idx+1, in.Length()-idx-1);
712 gROOT->LoadClass(
"TProof",
"libProof");
713 ret = gROOT->ProcessLine(Form(
"TProof::Reset(\"%s\")",url.GetUrl()));
714 ret = gROOT->ProcessLine(Form(
"TProof::Open(\"%s\")",url.GetUrl()));
716 Printf(
"Error: FastAnalysis::SetupProof: Failed to connect");
723 TString fwd = phy +
"/PWGLF/FORWARD/analysis2";
725 mkLib.ReplaceAll(
"-std=c++14",
"-std=c++98");
726 gROOT->SetMacroPath(Form(
"%s:%s/sim",
727 gROOT->GetMacroPath(), fwd.Data()));
728 ProofExec(Form(
"Exec(\"gSystem->SetMakeSharedLib(\\\"%s\\\")\")",
731 if (!
ProofLoad(
"FastMonitor.C", opt))
return false;
732 if (!
ProofLoad(
"FastShortHeader.C", opt))
return false;
733 if (!
ProofLoad(
"FastAnalysis.C", opt))
return false;
734 if (!
ProofLoad(
"FastCentHelper.C", opt))
return false;
735 if (!extra || extra[0] ==
'\0')
return true;
736 if (!
ProofLoad(extra, opt))
return false;
769 virtual void List()
const = 0;
773 virtual const char*
Script()
const = 0;
776 Maker(
const char* type=
"");
792 if (!instance) instance =
new Factory;
814 Bool_t help = (type.EqualTo(
"help",TString::kIgnoreCase) ||
815 type.EqualTo(
"list",TString::kIgnoreCase));
818 while ((maker = static_cast<Maker*>(next()))) {
819 if (!help && !type.EqualTo(maker->GetName(), TString::kIgnoreCase))
821 if (help) Printf(
"%s", maker->GetName());
823 subtype.EqualTo(
"help", TString::kIgnoreCase) ||
824 subtype.EqualTo(
"list", TString::kIgnoreCase)) {
838 while ((maker = static_cast<Maker*>(next()))) {
839 if (!type.EqualTo(maker->GetName(), TString::kIgnoreCase))
898 Printf(
"Error: FastAnalysis::Run: No analyser given");
903 Printf(
"Error: FastAnalysis::Run: URL %s is invalid", u.GetUrl());
907 TString treeName = u.GetAnchor();
908 if (treeName.IsNull()) treeName =
"T";
909 TFile*
file = TFile::Open(u.GetFile(),
"READ");
911 Printf(
"Error: FastAnalysis::Run: Failed to open %s",
917 TObject* o = file->Get(treeName);
919 Printf(
"Error: FastAnalysis::Run: Couldn't get %s from %s",
920 treeName.Data(), u.GetFile());
925 if (o->IsA()->InheritsFrom(TChain::Class()))
926 cret = chain->Add(static_cast<TChain*>(o));
927 else if (o->IsA()->InheritsFrom(TTree::Class()))
928 cret = chain->AddFile(u.GetFile());
929 else if (o->IsA()->InheritsFrom(TCollection::Class()))
930 cret = chain->AddFileInfoList(static_cast<TCollection*>(o));
933 Printf(
"Error: FastAnalysis::Run: Failed to create chain");
937 TString proto = u.GetProtocol();
938 Bool_t isProof = (proto.EqualTo(
"proof") || proto.EqualTo(
"lite"));
944 Printf(
"===================================================\n" 946 " Processing chain %s with selector %s\n" 947 " Max events: %lld\n" 948 " Event offset: %lld\n" 951 "===================================================",
952 chain->GetName(), a->GetName(), nev, offset, u.GetUrl());
954 if (nev < 0) nev = TChain::kBigNumber;
955 Long64_t ret = chain->Process(a,
"", nev, offset);
957 if (output && output[0] !=
'\0') {
958 TFile* out = TFile::Open(output,
"RECREATE");
959 a->GetOutputList()->Write(
"out",TObject::kSingleKey);
961 Printf(
"Saved in %s", out->GetName());
989 TObjString* token = 0;
990 TIter nextToken(opts);
991 while ((token = static_cast<TObjString*>(nextToken()))) {
992 TString& str = token->String();
993 if (str.IsNull())
continue;
995 if (str.EqualTo(
"verbose")) {
1001 uopt.Add(
new TObjString(key),
new TObjString(val));
1007 if (key.EqualTo(
"events")) nev = val.Atoll();
1008 else if (key.EqualTo(
"offset")) off = val.Atoll();
1009 else if (key.EqualTo(
"type")) type = val;
1010 else if (key.EqualTo(
"subtype")) sub = val;
1011 else if (key.EqualTo(
"monitor")) monitor = val.Atoi();
1013 uopt.Add(
new TObjString(key),
new TObjString(val));
1021 if (type.EqualTo(
"help",TString::kIgnoreCase) ||
1022 type.EqualTo(
"list",TString::kIgnoreCase) ||
1023 sub .EqualTo(
"help",TString::kIgnoreCase) ||
1024 sub .EqualTo(
"list",TString::kIgnoreCase))
return false;
1028 while ((k = static_cast<TPair*>(next()))) {
1029 TObject* v = uopt.GetValue(k);
1031 if (!uout.IsNull()) uout.Append(
"&");
1032 uout.Append(Form(
"%s=%s",k->GetName(),v->GetName()));
1036 return Run(u.GetUrl(), output, a, s, nev, off, monitor, verbose,
opt);
TObject * GetOutputObject(const char *name, TClass *cls)
Bool_t CheckTrigger() const
static Factory & Instance()
virtual void List() const =0
static Bool_t ProofLoad(const char *file, const char *opt)
void SetTrigger(const char *what)
FastAnalysis * Make(const TString &type, const TString &subtype, Int_t monitor, Bool_t verbose, TMap &uout)
FastShortHeader * fHeader
virtual Bool_t SetupEstimator()
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)
virtual FastAnalysis * Make(const TString &subtype, Int_t monitor, Bool_t verbose, TMap &uout)=0
virtual Bool_t ProcessHeader()
void SetVerbose(Bool_t verb)
const char * Script(const TString &type) const
virtual void Print(Option_t *option="") 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()
void SetTrigger(UInt_t mask, Bool_t isAnd)
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 const char * Script() const =0
virtual Bool_t ProcessParticle(const TParticle *p)=0
TFile * file
TList with histograms for a given trigger.
virtual TList * GetMonitorObjects()
virtual void SlaveTerminate()
void SetTrigger(UInt_t mask)
virtual Bool_t AcceptNeutrals() const
FastAnalysis(Bool_t verb=false, Int_t monitor=0)
Maker(const char *type="")
virtual Bool_t AcceptSecondaries() const
virtual void Clear(Option_t *option="")
static Long_t ProofExec(const char *cmd=0)