]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/DrawHitPatterns.C
TPC ALTRO mapping class
[u/mrichter/AliRoot.git] / FMD / scripts / DrawHitPatterns.C
1 //
2 // $Id$
3 //
4 // Script that contains a class to draw hits, using the
5 // AliFMDInputHits class in the util library. 
6 //
7 // It draws the energy loss versus the p/(mq^2).  It can be overlayed
8 // with the Bethe-Bloc curve to show how the simulation behaves
9 // relative to the expected. 
10 //
11 // Use the script `Compile.C' to compile this class using ACLic. 
12 //
13 #include <TH2D.h>
14 #include <AliFMDHit.h>
15 #include <AliFMDInput.h>
16 #include <iostream>
17 #include <TStyle.h>
18 #include <TArrayF.h>
19 #include <TMarker3DBox.h>
20 #include <TGeoManager.h>
21 #include <TMath.h>
22 #include <TApplication.h>
23 #include <TButton.h>
24 #include <TParticle.h>
25 #include <TCanvas.h>
26 #include <TView.h>
27 #include <TVirtualX.h>
28
29 class DrawHitPatterns : public AliFMDInputHits
30 {
31 private:
32   Bool_t     fWait;
33   Bool_t     fPrimary;
34   Int_t      fPdg;
35   TObjArray* fMarkers;
36   TObjArray* fHits;
37   TCanvas*   fCanvas;
38   TPad*      fPad;
39   TButton*   fButton;
40   TButton*   fZoom;
41   TButton*   fPick;
42   Bool_t     fZoomMode;
43 public:
44   static DrawHitPatterns* fgInstance;
45   DrawHitPatterns(Bool_t primary=kTRUE, Int_t pdg=211) 
46     : fPrimary(primary), fPdg(pdg), 
47       fCanvas(0), fPad(0), fButton(0)
48   { 
49     AddLoad(kKinematics);
50     AddLoad(kGeometry);
51     fMarkers = new TObjArray;
52     fHits    = new TObjArray;
53     fMarkers->SetOwner(kTRUE);
54     fHits->SetOwner(kFALSE);
55     fgInstance = this;
56   }
57   void Continue() { fWait = kFALSE; }
58   void Zoom() { fZoomMode = kTRUE; }
59   void Pick() { fZoomMode = kFALSE; }
60   void ExecuteEvent(Int_t event, Int_t px, Int_t py) 
61   {
62     Info("ExecuteEvent", "Event %d, at (%d,%d)", px, py);
63     static Float_t x0, y0, x1, y1;
64     static Int_t   px0, py0, pxOld,pyOld;
65     static Bool_t  lineDraw;
66     if (px == 0 && py == 0) return;
67     if (!fZoomMode && fPad->GetView()) {
68       fPad->GetView()->ExecuteRotateView(event, px, py);
69       return;
70     }
71     gPad->SetCursor(kCross);
72     switch (event) {
73     case kButton1Down: 
74       gPad->TAttLine::Modify();
75       x0 = fPad->AbsPixeltoX(px);
76       y0 = fPad->AbsPixeltoY(py);
77       px0 = pxOld = px;
78       py0 = pyOld = py;
79       lineDraw = kFALSE;
80       return;
81     case kButton1Motion:
82       if (lineDraw) 
83         gVirtualX->DrawBox(px0, py0, pxOld, pyOld, TVirtualX::kHollow);
84       pxOld = px;
85       pyOld = py;
86       lineDraw = kTRUE;
87       gVirtualX->DrawBox(px0, py0, pxOld, pyOld, TVirtualX::kHollow);
88       return;
89     case kButton1Up:
90       fPad->GetCanvas()->FeedbackMode(kFALSE);
91       if (px == px0 || py == py0) return;
92       x1 = gPad->AbsPixeltoX(px);
93       y1 = gPad->AbsPixeltoY(py);
94       if (x1 < x0) std::swap(x0, x1); 
95       if (y1 < y0) std::swap(y0, y1); 
96       gPad->Range(x0, y0, x1, y1);
97       gPad->Modified();
98       return;
99     }
100   }
101   Int_t  DistanceToPrimitive(Int_t px, Int_t py) 
102   {
103     Info("DistanceToPrimitive", "@ (%d,%d)", px, py);
104     gPad->SetCursor(kCross);
105     Float_t xmin = gPad->GetX1();
106     Float_t xmax = gPad->GetX2();
107     Float_t dx   = .02 * (xmax - xmin);
108     Float_t x    = gPad->AbsPixeltoX(px);
109     if (x < xmin + dx || x > xmax - dx) return 9999;
110     return (fZoomMode ? 0 : 7);
111   }
112   Bool_t Begin(Int_t event) 
113   {
114     if (!fCanvas) {
115       fCanvas = new TCanvas("display", "Display", 700, 700);
116       fCanvas->SetFillColor(1);
117       fCanvas->ToggleEventStatus();
118       fPad = new TPad("view3D", "3DView", 0.0, 0.1, 1.0, 1.0, 1, 0, 0);
119       fCanvas->cd();
120       fPad->Draw();
121     }
122     if (!fButton) {
123       fCanvas->cd();
124       fButton = new TButton("Continue", 
125                             "DrawHitPatterns::fgInstance->Continue()",
126                             0, 0, .5, .05);
127       fButton->Draw();
128       fZoom = new TButton("Zoom", 
129                           "DrawHitPatterns::fgInstance->Zoom()",
130                           .5, 0, .75, .05);
131       fZoom->Draw();
132       fPick = new TButton("Pick", 
133                           "DrawHitPatterns::fgInstance->Pick()",
134                           .75, 0, 1, .05);
135       fPick->Draw();
136     }
137     Info("Begin", "Clearing canvas");
138     // fCanvas->Clear();
139     if (!fGeoManager) {
140       Warning("End", "No geometry manager");
141       return kFALSE;
142     }
143     Info("Begin", "Drawing geometry");
144     fPad->cd();
145     fGeoManager->GetTopVolume()->Draw();
146     Info("Begin", "Adjusting view");
147     Int_t irep;
148     if (fPad->GetView()) {
149       fPad->GetView()->SetView(-200, -40, 80, irep);
150       fPad->GetView()->Zoom();
151       fPad->Modified();
152       fPad->cd();
153     }
154     Info("Begin", "Drawing button");
155
156     return AliFMDInputHits::Begin(event);
157   }
158     
159   Bool_t ProcessHit(AliFMDHit* hit, TParticle* p) 
160   {
161     if (!hit) {
162       std::cout << "No hit" << std::endl;
163       return kFALSE;
164     }
165
166     if (!p) {
167       std::cout << "No track" << std::endl;
168       return kFALSE;
169     }
170     if (fPrimary && !p->IsPrimary()) return kTRUE;
171     if (hit->IsStop()) return kTRUE;
172     if (fPdg != 0) {
173       if (TMath::Abs(hit->Pdg()) != fPdg) return kTRUE;
174     }
175     fHits->Add(hit);
176     Float_t  size  = TMath::Min(TMath::Max(hit->Edep() * .1, .1), 1.);
177     Float_t  pt    = TMath::Sqrt(hit->Py()*hit->Py()+hit->Px()*hit->Px());
178     Float_t  theta = TMath::ATan2(pt, hit->Pz());
179     Float_t  phi   = TMath::ATan2(hit->Py(), hit->Px());
180     TMarker3DBox* marker = new  TMarker3DBox(hit->X(), hit->Y(), hit->Z(),
181                                              size, size, size,
182                                              theta, phi);
183     marker->SetLineColor((p->IsPrimary() ? 3 : 4));
184     marker->SetRefObject(hit);
185     fMarkers->Add(marker);
186     return kTRUE;
187   }
188   Bool_t End() 
189   {
190     // fGeoManager->GetTopVolume()->Draw();
191     fPad->cd();
192     fMarkers->Draw();
193     AppendPad();
194     fPad->Modified(kTRUE);
195     fPad->Update();
196     fPad->cd();
197     fCanvas->Modified(kTRUE);
198     fCanvas->Update();
199     fCanvas->cd();
200     
201     fWait = kTRUE;
202     while (fWait) {
203       gApplication->StartIdleing();
204       gSystem->InnerLoop();
205       gApplication->StopIdleing();
206     }
207     Info("End", "After idle loop");
208     fMarkers->Delete();
209     fHits->Clear();
210     Info("End", "After clearing caches");
211     return AliFMDInputHits::End();
212   }
213   ClassDef(DrawHitPatterns,0);
214 };
215
216 DrawHitPatterns* DrawHitPatterns::fgInstance = 0;
217
218 //____________________________________________________________________
219 //
220 // EOF
221 //