]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/MediaTable.C
update from salvatore
[u/mrichter/AliRoot.git] / FMD / scripts / MediaTable.C
1 //____________________________________________________________________
2 //
3 // $Id$
4 //
5 // Script that extracts the medium numbers corresponding to each
6 // registered detector.
7 //
8 // Use the script `Compile.C' to compile this class using ACLic. 
9 //
10 /** @file    MediaTable.C
11     @author  Christian Holm Christensen <cholm@nbi.dk>
12     @date    Wed Dec 27 14:25:11 2006
13     @brief   Script to make a file with a list of medium numbers for
14     all active detectors.   
15 */
16 /** Script to make a file with a list of medium numbers for all active
17     detectors.  This should be executed in the same process as the one
18     that makes the @c galice.root file.  For example
19     @code 
20     void 
21     Simulate()
22     {
23       AliSimulation sim;
24       AliLog::SetModuleDebugLevel("FMD", 1);
25       sim.SetConfigFile("$(ALICE_ROOT)/FMD/Config.C");
26       // sim.SetMakeSDigits("FMD");
27       sim.SetMakeDigits("FMD ITS VZERO T0"); 
28       sim.SetWriteRawData("FMD"); 
29       gROOT->Macro("$(ALICE_ROOT)/FMD/scripts/MediaTable.C");
30       TStopwatch w; 
31       w.Start(); 
32       sim.Run(1);  
33       w.Stop(); 
34       w.Print(); 
35     }
36     @endcode 
37     It can also be executed after the fact, if one make sure to use
38     the same configuration file as the one used for the simulation.
39     For example 
40     @verbatim 
41     Root> gAlice->Init("$(ALICE_ROOT)/FMD/Config.C");
42     Root> .x $ALICE_ROOT/FMD/scripts/MediaTable.C 
43     Root> .q
44     @endverbatim 
45     The idea is to use the generated file to track where particles are
46     produced in the simulation.  This is needed to do background
47     studies in the FMD.  The file written contains a @c TObjArray of
48     @c TObjString objects.  The @c TObjString objects has the name of
49     the detector corresponding to the medium Id that the object is at
50     in the array.  To read the file, do for example: 
51     @code 
52     TFile*      file   = TFile::Open("mediatable.root", "READ");
53     TObjArray*  array  = (TObjArray*)(file->Get("mediatable"));
54     Int_t       n      = array->GetEntries();
55     TObjString* l      = 0;
56     Int_t       min = 0;
57     Int_t       j   = 0;
58     for (j = 0; j < n; j++) {
59       TObjString* s = static_cast<TObjString*>(array->At(j));
60       if (!l || s->Compare(l) != 0) {
61         if (l) 
62           std::cout << l->GetName() << "\t" << min 
63                     << "\t" << j - 1 << std::endl;
64         min = j;
65         l = s;
66       }
67     }
68     std::cout << l->GetName() << "\t" << min << "\t" << j << std::endl;
69     file->Close();    
70     @endcode 
71     See also the script @c BackgroundStudy.C for more on how this is
72     used in the FMD collaboration.   
73 */
74 //____________________________________________________________________
75 void 
76 MediaTable()
77 {
78   MediaMap m;
79   TFile*     file   = TFile::Open("mediatable.root", "RECREATE");
80   TObjArray* media  = gAlice->Modules();
81   AliModule* module = 0;
82   TIter next(media);
83   TObjArray* array = new TObjArray(media->GetEntries());
84   while ((module = static_cast<AliModule*>(next()))) {
85     Int_t low  = module->LoMedium();
86     Int_t high = module->HiMedium();
87     for (Int_t j = low; j <=high; j++) {
88       TObjString* o = new TObjString(module->GetName());
89       std::cout << "Adding " << j << ":\t" << o->GetName() << std::endl;
90       array->AddAtAndExpand(o, j);
91     }
92   }
93   array->Write("mediatable", TObject::kSingleKey);
94   file->Write();
95   file->Close();
96 }
97
98 //
99 // EOF
100 //