2 //////////////////////////////////////////////////////////////////////////
6 // Main class to control the AliFast program. //
8 // This class is a general framework for programs that needs to: //
9 // - Initialise some parameters //
10 // - Loop on events //
11 // - Print results and save histograms, etc //
13 // The event processor AliFast::Make loops on a list of Makers //
14 // where each maker performs some task on the event data and generates //
16 // New Makers can be inserted by a user without modifying this class. //
17 // Note that the order in which the Makers are called is the order //
18 // of insertion in the list of Makers. //
19 // Each Maker is responsible for creating its branch of the Tree. //
20 // The following table shows the list of makers currently implemented //
21 // The default option to Save the Maker info in the Tree is mentioned. //
23 // Maker name Save in Tree //
24 // ========== ============ //
28 // Makers must derive from the base class AliFMaker. //
29 // AliFMaker provides a common interface to all Makers. //
30 // Each Maker is responsible for defining its own parameters and //
32 // Each Maker has its own list of histograms. //
33 // Each Maker has an associated companion class corresponding to the //
34 // type of physics object reconstructed by the Maker. //
35 // For example, AliFClusterMaker creates AliFCluster objects. //
36 // AliFTriggerMaker creates one single AliFTrigger object. //
37 // The pointer supporting the created object(s) is defined in AliFMaker //
38 // fFruits may point to a single object (eg. AliFTrigger) or to a //
39 // TClonesArray of objects (eg. AliFCluster). //
41 // The function AliFast::Maketree must be called after the creation //
42 // of the AliFast object to create a Root Tree. //
44 // An example of main program/macro to use AliFast is given below: //
45 //========================================================================
46 //void umain(Int_t nevents=100)
49 // gSystem->Load("libalifast.so"); // dynamically link the compiled shared library
51 // // Open the root output file
52 // TFile file("alifast.root","recreate","AliFast root file",2);
54 // AliFast alifast("alifast"); // create main object to run alifast
56 // User user; // create an object of the User class defined in user.C
58 // alifast.Init(); // Initialise event (maker histograms,etc)
59 // alifast.MakeTree(); // Create the Root tree
61 // gROOT->LoadMacro("user.C"); // compile/interpret user file
63 // for (Int_t i=0; i<nevents; i++) {
64 // if (i%100 == 0) printf("In loop:%d\n",i);
65 // alifast.Make(i); // Generate and reconstruct event
66 // user.FillHistograms(); // User has possibility to decide if store event here!
67 // alifast.FillTree();
68 // alifast.Clear(); // Clear all event lists
72 // // save objects in Root file
73 // alifast.Write(); //save main alifast object (and run parameters)
75 //========================================================================
77 // This example illustrates how to: //
78 // - Load a shared library //
79 // - Open a Root file //
80 // - Initialise AliFast //
81 // - Load some user code (interpreted) //
82 // This user code may redefine some Maker parameters //
83 // - Make a loop on events //
84 // - Save histograms and the main AliFast object and its Makers //
86 //========================================================================
87 // An example of a User class is given below: //
88 //========================================================================
93 //////////////////////////////////////////////////////////////////////////
97 // Example of a user class to perform user specific tasks when running //
98 // the ALIfast program. //
100 // This class illustrates: //
101 // - How to set run parameters //
102 // - How to create and fill histograms //
104 //////////////////////////////////////////////////////////////////////////
108 //class AliFClusterMaker;
109 //class AliFPhotonMaker;
114 // TH1F *fhist1; //pointer to histogram
115 // TH1F *fhist2; //pointer to histogram
116 // TH1F *fhist3; //pointer to histogram
119 // void FillHistograms();
120 // void SetRunParameters();
125 //_________________________________________________________________________
128 // SetRunParameters(); //change default parameters
130 // Create a few histograms
131 // fhist1 = new TH1F("hist1","Number of tracks per event",100,0,100);
132 // fhist2 = new TH1F("hist2","Number of clusters",100,0,100);
133 // fhist3 = new TH1F("hist3","Number of isolated muons",20,0,20);
136 //_________________________________________________________________________
137 //void User::FillHistograms()
139 //// fhist1.Fill(event->GetNtracks());
140 //// fhist2.Fill(event->GetNclusters));
141 //// fhist3.Fill(event->GetNIsoMuons());
144 //_________________________________________________________________________
145 //void User::SetRunParameters()
147 // // change Alifast default parameters
149 // gAliFast->SetSmearMuonOpt(0);
150 // gAliFast->ClusterMaker()->SetGranBarrelEta(0.12);
151 // gAliFast->PhotonMaker()->SetMinPT(6.);
152 // gAliFast->TriggerMaker()->SetMuoEtaCoverage(2.8);
155 //======================end of User class=================================
157 //////////////////////////////////////////////////////////////////////////
162 #include <TBrowser.h>
163 #include <TClonesArray.h>
166 //#include "AliFMCMaker.h"
167 #include "AliFTrackMaker.h"
168 #include "AliFHistBrowser.h"
169 #include "AliFBigBang.h"
170 #include "AliFVirtualDisplay.h"
173 R__EXTERN AliRun * gAlice;
179 //_____________________________________________________________________________
180 //AliFast::AliFast() : TNamed("alifast","The ALICE fast simulation")
181 AliFast::AliFast() : AliRun("alifast","The ALICE fast simulation")
190 fDet = new AliFDet("Detector","Make AliFast detector");
192 gAlice = (AliRun*)this;
195 //_____________________________________________________________________________
196 //AliFast::AliFast(const char *name, const char *title): TNamed(name,title)
197 AliFast::AliFast(const char *name, const char *title): AliRun(name,title)
201 fVersion = 001; //AliFAST version number and release date
202 fVersionDate = 150399;
207 SetDefaultParameters();
209 gROOT->GetListOfBrowsables()->Add(this,"AliFast");
211 // create the support list for the various lists of AliFast objects
212 fMakers = new TList();
214 // create "standard" makers and add them to the list of makers (in AliFMaker constructor
215 // Note that the order in which makers are added to the list of makers is important
216 // makers will be processed in this order !!
218 //fMCMaker = new AliFMCMaker("MCMaker","Make MC events");
219 fTrackMaker = new AliFTrackMaker("TrackMaker","Make AliFast tracks");
221 fDet = new AliFDet("Detector","Make AliFast detector");
224 //_____________________________________________________________________________
227 // fMakers->Delete();
232 //______________________________________________________________________________
233 void AliFast::Browse(TBrowser *b)
238 if (fTree) b->Add(fTree,fTree->GetName());
240 b->Add(&fHistBrowser, "Histograms");
241 b->Add(&fBigBang, "BigBang");
246 while ((maker = (AliFMaker*)next())) {
247 b->Add(maker,maker->GetName());
251 //_____________________________________________________________________________
252 void AliFast::Clear(Option_t *option)
254 // Reset lists of event objects
257 while ((maker = (AliFMaker*)next())) {
258 maker->Clear(option);
260 //fca if (fDisplay) fDisplay->Clear();
263 //_____________________________________________________________________________
264 void AliFast::Draw(Option_t *option)
266 // Insert current event in graphics pad list
268 // Check if the Event Display object has been created
270 Error("Draw","You must create an AliFDisplay object first");
274 //fca fDisplay->Draw(option);
277 //_____________________________________________________________________________
278 void AliFast::GetTreeEvent(Int_t event)
280 // Read event from Tree
281 if (fTree) fTree->GetEvent(event);
285 //_____________________________________________________________________________
288 // Initialise detector
289 AliFDet *detector=gAliFast->Detector();
290 detector->InitDetParam();
295 TObject *objfirst, *objlast;
296 while ((maker = (AliFMaker*)next())) {
297 // save last created histogram in current Root directory
298 objlast = gDirectory->GetList()->Last();
303 // Add Maker histograms in Maker list of histograms
304 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
305 else objfirst = gDirectory->GetList()->First();
307 maker->Histograms()->Add(objfirst);
308 objfirst = gDirectory->GetList()->After(objfirst);
314 //_____________________________________________________________________________
315 void AliFast::Paint(Option_t *option)
317 // Paint AliFast objects
319 //fca fDisplay->Paint(option);
322 //_____________________________________________________________________________
323 void AliFast::PrintInfo()
325 // Gives information about versions etc.
327 printf("**************************************************************\n");
328 printf("* AliFast version:00%1d last update %6d *\n",
329 fVersion, fVersionDate);
330 printf("**************************************************************\n");
332 printf("* Simulates and reconstructs events on particle level *\n");
333 printf("* Package by: Yiota Foka and Elzbieta Richter-Was *\n");
334 printf("* Design based on ATLFast++ *\n");
335 printf("* by R. Brun and E. Richter-Was *\n");
336 printf("**************************************************************\n");
339 // Print info for detector geometry
340 AliFDet *detector=gAliFast->Detector();
341 detector->PrintDetInfo();
343 // Print info for all defined Makers
346 while ((maker = (AliFMaker*)next())) {
351 //_____________________________________________________________________________
352 void AliFast::FillTree()
354 // Fill the ROOT tree, looping on all active branches
356 // Clean generated particles (depending on option Save)
357 //MCMaker()->CleanParticles();
359 // Now ready to fill the Root Tree
360 if(fTree) fTree->Fill();
363 //_____________________________________________________________________________
364 void AliFast::InitChain(TChain *chain)
366 // Initialize branch addresses for all makers in a TChain
368 if (chain == 0) return;
374 while ((maker = (AliFMaker*)next())) {
375 maker->SetChainAddress(chain);
379 //_____________________________________________________________________________
380 void AliFast::MakeTree(const char* name, const char*title)
382 // Create a ROOT tree
383 // Loop on all makers to create the Root branch (if any)
387 fTree = new TTree(name,title);
391 while ((maker = (AliFMaker*)next())) {
396 //_____________________________________________________________________________
397 void AliFast::SetDefaultParameters()
400 // Setters for flags and switches
408 //_____________________________________________________________________________
409 void AliFast::Make(Int_t i)
413 // Loop on all makers
416 while ((maker = (AliFMaker*)next())) {
422 //_____________________________________________________________________________
423 void AliFast::FillClone()
425 // Fill Makers fruits clones
429 while ((maker = (AliFMaker*)next())) {
434 //_____________________________________________________________________________
435 void AliFast::Finish()
438 // place to make operations on histograms, normalization,etc.
442 while ((maker = (AliFMaker*)next())) {
447 //_____________________________________________________________________________
448 void AliFast::SortDown(Int_t n1, Float_t *a, Int_t *index, Bool_t down)
450 // sort the n1 elements of array a.
451 // In output the array index contains the indices of the sorted array.
452 // if down is false sort in increasing order (default is decreasing order)
453 // This is a translation of the CERNLIB routine sortzv (M101)
454 // based on the quicksort algorithm
456 Int_t i,i1,n,i2,i3,i33,i222,iswap,n2;
461 if (n == 1) {index[0] = 0; return;}
462 for (i=0;i<n;i++) index[i] = i+1;
463 for (i1=2;i1<=n;i1++) {
471 if (ai <= a[i22-1]) break;
480 index[n-1] = index[0];
483 if(n-1 < 0) {index[0] = i3; break;}
487 if (i2 <= n) i22 = index[i2-1];
488 if (i2-n > 0) {index[i1-1] = i3; break;}
491 if (a[i22-1] - a[i222-1] < 0) {
496 if (ai - a[i22-1] > 0) {index[i1-1] = i3; break;}
503 for (i=0;i<n1;i++) index[i]--;
506 index[i] = index[n1-i-1];
507 index[n1-i-1] = iswap;
510 //______________________________________________________________________________
511 void AliFast::Streamer(TBuffer &R__b)
513 // Stream an object of class AliFast.
515 if (R__b.IsReading()) {
516 R__b.ReadVersion(); // Version_t R__v = R__b.ReadVersion();
517 TNamed::Streamer(R__b);
518 if (!gAliFast) gAliFast = this;
519 gROOT->GetListOfBrowsables()->Add(this,"AliFast");
521 R__b >> fVersionDate;
525 fTree = (TTree*)gDirectory->Get("T");
532 R__b >> fSUSYcodeLSP;
533 R__b >> fTrackFinding;
535 fHistBrowser.Streamer(R__b);
538 R__b.WriteVersion(AliFast::IsA());
539 TNamed::Streamer(R__b);
541 R__b << fVersionDate;
552 R__b << fSUSYcodeLSP;
553 R__b << fTrackFinding;
555 fHistBrowser.Streamer(R__b);