]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/MakeFakeHits.C
Simple scripts to run various steps.
[u/mrichter/AliRoot.git] / FMD / scripts / MakeFakeHits.C
1 #include <iomanip>
2 void
3 MakeFakeHits()
4 {
5   if (!gAlice) { 
6     std::cerr << "This script must be run in AliROOT" <<std::edl;
7     return;
8   }
9   
10   // Initialize 
11   gAlice->InitMC("$ALICE_ROOT/FMD/Config.C");
12
13   // Get our detector 
14   AliFMD* fmd = gAlice->GetDetector("FMD");
15   if (!fmd) { 
16     std::cerr << "FMD object not defined" << std::endl;
17     return;
18   }
19   // Get the runloader
20   AliRunLoader* runLoader = gAlice->GetRunLoader();
21   if (!runLoader) { 
22     std::cerr << "No run loader defined" << std::end;
23     // return;
24   }
25
26   // OCDB manager
27   AliCDBManager* cdb = AliCDBManager::Instance();
28   cdb->SetDefaultStorage("local://$ALICE_ROOT")
29   cdb->SetRunNumber(0)
30
31   // Geometry database 
32   AliFMDGeometry* geom = AliFMDGeometry::Instance();
33   geom->Init();
34   geom->InitTransformations();
35
36   // Parameter database 
37   // AliFMDParameters* param = AliFMDParameters::Instance();
38   // param->Init(kFALSE, AliFMDParameters::kAltroMap);
39   AliFMDAltroMapping map;
40
41   // Monte-carlo application
42   AliMC* mc = gAlice->GetMCApp();
43   if (!mc) { 
44     std::cerr << "No MC application defined" << std::endl;
45     return;
46   }
47
48   // Make primaries - one for each strip
49   mc->BeginEvent();
50   Int_t ntr = 0;
51   for (size_t i = 0; i < 51200; i++) {
52     mc->PushTrack(1, -1, 211, 
53                   0, 0, 0, 0, 
54                   0, 0, 0, 0, 
55                   0, 0, 0, 
56                   kPPrimary, ntr);
57     // std::cout << "Made track # " << ntr << std::endl;
58   }
59
60   // Make hits
61   ntr = 0;
62   for (UShort_t d = 1; d <= 3; d++) { 
63     UShort_t nrng = (d == 1 ? 1 : 2);
64     for (UShort_t ir = 0; ir < nrng; ir++) { 
65       Char_t   r    = (ir == 0 ? 'I' : 'O');
66       UShort_t nsec = (ir == 0 ?  20 :  40);
67       UShort_t nstr = (ir == 0 ? 512 : 256);
68       for (UShort_t s = 0; s < nsec; s++) { 
69         for (UShort_t t = 0; t < nstr; t++) { 
70           mc->BeginPrimary();
71           
72           Double_t x, y, z;
73           geom->Detector2XYZ(d, r, s, t, x, y, z);
74           UInt_t ddl, board, altro, channel;
75           UShort_t timebin;
76           map.Detector2Hardware(d, r, s, t, 0, 0, 1, 
77                                 ddl, board, altro, channel, timebin);
78           Float_t e = Float_t(s) / nsec + Float_t(t)/(100*nstr);
79           e = Float_t(timebin) / 1024 * 4;
80
81           std::cout << "FMD" << d << r << "[" << std::setfill('0') 
82                     << std::setw(2) << s << "," << std::setw(3) << t 
83                     << "] " << std::setfill(' ')
84                     << std::setw(4) << timebin << " ("
85                     << std::setw(8) << x << "," 
86                     << std::setw(8) << y << "," 
87                     << std::setw(8) << z << ") -> " 
88                     << std::setw(10) << e << "\r"
89                     << std::flush;
90           fmd->AddHitByFields(ntr,     // Int_t    track,               
91                               d,       // UShort_t detector,    
92                               r,       // Char_t   ring,                
93                               s,       // UShort_t sector,      
94                               t,       // UShort_t strip,               
95                               x,       // Float_t  x=0,         
96                               y,       // Float_t  y=0,                 
97                               z,       // Float_t  z=0,         
98                               0,       // Float_t  px=0,                
99                               0,       // Float_t  py=0,                
100                               0,       // Float_t  pz=0,                
101                               e,       // Float_t  edep=0,              
102                               211,     // Int_t    pdg=0,               
103                               0,       // Float_t  t=0,                         
104                               0.03);   // Float_t  len=0,               
105           mc->FinishPrimary();         
106           ntr++;                      
107         } // Strip
108       } // Sector
109       std::cout << std::endl;
110     } // Ring 
111   } // Detector
112
113   // End of event.
114   mc->FinishEvent();
115   
116   // End of run
117   gAlice->FinishRun();
118   gGeoManager->Export("geometry.root");
119   
120 }
121
122   
123     
124       
125