HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseVertex3Dsim.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseVertex3Dsim.cxx
3 //
12 #include "HarpoConfig.h"
13 #include "HarpoDetSet.h"
14 #include "HarpoDebug.h"
15 #include "HarpoDccEvent.h"
16 #include "Pmm2Event.h"
17 #include "HarpoEvent.h"
18 #include "HarpoRecoEvent.h"
19 #include "HarpoSimEvent.h"
20 #include "TpcSimMCEvent.h"
21 #include "MakeNiceHisto.h"
22 
23 #include "TFile.h"
24 #include "TStyle.h"
25 #include "TCanvas.h"
26 #include "TRootEmbeddedCanvas.h"
27 #include "TLatex.h"
28 #include "TGraph.h"
29 #include "TF1.h"
30 #include "TMath.h"
31 #include "TGLabel.h"
32 #include "TRandom.h"
33 #include "TSystem.h"
34 
35 #include <cstdlib>
36 #include <cstring>
37 #include <cassert>
38 #include <fstream>
39 #include <iostream>
40 
41 ClassImp(HarpoAnalyseVertex3Dsim);
42 
44  {
45  unsigned int nd; // number of detectors
47 
48  assert(hdr != NULL);
49  hdr->print();
50 
51  for (nd = 0; nd < gkNDetectors; nd++) {
52  // if (fEvt->isdataExist(nd)) {
53  HarpoDccMap *plane = fEvt->GetDccMap(nd);
54  if (plane != NULL )plane->print();
55  }
56  }
57 
59 {
60  // Bool_t drawEvent = kFALSE;
61  nEvents++;
62  if(nEvents%1000==0)
63  Info("process","Event %ld",nEvents);
64  //???????????????????????????????
65  if (!gHDetSet->isExist(SIMDET)) return;
66  if(!fEvt->GetRecoEvent()) return;
67 
68 
69  Double_t angle_open_sim = 0;
70  // Double_t angle_omega_sim = 0;
71  TVector3 possim = TVector3(0,0,0);
72  TVector3 pgammasim = TVector3(0,0,1);
73  TVector3 ppolasim = TVector3(0,1,0);
74  TVector3 pgamma = TVector3(0,0,1);
75  Double_t egamma = -1;
76  TVector3 ppola = TVector3(0,1,0);
77  TVector3 ppositron, pelectron;
78  Double_t epositron= -1.0, eelectron = -1.0;
80  TpcSimMCEvent* mcEvent = simEvt->GetMCEvent();
81  Int_t nMCtr = mcEvent->GetNtracks();
82  // if(nMCtr==2){
83  //Double_t norm[2] = {0,0};
84  Bool_t palready = kFALSE;
85  for(Int_t i = 0; i<nMCtr; i++){
86  TpcSimMCTrack* track = mcEvent->GetTrack(i);
87  Int_t pdgcode = track->GetPdgCode();
88  if(pdgcode == 11 && palready) pdgcode = -11;
89  switch(pdgcode){
90  case 22:
91  possim = track->GetOrigin();
92  pgammasim = track->GetP();
93  ppolasim = track->GetPola();
94  pgamma = track->GetP();
95  egamma = track->GetE();
96  ppola = track->GetPola();
97  break;
98  case 11:
99  palready = kTRUE;
100  ppositron = track->GetP();
101  epositron = track->GetE();
102  break;
103  case -11:
104  pelectron = track->GetP();
105  eelectron = track->GetE();
106  break;
107  }
108  }
109  Double_t u1u2 = ppositron.Unit()*pelectron.Unit();
110  angle_open_sim=acos(u1u2);
111 
112 
113  // Info("process","Pgamma = (%g,%g,%g)",pgammasim.Px(),pgammasim.Py(),pgammasim.Pz());
114  // Info("process","Ppola = (%g,%g,%g)",ppolasim.Px(),ppolasim.Py(),ppolasim.Pz());
115 
116  TVector3 ppola2 = ppolasim.Cross(pgammasim.Unit());
117  TVector3 pPlusMC = TVector3(ppositron.Dot(pgammasim.Unit()),ppositron.Dot(ppolasim.Unit()),ppositron.Dot(ppola2.Unit())).Unit();
118  TVector3 pMinusMC = TVector3(pelectron.Dot(pgammasim.Unit()),pelectron.Dot(ppolasim.Unit()),pelectron.Dot(ppola2.Unit())).Unit();
119 
120  Double_t phiPlusMC = TMath::ATan2(pPlusMC.Pz(),pPlusMC.Py());
121  Double_t phiMinusMC = TMath::ATan2(pMinusMC.Pz(),pMinusMC.Py());
122  Double_t phipmMC = 0.5*(phiPlusMC+phiMinusMC);
123  if(gRandom->Rndm()<0.5) phipmMC += TMath::Pi();
124  while(phipmMC>TMath::Pi()) phipmMC -= 2*TMath::Pi();
125  while(phipmMC<-TMath::Pi()) phipmMC += 2*TMath::Pi();
126 
127  hOpenMC->Fill(angle_open_sim);
128  hPhiPmMC->Fill(phipmMC);
129 
130  HarpoRecoEvent* reco = fEvt->GetRecoEvent();
131 
132  TClonesArray* vArray = reco->GetVertex3DArray();
133  // TClonesArray* v2dArray = reco->GetVertexArray();
134  Int_t nV = vArray->GetEntries();
135  Int_t nIn = 0, nOut = 0;
136  for(Int_t iV = 0; iV<nV; iV++){
137  HarpoRecoVertex3D* vertex = (HarpoRecoVertex3D*)vArray->At(iV);
138 
139  Double_t e1 = eelectron; // TO DO FIX ME
140  Double_t e2 = epositron; // TO DO FIX ME
141  Double_t e = egamma; // TO DO FIX ME
142 
143  TVector3 p1 = vertex->GetP1Vertex3D();
144  TVector3 p2 = vertex->GetP2Vertex3D();
145  // TLorentzVector pL1(p1,e1);
146  // TLorentzVector pL2(p2,e2);
147  Double_t xV = vertex->GetXvertex3D();
148  Double_t yV = vertex->GetYvertex3D();
149  Double_t zV = vertex->GetZvertex3D();
150  // Int_t iVx = vertex->GetVertexX();
151  // Int_t iVy = vertex->GetVertexY();
152  TVector3 p = p1.Unit() + p2.Unit();
153  // TLorentzVector3 pL = pL1 + pL2;
154 
155  // HarpoRecoVertex* vertexX = (HarpoRecoVertex*)v2dArray->At(iVx);
156  // HarpoRecoVertex* vertexY = (HarpoRecoVertex*)v2dArray->At(iVy);
157 
158  hDistRecoSim->Fill(xV-possim.x()-150,yV-possim.y()-150,zV-possim.z()-250);
159 
160  hPosition->Fill(xV,yV,zV);
161 
162 
163  Double_t u1u2 = p1.Unit()*p2.Unit();
164  Double_t angle_open=acos(u1u2);
165  hOpen->Fill(angle_open);
166 
167  // TVector3 ppola2 = ppola.Cross(pgamma);
168  TVector3 pPlus = TVector3(p1.Dot(pgammasim.Unit()),p1.Dot(ppolasim.Unit()),p1.Dot(ppola2.Unit()));
169  TVector3 pMinus = TVector3(p2.Dot(pgammasim.Unit()),p2.Dot(ppolasim.Unit()),p2.Dot(ppola2.Unit()));
170  Double_t phiPlus = TMath::ATan2(pPlus.Pz(),pPlus.Py());
171  Double_t phiMinus = TMath::ATan2(pMinus.Pz(),pMinus.Py());
172  Double_t phipm = 0.5*(phiPlus+phiMinus);
173  if(gRandom->Rndm()<0.5) phipm += TMath::Pi();
174  while(phipm>TMath::Pi()) phipm -= 2*TMath::Pi();
175  while(phipm<-TMath::Pi()) phipm += 2*TMath::Pi();
176  Double_t deltaphipm = phipm-phipmMC;
177  while(deltaphipm>TMath::Pi()) deltaphipm -= 2*TMath::Pi();
178  while(deltaphipm<-TMath::Pi()) deltaphipm += 2*TMath::Pi();
179 
180  hPhiPm->Fill(phipm);
181  Double_t theta = pgammasim.Angle(p1.Unit()+p2.Unit());
182  //if(theta>TMath::Pi()/2) theta = TMath::Pi()-theta;
183  hTheta->Fill(theta);
184 
185  Double_t data[19];
186  for(Int_t i = 0; i<3; i++){
187  data[0+i] = possim[i];
188  data[3+i] = 0;
189  data[6+i] = p[i];
190  data[9+i] = pgammasim[i];
191  }
192  data[12] = e;
193  data[13] = e1;
194  data[14] = e2;
195  data[15] = theta;
196  data[16] = phipm;
197  data[17] = angle_open;
198  data[18] = 0;
199  if(TMath::Abs(xV-possim.x()-150)<10 &&TMath::Abs(yV-possim.y()-150)<10 &&TMath::Abs(zV-possim.z()-250)<10){
200  data[18] = 1;
201  hPhiPmCut->Fill(phipm);
202  hPositionCut->Fill(xV,yV,zV);
203  hDeltaPhiPm->Fill(deltaphipm);
204  hDeltaOpen->Fill(angle_open-angle_open_sim);
205 
206  hOpenCut->Fill(angle_open);
207  if(angle_open>0.05)// + 0.5/egamma)
208  hThetaCut->Fill(theta);
209 
210  nIn++;
211  }else
212  nOut++;
213  fNtuple->Fill(data);
214  }
215 
216 
217  hNin->Fill(nIn);
218  hNout->Fill(nOut);
219 
220 
221 }
222 
224 {
225 
226  fChooseNbins = 0;
227 
228  hPhiPmMC = new TH1F("hPhiPmMC","",200,-TMath::Pi(),TMath::Pi());
229  hPhiPm = new TH1F("hPhiPm","",200,-TMath::Pi(),TMath::Pi());
230  hPhiPmCut = new TH1F("hPhiPmCut","",200,-TMath::Pi(),TMath::Pi());
231  hDeltaPhiPm = new TH1F("hDeltaPhiPm","",200,-TMath::Pi(),TMath::Pi());
232  hOpenMC = new TH1F("hOpenMC","",200,0,TMath::Pi());
233  hOpen = new TH1F("hOpen","",200,0,TMath::Pi());
234  hDeltaOpen = new TH1F("hDeltaOpen","",200,-TMath::Pi(),TMath::Pi());
235  hOpenCut = new TH1F("hOpenCut","",200,0,TMath::Pi());
236  hDistRecoSim = new TH3F("hDistRecoSim","",200,-50,50,200,-50,50,200,-50,50);
237  hPosition = new TH3F("hPosition","",100,0,300,100,0,300,128,0,512);
238  hPositionCut = new TH3F("hPositionCut","",100,0,300,100,0,300,128,0,512);
239 
240  hTheta = new TH1F("hTheta","",200,0,TMath::Pi());
241  hThetaCut = new TH1F("hThetaCut","",200,0,TMath::Pi());
242 
243  hNin = new TH1F("hNin","",20,0,20);
244  hNout = new TH1F("hNout","",20,0,20);
245 
246  fNtuple = new TNtupleD("fNtuple","Vertex data","x:y:z:px:py:pz:pBx:pBy:pBz:pxsim:pysim:pzsim:e:e1:e2:theta:phipm:open:cut");
247  fNtuple->SetDirectory(0);
248 
249 
250  }
251 
252 void HarpoAnalyseVertex3Dsim::Save(char * /* mode */)
253  {
254 
255  OpenHistFile("vertex3dsim");
256 
257  // Save histograms here
258  hDistRecoSim->Write();
259  hPhiPm->Write();
260  hPhiPmCut->Write();
261  hPhiPmMC->Write();
262  hDeltaPhiPm->Write();
263  hOpen->Write();
264  hDeltaOpen->Write();
265  hOpenCut->Write();
266  hOpenMC->Write();
267  hPosition->Write();
268  hPositionCut->Write();
269  hNin->Write();
270  hNout->Write();
271  hTheta->Write();
272  hThetaCut->Write();
273 
274  fNtuple->Write();
275  }
276 
277 
278 
279 void HarpoAnalyseVertex3Dsim::DisplayAnalysis(TRootEmbeddedCanvas* ecTab, TGListBox* /* infobox */)
280 {
281  // in hrecomonitorgui: fills the canvas on the "Analysis" tab
282  TCanvas* c = ecTab->GetCanvas();
283  c->GetPad(1)->Delete();
284  c->GetPad(2)->Delete();
285  c->Divide(2);
286 
287  for(Int_t plane = 0; plane<2;plane++){
288  TVirtualPad* cMap = c->GetPad(plane+1);
289  HarpoDccMap* m = fEvt->GetDccMap(plane);
290  TH2F* h = new TH2F("h","",512,0,512,288,0,288);
291  for(Int_t i=1;i<NADC;i++){ //Time bins
292  for(Int_t j=0;j<NCHAN;j++){ // Channels
293  Double_t q = m->GetData(j,i);
294  h->SetBinContent(i+1,j+1,q);
295  }
296  }
297  h->SetMinimum(0);
298  MakeNiceHisto(h,cMap,"colz");
299  h->Delete();
300  }
301 
302  c->Update();
303 }
304 
305 
306 void HarpoAnalyseVertex3Dsim::ConfigFrame(TGMainFrame* fMain, Int_t id)
307 {
308  // in hrecomonitorgui: Creates a popup window for analysis configuration
309  // You must define SetConfig() properly
310 
311  UInt_t xsize = 200;
312  UInt_t ysize2 = 20;
313  UInt_t ysize = 10*ysize2;
314  TGTransientFrame* main = new TGTransientFrame(gClient->GetRoot(), fMain, xsize, ysize);
315  main->Connect("CloseWindow()", "HarpoRecoMonitorGui", main, "CloseWindow()");
316  main->DontCallClose(); // to avoid double deletions.
317 
318  // use hierarchical cleaning
319  main->SetCleanup(kDeepCleanup);
320 
321  TGVerticalFrame* frame = new TGVerticalFrame(main,xsize,ysize,kVerticalFrame);
322 
323  // Object layout options
324  TGLayoutHints* fLayout1 = new TGLayoutHints(kLHintsLeft ,5,5,5,5);
325  TGLayoutHints* fLayout2 = new TGLayoutHints(kLHintsRight ,5,5,5,5);
326  TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsTop | kLHintsExpandX ,5,5,5,5);
327  TGLayoutHints* fLayout4 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5);
328 
329  //________ DO NOT MODIFY ABOVE _____________________________
330 
331 
332 
333 
334  // Title of the analysis
335  TGLabel* fAnalysisLabel = new TGLabel(frame, "Template analysis");
336 
337  // Create a line for choosing value of parameter
338  TGHorizontalFrame* nBinsFrame = new TGHorizontalFrame(frame,xsize,ysize2,kHorizontalFrame);
339  TGLabel* nBinsLabel = new TGLabel(nBinsFrame, "fNbins");
340  fChooseNbins = new TGNumberEntry(nBinsFrame);
341  fChooseNbins->SetNumber(fNbins);
342 
343  main->AddFrame(frame,fLayout4);
344  frame->AddFrame(fAnalysisLabel,fLayout3);
345  frame->AddFrame(nBinsFrame,fLayout3);
346  nBinsFrame->AddFrame(nBinsLabel,fLayout1);
347  nBinsFrame->AddFrame(fChooseNbins,fLayout2);
348 
349 
350 
351  //________ DO NOT MODIFY BELOW _____________________________
352  // Button to validate configuration
353  TGTextButton* setConf = new TGTextButton(frame,"Save Config",id);
354  setConf->Associate(fMain);
355 
356  frame->AddFrame(setConf,fLayout3);
357 
358  main->MapSubwindows();
359  main->MapWindow();
360  main->Resize();
361  return;
362 }
363 
364 
365 
367 {
368  // Update the configuration according to the values in the popup window
369 
370  if(!fChooseNbins) return;
371 
372  fNbins = fChooseNbins->GetNumber();
373 }
Double_t GetZvertex3D()
Double_t GetYvertex3D()
TVector3 GetPola()
Definition: TpcSimMCEvent.h:40
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
TVector3 GetOrigin()
Definition: TpcSimMCEvent.h:27
void print()
Overloaded method which do all job.
#define NCHAN
Definition: HarpoDccMap.h:16
Dummy analysis to run as test and example. Give basic histograms of the data.
TVector3 GetP2Vertex3D()
TVector3 GetP()
Definition: TpcSimMCEvent.h:34
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
int main(int argc, char **argv)
Definition: drawAnalyse.cxx:25
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
Int_t GetPdgCode()
Definition: TpcSimMCEvent.h:43
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
Double_t GetE()
Definition: TpcSimMCEvent.h:33
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
A class store HARPO row DCC event data and header. End provide access metods to the row data...
Definition: HarpoSimEvent.h:24
virtual void print()
TFile * OpenHistFile(const char *ananame)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
HarpoDetEvent * GetDetEvent(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:93
Data from Keller temperuture and pressure sensors.
Definition: HarpoDet.h:22
TVector3 GetP1Vertex3D()
TVirtualPad * MakeNiceHisto(TH1 *hist, TVirtualPad *c1, const char *opt, Bool_t copy)
Int_t GetNtracks()
void ConfigFrame(TGMainFrame *fMain, Int_t id)
TpcSimMCTrack * GetTrack(Int_t i)
Definition: TpcSimMCEvent.h:91
#define NADC
Definition: HarpoDccMap.h:18
TpcSimMCEvent * GetMCEvent()
Definition: HarpoSimEvent.h:57
TClonesArray * GetVertex3DArray()
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
void DisplayAnalysis(TRootEmbeddedCanvas *ecTab, TGListBox *infobox)
Redefine empty default.
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
Double_t GetXvertex3D()
3D vertex object, containing position, angle and associated 2D vertexes, and quality info ...