]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/Macros/AliTRDdisplayDigits3D.C
Move macros to subdirectory
[u/mrichter/AliRoot.git] / TRD / Macros / AliTRDdisplayDigits3D.C
1 //_____________________________________________________________________________
2 Int_t AliTRDdisplayDigits3D(Int_t event = 0, Int_t thresh = 2
3                           , Bool_t sdigits = kFALSE) 
4 {
5   //  
6   //  TRD digits display
7   //
8   //  Input parameter:
9   //    <event>   : Event number 
10   //    <thresh>  : Threshold to suppress the noise
11   //    <sdigits> : If kTRUE it will display summable digits, normal digits otherwise.
12   //                The signal event is displayed in yellow.
13   //
14
15   Char_t *inputFile = "galice.root";
16
17   const Int_t kNdict = 3;
18
19   // Define the objects
20   AliTRDv1       *trd;
21   AliTRDgeometry *geo;
22
23   Int_t           track;
24   Int_t           idict;
25
26   TString evfoldname = AliConfig::GetDefaultEventFolderName();
27   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
28   if (!fRunLoader) {
29     fRunLoader = AliRunLoader::Open(inputFile
30                                    ,AliConfig::GetDefaultEventFolderName()
31                                    ,"UPDATE");
32   }
33   if (!fRunLoader) {
34     Printf("Can not open session for file %s.",inputFile);
35     return kFALSE;
36   }
37    
38   if (!fRunLoader->GetAliRun()) {
39     fRunLoader->LoadgAlice();
40   }
41   gAlice = fRunLoader->GetAliRun();  
42   if (!gAlice) {
43     printf("Could not find AliRun object.\n");
44     return kFALSE;
45   }
46
47   fRunLoader->GetEvent(event);
48   
49   AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
50   if (!loader) {
51     printf("Can not get TRD loader from Run Loader");
52   }
53   loader->LoadDigits();
54   
55   // Get the pointer to the detector object
56   trd = (AliTRDv1*) gAlice->GetDetector("TRD");
57
58   // Get the pointer to the geometry object
59   if (trd) {
60     geo = trd->GetGeometry();
61   }
62   else {
63     printf("Cannot find the geometry\n");
64     return 1;
65   }
66
67   AliCDBManager *cdbManager  = AliCDBManager::Instance();
68   cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
69   AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
70   calibration->SetRun(0);
71
72   TCanvas *c1 = new TCanvas("digits","TRD digits display",0,0,700,730);
73   TView   *v  = new TView(1);
74   v->SetRange(-430,-560,-430,430,560,1710);
75   c1->Clear();
76   c1->SetFillColor(1);
77   c1->SetTheta(90.0);
78   c1->SetPhi(0.0);
79
80   Int_t markerColorSignal = 2;
81   Int_t markerColorBgnd   = 7;
82   Int_t markerColorMerged = 5;
83   Int_t mask              = 10000000;
84
85   // Create the digits manager
86   AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
87   digitsManager->SetSDigits(sdigits);
88
89   // Read the digits from the file
90   if (sdigits) {
91     digitsManager->ReadDigits(loader->TreeS());
92   }
93   else {
94     if (!loader->TreeD()) {
95       printf("mist\n");
96       return kFALSE;
97     }
98     digitsManager->ReadDigits(loader->TreeD());
99   }
100
101   Int_t totalsignal = 0;
102   Int_t totalbgnd   = 0;
103   Int_t totalmerged = 0;
104   Int_t timeMax     = calibration->GetNumberOfTimeBins();
105
106   // Loop through all detectors
107   for (Int_t idet = 0; idet < geo->Ndet(); idet++) {
108
109     printf("<AliTRDdisplayDigits3D> Loading detector %d\n",idet);
110     AliTRDdataArrayI *digits  = digitsManager->GetDigits(idet);
111     digits->Expand();
112     AliTRDdataArrayI *tracks[kNdict];
113     for (Int_t idict = 0; idict < kNdict; idict++) {
114       tracks[idict] = digitsManager->GetDictionary(idet,idict);
115       tracks[idict]->Expand();
116     }
117
118     Int_t isec    = geo->GetSector(idet);
119     Int_t icha    = geo->GetChamber(idet);
120     Int_t ipla    = geo->GetPlane(idet);
121     AliTRDpadPlane *padPlane = new AliTRDpadPlane(ipla,icha);
122     Int_t  rowMax = padPlane->GetNrows();
123     Int_t  colMax = padPlane->GetNcols();
124
125     Int_t ndigits = digits->GetOverThreshold(thresh);
126
127     if (ndigits > 0) {
128
129       TPolyMarker3D *pmSignal = new TPolyMarker3D(ndigits);
130       TPolyMarker3D *pmBgnd   = new TPolyMarker3D(ndigits);
131       TPolyMarker3D *pmMerged = new TPolyMarker3D(ndigits);
132  
133       Int_t ibgnd   = 0;
134       Int_t isignal = 0;
135       Int_t imerged = 0;
136
137       for (Int_t time = 0; time < timeMax; time++) {
138         for (Int_t  col = 0;  col <  colMax;  col++) {
139           for (Int_t  row = 0;  row <  rowMax;  row++) {
140
141             Int_t type = 1;
142
143             Int_t amp = digits->GetDataUnchecked(row,col,time);
144             for (idict = 0; idict < kNdict; idict++) {
145               Int_t trk = tracks[idict]->GetDataUnchecked(row,col,time) - 1;
146               if ((idict == 0) && (trk >= mask)) {
147                 type = 2;
148               }
149               if ((type  == 1) && (trk >= mask)) {
150                 type = 3;
151               }              
152             }
153
154             if (amp > thresh) {
155           
156               Double_t glb[3];
157               Double_t loc[3];
158
159               loc[0] = row;
160               loc[1] = col;
161               loc[2] = time;
162               geo->Local2Global(idet,loc,glb);
163               Double_t x = glb[0];
164               Double_t y = glb[1];
165               Double_t z = glb[2];
166
167               if      (type == 1) {
168                 pmSignal->SetPoint(isignal,x,y,z);
169                 isignal++;
170                 totalsignal++;
171               }
172               else if (type == 2) {
173                 pmBgnd->SetPoint(ibgnd,x,y,z);
174                 ibgnd++;
175                 totalbgnd++;
176               }
177               else if (type == 3) {
178                 pmMerged->SetPoint(imerged,x,y,z);
179                 imerged++;
180                 totalmerged++;
181               }
182
183             }
184
185           }
186         }
187       }
188
189       digits->Compress(1,0);
190       for (idict = 0; idict < kNdict; idict++) {
191         tracks[idict]->Compress(1,0);
192       }
193
194       pmMerged->SetMarkerSize(1); 
195       pmMerged->SetMarkerColor(markerColorMerged);
196       pmMerged->SetMarkerStyle(1);
197       pmMerged->Draw();
198
199       pmBgnd->SetMarkerSize(1); 
200       pmBgnd->SetMarkerColor(markerColorBgnd);
201       pmBgnd->SetMarkerStyle(1);
202       pmBgnd->Draw();
203
204       pmSignal->SetMarkerSize(1); 
205       pmSignal->SetMarkerColor(markerColorSignal);
206       pmSignal->SetMarkerStyle(1);
207       pmSignal->Draw();
208    
209     }
210
211   }
212
213   delete padPlane;
214
215   TGeometry *geoAlice = gAlice->GetGeometry();
216   TNode     *main     = (TNode *) ((geoAlice->GetListOfNodes())->First());
217   TIter      next(main->GetListOfNodes());
218   TNode     *module   = 0;
219   while ((module = (TNode *) next())) {
220     Char_t ch[100];
221     sprintf(ch,"%s\n",module->GetTitle());
222     if ((ch[0] == 'T') && ((ch[1] == 'R') || (ch[1] == 'P'))) {
223       module->SetVisibility( 3);
224     }
225     else {
226       module->SetVisibility(-1);
227     }
228   }
229       
230   geoAlice->Draw("same");
231
232   c1->Modified(); 
233   c1->Update(); 
234
235   printf("<AliTRDdisplayDigits3D> Number of digits:\n");
236   printf("                        signal = %d, bgnd = %d, merged = %d\n"
237         ,totalsignal,totalbgnd,totalmerged);
238
239   return 0;
240
241 }
242