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 //////////////////////////////////////////////////////////////////////////
161 #include <TBrowser.h>
167 #include "AliFTrackMaker.h"
170 R__EXTERN AliRun * gAlice;
177 //_____________________________________________________________________________
179 AliRun("alifast","The ALICE fast simulation"),
188 fDet(new AliFDet("Detector","Make AliFast detector")),
197 // Default constructor
201 gAlice = (AliRun*)this;
204 //_____________________________________________________________________________
205 AliFast::AliFast(const char *name, const char *title):
207 fVersion(1), //AliFAST version number and release date
208 fVersionDate(150399),
212 fMakers(new TList()), // support list for the lists of AliFast objects
214 fTrackMaker(new AliFTrackMaker("TrackMaker","Make AliFast tracks")),
215 fDet(new AliFDet("Detector","Make AliFast detector")), // create detectors
224 // Standard constructor
229 SetDefaultParameters();
231 gROOT->GetListOfBrowsables()->Add(this,"AliFast");
233 // create "standard" makers and add them to the list of makers
234 // (in AliFMaker constructor)
235 // Note that the order in which makers are added to the list of makers
236 // is important makers will be processed in this order !!
238 //fMCMaker = new AliFMCMaker("MCMaker","Make MC events");
242 //_______________________________________________________________________
243 AliFast::AliFast(const AliFast& afast):
262 // Copy constructor for AliRun
267 //_____________________________________________________________________________
273 // fMakers->Delete();
278 //______________________________________________________________________________
279 void AliFast::Browse(TBrowser *b)
282 // To allow browsing of the class
287 if (fTree) b->Add(fTree,fTree->GetName());
289 b->Add(&fHistBrowser, "Histograms");
290 b->Add(&fBigBang, "BigBang");
295 while ((maker = (AliFMaker*)next())) {
296 b->Add(maker,maker->GetName());
300 //_____________________________________________________________________________
301 void AliFast::Clear(Option_t *option)
304 // Reset lists of event objects
308 while ((maker = (AliFMaker*)next())) {
309 maker->Clear(option);
313 //_____________________________________________________________________________
314 void AliFast::Draw(Option_t */*option*/) const
317 // Insert current event in graphics pad list
318 // Check if the Event Display object has been created
321 Error("Draw","You must create an AliFDisplay object first");
326 //_____________________________________________________________________________
327 void AliFast::GetTreeEvent(Int_t event)
330 // Read event from Tree
332 if (fTree) fTree->GetEvent(event);
336 //_____________________________________________________________________________
340 // Initialise detector
342 AliFDet *detector=gAliFast->Detector();
343 detector->InitDetParam();
348 TObject *objfirst, *objlast;
349 while ((maker = (AliFMaker*)next())) {
350 // save last created histogram in current Root directory
351 objlast = gDirectory->GetList()->Last();
356 // Add Maker histograms in Maker list of histograms
357 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
358 else objfirst = gDirectory->GetList()->First();
360 maker->Histograms()->Add(objfirst);
361 objfirst = gDirectory->GetList()->After(objfirst);
367 //_____________________________________________________________________________
368 void AliFast::Paint(Option_t */*option*/)
371 // Paint AliFast objects
375 //_____________________________________________________________________________
376 void AliFast::PrintInfo()
379 // Gives information about versions etc.
382 printf("**************************************************************\n");
383 printf("* AliFast version:00%1d last update %6d *\n",
384 fVersion, fVersionDate);
385 printf("**************************************************************\n");
387 printf("* Simulates and reconstructs events on particle level *\n");
388 printf("* Package by: Yiota Foka and Elzbieta Richter-Was *\n");
389 printf("* Design based on ATLFast++ *\n");
390 printf("* by R. Brun and E. Richter-Was *\n");
391 printf("**************************************************************\n");
394 // Print info for detector geometry
395 AliFDet *detector=gAliFast->Detector();
396 detector->PrintDetInfo();
398 // Print info for all defined Makers
401 while ((maker = (AliFMaker*)next())) {
406 //_____________________________________________________________________________
407 void AliFast::FillTree()
410 // Fill the ROOT tree, looping on all active branches
412 // Clean generated particles (depending on option Save)
413 // MCMaker()->CleanParticles();
416 // Now ready to fill the Root Tree
417 if(fTree) fTree->Fill();
420 //_____________________________________________________________________________
421 void AliFast::InitChain(TChain *chain)
424 // Initialize branch addresses for all makers in a TChain
427 if (chain == 0) return;
433 while ((maker = (AliFMaker*)next())) {
434 maker->SetChainAddress(chain);
438 //_____________________________________________________________________________
439 void AliFast::MakeTree(const char* name, const char*title)
442 // Create a ROOT tree
443 // Loop on all makers to create the Root branch (if any)
448 fTree = new TTree(name,title);
452 while ((maker = (AliFMaker*)next())) {
457 //_____________________________________________________________________________
458 void AliFast::SetDefaultParameters()
461 // Setters for flags and switches
470 //_____________________________________________________________________________
471 void AliFast::Make(Int_t i)
478 // Loop on all makers
481 while ((maker = (AliFMaker*)next())) {
487 //_____________________________________________________________________________
488 void AliFast::FillClone()
491 // Fill Makers fruits clones
496 while ((maker = (AliFMaker*)next())) {
501 //_____________________________________________________________________________
502 void AliFast::Finish()
506 // place to make operations on histograms, normalization,etc.
511 while ((maker = (AliFMaker*)next())) {
516 //_____________________________________________________________________________
517 void AliFast::SortDown(Int_t n1, Float_t *a, Int_t *index, Bool_t down) const
519 // sort the n1 elements of array a.
520 // In output the array index contains the indices of the sorted array.
521 // if down is false sort in increasing order (default is decreasing order)
522 // This is a translation of the CERNLIB routine sortzv (M101)
523 // based on the quicksort algorithm
525 Int_t i,i1,n,i2,i3,i33,i222,iswap,n2;
530 if (n == 1) {index[0] = 0; return;}
531 for (i=0;i<n;i++) index[i] = i+1;
532 for (i1=2;i1<=n;i1++) {
540 if (ai <= a[i22-1]) break;
549 index[n-1] = index[0];
552 if(n-1 < 0) {index[0] = i3; break;}
556 if (i2 <= n) i22 = index[i2-1];
557 if (i2-n > 0) {index[i1-1] = i3; break;}
560 if (a[i22-1] - a[i222-1] < 0) {
565 if (ai - a[i22-1] > 0) {index[i1-1] = i3; break;}
572 for (i=0;i<n1;i++) index[i]--;
575 index[i] = index[n1-i-1];
576 index[n1-i-1] = iswap;
579 //______________________________________________________________________________
580 void AliFast::Streamer(TBuffer &R__b)
583 // Stream an object of class AliFast.
585 if (R__b.IsReading()) {
587 if (!gAliFast) gAliFast = this;
588 gROOT->GetListOfBrowsables()->Add(this,"AliFast");
590 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
592 AliFast::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
594 fTree = (TTree*)gDirectory->Get("T");
596 AliFast::Class()->WriteBuffer(R__b,this);