10 #define ProofNtuple_cxx
27 ProofNtuple::~ProofNtuple()
38 void ProofNtuple::PlotNtuple(TNtuple *ntp,
const char *ntptitle)
45 TCanvas *c1 =
new TCanvas(Form(
"cv-%s", ntp->GetName()), ntptitle,800,10,700,780);
47 TPad *pad1 = (TPad *) c1->GetPad(1);
48 TPad *pad2 = (TPad *) c1->GetPad(2);
55 pad1->GetFrame()->SetFillColor(15);
57 ntp->SetFillStyle(1001);
58 ntp->SetFillColor(45);
59 ntp->Draw(
"3*px+2",
"px**2+py**2>1");
60 ntp->SetFillColor(38);
61 ntp->Draw(
"2*px+2",
"pz>2",
"same");
63 ntp->Draw(
"1.3*px+2",
"(px^2+py^2>4) && py>0",
"same");
69 ntp->Draw(
"pz:py:px",
"(pz<10 && pz>6)+(pz<4 && pz>3)");
70 ntp->SetMarkerColor(4);
71 ntp->Draw(
"pz:py:px",
"pz<6 && pz>4",
"same");
72 ntp->SetMarkerColor(5);
73 ntp->Draw(
"pz:py:px",
"pz<4 && pz>3",
"same");
74 TPaveText *l2 =
new TPaveText(0.,0.6,0.9,0.95);
77 l2->AddText(
"You can interactively rotate this view in 2 ways:");
78 l2->AddText(
" - With the RotateCube in clicking in this pad");
79 l2->AddText(
" - Selecting View with x3d in the View menu");
88 void ProofNtuple::Begin(TTree * )
94 TString option = GetOption();
96 TNamed *out = (TNamed *) fInput->FindObject(
"PROOF_NTUPLE_DONT_PLOT");
97 if (out) fPlotNtuple = kFALSE;
101 void ProofNtuple::SlaveBegin(TTree * )
107 TString option = GetOption();
110 TNamed *nm =
dynamic_cast<TNamed *
>(fInput->FindObject(
"SimpleNtuple.root"));
113 UInt_t opt = TProofOutputFile::kRegister | TProofOutputFile::kOverwrite | TProofOutputFile::kVerify;
114 fProofFile =
new TProofOutputFile(
"SimpleNtuple.root",
115 TProofOutputFile::kDataset, opt, nm->GetTitle());
119 TNamed *out = (TNamed *) fInput->FindObject(
"PROOF_OUTPUTFILE_LOCATION");
120 Info(
"SlaveBegin",
"PROOF_OUTPUTFILE_LOCATION: %s", (out ? out->GetTitle() :
"undef"));
121 fProofFile =
new TProofOutputFile(
"SimpleNtuple.root", (out ? out->GetTitle() :
"M"));
122 out = (TNamed *) fInput->FindObject(
"PROOF_OUTPUTFILE");
123 if (out) fProofFile->SetOutputFileName(out->GetTitle());
127 fFile = fProofFile->OpenFile(
"RECREATE");
128 if (fFile && fFile->IsZombie()) SafeDelete(fFile);
132 Info(
"SlaveBegin",
"could not create '%s': instance is invalid!", fProofFile->GetName());
137 fNtp =
new TNtuple(
"ntuple",
"Demo ntuple",
"px:py:pz:random:i");
139 fNtp->SetDirectory(fFile);
143 fNtp2 =
new TNtuple(
"ntuple2",
"Demo ntuple2",
"vx:vy:vz");
145 fNtp2->SetDirectory(fFile);
149 TNamed *unr = (TNamed *) fInput->FindObject(
"PROOF_USE_NTP_RNDM");
152 if (!(fNtpRndm = dynamic_cast<TNtuple *>(fInput->FindObject(
"NtpRndm")))) {
153 Warning(
"SlaveBegin",
154 "asked to use rndm ntuple but 'NtpRndm' not found in the"
155 " input list! Using the random generator");
158 Info(
"SlaveBegin",
"taking randoms from input ntuple 'NtpRndm'");
163 if (!fNtpRndm) fRandom =
new TRandom3(0);
167 Bool_t ProofNtuple::Process(Long64_t entry)
187 if (!fNtp)
return kTRUE;
190 Float_t px, py, random;
193 Float_t *ar = fNtpRndm->GetArgs();
194 Long64_t ent = entry % fNtpRndm->GetEntries();
195 fNtpRndm->GetEntry(ent);
197 px = (Float_t) TMath::ErfInverse((Double_t)(ar[1]*2 - 1.)) * TMath::Sqrt(2.);
198 py = (Float_t) TMath::ErfInverse((Double_t)(ar[2]*2 - 1.)) * TMath::Sqrt(2.);
199 }
else if (fRandom) {
200 fRandom->Rannor(px,py);
201 random = fRandom->Rndm();
203 Abort(
"no way to get random numbers! Stop processing", kAbortProcess);
206 Float_t pz = px*px + py*py;
207 Int_t i = (Int_t) entry;
208 fNtp->Fill(px,py,pz,random,i);
210 if (!fNtp2)
return kTRUE;
213 Float_t vz = random * 2. - 1.;
214 fNtp2->Fill(px,py,vz);
220 void ProofNtuple::SlaveTerminate()
229 Error(
"SlaveTerminate",
"'ntuple' is undefined!");
232 Bool_t cleanup = kFALSE;
233 TDirectory *savedir = gDirectory;
234 if (fNtp->GetEntries() > 0) {
236 fNtp->Write(0, TObject::kOverwrite);
237 if (fNtp2 && fNtp2->GetEntries() > 0) fNtp2->Write(0, TObject::kOverwrite);
239 fOutput->Add(fProofFile);
243 fNtp->SetDirectory(0);
244 if (fNtp2) fNtp2->SetDirectory(0);
245 gDirectory = savedir;
249 TUrl uf(*(fFile->GetEndpointUrl()));
251 gSystem->Unlink(uf.GetFile());
252 SafeDelete(fProofFile);
258 void ProofNtuple::Terminate()
265 if (!fPlotNtuple)
return;
269 dynamic_cast<TProofOutputFile*>(fOutput->FindObject(
"SimpleNtuple.root")))) {
271 TString outputFile(fProofFile->GetOutputFileName());
272 TString outputName(fProofFile->GetName());
273 outputName +=
".root";
274 Printf(
"outputFile: %s", outputFile.Data());
277 fFile = TFile::Open(outputFile);
279 Printf(
"Managed to open file: %s", outputFile.Data());
280 fNtp = (TNtuple *) fFile->Get(
"ntuple");
282 Error(
"Terminate",
"could not open file: %s", outputFile.Data());
287 Error(
"Terminate",
"TProofOutputFile not found");
292 if (fNtp) PlotNtuple(fNtp,
"proof ntuple");